Search in sources :

Example 16 with ClusterStatus

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

the class TestReplicationStatus method testReplicationStatus.

/**
   * Test for HBASE-9531
   * put a few rows into htable1, which should be replicated to htable2
   * create a ClusterStatus instance 'status' from HBaseAdmin
   * test : status.getLoad(server).getReplicationLoadSourceList()
   * test : status.getLoad(server).getReplicationLoadSink()
   * * @throws Exception
   */
@Test(timeout = 300000)
public void testReplicationStatus() throws Exception {
    LOG.info("testReplicationStatus");
    try (Admin hbaseAdmin = utility1.getConnection().getAdmin()) {
        // disable peer
        admin.disablePeer(PEER_ID);
        final byte[] qualName = Bytes.toBytes("q");
        Put p;
        for (int i = 0; i < NB_ROWS_IN_BATCH; i++) {
            p = new Put(Bytes.toBytes("row" + i));
            p.addColumn(famName, qualName, Bytes.toBytes("val" + i));
            htable1.put(p);
        }
        ClusterStatus status = hbaseAdmin.getClusterStatus();
        for (JVMClusterUtil.RegionServerThread thread : utility1.getHBaseCluster().getRegionServerThreads()) {
            ServerName server = thread.getRegionServer().getServerName();
            ServerLoad sl = status.getLoad(server);
            List<ReplicationLoadSource> rLoadSourceList = sl.getReplicationLoadSourceList();
            ReplicationLoadSink rLoadSink = sl.getReplicationLoadSink();
            // check SourceList only has one entry, beacuse only has one peer
            assertTrue("failed to get ReplicationLoadSourceList", (rLoadSourceList.size() == 1));
            assertEquals(PEER_ID, rLoadSourceList.get(0).getPeerID());
            // check Sink exist only as it is difficult to verify the value on the fly
            assertTrue("failed to get ReplicationLoadSink.AgeOfLastShippedOp ", (rLoadSink.getAgeOfLastAppliedOp() >= 0));
            assertTrue("failed to get ReplicationLoadSink.TimeStampsOfLastAppliedOp ", (rLoadSink.getTimeStampsOfLastAppliedOp() >= 0));
        }
        // Stop rs1, then the queue of rs1 will be transfered to rs0
        utility1.getHBaseCluster().getRegionServer(1).stop("Stop RegionServer");
        Thread.sleep(10000);
        status = hbaseAdmin.getClusterStatus();
        ServerName server = utility1.getHBaseCluster().getRegionServer(0).getServerName();
        ServerLoad sl = status.getLoad(server);
        List<ReplicationLoadSource> rLoadSourceList = sl.getReplicationLoadSourceList();
        // check SourceList still only has one entry
        assertTrue("failed to get ReplicationLoadSourceList", (rLoadSourceList.size() == 1));
        assertEquals(PEER_ID, rLoadSourceList.get(0).getPeerID());
    } finally {
        admin.enablePeer(PEER_ID);
        utility1.getHBaseCluster().getRegionServer(1).start();
    }
}
Also used : ServerLoad(org.apache.hadoop.hbase.ServerLoad) JVMClusterUtil(org.apache.hadoop.hbase.util.JVMClusterUtil) ServerName(org.apache.hadoop.hbase.ServerName) Admin(org.apache.hadoop.hbase.client.Admin) Put(org.apache.hadoop.hbase.client.Put) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus) Test(org.junit.Test)

Example 17 with ClusterStatus

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

the class TestMasterReplication method testLoopedReplication.

/**
   * Tests the replication scenario 0 -> 0. By default
   * {@link BaseReplicationEndpoint#canReplicateToSameCluster()} returns false, so the
   * ReplicationSource should terminate, and no further logs should get enqueued
   */
