redis slave请求master进行数据同步

1、slave启动后,在serverCron函数中,定时发起数据同步请求。

日志:

54489:S 16 Feb 2020 11:50:12.863 * MASTER <-> REPLICA sync started
54489:S 16 Feb 2020 11:50:12.863 * Non blocking connect for SYNC fired the event.
54489:S 16 Feb 2020 11:50:12.864 * Master replied to PING, replication can continue...
54489:S 16 Feb 2020 11:50:12.864 * Partial resynchronization not possible (no cached master)
54489:S 16 Feb 2020 11:50:12.865 * Full resync from master: 0e7213f468885be33d7e0d732f81dbcaa0661006:0
54489:S 16 Feb 2020 11:50:12.920 * MASTER <-> REPLICA sync: receiving 191 bytes from master
54489:S 16 Feb 2020 11:50:12.921 * MASTER <-> REPLICA sync: Flushing old data
54489:S 16 Feb 2020 11:50:12.921 * MASTER <-> REPLICA sync: Loading DB in memory
54489:S 16 Feb 2020 11:50:12.923 * MASTER <-> REPLICA sync: Finished with success

流程:

replicationCron

    connectWithMaster

         syncWithMaster

                  slaveTryPartialResynchronization

                   slave发送PSYNC命令给master,请求内容同步

 

2、服务端收到数据同步请求

接收日志:

54131:M 16 Feb 2020 11:50:12.865 * Replica 192.168.27.128:6479 asks for synchronization
54131:M 16 Feb 2020 11:50:12.865 * Full resync requested by replica 192.168.27.128:6479
54131:M 16 Feb 2020 11:50:12.865 * Starting BGSAVE for SYNC with target: disk
54131:M 16 Feb 2020 11:50:12.865 * Background saving started by pid 54497
54497:C 16 Feb 2020 11:50:12.873 * DB saved on disk
54497:C 16 Feb 2020 11:50:12.874 * RDB: 0 MB of memory used by copy-on-write
54131:M 16 Feb 2020 11:50:12.919 * Background saving terminated with success
54131:M 16 Feb 2020 11:50:12.920 * Synchronization with replica 192.168.27.128:6479 succeeded
 

流程:

接收psync命令

syncCommand

      masterTryPartialResynchronization

      startBgsaveForReplication

          rdbSaveBackground,rdb更新病保存到本地磁盘xxx.rdb

 

serverCron      

       backgroundSaveDoneHandlerDisk

            updateSlavesWaitingBgsave

                 sendBulkToSlave,,从master的rdb文件,读内容,组装起来,发给slave

你可能感兴趣的:(redis slave请求master进行数据同步)