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

The following examples show how to use org.apache.hadoop.hbase.zookeeper.ZKUtil#createSetData() . 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: ZKReplicationPeerStorage.java    From hbase with Apache License 2.0 6 votes vote down vote up
private SyncReplicationState getSyncReplicationState(String peerId, String path)
    throws ReplicationException {
  try {
    byte[] data = ZKUtil.getData(zookeeper, path);
    if (data == null || data.length == 0) {
      if (ZKUtil.checkExists(zookeeper, getPeerNode(peerId)) != -1) {
        // should be a peer from previous version, set the sync replication state for it.
        ZKUtil.createSetData(zookeeper, path, NONE_STATE_ZNODE_BYTES);
        return SyncReplicationState.NONE;
      } else {
        throw new ReplicationException(
          "Replication peer sync state shouldn't be empty, peerId=" + peerId);
      }
    }
    return SyncReplicationState.parseFrom(data);
  } catch (KeeperException | InterruptedException | IOException e) {
    throw new ReplicationException(
      "Error getting sync replication state of path " + path + " for peer with id=" + peerId, e);
  }
}
 
Example 2
Source File: ZKSecretWatcher.java    From hbase with Apache License 2.0 6 votes vote down vote up
public void addKeyToZK(AuthenticationKey key) {
  String keyZNode = getKeyNode(key.getKeyId());
  try {
    byte[] keyData = Writables.getBytes(key);
    // TODO: is there any point in retrying beyond what ZK client does?
    ZKUtil.createSetData(watcher, keyZNode, keyData);
  } catch (KeeperException ke) {
    LOG.error(HBaseMarkers.FATAL, "Unable to synchronize master key "+key.getKeyId()+
        " to znode "+keyZNode, ke);
    watcher.abort("Unable to synchronize secret key "+
        key.getKeyId()+" in zookeeper", ke);
  } catch (IOException ioe) {
    // this can only happen from an error serializing the key
    watcher.abort("Failed serializing key "+key.getKeyId(), ioe);
  }
}
 
Example 3
Source File: ZKSecretWatcher.java    From hbase with Apache License 2.0 6 votes vote down vote up
public void updateKeyInZK(AuthenticationKey key) {
  String keyZNode = getKeyNode(key.getKeyId());
  try {
    byte[] keyData = Writables.getBytes(key);
    try {
      ZKUtil.updateExistingNodeData(watcher, keyZNode, keyData, -1);
    } catch (KeeperException.NoNodeException ne) {
      // node was somehow removed, try adding it back
      ZKUtil.createSetData(watcher, keyZNode, keyData);
    }
  } catch (KeeperException ke) {
    LOG.error(HBaseMarkers.FATAL, "Unable to update master key "+key.getKeyId()+
        " in znode "+keyZNode);
    watcher.abort("Unable to synchronize secret key "+
        key.getKeyId()+" in zookeeper", ke);
  } catch (IOException ioe) {
    // this can only happen from an error serializing the key
    watcher.abort("Failed serializing key "+key.getKeyId(), ioe);
  }
}
 
Example 4
Source File: ZKReplicationPeerStorage.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void setPeerNewSyncReplicationState(String peerId, SyncReplicationState state)
    throws ReplicationException {
  try {
    ZKUtil.createSetData(zookeeper, getNewSyncReplicationStateNode(peerId),
      SyncReplicationState.toByteArray(state));
  } catch (KeeperException e) {
    throw new ReplicationException(
      "Unable to set the new sync replication state for peer with id=" + peerId, e);
  }
}
 
Example 5
Source File: RpcThrottleStorage.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Store the rpc throttle value.
 * @param enable Set to <code>true</code> to enable, <code>false</code> to disable.
 * @throws IOException if an unexpected io exception occurs
 */
public void switchRpcThrottle(boolean enable) throws IOException {
  try {
    byte[] upData = Bytes.toBytes(enable);
    ZKUtil.createSetData(zookeeper, rpcThrottleZNode, upData);
  } catch (KeeperException e) {
    throw new IOException("Failed to store rpc throttle", e);
  }
}
 
Example 6
Source File: HFileArchiveManager.java    From hbase with Apache License 2.0 3 votes vote down vote up
/**
 * Perform a best effort enable of hfile retention, which relies on zookeeper communicating the
 * change back to the hfile cleaner.
 * <p>
 * No attempt is made to make sure that backups are successfully created - it is inherently an
 * <b>asynchronous operation</b>.
 * @param zooKeeper watcher connection to zk cluster
 * @param table table name on which to enable archiving
 * @throws KeeperException if a ZooKeeper operation fails
 */
private void enable(ZKWatcher zooKeeper, byte[] table) throws KeeperException {
  LOG.debug("Ensuring archiving znode exists");
  ZKUtil.createAndFailSilent(zooKeeper, archiveZnode);

  // then add the table to the list of znodes to archive
  String tableNode = this.getTableNode(table);
  LOG.debug("Creating: " + tableNode + ", data: []");
  ZKUtil.createSetData(zooKeeper, tableNode, new byte[0]);
}