2021SC@SDUSC
DataTree函数方法
cachedApproximateDataSize:
//返回所有DataNode的路径和数据所占的空间大小
public long cachedApproximateDataSize() {
return nodeDataSize.get();
}
isSpecialPath:
//判断是否是特殊路径(/,/zookeeper,/zookeeper/config,/zookeeper/quota)
boolean isSpecialPath(String path) {
return rootZookeeper.equals(path)
|| procZookeeper.equals(path)
|| quotaZookeeper.equals(path)
|| configZookeeper.equals(path);
}
copyStatPersisted,copyStat:
//一个静态的工具方法,使得to存储的实例变量与from存储的实例变量完全一致
//即实现StatPersisted类型的拷贝
public static void copyStatPersisted(StatPersisted from, StatPersisted to) {
to.setAversion(from.getAversion());
to.setCtime(from.getCtime());
to.setCversion(from.getCversion());
to.setCzxid(from.getCzxid());
to.setMtime(from.getMtime());
to.setMzxid(from.getMzxid());
to.setPzxid(from.getPzxid());
to.setVersion(from.getVersion());
to.setEphemeralOwner(from.getEphemeralOwner());
}
//同上,是一个静态的工具方法,使得to存储的实例变量与from存储的实例变量完全一致
//即实现Stat类型的拷贝
public static void copyStat(Stat from, Stat to) {
to.setAversion(from.getAversion());
to.setCtime(from.getCtime());
to.setCversion(from.getCversion());
to.setCzxid(from.getCzxid());
to.setMtime(from.getMtime());
to.setMzxid(from.getMzxid());
to.setPzxid(from.getPzxid());
to.setVersion(from.getVersion());
to.setEphemeralOwner(from.getEphemeralOwner());
to.setDataLength(from.getDataLength());
to.setNumChildren(from.getNumChildren());
}
updateCountBytes:
public void updateCountBytes(String lastPrefix, long bytesDiff, int countDiff) {
//获取对应的Stat节点路径,通过路径由哈希表获取节点对象
String statNode = Quotas.statPath(lastPrefix);
DataNode node = nodes.get(statNode);
StatsTrack updatedStat = null;
if (node == null) {
//Stat节点不存在,报错
LOG.error("Missing count node for stat {}", statNode