List<String> metaReplicaNodes = zkw.getMetaReplicaNodes(); numReplicasConfigured = metaReplicaNodes.size(); } catch (KeeperException e) {
private void unassignExcessMetaReplica(int numMetaReplicasConfigured) { final ZKWatcher zooKeeper = master.getZooKeeper(); // unassign the unneeded replicas (for e.g., if the previous master was configured // with a replication of 3 and now it is 2, we need to unassign the 1 unneeded replica) try { List<String> metaReplicaZnodes = zooKeeper.getMetaReplicaNodes(); for (String metaReplicaZnode : metaReplicaZnodes) { int replicaId = zooKeeper.getZNodePaths().getMetaReplicaIdFromZnode(metaReplicaZnode); if (replicaId >= numMetaReplicasConfigured) { RegionState r = MetaTableLocator.getMetaRegionState(zooKeeper, replicaId); LOG.info("Closing excess replica of meta region " + r.getRegion()); // send a close and wait for a max of 30 seconds ServerManager.closeRegionSilentlyAndWait(master.getClusterConnection(), r.getServerName(), r.getRegion(), 30000); ZKUtil.deleteNode(zooKeeper, zooKeeper.getZNodePaths().getZNodeForReplica(replicaId)); } } } catch (Exception ex) { // ignore the exception since we don't want the master to be wedged due to potential // issues in the cleanup of the extra regions. We can do that cleanup via hbck or manually LOG.warn("Ignoring exception " + ex); } } }
@Nullable private String checkMetaLocationAndExplain(int originalReplicaCount) throws KeeperException, IOException { List<String> metaZnodes = TEST_UTIL.getZooKeeperWatcher().getMetaReplicaNodes(); if (metaZnodes.size() == originalReplicaCount) { RegionLocations rl = ((ClusterConnection) TEST_UTIL.getConnection()) .locateRegion(TableName.META_TABLE_NAME, HConstants.EMPTY_START_ROW, false, false); for (HRegionLocation location : rl.getRegionLocations()) { if (location == null) { return "Null location found in " + rl.toString(); } if (location.getRegionInfo() == null) { return "Null regionInfo for location " + location; } if (location.getHostname() == null) { return "Null hostName for location " + location; } } return null; // OK } return "Replica count is not as expected " + originalReplicaCount + " <> " + metaZnodes.size() + "(" + metaZnodes.toString() + ")"; }
private void stopMasterAndValidateReplicaCount(final int originalReplicaCount, final int newReplicaCount) throws Exception { ServerName sn = TEST_UTIL.getHBaseClusterInterface().getClusterMetrics().getMasterName(); TEST_UTIL.getHBaseClusterInterface().stopMaster(sn); TEST_UTIL.getHBaseClusterInterface().waitForMasterToStop(sn, 60000); List<String> metaZnodes = TEST_UTIL.getZooKeeperWatcher().getMetaReplicaNodes(); assert(metaZnodes.size() == originalReplicaCount); //we should have what was configured before TEST_UTIL.getHBaseClusterInterface().getConf().setInt(HConstants.META_REPLICAS_NUM, newReplicaCount); if (TEST_UTIL.getHBaseCluster().countServedRegions() < newReplicaCount) { TEST_UTIL.getHBaseCluster().startRegionServer(); } TEST_UTIL.getHBaseClusterInterface().startMaster(sn.getHostname(), 0); TEST_UTIL.getHBaseClusterInterface().waitForActiveAndReadyMaster(); TEST_UTIL.waitFor(10000, predicateMetaHasReplicas(newReplicaCount)); // also check if hbck returns without errors TEST_UTIL.getConfiguration().setInt(HConstants.META_REPLICAS_NUM, newReplicaCount); HBaseFsck hbck = HbckTestingUtil.doFsck(TEST_UTIL.getConfiguration(), false); HbckTestingUtil.assertNoErrors(hbck); }
List<String> metaReplicaNodes = zkw.getMetaReplicaNodes(); numReplicasConfigured = metaReplicaNodes.size(); } catch (KeeperException e) {
@Nullable private String checkMetaLocationAndExplain(int originalReplicaCount) throws KeeperException, IOException { List<String> metaZnodes = TEST_UTIL.getZooKeeperWatcher().getMetaReplicaNodes(); if (metaZnodes.size() == originalReplicaCount) { RegionLocations rl = ((ClusterConnection) TEST_UTIL.getConnection()) .locateRegion(TableName.META_TABLE_NAME, HConstants.EMPTY_START_ROW, false, false); for (HRegionLocation location : rl.getRegionLocations()) { if (location == null) { return "Null location found in " + rl.toString(); } if (location.getRegionInfo() == null) { return "Null regionInfo for location " + location; } if (location.getHostname() == null) { return "Null hostName for location " + location; } } return null; // OK } return "Replica count is not as expected " + originalReplicaCount + " <> " + metaZnodes.size() + "(" + metaZnodes.toString() + ")"; }
private void stopMasterAndValidateReplicaCount(final int originalReplicaCount, final int newReplicaCount) throws Exception { ServerName sn = TEST_UTIL.getHBaseClusterInterface().getClusterMetrics().getMasterName(); TEST_UTIL.getHBaseClusterInterface().stopMaster(sn); TEST_UTIL.getHBaseClusterInterface().waitForMasterToStop(sn, 60000); List<String> metaZnodes = TEST_UTIL.getZooKeeperWatcher().getMetaReplicaNodes(); assert(metaZnodes.size() == originalReplicaCount); //we should have what was configured before TEST_UTIL.getHBaseClusterInterface().getConf().setInt(HConstants.META_REPLICAS_NUM, newReplicaCount); if (TEST_UTIL.getHBaseCluster().countServedRegions() < newReplicaCount) { TEST_UTIL.getHBaseCluster().startRegionServer(); } TEST_UTIL.getHBaseClusterInterface().startMaster(sn.getHostname(), 0); TEST_UTIL.getHBaseClusterInterface().waitForActiveAndReadyMaster(); TEST_UTIL.waitFor(10000, predicateMetaHasReplicas(newReplicaCount)); // also check if hbck returns without errors TEST_UTIL.getConfiguration().setInt(HConstants.META_REPLICAS_NUM, newReplicaCount); HBaseFsck hbck = HbckTestingUtil.doFsck(TEST_UTIL.getConfiguration(), false); HbckTestingUtil.assertNoErrors(hbck); }