Search in sources :

Example 1 with LogEntry

use of org.apache.hadoop.hbase.client.LogEntry in project hbase by apache.

the class TestBalancerRejection method getBalancerRejectionLogEntries.

private List<LogEntry> getBalancerRejectionLogEntries(MasterClusterInfoProvider provider) {
    NamedQueueGetRequest namedQueueGetRequest = new NamedQueueGetRequest();
    namedQueueGetRequest.setNamedQueueEvent(BalancerRejectionDetails.BALANCER_REJECTION_EVENT);
    namedQueueGetRequest.setBalancerRejectionsRequest(MasterProtos.BalancerRejectionsRequest.getDefaultInstance());
    NamedQueueGetResponse namedQueueGetResponse = provider.getNamedQueueRecorder().getNamedQueueRecords(namedQueueGetRequest);
    List<RecentLogs.BalancerRejection> balancerRejections = namedQueueGetResponse.getBalancerRejections();
    MasterProtos.BalancerRejectionsResponse response = MasterProtos.BalancerRejectionsResponse.newBuilder().addAllBalancerRejection(balancerRejections).build();
    List<LogEntry> balancerRejectionRecords = ProtobufUtil.getBalancerRejectionEntries(response);
    return balancerRejectionRecords;
}
Also used : NamedQueueGetResponse(org.apache.hadoop.hbase.namequeues.response.NamedQueueGetResponse) NamedQueueGetRequest(org.apache.hadoop.hbase.namequeues.request.NamedQueueGetRequest) LogEntry(org.apache.hadoop.hbase.client.LogEntry) MasterProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos)

Example 2 with LogEntry

use of org.apache.hadoop.hbase.client.LogEntry in project hbase by apache.

the class TestBalancerDecision method testBalancerDecisions.

@Test
public void testBalancerDecisions() {
    conf.setBoolean("hbase.master.balancer.decision.buffer.enabled", true);
    MasterServices services = mock(MasterServices.class);
    when(services.getConfiguration()).thenReturn(conf);
    MasterClusterInfoProvider provider = new MasterClusterInfoProvider(services);
    loadBalancer.setClusterInfoProvider(provider);
    loadBalancer.onConfigurationChange(conf);
    float minCost = conf.getFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 0.05f);
    conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 1.0f);
    try {
        // Test with/without per table balancer.
        boolean[] perTableBalancerConfigs = { true, false };
        for (boolean isByTable : perTableBalancerConfigs) {
            conf.setBoolean(HConstants.HBASE_MASTER_LOADBALANCE_BYTABLE, isByTable);
            loadBalancer.onConfigurationChange(conf);
            for (int[] mockCluster : clusterStateMocks) {
                Map<ServerName, List<RegionInfo>> servers = mockClusterServers(mockCluster);
                Map<TableName, Map<ServerName, List<RegionInfo>>> LoadOfAllTable = (Map) mockClusterServersWithTables(servers);
                List<RegionPlan> plans = loadBalancer.balanceCluster(LoadOfAllTable);
                boolean emptyPlans = plans == null || plans.isEmpty();
                Assert.assertTrue(emptyPlans || needsBalanceIdleRegion(mockCluster));
            }
        }
        final NamedQueueGetRequest namedQueueGetRequest = new NamedQueueGetRequest();
        namedQueueGetRequest.setNamedQueueEvent(BalancerDecisionDetails.BALANCER_DECISION_EVENT);
        namedQueueGetRequest.setBalancerDecisionsRequest(MasterProtos.BalancerDecisionsRequest.getDefaultInstance());
        NamedQueueGetResponse namedQueueGetResponse = provider.getNamedQueueRecorder().getNamedQueueRecords(namedQueueGetRequest);
        List<RecentLogs.BalancerDecision> balancerDecisions = namedQueueGetResponse.getBalancerDecisions();
        MasterProtos.BalancerDecisionsResponse response = MasterProtos.BalancerDecisionsResponse.newBuilder().addAllBalancerDecision(balancerDecisions).build();
        List<LogEntry> balancerDecisionRecords = ProtobufUtil.getBalancerDecisionEntries(response);
        Assert.assertTrue(balancerDecisionRecords.size() > 160);
    } finally {
        // reset config
        conf.unset(HConstants.HBASE_MASTER_LOADBALANCE_BYTABLE);
        conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", minCost);
        loadBalancer.onConfigurationChange(conf);
    }
}
Also used : RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) MasterServices(org.apache.hadoop.hbase.master.MasterServices) TableName(org.apache.hadoop.hbase.TableName) RegionPlan(org.apache.hadoop.hbase.master.RegionPlan) ServerName(org.apache.hadoop.hbase.ServerName) List(java.util.List) NamedQueueGetResponse(org.apache.hadoop.hbase.namequeues.response.NamedQueueGetResponse) Map(java.util.Map) NamedQueueGetRequest(org.apache.hadoop.hbase.namequeues.request.NamedQueueGetRequest) LogEntry(org.apache.hadoop.hbase.client.LogEntry) MasterProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos) Test(org.junit.Test)

