Java Code Examples for org.apache.hadoop.hbase.zookeeper.ZKUtil#getDataAndWatch()

The following examples show how to use org.apache.hadoop.hbase.zookeeper.ZKUtil#getDataAndWatch() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZKVisibilityLabelWatcher.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void nodeDataChanged(String path) {
  if (path.equals(labelZnode) || path.equals(userAuthsZnode)) {
    try {
      watcher.syncOrTimeout(path);
      byte[] data = ZKUtil.getDataAndWatch(watcher, path);
      if (path.equals(labelZnode)) {
        refreshVisibilityLabelsCache(data);
      } else {
        refreshUserAuthsCache(data);
      }
    } catch (KeeperException ke) {
      LOG.error("Error reading data from zookeeper for node " + path, ke);
      // only option is to abort
      watcher.abort("ZooKeeper error getting data for node " + path, ke);
    }
  }
}
 
Example 2
Source File: ZKSecretWatcher.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void nodeDataChanged(String path) {
  if (keysParentZNode.equals(ZKUtil.getParent(path))) {
    try {
      byte[] data = ZKUtil.getDataAndWatch(watcher, path);
      if (data == null || data.length == 0) {
        LOG.debug("Ignoring empty node "+path);
        return;
      }

      AuthenticationKey key = (AuthenticationKey)Writables.getWritable(data,
          new AuthenticationKey());
      secretManager.addKey(key);
    } catch (KeeperException ke) {
      LOG.error(HBaseMarkers.FATAL, "Error reading data from zookeeper", ke);
      watcher.abort("Error reading updated key znode "+path, ke);
    } catch (IOException ioe) {
      LOG.error(HBaseMarkers.FATAL, "Error reading key writables", ioe);
      watcher.abort("Error reading key writables from znode "+path, ioe);
    }
  }
}
 
Example 3
Source File: ClientZKSyncer.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void watchAndCheckExists(String node) {
  try {
    if (ZKUtil.watchAndCheckExists(watcher, node)) {
      byte[] data = ZKUtil.getDataAndWatch(watcher, node);
      if (data != null) {
        // put the data into queue
        upsertQueue(node, data);
      } else {
        // It existed but now does not, should has been tracked by our watcher, ignore
        LOG.debug("Found no data from " + node);
        watchAndCheckExists(node);
      }
    } else {
      // cleanup stale ZNodes on client ZK to avoid invalid requests to server
      ZKUtil.deleteNodeFailSilent(clientZkWatcher, node);
    }
  } catch (KeeperException e) {
    server.abort("Unexpected exception during initialization, aborting", e);
  }
}
 
Example 4
Source File: ZKVisibilityLabelWatcher.java    From hbase with Apache License 2.0 5 votes vote down vote up
public void start() throws KeeperException {
  watcher.registerListener(this);
  ZKUtil.createWithParents(watcher, labelZnode);
  ZKUtil.createWithParents(watcher, userAuthsZnode);
  byte[] data = ZKUtil.getDataAndWatch(watcher, labelZnode);
  if (data != null && data.length > 0) {
    refreshVisibilityLabelsCache(data);
  }
  data = ZKUtil.getDataAndWatch(watcher, userAuthsZnode);
  if (data != null && data.length > 0) {
    refreshUserAuthsCache(data);
  }
}
 
Example 5
Source File: ClientZKSyncer.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void nodeCreated(String path) {
  if (!validate(path)) {
    return;
  }
  try {
    byte[] data = ZKUtil.getDataAndWatch(watcher, path);
    upsertQueue(path, data);
  } catch (KeeperException e) {
    LOG.warn("Unexpected exception handling nodeCreated event", e);
  }
}
 
Example 6
Source File: MetaRegionLocationCache.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the HRegionLocation for a given meta replica ID. Renews the watch on the znode for
 * future updates.
 * @param replicaId ReplicaID of the region.
 * @return HRegionLocation for the meta replica.
 * @throws KeeperException if there is any issue fetching/parsing the serialized data.
 */
private HRegionLocation getMetaRegionLocation(int replicaId)
    throws KeeperException {
  RegionState metaRegionState;
  try {
    byte[] data = ZKUtil.getDataAndWatch(watcher,
        watcher.getZNodePaths().getZNodeForReplica(replicaId));
    metaRegionState = ProtobufUtil.parseMetaRegionStateFrom(data, replicaId);
  } catch (DeserializationException e) {
    throw ZKUtil.convert(e);
  }
  return new HRegionLocation(metaRegionState.getRegion(), metaRegionState.getServerName());
}