zoukankan      html  css  js  c++  java
  • zookeeper源码之服务端数据库管理中心

      负责管理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源码之服务端持久化管理

  • 相关阅读:
    node异步转同步(循环)
    三级省市区PCASClass.js插件
    微信公众号基础总结(待更新)
    ES6详解
    webpack配置
    高性能 CSS3 动画
    github上传口令
    纯css3 实现3D轮播图
    优美的js代码,拿去玩~
    关于列举属性用点还是用【】
  • 原文地址:https://www.cnblogs.com/zhangwanhua/p/8472303.html
Copyright © 2011-2022 走看看