Exemple #1
0
 /**
  * Deletes an existing unassigned node that is in the specified state for the specified region.
  *
  * <p>If a node does not already exist for this region, a {@link NoNodeException} will be thrown.
  *
  * <p>No watcher is set whether this succeeds or not.
  *
  * <p>Returns false if the node was not in the proper state but did exist.
  *
  * <p>This method is used during table disables when a region finishes successfully closing. This
  * is the Master acknowledging completion of the specified regions transition to being closed.
  *
  * @param zkw zk reference
  * @param regionName region to be deleted from zk
  * @param expectedState state region must be in for delete to complete
  * @param expectedVersion of the znode that is to be deleted. If expectedVersion need not be
  *     compared while deleting the znode pass -1
  * @throws KeeperException if unexpected zookeeper exception
  * @throws KeeperException.NoNodeException if node does not exist
  */
 public static boolean deleteNode(
     ZooKeeperWatcher zkw, String regionName, EventType expectedState, int expectedVersion)
     throws KeeperException, KeeperException.NoNodeException {
   LOG.debug(
       zkw.prefix(
           "Deleting existing unassigned "
               + "node for "
               + regionName
               + " that is in expected state "
               + expectedState));
   String node = getNodeName(zkw, regionName);
   zkw.sync(node);
   Stat stat = new Stat();
   byte[] bytes = ZKUtil.getDataNoWatch(zkw, node, stat);
   if (bytes == null) {
     // If it came back null, node does not exist.
     throw KeeperException.create(Code.NONODE);
   }
   RegionTransitionData data = RegionTransitionData.fromBytes(bytes);
   if (!data.getEventType().equals(expectedState)) {
     LOG.warn(
         zkw.prefix(
             "Attempting to delete unassigned "
                 + "node "
                 + regionName
                 + " in "
                 + expectedState
                 + " state but node is in "
                 + data.getEventType()
                 + " state"));
     return false;
   }
   if (expectedVersion != -1 && stat.getVersion() != expectedVersion) {
     LOG.warn(
         "The node we are trying to delete is not the expected one. " + "Got a version mismatch");
     return false;
   }
   synchronized (zkw.getNodes()) {
     // TODO: Does this go here or only if we successfully delete node?
     zkw.getNodes().remove(node);
     if (!ZKUtil.deleteNode(zkw, node, stat.getVersion())) {
       LOG.warn(
           zkw.prefix(
               "Attempting to delete "
                   + "unassigned node in "
                   + expectedState
                   + " state but "
                   + "after verifying it was in OPENED state, we got a version mismatch"));
       return false;
     }
     LOG.debug(
         zkw.prefix(
             "Successfully deleted unassigned node for region "
                 + regionName
                 + " in expected state "
                 + expectedState));
     return true;
   }
 }
 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
   }
 }