Search in sources :

Example 11 with ClusterStatus

use of org.apache.hadoop.hbase.ClusterStatus in project hbase by apache.

the class HMaster method getClusterStatus.

/**
   * @return cluster status
   */
public ClusterStatus getClusterStatus() throws InterruptedIOException {
    // Build Set of backup masters from ZK nodes
    List<String> backupMasterStrings;
    try {
        backupMasterStrings = ZKUtil.listChildrenNoWatch(this.zooKeeper, this.zooKeeper.znodePaths.backupMasterAddressesZNode);
    } catch (KeeperException e) {
        LOG.warn(this.zooKeeper.prefix("Unable to list backup servers"), e);
        backupMasterStrings = null;
    }
    List<ServerName> backupMasters = null;
    if (backupMasterStrings != null && !backupMasterStrings.isEmpty()) {
        backupMasters = new ArrayList<>(backupMasterStrings.size());
        for (String s : backupMasterStrings) {
            try {
                byte[] bytes;
                try {
                    bytes = ZKUtil.getData(this.zooKeeper, ZKUtil.joinZNode(this.zooKeeper.znodePaths.backupMasterAddressesZNode, s));
                } catch (InterruptedException e) {
                    throw new InterruptedIOException();
                }
                if (bytes != null) {
                    ServerName sn;
                    try {
                        sn = ProtobufUtil.parseServerNameFrom(bytes);
                    } catch (DeserializationException e) {
                        LOG.warn("Failed parse, skipping registering backup server", e);
                        continue;
                    }
                    backupMasters.add(sn);
                }
            } catch (KeeperException e) {
                LOG.warn(this.zooKeeper.prefix("Unable to get information about " + "backup servers"), e);
            }
        }
        Collections.sort(backupMasters, new Comparator<ServerName>() {

            @Override
            public int compare(ServerName s1, ServerName s2) {
                return s1.getServerName().compareTo(s2.getServerName());
            }
        });
    }
    String clusterId = fileSystemManager != null ? fileSystemManager.getClusterId().toString() : null;
    Set<RegionState> regionsInTransition = assignmentManager != null ? assignmentManager.getRegionStates().getRegionsInTransition() : null;
    String[] coprocessors = cpHost != null ? getMasterCoprocessors() : null;
    boolean balancerOn = loadBalancerTracker != null ? loadBalancerTracker.isBalancerOn() : false;
    Map<ServerName, ServerLoad> onlineServers = null;
    Set<ServerName> deadServers = null;
    if (serverManager != null) {
        deadServers = serverManager.getDeadServers().copyServerNames();
        onlineServers = serverManager.getOnlineServers();
    }
    return new ClusterStatus(VersionInfo.getVersion(), clusterId, onlineServers, deadServers, serverName, backupMasters, regionsInTransition, coprocessors, balancerOn);
}
Also used : InterruptedIOException(java.io.InterruptedIOException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException) ServerLoad(org.apache.hadoop.hbase.ServerLoad) ServerName(org.apache.hadoop.hbase.ServerName) KeeperException(org.apache.zookeeper.KeeperException) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus)

Example 12 with ClusterStatus

use of org.apache.hadoop.hbase.ClusterStatus in project hbase by apache.

the class TestMasterFailover method testSimpleMasterFailover.

/**
   * Simple test of master failover.
   * <p>
   * Starts with three masters.  Kills a backup master.  Then kills the active
   * master.  Ensures the final master becomes active and we can still contact
   * the cluster.
   * @throws Exception
   */
