hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jxi...@apache.org
Subject svn commit: r1400358 [4/4] - in /hbase/trunk/hbase-server/src: main/java/org/apache/hadoop/hbase/ main/java/org/apache/hadoop/hbase/master/ main/java/org/apache/hadoop/hbase/master/handler/ main/java/org/apache/hadoop/hbase/protobuf/ main/java/org/apac...
Date Sat, 20 Oct 2012 03:57:50 GMT
Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1400358&r1=1400357&r2=1400358&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
Sat Oct 20 03:57:49 2012
@@ -135,6 +135,7 @@ import org.apache.hadoop.hbase.protobuf.
 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.GetStoreFileRequest;
 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.GetStoreFileResponse;
 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.OpenRegionRequest;
+import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.OpenRegionRequest.RegionOpenInfo;
 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.OpenRegionResponse;
 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.OpenRegionResponse.RegionOpeningState;
 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.ReplicateWALEntryRequest;
@@ -171,7 +172,6 @@ import org.apache.hadoop.hbase.protobuf.
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.Coprocessor;
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameBytesPair;
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameStringPair;
-import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionInfo;
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionLoad;
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier;
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType;
@@ -228,7 +228,6 @@ import org.codehaus.jackson.map.ObjectMa
 
 import com.google.common.base.Function;
 import com.google.protobuf.ByteString;
-import com.google.protobuf.Message;
 import com.google.protobuf.RpcController;
 import com.google.protobuf.ServiceException;
 
@@ -2595,14 +2594,13 @@ public class  HRegionServer implements C
     }
   }
 
