Search in sources :

Example 6 with RegionMetrics

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

the class TestRegionHDFSBlockLocationFinder method getMetricsWithLocality.

private ClusterMetrics getMetricsWithLocality(ServerName serverName, byte[] region, float locality) {
    RegionMetrics regionMetrics = mock(RegionMetrics.class);
    when(regionMetrics.getDataLocality()).thenReturn(locality);
    Map<byte[], RegionMetrics> regionMetricsMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
    regionMetricsMap.put(region, regionMetrics);
    ServerMetrics serverMetrics = mock(ServerMetrics.class);
    when(serverMetrics.getRegionMetrics()).thenReturn(regionMetricsMap);
    Map<ServerName, ServerMetrics> serverMetricsMap = new HashMap<>();
    serverMetricsMap.put(serverName, serverMetrics);
    ClusterMetrics metrics = mock(ClusterMetrics.class);
    when(metrics.getLiveServerMetrics()).thenReturn(serverMetricsMap);
    return metrics;
}
Also used : ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) HashMap(java.util.HashMap) ServerName(org.apache.hadoop.hbase.ServerName) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) TreeMap(java.util.TreeMap) RegionMetrics(org.apache.hadoop.hbase.RegionMetrics)

Example 7 with RegionMetrics

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

the class TestStochasticLoadBalancer method testKeepRegionLoad.

@Test
public void testKeepRegionLoad() throws Exception {
    ServerName sn = ServerName.valueOf("test:8080", 100);
    int numClusterStatusToAdd = 20000;
    for (int i = 0; i < numClusterStatusToAdd; i++) {
        ServerMetrics sl = mock(ServerMetrics.class);
        RegionMetrics rl = mock(RegionMetrics.class);
        when(rl.getReadRequestCount()).thenReturn(0L);
        when(rl.getCpRequestCount()).thenReturn(0L);
        when(rl.getWriteRequestCount()).thenReturn(0L);
        when(rl.getMemStoreSize()).thenReturn(Size.ZERO);
        when(rl.getStoreFileSize()).thenReturn(new Size(i, Size.Unit.MEGABYTE));
        Map<byte[], RegionMetrics> regionLoadMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
        regionLoadMap.put(Bytes.toBytes(REGION_KEY), rl);
        when(sl.getRegionMetrics()).thenReturn(regionLoadMap);
        ClusterMetrics clusterStatus = mock(ClusterMetrics.class);
        Map<ServerName, ServerMetrics> serverMetricsMap = new TreeMap<>();
        serverMetricsMap.put(sn, sl);
        when(clusterStatus.getLiveServerMetrics()).thenReturn(serverMetricsMap);
        loadBalancer.updateClusterMetrics(clusterStatus);
    }
    String regionNameAsString = RegionInfo.getRegionNameAsString(Bytes.toBytes(REGION_KEY));
    assertTrue(loadBalancer.loads.get(regionNameAsString) != null);
    assertTrue(loadBalancer.loads.get(regionNameAsString).size() == 15);
    Queue<BalancerRegionLoad> loads = loadBalancer.loads.get(regionNameAsString);
    int i = 0;
    while (loads.size() > 0) {
        BalancerRegionLoad rl = loads.remove();
        assertEquals(i + (numClusterStatusToAdd - 15), rl.getStorefileSizeMB());
        i++;
    }
}
Also used : ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) Size(org.apache.hadoop.hbase.Size) ServerName(org.apache.hadoop.hbase.ServerName) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) TreeMap(java.util.TreeMap) RegionMetrics(org.apache.hadoop.hbase.RegionMetrics) Test(org.junit.Test)

Example 8 with RegionMetrics

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

the class TestRegionsRecoveryChore method testRegionReopensWithoutStoreRefConfig.

