From bcd2aa9a9e5d2c1d4829d586ef2488b23a58ffe4 Mon Sep 17 00:00:00 2001 From: stack Date: Tue, 19 Nov 2019 12:15:43 -0800 Subject: [PATCH] HBASE-23321 [hbck2] fixHoles of fixMeta doesn't update in-memory state --- .../apache/hadoop/hbase/master/MetaFixer.java | 13 +++++++------ .../hadoop/hbase/master/TestMetaFixer.java | 17 +++++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetaFixer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetaFixer.java index 3477ec6e644..281df1ecc01 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetaFixer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetaFixer.java @@ -29,7 +29,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.RegionInfoBuilder; import org.apache.hadoop.hbase.exceptions.MergeRegionException; @@ -99,11 +98,13 @@ class MetaFixer { HRegion.createRegionDir(configuration, ri, FSUtils.getRootDir(configuration)); // If an error here, then we'll have a region in the filesystem but not // in hbase:meta (if the below fails). Should be able to rerun the fix. - // The second call to createRegionDir will just go through. Idempotent. - Put put = MetaTableAccessor.makePutFromRegionInfo(ri, HConstants.LATEST_TIMESTAMP); - MetaTableAccessor.putsToMetaTable(this.masterServices.getConnection(), - Collections.singletonList(put)); - LOG.info("Fixed hole by adding {}; region is NOT assigned (assign to online).", ri); + // Add to hbase:meta and then update in-memory state so it knows of new + // Region; addRegionToMeta adds region and adds a state column set to CLOSED. + MetaTableAccessor.addRegionToMeta(this.masterServices.getConnection(), ri); + this.masterServices.getAssignmentManager().getRegionStates(). + updateRegionState(ri, RegionState.State.CLOSED); + LOG.info("Fixed hole by adding {} in CLOSED state; region NOT assigned (assign to ONLINE).", + ri); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaFixer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaFixer.java index aba00fed336..16768a28fa6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaFixer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaFixer.java @@ -17,6 +17,7 @@ */ package org.apache.hadoop.hbase.master; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.IOException; @@ -35,7 +36,6 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.util.Threads; import org.junit.AfterClass; -import org.junit.Assert; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Rule; @@ -75,6 +75,7 @@ public class TestMetaFixer { TEST_UTIL.createMultiRegionTable(tn, HConstants.CATALOG_FAMILY); List ris = MetaTableAccessor.getTableRegions(TEST_UTIL.getConnection(), tn); MasterServices services = TEST_UTIL.getHBaseCluster().getMaster(); + int initialSize = services.getAssignmentManager().getRegionStates().getRegionStates().size(); services.getCatalogJanitor().scan(); CatalogJanitor.Report report = services.getCatalogJanitor().getLastReport(); assertTrue(report.isEmpty()); @@ -83,19 +84,23 @@ public class TestMetaFixer { deleteRegion(services, ris.get(ris.size() -1)); deleteRegion(services, ris.get(3)); deleteRegion(services, ris.get(0)); + assertEquals(initialSize - 3, + services.getAssignmentManager().getRegionStates().getRegionStates().size()); services.getCatalogJanitor().scan(); report = services.getCatalogJanitor().getLastReport(); - Assert.assertEquals(report.toString(), 3, report.getHoles().size()); + assertEquals(report.toString(), 3, report.getHoles().size()); MetaFixer fixer = new MetaFixer(services); fixer.fixHoles(report); services.getCatalogJanitor().scan(); report = services.getCatalogJanitor().getLastReport(); assertTrue(report.toString(), report.isEmpty()); + assertEquals(initialSize, + services.getAssignmentManager().getRegionStates().getRegionStates().size()); // Disable and reenable so the added regions get reassigned. TEST_UTIL.getAdmin().disableTable(tn); TEST_UTIL.getAdmin().enableTable(tn); ris = MetaTableAccessor.getTableRegions(TEST_UTIL.getConnection(), tn); - Assert.assertEquals(originalCount, ris.size()); + assertEquals(originalCount, ris.size()); } /** @@ -121,7 +126,7 @@ public class TestMetaFixer { report = services.getCatalogJanitor().getLastReport(); assertTrue(report.isEmpty()); ris = MetaTableAccessor.getTableRegions(TEST_UTIL.getConnection(), tn); - Assert.assertEquals(0, ris.size()); + assertEquals(0, ris.size()); } private static void makeOverlap(MasterServices services, RegionInfo a, RegionInfo b) @@ -154,8 +159,8 @@ public class TestMetaFixer { Threads.sleep(10000); services.getCatalogJanitor().scan(); report = services.getCatalogJanitor().getLastReport(); - Assert.assertEquals(6, report.getOverlaps().size()); - Assert.assertEquals(1, MetaFixer.calculateMerges(10, report.getOverlaps()).size()); + assertEquals(6, report.getOverlaps().size()); + assertEquals(1, MetaFixer.calculateMerges(10, report.getOverlaps()).size()); MetaFixer fixer = new MetaFixer(services); fixer.fixOverlaps(report); while (true) {