redis 4 增量同步的日志详解
1、1主 2从 环境下,关闭原先的master节点
2、在新的master上执行 slaveof no one
看到的日志:
6855:M 02 Sep 15:43:16.871 # Setting secondary replication ID to 2ba403b0a69dcacbfe92650ac8758ae236693d5c, valid up to offset: 4802. New replication ID is 5f01e7a777abda968d9765145d5bc09146226615
6855:M 02 Sep 15:43:16.871 * Discarding previously cached master state.
6855:M 02 Sep 15:43:16.871 * MASTER MODE enabled (user request from 'id=3 addr=127.0.0.1:59204 fd=8 name= age=3041 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=slaveof')
6855:M 02 Sep 15:43:33.820 * 1 changes in 900 seconds. Saving...
6855:M 02 Sep 15:43:33.840 * Background saving started by pid 6929
6929:C 02 Sep 15:43:33.854 * DB saved on disk
6929:C 02 Sep 15:43:33.855 * RDB: 0 MB of memory used by copy-on-write
6855:M 02 Sep 15:43:33.941 * Background saving terminated with success
###日志解说:
2ba403b0a69dcacbfe92650ac8758ae236693d5c 这个是 宕机的原先master的runid
5f01e7a777abda968d9765145d5bc09146226615 这个是 新的master的runid
可以看到,新的master 在提升为主的时候,还记录了之前复制到的pos和之前主库的runid
3、然后,新的slave上执行 slaveof 127.0.0.1 6379
看到的日志:
6923:S 02 Sep 15:43:59.751 * SLAVE OF 127.0.0.1:6379 enabled (user request from 'id=3 addr=127.0.0.1:42122 fd=8 name= age=115 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=slaveof')
6923:S 02 Sep 15:44:00.427 * Connecting to MASTER 127.0.0.1:6379
6923:S 02 Sep 15:44:00.427 * MASTER <-> SLAVE sync started
6923:S 02 Sep 15:44:00.427 * Non blocking connect for SYNC fired the event.
6923:S 02 Sep 15:44:00.427 * Master replied to PING, replication can continue...
6923:S 02 Sep 15:44:00.428 * Trying a partial resynchronization (request 2ba403b0a69dcacbfe92650ac8758ae236693d5c:4802). # 可以看到,从库在连接到新的主库时候,会把之前的主库复制的runid和pos发送给新master,尝试增量同步数据
6923:S 02 Sep 15:44:00.429 * Successful partial resynchronization with master.
6923:S 02 Sep 15:44:00.429 # Master replication ID changed to 5f01e7a777abda968d9765145d5bc09146226615
6923:S 02 Sep 15:44:00.429 * MASTER <-> SLAVE sync: Master accepted a Partial Resynchronization.
4、然后,再看下新的master的日志:
6855:M 02 Sep 15:44:00.428 * Slave 127.0.0.1:6381 asks for synchronization
6855:M 02 Sep 15:44:00.428 * Partial resynchronization request from 127.0.0.1:6381 accepted. Sending 128 bytes of backlog starting from offset 4802.
可看到,新master也同意了slave的增量复制的请求。