zookeeper源码之服务端数据库管理中心

本文介绍了ZooKeeper的数据管理机制,包括树结构管理和持久化管理。ZKDatabase作为核心类,利用DataTree进行树结构操作,并通过FileTxnSnapLog实现数据的持久化和恢复。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  负责管理ZooKeeper整个数据。主要管理树结构数据、session数据、持久化管理。

类图

  

ZKDatabase

  ZooKeeper数据管理门户类,底层通过DataTree来管理树结构,通过FileTxnSnapLog来管理数据持久化。

初始化

  初始化过程主要是从持久化文件中恢复数据,通过FileTxnSnapLog实现。

    public long loadDataBase() throws IOException {
        ...long zxid = snapLog.restore(dataTree,sessionsWithTimeouts,listener);
        initialized = true;
        return zxid;
    }

树结构管理

  树结构管理主要通过DataTree来实现。

...
public byte[] getData(String path, Stat stat, Watcher watcher) 
    throws KeeperException.NoNodeException {
        return dataTree.getData(path, stat, watcher);
    }
    public void setWatches(long relativeZxid, List<String> dataWatches,
            List<String> existWatches, List<String> childWatches, Watcher watcher) {
        dataTree.setWatches(relativeZxid, dataWatches, existWatches, childWatches, watcher);
    }
    public List<ACL> getACL(String path, Stat stat) throws NoNodeException {
        return dataTree.getACL(path, stat);
    }
...

持久化管理

  持久化管理主要通过FileTxnSnapLog和SerializeUtils来实现。

    public boolean append(Request si) throws IOException {
        return this.snapLog.append(si);
    }
    public void rollLog() throws IOException {
        this.snapLog.rollLog();
    }
    public void commit() throws IOException {
        this.snapLog.commit();
    }
    public void close() throws IOException {
        this.snapLog.close();
    } 
    public void deserializeSnapshot(InputArchive ia) throws IOException {
        clear();
        SerializeUtils.deserializeSnapshot(getDataTree(),ia,getSessionWithTimeOuts());
        initialized = true;
    }   
    
    public void serializeSnapshot(OutputArchive oa) throws IOException,
    InterruptedException {
        SerializeUtils.serializeSnapshot(getDataTree(), oa, getSessionWithTimeOuts());
    }

DataTree

  管理树结构数据,详见:zookeeper源码之服务端数据库树结构管理

FileTxnSnapLog

  管理持久化数据,详见: ZooKeeper源码之服务端持久化管理

转载于:https://www.cnblogs.com/zhangwanhua/p/8472303.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值