hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From li...@apache.org
Subject svn commit: r1558890 - in /hbase/branches/0.89-fb/src: main/java/org/apache/hadoop/hbase/client/ main/java/org/apache/hadoop/hbase/rest/client/ test/java/org/apache/hadoop/hbase/ test/java/org/apache/hadoop/hbase/client/
Date Thu, 16 Jan 2014 19:18:21 GMT
Author: liyin
Date: Thu Jan 16 19:18:21 2014
New Revision: 1558890

URL: http://svn.apache.org/r1558890
Log:
[HBASE-10360] Expose the HRegionLocations for each HTable in an efficient way

Author: liyintang

Summary:
After discussing with Calypso team, they are currently using HTable.getHRegionInfo() to get
all the HRegionLocation information. This function is relatively expensive because it needs
to scan through the META region to get all the Region to ServerAddress mapping. And Calypso
needs to issue this function call for each query. So this following new API will return the
cached HRegionLocation directly without querying the META. In the most cases, the cachedLocations
is relatively update-to-date and Calypso is also able to tolerant the stale information as
well.

  /**
   * Get all the cached HRegionLocations.
   * @param forceRefresh
   * @return
   */
  public Collection<HRegionLocation> getCachedHRegionLocations(boolean forceRefresh);

Test Plan: Run the unit test for this new API to make sure both HTable.getHRegionInfo() and
HTable.getCachedHRegionLocations() returns the same data.

Reviewers: manukranthk

Reviewed By: manukranthk

CC: hbase-eng@, ehwang

Differential Revision: https://phabricator.fb.com/D1124663

Modified:
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnection.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HTable.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HTableInterface.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java
    hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
    hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/client/TestHTable.java

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnection.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnection.java?rev=1558890&r1=1558889&r2=1558890&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnection.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnection.java Thu
Jan 16 19:18:21 2014
@@ -22,10 +22,12 @@ package org.apache.hadoop.hbase.client;
 import java.io.Closeable;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
 
+import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HRegionLocation;
 import org.apache.hadoop.hbase.HServerAddress;
@@ -421,4 +423,20 @@ public interface HConnection extends Clo
    * @throws IOException
    */
   public String getServerConfProperty(String prop) throws IOException;
+
+  /**
+   * Initialize all the HRegionLocations by scanning the META table and cache these locations
+   * properly.
+   * @param conf
+   * @param tableName
+   */
+  public void prefetchHRegionLocations(final Configuration conf, final byte[] tableName);
+
+
+  /**
+   * Get all the cached HRegionLocations
+   * @param tableName
+   * @return cachedHRegionLocations
+   */
+  public Collection<HRegionLocation> getCachedHRegionLocations(final byte [] tableName);
 }

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=1558890&r1=1558889&r2=1558890&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
Thu Jan 16 19:18:21 2014
@@ -27,19 +27,8 @@ import java.lang.reflect.UndeclaredThrow
 import java.net.ConnectException;
 import java.net.SocketTimeoutException;
 import java.nio.channels.ClosedChannelException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.Map.Entry;
-import java.util.Random;
-import java.util.Set;
-import java.util.TreeSet;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
@@ -919,13 +908,18 @@ public class HConnectionManager {
       }
     }
 
