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