From 9e8b7cf64dd05c9f89073a0b473b11da96b62bda Mon Sep 17 00:00:00 2001 From: Sergey Soldatov Date: Thu, 11 Jan 2018 13:40:38 -0800 Subject: HBASE-19774 incorrect behavior of locateRegionInMeta --- .../hbase/client/ConnectionImplementation.java | 8 +++--- .../hbase/client/TestScannersFromClientSide.java | 30 +++++++++++++++++----- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java index 562630f..e047c59 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java @@ -786,11 +786,13 @@ class ConnectionImplementation implements ClusterConnection, Closeable { // build the key of the meta region we should be looking for. // the extra 9's on the end are necessary to allow "exact" matches // without knowing the precise region names. - byte[] metaKey = RegionInfo.createRegionName(tableName, row, HConstants.NINES, false); + byte[] metaStartKey = RegionInfo.createRegionName(tableName, row, HConstants.NINES, false); + byte[] metaStopKey = RegionInfo.createRegionName(tableName, HConstants.EMPTY_START_ROW, "", false); Scan s = new Scan(); s.setReversed(true); - s.withStartRow(metaKey); + s.withStartRow(metaStartKey); + s.withStopRow(metaStopKey, true); s.addFamily(HConstants.CATALOG_FAMILY); if (this.useMetaReplicas) { @@ -908,7 +910,7 @@ class ConnectionImplementation implements ClusterConnection, Closeable { // Only relocate the parent region if necessary if(!(e instanceof RegionOfflineException || e instanceof NoServerForRegionException)) { - relocateRegion(TableName.META_TABLE_NAME, metaKey, replicaId); + relocateRegion(TableName.META_TABLE_NAME, metaStartKey, replicaId); } } finally { userRegionLock.unlock(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java index 5441e2b..7885e35 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java @@ -16,12 +16,6 @@ */ package org.apache.hadoop.hbase.client; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -41,6 +35,7 @@ import org.apache.hadoop.hbase.HTestConst; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.filter.BinaryComparator; import org.apache.hadoop.hbase.filter.ColumnPrefixFilter; import org.apache.hadoop.hbase.filter.ColumnRangeFilter; @@ -61,6 +56,8 @@ import org.junit.rules.TestName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.junit.Assert.*; + /** * A client-side test, mostly testing scanners with various parameters. */ @@ -236,6 +233,27 @@ public class TestScannersFromClientSide { clientScanner.getCacheSize() <= 1); } + /** + * Scan on not existing table should throw the exception with correct message + */ + @Test + public void testScannerForNotExistingTable () { + String[] tableNames = {"A", "Z", "A:A", "Z:Z"}; + for(String tableName : tableNames) { + try { + Table table = TEST_UTIL.getConnection().getTable(TableName.valueOf(tableName)); + testSmallScan(table, true, 1, 5); + fail("TableNotFoundException was not thrown"); + } catch (TableNotFoundException e) { + // We expect that the message for TableNotFoundException would have only the table name only + // Otherwise that would mean that localeRegionInMeta doesn't work properly + assertEquals(e.getMessage(), tableName); + } catch (Exception e) { + fail("Unexpected exception " + e.getMessage()); + } + } + } + @Test public void testSmallScan() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); -- 2.5.4 (Apple Git-61)