You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by hu...@apache.org on 2018/04/25 20:37:02 UTC
hbase git commit: HBASE-20229
ConnectionImplementation.locateRegions() returns duplicated entries when
region replication is on
Repository: hbase
Updated Branches:
refs/heads/branch-1 6685b62ab -> f11cf007a
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/f11cf007
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/f11cf007
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/f11cf007
Branch: refs/heads/branch-1
Commit: f11cf007a2233343781ff235a8b2282fa717c176
Parents: 6685b62
Author: Toshihiro Suzuki <br...@gmail.com>
Authored: Wed Apr 25 13:34:03 2018 -0700
Committer: Huaxiang Sun <hs...@cloudera.com>
Committed: Wed Apr 25 13:36:12 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/f11cf007/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 4e05a22..993f4d1 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
@@ -1138,6 +1138,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/f11cf007/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);
+ }
+ }
}