+    private void prefetchRegionCache(final byte[] tableName,
+                                     final byte[] row) {
+      prefetchRegionCache(tableName, row, this.prefetchRegionLimit);
+    }
+
     /*
      * Search .META. for the HRegionLocation info that contains the table and
      * row we're seeking. It will prefetch certain number of regions info and
      * save them to the global region cache.
      */
     private void prefetchRegionCache(final byte[] tableName,
-        final byte[] row) {
+        final byte[] row, int prefetchRegionLimit) {
       // Implement a new visitor for MetaScanner, and use it to walk through
       // the .META.
       MetaScannerVisitor visitor = new MetaScannerVisitor() {
@@ -976,8 +970,7 @@ public class HConnectionManager {
       };
       try {
         // pre-fetch certain number of regions info at region cache.
-        MetaScanner.metaScan(conf, visitor, tableName, row,
-            this.prefetchRegionLimit);
+        MetaScanner.metaScan(conf, visitor, tableName, row, prefetchRegionLimit);
       } catch (IOException e) {
         LOG.warn("Encounted problems when prefetch META table: ", e);
       }
@@ -1179,6 +1172,16 @@ public class HConnectionManager {
               e instanceof EOFException);
     }
 
+    public void prefetchHRegionLocations(final Configuration conf, final byte[] tableName)
{
+      prefetchRegionCache(tableName, null, Integer.MAX_VALUE);
+    }
+
+    public Collection<HRegionLocation> getCachedHRegionLocations(final byte [] tableName)
{
+      ConcurrentSkipListMap<byte [], HRegionLocation> tableLocations =
+        getTableLocations(tableName);
+      return tableLocations.values();
+    }
+
     /*
      * Search the cache for a location that fits our table and row key.
      * Return null if no suitable region is located. TODO: synchronization note
@@ -1335,23 +1338,21 @@ public class HConnectionManager {
       }
     }
 
-    /*
+    /**
      * Put a newly discovered HRegionLocation into the cache.
      */
     private void cacheLocation(final byte [] tableName,
         final HRegionLocation location) {
       byte [] startKey = location.getRegionInfo().getStartKey();
-      Map<byte [], HRegionLocation> tableLocations =
-        getTableLocations(tableName);
-      boolean hasNewCache = false;
+      boolean hasNewCache;
       synchronized (this.cachedRegionLocations) {
         cachedServers.add(location.getServerAddress().toString());
-        hasNewCache = (tableLocations.put(startKey, location) == null);
+        hasNewCache = (getTableLocations(tableName).put(startKey, location) == null);
       }
       if (hasNewCache) {
         LOG.debug("Cached location for " +
-            location.getRegionInfo().getRegionNameAsString() +
-            " is " + location.getServerAddress().toString());
+          location.getRegionInfo().getRegionNameAsString() +
+          " is " + location.getServerAddress().toString());
       }
     }
 

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HTable.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HTable.java?rev=1558890&r1=1558889&r2=1558890&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HTable.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HTable.java Thu Jan
16 19:18:21 2014
@@ -19,31 +19,8 @@
  */
 package org.apache.hadoop.hbase.client;
 
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.NavigableMap;
-import java.util.TreeMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.SynchronousQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.DoNotRetryIOException;
-import org.apache.hadoop.hbase.HBaseConfiguration;
-import org.apache.hadoop.hbase.HConstants;
-import org.apache.hadoop.hbase.HRegionInfo;
-import org.apache.hadoop.hbase.HRegionLocation;
-import org.apache.hadoop.hbase.HServerAddress;
-import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.NotServingRegionException;
-import org.apache.hadoop.hbase.UnknownScannerException;
+import org.apache.hadoop.hbase.*;
 import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor;
 import org.apache.hadoop.hbase.io.hfile.Compression;
 import org.apache.hadoop.hbase.io.hfile.PreloadThreadPool;
