Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions libs/server/Metrics/Info/InfoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ private bool NetworkINFO()
var info = garnetInfo.GetRespInfo(sectionsArr, activeDbId, storeWrapper);
if (!string.IsNullOrEmpty(info))
{
WriteVerbatimString(Encoding.ASCII.GetBytes(info));
WriteLargeVerbatimString(Encoding.ASCII.GetBytes(info));
}
else
{
while (!RespWriteUtils.TryWriteDirect(CmdStrings.RESP_EMPTY, ref dcurr, dend))
SendAndReset();
WriteDirect(CmdStrings.RESP_EMPTY);
}
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions libs/server/Resp/ClientCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private bool NetworkCLIENTLIST()

resultSb.Append("\n");
var result = resultSb.ToString();
WriteVerbatimString(Encoding.ASCII.GetBytes(result));
WriteLargeVerbatimString(Encoding.ASCII.GetBytes(result));

return true;
}
Expand Down Expand Up @@ -194,7 +194,7 @@ private bool NetworkCLIENTINFO()

resultSb.Append("\n");
var result = resultSb.ToString();
WriteVerbatimString(Encoding.ASCII.GetBytes(result));
WriteLargeVerbatimString(Encoding.ASCII.GetBytes(result));

return true;
}
Expand Down
47 changes: 43 additions & 4 deletions libs/server/Resp/RespServerSessionOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Licensed under the MIT license.

using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Garnet.common;
using Tsavorite.core;

Expand Down Expand Up @@ -272,17 +274,54 @@ private void WriteUtf8BulkString(ReadOnlySpan<char> chars)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void WriteVerbatimString(scoped ReadOnlySpan<byte> item, scoped ReadOnlySpan<byte> ext = default)
private void WriteLargeVerbatimString(scoped ReadOnlySpan<byte> item, scoped ReadOnlySpan<byte> ext = default)
Comment thread
kevin-montrose marked this conversation as resolved.
{
if (respProtocolVersion >= 3)
{
while (!RespWriteUtils.TryWriteVerbatimString(item, ext.IsEmpty ? RespStrings.VerbatimTxt : ext, ref dcurr, dend))
ext = ext.IsEmpty ? RespStrings.VerbatimTxt : ext;
Debug.Assert(ext.Length == 3);

var actualLength = 3 + 1 + item.Length;
var itemDigits = NumUtils.CountDigits(actualLength);

var lenSpace = 1 + itemDigits + 2; // =<digits>\r\n
if (lenSpace > (int)(dend - dcurr))
{
SendAndReset();
}
Debug.Assert((int)(dend - dcurr) >= lenSpace, "Should always have enough space for length after a flush");

// Write out: =<digits>\r\n
*dcurr = (byte)'=';
dcurr++;
NumUtils.WriteInt32(actualLength, itemDigits, ref dcurr);
Unsafe.WriteUnaligned(dcurr, MemoryMarshal.Read<ushort>("\r\n"u8));
Comment thread
kevin-montrose marked this conversation as resolved.
Outdated
dcurr += 2;

// Write oute <ext>:
Comment thread
kevin-montrose marked this conversation as resolved.
Outdated
WriteDirectLarge(ext);
if ((int)(dend - dcurr) < 1)
{
SendAndReset();
}
WriteDirect(":"u8);

// Write out item
WriteDirectLarge(item);

if ((int)(dend - dcurr) < 2)
{
SendAndReset();
}

// Write out trailing \r\n
Unsafe.WriteUnaligned(dcurr, MemoryMarshal.Read<ushort>("\r\n"u8));
Comment thread
kevin-montrose marked this conversation as resolved.
Outdated
dcurr += 2;
}
else
{
while (!RespWriteUtils.TryWriteBulkString(item, ref dcurr, dend))
SendAndReset();
// RESP2 just gets a bulk string
WriteDirectLargeRespString(item);
}
}
}
Expand Down
25 changes: 16 additions & 9 deletions test/Garnet.test/RespInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ public void TearDown()
}

[Test]
Comment thread
kevin-montrose marked this conversation as resolved.
Outdated
public void ResetStatsTest()
[TestCase(RedisProtocol.Resp2)]
[TestCase(RedisProtocol.Resp3)]
public void ResetStatsTest(RedisProtocol protocol)
{
TimeSpan metricsUpdateDelay = TimeSpan.FromSeconds(1.1);
using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig());
using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig(protocol: protocol));
var db = redis.GetDatabase(0);

var infoResult = db.Execute("INFO").ToString();
Expand Down Expand Up @@ -76,12 +78,15 @@ public void ResetStatsTest()
}

[Test]
[TestCase("ALL")]
[TestCase("DEFAULT")]
[TestCase("EVERYTHING")]
public void InfoSectionOptionsTest(string option)
[TestCase("ALL", RedisProtocol.Resp2)]
[TestCase("ALL", RedisProtocol.Resp3)]
[TestCase("DEFAULT", RedisProtocol.Resp2)]
[TestCase("DEFAULT", RedisProtocol.Resp3)]
[TestCase("EVERYTHING", RedisProtocol.Resp2)]
[TestCase("EVERYTHING", RedisProtocol.Resp3)]
public void InfoSectionOptionsTest(string option, RedisProtocol protocol)
Comment thread
kevin-montrose marked this conversation as resolved.
Comment thread
kevin-montrose marked this conversation as resolved.
{
using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig());
using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig(protocol: protocol));
var db = redis.GetDatabase(0);

var infoResult = db.Execute("INFO", option).ToString();
Expand Down Expand Up @@ -115,9 +120,11 @@ public void InfoSectionOptionsTest(string option)
}

[Test]
Comment thread
kevin-montrose marked this conversation as resolved.
Outdated
public void InfoDefaultMatchesNoArgsTest()
[TestCase(RedisProtocol.Resp2)]
[TestCase(RedisProtocol.Resp3)]
public void InfoDefaultMatchesNoArgsTest(RedisProtocol protocol)
{
using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig());
using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig(protocol: protocol));
var db = redis.GetDatabase(0);

var infoNoArgs = db.Execute("INFO").ToString();
Expand Down
Loading