Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] master_repl_offset increased without write operations #11956

Open
polaris-alioth opened this issue Mar 23, 2023 · 3 comments
Open

Comments

@polaris-alioth
Copy link
Contributor

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);
        }
@sundb
Copy link
Collaborator

sundb commented Mar 23, 2023

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

@polaris-alioth
Copy link
Contributor Author

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?

@sundb
Copy link
Collaborator

sundb commented Mar 24, 2023

@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;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants