Skip to content

Commit 5754449

Browse files
committed
HBASE-27681 Refactor Table Latency Metrics
1 parent 586073d commit 5754449

File tree

13 files changed

+659
-513
lines changed

13 files changed

+659
-513
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: 23 additions & 3 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.MetricsTableRequests;
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+
public MetricsTableRequests getMetricsTableRequests() {
378+
return metricsTableRequests;
379+
}
380+
381+
// Handle table latency metrics
382+
private MetricsTableRequests metricsTableRequests;
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 (metricsTableRequests != null) {
974+
metricsTableRequests.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+
metricsTableRequests = new MetricsTableRequests(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 (metricsTableRequests != null) {
1896+
metricsTableRequests.removeRegistry();
1897+
}
1898+
18781899
if (!canFlush) {
18791900
decrMemStoreSize(this.memStoreSizing.getMemStoreSize());
18801901
} else if (this.memStoreSizing.getDataSize() != 0) {
@@ -4691,8 +4712,7 @@ private OperationStatus[] batchMutate(BatchOperation<?> batchOp) throws IOExcept
46914712
}
46924713
} finally {
46934714
if (rsServices != null && rsServices.getMetrics() != null) {
4694-
rsServices.getMetrics().updateWriteQueryMeter(this.htableDescriptor.getTableName(),
4695-
batchOp.size());
4715+
rsServices.getMetrics().updateWriteQueryMeter(this, batchOp.size());
46964716
}
46974717
batchOp.closeRegionOperation();
46984718
}
@@ -7885,7 +7905,7 @@ void metricsUpdateForGet(List<Cell> results, long before) {
78857905
this.metricsRegion.updateGet(EnvironmentEdgeManager.currentTime() - before);
78867906
}
78877907
if (this.rsServices != null && this.rsServices.getMetrics() != null) {
7888-
rsServices.getMetrics().updateReadQueryMeter(getRegionInfo().getTable(), 1);
7908+
rsServices.getMetrics().updateReadQueryMeter(this, 1);
78897909
}
78907910

78917911
}

0 commit comments

Comments
 (0)