Perform necessary tasks after a command was executed: * * 1. The client is reset unless there are reasons to avoid doing it. * 2. In the case of master clients, the replication offset is updated. * 3. Propagate commands we got from our master to replicas down the line. */
| 2463 | * 2. In the case of master clients, the replication offset is updated. |
| 2464 | * 3. Propagate commands we got from our master to replicas down the line. */ |
| 2465 | void commandProcessed(client *c, int flags) { |
| 2466 | /* If client is blocked(including paused), just return avoid reset and replicate. |
| 2467 | * |
| 2468 | * 1. Don't reset the client structure for blocked clients, so that the reply |
| 2469 | * callback will still be able to access the client argv and argc fields. |
| 2470 | * The client will be reset in unblockClient(). |
| 2471 | * 2. Don't update replication offset or propagate commands to replicas, |
| 2472 | * since we have not applied the command. */ |
| 2473 | if (c->flags & CLIENT_BLOCKED) return; |
| 2474 | |
| 2475 | resetClient(c); |
| 2476 | |
| 2477 | long long prev_offset = c->reploff; |
| 2478 | if (c->flags & CLIENT_MASTER && !(c->flags & CLIENT_MULTI)) { |
| 2479 | /* Update the applied replication offset of our master. */ |
| 2480 | serverAssert(c->reploff <= c->reploff_cmd); |
| 2481 | c->reploff = c->reploff_cmd; |
| 2482 | } |
| 2483 | |
| 2484 | /* If the client is a master we need to compute the difference |
| 2485 | * between the applied offset before and after processing the buffer, |
| 2486 | * to understand how much of the replication stream was actually |
| 2487 | * applied to the master state: this quantity, and its corresponding |
| 2488 | * part of the replication stream, will be propagated to the |
| 2489 | * sub-replicas and to the replication backlog. */ |
| 2490 | if (c->flags & CLIENT_MASTER) { |
| 2491 | AeLocker ae; |
| 2492 | ae.arm(c); |
| 2493 | long long applied = c->reploff - prev_offset; |
| 2494 | if (applied) { |
| 2495 | if (!g_pserver->fActiveReplica && (flags & CMD_CALL_PROPAGATE)) |
| 2496 | { |
| 2497 | replicationFeedSlavesFromMasterStream(c->pending_querybuf, applied); |
| 2498 | } |
| 2499 | sdsrange(c->pending_querybuf,applied,-1); |
| 2500 | } |
| 2501 | } |
| 2502 | } |
| 2503 | |
| 2504 | /* This function calls processCommand(), but also performs a few sub tasks |
| 2505 | * for the client that are useful in that context: |
no test coverage detected