@Override public void run() { try { while (!master.isStopped() && master.isActiveMaster()) { Thread.sleep(timeout); if (master.isInitialized()) { LOG.debug("Initialization completed within allotted tolerance. Monitor exiting."); } else { LOG.error("Master failed to complete initialization after " + timeout + "ms. Please" + " consider submitting a bug report including a thread dump of this process."); if (haltOnTimeout) { LOG.error("Zombie Master exiting. Thread dump to stdout"); Threads.printThreadInfo(System.out, "Zombie HMaster"); System.exit(-1); } } } } catch (InterruptedException ie) { LOG.trace("InitMonitor thread interrupted. Existing."); } } }
public static String getUserTables(HMaster master, List<TableDescriptor> tables){ if (master.isInitialized()){ try { Map<String, TableDescriptor> descriptorMap = master.getTableDescriptors().getAll(); if (descriptorMap != null) { for (TableDescriptor desc : descriptorMap.values()) { if (!desc.getTableName().isSystemTable()) { tables.add(desc); } } } } catch (IOException e) { return "Got user tables error, " + e.getMessage(); } } return null; }
private void waitForClusterOnline(MasterThread master) throws InterruptedException { while (true) { if (master.getMaster().isInitialized()) { break; } Thread.sleep(SLEEP_INTERVAL); LOG.debug("Waiting for master to come online ..."); } rs.waitForServerOnline(); }
void checkInitialized() throws PleaseHoldException, ServerNotRunningYetException, MasterNotRunningException, MasterStoppedException { checkServiceStarted(); if (!isInitialized()) { throw new PleaseHoldException("Master is initializing"); } if (isStopped()) { throw new MasterStoppedException(); } }
private void waitForClusterOnline() { while (true) { if (master.getMaster().isInitialized()) { break; } try { Thread.sleep(100); } catch (InterruptedException ignored) { // Keep waiting } } rs.waitForServerOnline(); }
@Override public PairOfSameType<Integer> getRegionCounts() { try { if (!master.isInitialized()) { return new PairOfSameType<>(0, 0); } Integer onlineRegionCount = 0; Integer offlineRegionCount = 0; List<TableDescriptor> descriptors = master.listTableDescriptors(null, null, null, false); for (TableDescriptor htDesc : descriptors) { TableName tableName = htDesc.getTableName(); Map<RegionState.State, List<RegionInfo>> tableRegions = master.getAssignmentManager().getRegionStates() .getRegionByStateOfTable(tableName); onlineRegionCount += tableRegions.get(RegionState.State.OPEN).size(); offlineRegionCount += tableRegions.get(RegionState.State.OFFLINE).size(); } return new PairOfSameType<>(onlineRegionCount, offlineRegionCount); } catch (IOException e) { return new PairOfSameType<>(0, 0); } } }
public static void waitBackupMaster(final HBaseTestingUtility testUtil, final HMaster oldMaster) throws Exception { MiniHBaseCluster 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); } }
JVMClusterUtil.MasterThread t = findActiveMaster(masters); return t != null && t.master.isInitialized();
/** * Blocks until there is an active master and that master has completed * initialization. * * @return true if an active master becomes available. false if there are no * masters left. * @throws InterruptedException */ @Override public boolean waitForActiveAndReadyMaster(long timeout) throws IOException { List<JVMClusterUtil.MasterThread> mts; long start = System.currentTimeMillis(); while (!(mts = getMasterThreads()).isEmpty() && (System.currentTimeMillis() - start) < timeout) { for (JVMClusterUtil.MasterThread mt : mts) { if (mt.getMaster().isActiveMaster() && mt.getMaster().isInitialized()) { return true; } } Threads.sleep(100); } return false; }
@Test(timeout = 60000) public void testMasterInitWithObserverModeClientZKQuorum() throws Exception { Configuration conf = new Configuration(TESTUTIL.getConfiguration()); Assert.assertFalse(Boolean.getBoolean(HConstants.CLIENT_ZOOKEEPER_OBSERVER_MODE)); // set client ZK to some non-existing address and make sure server won't access client ZK // (server start should not be affected) conf.set(HConstants.CLIENT_ZOOKEEPER_QUORUM, HConstants.LOCALHOST); conf.setInt(HConstants.CLIENT_ZOOKEEPER_CLIENT_PORT, TESTUTIL.getZkCluster().getClientPort() + 1); // settings to allow us not to start additional RS conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 1); conf.setBoolean(LoadBalancer.TABLES_ON_MASTER, true); // main setting for this test case conf.setBoolean(HConstants.CLIENT_ZOOKEEPER_OBSERVER_MODE, true); HMaster master = new HMaster(conf); master.start(); while (!master.isInitialized()) { Threads.sleep(200); } Assert.assertNull(master.metaLocationSyncer); Assert.assertNull(master.masterAddressSyncer); master.stopMaster(); master.join(); } }
while (!UTIL.getMiniHBaseCluster().getMaster().isInitialized()) { Threads.sleep(1); FavoredStochasticBalancer.class.getName()); UTIL.restartHBaseCluster(SLAVES); while (!UTIL.getMiniHBaseCluster().getMaster().isInitialized()) { Threads.sleep(1);
@Test public void testClusterRestart() throws Exception { UTIL.startMiniCluster(3); while (!UTIL.getMiniHBaseCluster().getMaster().isInitialized()) { Threads.sleep(1);
while (!UTIL.getMiniHBaseCluster().getMaster().isInitialized()) { LOG.info("Wait the new active master to be initialized"); Thread.sleep(3000);
@Test public void testMasterSwitch() throws Exception { // get an admin instance and issue some request first Connection conn = TEST_UTIL.getConnection(); Admin admin = conn.getAdmin(); LOG.debug("Tables: " + admin.listTableDescriptors()); try { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); // switch active master HMaster master = cluster.getMaster(); master.stopMaster(); while (!master.isShutDown()) { Thread.sleep(200); } while (cluster.getMaster() == null || !cluster.getMaster().isInitialized()) { Thread.sleep(200); } // confirm client access still works Assert.assertTrue(admin.balance(false)); } finally { admin.close(); } }
TEST_UTIL.getMiniHBaseCluster().startMaster(); TEST_UTIL.waitFor(30000, () -> TEST_UTIL.getMiniHBaseCluster().getMaster() != null && TEST_UTIL.getMiniHBaseCluster().getMaster().isInitialized()); assertTrue(fs.exists(hbckLockPath)); TEST_UTIL.getMiniHBaseCluster().getMaster().isInitialized());
@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 })); }
@Test public void testMigration() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY_STR); TEST_UTIL.getAdmin().disableTable(tableName); // Table is disabled. Now remove the DISABLED column from the hbase:meta for this table's // region. We want to see if Master will read the DISABLED from zk and make use of it as // though it were reading the zk table state written by a hbase-1.x cluster. TableState state = MetaTableAccessor.getTableState(TEST_UTIL.getConnection(), tableName); assertTrue("State=" + state, state.getState().equals(TableState.State.DISABLED)); MetaTableAccessor.deleteTableState(TEST_UTIL.getConnection(), tableName); assertTrue(MetaTableAccessor.getTableState(TEST_UTIL.getConnection(), tableName) == null); // Now kill Master so a new one can come up and run through the zk migration. HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); master.stop("Restarting"); while (!master.isStopped()) { Threads.sleep(1); } assertTrue(master.isStopped()); JVMClusterUtil.MasterThread newMasterThread = TEST_UTIL.getMiniHBaseCluster().startMaster(); master = newMasterThread.getMaster(); while (!master.isInitialized()) { Threads.sleep(1); } assertTrue(MetaTableAccessor.getTableState(TEST_UTIL.getConnection(), tableName).getState().equals(TableState.State.DISABLED)); } }
@Test public void test() throws Exception { List<RegionInfo> regionInfos = admin.getRegions(TABLE_NAME); MergeTableRegionsProcedure mergeTableRegionsProcedure = new MergeTableRegionsProcedure( UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor() .getEnvironment(), regionInfos.get(0), regionInfos.get(1)); long procID = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor() .submitProcedure(mergeTableRegionsProcedure); mergeCommitArrive.await(); UTIL.getMiniHBaseCluster().stopMaster(0); UTIL.getMiniHBaseCluster().startMaster(); //wait until master initialized UTIL.waitFor(30000, () -> UTIL.getMiniHBaseCluster().getMaster() != null && UTIL .getMiniHBaseCluster().getMaster().isInitialized()); UTIL.waitFor(30000, () -> UTIL.getMiniHBaseCluster().getMaster() .getMasterProcedureExecutor().isFinished(procID)); Assert.assertTrue("Found region RIT, that's impossible!", UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager() .getRegionsInTransition().size() == 0); }
@Test public void test() throws Exception { JVMClusterUtil.RegionServerThread rsThread = null; for (JVMClusterUtil.RegionServerThread t : UTIL.getMiniHBaseCluster() .getRegionServerThreads()) { if (!t.getRegionServer().getRegions(TABLE_NAME).isEmpty()) { rsThread = t; break; } } // find the rs and hri of the table HRegionServer rs = rsThread.getRegionServer(); RegionInfo hri = rs.getRegions(TABLE_NAME).get(0).getRegionInfo(); TransitRegionStateProcedure moveRegionProcedure = TransitRegionStateProcedure.reopen( UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getEnvironment(), hri); RegionStateNode regionNode = UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager() .getRegionStates().getOrCreateRegionStateNode(hri); regionNode.setProcedure(moveRegionProcedure); UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor() .submitProcedure(moveRegionProcedure); countDownLatch.await(); UTIL.getMiniHBaseCluster().stopMaster(0); UTIL.getMiniHBaseCluster().startMaster(); // wait until master initialized UTIL.waitFor(30000, () -> UTIL.getMiniHBaseCluster().getMaster() != null && UTIL.getMiniHBaseCluster().getMaster().isInitialized()); Assert.assertTrue("Should be 3 RS after master restart", UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().size() == 3); }
FAIL_LOAD = false; HMaster master = UTIL.getMiniHBaseCluster().startMaster().getMaster(); UTIL.waitFor(30000, () -> master.isActiveMaster() && master.isInitialized());