use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.
the class RestartActiveNameNodeAction method perform.
@Override
public void perform() throws Exception {
getLogger().info("Performing action: Restart active namenode");
Configuration conf = CommonFSUtils.getRootDir(getConf()).getFileSystem(getConf()).getConf();
String nameServiceID = DFSUtil.getNamenodeNameServiceId(conf);
if (!HAUtil.isHAEnabled(conf, nameServiceID)) {
throw new Exception("HA for namenode is not enabled");
}
ZKWatcher zkw = null;
RecoverableZooKeeper rzk = null;
String activeNamenode = null;
String hadoopHAZkNode = conf.get(ZK_PARENT_ZNODE_KEY, ZK_PARENT_ZNODE_DEFAULT);
try {
zkw = new ZKWatcher(conf, "get-active-namenode", null);
rzk = zkw.getRecoverableZooKeeper();
String hadoopHAZkNodePath = ZNodePaths.joinZNode(hadoopHAZkNode, nameServiceID);
List<String> subChildern = ZKUtil.listChildrenNoWatch(zkw, hadoopHAZkNodePath);
for (String eachEntry : subChildern) {
if (eachEntry.contains(ACTIVE_NN_LOCK_NAME)) {
byte[] data = rzk.getData(ZNodePaths.joinZNode(hadoopHAZkNodePath, ACTIVE_NN_LOCK_NAME), false, null);
ActiveNodeInfo proto = ActiveNodeInfo.parseFrom(data);
activeNamenode = proto.getHostname();
}
}
} finally {
if (zkw != null) {
zkw.close();
}
}
if (activeNamenode == null) {
throw new Exception("No active Name node found in zookeeper under " + hadoopHAZkNode);
}
getLogger().info("Found active namenode host:" + activeNamenode);
ServerName activeNNHost = ServerName.valueOf(activeNamenode, -1, -1);
getLogger().info("Restarting Active NameNode :" + activeNamenode);
restartNameNode(activeNNHost, sleepTime);
}
use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.
the class AssignmentManager method mirrorMetaLocations.
private void mirrorMetaLocations() throws IOException, KeeperException {
// For compatibility, mirror the meta region state to zookeeper
// And we still need to use zookeeper to publish the meta region locations to region
// server, so they can serve as ClientMetaService
ZKWatcher zk = master.getZooKeeper();
if (zk == null || !zk.getRecoverableZooKeeper().getState().isAlive()) {
// this is possible in tests, we do not provide a zk watcher or the zk watcher has been closed
return;
}
Collection<RegionStateNode> metaStates = regionStates.getRegionStateNodes();
for (RegionStateNode metaState : metaStates) {
MetaTableLocator.setMetaLocation(zk, metaState.getRegionLocation(), metaState.getRegionInfo().getReplicaId(), metaState.getState());
}
int replicaCount = metaStates.size();
// remove extra mirror locations
for (String znode : zk.getMetaReplicaNodes()) {
int replicaId = zk.getZNodePaths().getMetaReplicaIdFromZNode(znode);
if (replicaId >= replicaCount) {
MetaTableLocator.deleteMetaLocation(zk, replicaId);
}
}
}
use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.
the class ReplicationLogCleaner method init.
@Override
public void init(Map<String, Object> params) {
super.init(params);
try {
if (MapUtils.isNotEmpty(params)) {
Object master = params.get(HMaster.MASTER);
if (master != null && master instanceof HMaster) {
zkw = ((HMaster) master).getZooKeeper();
shareZK = true;
}
}
if (zkw == null) {
zkw = new ZKWatcher(getConf(), "replicationLogCleaner", null);
}
this.queueStorage = ReplicationStorageFactory.getReplicationQueueStorage(zkw, getConf());
} catch (IOException e) {
LOG.error("Error while configuring " + this.getClass().getName(), e);
}
}
use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.
the class TestAdmin4 method testDecommissionAndStopRegionServers.
// For HBASE-24208
@Test
public void testDecommissionAndStopRegionServers() throws Exception {
List<ServerName> decommissionedRegionServers = ADMIN.listDecommissionedRegionServers();
assertTrue(decommissionedRegionServers.isEmpty());
ArrayList<ServerName> clusterRegionServers = new ArrayList<>(ADMIN.getRegionServers(true));
List<ServerName> serversToDecommission = new ArrayList<ServerName>();
serversToDecommission.add(clusterRegionServers.get(0));
// Decommission
ADMIN.decommissionRegionServers(serversToDecommission, true);
assertEquals(1, ADMIN.listDecommissionedRegionServers().size());
// Stop decommissioned region server and verify it is removed from draining znode
ServerName serverName = serversToDecommission.get(0);
ADMIN.stopRegionServer(serverName.getHostname() + ":" + serverName.getPort());
assertNotEquals("RS not removed from decommissioned list", -1, TEST_UTIL.waitFor(10000, () -> ADMIN.listDecommissionedRegionServers().isEmpty()));
ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
assertEquals(-1, ZKUtil.checkExists(zkw, ZNodePaths.joinZNode(zkw.getZNodePaths().drainingZNode, serverName.getServerName())));
}
use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.
the class TestMetaRegionLocationCache method verifyCachedMetaLocations.
// Verifies that the cached meta locations in the given master are in sync with what is in ZK.
private void verifyCachedMetaLocations(HMaster master) throws Exception {
// Wait until initial meta locations are loaded.
int retries = 0;
while (master.getMetaRegionLocationCache().getMetaRegionLocations().isEmpty()) {
Thread.sleep(1000);
if (++retries == 10) {
break;
}
}
ZKWatcher zk = master.getZooKeeper();
List<String> metaZnodes = zk.getMetaReplicaNodes();
// Wait till all replicas available.
retries = 0;
while (master.getMetaRegionLocationCache().getMetaRegionLocations().size() != metaZnodes.size()) {
Thread.sleep(1000);
if (++retries == 10) {
break;
}
}
List<HRegionLocation> metaHRLs = master.getMetaRegionLocationCache().getMetaRegionLocations();
assertFalse(metaHRLs.isEmpty());
assertEquals(metaZnodes.size(), metaHRLs.size());
List<HRegionLocation> actualHRLs = getCurrentMetaLocations(zk);
Collections.sort(metaHRLs);
Collections.sort(actualHRLs);
assertEquals(actualHRLs, metaHRLs);
}
Aggregations