@@ -55,6 +32,15 @@ import org.apache.hadoop.hbase.util.Daem
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.hadoop.hbase.util.Writables;
 
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
 /**
  * Used to communicate with a single HBase table.
  *
@@ -468,35 +454,28 @@ public class HTable implements HTableInt
     final NavigableMap<HRegionInfo, HServerAddress> regionMap =
       new TreeMap<HRegionInfo, HServerAddress>();
 
-    MetaScannerVisitor visitor = new MetaScannerVisitor() {
-      public boolean processRow(Result rowResult) throws IOException {
-        HRegionInfo info = Writables.getHRegionInfo(
-            rowResult.getValue(HConstants.CATALOG_FAMILY,
-                HConstants.REGIONINFO_QUALIFIER));
-
-        if (!(Bytes.equals(info.getTableDesc().getName(), getTableName()))) {
-          return false;
-        }
+    for (HRegionLocation location : getCachedHRegionLocations(true)) {
+      regionMap.put(location.getRegionInfo(), location.getServerAddress());
+    }
 
-        HServerAddress server = new HServerAddress();
-        byte [] value = rowResult.getValue(HConstants.CATALOG_FAMILY,
-            HConstants.SERVER_QUALIFIER);
-        if (value != null && value.length > 0) {
-          String address = Bytes.toString(value);
-          server = new HServerAddress(address);
-        }
+    return regionMap;
+  }
 
-        if (!(info.isOffline() || info.isSplit())) {
-          regionMap.put(new UnmodifyableHRegionInfo(info), server);
-        }
-        return true;
-      }
+  /**
+   * Get all the cached HRegionLocations.
+   * @param forceRefresh
+   * @return
+   */
+  @Override
+  public Collection<HRegionLocation> getCachedHRegionLocations(boolean forceRefresh)
{
+    if (forceRefresh) {
+      connection.prefetchHRegionLocations(configuration, tableName);
+    }
 
-    };
-    MetaScanner.metaScan(configuration, visitor, tableName);
-    return regionMap;
+    return connection.getCachedHRegionLocations(tableName);
   }
 
+
   /**
    * Save the passed region information and the table's regions
    * cache.

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HTableInterface.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HTableInterface.java?rev=1558890&r1=1558889&r2=1558890&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HTableInterface.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HTableInterface.java
Thu Jan 16 19:18:21 2014
@@ -20,9 +20,11 @@
 package org.apache.hadoop.hbase.client;
 
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HRegionLocation;
 import org.apache.hadoop.hbase.HTableDescriptor;
 
 import java.io.IOException;
+import java.util.Collection;
 import java.util.List;
 
 /**
@@ -355,4 +357,12 @@ public interface HTableInterface {
   Result[] batchGet(List<Get> actions) throws IOException;
 
   void batchMutate(List<Mutation> actions) throws IOException;
+
+  /**
+   * Get all the cached HRegionLocations.
+   * @param forceRefresh
+   * @return
+   */
+  public Collection<HRegionLocation> getCachedHRegionLocations(boolean forceRefresh)
+    throws IOException;
 }

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java?rev=1558890&r1=1558889&r2=1558890&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java
Thu Jan 16 19:18:21 2014
@@ -20,44 +20,19 @@
 
 package org.apache.hadoop.hbase.rest.client;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
-import org.apache.hadoop.util.StringUtils;
-
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseConfiguration;
-import org.apache.hadoop.hbase.HConstants;
-import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.client.Mutation;
-import org.apache.hadoop.hbase.client.Row;
-import org.apache.hadoop.hbase.client.RowMutations;
-import org.apache.hadoop.hbase.client.Delete;
-import org.apache.hadoop.hbase.client.Get;
-import org.apache.hadoop.hbase.client.HTableInterface;
-import org.apache.hadoop.hbase.client.Put;
-import org.apache.hadoop.hbase.client.Result;
-import org.apache.hadoop.hbase.client.ResultScanner;
-import org.apache.hadoop.hbase.client.RowLock;
-import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.*;
+import org.apache.hadoop.hbase.client.*;
 import org.apache.hadoop.hbase.io.TimeRange;
 import org.apache.hadoop.hbase.rest.Constants;
