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

关于积压空间的创建和写入问题 #29

Open
hzkltt opened this issue Aug 12, 2014 · 1 comment
Open

关于积压空间的创建和写入问题 #29

hzkltt opened this issue Aug 12, 2014 · 1 comment

Comments

@hzkltt
Copy link

hzkltt commented Aug 12, 2014

问题1:server.master_repl_offset为什么要加1, server.repl_backlog_off 为什么是server.master_repl_offset+1????????
void createReplicationBacklog(void) {
redisAssert(server.repl_backlog == NULL);
server.repl_backlog = zmalloc(server.repl_backlog_size);
server.repl_backlog_histlen = 0;
server.repl_backlog_idx = 0;
server.master_repl_offset++;
server.repl_backlog_off = server.master_repl_offset+1;
}

@gqtc
Copy link

gqtc commented Apr 22, 2016

根据注释以及自己的理解,这两条语句的作用是:因为新创建的积压队列为空,因此不能为从节点提供部分重同步功能。

正常的同步过程中,主节点上的server.master_repl_offset和从节点的server.master->reploff是保持一致的,当有新的客户端命令发送给主节点时,server.master_repl_offset会增加命令的长度值,然后主节点将该命令发送给从节点时,从节点的server.master->reploff也增加相应的字节数,从而达到主节点server.master_repl_offset和从节点server.master->reploff的再度一致;

当主从节点之间的连接断掉时,从节点server.master->reploff保持不变,当主节点与所有的从节点断链之后,可能会释放积压队列。

当有之前的从节点重新连接该主节点时,主节点创建积压队列,从节点发来的offset为erver.master->reploff+1,而主节点创建积压队列时,执行下面两条语句:

server.master_repl_offset++;
server.repl_backlog_off = server.master_repl_offset+1;

这样从节点发来的offset一定是小于主节点的server.repl_backlog_off的,因此,主节点就不会为该从节点执行部分重同步功能。

个人理解,欢迎讨论!

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