@Test(timeout = 240000)
public void testSimpleMasterFailover() throws Exception {
    final int NUM_MASTERS = 3;
    final int NUM_RS = 3;
    // Start the cluster
    HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
    TEST_UTIL.startMiniCluster(NUM_MASTERS, NUM_RS);
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    // get all the master threads
    List<MasterThread> masterThreads = cluster.getMasterThreads();
    // wait for each to come online
    for (MasterThread mt : masterThreads) {
        assertTrue(mt.isAlive());
    }
    // verify only one is the active master and we have right number
    int numActive = 0;
    int activeIndex = -1;
    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();
        }
    }
    assertEquals(1, numActive);
    assertEquals(NUM_MASTERS, masterThreads.size());
    LOG.info("Active master " + activeName);
    // Check that ClusterStatus reports the correct active and backup masters
    assertNotNull(active);
    ClusterStatus status = active.getClusterStatus();
    assertTrue(status.getMaster().equals(activeName));
    assertEquals(2, status.getBackupMastersSize());
    assertEquals(2, status.getBackupMasters().size());
    // attempt to stop one of the inactive masters
    int backupIndex = (activeIndex == 0 ? 1 : activeIndex - 1);
    HMaster master = cluster.getMaster(backupIndex);
    LOG.debug("\n\nStopping a backup master: " + master.getServerName() + "\n");
    cluster.stopMaster(backupIndex, false);
    cluster.waitOnMaster(backupIndex);
    // Verify still one active master and it's the same
    for (int i = 0; i < masterThreads.size(); i++) {
        if (masterThreads.get(i).getMaster().isActiveMaster()) {
            assertTrue(activeName.equals(masterThreads.get(i).getMaster().getServerName()));
            activeIndex = i;
            active = masterThreads.get(activeIndex).getMaster();
        }
    }
    assertEquals(1, numActive);
    assertEquals(2, masterThreads.size());
    int rsCount = masterThreads.get(activeIndex).getMaster().getClusterStatus().getServersSize();
    LOG.info("Active master " + active.getServerName() + " managing " + rsCount + " regions servers");
    assertEquals(4, rsCount);
    // Check that ClusterStatus reports the correct active and backup masters
    assertNotNull(active);
    status = active.getClusterStatus();
    assertTrue(status.getMaster().equals(activeName));
    assertEquals(1, status.getBackupMastersSize());
    assertEquals(1, status.getBackupMasters().size());
    // kill the active master
    LOG.debug("\n\nStopping the active master " + active.getServerName() + "\n");
    cluster.stopMaster(activeIndex, false);
    cluster.waitOnMaster(activeIndex);
    // wait for an active master to show up and be ready
    assertTrue(cluster.waitForActiveAndReadyMaster());
    LOG.debug("\n\nVerifying backup master is now active\n");
    // should only have one master now
    assertEquals(1, masterThreads.size());
    // and he should be active
    active = masterThreads.get(0).getMaster();
    assertNotNull(active);
    status = active.getClusterStatus();
    ServerName mastername = status.getMaster();
    assertTrue(mastername.equals(active.getServerName()));
    assertTrue(active.isActiveMaster());
    assertEquals(0, status.getBackupMastersSize());
    assertEquals(0, status.getBackupMasters().size());
    int rss = status.getServersSize();
    LOG.info("Active master " + mastername.getServerName() + " managing " + rss + " region servers");
    assertEquals(4, rss);
    // Stop the cluster
    TEST_UTIL.shutdownMiniCluster();
}
Also used : HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) MasterThread(org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread) ServerName(org.apache.hadoop.hbase.ServerName) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus) Test(org.junit.Test)

Example 13 with ClusterStatus

use of org.apache.hadoop.hbase.ClusterStatus in project hbase by apache.

the class TestMasterFailoverBalancerPersistence method testMasterFailoverBalancerPersistence.

/**
   * Test that if the master fails, the load balancer maintains its
   * state (running or not) when the next master takes over
   *
   * @throws Exception
   */
@Test(timeout = 240000)
public void testMasterFailoverBalancerPersistence() throws Exception {
    final int NUM_MASTERS = 3;
    final int NUM_RS = 1;
    // Start the cluster
    HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
    TEST_UTIL.startMiniCluster(NUM_MASTERS, NUM_RS);
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    assertTrue(cluster.waitForActiveAndReadyMaster());
    HMaster active = cluster.getMaster();
    // check that the balancer is on by default for the active master
    ClusterStatus clusterStatus = active.getClusterStatus();
    assertTrue(clusterStatus.isBalancerOn());
    active = killActiveAndWaitForNewActive(cluster);
    // ensure the load balancer is still running on new master
    clusterStatus = active.getClusterStatus();
    assertTrue(clusterStatus.isBalancerOn());
    // turn off the load balancer
    active.balanceSwitch(false);
    // once more, kill active master and wait for new active master to show up
    active = killActiveAndWaitForNewActive(cluster);
    // ensure the load balancer is not running on the new master
    clusterStatus = active.getClusterStatus();
    assertFalse(clusterStatus.isBalancerOn());
    // Stop the cluster
    TEST_UTIL.shutdownMiniCluster();
}
Also used : HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus) Test(org.junit.Test)

Example 14 with ClusterStatus

use of org.apache.hadoop.hbase.ClusterStatus in project hbase by apache.

the class ProtobufUtil method convert.

/**
   * Convert a protobuf ClusterStatus to a ClusterStatus
   *
   * @param proto the protobuf ClusterStatus
   * @return the converted ClusterStatus
   */