Example 3 with LogEntry

use of org.apache.hadoop.hbase.client.LogEntry in project hbase by apache.

the class TestBalancerRejection method testBalancerRejections.

@Test
public void testBalancerRejections() throws Exception {
    try {
        // enabled balancer rejection recording
        conf.setBoolean(BaseLoadBalancer.BALANCER_REJECTION_BUFFER_ENABLED, true);
        conf.set(StochasticLoadBalancer.COST_FUNCTIONS_COST_FUNCTIONS_KEY, MockCostFunction.class.getName());
        MasterServices services = mock(MasterServices.class);
        when(services.getConfiguration()).thenReturn(conf);
        MasterClusterInfoProvider provider = new MasterClusterInfoProvider(services);
        loadBalancer.setClusterInfoProvider(provider);
        loadBalancer.onConfigurationChange(conf);
        // Simulate 2 servers with 5 regions.
        Map<ServerName, List<RegionInfo>> servers = mockClusterServers(new int[] { 5, 5 });
        Map<TableName, Map<ServerName, List<RegionInfo>>> LoadOfAllTable = (Map) mockClusterServersWithTables(servers);
        // Reject case 1: Total cost < 0
        MockCostFunction.mockCost = -Double.MAX_VALUE;
        // Since the Balancer was rejected, there should not be any plans
        Assert.assertNull(loadBalancer.balanceCluster(LoadOfAllTable));
        // Reject case 2: Cost < minCostNeedBalance
        MockCostFunction.mockCost = 1;
        conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", Float.MAX_VALUE);
        loadBalancer.onConfigurationChange(conf);
        Assert.assertNull(loadBalancer.balanceCluster(LoadOfAllTable));
        // NamedQueue is an async Producer-consumer Pattern, waiting here until it completed
        int maxWaitingCount = 10;
        while (maxWaitingCount-- > 0 && getBalancerRejectionLogEntries(provider).size() != 2) {
            Thread.sleep(1000);
        }
        // There are two cases, should be 2 logEntries
        List<LogEntry> logEntries = getBalancerRejectionLogEntries(provider);
        Assert.assertEquals(2, logEntries.size());
        Assert.assertTrue(logEntries.get(0).toJsonPrettyPrint().contains("minCostNeedBalance"));
        Assert.assertTrue(logEntries.get(1).toJsonPrettyPrint().contains("cost1*multiplier1"));
    } finally {
        conf.unset(StochasticLoadBalancer.COST_FUNCTIONS_COST_FUNCTIONS_KEY);
        conf.unset(BaseLoadBalancer.BALANCER_REJECTION_BUFFER_ENABLED);
        loadBalancer.onConfigurationChange(conf);
    }
}
Also used : RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) MasterServices(org.apache.hadoop.hbase.master.MasterServices) TableName(org.apache.hadoop.hbase.TableName) ServerName(org.apache.hadoop.hbase.ServerName) List(java.util.List) Map(java.util.Map) LogEntry(org.apache.hadoop.hbase.client.LogEntry) Test(org.junit.Test)

Aggregations

LogEntry (org.apache.hadoop.hbase.client.LogEntry)3 List (java.util.List)2 Map (java.util.Map)2 ServerName (org.apache.hadoop.hbase.ServerName)2 TableName (org.apache.hadoop.hbase.TableName)2 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)2 MasterServices (org.apache.hadoop.hbase.master.MasterServices)2 NamedQueueGetRequest (org.apache.hadoop.hbase.namequeues.request.NamedQueueGetRequest)2 NamedQueueGetResponse (org.apache.hadoop.hbase.namequeues.response.NamedQueueGetResponse)2 MasterProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos)2 Test (org.junit.Test)2 RegionPlan (org.apache.hadoop.hbase.master.RegionPlan)1