hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject svn commit: r1339915 - in /hbase/branches/0.94/src: main/java/org/apache/hadoop/hbase/master/ main/java/org/apache/hadoop/hbase/master/handler/ test/java/org/apache/hadoop/hbase/master/
Date Thu, 17 May 2012 22:59:58 GMT
Author: tedyu
Date: Thu May 17 22:59:58 2012
New Revision: 1339915

URL: http://svn.apache.org/viewvc?rev=1339915&view=rev
Log:
HBASE-5927 SSH and DisableTableHandler happening together does not clear the znode of the
region and RIT map (Jieshan)

Modified:
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java?rev=1339915&r1=1339914&r2=1339915&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
(original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
Thu May 17 22:59:58 2012
@@ -2077,7 +2077,11 @@ public class AssignmentManager extends Z
     }
   }
   
-  private void deleteClosingOrClosedNode(HRegionInfo region) {
+  /**
+   * 
+   * @param region regioninfo of znode to be deleted.
+   */
+  public void deleteClosingOrClosedNode(HRegionInfo region) {
     try {
       if (!ZKAssign.deleteNode(master.getZooKeeper(), region.getEncodedName(),
           EventHandler.EventType.M_ZK_REGION_CLOSING)) {

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java?rev=1339915&r1=1339914&r2=1339915&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java
(original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java
Thu May 17 22:59:58 2012
@@ -284,10 +284,10 @@ public class ServerShutdownHandler exten
       // Iterate regions that were on this server and assign them
       if (hris != null) {
         for (Map.Entry<HRegionInfo, Result> e: hris.entrySet()) {
+          RegionState rit = this.services.getAssignmentManager().isRegionInTransition(e.getKey());
           if (processDeadRegion(e.getKey(), e.getValue(),
               this.services.getAssignmentManager(),
               this.server.getCatalogTracker())) {
-            RegionState rit = this.services.getAssignmentManager().isRegionInTransition(e.getKey());
             ServerName addressFromAM = this.services.getAssignmentManager()
                 .getRegionServerOfRegion(e.getKey());
             if (rit != null && !rit.isClosing() && !rit.isPendingClose())
{
@@ -304,6 +304,20 @@ public class ServerShutdownHandler exten
                 this.services.getAssignmentManager().assign(e.getKey(), true);
               }
           }
+          // If the table was partially disabled and the RS went down, we should clear the
RIT
+          // and remove the node for the region.
+          // The rit that we use may be stale in case the table was in DISABLING state
+          // but though we did assign we will not be clearing the znode in CLOSING state.
+          // Doing this will have no harm. See HBASE-5927
+          if (rit != null
+              && (rit.isClosing() || rit.isPendingClose())
+              && this.services.getAssignmentManager().getZKTable()
+                  .isDisablingOrDisabledTable(rit.getRegion().getTableNameAsString())) {
+            HRegionInfo hri = rit.getRegion();
+            AssignmentManager am = this.services.getAssignmentManager();
+            am.deleteClosingOrClosedNode(hri);
+            am.regionOffline(hri);
+          }
         }
       }
     } finally {

Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java?rev=1339915&r1=1339914&r2=1339915&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java
(original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java
Thu May 17 22:59:58 2012
@@ -18,6 +18,7 @@
 package org.apache.hadoop.hbase.master;
 
 import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
@@ -47,6 +48,8 @@ import org.apache.hadoop.hbase.executor.
 import org.apache.hadoop.hbase.executor.ExecutorService.ExecutorType;
 import org.apache.hadoop.hbase.executor.RegionTransitionData;
 import org.apache.hadoop.hbase.ipc.HRegionInterface;
+import org.apache.hadoop.hbase.master.AssignmentManager.RegionState;
+import org.apache.hadoop.hbase.master.AssignmentManager.RegionState.State;
 import org.apache.hadoop.hbase.master.handler.ServerShutdownHandler;
 import org.apache.hadoop.hbase.regionserver.RegionOpeningState;
 import org.apache.hadoop.hbase.util.Bytes;
@@ -56,6 +59,7 @@ import org.apache.hadoop.hbase.util.Writ
 import org.apache.hadoop.hbase.zookeeper.ZKAssign;
 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKTable.TableState;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.KeeperException.NodeExistsException;
 import org.junit.After;
@@ -379,42 +383,68 @@ public class TestAssignmentManager {
     AssignmentManager am =
       new AssignmentManager(this.server, this.serverManager, ct, balancer, executor);
     try {
-      // Make sure our new AM gets callbacks; once registered, can't unregister.
-      // Thats ok because we make a new zk watcher for each test.
-      this.watcher.registerListenerFirst(am);
+      processServerShutdownHandler(ct, am);
+    } finally {
+      executor.shutdown();
+      am.shutdown();
+      // Clean up all znodes
+      ZKAssign.deleteAllNodes(this.watcher);
+    }
+  }
+
+  /**
+   * To test closed region handler to remove rit and delete corresponding znode if region
in pending
+   * close or closing while processing shutdown of a region server.(HBASE-5927). 
+   * @throws KeeperException
+   * @throws IOException
+   */
+  @Test
+  public void testSSHWhenDisableTableInProgress()
+      throws KeeperException, IOException {
+    testCaseWithPartiallyDisabledState(TableState.DISABLING);
+    testCaseWithPartiallyDisabledState(TableState.DISABLED);
+  }
+
+  private void testCaseWithPartiallyDisabledState(TableState state) throws KeeperException,
IOException, NodeExistsException {
+    // Create and startup an executor. This is used by AssignmentManager
+    // handling zk callbacks.
+    ExecutorService executor = startupMasterExecutor("testSSHWhenDisableTableInProgress");
+
+    // We need a mocked catalog tracker.
+    CatalogTracker ct = Mockito.mock(CatalogTracker.class);
+    LoadBalancer balancer = LoadBalancerFactory.getLoadBalancer(server.getConfiguration());
+    // Create an AM.
+    AssignmentManager am = new AssignmentManager(this.server, this.serverManager, ct, balancer,
+        executor);
+    // adding region to regions and servers maps.
+    am.regionOnline(REGIONINFO, SERVERNAME_A);
+    // adding region in pending close.
+    am.regionsInTransition.put(REGIONINFO.getEncodedName(), new RegionState(REGIONINFO,
+        State.PENDING_CLOSE));
+
+    if (state == TableState.DISABLING) {
+      am.getZKTable().setDisablingTable(REGIONINFO.getTableNameAsString());
+    } else {
+      am.getZKTable().setDisabledTable(REGIONINFO.getTableNameAsString());
+    }
+    
+    RegionTransitionData data = new RegionTransitionData(EventType.M_ZK_REGION_CLOSING,
+        REGIONINFO.getRegionName(), SERVERNAME_A);
+    String node = ZKAssign.getNodeName(this.watcher, REGIONINFO.getEncodedName());
+    // create znode in M_ZK_REGION_CLOSING state.
+    ZKUtil.createAndWatch(this.watcher, node, data.getBytes());
 
-      // Need to set up a fake scan of meta for the servershutdown handler
-      // Make an RS Interface implementation.  Make it so a scanner can go against it.
-      HRegionInterface implementation = Mockito.mock(HRegionInterface.class);
-      // Get a meta row result that has region up on SERVERNAME_A
-      Result r = getMetaTableRowResult(REGIONINFO, SERVERNAME_A);
-      Mockito.when(implementation.openScanner((byte [])Mockito.any(), (Scan)Mockito.any())).
-        thenReturn(System.currentTimeMillis());
-      // Return a good result first and then return null to indicate end of scan
-      Mockito.when(implementation.next(Mockito.anyLong(), Mockito.anyInt())).
-        thenReturn(new Result [] {r}, (Result [])null);
-
-      // Get a connection w/ mocked up common methods.
-      HConnection connection =
-        HConnectionTestingUtility.getMockedConnectionAndDecorate(HTU.getConfiguration(),
-          implementation, SERVERNAME_B, REGIONINFO);
-
-      // Make it so we can get a catalogtracker from servermanager.. .needed
-      // down in guts of server shutdown handler.
-      Mockito.when(ct.getConnection()).thenReturn(connection);
-      Mockito.when(this.server.getCatalogTracker()).thenReturn(ct);
-
-      // Now make a server shutdown handler instance and invoke process.
-      // Have it that SERVERNAME_A died.
-      DeadServer deadServers = new DeadServer();
-      deadServers.add(SERVERNAME_A);
-      // I need a services instance that will return the AM
-      MasterServices services = Mockito.mock(MasterServices.class);
-      Mockito.when(services.getAssignmentManager()).thenReturn(am);
-      ServerShutdownHandler handler = new ServerShutdownHandler(this.server,
-        services, deadServers, SERVERNAME_A, false);
-      handler.process();
-      // The region in r will have been assigned.  It'll be up in zk as unassigned.
+    try {
+      processServerShutdownHandler(ct, am);
+      // check znode deleted or not.
+      // In both cases the znode should be deleted.
+      assertTrue("The znode should be deleted.",ZKUtil.checkExists(this.watcher, node) ==
-1);
+      // check whether in rit or not.  In the DISABLING case also the below assert will be
true
+      // but the piece of code added for HBASE-5927 will not do that.
+      if (state == TableState.DISABLED) {
+        assertTrue("Region state of region in pending close should be removed from rit.",
+            am.regionsInTransition.isEmpty());
+      }
     } finally {
       executor.shutdown();
       am.shutdown();
@@ -423,6 +453,46 @@ public class TestAssignmentManager {
     }
   }
 
+  private void processServerShutdownHandler(CatalogTracker ct, AssignmentManager am)
+      throws IOException {
+    // Make sure our new AM gets callbacks; once registered, can't unregister.
+    // Thats ok because we make a new zk watcher for each test.
+    this.watcher.registerListenerFirst(am);
+
+    // Need to set up a fake scan of meta for the servershutdown handler
+    // Make an RS Interface implementation.  Make it so a scanner can go against it.
+    HRegionInterface implementation = Mockito.mock(HRegionInterface.class);
+    // Get a meta row result that has region up on SERVERNAME_A
+    Result r = getMetaTableRowResult(REGIONINFO, SERVERNAME_A);
+    Mockito.when(implementation.openScanner((byte [])Mockito.any(), (Scan)Mockito.any())).
+      thenReturn(System.currentTimeMillis());
+    // Return a good result first and then return null to indicate end of scan
+    Mockito.when(implementation.next(Mockito.anyLong(), Mockito.anyInt())).
+      thenReturn(new Result [] {r}, (Result [])null);
+
+    // Get a connection w/ mocked up common methods.
+    HConnection connection =
+      HConnectionTestingUtility.getMockedConnectionAndDecorate(HTU.getConfiguration(),
+        implementation, SERVERNAME_B, REGIONINFO);
+
+    // Make it so we can get a catalogtracker from servermanager.. .needed
+    // down in guts of server shutdown handler.
+    Mockito.when(ct.getConnection()).thenReturn(connection);
+    Mockito.when(this.server.getCatalogTracker()).thenReturn(ct);
+
+    // Now make a server shutdown handler instance and invoke process.
+    // Have it that SERVERNAME_A died.
+    DeadServer deadServers = new DeadServer();
+    deadServers.add(SERVERNAME_A);
+    // I need a services instance that will return the AM
+    MasterServices services = Mockito.mock(MasterServices.class);
+    Mockito.when(services.getAssignmentManager()).thenReturn(am);
+    ServerShutdownHandler handler = new ServerShutdownHandler(this.server,
+      services, deadServers, SERVERNAME_A, false);
+    handler.process();
+    // The region in r will have been assigned.  It'll be up in zk as unassigned.
+  }
+
   /**
    * @param sn ServerName to use making startcode and server in meta
    * @param hri Region to serialize into HRegionInfo



Mime
View raw message