Skip to content

Commit

Permalink
fix slot info
Browse files Browse the repository at this point in the history
Signed-off-by: catcherwong <[email protected]>
  • Loading branch information
catcherwong committed Oct 6, 2024
1 parent 7887675 commit a8a8e32
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 34 deletions.
4 changes: 0 additions & 4 deletions src/RDBCli/Callbacks/KeysOnlyCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,5 @@ public void ZAdd(byte[] key, double score, byte[] member)
public void SetIdleOrFreq(int val)
{
}

public void SetSlotInfo(ulong slotId, ulong slotSize, ulong expireSlotSize)
{
}
}
}
4 changes: 0 additions & 4 deletions src/RDBCli/Callbacks/MemoryCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,5 @@ public void SetIdleOrFreq(int val)
{
_idleOrFreq = val;
}

public void SetSlotInfo(ulong slotId, ulong slotSize, ulong expireSlotSize)
{
}
}
}
14 changes: 10 additions & 4 deletions src/RDBParser/BinaryReaderRDBParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public partial class BinaryReaderRDBParser : IRDBParser
private int _freq = 0;
private int _mem_policy = -1; // 1 - lru | 2 - lfu
private int _version = -1;
private ulong _slotId = 0;
private HashSet<string> _auxKey = new HashSet<string>();

public BinaryReaderRDBParser(IReaderCallback callback, ParserFilter filter = null)
Expand Down Expand Up @@ -90,10 +91,14 @@ public void Parse(string path)

if (opType == Constant.OpCode.SLOTINFO)
{
var slotId = br.ReadLength();
var slotSize = br.ReadLength();
var expireSlotSize = br.ReadLength();
_callback.SetSlotInfo(slotId, slotSize, expireSlotSize);
// cluster keyslot yourkey
_slotId = br.ReadLength();

// slotSize
_ = br.ReadLength();

// expireSlotSize
_ = br.ReadLength();
continue;
}

Expand Down Expand Up @@ -183,6 +188,7 @@ public void Parse(string path)
{
info.Idle = _idle;
info.Freq = _freq;
info.SlotId = _slotId;

ReadObject(br, _key, opType, _expiry, info);
}
Expand Down
5 changes: 0 additions & 5 deletions src/RDBParser/Callbacks/DefaultConsoleReaderCallBack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ public void SetIdleOrFreq(int val)
Console.WriteLine($"SetIdleOrFreq, val={val}");
}

public void SetSlotInfo(ulong slotId, ulong slotSize, ulong expireSlotSize)
{
Console.WriteLine($"SetSlotInfo, slotId={slotId}, slotSize={slotSize}, expireSlotSize={expireSlotSize}");
}

public void StartDatabase(int database)
{
Console.WriteLine($"Start database = {database}");
Expand Down
8 changes: 0 additions & 8 deletions src/RDBParser/Callbacks/IReaderCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,5 @@ public interface IReaderCallback
/// </summary>
/// <param name="val"></param>
void SetIdleOrFreq(int val);

/// <summary>
/// Record Slot Info
/// </summary>
/// <param name="slotId"></param>
/// <param name="slotSize"></param>
/// <param name="expireSlotSize"></param>
void SetSlotInfo(ulong slotId, ulong slotSize, ulong expireSlotSize);
}
}
2 changes: 2 additions & 0 deletions src/RDBParser/Callbacks/Models/Info.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class Info

public ulong Zips { get; set; }

public ulong SlotId { get; set; }

public override string ToString()
{
return $"Info{{Encoding={Encoding},Idle={Idle},Freq={Freq},SizeOfValue={SizeOfValue},Zips={Zips}}}";
Expand Down
4 changes: 0 additions & 4 deletions src/RDBParser/Callbacks/NoOpReaderCallBack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ public void SetIdleOrFreq(int val)
{
}

public void SetSlotInfo(ulong slotId, ulong slotSize, ulong expireSlotSize)
{
}

public void StartDatabase(int database)
{
}
Expand Down
34 changes: 34 additions & 0 deletions tests/RDBParserTests/ClusterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using RDBParser;
using System.Text;
using Xunit;
using Xunit.Abstractions;

namespace RDBParserTests
{
public class ClusterTests
{
private ITestOutputHelper _output;

public ClusterTests(ITestOutputHelper output)
{
this._output = output;
}

[Fact]
public void TestSoltInfo()
{
// set mykey v1
// bgsave
var path = TestHelper.GetRDBPath("redis74_cluster_slotinfo.rdb");

var callback = new TestReaderCallback(_output);
var parser = new BinaryReaderRDBParser(callback);
parser.Parse(path);

var infos = callback.GetInfos();

Assert.Equal(1165, (int)infos[0][Encoding.UTF8.GetBytes("key{v1}")].SlotId);
Assert.Equal(2589, (int)infos[0][Encoding.UTF8.GetBytes("key{v12}")].SlotId);
}
}
}
5 changes: 0 additions & 5 deletions tests/RDBParserTests/TestReaderCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,5 @@ public void SetIdleOrFreq(int val)
{
_idleOrFreq = val;
}

public void SetSlotInfo(ulong slotId, ulong slotSize, ulong expireSlotSize)
{
System.Diagnostics.Trace.WriteLine($"{slotId}, {slotSize}, {expireSlotSize}");
}
}
}
Binary file added tests/dumps/redis74_cluster_slotinfo.rdb
Binary file not shown.

0 comments on commit a8a8e32

Please sign in to comment.