From 040dacd437e22b773679b7bc68c13b7926cf0e90 Mon Sep 17 00:00:00 2001 From: Josh Elser Date: Wed, 19 Jan 2022 14:11:10 -0500 Subject: [PATCH 1/2] HBASE-26687 Avoid the newBuilder(RegionInfo) constructor in RegionInfoMismatchTool A previously-fixed bug in HBase might break this tool in that the new RegionInfo built by the Tool is still incorrect because the region name and region encoded name are not recomputed. Thankfully, the sanity check on the tool prevented any damage from being done to hbase:meta. --- .../java/org/apache/hbase/RegionInfoMismatchTool.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hbase-hbck2/src/main/java/org/apache/hbase/RegionInfoMismatchTool.java b/hbase-hbck2/src/main/java/org/apache/hbase/RegionInfoMismatchTool.java index bc37423bb9..01073ee71c 100644 --- a/hbase-hbck2/src/main/java/org/apache/hbase/RegionInfoMismatchTool.java +++ b/hbase-hbck2/src/main/java/org/apache/hbase/RegionInfoMismatchTool.java @@ -148,9 +148,17 @@ void run(PrintStream out, boolean fix) throws IOException, DeserializationExcept } // Third component of a region name is just a literal numeric (not a binary-encoded long) long regionId = Long.parseLong(Bytes.toString(regionNameParts[2])); - RegionInfo correctedRegionInfo = RegionInfoBuilder.newBuilder(wrongRegionInfo) + // HBASE-24500: We cannot use newBuilder(RegionInfo) because it will copy the NAME and encodedName + // from the original RegionInfo instead of re-computing it. Copy all of the fields by hand + // which will force the new RegionInfo to recompute the NAME/encodedName fields. + RegionInfo correctedRegionInfo = RegionInfoBuilder.newBuilder(wrongRegionInfo.getTable()) + // regionId shouldn't need to be re-set .setRegionId(regionId) + .setStartKey(wrongRegionInfo.getStartKey()) + .setEndKey(wrongRegionInfo.getEndKey()) .setReplicaId(0) + .setOffline(wrongRegionInfo.isOffline()) + .setSplit(wrongRegionInfo.isSplit()) .build(); String rowkeyEncodedRegionName = HBCKRegionInfo.encodeRegionName(regionName); From d03fc33b405556720d4e6a74ab88d30e4bcbb879 Mon Sep 17 00:00:00 2001 From: Josh Elser Date: Wed, 19 Jan 2022 17:48:28 -0500 Subject: [PATCH 2/2] Fix checkstyle and remove an unnecessary comment --- .../java/org/apache/hbase/RegionInfoMismatchTool.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hbase-hbck2/src/main/java/org/apache/hbase/RegionInfoMismatchTool.java b/hbase-hbck2/src/main/java/org/apache/hbase/RegionInfoMismatchTool.java index 01073ee71c..494191ecf1 100644 --- a/hbase-hbck2/src/main/java/org/apache/hbase/RegionInfoMismatchTool.java +++ b/hbase-hbck2/src/main/java/org/apache/hbase/RegionInfoMismatchTool.java @@ -148,11 +148,11 @@ void run(PrintStream out, boolean fix) throws IOException, DeserializationExcept } // Third component of a region name is just a literal numeric (not a binary-encoded long) long regionId = Long.parseLong(Bytes.toString(regionNameParts[2])); - // HBASE-24500: We cannot use newBuilder(RegionInfo) because it will copy the NAME and encodedName - // from the original RegionInfo instead of re-computing it. Copy all of the fields by hand - // which will force the new RegionInfo to recompute the NAME/encodedName fields. + // HBASE-24500: We cannot use newBuilder(RegionInfo) because it will copy the NAME and + // encodedName from the original RegionInfo instead of re-computing it. Copy all of the + // fields by hand which will force the new RegionInfo to recompute the NAME/encodedName + // fields. RegionInfo correctedRegionInfo = RegionInfoBuilder.newBuilder(wrongRegionInfo.getTable()) - // regionId shouldn't need to be re-set .setRegionId(regionId) .setStartKey(wrongRegionInfo.getStartKey()) .setEndKey(wrongRegionInfo.getEndKey())