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. */
| 1991 | * 2. In the case of master clients, the replication offset is updated. |
| 1992 | * 3. Propagate commands we got from our master to replicas down the line. */ |
| 1993 | void commandProcessed(client *c) { |
| 1994 | /* If client is blocked(including paused), just return avoid reset and replicate. |
| 1995 | * |
| 1996 | * 1. Don't reset the client structure for blocked clients, so that the reply |
| 1997 | * callback will still be able to access the client argv and argc fields. |
| 1998 | * The client will be reset in unblockClient(). |
| 1999 | * 2. Don't update replication offset or propagate commands to replicas, |
| 2000 | * since we have not applied the command. */ |
| 2001 | if (c->flags & CLIENT_BLOCKED) return; |
| 2002 | |
| 2003 | resetClient(c); |
| 2004 | |
| 2005 | long long prev_offset = c->reploff; |
| 2006 | if (c->flags & CLIENT_MASTER && !(c->flags & CLIENT_MULTI)) { |
| 2007 | /* Update the applied replication offset of our master. */ |
| 2008 | c->reploff = c->read_reploff - sdslen(c->querybuf) + c->qb_pos; |
| 2009 | } |
| 2010 | |
| 2011 | /* If the client is a master we need to compute the difference |
| 2012 | * between the applied offset before and after processing the buffer, |
| 2013 | * to understand how much of the replication stream was actually |
| 2014 | * applied to the master state: this quantity, and its corresponding |
| 2015 | * part of the replication stream, will be propagated to the |
| 2016 | * sub-replicas and to the replication backlog. */ |
| 2017 | if (c->flags & CLIENT_MASTER) { |
| 2018 | long long applied = c->reploff - prev_offset; |
| 2019 | if (applied) { |
| 2020 | replicationFeedSlavesFromMasterStream(server.slaves, |
| 2021 | c->pending_querybuf, applied); |
| 2022 | sdsrange(c->pending_querybuf,applied,-1); |
| 2023 | } |
| 2024 | } |
| 2025 | } |
| 2026 | |
| 2027 | /* This function calls processCommand(), but also performs a few sub tasks |
| 2028 | * for the client that are useful in that context: |
no test coverage detected