summaryrefslogtreecommitdiff
path: root/src/blocked.c
diff options
context:
space:
mode:
authorzhaozhao.zz <276441700@qq.com>2021-09-08 16:07:25 +0800
committerGitHub <noreply@github.com>2021-09-08 16:07:25 +0800
commit1b83353dc382959e218191f64d94edb9703552e3 (patch)
tree65c87fd59e43f7d24769d1e7e2f7bd1104246943 /src/blocked.c
parent74d9a35621d66a816e1c30de9cd84c461297495a (diff)
downloadredis-1b83353dc382959e218191f64d94edb9703552e3.tar.gz
Fix wrong offset when replica pause (#9448)
When a replica paused, it would not apply any commands event the command comes from master, if we feed the non-applied command to replication stream, the replication offset would be wrong, and data would be lost after failover(since replica's `master_repl_offset` grows but command is not applied). To fix it, here are the changes: * Don't update replica's replication offset or propagate commands to sub-replicas when it's paused in `commandProcessed`. * Show `slave_read_repl_offset` in info reply. * Add an assert to make sure master client should never be blocked unless pause or module (some modules may use block way to do background (parallel) processing and forward original block module command to the replica, it's not a good way but it can work, so the assert excludes module now, but someday in future all modules should rewrite block command to propagate like what `BLPOP` does).
Diffstat (limited to 'src/blocked.c')
-rw-r--r--src/blocked.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/blocked.c b/src/blocked.c
index ba47796b6..6ce4b9893 100644
--- a/src/blocked.c
+++ b/src/blocked.c
@@ -87,6 +87,11 @@ typedef struct bkinfo {
* flag is set client query buffer is not longer processed, but accumulated,
* and will be processed when the client is unblocked. */
void blockClient(client *c, int btype) {
+ /* Master client should never be blocked unless pause or module */
+ serverAssert(!(c->flags & CLIENT_MASTER &&
+ btype != BLOCKED_MODULE &&
+ btype != BLOCKED_PAUSE));
+
c->flags |= CLIENT_BLOCKED;
c->btype = btype;
server.blocked_clients++;