@Test(timeout = 300000)
public void testLoopedReplication() throws Exception {
    LOG.info("testLoopedReplication");
    startMiniClusters(1);
    createTableOnClusters(table);
    addPeer("1", 0, 0);
    Thread.sleep(SLEEP_TIME);
    // wait for source to terminate
    final ServerName rsName = utilities[0].getHBaseCluster().getRegionServer(0).getServerName();
    Waiter.waitFor(baseConfiguration, 10000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            ClusterStatus clusterStatus = utilities[0].getAdmin().getClusterStatus();
            ServerLoad serverLoad = clusterStatus.getLoad(rsName);
            List<ReplicationLoadSource> replicationLoadSourceList = serverLoad.getReplicationLoadSourceList();
            return replicationLoadSourceList.isEmpty();
        }
    });
    Table[] htables = getHTablesOnClusters(tableName);
    putAndWait(row, famName, htables[0], htables[0]);
    rollWALAndWait(utilities[0], table.getTableName(), row);
    ZooKeeperWatcher zkw = utilities[0].getZooKeeperWatcher();
    String queuesZnode = ZKUtil.joinZNode(zkw.getZNodePaths().baseZNode, ZKUtil.joinZNode("replication", "rs"));
    List<String> listChildrenNoWatch = ZKUtil.listChildrenNoWatch(zkw, ZKUtil.joinZNode(queuesZnode, rsName.toString()));
    assertEquals(0, listChildrenNoWatch.size());
}
Also used : Table(org.apache.hadoop.hbase.client.Table) IOException(java.io.IOException) ServerLoad(org.apache.hadoop.hbase.ServerLoad) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) ServerName(org.apache.hadoop.hbase.ServerName) List(java.util.List) Waiter(org.apache.hadoop.hbase.Waiter) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus) Test(org.junit.Test)

Example 18 with ClusterStatus

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

the class Action method getCurrentServers.

/** Returns current region servers - active master */
protected ServerName[] getCurrentServers() throws IOException {
    ClusterStatus clusterStatus = cluster.getClusterStatus();
    Collection<ServerName> regionServers = clusterStatus.getServers();
    int count = regionServers == null ? 0 : regionServers.size();
    if (count <= 0) {
        return new ServerName[] {};
    }
    ServerName master = clusterStatus.getMaster();
    if (master == null || !regionServers.contains(master)) {
        return regionServers.toArray(new ServerName[count]);
    }
    if (count == 1) {
        return new ServerName[] {};
    }
    ArrayList<ServerName> tmp = new ArrayList<>(count);
    tmp.addAll(regionServers);
    tmp.remove(master);
    return tmp.toArray(new ServerName[count - 1]);
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus)

Example 19 with ClusterStatus

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

the class UnbalanceRegionsAction method perform.

@Override
public void perform() throws Exception {
    LOG.info("Unbalancing regions");
    ClusterStatus status = this.cluster.getClusterStatus();
    List<ServerName> victimServers = new LinkedList<>(status.getServers());
    int targetServerCount = (int) Math.ceil(fractionOfServers * victimServers.size());
    List<ServerName> targetServers = new ArrayList<>(targetServerCount);
    for (int i = 0; i < targetServerCount; ++i) {
        int victimIx = RandomUtils.nextInt(victimServers.size());
        targetServers.add(victimServers.remove(victimIx));
    }
    unbalanceRegions(status, victimServers, targetServers, fractionOfRegions);
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus) LinkedList(java.util.LinkedList)

Example 20 with ClusterStatus

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

the class RestartRsHoldingMetaAction method perform.

@Override
public void perform() throws Exception {
    LOG.info("Performing action: Restart region server holding META");
    ServerName server = cluster.getServerHoldingMeta();
    if (server == null) {
        LOG.warn("No server is holding hbase:meta right now.");
        return;
    }
    ClusterStatus clusterStatus = cluster.getClusterStatus();
    if (server.equals(clusterStatus.getMaster())) {
        // Master holds the meta, so restart the master.
        restartMaster(server, sleepTime);
    } else {
        restartRs(server, sleepTime);
    }
}
Also used : 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