@Test
public void testRegionReopensWithoutStoreRefConfig() throws Exception {
    regionNo = 0;
    ClusterMetrics clusterMetrics = TestRegionsRecoveryChore.getClusterMetrics(10);
    final Map<ServerName, ServerMetrics> serverMetricsMap = clusterMetrics.getLiveServerMetrics();
    LOG.debug("All Region Names with refCount....");
    for (ServerMetrics serverMetrics : serverMetricsMap.values()) {
        Map<byte[], RegionMetrics> regionMetricsMap = serverMetrics.getRegionMetrics();
        for (RegionMetrics regionMetrics : regionMetricsMap.values()) {
            LOG.debug("name: " + new String(regionMetrics.getRegionName()) + " refCount: " + regionMetrics.getStoreRefCount());
        }
    }
    Mockito.when(hMaster.getClusterMetrics()).thenReturn(clusterMetrics);
    Mockito.when(hMaster.getAssignmentManager()).thenReturn(assignmentManager);
    for (byte[] regionName : REGION_NAME_LIST) {
        Mockito.when(assignmentManager.getRegionInfo(regionName)).thenReturn(TestRegionsRecoveryChore.getRegionInfo(regionName));
    }
    Stoppable stoppable = new StoppableImplementation();
    Configuration configuration = getCustomConf();
    configuration.unset("hbase.regions.recovery.store.file.ref.count");
    regionsRecoveryChore = new RegionsRecoveryChore(stoppable, configuration, hMaster);
    regionsRecoveryChore.chore();
    // Verify that by default the feature is turned off so no regions
    // should be reopened
    Mockito.verify(hMaster, Mockito.times(0)).reopenRegions(Mockito.any(), Mockito.anyList(), Mockito.anyLong(), Mockito.anyLong());
    // default maxCompactedStoreFileRefCount is -1 (no regions to be reopened using AM)
    Mockito.verify(hMaster, Mockito.times(0)).getAssignmentManager();
    Mockito.verify(assignmentManager, Mockito.times(0)).getRegionInfo(Mockito.any());
}
Also used : ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) Configuration(org.apache.hadoop.conf.Configuration) ServerName(org.apache.hadoop.hbase.ServerName) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) Stoppable(org.apache.hadoop.hbase.Stoppable) RegionMetrics(org.apache.hadoop.hbase.RegionMetrics) Test(org.junit.Test)

Example 9 with RegionMetrics

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

the class TestRegionsRecoveryChore method getServerMetrics.

private static ServerMetrics getServerMetrics(int noOfRegions) {
    ServerMetrics serverMetrics = new ServerMetrics() {

        @Override
        public ServerName getServerName() {
            return null;
        }

        @Override
        public long getRequestCountPerSecond() {
            return 0;
        }

        @Override
        public long getRequestCount() {
            return 0;
        }

        @Override
        public long getReadRequestsCount() {
            return 0;
        }

        @Override
        public long getWriteRequestsCount() {
            return 0;
        }

        @Override
        public Size getUsedHeapSize() {
            return null;
        }

        @Override
        public Size getMaxHeapSize() {
            return null;
        }

        @Override
        public int getInfoServerPort() {
            return 0;
        }

        @Override
        public List<ReplicationLoadSource> getReplicationLoadSourceList() {
            return null;
        }

        @Override
        public Map<String, List<ReplicationLoadSource>> getReplicationLoadSourceMap() {
            return null;
        }

        @Nullable
        @Override
        public ReplicationLoadSink getReplicationLoadSink() {
            return null;
        }

        @Override
        public Map<byte[], RegionMetrics> getRegionMetrics() {
            Map<byte[], RegionMetrics> regionMetricsMap = new HashMap<>();
            for (int i = 0; i < noOfRegions; i++) {
                byte[] regionName = Bytes.toBytes("region" + regionNo + "_" + i);
                regionMetricsMap.put(regionName, TestRegionsRecoveryChore.getRegionMetrics(regionName, 100 * i));
                ++regionNo;
            }
            return regionMetricsMap;
        }

        @Override
        public Map<byte[], UserMetrics> getUserMetrics() {
            return new HashMap<>();
        }

        @Override
        public Set<String> getCoprocessorNames() {
            return null;
        }

        @Override
        public long getReportTimestamp() {
            return 0;
        }

        @Override
        public long getLastReportTimestamp() {
            return 0;
        }

        @Override
        public List<ServerTask> getTasks() {
            return null;
        }
    };
    return serverMetrics;
}
Also used : ReplicationLoadSource(org.apache.hadoop.hbase.replication.ReplicationLoadSource) ServerTask(org.apache.hadoop.hbase.ServerTask) HashMap(java.util.HashMap) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) List(java.util.List) UserMetrics(org.apache.hadoop.hbase.UserMetrics) RegionMetrics(org.apache.hadoop.hbase.RegionMetrics)

