/**
  * @param clusterKey
  * @return Serialized protobuf of <code>clusterKey</code> with pb magic prefix prepended suitable
  *     for use as content of a this.peersZNode; i.e. the content of PEER_ID znode under
  *     /hbase/replication/peers/PEER_ID
  */
 private static byte[] toByteArray(final String clusterKey) {
   byte[] bytes =
       ZooKeeperProtos.ReplicationPeer.newBuilder()
           .setClusterkey(clusterKey)
           .build()
           .toByteArray();
   return ProtobufUtil.prependPBMagic(bytes);
 }
 /** This acts as the ack for a completed procedure */
 @Override
 public void sendMemberCompleted(Subprocedure sub, byte[] data) throws IOException {
   String procName = sub.getName();
   LOG.debug(
       "Marking procedure  '" + procName + "' completed for member '" + memberName + "' in zk");
   String joinPath = ZKUtil.joinZNode(zkController.getReachedBarrierNode(procName), memberName);
   // ProtobufUtil.prependPBMagic does not take care of null
   if (data == null) {
     data = new byte[0];
   }
   try {
     ZKUtil.createAndFailSilent(
         zkController.getWatcher(), joinPath, ProtobufUtil.prependPBMagic(data));
   } catch (KeeperException e) {
     member.controllerConnectionFailure(
         "Failed to post zk node:" + joinPath + " to join procedure barrier.", e, procName);
   }
 }
 /**
  * This should be called by the member and should write a serialized root cause exception as to
  * the abort znode.
  */
 @Override
 public void sendMemberAborted(Subprocedure sub, ForeignException ee) {
   if (sub == null) {
     LOG.error("Failed due to null subprocedure", ee);
     return;
   }
   String procName = sub.getName();
   LOG.debug("Aborting procedure (" + procName + ") in zk");
   String procAbortZNode = zkController.getAbortZNode(procName);
   try {
     String source = (ee.getSource() == null) ? memberName : ee.getSource();
     byte[] errorInfo = ProtobufUtil.prependPBMagic(ForeignException.serialize(source, ee));
     ZKUtil.createAndFailSilent(zkController.getWatcher(), procAbortZNode, errorInfo);
     LOG.debug("Finished creating abort znode:" + procAbortZNode);
   } catch (KeeperException e) {
     // possible that we get this error for the procedure if we already reset the zk state, but in
     // that case we should still get an error for that procedure anyways
     zkController.logZKTree(zkController.getBaseZnode());
     member.controllerConnectionFailure(
         "Failed to post zk node:" + procAbortZNode + " to abort procedure", e, procName);
   }
 }
 /**
  * Sets the location of <code>hbase:meta</code> in ZooKeeper to the specified server address.
  *
  * @param zookeeper
  * @param serverName
  * @param replicaId
  * @param state
  * @throws KeeperException
  */
 public static void setMetaLocation(
     ZooKeeperWatcher zookeeper, ServerName serverName, int replicaId, RegionState.State state)
     throws KeeperException {
   LOG.info("Setting hbase:meta region location in ZooKeeper as " + serverName);
   // Make the MetaRegionServer pb and then get its bytes and save this as
   // the znode content.
   MetaRegionServer pbrsr =
       MetaRegionServer.newBuilder()
           .setServer(ProtobufUtil.toServerName(serverName))
           .setRpcVersion(HConstants.RPC_CURRENT_VERSION)
           .setState(state.convert())
           .build();
   byte[] data = ProtobufUtil.prependPBMagic(pbrsr.toByteArray());
   try {
     ZKUtil.setData(zookeeper, zookeeper.getZNodeForReplica(replicaId), data);
   } catch (KeeperException.NoNodeException nne) {
     if (replicaId == HRegionInfo.DEFAULT_REPLICA_ID) {
       LOG.debug("META region location doesn't exist, create it");
     } else {
       LOG.debug("META region location doesn't exist for replicaId " + replicaId + ", create it");
     }
     ZKUtil.createAndWatch(zookeeper, zookeeper.getZNodeForReplica(replicaId), data);
   }
 }
Exemple #5
0
 /**
  * @return This instance serialized as protobuf w/ a magic pb prefix.
  * @see #parseFrom(byte[])
  */
 public byte[] toByteArray() {
   byte[] bytes = convert().toByteArray();
   return ProtobufUtil.prependPBMagic(bytes);
 }