@Test public void testMasterCoprocessorsReported() { // HBASE 4070: Improve region server metrics to report loaded coprocessors // to master: verify that the master is reporting the correct set of // loaded coprocessors. final String loadedMasterCoprocessorsVerify = "[" + masterCoprocessor.getSimpleName() + "]"; String loadedMasterCoprocessors = java.util.Arrays.toString( TEST_UTIL.getHBaseCluster().getMaster().getMasterCoprocessors()); assertEquals(loadedMasterCoprocessorsVerify, loadedMasterCoprocessors); }
@Test public void testErrorAfterUpdate() throws IOException, ReplicationException { ((MockHMaster) UTIL.getHBaseCluster().getMaster()).reset(false); doTest(); }
@Test public void testIsMetaWhenAllHealthy() throws InterruptedException { HMaster m = UTIL.getMiniHBaseCluster().getMaster(); assertTrue(m.waitForMetaOnline()); }
@Test public void testFsUriSetProperly() throws Exception { HMaster master = UTIL.getMiniHBaseCluster().getMaster(); MasterFileSystem fs = master.getMasterFileSystem(); Path masterRoot = FSUtils.getRootDir(fs.getConfiguration()); Path rootDir = FSUtils.getRootDir(fs.getFileSystem().getConf()); // make sure the fs and the found root dir have the same scheme LOG.debug("from fs uri:" + FileSystem.getDefaultUri(fs.getFileSystem().getConf())); LOG.debug("from configuration uri:" + FileSystem.getDefaultUri(fs.getConfiguration())); // make sure the set uri matches by forcing it. assertEquals(masterRoot, rootDir); } }
@Test public void testCleanupMetaWAL() throws Exception { TEST_UTIL.createTable(TableName.valueOf("test"), "cf"); HRegionServer serverWithMeta = TEST_UTIL.getMiniHBaseCluster() .getRegionServer(TEST_UTIL.getMiniHBaseCluster().getServerWithMeta()); TEST_UTIL.getAdmin() .move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes(), null); LOG.info("KILL"); TEST_UTIL.getMiniHBaseCluster().killRegionServer(serverWithMeta.getServerName()); LOG.info("WAIT"); TEST_UTIL.waitFor(30000, () -> TEST_UTIL.getMiniHBaseCluster().getMaster().getProcedures().stream() .filter(p -> p instanceof ServerCrashProcedure && p.isFinished()).count() > 0); LOG.info("DONE WAITING"); MasterFileSystem fs = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem(); Path walPath = new Path(fs.getWALRootDir(), HConstants.HREGION_LOGDIR_NAME); for (FileStatus status : FSUtils.listStatus(fs.getFileSystem(), walPath)) { if (status.getPath().toString().contains(SPLITTING_EXT)) { fail("Should not have splitting wal dir here:" + status); } } } }
private RegionInfo getAndCheckSingleTableRegion(final List<HRegion> regions) throws IOException, InterruptedException { assertEquals(1, regions.size()); RegionInfo hri = regions.get(0).getRegionInfo(); AssignmentTestingUtil.waitForAssignment(cluster.getMaster().getAssignmentManager(), hri); return hri; }
private void validateSingleRegionServerAssignment(Connection connection, int numRegions, int numReplica) throws IOException { SnapshotOfRegionAssignmentFromMeta snapshot = new SnapshotOfRegionAssignmentFromMeta( connection); snapshot.initialize(); Map<RegionInfo, ServerName> regionToServerMap = snapshot.getRegionToRegionServerMap(); assertEquals(regionToServerMap.size(), numRegions * numReplica); Map<ServerName, List<RegionInfo>> serverToRegionMap = snapshot.getRegionServerToRegionMap(); assertEquals("One Region Only", 1, serverToRegionMap.keySet().size()); for (Map.Entry<ServerName, List<RegionInfo>> entry : serverToRegionMap.entrySet()) { if (entry.getKey().equals(TEST_UTIL.getHBaseCluster().getMaster().getServerName())) { continue; } assertEquals(entry.getValue().size(), numRegions * numReplica); } } }
private void resetProcExecutorTestingKillFlag() { ProcedureExecutor<MasterProcedureEnv> procExec = UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor(); ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false); assertTrue("expected executor to be running", procExec.isRunning()); }
private void testDeleteWithFailoverAtStep(final int step) throws Exception { final TableName tableName = TableName.valueOf("testDeleteWithFailoverAtStep" + step); // create the table byte[][] splitKeys = null; RegionInfo[] regions = MasterProcedureTestingUtility.createTable( getMasterProcedureExecutor(), tableName, splitKeys, "f1", "f2"); Path tableDir = FSUtils.getTableDir(getRootDir(), tableName); MasterProcedureTestingUtility.validateTableCreation( UTIL.getHBaseCluster().getMaster(), tableName, regions, "f1", "f2"); UTIL.getAdmin().disableTable(tableName); ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); ProcedureTestingUtility.setKillBeforeStoreUpdate(procExec, true); ProcedureTestingUtility.setToggleKillBeforeStoreUpdate(procExec, true); // Start the Delete procedure && kill the executor long procId = procExec.submitProcedure( new DeleteTableProcedure(procExec.getEnvironment(), tableName)); testRecoveryAndDoubleExecution(UTIL, procId, step); MasterProcedureTestingUtility.validateTableDeletion( UTIL.getHBaseCluster().getMaster(), tableName); }
@BeforeClass public static void setUp() throws Exception { UTIL.getConfiguration().setLong(ProcedureExecutor.WORKER_KEEP_ALIVE_TIME_CONF_KEY, 5000); UTIL.getConfiguration().setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 4); UTIL.getConfiguration().set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, MyCP.class.getName()); UTIL.startMiniCluster(3); CORE_POOL_SIZE = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getCorePoolSize(); TABLE_COUNT = 50 * CORE_POOL_SIZE; List<Future<?>> futures = new ArrayList<>(); for (int i = 0; i < TABLE_COUNT; i++) { futures.add(UTIL.getAdmin().createTableAsync( TableDescriptorBuilder.newBuilder(TableName.valueOf(TABLE_NAME_PREFIX + i)) .setColumnFamily(ColumnFamilyDescriptorBuilder.of(CF)).build(), null)); } for (Future<?> future : futures) { future.get(1, TimeUnit.MINUTES); } UTIL.getAdmin().balance(true); UTIL.waitUntilNoRegionsInTransition(); }
/** * Wait on crash processing. Balancer won't run if processing a crashed server. */ private void waitOnCrashProcessing() { while (UTIL.getHBaseCluster().getMaster().getServerManager().areDeadServersInProgress()) { LOG.info("Waiting on processing of crashed server before proceeding..."); Threads.sleep(1000); } }
@Test public void testObserverAddedByDefault() throws Exception { final HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); final MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost(); Set<String> coprocessorNames = cpHost.getCoprocessors(); assertTrue( "Did not find MasterQuotasObserver in list of CPs: " + coprocessorNames, coprocessorNames.contains(MasterQuotasObserver.class.getSimpleName())); }
@Test public void testFlushedSequenceIdsSentToHMaster() throws IOException, InterruptedException, org.apache.hbase.thirdparty.com.google.protobuf.ServiceException, ServiceException { SortedMap<byte[], Long> allFlushedSequenceIds = new TreeMap<>(Bytes.BYTES_COMPARATOR); for (int i = 0; i < NUM_RS; ++i) { flushAllRegions(i); } Thread.sleep(10000); HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); for (int i = 0; i < NUM_RS; ++i) { for (byte[] regionName : getRegionsByServer(i)) { if (allFlushedSequenceIds.containsKey(regionName)) { GetLastFlushedSequenceIdRequest req = RequestConverter.buildGetLastFlushedSequenceIdRequest(regionName); assertEquals((long)allFlushedSequenceIds.get(regionName), master.getMasterRpcServices().getLastFlushedSequenceId( null, req).getLastFlushedSequenceId()); } } } }
@Test public void testGetRSGroupInfoOfServerCPHookCalled() throws Exception { ServerName masterServerName = ((MiniHBaseCluster) cluster).getMaster().getServerName(); rsGroupAdmin.getRSGroupOfServer(masterServerName.getAddress()); assertTrue(observer.preGetRSGroupInfoOfServerCalled); assertTrue(observer.postGetRSGroupInfoOfServerCalled); }
@Test public void testErrorBeforeUpdate() throws IOException, ReplicationException { ((MockHMaster) UTIL.getHBaseCluster().getMaster()).reset(true); doTest(); }
@Test public void testMasterInitializedEvent() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); HMaster master = UTIL.getMiniHBaseCluster().getMaster(); ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor(); RegionInfo hri = RegionInfoBuilder.newBuilder(tableName).build(); TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName) .setColumnFamily(ColumnFamilyDescriptorBuilder.of("f")).build(); while (!master.isInitialized()) { Thread.sleep(250); } master.setInitialized(false); // fake it, set back later // check event wait/wake testProcedureEventWaitWake(master, master.getInitializedEvent(), new CreateTableProcedure(procExec.getEnvironment(), htd, new RegionInfo[] { hri })); }
@After public void cleanup() throws Exception, KeeperException { for (HTableDescriptor table : ADMIN.listTables()) { ADMIN.disableTable(table.getTableName()); deleteTable(table.getTableName()); } for (NamespaceDescriptor ns : ADMIN.listNamespaceDescriptors()) { if (ns.getName().startsWith(prefix)) { ADMIN.deleteNamespace(ns.getName()); } } assertTrue("Quota manager not initialized", UTIL.getHBaseCluster().getMaster() .getMasterQuotaManager().isQuotaInitialized()); }
private void testCreateWithFailoverAtStep(final int step) throws Exception { final TableName tableName = TableName.valueOf("testCreateWithFailoverAtStep" + step); // create the table ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); ProcedureTestingUtility.setKillBeforeStoreUpdate(procExec, true); ProcedureTestingUtility.setToggleKillBeforeStoreUpdate(procExec, true); // Start the Create procedure && kill the executor byte[][] splitKeys = null; TableDescriptor htd = MasterProcedureTestingUtility.createHTD(tableName, "f1", "f2"); RegionInfo[] regions = ModifyRegionUtils.createRegionInfos(htd, splitKeys); long procId = procExec.submitProcedure( new CreateTableProcedure(procExec.getEnvironment(), htd, regions)); testRecoveryAndDoubleExecution(UTIL, procId, step); MasterProcedureTestingUtility.validateTableCreation( UTIL.getHBaseCluster().getMaster(), tableName, regions, "f1", "f2"); }
private void restartMaster() throws Exception { UTIL.getHBaseCluster().getMaster(0).stop("Stopping to start again"); UTIL.getHBaseCluster().waitOnMaster(0); UTIL.getHBaseCluster().startMaster(); waitForQuotaInitialize(UTIL); }
@Test public void testMasterRpcScheduler() { HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); MasterRpcServices masterRpcServices = master.getMasterRpcServices(); RpcScheduler masterRpcScheduler = masterRpcServices.getRpcScheduler(); Assert.assertTrue(masterRpcScheduler instanceof MasterFifoRpcScheduler); }