Skip to content

HBASE-28123 TableRequests metrics broken after altering table#7855

Open
liuxiaocs7 wants to merge 3 commits intoapache:masterfrom
liuxiaocs7:HBASE-28123
Open

HBASE-28123 TableRequests metrics broken after altering table#7855
liuxiaocs7 wants to merge 3 commits intoapache:masterfrom
liuxiaocs7:HBASE-28123

Conversation

@liuxiaocs7
Copy link
Copy Markdown
Member

Comment on lines 65 to +76
private class MetricsSourceAdapter implements MetricsSource {
private final MetricRegistry registry;
private final MetricRegistryInfo info;

MetricsSourceAdapter(MetricRegistry registry) {
this.registry = registry;
MetricsSourceAdapter(MetricRegistryInfo info) {
this.info = info;
}

@Override
public void getMetrics(MetricsCollector collector, boolean all) {
metricsAdapter.snapshotAllMetrics(registry, collector);
Optional<MetricRegistry> registryOpt = MetricRegistries.global().get(info);
registryOpt
.ifPresent(metricRegistry -> metricsAdapter.snapshotAllMetrics(metricRegistry, collector));
Copy link
Copy Markdown
Member Author

@liuxiaocs7 liuxiaocs7 Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the fix, we should always use the newest metricRegistry here

@liuxiaocs7 liuxiaocs7 closed this Mar 6, 2026
@liuxiaocs7 liuxiaocs7 reopened this Mar 6, 2026
@liuxiaocs7
Copy link
Copy Markdown
Member Author

Hi, @Apache9, what do you think of this change for this bug, more details see HBASE-28123, Thanks!

@liuxiaocs7
Copy link
Copy Markdown
Member Author

Now the CI pass all!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds regression coverage and fixes for TableRequests metrics behavior around table lifecycle events (alter/reopen, drop), addressing HBASE-28123 where metrics could become stale/broken after an alter.

Changes:

  • Fix GlobalMetricRegistriesAdapter to snapshot metrics from the current MetricRegistry (lookup by MetricRegistryInfo) instead of holding a stale registry instance.
  • Rename/clean up MetricsTableRequests query-meter flag + API, and remove unused no-arg meter update methods (plus corresponding unused RS wrapper).
  • Add/modernize JUnit5 tests, including a new mini-cluster integration test for metrics re-register/unregister behavior and a ref-counting test.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/metrics/TestMetricsTableRequestsRegister.java New mini-cluster regression tests for metrics (re)registration after alter and unregistration after drop.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/metrics/TestMetricsTableRequests.java Move to correct package/JUnit5; add ref-counting test and minor assertion cleanups.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsUserAggregate.java Update mocks for renamed MetricsTableRequests query-meter enable method.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestMetricsRegionServer.java Update mocks for renamed MetricsTableRequests query-meter enable method.
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/MetricsTableRequests.java Rename query-meter enable flag/getter; remove unused no-arg meter methods; restrict registry getters to tests.
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServer.java Remove unused no-arg updateWriteQueryMeter wrapper.
hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/metrics/impl/GlobalMetricRegistriesAdapter.java Ensure metrics2 adapter snapshots from the latest registry instance to survive registry replacement on alter/reopen.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/metrics/TestMetricsTableRequests.java:49

  • This test class creates MetricRegistries.global() entries (e.g., for "table1"/"table2") but never clears/removes them, so state can leak across tests/classes and make assertions order-dependent/flaky. Add an @AfterEach that calls MetricRegistries.global().clear() (or explicitly remove the registries you create) and consider deriving table names from TestInfo to avoid collisions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (3)

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/metrics/TestMetricsTableRequests.java:137

  • MetricRegistries.remove returns true only when the registry is actually removed (refCount reaches 0). Consider asserting the return values here (first remove should be false, second should be true) so the test validates ref-count semantics directly, not just presence/absence.
    hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/metrics/TestMetricsTableRequests.java:128
  • This class uses MetricRegistries.global() but does not clear it between tests. Since MetricRegistries is global and ref-counted, leftover registries can leak into later tests (and other classes) and make assertions order-dependent. Consider adding an @AfterEach that calls MetricRegistries.global().clear() (consistent with TestMetricsRegionServer.java:72-76 and TestMetricsThrottleExceptions.java:53-57).
    hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/metrics/TestMetricsTableRequests.java:131
  • The intent here is to verify ref-counting returns the same MetricRegistry instance, but assertEquals would also pass if MetricRegistry ever implements value-based equality. Prefer asserting identity (assertSame) for metricRegistry1/metricRegistry2 to make the test strictly validate instance reuse.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants