WAIT
Syntax
WAIT numreplicas timeout
Time complexity: O(1)
ACL categories: @slow, @connection
This command blocks the current client until all previous write commands are
acknowledged by at least numreplicas replicas, or until timeout
(in milliseconds) is reached.
It returns the number of replicas that acknowledged the writes. If the
requested number of replicas acknowledged before the timeout, the command
returns as soon as that happens; otherwise, it returns when the timeout
expires. In either case, the returned count may be lower than numreplicas.
WAIT can only be issued on a master instance. When called on a replica, it
returns an error.
Note that WAIT does not make Dragonfly a strongly consistent store: acknowledged
writes can still be lost during a failover, depending on which replica is promoted.
However, it greatly reduces the window of data loss.
Dragonfly-specific behavior
Dragonfly's WAIT differs from Redis in a few ways:
- Stronger acknowledgment guarantee. Redis only waits for the writes
issued on the calling connection. Dragonfly waits for all writes
performed on the instance up to the moment
WAITis called, from any connection. This is a strictly stronger guarantee. - A timeout of
0is bounded. In Redis,timeout = 0blocks forever. In Dragonfly, it is capped at 10 minutes, after which the command returns the current acknowledgment count. - Early return on role or state changes.
WAITreturns the current count early if the instance starts shutting down or a takeover begins, and returns an error if the instance becomes a replica while waiting (for example, due to a concurrentREPLICAOF). - Fixed replica set. The set of replicas is snapshotted when
WAITis invoked. If fewer connected replicas remain thannumreplicasand all of them have already acknowledged, the command returns immediately instead of waiting out the timeout.
As in Redis, when WAIT is called inside a MULTI/EXEC transaction it does
not block, and instead returns the number of replicas that have already
acknowledged all prior writes.
Return
Integer reply: the number of
replicas that acknowledged all write commands issued before the WAIT call.
Examples
dragonfly> SET foo bar
OK
dragonfly> WAIT 1 100
(integer) 1
dragonfly> WAIT 5 100
(integer) 1
In the example above, the instance has a single replica. The first WAIT
returns as soon as that replica acknowledges the write. The second call asks
for five replicas; since only one exists, it returns 1 immediately.