zk 创建瞬时、顺序节点的原理


命令:

create -s -e /worker/lock xx

 

zk 的实现代码在:PrepRequestProcessor.pRequest2Txn 中

//The number of changes to the children of this znode.
int parentCVersion = parentRecord.stat.getCversion();
CreateMode createMode =
	CreateMode.fromFlag(createRequest.getFlags());
if (createMode.isSequential()) {
	path = path + String.format(Locale.ENGLISH, "%010d", parentCVersion);
}

根据 parenetCVersion 生成 序号,注意不是上图中的 cversion。

上图中的 cversion 是 Stat 中的属性,而这里的 cversion 是 StatPersisted 中的属性,持久化到磁盘中的属性。

public class DataNode implements Record {
    // 省略其他代码
    /**
     * the stat for this node that is persisted to disk.
     */
    public StatPersisted stat;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM