use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.
the class TestMasterObserverPostCalls method testPostModifyNamespace.
@Test
public void testPostModifyNamespace() throws IOException {
final Admin admin = UTIL.getAdmin();
final String ns = "postmodifyns";
NamespaceDescriptor nsDesc = NamespaceDescriptor.create(ns).build();
admin.createNamespace(nsDesc);
HMaster master = UTIL.getMiniHBaseCluster().getMaster();
MasterObserverForTest observer = master.getMasterCoprocessorHost().findCoprocessor(MasterObserverForTest.class);
int preCount = observer.postHookCalls.get();
try {
admin.modifyNamespace(NamespaceDescriptor.create("nonexistent").build());
fail("Modifying a missing namespace should fail");
} catch (IOException e) {
// Pass
}
int postCount = observer.postHookCalls.get();
assertEquals("Expected no invocations of postModifyNamespace when the operation fails", preCount, postCount);
// Validate that the postDeletNS hook is invoked
preCount = observer.postHookCalls.get();
admin.modifyNamespace(NamespaceDescriptor.create(nsDesc).addConfiguration("foo", "bar").build());
postCount = observer.postHookCalls.get();
assertEquals("Expected 1 invocation of postModifyNamespace", preCount + 1, postCount);
}
use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.
the class TestHBCKSCP method test.
@Test
public void test() throws Exception {
// we are about to do one for it?
SingleProcessHBaseCluster cluster = this.util.getHBaseCluster();
// Assert that we have three RegionServers. Test depends on there being multiple.
assertEquals(RS_COUNT, cluster.getLiveRegionServerThreads().size());
int count;
try (Table table = createTable(TableName.valueOf(this.name.getMethodName()))) {
// Load the table with a bit of data so some logs to split and some edits in each region.
this.util.loadTable(table, HBaseTestingUtil.COLUMNS[0]);
count = util.countRows(table);
}
assertTrue("expected some rows", count > 0);
// Make the test easier by not working on server hosting meta...
// Find another RS. Purge it from Master memory w/o running SCP (if
// SCP runs, it will clear entries from hbase:meta which frustrates
// our attempt at manufacturing 'Unknown Servers' condition).
int metaIndex = this.util.getMiniHBaseCluster().getServerWithMeta();
int rsIndex = (metaIndex + 1) % RS_COUNT;
ServerName rsServerName = cluster.getRegionServer(rsIndex).getServerName();
HMaster master = cluster.getMaster();
// Get a Region that is on the server.
RegionInfo rsRI = master.getAssignmentManager().getRegionsOnServer(rsServerName).get(0);
Result r = MetaTableAccessor.getRegionResult(master.getConnection(), rsRI.getRegionName());
// Assert region is OPEN.
assertEquals(RegionState.State.OPEN.toString(), Bytes.toString(r.getValue(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER)));
ServerName serverName = CatalogFamilyFormat.getServerName(r, 0);
assertEquals(rsServerName, serverName);
// moveFrom adds to dead servers and adds it to processing list only we will
// not be processing this server 'normally'. Remove it from processing by
// calling 'finish' and then remove it from dead servers so rsServerName
// becomes an 'Unknown Server' even though it is still around.
LOG.info("Killing {}", rsServerName);
cluster.killRegionServer(rsServerName);
master.getServerManager().moveFromOnlineToDeadServers(rsServerName);
master.getServerManager().getDeadServers().removeDeadServer(rsServerName);
master.getAssignmentManager().getRegionStates().removeServer(rsServerName);
// Kill the server. Nothing should happen since an 'Unknown Server' as far
// as the Master is concerned; i.e. no SCP.
HRegionServer hrs = cluster.getRegionServer(rsServerName);
while (!hrs.isStopped()) {
Threads.sleep(10);
}
LOG.info("Dead {}", rsServerName);
// Now assert still references in hbase:meta to the 'dead' server -- they haven't been
// cleaned up by an SCP or by anything else.
assertTrue(searchMeta(master, rsServerName));
// Assert region is OPEN on dead server still.
r = MetaTableAccessor.getRegionResult(master.getConnection(), rsRI.getRegionName());
assertEquals(RegionState.State.OPEN.toString(), Bytes.toString(r.getValue(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER)));
serverName = CatalogFamilyFormat.getServerName(r, 0);
assertNotNull(cluster.getRegionServer(serverName));
assertEquals(rsServerName, serverName);
// I now have 'Unknown Server' references in hbase:meta; i.e. Server references
// with no corresponding SCP. Queue one.
long pid = scheduleHBCKSCP(rsServerName, master);
assertNotEquals(Procedure.NO_PROC_ID, pid);
while (master.getMasterProcedureExecutor().getActiveProcIds().contains(pid)) {
Threads.sleep(10);
}
// After SCP, assert region is OPEN on new server.
r = MetaTableAccessor.getRegionResult(master.getConnection(), rsRI.getRegionName());
assertEquals(RegionState.State.OPEN.toString(), Bytes.toString(r.getValue(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER)));
serverName = CatalogFamilyFormat.getServerName(r, 0);
assertNotNull(cluster.getRegionServer(serverName));
assertNotEquals(rsServerName, serverName);
// Make sure no mention of old server post SCP.
assertFalse(searchMeta(master, rsServerName));
}
use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.
the class MasterProcedureTestingUtility method waitBackupMaster.
public static void waitBackupMaster(final HBaseTestingUtil testUtil, final HMaster oldMaster) throws Exception {
SingleProcessHBaseCluster cluster = testUtil.getMiniHBaseCluster();
HMaster newMaster = cluster.getMaster();
while (newMaster == null || newMaster == oldMaster) {
Thread.sleep(250);
newMaster = cluster.getMaster();
}
while (!(newMaster.isActiveMaster() && newMaster.isInitialized())) {
Thread.sleep(250);
}
}
use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.
the class TestMetaFixer method testOverlapCommon.
private void testOverlapCommon(final TableName tn) throws Exception {
Table t = TEST_UTIL.createMultiRegionTable(tn, HConstants.CATALOG_FAMILY);
TEST_UTIL.loadTable(t, HConstants.CATALOG_FAMILY);
List<RegionInfo> ris = MetaTableAccessor.getTableRegions(TEST_UTIL.getConnection(), tn);
assertTrue(ris.size() > 5);
HMaster services = TEST_UTIL.getHBaseCluster().getMaster();
services.getCatalogJanitor().scan();
Report report = services.getCatalogJanitor().getLastReport();
assertTrue(report.isEmpty());
// Make a simple overlap spanning second and third region.
makeOverlap(services, ris.get(1), ris.get(3));
makeOverlap(services, ris.get(2), ris.get(3));
makeOverlap(services, ris.get(2), ris.get(4));
}
use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.
the class TestMetaFixer method testOverlap.
@Test
public void testOverlap() throws Exception {
TableName tn = TableName.valueOf(this.name.getMethodName());
testOverlapCommon(tn);
HMaster services = TEST_UTIL.getHBaseCluster().getMaster();
HbckChore hbckChore = services.getHbckChore();
CatalogJanitor cj = services.getCatalogJanitor();
cj.scan();
Report report = cj.getLastReport();
assertEquals(6, report.getOverlaps().size());
assertEquals(1, MetaFixer.calculateMerges(10, report.getOverlaps()).size());
MetaFixer fixer = new MetaFixer(services);
fixer.fixOverlaps(report);
HBaseTestingUtil.await(10, () -> {
try {
if (cj.scan() > 0) {
// It submits GC once, then it will immediately kick off another GC to test if
// GCMultipleMergedRegionsProcedure is idempotent. If it is not, it will create
// a hole.
Map<RegionInfo, Result> mergedRegions = cj.getLastReport().mergedRegions;
for (Map.Entry<RegionInfo, Result> e : mergedRegions.entrySet()) {
List<RegionInfo> parents = CatalogFamilyFormat.getMergeRegions(e.getValue().rawCells());
if (parents != null) {
ProcedureExecutor<MasterProcedureEnv> pe = services.getMasterProcedureExecutor();
pe.submitProcedure(new GCMultipleMergedRegionsProcedure(pe.getEnvironment(), e.getKey(), parents));
}
}
return true;
}
return false;
} catch (Exception e) {
throw new RuntimeException(e);
}
});
// Wait until all GCs settled down
HBaseTestingUtil.await(10, () -> {
return services.getMasterProcedureExecutor().getActiveProcIds().isEmpty();
});
// No orphan regions on FS
hbckChore.choreForTesting();
assertEquals(0, hbckChore.getOrphanRegionsOnFS().size());
// No holes reported.
cj.scan();
final Report postReport = cj.getLastReport();
assertTrue(postReport.isEmpty());
}
Aggregations