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