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

  • 相关阅读:
    UESTC_王之迷宫 2015 UESTC Training for Search Algorithm & String<Problem A>
    UESTC_The Most Wonderful Competition CDOJ 56
    UESTC_神秘绑架案 CDOJ 881
    MFC 自定义消息的一般过程
    MFC 如何添加自定义消息
    MFC子窗口向父窗口发送消息
    MFC子窗口和父窗口
    单链表
    C++ STL基本容器的使用
    C++ Primer 3rd 读书笔记
  • 原文地址:https://www.cnblogs.com/zhangwanhua/p/8472303.html
Copyright © 2011-2022 走看看