Skip to content
Open
Changes from 1 commit
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
23 changes: 13 additions & 10 deletions solr/core/src/java/org/apache/solr/core/CoreContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public JerseyAppHandlerCache getJerseyAppHandlerCache() {

protected MetricsHandler metricsHandler;

private volatile SolrClientCache solrClientCache;
// SolrClientCache is now stored in objectCache with key "solrClientCache"

private volatile Map<String, SolrCache<?, ?>> caches;

Expand Down Expand Up @@ -690,12 +690,15 @@ public FileStore getFileStore() {
* @see #getDefaultHttpSolrClient()
* @see ZkController#getSolrClient()
* @see Http2SolrClient#requestWithBaseUrl(String, String, SolrRequest)
* @deprecated likely to simply be moved to the ObjectCache so as to not be used
*/
@Deprecated
public SolrClientCache getSolrClientCache() {
Copy link
Contributor

Choose a reason for hiding this comment

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

No; this misses the point. I don't like this method's existence; it's too tempting to use it when usually you shouldn't use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you elaborate more on what the problem with this method is? Is there a more general approach that we are supposed to take for getting clients? at least to me, it appears super useful... If we we have a client created, great, use it, and if not, it creates it...

Only six classes call it, so if we want to eliminate it, it doesn't seem unsurmountable. Just unclear on what we would replace it with.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the javadocs don't already answer your question, I failed to make them clear enough. Let me flip this inquiry around... hey Eric, why do you think we need a cache of clients at all? Why cache them? What's wrong with our existing clients (linked to in javadocs)?

note: distributed file store usage could easily switch to coreContainer.getDefaultHttpSolrClient().requestWithBaseUrl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, after re-reading and more context.. ( I sound like a LLM!) I think what you are saying is that we could replace most calls with one of:

   * @see #getDefaultHttpSolrClient()
   * @see ZkController#getSolrClient()
   * @see Http2SolrClient#requestWithBaseUrl(String, String, SolrRequest)

and that would work? I'll take a looksee at that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm also fine with the PR, TBH... enough callers of it want a SolrClientCache that it'd be annoying to outright remove it. And it's not a big deal if a plugin or something uses it when they could have used an alternative.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so coreContainer.getDefaultHttpSolrClient().requestWithBaseUrl already is used in some places in DistribFileStore. However we do:

final var fileResponse = solrClient.requestWithBaseUrl(baseUrl, null, fileRequest);
        try (final var stream = fileResponse.getResponseStreamIfSuccessful()) {

can't quite figure that getResponseStreamIfSucessful to work yet

// TODO put in the objectCache instead
return solrClientCache;
return objectCache.computeIfAbsent(
"solrClientCache",
SolrClientCache.class,
k -> {
// Create a new SolrClientCache with the appropriate solrClientProvider
return new SolrClientCache(solrClientProvider.getSolrClient());
});
}

public ObjectCache getObjectCache() {
Expand Down Expand Up @@ -777,7 +780,8 @@ private void loadInternal() {
solrClientProvider =
new HttpSolrClientProvider(cfg.getUpdateShardHandlerConfig(), solrMetricsContext);
updateShardHandler.initializeMetrics(solrMetricsContext, "updateShardHandler");
solrClientCache = new SolrClientCache(solrClientProvider.getSolrClient());
// We don't pre-initialize SolrClientCache here anymore
// It will be created on-demand in getSolrClientCache() when first needed

Map<String, CacheConfig> cachesConfig = cfg.getCachesConfig();
if (cachesConfig.isEmpty()) {
Expand All @@ -799,7 +803,7 @@ private void loadInternal() {

zkSys.initZooKeeper(this, cfg.getCloudConfig());
if (isZooKeeperAware()) {
solrClientCache.setDefaultZKHost(getZkController().getZkServerAddress());
getSolrClientCache().setDefaultZKHost(getZkController().getZkServerAddress());
// initialize ZkClient metrics
zkSys.getZkMetricsProducer().initializeMetrics(solrMetricsContext, "zkClient");
pkiAuthenticationSecurityBuilder =
Expand Down Expand Up @@ -1306,9 +1310,8 @@ public void shutdown() {
} catch (Exception e) {
log.warn("Error shutting down CoreAdminHandler. Continuing to close CoreContainer.", e);
}
if (solrClientCache != null) {
solrClientCache.close();
}
// SolrClientCache is stored in objectCache with key "solrClientCache"
// and will be closed when objectCache is closed
if (containerPluginsRegistry != null) {
IOUtils.closeQuietly(containerPluginsRegistry);
}
Expand Down