@Override public void stop(String msg) { if (!isStopped()) { super.stop(msg); if (this.activeMasterManager != null) { this.activeMasterManager.stop(); } } }
@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."); } } }
@Override public void abort(String reason, Throwable cause) { if (isAborted() || isStopped()) { return; } if (cpHost != null) { // HBASE-4014: dump a list of loaded coprocessors. LOG.error(HBaseMarkers.FATAL, "Master server abort: loaded coprocessors are: " + getLoadedCoprocessors()); } String msg = "***** ABORTING master " + this + ": " + reason + " *****"; if (cause != null) { LOG.error(HBaseMarkers.FATAL, msg, cause); } else { LOG.error(HBaseMarkers.FATAL, msg); } try { stopMaster(); } catch (IOException e) { LOG.error("Exception occurred while stopping master", e); } }
/** * If configured to put regions on active master, * wait till a backup master becomes active. * Otherwise, loop till the server is stopped or aborted. */ @Override protected void waitForMasterActive(){ if (maintenanceMode) { return; } boolean tablesOnMaster = LoadBalancer.isTablesOnMaster(conf); while (!(tablesOnMaster && activeMaster) && !isStopped() && !isAborted()) { sleeper.sleep(); } }
void checkInitialized() throws PleaseHoldException, ServerNotRunningYetException, MasterNotRunningException, MasterStoppedException { checkServiceStarted(); if (!isInitialized()) { throw new PleaseHoldException("Master is initializing"); } if (isStopped()) { throw new MasterStoppedException(); } }
/** * Gets the current active master, if available. If no active master, returns * null. * @return the HMaster for the active master */ public HMaster getActiveMaster() { for (JVMClusterUtil.MasterThread mt : masterThreads) { // Ensure that the current active master is not stopped. // We don't want to return a stopping master as an active master. if (mt.getMaster().isActiveMaster() && !mt.getMaster().isStopped()) { return mt.getMaster(); } } return null; }
@Override public IsMasterRunningResponse isMasterRunning(RpcController c, IsMasterRunningRequest req) throws ServiceException { try { master.checkServiceStarted(); return IsMasterRunningResponse.newBuilder().setIsMasterRunning( !master.isStopped()).build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public long createSystemTable(final TableDescriptor tableDescriptor) throws IOException { if (isStopped()) { throw new MasterNotRunningException(); } TableName tableName = tableDescriptor.getTableName(); if (!(tableName.isSystemTable())) { throw new IllegalArgumentException( "Only system table creation can use this createSystemTable API"); } RegionInfo[] newRegions = ModifyRegionUtils.createRegionInfos(tableDescriptor, null); LOG.info(getClientIdAuditPrefix() + " create " + tableDescriptor); // This special create table is called locally to master. Therefore, no RPC means no need // to use nonce to detect duplicated RPC call. long procId = this.procedureExecutor.submitProcedure( new CreateTableProcedure(procedureExecutor.getEnvironment(), tableDescriptor, newRegions)); return procId; }
logProcessInfo(getConf()); HMaster master = HMaster.constructMaster(masterClass, conf); if (master.isStopped()) { LOG.info("Won't bring the Master up as a shutdown is requested"); return 1;
/** * @return True if region is online and scannable else false if an error or shutdown (Otherwise * we just block in here holding up all forward-progess). */ private boolean isRegionOnline(RegionInfo ri) throws InterruptedException { RetryCounter rc = null; while (!isStopped()) { RegionState rs = this.assignmentManager.getRegionStates().getRegionState(ri); if (rs.isOpened()) { if (this.getServerManager().isServerOnline(rs.getServerName())) { return true; } } // Region is not OPEN. Optional<Procedure<MasterProcedureEnv>> optProc = this.procedureExecutor.getProcedures(). stream().filter(p -> p instanceof ServerCrashProcedure).findAny(); // TODO: Add a page to refguide on how to do repair. Have this log message point to it. // Page will talk about loss of edits, how to schedule at least the meta WAL recovery, and // then how to assign including how to break region lock if one held. LOG.warn("{} is NOT online; state={}; ServerCrashProcedures={}. Master startup cannot " + "progress, in holding-pattern until region onlined.", ri.getRegionNameAsString(), rs, optProc.isPresent()); // Check once-a-minute. if (rc == null) { rc = new RetryCounterFactory(1000).create(); } Threads.sleep(rc.getBackoffTimeAndIncrementAttempts()); } return false; }
@Test public void testStop() throws Exception { HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0); assertFalse(rs.isStopped()); admin.stopRegionServer(rs.getServerName()).join(); assertTrue(rs.isStopped()); HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); assertFalse(master.isStopped()); admin.stopMaster().join(); assertTrue(master.isStopped()); }
@Test public void testShutdown() throws Exception { TEST_UTIL.getMiniHBaseCluster().getMasterThreads().forEach(thread -> { assertFalse(thread.getMaster().isStopped()); }); TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads().forEach(thread -> { assertFalse(thread.getRegionServer().isStopped()); }); admin.shutdown().join(); TEST_UTIL.getMiniHBaseCluster().getMasterThreads().forEach(thread -> { while (!thread.getMaster().isStopped()) { trySleep(100, TimeUnit.MILLISECONDS); } }); TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads().forEach(thread -> { while (!thread.getRegionServer().isStopped()) { trySleep(100, TimeUnit.MILLISECONDS); } }); }
/** * Master recovery when the znode already exists. Internally, this * test differs from {@link #testMasterSessionExpired} because here * the master znode will exist in ZK. */ @Test public void testMasterZKSessionRecoveryFailure() throws Exception { LOG.info("Starting " + name.getMethodName()); MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HMaster m = cluster.getMaster(); m.abort("Test recovery from zk session expired", new KeeperException.SessionExpiredException()); assertTrue(m.isStopped()); // Master doesn't recover any more testSanity(name.getMethodName()); }
assertTrue(m.isStopped()); // Master doesn't recover any more cluster.killRegionServer(TEST_UTIL.getRSForFirstRegionInTable(tableName).getServerName());
if (isStopped()) { return;
m.abort("Test recovery from zk session expired", new KeeperException.SessionExpiredException()); assertTrue(m.isStopped()); // Master doesn't recover any more
assertEquals(true, firstMaster.isStopped());
@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 testStop() throws Exception { HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0); assertFalse(rs.isStopped()); admin.stopRegionServer(rs.getServerName()).join(); assertTrue(rs.isStopped()); HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); assertFalse(master.isStopped()); admin.stopMaster().join(); assertTrue(master.isStopped()); }