In master-slave replication(1 master,1 slave), i find that master_repl_offset increases by 14 every 10 seconds(I did not do any write operations). e.g.

127.0.0.1:9091> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=127.0.0.1,port=9092,state=online,offset=28,lag=0
master_failover_state:no-failover
master_replid:bc3c679709bc361f8d188499a717863cb3f08ef3
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:28
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:28
127.0.0.1:9091> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=127.0.0.1,port=9092,state=online,offset=42,lag=0
master_failover_state:no-failover
master_replid:bc3c679709bc361f8d188499a717863cb3f08ef3
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:42
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:42
127.0.0.1:9091> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=127.0.0.1,port=9092,state=online,offset=42,lag=1
master_failover_state:no-failover
master_replid:bc3c679709bc361f8d188499a717863cb3f08ef3
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:56
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:56

scaned the coed, i find that master_repl_offset increases by ping. without write operations,master_repl_offset is increased. i'm wondering if this is a mechanism or a bug?

if (!manual_failover_in_progress) {
            ping_argv[0] = shared.ping;
            replicationFeedSlaves(server.slaves, -1,
                ping_argv, 1);
        }

Comment From: sundb

It's a mechanism that the master periodically sends PING to the replications to ensure the connection between them.

Comment From: polaris-alioth

sorry,i don't know much about this. i know that PING to the replications to ensure the connection between them,but i don't understand why ping needs to cause the increase of master_repl_offset. Shouldn't only the write operation cause the increase of master_repl_offset?

Comment From: sundb

@polaris-alioth If we don't increase master_repl_offset that will cause master and repl to be out of sync. the code that the replication sync repl offset with master

    long long prev_offset = c->reploff;
    if (c->flags & CLIENT_MASTER && !(c->flags & CLIENT_MULTI)) {
        /* Update the applied replication offset of our master. */
        c->reploff = c->read_reploff - sdslen(c->querybuf) + c->qb_pos;
    }