-import org.apache.hadoop.hbase.rest.model.CellModel;
-import org.apache.hadoop.hbase.rest.model.CellSetModel;
-import org.apache.hadoop.hbase.rest.model.RowModel;
-import org.apache.hadoop.hbase.rest.model.ScannerModel;
-import org.apache.hadoop.hbase.rest.model.TableSchemaModel;
+import org.apache.hadoop.hbase.rest.model.*;
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.util.StringUtils;
+
+import java.io.IOException;
+import java.util.*;
 
 /**
  * HTable interface to remote tables accessed via REST gateway
@@ -641,4 +616,10 @@ public class RemoteHTable implements HTa
   public void batchMutate(List<Mutation> actions) throws IOException {
     throw new IOException("batchMutate not supported");
   }
+
+  @Override
+  public Collection<HRegionLocation> getCachedHRegionLocations(boolean forceRefresh)
+    throws IOException {
+    throw new IOException("atomicMutation not supported");
+  }
 }

Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java?rev=1558890&r1=1558889&r2=1558890&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
(original)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
Thu Jan 16 19:18:21 2014
@@ -78,13 +78,8 @@ import org.apache.hadoop.hbase.regionser
 import org.apache.hadoop.hbase.regionserver.MultiVersionConsistencyControl;
 import org.apache.hadoop.hbase.regionserver.Store;
 import org.apache.hadoop.hbase.regionserver.StoreFile;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.FSUtils;
+import org.apache.hadoop.hbase.util.*;
 import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
-import org.apache.hadoop.hbase.util.Pair;
-import org.apache.hadoop.hbase.util.RegionSplitter;
-import org.apache.hadoop.hbase.util.Threads;
-import org.apache.hadoop.hbase.util.Writables;
 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWrapper;
 import org.apache.hadoop.hdfs.DFSClient;
 import org.apache.hadoop.hdfs.DistributedFileSystem;
@@ -1279,6 +1274,41 @@ public class HBaseTestingUtility {
     }
   }
 
+  /**
+   *
+   * @param expectedUserRegions The number of regions which are not META or ROOT
+   */
+  public void waitForOnlineRegionsToBeAssigned(int expectedUserRegions) {
+    int actualRegions;
+
+    do {
+      try {
+        Thread.sleep(1000);
+      } catch (InterruptedException e) {} // Ignore
+
+      actualRegions = 0;
+
+      for (HRegionServer server : getOnlineRegionServers()) {
+        for (HRegion region : server.getOnlineRegions()) {
+          if (!region.getRegionInfo().isMetaRegion() && !region.getRegionInfo().isRootRegion())
{
+            actualRegions += 1;
+          }
+        }
+      }
+    } while (actualRegions != expectedUserRegions);
+
+  }
+
+  public List<HRegionServer> getOnlineRegionServers() {
+    List<HRegionServer> list = new ArrayList<HRegionServer>();
+    for (JVMClusterUtil.RegionServerThread rst : this.getMiniHBaseCluster().getRegionServerThreads())
{
+      if (rst.getRegionServer().isOnline() && !rst.getRegionServer().isStopped())
{
+        list.add(rst.getRegionServer());
+      }
+    }
+    return list;
+  }
+
 
   /**
    * Wait until <code>countOfRegion</code> in .META. have a non-empty

Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/client/TestHTable.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/client/TestHTable.java?rev=1558890&r1=1558889&r2=1558890&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/client/TestHTable.java (original)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/client/TestHTable.java Thu
Jan 16 19:18:21 2014
@@ -1,20 +1,22 @@
 package org.apache.hadoop.hbase.client;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.*;
+import org.apache.hadoop.hbase.regionserver.HRegion;
+import org.apache.hadoop.hbase.regionserver.HRegionServer;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.*;
 
+import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.NavigableMap;
 import java.util.concurrent.ThreadPoolExecutor;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.hbase.HBaseTestingUtility;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 public class TestHTable {
   final Log LOG = LogFactory.getLog(getClass());
@@ -27,33 +29,84 @@ public class TestHTable {
   /**
    * @throws java.lang.Exception
    */
