命令:
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; }