public static ClusterStatus convert(ClusterStatusProtos.ClusterStatus proto) {
    Map<ServerName, ServerLoad> servers = null;
    servers = new HashMap<>(proto.getLiveServersList().size());
    for (LiveServerInfo lsi : proto.getLiveServersList()) {
        servers.put(ProtobufUtil.toServerName(lsi.getServer()), new ServerLoad(lsi.getServerLoad()));
    }
    Collection<ServerName> deadServers = null;
    deadServers = new ArrayList<>(proto.getDeadServersList().size());
    for (HBaseProtos.ServerName sn : proto.getDeadServersList()) {
        deadServers.add(ProtobufUtil.toServerName(sn));
    }
    Collection<ServerName> backupMasters = null;
    backupMasters = new ArrayList<>(proto.getBackupMastersList().size());
    for (HBaseProtos.ServerName sn : proto.getBackupMastersList()) {
        backupMasters.add(ProtobufUtil.toServerName(sn));
    }
    Set<RegionState> rit = null;
    rit = new HashSet<>(proto.getRegionsInTransitionList().size());
    for (RegionInTransition region : proto.getRegionsInTransitionList()) {
        RegionState value = RegionState.convert(region.getRegionState());
        rit.add(value);
    }
    String[] masterCoprocessors = null;
    final int numMasterCoprocessors = proto.getMasterCoprocessorsCount();
    masterCoprocessors = new String[numMasterCoprocessors];
    for (int i = 0; i < numMasterCoprocessors; i++) {
        masterCoprocessors[i] = proto.getMasterCoprocessors(i).getName();
    }
    return new ClusterStatus(proto.getHbaseVersion().getVersion(), ClusterId.convert(proto.getClusterId()).toString(), servers, deadServers, ProtobufUtil.toServerName(proto.getMaster()), backupMasters, rit, masterCoprocessors, proto.getBalancerOn());
}
Also used : ByteString(org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) HBaseProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos) ServerLoad(org.apache.hadoop.hbase.ServerLoad) RegionInTransition(org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.RegionInTransition) RegionState(org.apache.hadoop.hbase.master.RegionState) LiveServerInfo(org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.LiveServerInfo) ServerName(org.apache.hadoop.hbase.ServerName) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus)

Example 15 with ClusterStatus

use of org.apache.hadoop.hbase.ClusterStatus in project hbase by apache.

the class ProtobufUtil method convert.

/**
   * Convert a ClusterStatus to a protobuf ClusterStatus
   *
   * @return the protobuf ClusterStatus
   */
public static ClusterStatusProtos.ClusterStatus convert(ClusterStatus status) {
    ClusterStatusProtos.ClusterStatus.Builder builder = ClusterStatusProtos.ClusterStatus.newBuilder();
    builder.setHbaseVersion(HBaseVersionFileContent.newBuilder().setVersion(status.getHBaseVersion()));
    if (status.getServers() != null) {
        for (ServerName serverName : status.getServers()) {
            LiveServerInfo.Builder lsi = LiveServerInfo.newBuilder().setServer(ProtobufUtil.toServerName(serverName));
            status.getLoad(serverName);
            lsi.setServerLoad(status.getLoad(serverName).obtainServerLoadPB());
            builder.addLiveServers(lsi.build());
        }
    }
    if (status.getDeadServerNames() != null) {
        for (ServerName deadServer : status.getDeadServerNames()) {
            builder.addDeadServers(ProtobufUtil.toServerName(deadServer));
        }
    }
    if (status.getRegionsInTransition() != null) {
        for (RegionState rit : status.getRegionsInTransition()) {
            ClusterStatusProtos.RegionState rs = rit.convert();
            RegionSpecifier.Builder spec = RegionSpecifier.newBuilder().setType(RegionSpecifierType.REGION_NAME);
            spec.setValue(UnsafeByteOperations.unsafeWrap(rit.getRegion().getRegionName()));
            RegionInTransition pbRIT = RegionInTransition.newBuilder().setSpec(spec.build()).setRegionState(rs).build();
            builder.addRegionsInTransition(pbRIT);
        }
    }
    if (status.getClusterId() != null) {
        builder.setClusterId(new ClusterId(status.getClusterId()).convert());
    }
    if (status.getMasterCoprocessors() != null) {
        for (String coprocessor : status.getMasterCoprocessors()) {
            builder.addMasterCoprocessors(HBaseProtos.Coprocessor.newBuilder().setName(coprocessor));
        }
    }
    if (status.getMaster() != null) {
        builder.setMaster(ProtobufUtil.toServerName(status.getMaster()));
    }
    if (status.getBackupMasters() != null) {
        for (ServerName backup : status.getBackupMasters()) {
            builder.addBackupMasters(ProtobufUtil.toServerName(backup));
        }
    }
    if (status.getBalancerOn() != null) {
        builder.setBalancerOn(status.getBalancerOn());
    }
    return builder.build();
}
Also used : ClusterStatusProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos) ClusterId(org.apache.hadoop.hbase.ClusterId) ByteString(org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) RegionSpecifier(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier) RegionInTransition(org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.RegionInTransition) RegionState(org.apache.hadoop.hbase.master.RegionState) LiveServerInfo(org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.LiveServerInfo) ServerName(org.apache.hadoop.hbase.ServerName) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus)

Aggregations

ClusterStatus (org.apache.hadoop.hbase.ClusterStatus)23 ServerName (org.apache.hadoop.hbase.ServerName)19 ServerLoad (org.apache.hadoop.hbase.ServerLoad)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 RegionLoad (org.apache.hadoop.hbase.RegionLoad)4 HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)3 MiniHBaseCluster (org.apache.hadoop.hbase.MiniHBaseCluster)3 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)3 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 TableName (org.apache.hadoop.hbase.TableName)2 Admin (org.apache.hadoop.hbase.client.Admin)2 RegionState (org.apache.hadoop.hbase.master.RegionState)2 ByteString (org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString)2 LiveServerInfo (org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.LiveServerInfo)2 RegionInTransition (org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.RegionInTransition)2 MasterThread (org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread)2