Skip to content

Commit

Permalink
Fix writing output for scan (#880)
Browse files Browse the repository at this point in the history
* Writing output for scan was not handling output buffer (dcurr, dend) correctly. Also, it was not handling large keys correctly.

* update version
  • Loading branch information
badrishc authored Dec 13, 2024
1 parent 3f679b0 commit 178dc21
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Version.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<!-- Versioning property for builds and packages -->
<PropertyGroup>
<VersionPrefix>1.0.47</VersionPrefix>
<VersionPrefix>1.0.48</VersionPrefix>
</PropertyGroup>
</Project>
13 changes: 5 additions & 8 deletions libs/server/Resp/ArrayCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ private bool NetworkSCAN<TGarnetApi>(ref TGarnetApi storageApi)
SendAndReset();

if (keys.Count > 0)
WriteOutputForScan(cursor, keys, ref dcurr, dend);
WriteOutputForScan(cursor, keys);
}

return true;
Expand Down Expand Up @@ -415,24 +415,21 @@ private bool NetworkTYPE<TGarnetApi>(ref TGarnetApi storageApi)
/// </summary>
/// <param name="cursorValue">Cursor value to write to the output</param>
/// <param name="keys">Keys to write to the output</param>
/// <param name="curr">Pointer to output buffer</param>
/// <param name="end">End of the output buffer</param>
private void WriteOutputForScan(long cursorValue, List<byte[]> keys, ref byte* curr, byte* end)
private void WriteOutputForScan(long cursorValue, List<byte[]> keys)
{
// The output is an array of two elements: cursor value and an array of keys
// Note the cursor value should be formatted as bulk string ('$')
while (!RespWriteUtils.WriteIntegerAsBulkString(cursorValue, ref curr, end, out _))
while (!RespWriteUtils.WriteIntegerAsBulkString(cursorValue, ref dcurr, dend, out _))
SendAndReset();

// Write size of the array
while (!RespWriteUtils.WriteArrayLength(keys.Count, ref curr, end))
while (!RespWriteUtils.WriteArrayLength(keys.Count, ref dcurr, dend))
SendAndReset();

// Write the keys matching the pattern
for (int i = 0; i < keys.Count; i++)
{
while (!RespWriteUtils.WriteBulkString(keys[i], ref curr, end))
SendAndReset();
WriteDirectLargeRespString(keys[i]);
}
}

Expand Down

0 comments on commit 178dc21

Please sign in to comment.