-  protected void checkIfRegionInTransition(HRegionInfo region,
+  protected void checkIfRegionInTransition(byte[] regionEncodedName,
       String currentAction) throws RegionAlreadyInTransitionException {
-    byte[] encodedName = region.getEncodedNameAsBytes();
-    if (this.regionsInTransitionInRS.containsKey(encodedName)) {
-      boolean openAction = this.regionsInTransitionInRS.get(encodedName);
+    if (this.regionsInTransitionInRS.containsKey(regionEncodedName)) {
+      boolean openAction = this.regionsInTransitionInRS.get(regionEncodedName);
       // The below exception message will be used in master.
       throw new RegionAlreadyInTransitionException("Received:" + currentAction +
-        " for the region:" + region.getRegionNameAsString() +
+        " for the region:" + Bytes.toString(regionEncodedName) +
         " ,which we are already trying to " +
         (openAction ? OPEN : CLOSE)+ ".");
     }
@@ -3568,12 +3566,8 @@ public class  HRegionServer implements C
    */
   @Override
   @QosPriority(priority=HConstants.HIGH_QOS)
-  public OpenRegionResponse openRegion(final RpcController controller, final OpenRegionRequest
request)
-  throws ServiceException {
-    int versionOfOfflineNode = -1;
-    if (request.hasVersionOfOfflineNode()) {
-      versionOfOfflineNode = request.getVersionOfOfflineNode();
-    }
+  public OpenRegionResponse openRegion(final RpcController controller,
+      final OpenRegionRequest request) throws ServiceException {
     try {
       checkOpen();
     } catch (IOException ie) {
@@ -3581,13 +3575,18 @@ public class  HRegionServer implements C
     }
     requestCount.incrementAndGet();
     OpenRegionResponse.Builder builder = OpenRegionResponse.newBuilder();
-    Map<String, HTableDescriptor> htds = new HashMap<String, HTableDescriptor>(
-        request.getRegionList().size());
-    boolean isBulkAssign = request.getRegionList().size() > 1;
-    for (RegionInfo regionInfo : request.getRegionList()) {
-      HRegionInfo region = HRegionInfo.convert(regionInfo);
+    int regionCount = request.getOpenInfoCount();
+    Map<String, HTableDescriptor> htds =
+      new HashMap<String, HTableDescriptor>(regionCount);
+    boolean isBulkAssign = regionCount > 1;
+    for (RegionOpenInfo regionOpenInfo : request.getOpenInfoList()) {
+      HRegionInfo region = HRegionInfo.convert(regionOpenInfo.getRegion());
+      int versionOfOfflineNode = -1;
+      if (regionOpenInfo.hasVersionOfOfflineNode()) {
+        versionOfOfflineNode = regionOpenInfo.getVersionOfOfflineNode();
+      }
       try {
-        checkIfRegionInTransition(region, OPEN);
+        checkIfRegionInTransition(region.getEncodedNameAsBytes(), OPEN);
         HRegion onlineRegion = getFromOnlineRegions(region.getEncodedName());
         if (null != onlineRegion) {
           // See HBASE-5094. Cross check with META if still this RS is owning
@@ -3643,7 +3642,6 @@ public class  HRegionServer implements C
       }
     }
     return builder.build();
-
   }
 
   /**
@@ -3668,17 +3666,26 @@ public class  HRegionServer implements C
     try {
       checkOpen();
       requestCount.incrementAndGet();
-      HRegion region = getRegion(request.getRegion());
-      CloseRegionResponse.Builder
-        builder = CloseRegionResponse.newBuilder();
+      String encodedRegionName =
+        ProtobufUtil.getRegionEncodedName(request.getRegion());
+      byte[] encodedName = Bytes.toBytes(encodedRegionName);
+      Boolean openAction = regionsInTransitionInRS.get(encodedName);
+      if (openAction != null) {
+        if (openAction.booleanValue()) {
+          regionsInTransitionInRS.replace(encodedName, openAction, Boolean.FALSE);
+        }
+        checkIfRegionInTransition(encodedName, CLOSE);
+      }
+      HRegion region = getRegionByEncodedName(encodedRegionName);
       LOG.info("Received close region: " + region.getRegionNameAsString() +
         ". Version of ZK closing node:" + versionOfClosingNode +
         ". Destination server:" + sn);
       HRegionInfo regionInfo = region.getRegionInfo();
-      checkIfRegionInTransition(regionInfo, CLOSE);
+      checkIfRegionInTransition(encodedName, CLOSE);
       boolean closed = closeRegion(
         regionInfo, false, zk, versionOfClosingNode, sn);
-      builder.setClosed(closed);
+      CloseRegionResponse.Builder builder =
+        CloseRegionResponse.newBuilder().setClosed(closed);
       return builder.build();
     } catch (IOException ie) {
       throw new ServiceException(ie);
@@ -3874,18 +3881,8 @@ public class  HRegionServer implements C
    */
   protected HRegion getRegion(
       final RegionSpecifier regionSpecifier) throws IOException {
-    byte[] value = regionSpecifier.getValue().toByteArray();
-    RegionSpecifierType type = regionSpecifier.getType();
-    checkOpen();
-    switch (type) {
-      case REGION_NAME:
-        return getRegion(value);
-      case ENCODED_REGION_NAME:
-        return getRegionByEncodedName(Bytes.toString(value));
-      default:
-        throw new DoNotRetryIOException(
-          "Unsupported region specifier type: " + type);
-    }
+    return getRegionByEncodedName(
+      ProtobufUtil.getRegionEncodedName(regionSpecifier));
   }
 
   /**

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenRegionHandler.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenRegionHandler.java?rev=1400358&r1=1400357&r2=1400358&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenRegionHandler.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/OpenRegionHandler.java
Sat Oct 20 03:57:49 2012
@@ -134,6 +134,14 @@ public class OpenRegionHandler extends E
         cleanupFailedOpen(region);
         return;
       }
+
+      // One more check to make sure we are opening instead of closing
+      if (!isRegionStillOpening()) {
+        LOG.warn("Open region aborted since it isn't opening any more");
+        cleanupFailedOpen(region);
+        return;
+      }
+
       // Successful region open, and add it to OnlineRegions
       this.rsServices.addToOnlineRegions(region);
 
@@ -269,6 +277,10 @@ public class OpenRegionHandler extends E
    * @throws IOException
    */
   private boolean transitionToOpened(final HRegion r) throws IOException {
+    if (!isRegionStillOpening()) {
+      LOG.warn("Open region aborted since it isn't opening any more");
+      return false;
+    }
     boolean result = false;
     HRegionInfo hri = r.getRegionInfo();
     final String name = hri.getRegionNameAsString();
@@ -364,6 +376,12 @@ public class OpenRegionHandler extends E
     if (region != null) region.close();
   }
 
+  private boolean isRegionStillOpening() {
+    byte[] encodedName = regionInfo.getEncodedNameAsBytes();
+    Boolean action = rsServices.getRegionsInTransitionInRS().get(encodedName);
+    return action != null && action.booleanValue();
+  }
+
   /**
    * Transition ZK node from OFFLINE to OPENING.
    * @param encodedName Name of the znode file (Region encodedName is the znode
@@ -374,6 +392,10 @@ public class OpenRegionHandler extends E
    */
   boolean transitionZookeeperOfflineToOpening(final String encodedName,
       int versionOfOfflineNode) {
+    if (!isRegionStillOpening()) {
+      LOG.warn("Open region aborted since it isn't opening any more");
+      return false;
+    }
     // TODO: should also handle transition from CLOSED?
     try {
       // Initialize the znode version.
@@ -399,6 +421,10 @@ public class OpenRegionHandler extends E
    * @return True if successful transition.
    */
   boolean tickleOpening(final String context) {
+    if (!isRegionStillOpening()) {
+      LOG.warn("Open region aborted since it isn't opening any more");
+      return false;
+    }
     // If previous checks failed... do not try again.
     if (!isGoodVersion()) return false;
     String encodedName = this.regionInfo.getEncodedName();

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/KeyLocker.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/KeyLocker.java?rev=1400358&r1=1400357&r2=1400358&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/KeyLocker.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/KeyLocker.java Sat
Oct 20 03:57:49 2012
@@ -19,14 +19,18 @@
 package org.apache.hadoop.hbase.util;
 
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 /**
  * A utility class to manage a set of locks. Each lock is identified by a String which serves
  * as a key. Typical usage is: <p>
@@ -44,7 +48,7 @@ import java.util.concurrent.locks.Reentr
  * }
  * </p>
  */
-public class KeyLocker<K> {
+public class KeyLocker<K extends Comparable<? super K>> {
   private static final Log LOG = LogFactory.getLog(KeyLocker.class);
 
   // The number of lock we want to easily support. It's not a maximum.
@@ -79,6 +83,19 @@ public class KeyLocker<K> {
   }
 
   /**
+   * Acquire locks for a set of keys. The keys will be
+   * sorted internally to avoid possible deadlock.
+   */
+  public Map<K, Lock> acquireLocks(final Set<K> keys) {
+    Map<K, Lock> locks = new HashMap<K, Lock>(keys.size());
+    SortedSet<K> sortedKeys = new TreeSet<K>(keys);
+    for (K key : sortedKeys) {
+      locks.put(key, acquireLock(key));
+    }
+    return locks;
+  }
+
+  /**
    * Free the lock for the given key.
    */
   private synchronized void releaseLock(K key) {
@@ -95,7 +112,9 @@ public class KeyLocker<K> {
     }
   }
 
-  static class KeyLock<K> extends ReentrantLock {
+  static class KeyLock<K extends Comparable<? super K>> extends ReentrantLock
{
+    private static final long serialVersionUID = -12432857283423584L;
+
     private final KeyLocker<K> locker;
     private final K lockId;
 

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAssign.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAssign.java?rev=1400358&r1=1400357&r2=1400358&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAssign.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAssign.java
Sat Oct 20 03:57:49 2012
@@ -133,7 +133,7 @@ public class ZKAssign {
    *
    * @param zkw zk reference
    * @param region region to be created as offline
-   * @param serverName server event originates from
+   * @param serverName server transition will happen on
    * @throws KeeperException if unexpected zookeeper exception
    * @throws KeeperException.NodeExistsException if node already exists
    */
@@ -163,7 +163,7 @@ public class ZKAssign {
    *
    * @param zkw zk reference
    * @param region region to be created as offline
-   * @param serverName server event originates from
+   * @param serverName server transition will happen on
    * @param cb
    * @param ctx
    * @throws KeeperException if unexpected zookeeper exception
@@ -182,35 +182,6 @@ public class ZKAssign {
   }
 
   /**
-   * Forces an existing unassigned node to the OFFLINE state for the specified
-   * region.
-   *
-   * <p>Does not create a new node.  If a node does not already exist for this
-   * region, a {@link NoNodeException} will be thrown.
-   *
-   * <p>Sets a watcher on the unassigned region node if the method is
-   * successful.
-   *
-   * <p>This method should only be used during recovery of regionserver failure.
-   *
-   * @param zkw zk reference
-   * @param region region to be forced as offline
-   * @param serverName server event originates from
-   * @throws KeeperException if unexpected zookeeper exception
-   * @throws KeeperException.NoNodeException if node does not exist
-   */
-  public static void forceNodeOffline(ZooKeeperWatcher zkw, HRegionInfo region,
-      ServerName serverName)
-  throws KeeperException, KeeperException.NoNodeException {
-    LOG.debug(zkw.prefix("Forcing existing unassigned node for " +
-      region.getEncodedName() + " to OFFLINE state"));
-    RegionTransition rt =
-      RegionTransition.createRegionTransition(EventType.M_ZK_REGION_OFFLINE, region.getRegionName(),
serverName);
-    String node = getNodeName(zkw, region.getEncodedName());
-    ZKUtil.setData(zkw, node, rt.toByteArray());
-  }
-
-  /**
    * Creates or force updates an unassigned node to the OFFLINE state for the
    * specified region.
    * <p>
@@ -224,7 +195,7 @@ public class ZKAssign {
    *
    * @param zkw zk reference
    * @param region region to be created as offline
-   * @param serverName server event originates from
+   * @param serverName server transition will happen on
    * @return the version of the znode created in OFFLINE state, -1 if
    *         unsuccessful.
    * @throws KeeperException if unexpected zookeeper exception
@@ -232,76 +203,17 @@ public class ZKAssign {
    */
   public static int createOrForceNodeOffline(ZooKeeperWatcher zkw,
       HRegionInfo region, ServerName serverName) throws KeeperException {
-    return createOrForceNodeOffline(zkw, region, serverName, false, true);
-  }
-
-  /**
-   * 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
-   * @param hijack
-   *          - true if to be hijacked and reassigned, false otherwise
-   * @param allowCreation
-   *          - true if the node has to be created newly, false otherwise
-   * @throws KeeperException
-   *           if unexpected zookeeper exception
-   * @return the version of the znode created in OFFLINE state, -1 if
-   *         unsuccessful.
-   * @throws KeeperException.NodeExistsException
-   *           if node already exists
-   */
-  public static int createOrForceNodeOffline(ZooKeeperWatcher zkw,
-      HRegionInfo region, ServerName serverName,
-      boolean hijack, boolean allowCreation)
-  throws KeeperException {
     LOG.debug(zkw.prefix("Creating (or updating) unassigned node for " +
       region.getEncodedName() + " with OFFLINE state"));
     RegionTransition rt = RegionTransition.createRegionTransition(EventType.M_ZK_REGION_OFFLINE,
       region.getRegionName(), serverName, HConstants.EMPTY_BYTE_ARRAY);
     byte [] data = rt.toByteArray();
     String node = getNodeName(zkw, region.getEncodedName());
-    Stat stat = new Stat();
     zkw.sync(node);
     int version = ZKUtil.checkExists(zkw, node);
     if (version == -1) {
-      // While trying to transit a node to OFFLINE that was in previously in 
-      // OPENING state but before it could transit to OFFLINE state if RS had 
-      // opened the region then the Master deletes the assigned region znode. 
-      // In that case the znode will not exist. So we should not
-      // create the znode again which will lead to double assignment.
-      if (hijack && !allowCreation) {
-        return -1;
-      }
       return ZKUtil.createAndWatch(zkw, node, data);
     } else {
-      byte [] curDataInZNode = ZKAssign.getDataNoWatch(zkw, region.getEncodedName(), stat);
-      RegionTransition curRt = getRegionTransition(curDataInZNode);
-      // Do not move the node to OFFLINE if znode is in any of the following
-      // state.
-      // Because these are already executed states.
-      if (hijack && curRt != null) {
-        EventType eventType = curRt.getEventType();
-        if (eventType.equals(EventType.M_ZK_REGION_CLOSING)
-            || eventType.equals(EventType.RS_ZK_REGION_CLOSED)
-            || eventType.equals(EventType.RS_ZK_REGION_OPENED)) {
-          return -1;
-        }
-      }
-
       boolean setData = false;
       try {
         setData = ZKUtil.setData(zkw, node, data, version);
@@ -327,7 +239,7 @@ public class ZKAssign {
         }
       }
     }
-    return stat.getVersion() + 1;
+    return version + 1;
   }
 
   /**
@@ -558,7 +470,7 @@ public class ZKAssign {
    *
    * @param zkw zk reference
    * @param region region to be created as closing
-   * @param serverName server event originates from
+   * @param serverName server transition will happen on
    * @return version of node after transition, -1 if unsuccessful transition
    * @throws KeeperException if unexpected zookeeper exception
    * @throws KeeperException.NodeExistsException if node already exists
@@ -596,7 +508,7 @@ public class ZKAssign {
    *
    * @param zkw zk reference
    * @param region region to be transitioned to closed
-   * @param serverName server event originates from
+   * @param serverName server transition happens on
    * @return version of node after transition, -1 if unsuccessful transition
    * @throws KeeperException if unexpected zookeeper exception
    */
@@ -630,7 +542,7 @@ public class ZKAssign {
    *
    * @param zkw zk reference
    * @param region region to be transitioned to opening
-   * @param serverName server event originates from
+   * @param serverName server transition happens on
    * @return version of node after transition, -1 if unsuccessful transition
    * @throws KeeperException if unexpected zookeeper exception
    */
@@ -670,7 +582,7 @@ public class ZKAssign {
    *
    * @param zkw zk reference
    * @param region region to be transitioned to opening
-   * @param serverName server event originates from
+   * @param serverName server transition happens on
    * @return version of node after transition, -1 if unsuccessful transition
    * @throws KeeperException if unexpected zookeeper exception
    */
@@ -706,7 +618,7 @@ public class ZKAssign {
    *
    * @param zkw zk reference
    * @param region region to be transitioned to opened
-   * @param serverName server event originates from
+   * @param serverName server transition happens on
    * @return version of node after transition, -1 if unsuccessful transition
    * @throws KeeperException if unexpected zookeeper exception
    */
@@ -739,7 +651,7 @@ public class ZKAssign {
    *
    * @param zkw zk reference
    * @param region region to be transitioned to opened
-   * @param serverName server event originates from
+   * @param serverName server transition happens on
    * @param endState state to transition node to if all checks pass
    * @param beginState state the node must currently be in to do transition
    * @param expectedVersion expected version of data before modification, or -1

Modified: hbase/trunk/hbase-server/src/main/protobuf/Admin.proto
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/protobuf/Admin.proto?rev=1400358&r1=1400357&r2=1400358&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/protobuf/Admin.proto (original)
+++ hbase/trunk/hbase-server/src/main/protobuf/Admin.proto Sat Oct 20 03:57:49 2012
@@ -64,8 +64,12 @@ message GetOnlineRegionResponse {
 }
 
 message OpenRegionRequest {
-  repeated RegionInfo region = 1;
-  optional uint32 versionOfOfflineNode = 2;
+  repeated RegionOpenInfo openInfo = 1;
+
+  message RegionOpenInfo {
+    required RegionInfo region = 1;
+    optional uint32 versionOfOfflineNode = 2;
+  }
 }
 
 message OpenRegionResponse {

Modified: hbase/trunk/hbase-server/src/main/protobuf/ZooKeeper.proto
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/protobuf/ZooKeeper.proto?rev=1400358&r1=1400357&r2=1400358&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/protobuf/ZooKeeper.proto (original)
+++ hbase/trunk/hbase-server/src/main/protobuf/ZooKeeper.proto Sat Oct 20 03:57:49 2012
@@ -62,7 +62,8 @@ message RegionTransition {
   // Full regionname in bytes
   required bytes regionName = 2;
   required uint64 createTime = 3;
-  optional ServerName originServerName = 4;
+  // The region server where the transition will happen or is happening
+  required ServerName serverName = 4;
   optional bytes payload = 5;
 }
 

Modified: hbase/trunk/hbase-server/src/main/ruby/shell/commands/assign.rb
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/ruby/shell/commands/assign.rb?rev=1400358&r1=1400357&r2=1400358&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/ruby/shell/commands/assign.rb (original)
+++ hbase/trunk/hbase-server/src/main/ruby/shell/commands/assign.rb Sat Oct 20 03:57:49 2012
@@ -22,9 +22,8 @@ module Shell
     class Assign < Command
       def help
         return <<-EOF
-Assign a region.Use with caution.If region already assigned,
-this command will just go ahead and reassign
-the region anyways. For experts only.
+Assign a region. Use with caution. If region already assigned,
+this command will do a force reassign. For experts only.
 EOF
       end
 

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java?rev=1400358&r1=1400357&r2=1400358&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java
Sat Oct 20 03:57:49 2012
@@ -192,6 +192,11 @@ public class TestAssignmentManager {
       createRegionPlanAndBalance(am, SERVERNAME_A, SERVERNAME_B, REGIONINFO);
       startFakeFailedOverMasterAssignmentManager(am, this.watcher);
       while (!am.processRITInvoked) Thread.sleep(1);
+      // As part of the failover cleanup, the balancing region plan is removed.
+      // So a random server will be used to open the region. For testing purpose,
+      // let's assume it is going to open on server b:
+      am.addPlan(REGIONINFO.getEncodedName(), new RegionPlan(REGIONINFO, null, SERVERNAME_B));
+
       // Now fake the region closing successfully over on the regionserver; the
       // regionserver will have set the region in CLOSED state. This will
       // trigger callback into AM. The below zk close call is from the RS close
@@ -208,7 +213,7 @@ public class TestAssignmentManager {
       assertNotSame(-1, versionid);
       // This uglyness below is what the openregionhandler on RS side does.
       versionid = ZKAssign.transitionNode(server.getZooKeeper(), REGIONINFO,
-        SERVERNAME_A, EventType.M_ZK_REGION_OFFLINE,
+        SERVERNAME_B, EventType.M_ZK_REGION_OFFLINE,
         EventType.RS_ZK_REGION_OPENING, versionid);
       assertNotSame(-1, versionid);
       // Move znode from OPENING to OPENED as RS does on successful open.
@@ -233,6 +238,11 @@ public class TestAssignmentManager {
       createRegionPlanAndBalance(am, SERVERNAME_A, SERVERNAME_B, REGIONINFO);
       startFakeFailedOverMasterAssignmentManager(am, this.watcher);
       while (!am.processRITInvoked) Thread.sleep(1);
+      // As part of the failover cleanup, the balancing region plan is removed.
+      // So a random server will be used to open the region. For testing purpose,
+      // let's assume it is going to open on server b:
+      am.addPlan(REGIONINFO.getEncodedName(), new RegionPlan(REGIONINFO, null, SERVERNAME_B));
+
       // Now fake the region closing successfully over on the regionserver; the
       // regionserver will have set the region in CLOSED state. This will
       // trigger callback into AM. The below zk close call is from the RS close
@@ -250,7 +260,7 @@ public class TestAssignmentManager {
       assertNotSame(-1, versionid);
       // This uglyness below is what the openregionhandler on RS side does.
       versionid = ZKAssign.transitionNode(server.getZooKeeper(), REGIONINFO,
-          SERVERNAME_A, EventType.M_ZK_REGION_OFFLINE,
+          SERVERNAME_B, EventType.M_ZK_REGION_OFFLINE,
           EventType.RS_ZK_REGION_OPENING, versionid);
       assertNotSame(-1, versionid);
       // Move znode from OPENING to OPENED as RS does on successful open.
@@ -275,6 +285,11 @@ public class TestAssignmentManager {
       createRegionPlanAndBalance(am, SERVERNAME_A, SERVERNAME_B, REGIONINFO);
       startFakeFailedOverMasterAssignmentManager(am, this.watcher);
       while (!am.processRITInvoked) Thread.sleep(1);
+      // As part of the failover cleanup, the balancing region plan is removed.
+      // So a random server will be used to open the region. For testing purpose,
+      // let's assume it is going to open on server b:
+      am.addPlan(REGIONINFO.getEncodedName(), new RegionPlan(REGIONINFO, null, SERVERNAME_B));
+
       // Now fake the region closing successfully over on the regionserver; the
       // regionserver will have set the region in CLOSED state. This will
       // trigger callback into AM. The below zk close call is from the RS close
@@ -292,7 +307,7 @@ public class TestAssignmentManager {
       assertNotSame(-1, versionid);
       // This uglyness below is what the openregionhandler on RS side does.
       versionid = ZKAssign.transitionNode(server.getZooKeeper(), REGIONINFO,
-          SERVERNAME_A, EventType.M_ZK_REGION_OFFLINE,
+          SERVERNAME_B, EventType.M_ZK_REGION_OFFLINE,
           EventType.RS_ZK_REGION_OPENING, versionid);
       assertNotSame(-1, versionid);
       // Move znode from OPENING to OPENED as RS does on successful open.
@@ -798,12 +813,11 @@ public class TestAssignmentManager {
         EventType.RS_ZK_REGION_OPENING, version);
     RegionTransition rt = RegionTransition.createRegionTransition(EventType.RS_ZK_REGION_OPENING,
         REGIONINFO.getRegionName(), SERVERNAME_A, HConstants.EMPTY_BYTE_ARRAY);
-    Map<ServerName, List<HRegionInfo>> deadServers =
-      new HashMap<ServerName, List<HRegionInfo>>();
-    deadServers.put(SERVERNAME_A, null);
     version = ZKAssign.getVersion(this.watcher, REGIONINFO);
+    Mockito.when(this.serverManager.isServerOnline(SERVERNAME_A)).thenReturn(false);
+    am.getRegionStates().createRegionState(REGIONINFO);
     am.gate.set(false);
-    am.processRegionsInTransition(rt, REGIONINFO, deadServers, version);
+    am.processRegionsInTransition(rt, REGIONINFO, version);
     // Waiting for the assignment to get completed.
     while (!am.gate.get()) {
       Thread.sleep(10);
@@ -1017,22 +1031,18 @@ public class TestAssignmentManager {
 
     @Override
     boolean processRegionInTransition(String encodedRegionName,
-        HRegionInfo regionInfo,
-        Map<ServerName, List<HRegionInfo>> deadServers)
-        throws KeeperException, IOException {
+        HRegionInfo regionInfo) throws KeeperException, IOException {
       this.processRITInvoked = true;
-      return super.processRegionInTransition(encodedRegionName, regionInfo,
-          deadServers);
+      return super.processRegionInTransition(encodedRegionName, regionInfo);
     }
 
     @Override
-    public void assign(HRegionInfo region, boolean setOfflineInZK, boolean forceNewPlan,
-        boolean hijack) {
+    public void assign(HRegionInfo region, boolean setOfflineInZK, boolean forceNewPlan)
{
       if (enabling) {
         assignmentCount++;
         this.regionOnline(region, SERVERNAME_A);
       } else {
-        super.assign(region, setOfflineInZK, forceNewPlan, hijack);
+        super.assign(region, setOfflineInZK, forceNewPlan);
         this.gate.set(true);
       }
     }
@@ -1097,5 +1107,4 @@ public class TestAssignmentManager {
     t.start();
     while (!t.isAlive()) Threads.sleep(1);
   }
-
 }

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestCloseRegionHandler.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestCloseRegionHandler.java?rev=1400358&r1=1400357&r2=1400358&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestCloseRegionHandler.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestCloseRegionHandler.java
Sat Oct 20 03:57:49 2012
@@ -210,6 +210,7 @@ public class TestCloseRegionHandler {
        // Create it OFFLINE node, which is what Master set before sending OPEN RPC
        ZKAssign.createNodeOffline(server.getZooKeeper(), hri, server.getServerName());
        OpenRegionHandler openHandler = new OpenRegionHandler(server, rss, hri, htd);
+       rss.getRegionsInTransitionInRS().put(hri.getEncodedNameAsBytes(), Boolean.TRUE);
        openHandler.process();
        // This parse is not used?
        RegionTransition.parseFrom(ZKAssign.getData(server.getZooKeeper(), hri.getEncodedName()));

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestOpenRegionHandler.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestOpenRegionHandler.java?rev=1400358&r1=1400357&r2=1400358&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestOpenRegionHandler.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestOpenRegionHandler.java
Sat Oct 20 03:57:49 2012
@@ -114,9 +114,13 @@ public class TestOpenRegionHandler {
           return region;
         }
       };
+      rss.getRegionsInTransitionInRS().put(
+        hri.getEncodedNameAsBytes(), Boolean.TRUE);
       // Call process without first creating OFFLINE region in zk, see if
       // exception or just quiet return (expected).
       handler.process();
+      rss.getRegionsInTransitionInRS().put(
+        hri.getEncodedNameAsBytes(), Boolean.TRUE);
       ZKAssign.createNodeOffline(server.getZooKeeper(), hri, server.getServerName());
       // Call process again but this time yank the zk znode out from under it
       // post OPENING; again will expect it to come back w/o NPE or exception.
@@ -143,6 +147,8 @@ public class TestOpenRegionHandler {
           return null;
         }
     };
+    rsServices.getRegionsInTransitionInRS().put(
+      TEST_HRI.getEncodedNameAsBytes(), Boolean.TRUE);
     handler.process();
 
     // Handler should have transitioned it to FAILED_OPEN
@@ -168,6 +174,8 @@ public class TestOpenRegionHandler {
           return false;
         }
     };
+    rsServices.getRegionsInTransitionInRS().put(
+      TEST_HRI.getEncodedNameAsBytes(), Boolean.TRUE);
     handler.process();
 
     // Handler should have transitioned it to FAILED_OPEN



Mime
View raw message