Skip to content

Commit

Permalink
fix edge cases for centralized slot verification
Browse files Browse the repository at this point in the history
  • Loading branch information
vazois committed Jul 8, 2024
1 parent 66e1790 commit b144d93
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
12 changes: 11 additions & 1 deletion libs/server/Resp/Parser/RespCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,17 @@ public static bool IsReadOnly(this RespCommand cmd)
=> cmd <= LastReadCommand();

public static bool IsDataCommand(this RespCommand cmd)
=> cmd >= FirstReadCommand() && cmd <= LastWriteCommand();
{
return cmd switch
{
// TODO: validate if these cases need to be excluded
RespCommand.MIGRATE => false,
RespCommand.DBSIZE => false,
RespCommand.MEMORY_USAGE => false,
RespCommand.FLUSHDB => false,
_ => cmd >= FirstReadCommand() && cmd <= LastWriteCommand()
};
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsWriteOnly(this RespCommand cmd)
Expand Down
6 changes: 4 additions & 2 deletions libs/server/Resp/RespServerSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private void ProcessMessages()
}

// Check ACL permissions for the command
if (cmd != RespCommand.INVALID && CanServeSlot(cmd) && CheckACLPermissions(cmd))
if (cmd != RespCommand.INVALID && CheckACLPermissions(cmd))
{
if (txnManager.state != TxnState.None)
{
Expand All @@ -370,7 +370,9 @@ private void ProcessMessages()
}
else
{
_ = ProcessBasicCommands(cmd, ref basicGarnetApi);
// Check if can serve slot for provided keys
if (CanServeSlot(cmd))
_ = ProcessBasicCommands(cmd, ref basicGarnetApi);
}
}

Expand Down
7 changes: 1 addition & 6 deletions libs/server/Resp/RespServerSessionSlotVerify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,8 @@ bool CanServeSlot(RespCommand cmd)
if (clusterSession == null)
return true;

// If this is a UNKNOWN command let process message generate the appropriate response
if (cmd == RespCommand.NONE)
return true;

// Verify slot for command if it falls into data command category
// TODO: Skip validation of MIGRATE until refactoring of parsing is complete.
if (!cmd.IsDataCommand() || cmd == RespCommand.MIGRATE)
if (!cmd.IsDataCommand())
return true;

cmd = cmd.NormalizeForACLs();
Expand Down

0 comments on commit b144d93

Please sign in to comment.