redis 4 增量同步的日誌詳解
- 2019 年 10 月 5 日
- 筆記
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的增量複製的請求。