Skip to content

Commit 7bbde6d

Browse files
committed
HBASE-27681 Refactor Table Latency Metrics
1 parent d2b0074 commit 7bbde6d

File tree

12 files changed

+636
-477
lines changed

12 files changed

+636
-477
lines changed

hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/impl/GlobalMetricRegistriesAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ private void doRun() {
115115
for (MetricRegistry registry : registries) {
116116
MetricRegistryInfo info = registry.getMetricRegistryInfo();
117117

118+
LOG.trace("MetricRegistryInfo : " + info.getMetricsName());
118119
if (info.isExistingSource()) {
119120
// If there is an already existing BaseSource for this MetricRegistry, skip it here. These
120121
// types of registries are there only due to existing BaseSource implementations in the

hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsTableQueryMeter.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsTableQueryMeterImpl.java

Lines changed: 0 additions & 99 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.metrics.impl;
19+
20+
import static org.junit.Assert.assertTrue;
21+
22+
import java.util.Optional;
23+
import org.apache.hadoop.hbase.HBaseClassTestRule;
24+
import org.apache.hadoop.hbase.metrics.MetricRegistries;
25+
import org.apache.hadoop.hbase.metrics.MetricRegistry;
26+
import org.apache.hadoop.hbase.metrics.MetricRegistryInfo;
27+
import org.apache.hadoop.hbase.testclassification.SmallTests;
28+
import org.junit.ClassRule;
29+
import org.junit.Test;
30+
import org.junit.experimental.categories.Category;
31+
32+
/**
33+
* Test class for {@link MetricRegistries}.
34+
*/
35+
@Category(SmallTests.class)
36+
public class TestMetricRegistriesImpl {
37+
38+
@ClassRule
39+
public static final HBaseClassTestRule CLASS_RULE =
40+
HBaseClassTestRule.forClass(TestMetricRegistriesImpl.class);
41+
42+
@Test
43+
public void testMetricsRegistriesRemoveRef() {
44+
MetricRegistryInfo registryInfo =
45+
new MetricRegistryInfo("testMetrics", null, null, null, false);
46+
MetricRegistries.global().create(registryInfo);
47+
Optional<MetricRegistry> registry1 = MetricRegistries.global().get(registryInfo);
48+
assertTrue(registry1.isPresent());
49+
50+
MetricRegistries.global().create(registryInfo);
51+
Optional<MetricRegistry> registry2 = MetricRegistries.global().get(registryInfo);
52+
assertTrue(registry2.isPresent());
53+
54+
MetricRegistries.global().remove(registryInfo);
55+
Optional<MetricRegistry> registry3 = MetricRegistries.global().get(registryInfo);
56+
assertTrue(registry3.isPresent());
57+
58+
MetricRegistries.global().remove(registryInfo);
59+
Optional<MetricRegistry> registry4 = MetricRegistries.global().get(registryInfo);
60+
assertTrue(!registry4.isPresent());
61+
}
62+
}

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
import org.apache.hadoop.hbase.regionserver.compactions.CompactionContext;
149149
import org.apache.hadoop.hbase.regionserver.compactions.CompactionLifeCycleTracker;
150150
import org.apache.hadoop.hbase.regionserver.compactions.ForbidMajorCompactionChecker;
151+
import org.apache.hadoop.hbase.regionserver.metrics.MetricsTableLatencies;
151152
import org.apache.hadoop.hbase.regionserver.regionreplication.RegionReplicationSink;
152153
import org.apache.hadoop.hbase.regionserver.throttle.CompactionThroughputControllerFactory;
153154
import org.apache.hadoop.hbase.regionserver.throttle.NoLimitThroughputController;
@@ -373,6 +374,13 @@ public void setRestoredRegion(boolean restoredRegion) {
373374
isRestoredRegion = restoredRegion;
374375
}
375376

377+
// Handle table latency metrics
378+
private MetricsTableLatencies metricsTableLatencies;
379+
380+
public MetricsTableLatencies getMetricsTableLatencies() {
381+
return metricsTableLatencies;
382+
}
383+
376384
// The internal wait duration to acquire a lock before read/update
377385
// from the region. It is not per row. The purpose of this wait time
378386
// is to avoid waiting a long time while the region is busy, so that
@@ -962,6 +970,9 @@ long initialize(final CancelableProgressable reporter) throws IOException {
962970
}
963971

964972
}
973+
if (metricsTableLatencies != null) {
974+
metricsTableLatencies.removeRegistry();
975+
}
965976
throw e;
966977
} finally {
967978
// nextSeqid will be -1 if the initialization fails.
@@ -1091,6 +1102,9 @@ private long initializeRegionInternals(final CancelableProgressable reporter,
10911102
status.setStatus("Running coprocessor post-open hooks");
10921103
coprocessorHost.postOpen();
10931104
}
1105+
1106+
metricsTableLatencies = new MetricsTableLatencies(htableDescriptor.getTableName(), conf);
1107+
10941108
status.markComplete("Region opened successfully");
10951109
return nextSeqId;
10961110
}
@@ -1875,6 +1889,13 @@ public Pair<byte[], Collection<HStoreFile>> call() throws IOException {
18751889
writeRegionCloseMarker(wal);
18761890
}
18771891
this.closed.set(true);
1892+
1893+
// Decrease refCount of table latency metric registry.
1894+
// Do this after closed#set to make sure only -1.
1895+
if (metricsTableLatencies != null) {
1896+
metricsTableLatencies.removeRegistry();
1897+
}
1898+
18781899
if (!canFlush) {
18791900
decrMemStoreSize(this.memStoreSizing.getMemStoreSize());
18801901
} else if (this.memStoreSizing.getDataSize() != 0) {
@@ -4690,9 +4711,13 @@ private OperationStatus[] batchMutate(BatchOperation<?> batchOp) throws IOExcept
46904711
requestFlushIfNeeded();
46914712
}
46924713
} finally {
4693-
if (rsServices != null && rsServices.getMetrics() != null) {
4694-
rsServices.getMetrics().updateWriteQueryMeter(this.htableDescriptor.getTableName(),
4695-
batchOp.size());
4714+
if (rsServices != null) {
4715+
if (metricsTableLatencies != null && metricsTableLatencies.isEnabTableQueryMeterMetrics()) {
4716+
metricsTableLatencies.updateTableWriteQueryMeter(batchOp.size());
4717+
}
4718+
if (rsServices.getMetrics() != null) {
4719+
rsServices.getMetrics().updateWriteQueryMeter(batchOp.size());
4720+
}
46964721
}
46974722
batchOp.closeRegionOperation();
46984723
}
@@ -7884,8 +7909,13 @@ void metricsUpdateForGet(List<Cell> results, long before) {
78847909
if (this.metricsRegion != null) {
78857910
this.metricsRegion.updateGet(EnvironmentEdgeManager.currentTime() - before);
78867911
}
7887-
if (this.rsServices != null && this.rsServices.getMetrics() != null) {
7888-
rsServices.getMetrics().updateReadQueryMeter(getRegionInfo().getTable(), 1);
7912+
if (rsServices != null) {
7913+
if (this.rsServices.getMetrics() != null) {
7914+
rsServices.getMetrics().updateReadQueryMeter(1);
7915+
}
7916+
if (metricsTableLatencies != null && metricsTableLatencies.isEnabTableQueryMeterMetrics()) {
7917+
metricsTableLatencies.updateTableReadQueryMeter(1);
7918+
}
78897919
}
78907920

78917921
}

0 commit comments

Comments
 (0)