Ejemplo n.º 1
0
 public void deleteMetaLocation(ZooKeeperWatcher zookeeper, int replicaId) throws KeeperException {
   if (replicaId == HRegionInfo.DEFAULT_REPLICA_ID) {
     LOG.info("Deleting hbase:meta region location in ZooKeeper");
   } else {
     LOG.info("Deleting hbase:meta for " + replicaId + " region location in ZooKeeper");
   }
   try {
     // Just delete the node.  Don't need any watches.
     ZKUtil.deleteNode(zookeeper, zookeeper.getZNodeForReplica(replicaId));
   } catch (KeeperException.NoNodeException nne) {
     // Has already been deleted
   }
 }
Ejemplo n.º 2
0
 /**
  * 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);
   }
 }
Ejemplo n.º 3
0
 /**
  * Load the meta region state from the meta server ZNode.
  *
  * @param zkw
  * @param replicaId
  * @return regionstate
  * @throws KeeperException
  */
 public static RegionState getMetaRegionState(ZooKeeperWatcher zkw, int replicaId)
     throws KeeperException {
   RegionState.State state = RegionState.State.OPEN;
   ServerName serverName = null;
   try {
     byte[] data = ZKUtil.getData(zkw, zkw.getZNodeForReplica(replicaId));
     if (data != null && data.length > 0 && ProtobufUtil.isPBMagicPrefix(data)) {
       try {
         int prefixLen = ProtobufUtil.lengthOfPBMagic();
         ZooKeeperProtos.MetaRegionServer rl =
             ZooKeeperProtos.MetaRegionServer.PARSER.parseFrom(
                 data, prefixLen, data.length - prefixLen);
         if (rl.hasState()) {
           state = RegionState.State.convert(rl.getState());
         }
         HBaseProtos.ServerName sn = rl.getServer();
         serverName = ServerName.valueOf(sn.getHostName(), sn.getPort(), sn.getStartCode());
       } catch (InvalidProtocolBufferException e) {
         throw new DeserializationException("Unable to parse meta region location");
       }
     } else {
       // old style of meta region location?
       serverName = ServerName.parseFrom(data);
     }
   } catch (DeserializationException e) {
     throw ZKUtil.convert(e);
   } catch (InterruptedException e) {
     Thread.currentThread().interrupt();
   }
   if (serverName == null) {
     state = RegionState.State.OFFLINE;
   }
   return new RegionState(
       RegionReplicaUtil.getRegionInfoForReplica(HRegionInfo.FIRST_META_REGIONINFO, replicaId),
       state,
       serverName);
 }