Skip to content

Commit

Permalink
Clear input header field (flags) for object store RMW operations (#357)
Browse files Browse the repository at this point in the history
* When preparing input for the object store RMW operations, we need to set the flag field to 0 as the buffer being used to create the input may not be zero'ed out.

* small fix

* Clean up Unit Test

---------

Co-authored-by: TedHartMS <15467143+TedHartMS@users.noreply.github.com>
  • Loading branch information
badrishc and TedHartMS authored May 3, 2024
1 parent 2dc2c73 commit 30e3780
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 1 deletion.
8 changes: 8 additions & 0 deletions libs/server/Resp/Objects/HashCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private unsafe bool HashSet<TGarnetApi>(int count, byte* ptr, HashOperation hop,

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.Hash;
inputPtr->header.flags = 0;
inputPtr->header.HashOp = hop;
inputPtr->count = inputCount;
inputPtr->done = hashOpsCount;
Expand Down Expand Up @@ -152,6 +153,7 @@ private unsafe bool HashGet<TGarnetApi>(int count, byte* ptr, HashOperation op,
int inputCount = op == HashOperation.HGETALL ? 0 : (op == HashOperation.HRANDFIELD ? count + 1 : count - 1);
// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.Hash;
inputPtr->header.flags = 0;
inputPtr->header.HashOp = op;
inputPtr->count = inputCount;
inputPtr->done = hashItemsDoneCount;
Expand Down Expand Up @@ -253,6 +255,7 @@ private unsafe bool HashLength<TGarnetApi>(int count, byte* ptr, ref TGarnetApi

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.Hash;
inputPtr->header.flags = 0;
inputPtr->header.HashOp = HashOperation.HLEN;
inputPtr->count = 1;
inputPtr->done = 0;
Expand Down Expand Up @@ -323,6 +326,7 @@ private unsafe bool HashStrLength<TGarnetApi>(int count, byte* ptr, ref TGarnetA

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.Hash;
inputPtr->header.flags = 0;
inputPtr->header.HashOp = HashOperation.HSTRLEN;
inputPtr->count = 1;
inputPtr->done = 0;
Expand Down Expand Up @@ -397,6 +401,7 @@ private unsafe bool HashDelete<TGarnetApi>(int count, byte* ptr, ref TGarnetApi

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.Hash;
inputPtr->header.flags = 0;
inputPtr->header.HashOp = HashOperation.HDEL;
inputPtr->count = inputCount;
inputPtr->done = hashItemsDoneCount;
Expand Down Expand Up @@ -474,6 +479,7 @@ private unsafe bool HashExists<TGarnetApi>(int count, byte* ptr, ref TGarnetApi

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.Hash;
inputPtr->header.flags = 0;
inputPtr->header.HashOp = HashOperation.HEXISTS;
inputPtr->count = 1;
inputPtr->done = 0;
Expand Down Expand Up @@ -546,6 +552,7 @@ private unsafe bool HashKeys<TGarnetApi>(int count, byte* ptr, HashOperation op,

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.Hash;
inputPtr->header.flags = 0;
inputPtr->header.HashOp = op;
inputPtr->count = count - 1;
inputPtr->done = hashOpsCount;
Expand Down Expand Up @@ -634,6 +641,7 @@ private unsafe bool HashIncrement<TGarnetApi>(int count, byte* ptr, HashOperatio

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.Hash;
inputPtr->header.flags = 0;
inputPtr->header.HashOp = op;
inputPtr->count = count + 1;
inputPtr->done = 0;
Expand Down
9 changes: 9 additions & 0 deletions libs/server/Resp/Objects/ListCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private unsafe bool ListPush<TGarnetApi>(int count, byte* ptr, ListOperation lop

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.List;
inputPtr->header.flags = 0;
inputPtr->header.ListOp = lop;
inputPtr->count = inputCount;
inputPtr->done = listItemsDoneCount;
Expand Down Expand Up @@ -157,6 +158,7 @@ private unsafe bool ListPop<TGarnetApi>(int count, byte* ptr, ListOperation lop,

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.List;
inputPtr->header.flags = 0;
inputPtr->header.ListOp = lop;
inputPtr->done = 0;
inputPtr->count = popCount;
Expand Down Expand Up @@ -230,6 +232,7 @@ private unsafe bool ListLength<TGarnetApi>(int count, byte* ptr, ref TGarnetApi

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.List;
inputPtr->header.flags = 0;
inputPtr->header.ListOp = ListOperation.LLEN;
inputPtr->count = count;
inputPtr->done = 0;
Expand Down Expand Up @@ -307,6 +310,7 @@ private unsafe bool ListTrim<TGarnetApi>(int count, byte* ptr, ref TGarnetApi st

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.List;
inputPtr->header.flags = 0;
inputPtr->header.ListOp = ListOperation.LTRIM;
inputPtr->count = start;
inputPtr->done = stop;
Expand Down Expand Up @@ -375,6 +379,7 @@ private unsafe bool ListRange<TGarnetApi>(int count, byte* ptr, ref TGarnetApi s
var inputLength = (int)(recvBufferPtr + bytesRead - (byte*)inputPtr);

inputPtr->header.type = GarnetObjectType.List;
inputPtr->header.flags = 0;
inputPtr->header.ListOp = ListOperation.LRANGE;
inputPtr->count = start;
inputPtr->done = end;
Expand Down Expand Up @@ -449,6 +454,7 @@ private unsafe bool ListIndex<TGarnetApi>(int count, byte* ptr, ref TGarnetApi s

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.List;
inputPtr->header.flags = 0;
inputPtr->header.ListOp = ListOperation.LINDEX;
inputPtr->count = index;
inputPtr->done = 0;
Expand Down Expand Up @@ -524,6 +530,7 @@ private unsafe bool ListInsert<TGarnetApi>(int count, byte* ptr, ref TGarnetApi

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.List;
inputPtr->header.flags = 0;
inputPtr->header.ListOp = ListOperation.LINSERT;
inputPtr->done = 0;
inputPtr->count = 0;
Expand Down Expand Up @@ -610,6 +617,7 @@ private unsafe bool ListRemove<TGarnetApi>(int count, byte* ptr, ref TGarnetApi

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.List;
inputPtr->header.flags = 0;
inputPtr->header.ListOp = ListOperation.LREM;
inputPtr->count = nCount;
inputPtr->done = 0;
Expand Down Expand Up @@ -818,6 +826,7 @@ public unsafe bool ListSet<TGarnetApi>(int count, byte* ptr, ref TGarnetApi stor

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.List;
inputPtr->header.flags = 0;
inputPtr->header.ListOp = ListOperation.LSET;
inputPtr->count = 0;
inputPtr->done = 0;
Expand Down
7 changes: 7 additions & 0 deletions libs/server/Resp/Objects/SetCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private unsafe bool SetAdd<TGarnetApi>(int count, byte* ptr, ref TGarnetApi stor

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.Set;
inputPtr->header.flags = 0;
inputPtr->header.SetOp = SetOperation.SADD;
inputPtr->count = inputCount;
inputPtr->done = setOpsCount;
Expand Down Expand Up @@ -249,6 +250,7 @@ private unsafe bool SetRemove<TGarnetApi>(int count, byte* ptr, ref TGarnetApi s

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.Set;
inputPtr->header.flags = 0;
inputPtr->header.SetOp = SetOperation.SREM;
inputPtr->count = inputCount;
inputPtr->done = setItemsDoneCount;
Expand Down Expand Up @@ -329,6 +331,7 @@ private unsafe bool SetLength<TGarnetApi>(int count, byte* ptr, ref TGarnetApi s

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.Set;
inputPtr->header.flags = 0;
inputPtr->header.SetOp = SetOperation.SCARD;
inputPtr->count = 1;
inputPtr->done = 0;
Expand Down Expand Up @@ -396,6 +399,7 @@ private unsafe bool SetMembers<TGarnetApi>(int count, byte* ptr, ref TGarnetApi

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.Set;
inputPtr->header.flags = 0;
inputPtr->header.SetOp = SetOperation.SMEMBERS;
inputPtr->count = count;
inputPtr->done = setItemsDoneCount;
Expand Down Expand Up @@ -466,6 +470,7 @@ private unsafe bool SetIsMember<TGarnetApi>(int count, byte* ptr, ref TGarnetApi

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.Set;
inputPtr->header.flags = 0;
inputPtr->header.SetOp = SetOperation.SISMEMBER;
inputPtr->count = count - 2;
inputPtr->done = 0;
Expand Down Expand Up @@ -543,6 +548,7 @@ private unsafe bool SetPop<TGarnetApi>(int count, byte* ptr, ref TGarnetApi stor

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.Set;
inputPtr->header.flags = 0;
inputPtr->header.SetOp = SetOperation.SPOP;
inputPtr->count = int.MinValue;

Expand Down Expand Up @@ -726,6 +732,7 @@ private unsafe bool SetRandomMember<TGarnetApi>(int count, byte* ptr, ref TGarne

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.Set;
inputPtr->header.flags = 0;
inputPtr->header.SetOp = SetOperation.SRANDMEMBER;
inputPtr->count = Int32.MinValue;

Expand Down
1 change: 1 addition & 0 deletions libs/server/Resp/Objects/SharedObjectCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private unsafe bool ObjectScan<TGarnetApi>(int count, byte* ptr, GarnetObjectTyp

// ObjectInputHeader
(*(ObjectInputHeader*)(pcurr)).header.type = objectType;
(*(ObjectInputHeader*)(pcurr)).header.flags = 0;

switch (objectType)
{
Expand Down
13 changes: 13 additions & 0 deletions libs/server/Resp/Objects/SortedSetCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private unsafe bool SortedSetAdd<TGarnetApi>(int count, byte* ptr, ref TGarnetAp

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.SortedSet;
inputPtr->header.flags = 0;
inputPtr->header.SortedSetOp = SortedSetOperation.ZADD;
inputPtr->count = inputCount;
inputPtr->done = zaddDoneCount;
Expand Down Expand Up @@ -143,6 +144,7 @@ private unsafe bool SortedSetRemove<TGarnetApi>(int count, byte* ptr, ref TGarne

// Prepare header in input buffer
rmwInput->header.type = GarnetObjectType.SortedSet;
rmwInput->header.flags = 0;
rmwInput->header.SortedSetOp = SortedSetOperation.ZREM;
rmwInput->count = inputCount;
rmwInput->done = zaddDoneCount;
Expand Down Expand Up @@ -226,6 +228,7 @@ private unsafe bool SortedSetLength<TGarnetApi>(int count, byte* ptr, ref TGarne

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.SortedSet;
inputPtr->header.flags = 0;
inputPtr->header.SortedSetOp = SortedSetOperation.ZCARD;
inputPtr->count = 1;
inputPtr->done = 0;
Expand Down Expand Up @@ -312,6 +315,7 @@ private unsafe bool SortedSetRange<TGarnetApi>(int count, byte* ptr, SortedSetOp

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.SortedSet;
inputPtr->header.flags = 0;
inputPtr->header.SortedSetOp = op;
inputPtr->count = count - 1;
inputPtr->done = 0;
Expand Down Expand Up @@ -411,6 +415,7 @@ private unsafe bool SortedSetScore<TGarnetApi>(int count, byte* ptr, ref TGarnet

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.SortedSet;
inputPtr->header.flags = 0;
inputPtr->header.SortedSetOp = SortedSetOperation.ZSCORE;
inputPtr->count = scoreKeySize;
inputPtr->done = 0;
Expand Down Expand Up @@ -485,6 +490,7 @@ private unsafe bool SortedSetScores<TGarnetApi>(int count, byte* ptr, ref TGarne

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.SortedSet;
inputPtr->header.flags = 0;
inputPtr->header.SortedSetOp = SortedSetOperation.ZMSCORE;
inputPtr->count = inputCount;
inputPtr->done = 0;
Expand Down Expand Up @@ -572,6 +578,7 @@ private unsafe bool SortedSetPop<TGarnetApi>(int count, byte* ptr, SortedSetOper

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.SortedSet;
inputPtr->header.flags = 0;
inputPtr->header.SortedSetOp = op;
inputPtr->count = popCount;
inputPtr->done = zaddDoneCount;
Expand Down Expand Up @@ -649,6 +656,7 @@ private unsafe bool SortedSetCount<TGarnetApi>(int count, byte* ptr, ref TGarnet

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.SortedSet;
inputPtr->header.flags = 0;
inputPtr->header.SortedSetOp = SortedSetOperation.ZCOUNT;
inputPtr->count = 0;
inputPtr->done = 0;
Expand Down Expand Up @@ -739,6 +747,7 @@ private unsafe bool SortedSetLengthByValue<TGarnetApi>(int count, byte* ptr, Sor

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.SortedSet;
inputPtr->header.flags = 0;
inputPtr->header.SortedSetOp = op;
inputPtr->count = 0;
inputPtr->done = 0;
Expand Down Expand Up @@ -823,6 +832,7 @@ private unsafe bool SortedSetIncrement<TGarnetApi>(int count, byte* ptr, ref TGa

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.SortedSet;
inputPtr->header.flags = 0;
inputPtr->header.SortedSetOp = SortedSetOperation.ZINCRBY;
inputPtr->count = count - 1;
inputPtr->done = 0;
Expand Down Expand Up @@ -925,6 +935,7 @@ private unsafe bool SortedSetRank<TGarnetApi>(int count, byte* ptr, SortedSetOpe

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.SortedSet;
inputPtr->header.flags = 0;
inputPtr->header.SortedSetOp = op;
inputPtr->count = memberSize;
inputPtr->done = 0;
Expand Down Expand Up @@ -997,6 +1008,7 @@ private unsafe bool SortedSetRemoveRange<TGarnetApi>(int count, byte* ptr, Sorte

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.SortedSet;
inputPtr->header.flags = 0;
inputPtr->header.SortedSetOp = op;
inputPtr->count = 0;
inputPtr->done = 0;
Expand Down Expand Up @@ -1101,6 +1113,7 @@ private unsafe bool SortedSetRandomMember<TGarnetApi>(int count, byte* ptr, ref

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.SortedSet;
inputPtr->header.flags = 0;
inputPtr->header.SortedSetOp = SortedSetOperation.ZRANDMEMBER;
inputPtr->count = count == 1 ? 1 : paramCount;
inputPtr->done = withScoresSpan.SequenceEqual(includeWithScores) ? 1 : 0;
Expand Down
2 changes: 2 additions & 0 deletions libs/server/Resp/Objects/SortedSetGeoCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private unsafe bool GeoAdd<TGarnetApi>(int count, byte* ptr, ref TGarnetApi stor

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.SortedSet;
inputPtr->header.flags = 0;
inputPtr->header.SortedSetOp = SortedSetOperation.GEOADD;
inputPtr->count = inputCount;
inputPtr->done = zaddDoneCount;
Expand Down Expand Up @@ -154,6 +155,7 @@ private unsafe bool GeoCommands<TGarnetApi>(int count, byte* ptr, SortedSetOpera

// Prepare header in input buffer
inputPtr->header.type = GarnetObjectType.SortedSet;
inputPtr->header.flags = 0;
inputPtr->header.SortedSetOp = op;
inputPtr->count = inputCount;

Expand Down
Loading

0 comments on commit 30e3780

Please sign in to comment.