Package org.apache.helix.store.zk

Examples of org.apache.helix.store.zk.ZNode


    try {
      Stat stat = new Stat();
      ZNRecord record = zkAccessor.get(path, stat, 0);
      List<String> childNames = zkAccessor.getChildNames(path, 0);
      // System.out.println("childNames: " + childNames);
      ZNode node = new ZNode(path, record, stat);
      node.addChildren(childNames);
      map.put(path, node);

      if (childNames != null && !childNames.isEmpty()) {
        for (String childName : childNames) {
          String childPath = path + "/" + childName;
View Full Code Here


      return false;
    }

    // everything in cache is also in map
    for (String path : cache.keySet()) {
      ZNode cacheNode = cache.get(path);
      ZNode zkNode = zkMap.get(path);

      if (zkNode == null) {
        // in cache but not on zk
        System.err.println("path: " + path + " in cache but not on zk: inCacheNode: " + cacheNode);
        return false;
      }

      if ((zkNode.getData() == null && cacheNode.getData() != null)
          || (zkNode.getData() != null && cacheNode.getData() == null)
          || (zkNode.getData() != null && cacheNode.getData() != null && !zkNode.getData().equals(
              cacheNode.getData()))) {
        // data not equal
        System.err.println("data mismatch on path: " + path + ", inCache: " + cacheNode.getData()
            + ", onZk: " + zkNode.getData());
        return false;
      }

      if ((zkNode.getChildSet() == null && cacheNode.getChildSet() != null)
          || (zkNode.getChildSet() != null && cacheNode.getChildSet() == null)
          || (zkNode.getChildSet() != null && cacheNode.getChildSet() != null && !zkNode
              .getChildSet().equals(cacheNode.getChildSet()))) {
        // childSet not equal
        System.err.println("childSet mismatch on path: " + path + ", inCache: "
            + cacheNode.getChildSet() + ", onZk: " + zkNode.getChildSet());
        return false;
      }

      if (needVerifyStat && pathsExcludeForStat != null && !pathsExcludeForStat.contains(path)) {
        if (cacheNode.getStat() == null || !zkNode.getStat().equals(cacheNode.getStat())) {
          // stat not equal
          System.err.println("Stat mismatch on path: " + path + ", inCache: " + cacheNode.getStat()
              + ", onZk: " + zkNode.getStat());
          return false;
        }
      }
    }
View Full Code Here

  public void update(String path, T data, Stat stat) {
    String parentPath = HelixUtil.getZkParentPath(path);
    String childName = HelixUtil.getZkName(path);

    addToParentChildSet(parentPath, childName);
    ZNode znode = _cache.get(path);
    if (znode == null) {
      _cache.put(path, new ZNode(path, data, stat));
      fireEvents(path, EventType.NodeCreated);
    } else {
      Stat oldStat = znode.getStat();

      znode.setData(data);
      znode.setStat(stat);
      // System.out.println("\t\t--setData. path: " + path + ", data: " + data);

      if (oldStat.getCzxid() != stat.getCzxid()) {
        fireEvents(path, EventType.NodeDeleted);
        fireEvents(path, EventType.NodeCreated);
View Full Code Here

        // we still need to subscribe child change
      }

      // recursively update children nodes if not exists
      // System.out.println("subcribeChildChange: " + path);
      ZNode znode = _cache.get(path);
      List<String> childNames = _accessor.subscribeChildChanges(path, this);
      if (childNames != null && !childNames.isEmpty()) {
        for (String childName : childNames) {
          if (!znode.hasChild(childName)) {
            String childPath = path + "/" + childName;
            znode.addChild(childName);
            updateRecursive(childPath);
          }
        }
      }
    } finally {
View Full Code Here

      // TODO: optimize it by get stat from callback
      Stat stat = new Stat();
      Object readData = _accessor.get(dataPath, stat, AccessOption.THROW_EXCEPTION_IFNOTEXIST);

      ZNode znode = _cache.get(dataPath);
      if (znode != null) {
        Stat oldStat = znode.getStat();

        // System.out.println("handleDataChange: " + dataPath + ", data: " + data);
        // System.out.println("handleDataChange: " + dataPath + ", oldCzxid: " +
        // oldStat.getCzxid() + ", newCzxid: " + stat.getCzxid()
        // + ", oldVersion: " + oldStat.getVersion() + ", newVersion: " +
        // stat.getVersion());
        znode.setData(readData);
        znode.setStat(stat);

        // if create right after delete, and zkCallback comes after create
        // no DataDelete() will be fired, instead will fire 2 DataChange()
        // see ZkClient.fireDataChangedEvents()
        if (oldStat.getCzxid() != stat.getCzxid()) {
View Full Code Here

    _lock = new ReentrantReadWriteLock();
    _cache = new ConcurrentHashMap<String, ZNode>();
  }

  public void addToParentChildSet(String parentPath, String childName) {
    ZNode znode = _cache.get(parentPath);
    if (znode != null) {
      znode.addChild(childName);
    }
  }
View Full Code Here

    }
  }

  public void addToParentChildSet(String parentPath, List<String> childNames) {
    if (childNames != null && !childNames.isEmpty()) {
      ZNode znode = _cache.get(parentPath);
      if (znode != null) {
        znode.addChildren(childNames);
      }
    }
  }
View Full Code Here

      }
    }
  }

  public void removeFromParentChildSet(String parentPath, String name) {
    ZNode zNode = _cache.get(parentPath);
    if (zNode != null) {
      zNode.removeChild(name);
    }
  }
View Full Code Here

      String parentPath = HelixUtil.getZkParentPath(path);
      String name = HelixUtil.getZkName(path);
      removeFromParentChildSet(parentPath, name);

      ZNode znode = _cache.remove(path);
      if (znode != null) {
        // recursively remove children nodes
        Set<String> childNames = znode.getChildSet();
        for (String childName : childNames) {
          String childPath = path + "/" + childName;
          purgeRecursive(childPath);
        }
      }
View Full Code Here

    String serverPath = prependChroot(clientPath);

    Cache<T> cache = getCache(serverPath);
    if (cache != null) {
      T record = null;
      ZNode znode = cache.get(serverPath);

      if (znode != null) {
        // TODO: shall return a deep copy instead of reference
        record = ((T) znode.getData());
        if (stat != null) {
          DataTree.copyStat(znode.getStat(), stat);
        }
        return record;

      } else {
        // if cache miss, fall back to zk and update cache
View Full Code Here

TOP

Related Classes of org.apache.helix.store.zk.ZNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.