Exemple #1
0
 /**
  * Creates or force updates an unassigned node to the OFFLINE state for the specified region.
  *
  * <p>Attempts to create the node but if it exists will force it to transition to and OFFLINE
  * state.
  *
  * <p>Sets a watcher on the unassigned region node if the method is successful.
  *
  * <p>This method should be used when assigning a region.
  *
  * @param zkw zk reference
  * @param region region to be created as offline
  * @param serverName server event originates from
  * @throws KeeperException if unexpected zookeeper exception
  * @throws KeeperException.NodeExistsException if node already exists
  */
 public static boolean createOrForceNodeOffline(
     ZooKeeperWatcher zkw, HRegionInfo region, String serverName) throws KeeperException {
   LOG.debug(
       zkw.prefix(
           "Creating (or updating) unassigned node for "
               + region.getEncodedName()
               + " with OFFLINE state"));
   RegionTransitionData data =
       new RegionTransitionData(EventType.M_ZK_REGION_OFFLINE, region.getRegionName(), serverName);
   synchronized (zkw.getNodes()) {
     String node = getNodeName(zkw, region.getEncodedName());
     zkw.sync(node);
     zkw.getNodes().add(node);
     int version = ZKUtil.checkExists(zkw, node);
     if (version == -1) {
       ZKUtil.createAndWatch(zkw, node, data.getBytes());
     } else {
       if (!ZKUtil.setData(zkw, node, data.getBytes(), version)) {
         return false;
       } else {
         // We successfully forced to OFFLINE, reset watch and handle if
         // the state changed in between our set and the watch
         RegionTransitionData curData = ZKAssign.getData(zkw, region.getEncodedName());
         if (curData.getEventType() != data.getEventType()) {
           // state changed, need to process
           return false;
         }
       }
     }
   }
   return true;
 }
Exemple #2
0
 public static void createNodeOffline(
     ZooKeeperWatcher zkw, HRegionInfo region, String serverName, final EventType event)
     throws KeeperException, KeeperException.NodeExistsException {
   LOG.debug(
       zkw.prefix(
           "Creating unassigned node for " + region.getEncodedName() + " in OFFLINE state"));
   RegionTransitionData data = new RegionTransitionData(event, region.getRegionName(), serverName);
   synchronized (zkw.getNodes()) {
     String node = getNodeName(zkw, region.getEncodedName());
     zkw.getNodes().add(node);
     ZKUtil.createAndWatch(zkw, node, data.getBytes());
   }
 }
Exemple #3
0
  /**
   * Creates a new unassigned node in the CLOSING state for the specified region.
   *
   * <p>Does not transition nodes from any states. If a node already exists for this region, a
   * {@link NodeExistsException} will be thrown.
   *
   * <p>If creation is successful, returns the version number of the CLOSING node created.
   *
   * <p>Does not set any watches.
   *
   * <p>This method should only be used by a RegionServer when initiating a close of a region after
   * receiving a CLOSE RPC from the Master.
   *
   * @param zkw zk reference
   * @param region region to be created as closing
   * @param serverName server event originates from
   * @return version of node after transition, -1 if unsuccessful transition
   * @throws KeeperException if unexpected zookeeper exception
   * @throws KeeperException.NodeExistsException if node already exists
   */
  public static int createNodeClosing(ZooKeeperWatcher zkw, HRegionInfo region, String serverName)
      throws KeeperException, KeeperException.NodeExistsException {
    LOG.debug(
        zkw.prefix(
            "Creating unassigned node for " + region.getEncodedName() + " in a CLOSING state"));

    RegionTransitionData data =
        new RegionTransitionData(
            EventType.RS_ZK_REGION_CLOSING, region.getRegionName(), serverName);

    synchronized (zkw.getNodes()) {
      String node = getNodeName(zkw, region.getEncodedName());
      zkw.getNodes().add(node);
      return ZKUtil.createAndWatch(zkw, node, data.getBytes());
    }
  }
 /**
  * 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);
   }
 }