public BalancerChore(HMaster master) { super(master.getServerName() + "-BalancerChore", master, master.getConfiguration().getInt( HConstants.HBASE_BALANCER_PERIOD, HConstants.DEFAULT_HBASE_BALANCER_PERIOD)); this.master = master; }
@Override public String getServerName() { ServerName serverName = master.getServerName(); if (serverName == null) { return ""; } return serverName.getServerName(); }
public RegionNormalizerChore(HMaster master) { super(master.getServerName() + "-RegionNormalizerChore", master, master.getConfiguration().getInt("hbase.normalizer.period", 300000)); this.master = master; }
public ClusterStatusChore(HMaster master, LoadBalancer balancer) { super(master.getServerName() + "-ClusterStatusChore", master, master.getConfiguration().getInt( "hbase.balancer.statusPeriod", 60000)); this.master = master; this.balancer = balancer; }
public MasterThread(final HMaster m, final int index) { super(m, "M:" + index + ";" + m.getServerName().toShortString()); this.master = m; }
public MobCompactionChore(HMaster master, int period) { // use the period as initial delay. super(master.getServerName() + "-MobCompactionChore", master, period, period, TimeUnit.SECONDS); this.master = master; this.pool = MobUtils.createMobCompactorThreadPool(master.getConfiguration()); }
public ExpiredMobFileCleanerChore(HMaster master) { super(master.getServerName() + "-ExpiredMobFileCleanerChore", master, master.getConfiguration() .getInt(MobConstants.MOB_CLEANER_PERIOD, MobConstants.DEFAULT_MOB_CLEANER_PERIOD), master .getConfiguration().getInt(MobConstants.MOB_CLEANER_PERIOD, MobConstants.DEFAULT_MOB_CLEANER_PERIOD), TimeUnit.SECONDS); this.master = master; cleaner = new ExpiredMobFileCleaner(); cleaner.setConf(master.getConfiguration()); }
/** * Wait for the specified master to stop. Removes this thread from list of running threads. * @return Name of master that just went down. */ public String waitOnMaster(JVMClusterUtil.MasterThread masterThread) { while (masterThread.isAlive()) { try { LOG.info("Waiting on " + masterThread.getMaster().getServerName().toString()); masterThread.join(); } catch (InterruptedException e) { LOG.error("Interrupted while waiting for {} to finish. Retrying join", masterThread.getName(), e); Thread.currentThread().interrupt(); } } masterThreads.remove(masterThread); return masterThread.getName(); }
protected int getMasterIndex(ServerName serverName) { List<MasterThread> masters = getMasterThreads(); for (int i = 0; i < masters.size(); i++) { if (masters.get(i).getMaster().getServerName().equals(serverName)) { return i; } } return -1; }
@Test public void testMasterOnlineConfigChange() throws IOException { LOG.debug("Starting the test"); Path cnfPath = FileSystems.getDefault().getPath("target/test-classes/hbase-site.xml"); Path cnf2Path = FileSystems.getDefault().getPath("target/test-classes/hbase-site2.xml"); Path cnf3Path = FileSystems.getDefault().getPath("target/test-classes/hbase-site3.xml"); // make a backup of hbase-site.xml Files.copy(cnfPath, cnf3Path, StandardCopyOption.REPLACE_EXISTING); // update hbase-site.xml by overwriting it Files.copy(cnf2Path, cnfPath, StandardCopyOption.REPLACE_EXISTING); Admin admin = TEST_UTIL.getAdmin(); ServerName server = TEST_UTIL.getHBaseCluster().getMaster().getServerName(); admin.updateConfiguration(server); Configuration conf = TEST_UTIL.getMiniHBaseCluster().getMaster().getConfiguration(); int custom = conf.getInt("hbase.custom.config", 0); assertEquals(1000, custom); // restore hbase-site.xml Files.copy(cnf3Path, cnfPath, StandardCopyOption.REPLACE_EXISTING); }
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); } } }
public static void masterFailover(final HBaseTestingUtility testUtil) throws Exception { MiniHBaseCluster cluster = testUtil.getMiniHBaseCluster(); // Kill the master HMaster oldMaster = cluster.getMaster(); cluster.killMaster(cluster.getMaster().getServerName()); // Wait the secondary waitBackupMaster(testUtil, oldMaster); }
@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 testGetRSGroupInfoOfServerCPHookCalled() throws Exception { ServerName masterServerName = ((MiniHBaseCluster) cluster).getMaster().getServerName(); rsGroupAdmin.getRSGroupOfServer(masterServerName.getAddress()); assertTrue(observer.preGetRSGroupInfoOfServerCalled); assertTrue(observer.postGetRSGroupInfoOfServerCalled); }
@Override public ServerName getServerHoldingRegion(final TableName tn, byte[] regionName) throws IOException { // Assume there is only one master thread which is the active master. // If there are multiple master threads, the backup master threads // should hold some regions. Please refer to #countServedRegions // to see how we find out all regions. HMaster master = getMaster(); Region region = master.getOnlineRegion(regionName); if (region != null) { return master.getServerName(); } int index = getServerWith(regionName); if (index < 0) { return null; } return getRegionServer(index).getServerName(); }
@Test(expected = UnknownHostException.class) public void testGetAdminBadHostname() throws Exception { // verify that we can get an instance with the cluster hostname ServerName master = testUtil.getHBaseCluster().getMaster().getServerName(); try { conn.getAdmin(master); } catch (UnknownHostException uhe) { fail("Obtaining admin to the cluster master should have succeeded"); } // test that we fail to get a client to an unresolvable hostname, which // means it won't be cached ServerName badHost = ServerName.valueOf("unknownhost.invalid:" + HConstants.DEFAULT_MASTER_PORT, System.currentTimeMillis()); conn.getAdmin(badHost); fail("Obtaining admin to unresolvable hostname should have failed"); }
@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()); }
@Test public void test() throws InterruptedException, ExecutionException, IOException { LOG.info("STARTED TEST"); String clusterId = REGISTRY.getClusterId().get(); String expectedClusterId = TEST_UTIL.getHBaseCluster().getMaster().getClusterId(); assertEquals("Expected " + expectedClusterId + ", found=" + clusterId, expectedClusterId, clusterId); assertEquals(TEST_UTIL.getHBaseCluster().getClusterMetrics().getLiveServerMetrics().size(), REGISTRY.getCurrentNrHRS().get().intValue()); assertEquals(TEST_UTIL.getHBaseCluster().getMaster().getServerName(), REGISTRY.getMasterAddress().get()); assertEquals(-1, REGISTRY.getMasterInfoPort().get().intValue()); RegionReplicaTestHelper.waitUntilAllMetaReplicasHavingRegionLocation(REGISTRY, 3); RegionLocations locs = REGISTRY.getMetaRegionLocation().get(); assertEquals(3, locs.getRegionLocations().length); IntStream.range(0, 3).forEach(i -> { HRegionLocation loc = locs.getRegionLocation(i); assertNotNull("Replica " + i + " doesn't have location", loc); assertEquals(TableName.META_TABLE_NAME, loc.getRegion().getTable()); assertEquals(i, loc.getRegion().getReplicaId()); }); }
@Test public void testDefaultMasterMetrics() throws Exception { MetricsMasterSource masterSource = master.getMasterMetrics().getMetricsSource(); boolean tablesOnMaster = LoadBalancer.isTablesOnMaster(TEST_UTIL.getConfiguration()); metricsHelper.assertGauge("numRegionServers", 1 + (tablesOnMaster ? 1 : 0), masterSource); metricsHelper.assertGauge("averageLoad", 1, masterSource); metricsHelper.assertGauge("numDeadRegionServers", 0, masterSource); metricsHelper.assertGauge("masterStartTime", master.getMasterStartTime(), masterSource); metricsHelper.assertGauge("masterActiveTime", master.getMasterActiveTime(), masterSource); metricsHelper.assertTag("isActiveMaster", "true", masterSource); metricsHelper.assertTag("serverName", master.getServerName().toString(), masterSource); metricsHelper.assertTag("clusterId", master.getClusterId(), masterSource); metricsHelper.assertTag("zookeeperQuorum", master.getZooKeeper().getQuorum(), masterSource); }
@Test public void testClusterRequests() throws Exception { // sending fake request to master to see how metric value has changed RegionServerStatusProtos.RegionServerReportRequest.Builder request = RegionServerStatusProtos.RegionServerReportRequest.newBuilder(); ServerName serverName = cluster.getMaster(0).getServerName(); request.setServer(ProtobufUtil.toServerName(serverName)); long expectedRequestNumber = 10000; MetricsMasterSource masterSource = master.getMasterMetrics().getMetricsSource(); ClusterStatusProtos.ServerLoad sl = ClusterStatusProtos.ServerLoad.newBuilder() .setTotalNumberOfRequests(expectedRequestNumber).build(); request.setLoad(sl); master.getMasterRpcServices().regionServerReport(null, request.build()); metricsHelper.assertCounter("cluster_requests", expectedRequestNumber, masterSource); expectedRequestNumber = 15000; sl = ClusterStatusProtos.ServerLoad.newBuilder().setTotalNumberOfRequests(expectedRequestNumber) .build(); request.setLoad(sl); master.getMasterRpcServices().regionServerReport(null, request.build()); metricsHelper.assertCounter("cluster_requests", expectedRequestNumber, masterSource); }