HBASE-23321 [hbck2] fixHoles of fixMeta doesn't update in-memory state

This commit is contained in:
stack 2019-11-19 12:15:43 -08:00
parent 96fd75bd0e
commit bcd2aa9a9e
2 changed files with 18 additions and 12 deletions

View File

@ -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);
}
}

View File

@ -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<RegionInfo> 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) {