Add BLOCKED_ASYNC blocking type and orchestrate cluster protocol dispatchers#3536
Add BLOCKED_ASYNC blocking type and orchestrate cluster protocol dispatchers#3536zuiderkwast wants to merge 2 commits intovalkey-io:cluster-v2from
Conversation
Add a new blocking type for async operations (e.g. Raft commit). When a client is blocked with BLOCKED_ASYNC, the operation handle is owned by the caller. On disconnect or timeout, no special cleanup is needed — the handle will be consumed later and the client lookup will return NULL. Add blockedAsyncCreate/blockedAsyncConsume API in blocked.c. An async handle (opaque blockedAsyncHandle struct) wraps a client ID so that a completion callback can safely look up the client even if it disconnected while waiting. Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Block the client using blockClientAsync before calling vtable callbacks that may complete asynchronously: slotChange (ADDSLOTS, DELSLOTS, ADDSLOTSRANGE, DELSLOTSRANGE, FLUSHSLOTS, SETSLOT NODE), meet, setReplicaOf, forgetNode, and failover. The completion callbacks use consumeBlockedClientAsyncHandle and unblockClientAsync. This allows protocol implementations (e.g. Raft) to defer the reply until the operation is committed, while the legacy gossip implementation completes synchronously inside call(). Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## cluster-v2 #3536 +/- ##
==============================================
+ Coverage 76.59% 76.61% +0.01%
==============================================
Files 160 160
Lines 79288 79370 +82
==============================================
+ Hits 60733 60807 +74
- Misses 18555 18563 +8
🚀 New features to boost your workflow:
|
|
One downside of making commands like CLUSTER ADDSLOTS blocking is that they can't be used in MULTI-EXEC. We don't have to mark these commands with NO_MULTI if we just fail them if instead detect that we're in multi and fail explicitly in The alternative is to keep CLUSTER MEET, CLUSTER ADDSLOTS and similar non-blocking like in legacy, returning OK immediately. Test framework's |
Add a new blocking type for async operations. During a command execution, the client can be blocked and later unblocked, either during the same command execution (synchronously) or unblocked later (asynchronously).
Functions added in blocked.c API:
This allows cluster protocol implementations (e.g. Raft cluster) to defer the reply until the operation is committed, while the legacy gossip implementation completes synchronously. The cluster implementation itself doens't need to bother with the blocking. It just calls the completion callbacks whenever it likes.
Cluster bus type callbacks orchestrated with the blocking: slotChange (ADDSLOTS, DELSLOTS, ADDSLOTSRANGE, DELSLOTSRANGE, FLUSHSLOTS, SETSLOT NODE), meet, setReplicaOf, forgetNode, and failover.
Tests for the blocking mechanism itself are added using a new DEBUG command variant: