Skip to content

HBASE-27681 Refactor Table Latency Metrics #5072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ private void doRun() {
for (MetricRegistry registry : registries) {
MetricRegistryInfo info = registry.getMetricRegistryInfo();

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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.metrics.impl;

import static org.junit.Assert.assertTrue;

import java.util.Optional;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.metrics.MetricRegistries;
import org.apache.hadoop.hbase.metrics.MetricRegistry;
import org.apache.hadoop.hbase.metrics.MetricRegistryInfo;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;

/**
* Test class for {@link MetricRegistries}.
*/
@Category(SmallTests.class)
public class TestMetricRegistriesImpl {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestMetricRegistriesImpl.class);

@Test
public void testMetricsRegistriesRemoveRef() {
MetricRegistryInfo registryInfo =
new MetricRegistryInfo("testMetrics", null, null, null, false);
MetricRegistries.global().create(registryInfo);
Optional<MetricRegistry> registry1 = MetricRegistries.global().get(registryInfo);
assertTrue(registry1.isPresent());

MetricRegistries.global().create(registryInfo);
Optional<MetricRegistry> registry2 = MetricRegistries.global().get(registryInfo);
assertTrue(registry2.isPresent());

MetricRegistries.global().remove(registryInfo);
Optional<MetricRegistry> registry3 = MetricRegistries.global().get(registryInfo);
assertTrue(registry3.isPresent());

MetricRegistries.global().remove(registryInfo);
Optional<MetricRegistry> registry4 = MetricRegistries.global().get(registryInfo);
assertTrue(!registry4.isPresent());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
import org.apache.hadoop.hbase.regionserver.compactions.CompactionContext;
import org.apache.hadoop.hbase.regionserver.compactions.CompactionLifeCycleTracker;
import org.apache.hadoop.hbase.regionserver.compactions.ForbidMajorCompactionChecker;
import org.apache.hadoop.hbase.regionserver.metrics.MetricsTableRequests;
import org.apache.hadoop.hbase.regionserver.regionreplication.RegionReplicationSink;
import org.apache.hadoop.hbase.regionserver.throttle.CompactionThroughputControllerFactory;
import org.apache.hadoop.hbase.regionserver.throttle.NoLimitThroughputController;
Expand Down Expand Up @@ -373,6 +374,13 @@ public void setRestoredRegion(boolean restoredRegion) {
isRestoredRegion = restoredRegion;
}

public MetricsTableRequests getMetricsTableRequests() {
return metricsTableRequests;
}

// Handle table latency metrics
private MetricsTableRequests metricsTableRequests;

// The internal wait duration to acquire a lock before read/update
// from the region. It is not per row. The purpose of this wait time
// is to avoid waiting a long time while the region is busy, so that
Expand Down Expand Up @@ -962,6 +970,9 @@ long initialize(final CancelableProgressable reporter) throws IOException {
}

}
if (metricsTableRequests != null) {
metricsTableRequests.removeRegistry();
}
throw e;
} finally {
// nextSeqid will be -1 if the initialization fails.
Expand Down Expand Up @@ -1091,6 +1102,9 @@ private long initializeRegionInternals(final CancelableProgressable reporter,
status.setStatus("Running coprocessor post-open hooks");
coprocessorHost.postOpen();
}

metricsTableRequests = new MetricsTableRequests(htableDescriptor.getTableName(), conf);

status.markComplete("Region opened successfully");
return nextSeqId;
}
Expand Down Expand Up @@ -1875,6 +1889,13 @@ public Pair<byte[], Collection<HStoreFile>> call() throws IOException {
writeRegionCloseMarker(wal);
}
this.closed.set(true);

// Decrease refCount of table latency metric registry.
// Do this after closed#set to make sure only -1.
if (metricsTableRequests != null) {
metricsTableRequests.removeRegistry();
}

if (!canFlush) {
decrMemStoreSize(this.memStoreSizing.getMemStoreSize());
} else if (this.memStoreSizing.getDataSize() != 0) {
Expand Down Expand Up @@ -4691,8 +4712,7 @@ private OperationStatus[] batchMutate(BatchOperation<?> batchOp) throws IOExcept
}
} finally {
if (rsServices != null && rsServices.getMetrics() != null) {
rsServices.getMetrics().updateWriteQueryMeter(this.htableDescriptor.getTableName(),
batchOp.size());
rsServices.getMetrics().updateWriteQueryMeter(this, batchOp.size());
}
batchOp.closeRegionOperation();
}
Expand Down Expand Up @@ -7885,7 +7905,7 @@ void metricsUpdateForGet(List<Cell> results, long before) {
this.metricsRegion.updateGet(EnvironmentEdgeManager.currentTime() - before);
}
if (this.rsServices != null && this.rsServices.getMetrics() != null) {
rsServices.getMetrics().updateReadQueryMeter(getRegionInfo().getTable(), 1);
rsServices.getMetrics().updateReadQueryMeter(this, 1);
}

}
Expand Down
Loading