-
Notifications
You must be signed in to change notification settings - Fork 821
SOLR-17857: Ensure SolrMetricsContext is closed #4226
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
dsmiley
merged 15 commits into
apache:main
from
dsmiley:SOLR-17857-trackSolrMetricsContext
Mar 28, 2026
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
031e9b7
SOLR-17875: Ensure SolrMetricsContext is closed
dsmiley 4e53226
Make sure we aren't closing metrics more than once
HoustonPutman 1b761e6
Add assertion in RequestHandlerBase to enforce that initializeMetrics()
dsmiley 4a32ff2
Remove SolrFieldCache from core metrics
dsmiley e852bab
changelog
dsmiley ad47ac0
No need to collect Closeables here.
dsmiley b298f82
Hack/work-around for MissingSegmentRecoveryTest
dsmiley 60dcb39
SolrFieldCacheBean: fix recursive close
dsmiley 48e0bbb
remove needless ArrayList
dsmiley f2859ed
FQN
dsmiley 3ed94d7
Merge remote-tracking branch 'apache/main' into SOLR-17857-trackSolrM…
dsmiley b6ea107
tidy
dsmiley f0609b0
fix FQN
dsmiley 4f608a0
HighlightComponent: Fix unclosed context due to improper default/alia…
dsmiley e370ca4
CoreContainer.shutdown:
dsmiley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| title: SolrMetricsContext is now reliably closed (once), and thus some components possessing one are too. Fixes double-close of OTEL, yielding warnings. | ||
| type: fixed | ||
| authors: | ||
| - name: David Smiley | ||
| - name: Houston Putman | ||
| links: | ||
| - name: SOLR-17857 | ||
| url: https://issues.apache.org/jira/browse/SOLR-17857 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -764,6 +764,10 @@ private void loadInternal() { | |
| } | ||
| logging = LogWatcher.newRegisteredLogWatcher(cfg.getLogWatcherConfig(), loader); | ||
|
|
||
| solrMetricsContext = new SolrMetricsContext(metricManager, NODE_REGISTRY); | ||
|
|
||
| initGpuMetricsService(); // Initialize GPU metrics service | ||
|
|
||
| ClusterPluginsSource pluginsSource = | ||
| ClusterPluginsSource.loadClusterPluginsSource(this, loader); | ||
| containerPluginsRegistry = | ||
|
|
@@ -780,10 +784,12 @@ private void loadInternal() { | |
| containerPluginsRegistry.registerListener( | ||
| clusterEventProducerFactory.getPluginRegistryListener()); | ||
|
|
||
| solrMetricsContext = new SolrMetricsContext(metricManager, NODE_REGISTRY); | ||
|
|
||
| // Initialize GPU metrics service | ||
| initGpuMetricsService(); | ||
| // PublicKeyHandler was added to containerHandlers in the constructor before metrics were ready | ||
| containerHandlers | ||
| .get(PublicKeyHandler.PATH) | ||
| .initializeMetrics( | ||
| solrMetricsContext, | ||
| Attributes.builder().put(HANDLER_ATTR, PublicKeyHandler.PATH).build()); | ||
|
|
||
| shardHandlerFactory = | ||
| ShardHandlerFactory.newInstance(cfg.getShardHandlerFactoryPluginInfo(), loader); | ||
|
|
@@ -1248,6 +1254,10 @@ public void shutdown() { | |
| zkSys.zkController.tryCancelAllElections(); | ||
| } | ||
|
|
||
| // Shut down the coreZkRegister executor early so that any in-progress async reloads | ||
| // (triggered by ZK config watchers) complete before we close cores. | ||
| ExecutorUtil.shutdownAndAwaitTermination(zkSys.getCoreZkRegisterExecutorService()); | ||
|
|
||
| ExecutorUtil.shutdownAndAwaitTermination(coreLoadExecutor); // actually already shutdown | ||
|
|
||
| // Now clear all the cores that are being operated upon. | ||
|
|
@@ -1279,14 +1289,6 @@ public void shutdown() { | |
|
|
||
| customThreadPool.execute(replayUpdatesExecutor::shutdownAndAwaitTermination); | ||
|
|
||
| // Shutdown GPU metrics service if it was initialized | ||
| shutdownGpuMetricsService(); | ||
|
|
||
| if (metricManager != null) { | ||
| // Close all OTEL meter providers and metrics | ||
| metricManager.closeAllRegistries(); | ||
| } | ||
|
|
||
| if (isZooKeeperAware()) { | ||
| cancelCoreRecoveries(); | ||
| } | ||
|
|
@@ -1339,6 +1341,14 @@ public void shutdown() { | |
| } | ||
|
|
||
| // It should be safe to close the authentication plugin at this point. | ||
| try { | ||
| if (pkiAuthenticationSecurityBuilder != null) { | ||
| pkiAuthenticationSecurityBuilder.close(); | ||
| } | ||
| } catch (Exception e) { | ||
| log.warn("Exception while closing PKI authentication plugin.", e); | ||
| } | ||
|
|
||
| try { | ||
| if (authenticationPlugin != null) { | ||
| authenticationPlugin.plugin.close(); | ||
|
|
@@ -1362,6 +1372,14 @@ public void shutdown() { | |
| org.apache.lucene.util.IOUtils.closeWhileHandlingException(packageLoader); | ||
| } | ||
| org.apache.lucene.util.IOUtils.closeWhileHandlingException(loader); // best effort | ||
|
|
||
| containerHandlers.close(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line is new |
||
|
|
||
| shutdownGpuMetricsService(); // Shutdown GPU metrics service if it was initialized | ||
|
|
||
| IOUtils.closeQuietly(solrMetricsContext); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line is new |
||
|
|
||
| metricManager.closeAllRegistries(); // Close all OTEL meter providers and metrics | ||
| } | ||
|
|
||
| public void cancelCoreRecoveries() { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shutdown/close should do its work in reverse order of construction. Since metrics is initialized super early, I moved the compensating shutdown logic to the end.