Search in sources :

Example 31 with ZKWatcher

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);
}
Also used : ActiveNodeInfo(org.apache.hadoop.hdfs.server.namenode.ha.proto.HAZKInfoProtos.ActiveNodeInfo) RecoverableZooKeeper(org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper) Configuration(org.apache.hadoop.conf.Configuration) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) ServerName(org.apache.hadoop.hbase.ServerName)

Example 32 with ZKWatcher

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);
        }
    }
}
Also used : ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher)

Example 33 with ZKWatcher

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);
    }
}
Also used : ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) HMaster(org.apache.hadoop.hbase.master.HMaster) IOException(java.io.IOException)

Example 34 with ZKWatcher

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())));
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 35 with ZKWatcher

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);
}
Also used : HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher)

Aggregations

ZKWatcher (org.apache.hadoop.hbase.zookeeper.ZKWatcher)66 Configuration (org.apache.hadoop.conf.Configuration)27 Test (org.junit.Test)24 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)13 ArrayList (java.util.ArrayList)10 ServerName (org.apache.hadoop.hbase.ServerName)10 IOException (java.io.IOException)8 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)8 Before (org.junit.Before)8 BeforeClass (org.junit.BeforeClass)8 Admin (org.apache.hadoop.hbase.client.Admin)7 Abortable (org.apache.hadoop.hbase.Abortable)6 HMaster (org.apache.hadoop.hbase.master.HMaster)6 MiniZooKeeperCluster (org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster)6 List (java.util.List)5 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)5 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)5 ReplicationPeerConfig (org.apache.hadoop.hbase.replication.ReplicationPeerConfig)5 KeeperException (org.apache.zookeeper.KeeperException)5 CountDownLatch (java.util.concurrent.CountDownLatch)4