When run info replication on slave, we can get the current slave reply offset slave_repl_offset and the master current offset master_repl_offset:

127.0.0.1:6379> info replication
# Replication
role:slave
master_host:127.0.0.1
master_port:6379
master_link_status:up
master_last_io_seconds_ago:0
master_sync_in_progress:0
slave_repl_offset:17087984877958
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:e1331156aaafe4cee48fe51af35cff88f8d383e7
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:17087984877958
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:17087983829383
repl_backlog_histlen:1048576

I review the redis source code, and can't find where the slave update master_repl_offset value. I think this value maybe calculated by the offset sent by PSYN add the backlog data len when it reconnect to master, but i can't prove it, can anyone help me figure it out? Thanks!

Comment From: ShooterIT

not sure what's your redis version, but generally, replicas update master_repl_offset when it received and processed the replication stream from master. for code, you can read commandProcessed->replicationFeedStreamFromMasterStream->feedReplicationBuffer

Comment From: woodliu

@ShooterIT Thanks, much helpful. Here is my understanding(Ignore full sync): Master: propagateNow->replicationFeedSlaves write command to backlog Slave: will fetch and process the command from master backlog every 1 second(replicationCron)

Am i right?

Comment From: ShooterIT

No, send replication buffer to replicas by client output buffer instead of backlog. replicas received the replication buffer from master and then process it instead of fetching every 1 second, you may should read some blogs first about redis replication

Comment From: woodliu

No, send replication buffer to replicas by client output buffer instead of backlog. replicas received the replication buffer from master and then process it instead of fetching every 1 second, you may should read some blogs first about redis replication

@ShooterIT Thank you for replying! I have gotten that point