Skip to content

Commit

Permalink
generalized keyspecs use
Browse files Browse the repository at this point in the history
  • Loading branch information
vazois committed Aug 9, 2024
1 parent 447693b commit 5d81a85
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 41 deletions.
92 changes: 52 additions & 40 deletions libs/server/Resp/RespServerSessionSlotVerify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

using System;
using Garnet.common;

namespace Garnet.server
{
Expand Down Expand Up @@ -51,51 +52,62 @@ bool CanServeSlot(RespCommand cmd)
return true;

var specs = commandInfo.KeySpecifications;
switch (cmd)
switch (specs.Length)
{
case RespCommand.ZDIFF:
var beginSearch = (BeginSearchIndex)specs[0].BeginSearch;
var findKeysKeyNum = (FindKeysKeyNum)specs[0].FindKeys;
csvi.firstKey = beginSearch.Index;
csvi.lastKey = beginSearch.Index + parseState.GetInt(0);
csvi.step = findKeysKeyNum.KeyStep;
break;
case RespCommand.BITOP:
beginSearch = (BeginSearchIndex)specs[0].BeginSearch;
var findKeys = (FindKeysRange)specs[1].FindKeys;
csvi.firstKey = beginSearch.Index - 2;
csvi.lastKey = findKeys.LastKey < 0 ? findKeys.LastKey + parseState.count + 1 : findKeys.LastKey - beginSearch.Index + 1;
csvi.step = findKeys.KeyStep;
break;
case RespCommand.PFMERGE:
case RespCommand.SDIFFSTORE:
case RespCommand.SUNIONSTORE:
case RespCommand.SINTERSTORE:
beginSearch = (BeginSearchIndex)specs[0].BeginSearch;
findKeys = (FindKeysRange)specs[1].FindKeys;
csvi.firstKey = beginSearch.Index - 1;
csvi.lastKey = findKeys.LastKey < 0 ? findKeys.LastKey + parseState.count + 1 : findKeys.LastKey - beginSearch.Index + 1;
csvi.step = findKeys.KeyStep;
case 1:
var searchIndex = (BeginSearchIndex)specs[0].BeginSearch;

switch (specs[0].FindKeys)
{
case FindKeysRange:
var findRange = (FindKeysRange)specs[0].FindKeys;
csvi.firstKey = searchIndex.Index - 1;
csvi.lastKey = findRange.LastKey < 0 ? findRange.LastKey + parseState.count + 1 : findRange.LastKey - searchIndex.Index + 1;
csvi.step = findRange.KeyStep;
break;
case FindKeysKeyNum:
var findKeysKeyNum = (FindKeysKeyNum)specs[0].FindKeys;
csvi.firstKey = searchIndex.Index + findKeysKeyNum.FirstKey - 1;
csvi.lastKey = searchIndex.Index + parseState.GetInt(0);
csvi.step = findKeysKeyNum.KeyStep;
break;
case FindKeysUnknown:
default:
throw new GarnetException("FindKeysUnknown range");
}

break;
case RespCommand.RENAME:
case RespCommand.SMOVE:
case RespCommand.LMOVE:
beginSearch = (BeginSearchIndex)specs[0].BeginSearch;
var beginSearch1 = (BeginSearchIndex)specs[1].BeginSearch;
findKeys = (FindKeysRange)specs[1].FindKeys;
csvi.firstKey = beginSearch.Index - 1;
csvi.lastKey = beginSearch1.Index - beginSearch.Index + 1;
csvi.step = findKeys.KeyStep;
case 2:
searchIndex = (BeginSearchIndex)specs[0].BeginSearch;
switch (specs[0].FindKeys)
{
case FindKeysRange:
csvi.firstKey = RespCommand.BITOP == cmd ? searchIndex.Index - 2 : searchIndex.Index - 1;
break;
case FindKeysKeyNum:
case FindKeysUnknown:
default:
throw new GarnetException("FindKeysUnknown range");
}

switch (specs[1].FindKeys)
{
case FindKeysRange:
var searchIndex1 = (BeginSearchIndex)specs[1].BeginSearch;
var findRange = (FindKeysRange)specs[1].FindKeys;
csvi.lastKey = findRange.LastKey < 0 ? findRange.LastKey + parseState.count + 1 : findRange.LastKey + searchIndex1.Index - searchIndex.Index + 1;
csvi.step = findRange.KeyStep;
break;
case FindKeysKeyNum:
case FindKeysUnknown:
default:
throw new GarnetException("FindKeysUnknown range");
}

break;
default:
beginSearch = (BeginSearchIndex)specs[0].BeginSearch;
findKeys = (FindKeysRange)specs[0].FindKeys;
csvi.firstKey = beginSearch.Index - 1;
csvi.lastKey = findKeys.LastKey < 0 ? findKeys.LastKey + parseState.count + 1 : findKeys.LastKey - beginSearch.Index + 1;
csvi.step = findKeys.KeyStep;
break;
throw new GarnetException("KeySpecification unknown count");
}

csvi.readOnly = cmd.IsReadOnly();
csvi.sessionAsking = SessionAsking;

Expand Down
2 changes: 1 addition & 1 deletion test/Garnet.test.cluster/ClusterTestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal class ClusterTestContext
public void Setup(Dictionary<string, LogLevel> monitorTests)
{
TestFolder = TestUtils.UnitTestWorkingDir() + "\\";
var logLevel = !string.IsNullOrEmpty(TestContext.CurrentContext.Test.MethodName) && monitorTests.Contains(TestContext.CurrentContext.Test.MethodName) ? LogLevel.Trace : LogLevel.Error;
var logLevel = !string.IsNullOrEmpty(TestContext.CurrentContext.Test.MethodName) && monitorTests.ContainsKey(TestContext.CurrentContext.Test.MethodName) ? LogLevel.Trace : LogLevel.Error;
loggerFactory = TestUtils.CreateLoggerFactoryInstance(logTextWriter, logLevel, scope: TestContext.CurrentContext.Test.Name);
logger = loggerFactory.CreateLogger(TestContext.CurrentContext.Test.Name);
logger.LogDebug("0. Setup >>>>>>>>>>>>");
Expand Down

0 comments on commit 5d81a85

Please sign in to comment.