From 6b93373a0a88109b1701ad35a1895648c8916989 Mon Sep 17 00:00:00 2001 From: Joseph295 <517536891@qq.com> Date: Sun, 27 Sep 2020 11:05:16 +0800 Subject: [PATCH] HBASE-25088 CatalogFamilyFormat/MetaTableAccessor.parseRegionInfoFromRegionName incorrectly setEndKey to regionId (#2462) Signed-off-by: Duo Zhang --- .../hadoop/hbase/MetaTableAccessor.java | 7 +----- .../hadoop/hbase/TestMetaTableAccessor.java | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java index 7cf6bb13831..fc4ebc489f9 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java @@ -329,12 +329,7 @@ public class MetaTableAccessor { long regionId = Long.parseLong(Bytes.toString(fields[2])); int replicaId = fields.length > 3 ? Integer.parseInt(Bytes.toString(fields[3]), 16) : 0; return RegionInfoBuilder.newBuilder(TableName.valueOf(fields[0])) - .setStartKey(fields[1]) - .setEndKey(fields[2]) - .setSplit(false) - .setRegionId(regionId) - .setReplicaId(replicaId) - .build(); + .setStartKey(fields[1]).setRegionId(regionId).setReplicaId(replicaId).build(); } /** diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java index 20e0edd4ebb..fae0ebc6a67 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java @@ -404,6 +404,29 @@ public class TestMetaTableAccessor { MetaTableAccessor.parseReplicaIdFromServerColumn(Bytes.toBytes(column6))); } + /** + * The info we can get from the regionName is: table name, start key, regionId, replicaId. + */ + @Test + public void testParseRegionInfoFromRegionName() throws IOException { + RegionInfo originalRegionInfo = RegionInfoBuilder.newBuilder( + TableName.valueOf(name.getMethodName())).setRegionId(999999L) + .setStartKey(Bytes.toBytes("2")).setEndKey(Bytes.toBytes("3")) + .setReplicaId(1).build(); + RegionInfo newParsedRegionInfo = MetaTableAccessor + .parseRegionInfoFromRegionName(originalRegionInfo.getRegionName()); + assertEquals("Parse TableName error", originalRegionInfo.getTable(), + newParsedRegionInfo.getTable()); + assertEquals("Parse regionId error", originalRegionInfo.getRegionId(), + newParsedRegionInfo.getRegionId()); + assertTrue("Parse startKey error", Bytes.equals(originalRegionInfo.getStartKey(), + newParsedRegionInfo.getStartKey())); + assertEquals("Parse replicaId error", originalRegionInfo.getReplicaId(), + newParsedRegionInfo.getReplicaId()); + assertTrue("We can't parse endKey from regionName only", + Bytes.equals(HConstants.EMPTY_END_ROW, newParsedRegionInfo.getEndKey())); + } + @Test public void testMetaReaderGetColumnMethods() { assertArrayEquals(HConstants.SERVER_QUALIFIER, MetaTableAccessor.getServerColumn(0));