zookeeper源码解析(十二)

本文深入探讨Zookeeper中的DataTree数据结构,详细解析了如cachedApproximateDataSize、isSpecialPath、copyStatPersisted、copyStat、updateCountBytes、createNode和deleteNode等关键函数的实现和作用,帮助理解Zookeeper内部的数据管理和操作机制。
摘要由CSDN通过智能技术生成

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值