Repository: hbase
Updated Branches:
  refs/heads/branch-1.3 5893c7784 -> 4d568a968


HBASE-20229 ConnectionImplementation.locateRegions() returns duplicated entries 
when region replication is on


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/4d568a96
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/4d568a96
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/4d568a96

Branch: refs/heads/branch-1.3
Commit: 4d568a968b1d57787ab6816bded123211d2ce70f
Parents: 5893c77
Author: Toshihiro Suzuki <brfrn...@gmail.com>
Authored: Wed Apr 25 13:34:03 2018 -0700
Committer: Andrew Purtell <apurt...@apache.org>
Committed: Wed Apr 25 16:18:39 2018 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/client/ConnectionManager.java  |  3 ++
 .../client/TestConnectionImplementation.java    | 48 +++++++++++++++++++-
 2 files changed, 49 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/4d568a96/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
----------------------------------------------------------------------
diff --git 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
 
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
index dd4930f..ab6dd51 100644
--- 
a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
+++ 
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
@@ -1105,6 +1105,9 @@ class ConnectionManager {
       NavigableMap<HRegionInfo, ServerName> regions = 
MetaScanner.allTableRegions(this, tableName);
       final List<HRegionLocation> locations = new ArrayList<HRegionLocation>();
       for (HRegionInfo regionInfo : regions.keySet()) {
+        if (!RegionReplicaUtil.isDefaultReplica(regionInfo)) {
+          continue;
+        }
         RegionLocations list = locateRegion(tableName, 
regionInfo.getStartKey(), useCache, true);
         if (list != null) {
           for (HRegionLocation loc : list.getRegionLocations()) {

http://git-wip-us.apache.org/repos/asf/hbase/blob/4d568a96/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionImplementation.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionImplementation.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionImplementation.java
index 30f44ce..2256340 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionImplementation.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestConnectionImplementation.java
@@ -18,20 +18,32 @@
 
 package org.apache.hadoop.hbase.client;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.io.IOException;
+import java.net.UnknownHostException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
 import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HColumnDescriptor;
 import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.HRegionLocation;
+import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.testclassification.ClientTests;
 import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.util.Bytes;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import java.net.UnknownHostException;
-
 /**
  * Tests that we fail fast when hostname resolution is not working and do not 
cache
  * unresolved InetSocketAddresses.
@@ -91,4 +103,36 @@ public class TestConnectionImplementation {
     conn.getAdmin(badHost);
     fail("Obtaining client to unresolvable hostname should have failed");
   }
+
+  @Test
+  public void testLocateRegionsWithRegionReplicas() throws IOException {
+    int regionReplication = 3;
+    byte[] family = Bytes.toBytes("cf");
+    TableName tableName = 
TableName.valueOf("testLocateRegionsWithRegionReplicas");
+
+    // Create a table with region replicas
+    HTableDescriptor desc = new HTableDescriptor(tableName);
+    desc.addFamily(new HColumnDescriptor(family));
+    desc.setRegionReplication(regionReplication);
+    testUtil.getConnection().getAdmin().createTable(desc);
+
+    try (ConnectionManager.HConnectionImplementation con =
+      (ConnectionManager.HConnectionImplementation) ConnectionFactory.
+        createConnection(testUtil.getConfiguration())) {
+
+      // Get locations of the regions of the table
+      List<HRegionLocation> locations = con.locateRegions(tableName, false, 
false);
+
+      // The size of the returned locations should be 3
+      assertEquals(regionReplication, locations.size());
+
+      // The replicaIds of the returned locations should be 0, 1 and 2
+      Set<Integer> expectedReplicaIds = new HashSet<>(Arrays.asList(0, 1, 2));
+      for (HRegionLocation location : locations) {
+        
assertTrue(expectedReplicaIds.remove(location.getRegionInfo().getReplicaId()));
+      }
+    } finally {
+      testUtil.deleteTable(tableName);
+    }
+  }
 }

Reply via email to