Search in sources :

Example 1 with ZKWatcher

use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.

the class TestReplicationStateZKImpl method initPeerClusterState.

private static String initPeerClusterState(String baseZKNode) throws IOException, KeeperException {
    // Add a dummy region server and set up the cluster id
    Configuration testConf = new Configuration(conf);
    testConf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, baseZKNode);
    ZKWatcher zkw1 = new ZKWatcher(testConf, "test1", null);
    String fakeRs = ZNodePaths.joinZNode(zkw1.getZNodePaths().rsZNode, "hostname1.example.org:1234");
    ZKUtil.createWithParents(zkw1, fakeRs);
    ZKClusterId.setClusterId(zkw1, new ClusterId());
    return ZKConfig.getZooKeeperClusterKey(testConf);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ZKClusterId(org.apache.hadoop.hbase.zookeeper.ZKClusterId) ClusterId(org.apache.hadoop.hbase.ClusterId) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher)

Example 2 with ZKWatcher

use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.

the class ServerManager method letRegionServersShutdown.

void letRegionServersShutdown() {
    long previousLogTime = 0;
    ServerName sn = master.getServerName();
    ZKWatcher zkw = master.getZooKeeper();
    int onlineServersCt;
    while ((onlineServersCt = onlineServers.size()) > 0) {
        if (EnvironmentEdgeManager.currentTime() > (previousLogTime + 1000)) {
            Set<ServerName> remainingServers = onlineServers.keySet();
            synchronized (onlineServers) {
                if (remainingServers.size() == 1 && remainingServers.contains(sn)) {
                    // Master will delete itself later.
                    return;
                }
            }
            StringBuilder sb = new StringBuilder();
            // It's ok here to not sync on onlineServers - merely logging
            for (ServerName key : remainingServers) {
                if (sb.length() > 0) {
                    sb.append(", ");
                }
                sb.append(key);
            }
            LOG.info("Waiting on regionserver(s) " + sb.toString());
            previousLogTime = EnvironmentEdgeManager.currentTime();
        }
        try {
            List<String> servers = getRegionServersInZK(zkw);
            if (servers == null || servers.isEmpty() || (servers.size() == 1 && servers.contains(sn.toString()))) {
                LOG.info("ZK shows there is only the master self online, exiting now");
                // Master could have lost some ZK events, no need to wait more.
                break;
            }
        } catch (KeeperException ke) {
            LOG.warn("Failed to list regionservers", ke);
            // ZK is malfunctioning, don't hang here
            break;
        }
        synchronized (onlineServers) {
            try {
                if (onlineServersCt == onlineServers.size())
                    onlineServers.wait(100);
            } catch (InterruptedException ignored) {
            // continue
            }
        }
    }
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) KeeperException(org.apache.zookeeper.KeeperException)

Example 3 with ZKWatcher

use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.

the class HMaster method initializeZKBasedSystemTrackers.

/**
 * Initialize all ZK based system trackers. But do not include {@link RegionServerTracker}, it
 * should have already been initialized along with {@link ServerManager}.
 */