Example 10 with RegionMetrics

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

the class TestRegionsRecoveryChore method testRegionReopensWithLessThreshold.

@Test
public void testRegionReopensWithLessThreshold() throws Exception {
    regionNo = 0;
    ClusterMetrics clusterMetrics = TestRegionsRecoveryChore.getClusterMetrics(4);
    final Map<ServerName, ServerMetrics> serverMetricsMap = clusterMetrics.getLiveServerMetrics();
    LOG.debug("All Region Names with refCount....");
    for (ServerMetrics serverMetrics : serverMetricsMap.values()) {
        Map<byte[], RegionMetrics> regionMetricsMap = serverMetrics.getRegionMetrics();
        for (RegionMetrics regionMetrics : regionMetricsMap.values()) {
            LOG.debug("name: " + new String(regionMetrics.getRegionName()) + " refCount: " + regionMetrics.getStoreRefCount());
        }
    }
    Mockito.when(hMaster.getClusterMetrics()).thenReturn(clusterMetrics);
    Mockito.when(hMaster.getAssignmentManager()).thenReturn(assignmentManager);
    for (byte[] regionName : REGION_NAME_LIST) {
        Mockito.when(assignmentManager.getRegionInfo(regionName)).thenReturn(TestRegionsRecoveryChore.getRegionInfo(regionName));
    }
    Stoppable stoppable = new StoppableImplementation();
    Configuration configuration = getCustomConf();
    configuration.setInt("hbase.regions.recovery.store.file.ref.count", 400);
    regionsRecoveryChore = new RegionsRecoveryChore(stoppable, configuration, hMaster);
    regionsRecoveryChore.chore();
    // Verify that we need to reopen regions of only 1 table
    Mockito.verify(hMaster, Mockito.times(1)).reopenRegions(Mockito.any(), Mockito.anyList(), Mockito.anyLong(), Mockito.anyLong());
    Mockito.verify(hMaster, Mockito.times(1)).getClusterMetrics();
    // Verify that we need to reopen only 1 region with refCount > 400
    Mockito.verify(hMaster, Mockito.times(1)).getAssignmentManager();
    Mockito.verify(assignmentManager, Mockito.times(1)).getRegionInfo(Mockito.any());
}
Also used : ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) Configuration(org.apache.hadoop.conf.Configuration) ServerName(org.apache.hadoop.hbase.ServerName) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) Stoppable(org.apache.hadoop.hbase.Stoppable) RegionMetrics(org.apache.hadoop.hbase.RegionMetrics) Test(org.junit.Test)

Aggregations

RegionMetrics (org.apache.hadoop.hbase.RegionMetrics)25 ServerMetrics (org.apache.hadoop.hbase.ServerMetrics)18 ServerName (org.apache.hadoop.hbase.ServerName)16 ClusterMetrics (org.apache.hadoop.hbase.ClusterMetrics)7 HashMap (java.util.HashMap)6 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)5 Test (org.junit.Test)5 Map (java.util.Map)4 TreeMap (java.util.TreeMap)4 Size (org.apache.hadoop.hbase.Size)4 ArrayList (java.util.ArrayList)3 Configuration (org.apache.hadoop.conf.Configuration)3 Stoppable (org.apache.hadoop.hbase.Stoppable)3 IOException (java.io.IOException)2 List (java.util.List)2 TableName (org.apache.hadoop.hbase.TableName)2 UserMetrics (org.apache.hadoop.hbase.UserMetrics)2 InterruptedIOException (java.io.InterruptedIOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UnknownHostException (java.net.UnknownHostException)1