diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 810bf07ce2f..60d0441aab6 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -47,7 +47,6 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -86,7 +85,6 @@ import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; import org.apache.hadoop.hbase.client.MasterSwitchType; import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.RegionInfoBuilder; -import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.client.TableState; @@ -2548,39 +2546,6 @@ public class HMaster extends HRegionServer implements MasterServices { }); } - /** - * Return the region and current deployment for the region containing - * the given row. If the region cannot be found, returns null. If it - * is found, but not currently deployed, the second element of the pair - * may be null. - */ - @VisibleForTesting // Used by TestMaster. - Pair getTableRegionForRow( - final TableName tableName, final byte [] rowKey) - throws IOException { - final AtomicReference> result = new AtomicReference<>(null); - - MetaTableAccessor.Visitor visitor = new MetaTableAccessor.Visitor() { - @Override - public boolean visit(Result data) throws IOException { - if (data == null || data.size() <= 0) { - return true; - } - Pair pair = - new Pair<>(MetaTableAccessor.getRegionInfo(data), - MetaTableAccessor.getServerName(data,0)); - if (!pair.getFirst().getTable().equals(tableName)) { - return false; - } - result.set(pair); - return true; - } - }; - - MetaTableAccessor.scanMeta(clusterConnection, visitor, tableName, rowKey, 1); - return result.get(); - } - private long modifyTable(final TableName tableName, final TableDescriptorGetter newDescriptorGetter, final long nonceGroup, final long nonce) throws IOException { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java index f81c94eac26..ce047615d49 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java @@ -25,7 +25,9 @@ import static org.junit.Assert.fail; import java.io.IOException; import java.util.List; - +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; +import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.HBaseClassTestRule; @@ -42,6 +44,7 @@ import org.apache.hadoop.hbase.UnknownRegionException; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.RegionInfoBuilder; +import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.client.TableState; import org.apache.hadoop.hbase.testclassification.MasterTests; @@ -92,6 +95,35 @@ public class TestMaster { TEST_UTIL.shutdownMiniCluster(); } + /** + * Return the region and current deployment for the region containing the given row. If the region + * cannot be found, returns null. If it is found, but not currently deployed, the second element + * of the pair may be null. + */ + private Pair getTableRegionForRow(HMaster master, TableName tableName, + byte[] rowKey) throws IOException { + final AtomicReference> result = new AtomicReference<>(null); + + MetaTableAccessor.Visitor visitor = new MetaTableAccessor.Visitor() { + @Override + public boolean visit(Result data) throws IOException { + if (data == null || data.size() <= 0) { + return true; + } + Pair pair = new Pair<>(MetaTableAccessor.getRegionInfo(data), + MetaTableAccessor.getServerName(data, 0)); + if (!pair.getFirst().getTable().equals(tableName)) { + return false; + } + result.set(pair); + return true; + } + }; + + MetaTableAccessor.scanMeta(master.getConnection(), visitor, tableName, rowKey, 1); + return result.get(); + } + @Test @SuppressWarnings("deprecation") public void testMasterOpsWhileSplitting() throws Exception { @@ -126,8 +158,7 @@ public class TestMaster { // We have three regions because one is split-in-progress assertEquals(3, tableRegions.size()); LOG.info("Making sure we can call getTableRegionClosest while opening"); - Pair pair = - m.getTableRegionForRow(TABLENAME, Bytes.toBytes("cde")); + Pair pair = getTableRegionForRow(m, TABLENAME, Bytes.toBytes("cde")); LOG.info("Result is: " + pair); Pair tableRegionFromName = MetaTableAccessor.getRegion(m.getConnection(),