t.getRegionServer().stop("Shutdown requested"); if (t.isAlive() && !wasInterrupted && now < maxTime) { try { t.join(maxTime - now); } catch (InterruptedException e) { LOG.info("Got InterruptedException on shutdown - " + boolean atLeastOneLiveServer = false; for (RegionServerThread t : regionservers) { if (t.isAlive()) { atLeastOneLiveServer = true; try { LOG.warn("RegionServerThreads remaining, give one more chance before interrupting"); t.join(1000); } catch (InterruptedException e) { wasInterrupted = true; if (t.isAlive()) { LOG.warn("RegionServerThreads taking too long to stop, interrupting; thread dump " + "if > 3 attempts: i=" + i); if (i > 3) { Threads.printThreadInfo(System.out, "Thread dump " + t.getName()); t.interrupt();
/** * Creates a {@link RegionServerThread}. * Call 'start' on the returned thread to make it run. * @param c Configuration to use. * @param hrsc Class to create. * @param index Used distinguishing the object returned. * @throws IOException * @return Region server added. */ public static JVMClusterUtil.RegionServerThread createRegionServerThread(final Configuration c, final Class<? extends HRegionServer> hrsc, final int index) throws IOException { HRegionServer server; try { Constructor<? extends HRegionServer> ctor = hrsc.getConstructor(Configuration.class); ctor.setAccessible(true); server = ctor.newInstance(c); } catch (InvocationTargetException ite) { Throwable target = ite.getTargetException(); throw new RuntimeException("Failed construction of RegionServer: " + hrsc.toString() + ((target.getCause() != null)? target.getCause().getMessage(): ""), target); } catch (Exception e) { IOException ioe = new IOException(); ioe.initCause(e); throw ioe; } return new JVMClusterUtil.RegionServerThread(server, index); }
cluster.getRegionServers().get(i).start();
HRegionServer hrs = t.getRegionServer(); ShutdownHook.install(hrs.getConfiguration(), FileSystem.get(hrs .getConfiguration()), hrs, t); t.start();
LOG.debug("Starting master: " + master.getMaster().getServerName()); master.start(); rs.start(); LOG.debug("Starting 2nd region server: " + rs2.getRegionServer().getServerName()); rs2.start();
HRegionServer hrs = rst.getRegionServer(); List<RegionInfo> hris = ProtobufUtil.getOnlineRegions(hrs.getRSRpcServices()); for (RegionInfo hri : hris) { "adding data to rs = " + rst.getName() + " region = " + hri.getRegionNameAsString()); Region region = hrs.getOnlineRegion(hri.getRegionName()); assertTrue(region != null);
throw ioe; return new JVMClusterUtil.RegionServerThread(server, index);
/** * Creates a {@link RegionServerThread}. * Call 'start' on the returned thread to make it run. * @param c Configuration to use. * @param hrsc Class to create. * @param index Used distinguishing the object returned. * @throws IOException * @return Region server added. */ public static JVMClusterUtil.RegionServerThread createRegionServerThread( final Configuration c, final Class<? extends HRegionServer> hrsc, final int index) throws IOException { HRegionServer server; try { server = hrsc.getConstructor(Configuration.class).newInstance(c); } catch (InvocationTargetException ite) { Throwable target = ite.getTargetException(); throw new RuntimeException("Failed construction of RegionServer: " + hrsc.toString() + ((target.getCause() != null)? target.getCause().getMessage(): ""), target); } catch (Exception e) { IOException ioe = new IOException(); ioe.initCause(e); throw ioe; } return new JVMClusterUtil.RegionServerThread(server, index); }
/** * Wait for the specified region server to stop * Removes this thread from list of running threads. * @param rst * @return Name of region server that just went down. */ public String waitOnRegionServer(JVMClusterUtil.RegionServerThread rst) { while (rst.isAlive()) { try { LOG.info("Waiting on " + rst.getRegionServer().toString()); rst.join(); } catch (InterruptedException e) { e.printStackTrace(); } } for (int i=0;i<regionThreads.size();i++) { if (regionThreads.get(i) == rst) { regionThreads.remove(i); break; } } return rst.getName(); }
/** * Wait for the specified region server to stop * Removes this thread from list of running threads. * @param rst * @return Name of region server that just went down. */ public String waitOnRegionServer(JVMClusterUtil.RegionServerThread rst) { while (rst.isAlive()) { try { LOG.info("Waiting on " + rst.getRegionServer().toString()); rst.join(); } catch (InterruptedException e) { e.printStackTrace(); } } for (int i=0;i<regionThreads.size();i++) { if (regionThreads.get(i) == rst) { regionThreads.remove(i); break; } } return rst.getName(); }
/** * Wait for the specified region server to stop * Removes this thread from list of running threads. * @param serverNumber * @return Name of region server that just went down. */ public String waitOnRegionServer(int serverNumber) { JVMClusterUtil.RegionServerThread regionServerThread = this.regionThreads.remove(serverNumber); while (regionServerThread.isAlive()) { try { LOG.info("Waiting on " + regionServerThread.getRegionServer().toString()); regionServerThread.join(); } catch (InterruptedException e) { e.printStackTrace(); } } return regionServerThread.getName(); }
/** * Starts a region server thread running * * @throws IOException * @return New RegionServerThread */ public JVMClusterUtil.RegionServerThread startRegionServer() throws IOException { final Configuration newConf = HBaseConfiguration.create(conf); User rsUser = HBaseTestingUtility.getDifferentUser(newConf, ".hfs."+index++); JVMClusterUtil.RegionServerThread t = null; try { t = hbaseCluster.addRegionServer( newConf, hbaseCluster.getRegionServers().size(), rsUser); t.start(); t.waitForServerOnline(); } catch (InterruptedException ie) { throw new IOException("Interrupted adding regionserver to cluster", ie); } return t; }
/** * Wait for the specified region server to stop * Removes this thread from list of running threads. * @param serverNumber * @return Name of region server that just went down. */ public String waitOnRegionServer(int serverNumber) { JVMClusterUtil.RegionServerThread regionServerThread = this.regionThreads.remove(serverNumber); while (regionServerThread.isAlive()) { try { LOG.info("Waiting on " + regionServerThread.getRegionServer().toString()); regionServerThread.join(); } catch (InterruptedException e) { e.printStackTrace(); } } return regionServerThread.getName(); }
@Test public void testClusterId() throws Exception { TEST_UTIL.startMiniZKCluster(); TEST_UTIL.startMiniDFSCluster(1); Configuration conf = new Configuration(TEST_UTIL.getConfiguration()); //start region server, needs to be separate //so we get an unset clusterId rst = JVMClusterUtil.createRegionServerThread(conf, HRegionServer.class, 0); rst.start(); //Make sure RS is in blocking state Thread.sleep(10000); TEST_UTIL.startMiniHBaseCluster(1, 0); rst.waitForServerOnline(); String clusterId = ZKClusterId.readClusterIdZNode(TEST_UTIL.getZooKeeperWatcher()); assertNotNull(clusterId); assertEquals(clusterId, rst.getRegionServer().getClusterId()); }
@BeforeClass public static void setUpBeforeClass() throws Exception { Configuration conf = HBaseConfiguration.create(); conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, MyObserver.class.getName()); UTIL = new HBaseTestingUtility(conf); UTIL.startMiniCluster(MASTERS, SLAVES); CLUSTER = UTIL.getHBaseCluster(); CLUSTER.waitForActiveAndReadyMaster(); ADMIN = UTIL.getAdmin(); // Kill one region server List<RegionServerThread> rsts = CLUSTER.getLiveRegionServerThreads(); RegionServerThread rst = rsts.get(rsts.size() - 1); DEAD = rst.getRegionServer(); DEAD.stop("Test dead servers metrics"); while (rst.isAlive()) { Thread.sleep(500); } }
@BeforeClass public static void setUpBeforeClass() throws Exception { Configuration conf = HBaseConfiguration.create(); conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, MyObserver.class.getName()); UTIL = new HBaseTestingUtility(conf); UTIL.startMiniCluster(MASTERS, SLAVES); CLUSTER = UTIL.getHBaseCluster(); CLUSTER.waitForActiveAndReadyMaster(); ADMIN = UTIL.getAdmin(); // Kill one region server List<RegionServerThread> rsts = CLUSTER.getLiveRegionServerThreads(); RegionServerThread rst = rsts.get(rsts.size() - 1); DEAD = rst.getRegionServer(); DEAD.stop("Test dead servers status"); while (rst.isAlive()) { Thread.sleep(500); } }
/** * @return List of running servers (Some servers may have been killed or * aborted during lifetime of cluster; these servers are not included in this * list). */ public List<JVMClusterUtil.RegionServerThread> getLiveRegionServers() { List<JVMClusterUtil.RegionServerThread> liveServers = new ArrayList<JVMClusterUtil.RegionServerThread>(); List<RegionServerThread> list = getRegionServers(); for (JVMClusterUtil.RegionServerThread rst: list) { if (rst.isAlive()) liveServers.add(rst); else LOG.info("Not alive " + rst.getName()); } return liveServers; }
/** * @return List of running servers (Some servers may have been killed or * aborted during lifetime of cluster; these servers are not included in this * list). */ public List<JVMClusterUtil.RegionServerThread> getLiveRegionServers() { List<JVMClusterUtil.RegionServerThread> liveServers = new ArrayList<JVMClusterUtil.RegionServerThread>(); List<RegionServerThread> list = getRegionServers(); for (JVMClusterUtil.RegionServerThread rst: list) { if (rst.isAlive()) liveServers.add(rst); else LOG.info("Not alive " + rst.getName()); } return liveServers; }