Skip to content

Commit

Permalink
ensure noResponse for slot verification of cluster commands
Browse files Browse the repository at this point in the history
  • Loading branch information
vazois committed Jan 17, 2025
1 parent 7e31ae7 commit 74325aa
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libs/cluster/Session/ClusterSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void ProcessClusterCommands(RespCommand command, ref SessionParseState pa
{
csvi.keyNumOffset = -1;
clusterProvider.ExtractKeySpecs(commandInfo, command, ref parseState, ref csvi);
if (NetworkMultiKeySlotVerify(ref parseState, ref csvi, ref this.dcurr, ref this.dend))
if (NetworkMultiKeySlotVerifyNoResponse(ref parseState, ref csvi, ref this.dcurr, ref this.dend))
return;
}

Expand Down
27 changes: 27 additions & 0 deletions libs/cluster/Session/SlotVerification/RespClusterSlotVerify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ public bool NetworkKeyArraySlotVerify(Span<ArgSlice> keys, bool readOnly, byte s
return true;
}

/// <summary>
/// Verify multi-key slot ownership
/// </summary>
/// <param name="parseState"></param>
/// <param name="csvi"></param>
/// <param name="dcurr"></param>
/// <param name="dend"></param>
/// <returns></returns>
public unsafe bool NetworkMultiKeySlotVerify(ref SessionParseState parseState, ref ClusterSlotVerificationInput csvi, ref byte* dcurr, ref byte* dend)
{
// If cluster is not enabled or a transaction is running skip slot check
Expand All @@ -124,5 +132,24 @@ public unsafe bool NetworkMultiKeySlotVerify(ref SessionParseState parseState, r
WriteClusterSlotVerificationMessage(config, vres, ref dcurr, ref dend);
return true;
}

/// <summary>
/// Verify multi-key slot ownership without generating a response
/// </summary>
/// <param name="parseState"></param>
/// <param name="csvi"></param>
/// <param name="dcurr"></param>
/// <param name="dend"></param>
/// <returns></returns>
public unsafe bool NetworkMultiKeySlotVerifyNoResponse(ref SessionParseState parseState, ref ClusterSlotVerificationInput csvi, ref byte* dcurr, ref byte* dend)
{
// If cluster is not enabled or a transaction is running skip slot check
if (!clusterProvider.serverOptions.EnableCluster || txnManager.state == TxnState.Running) return false;

var config = clusterProvider.clusterManager.CurrentConfig;
var vres = MultiKeySlotVerify(config, ref parseState, ref csvi);

return vres.state == SlotVerifiedState.OK ? false : true;
}
}
}
10 changes: 10 additions & 0 deletions libs/server/Cluster/IClusterSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ public interface IClusterSession
/// <returns></returns>
unsafe bool NetworkMultiKeySlotVerify(ref SessionParseState parseState, ref ClusterSlotVerificationInput csvi, ref byte* dcurr, ref byte* dend);

/// <summary>
/// Array slot verify with no response
/// </summary>
/// <param name="parseState"></param>
/// <param name="csvi"></param>
/// <param name="dcurr"></param>
/// <param name="dend"></param>
/// <returns></returns>
unsafe bool NetworkMultiKeySlotVerifyNoResponse(ref SessionParseState parseState, ref ClusterSlotVerificationInput csvi, ref byte* dcurr, ref byte* dend);

/// <summary>
/// Sets the user currently authenticated in this session (used for permission checks)
/// </summary>
Expand Down

0 comments on commit 74325aa

Please sign in to comment.