private void initializeZKBasedSystemTrackers() throws IOException, KeeperException, ReplicationException {
    if (maintenanceMode) {
        // in maintenance mode, always use MaintenanceLoadBalancer.
        conf.unset(LoadBalancer.HBASE_RSGROUP_LOADBALANCER_CLASS);
        conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, MaintenanceLoadBalancer.class, LoadBalancer.class);
    }
    this.balancer = new RSGroupBasedLoadBalancer();
    this.loadBalancerTracker = new LoadBalancerTracker(zooKeeper, this);
    this.loadBalancerTracker.start();
    this.regionNormalizerManager = RegionNormalizerFactory.createNormalizerManager(conf, zooKeeper, this);
    this.configurationManager.registerObserver(regionNormalizerManager);
    this.regionNormalizerManager.start();
    this.splitOrMergeTracker = new SplitOrMergeTracker(zooKeeper, conf, this);
    this.splitOrMergeTracker.start();
    // This is for backwards compatible. We do not need the CP for rs group now but if user want to
    // load it, we need to enable rs group.
    String[] cpClasses = conf.getStrings(MasterCoprocessorHost.MASTER_COPROCESSOR_CONF_KEY);
    if (cpClasses != null) {
        for (String cpClass : cpClasses) {
            if (RSGroupAdminEndpoint.class.getName().equals(cpClass)) {
                RSGroupUtil.enableRSGroup(conf);
                break;
            }
        }
    }
    this.rsGroupInfoManager = RSGroupInfoManager.create(this);
    this.replicationPeerManager = ReplicationPeerManager.create(zooKeeper, conf, clusterId);
    this.drainingServerTracker = new DrainingServerTracker(zooKeeper, this, this.serverManager);
    this.drainingServerTracker.start();
    this.snapshotCleanupTracker = new SnapshotCleanupTracker(zooKeeper, this);
    this.snapshotCleanupTracker.start();
    String clientQuorumServers = conf.get(HConstants.CLIENT_ZOOKEEPER_QUORUM);
    boolean clientZkObserverMode = conf.getBoolean(HConstants.CLIENT_ZOOKEEPER_OBSERVER_MODE, HConstants.DEFAULT_CLIENT_ZOOKEEPER_OBSERVER_MODE);
    if (clientQuorumServers != null && !clientZkObserverMode) {
        // we need to take care of the ZK information synchronization
        // if given client ZK are not observer nodes
        ZKWatcher clientZkWatcher = new ZKWatcher(conf, getProcessName() + ":" + rpcServices.getSocketAddress().getPort() + "-clientZK", this, false, true);
        this.metaLocationSyncer = new MetaLocationSyncer(zooKeeper, clientZkWatcher, this);
        this.metaLocationSyncer.start();
        this.masterAddressSyncer = new MasterAddressSyncer(zooKeeper, clientZkWatcher, this);
        this.masterAddressSyncer.start();
        // set cluster id is a one-go effort
        ZKClusterId.setClusterId(clientZkWatcher, fileSystemManager.getClusterId());
    }
    // Set the cluster as up.  If new RSs, they'll be waiting on this before
    // going ahead with their startup.
    boolean wasUp = this.clusterStatusTracker.isClusterUp();
    if (!wasUp)
        this.clusterStatusTracker.setClusterUp();
    LOG.info("Active/primary master=" + this.serverName + ", sessionid=0x" + Long.toHexString(this.zooKeeper.getRecoverableZooKeeper().getSessionId()) + ", setting cluster-up flag (Was=" + wasUp + ")");
    // create/initialize the snapshot manager and other procedure managers
    this.snapshotManager = new SnapshotManager();
    this.mpmHost = new MasterProcedureManagerHost();
    this.mpmHost.register(this.snapshotManager);
    this.mpmHost.register(new MasterFlushTableProcedureManager());
    this.mpmHost.loadProcedures(conf);
    this.mpmHost.initialize(this, this.metricsMaster);
}
Also used : MasterFlushTableProcedureManager(org.apache.hadoop.hbase.procedure.flush.MasterFlushTableProcedureManager) MasterProcedureManagerHost(org.apache.hadoop.hbase.procedure.MasterProcedureManagerHost) RSGroupAdminEndpoint(org.apache.hadoop.hbase.rsgroup.RSGroupAdminEndpoint) MetaLocationSyncer(org.apache.hadoop.hbase.master.zksyncer.MetaLocationSyncer) SnapshotCleanupTracker(org.apache.hadoop.hbase.zookeeper.SnapshotCleanupTracker) LoadBalancerTracker(org.apache.hadoop.hbase.zookeeper.LoadBalancerTracker) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) RSGroupBasedLoadBalancer(org.apache.hadoop.hbase.rsgroup.RSGroupBasedLoadBalancer) MasterAddressSyncer(org.apache.hadoop.hbase.master.zksyncer.MasterAddressSyncer) SnapshotManager(org.apache.hadoop.hbase.master.snapshot.SnapshotManager)

Example 4 with ZKWatcher

use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.

the class IntegrationTestMetaReplicas method setUp.

@BeforeClass
public static void setUp() throws Exception {
    // Set up the integration test util
    if (util == null) {
        util = new IntegrationTestingUtility();
    }
    util.getConfiguration().setInt(StorefileRefresherChore.REGIONSERVER_STOREFILE_REFRESH_PERIOD, 1000);
    // Make sure there are three servers.
    util.initializeCluster(3);
    HBaseTestingUtil.setReplicas(util.getAdmin(), TableName.META_TABLE_NAME, 3);
    ZKWatcher zkw = util.getZooKeeperWatcher();
    Configuration conf = util.getConfiguration();
    String baseZNode = conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT);
    String primaryMetaZnode = ZNodePaths.joinZNode(baseZNode, conf.get("zookeeper.znode.metaserver", "meta-region-server"));
    // check that the data in the znode is parseable (this would also mean the znode exists)
    byte[] data = ZKUtil.getData(zkw, primaryMetaZnode);
    ProtobufUtil.toServerName(data);
    waitUntilZnodeAvailable(1);
    waitUntilZnodeAvailable(2);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) BeforeClass(org.junit.BeforeClass)

Example 5 with ZKWatcher

use of org.apache.hadoop.hbase.zookeeper.ZKWatcher in project hbase by apache.

the class RegionServerSnapshotManager method initialize.

/**
 * Create a default snapshot handler - uses a zookeeper based member controller.
 * @param rss region server running the handler
 * @throws KeeperException if the zookeeper cluster cannot be reached
 */
@Override
public void initialize(RegionServerServices rss) throws KeeperException {
    this.rss = rss;
    ZKWatcher zkw = rss.getZooKeeper();
    this.memberRpcs = new ZKProcedureMemberRpcs(zkw, SnapshotManager.ONLINE_SNAPSHOT_CONTROLLER_DESCRIPTION);
    // read in the snapshot request configuration properties
    Configuration conf = rss.getConfiguration();
    long keepAlive = conf.getLong(SNAPSHOT_TIMEOUT_MILLIS_KEY, SNAPSHOT_TIMEOUT_MILLIS_DEFAULT);
    int opThreads = conf.getInt(SNAPSHOT_REQUEST_THREADS_KEY, SNAPSHOT_REQUEST_THREADS_DEFAULT);
    // create the actual snapshot procedure member
    ThreadPoolExecutor pool = ProcedureMember.defaultPool(rss.getServerName().toString(), opThreads, keepAlive);
    this.member = new ProcedureMember(memberRpcs, pool, new SnapshotSubprocedureBuilder());
}
Also used : ProcedureMember(org.apache.hadoop.hbase.procedure.ProcedureMember) Configuration(org.apache.hadoop.conf.Configuration) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) ZKProcedureMemberRpcs(org.apache.hadoop.hbase.procedure.ZKProcedureMemberRpcs) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

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