-  @BeforeClass
-  public static void setUpBeforeClass() throws Exception {
+  @Before
+  public void setUp() throws Exception {
     TEST_UTIL.startMiniCluster(SLAVES);
   }
 
   /**
    * @throws java.lang.Exception
    */
-  @AfterClass
-  public static void tearDownAfterClass() throws Exception {
+  @After
+  public void tearDown() throws Exception {
     TEST_UTIL.shutdownMiniCluster();
   }
 
-  /**
-   * @throws java.lang.Exception
-   */
-  @Before
-  public void setUp() throws Exception {
-    // Nothing to do.
+  @Test
+  public void testCachedHRegionLocations() throws IOException {
+    final int NUM_REGIONS = 20;
+    byte[] tableName = Bytes.toBytes("testCachedHRegionLocations");
+    HTable table = TEST_UTIL.createTable(tableName, new byte[][]{FAMILY},
+      3, Bytes.toBytes("aaaaa"), Bytes.toBytes("zzzzz"), NUM_REGIONS);
+
+    NavigableMap<HRegionInfo, HServerAddress> allRegionsInfoMap =  table.getRegionsInfo();
+    Collection<HRegionLocation> regionLocations = table.getCachedHRegionLocations(true);
+
+    // Make sure allRegions and regionLocations containing the same information
+    verifyOnlineRegionsAndRegionLocations(allRegionsInfoMap, regionLocations, NUM_REGIONS);
+
+    HRegionServer killedServer = TEST_UTIL.getRSForFirstRegionInTable(tableName);
+    Collection<HRegion> regionsToBeMoved = killedServer.getOnlineRegions();
+    List<HRegionInfo> testRegionInfos = new ArrayList();
+
+    for (HRegion region : regionsToBeMoved) {
+      HRegionInfo regionInfo = region.getRegionInfo();
+      if (Bytes.equals(regionInfo.getTableDesc().getName(),tableName)) {
+        testRegionInfos.add(regionInfo);
+      }
+    }
+    Assert.assertTrue(testRegionInfos.size() > 0);
+
+    HServerAddress killedAddress = killedServer.getHServerInfo().getServerAddress();
+    killedServer.stop("Testing");  // Stop this region server
+
+    TEST_UTIL.waitForOnlineRegionsToBeAssigned(NUM_REGIONS);
+
+    Assert.assertTrue(killedServer.getOnlineRegions().size() == 0);
+
+    regionLocations = table.getCachedHRegionLocations(false);
+    // Make sure allRegions and regionLocations containing the same information
+    verifyOnlineRegionsAndRegionLocations(allRegionsInfoMap, regionLocations, NUM_REGIONS);
+    // Also, it has the stale information about the region location
+    for (HRegionInfo info : testRegionInfos) {
+      Assert.assertTrue(allRegionsInfoMap.get(info).equals(killedAddress));
+    }
+
+    // Update the allRegionsInfoMap and regionLocations by fetching the META table again
+    allRegionsInfoMap = table.getRegionsInfo();
+    regionLocations = table.getCachedHRegionLocations(true);
+    // Make sure allRegions and regionLocations containing the same information
+    verifyOnlineRegionsAndRegionLocations(allRegionsInfoMap, regionLocations, NUM_REGIONS);
+
+    Assert.assertTrue(killedServer.getOnlineRegions().size() == 0);
+    // Verify the new allRegionsInfoMap has been updated without the stale information
+    for (HRegionInfo info : testRegionInfos) {
+      Assert.assertFalse((allRegionsInfoMap.get(info).equals(killedAddress)));
+    }
   }
 
-  /**
-   * @throws java.lang.Exception
-   */
-  @After
-  public void tearDown() throws Exception {
-    // Nothing to do.
+  private void verifyOnlineRegionsAndRegionLocations(NavigableMap<HRegionInfo,HServerAddress>
allRegions,
+                                                     Collection<HRegionLocation> regionLocation,
+                                                     int numRegions) {
+    Assert.assertEquals(numRegions, allRegions.size());
+    Assert.assertEquals(numRegions, regionLocation.size());
+    for (HRegionLocation location : regionLocation) {
+      HRegionInfo regionInfo = location.getRegionInfo();
+      HServerAddress address = location.getServerAddress();
+      HServerAddress address2 = allRegions.get(regionInfo);
+      Assert.assertTrue(address2 != null);
+      Assert.assertEquals(address, address2);
+    }
   }
 
   @Test



Mime
View raw message