private static JVMClusterUtil.MasterThread findActiveMaster( List<JVMClusterUtil.MasterThread> masters) { for (JVMClusterUtil.MasterThread t : masters) { if (t.master.isActiveMaster()) { return t; } } return null; }
@Override public boolean getIsActiveMaster() { return master.isActiveMaster(); }
@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."); } } }
/** * 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; }
/** * Returns the current active master thread, if available. * @return the active MasterThread, null if none is active. */ public MasterThread getMasterThread() { for (MasterThread mt: hbaseCluster.getLiveMasters()) { if (mt.getMaster().isActiveMaster()) { return mt; } } return null; }
/** * return the index of the active master in the cluster * * @throws org.apache.hadoop.hbase.MasterNotRunningException * if no active master found */ private int getActiveMasterIndex(MiniHBaseCluster cluster) throws MasterNotRunningException { // get all the master threads List<JVMClusterUtil.MasterThread> masterThreads = cluster.getMasterThreads(); for (int i = 0; i < masterThreads.size(); i++) { if (masterThreads.get(i).getMaster().isActiveMaster()) { return i; } } throw new MasterNotRunningException(); }
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); } }
private void abortMaster(MiniHBaseCluster cluster) throws InterruptedException { for (MasterThread mt : cluster.getLiveMasterThreads()) { if (mt.getMaster().isActiveMaster()) { mt.getMaster().abort("Aborting for tests", new Exception("Trace info")); mt.join(); break; } } LOG.debug("Master is aborted"); }
Set<ServerName> deadServers = null; if(master.isActiveMaster()) { metaLocation = getMetaLocationOrNull(master); ServerManager serverManager = master.getServerManager();
/** * 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; }
out.write("</title>\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <meta name=\"description\" content=\"\">\n <meta name=\"author\" content=\"\">\n\n <link href=\"/static/css/bootstrap.min.css\" rel=\"stylesheet\">\n <link href=\"/static/css/bootstrap-theme.min.css\" rel=\"stylesheet\">\n <link href=\"/static/css/hbase.css\" rel=\"stylesheet\">\n </head>\n <body>\n <div class=\"navbar navbar-fixed-top navbar-default\">\n <div class=\"container-fluid\">\n <div class=\"navbar-header\">\n <button type=\"button\" class=\"navbar-toggle\" data-toggle=\"collapse\"\n data-target=\".navbar-collapse\">\n <span class=\"icon-bar\"></span>\n <span class=\"icon-bar\"></span>\n <span class=\"icon-bar\"></span>\n </button>\n <a class=\"navbar-brand\" href=\"/master-status\">\n <img src=\"/static/hbase_logo_small.png\" alt=\"HBase Logo\"/>\n </a>\n </div>\n <div class=\"collapse navbar-collapse\">\n <ul class=\"nav navbar-nav\">\n <li><a href=\"/master-status\">Home</a></li>\n"); out.write(" <li><a href=\"/tablesDetailed.jsp\">Table Details</a></li>\n "); if (master.isActiveMaster()){ out.write("\n <li><a href=\"/procedures.jsp\">Procedures & Locks</a></li>\n ");
@Test public void testShutdownWhileBecomingActive() throws InterruptedException { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster activeMaster = null; HMaster backupMaster = null; for (MasterThread t : cluster.getMasterThreads()) { if (t.getMaster().isActiveMaster()) { activeMaster = t.getMaster(); } else { backupMaster = t.getMaster(); } } assertNotNull(activeMaster); assertNotNull(backupMaster); ARRIVE = new CountDownLatch(1); CONTINUE = new CountDownLatch(1); activeMaster.abort("Aborting active master for test"); // wait until we arrive the initClusterSchemaService ARRIVE.await(); // killall RSes cluster.getRegionServerThreads().stream().map(t -> t.getRegionServer()) .forEachOrdered(rs -> rs.abort("Aborting RS for test")); CONTINUE.countDown(); } }
@Test public void testMasterAndBackupMastersStatus() throws Exception { // get all the master threads List<MasterThread> masterThreads = CLUSTER.getMasterThreads(); int numActive = 0; int activeIndex = 0; ServerName activeName = null; HMaster active = null; for (int i = 0; i < masterThreads.size(); i++) { if (masterThreads.get(i).getMaster().isActiveMaster()) { numActive++; activeIndex = i; active = masterThreads.get(activeIndex).getMaster(); activeName = active.getServerName(); } } Assert.assertNotNull(active); Assert.assertEquals(1, numActive); Assert.assertEquals(MASTERS, masterThreads.size()); // Retrieve master and backup masters infos only. EnumSet<Option> options = EnumSet.of(Option.MASTER, Option.BACKUP_MASTERS); ClusterMetrics metrics = ADMIN.getClusterMetrics(options); Assert.assertTrue(metrics.getMasterName().equals(activeName)); Assert.assertEquals(MASTERS - 1, metrics.getBackupMasterNames().size()); }
@Test public void testMasterAndBackupMastersStatus() throws Exception { // get all the master threads List<MasterThread> masterThreads = CLUSTER.getMasterThreads(); int numActive = 0; int activeIndex = 0; ServerName activeName = null; HMaster active = null; for (int i = 0; i < masterThreads.size(); i++) { if (masterThreads.get(i).getMaster().isActiveMaster()) { numActive++; activeIndex = i; active = masterThreads.get(activeIndex).getMaster(); activeName = active.getServerName(); } } Assert.assertNotNull(active); Assert.assertEquals(1, numActive); Assert.assertEquals(MASTERS, masterThreads.size()); // Retrieve master and backup masters infos only. EnumSet<Option> options = EnumSet.of(Option.MASTER, Option.BACKUP_MASTERS); ClusterStatus status = new ClusterStatus(ADMIN.getClusterMetrics(options)); Assert.assertTrue(status.getMaster().equals(activeName)); Assert.assertEquals(MASTERS - 1, status.getBackupMastersSize()); }
Mockito.doReturn(true).when(backupMaster3).isActiveMaster(); final WALProcedureStore procStore2 = new WALProcedureStore(firstMaster.getConfiguration(), ((WALProcedureStore)procStore).getWALDir(),
if (masterThreads.get(i).getMaster().isActiveMaster()) { active = masterThreads.get(i).getMaster(); break;
assertTrue(backupMaster.getMaster().isActiveMaster()); assertTrue(backupMaster.getMaster().isInitialized()); assertEquals(backupMaster.getMaster().getServerManager().getOnlineServersList().size(),
/** * Do a simulated kill all masters and regionservers. Useful when it is * impossible to bring the mini-cluster back for clean shutdown. */ public void killAll() { // Do backups first. MasterThread activeMaster = null; for (MasterThread masterThread : getMasterThreads()) { if (!masterThread.getMaster().isActiveMaster()) { masterThread.getMaster().abort("killAll"); } else { activeMaster = masterThread; } } // Do active after. if (activeMaster != null) { activeMaster.getMaster().abort("killAll"); } for (RegionServerThread rst : getRegionServerThreads()) { rst.getRegionServer().abort("killAll"); } }
@Test public void testStarted() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); assertTrue("Master should be active", master.isActiveMaster()); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); assertNotNull("CoprocessorHost should not be null", host); CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class); assertNotNull("CPMasterObserver coprocessor not found or not installed!", cp); // check basic lifecycle assertTrue("MasterObserver should have been started", cp.wasStarted()); assertTrue("preMasterInitialization() hook should have been called", cp.wasMasterInitializationCalled()); assertTrue("postStartMaster() hook should have been called", cp.wasStartMasterCalled()); }
FAIL_LOAD = false; HMaster master = UTIL.getMiniHBaseCluster().startMaster().getMaster(); UTIL.waitFor(30000, () -> master.isActiveMaster() && master.isInitialized());