MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / waitCommand

Function waitCommand

src/replication.cpp:4652–4686  ·  view source on GitHub ↗

WAIT for N replicas to acknowledge the processing of our latest * write command (and all the previous commands). */

Source from the content-addressed store, hash-verified

4650/* WAIT for N replicas to acknowledge the processing of our latest
4651 * write command (and all the previous commands). */
4652void waitCommand(client *c) {
4653 mstime_t timeout;
4654 long numreplicas, ackreplicas;
4655 long long offset = c->woff;
4656
4657 if (listLength(g_pserver->masters) && !g_pserver->fActiveReplica) {
4658 addReplyError(c,"WAIT cannot be used with replica instances. Please also note that since Redis 4.0 if a replica is configured to be writable (which is not the default) writes to replicas are just local and are not propagated.");
4659 return;
4660 }
4661
4662 /* Argument parsing. */
4663 if (getLongFromObjectOrReply(c,c->argv[1],&numreplicas,NULL) != C_OK)
4664 return;
4665 if (getTimeoutFromObjectOrReply(c,c->argv[2],&timeout,UNIT_MILLISECONDS)
4666 != C_OK) return;
4667
4668 /* First try without blocking at all. */
4669 ackreplicas = replicationCountAcksByOffset(c->woff);
4670 if (ackreplicas >= numreplicas || c->flags & CLIENT_MULTI) {
4671 addReplyLongLong(c,ackreplicas);
4672 return;
4673 }
4674
4675 /* Otherwise block the client and put it into our list of clients
4676 * waiting for ack from slaves. */
4677 c->bpop.timeout = timeout;
4678 c->bpop.reploffset = offset;
4679 c->bpop.numreplicas = numreplicas;
4680 listAddNodeHead(g_pserver->clients_waiting_acks,c);
4681 blockClient(c,BLOCKED_WAIT);
4682
4683 /* Make sure that the server will send an ACK request to all the slaves
4684 * before returning to the event loop. */
4685 replicationRequestAckFromSlaves();
4686}
4687
4688/* This is called by unblockClient() to perform the blocking op type
4689 * specific cleanup. We just remove the client from the list of clients

Callers

nothing calls this directly

Calls 8

addReplyErrorFunction · 0.85
getLongFromObjectOrReplyFunction · 0.85
addReplyLongLongFunction · 0.85
listAddNodeHeadFunction · 0.85
blockClientFunction · 0.85

Tested by

no test coverage detected