Apache Solr open-source search software
SOLR-10464: setCollectionCacheTTL should be deprecated in favor of Solr Client Builder methods (#1247)
Eric Pughf0c6549efd77
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 5e3589aee38..ff425e966d1 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -98,6 +98,9 @@ Improvements* SOLR-10462: Introduce Builder setter for pollQueueTime on ConcurrentUpdateHttp2SolrClient. Deprecateddirect setter setPollQueueTime on ConcurrentUpdateHttp2SolrClient. (Eric Pugh)++* SOLR-10464: Introduce Builder setter for collectionCacheTtl on cloud SolrClients. Deprecated+ direct setter setCollectionCacheTTL on cloud SolrClients. (Eric Pugh, David Smiley)* SOLR-10452: Introduce Builder setter withTheseParamNamesInTheUrl for queryParams, renaming them to urlParamNamesto clarify they are parameter names, not the values. Deprecated direct setter setQueryParams and addQueryParamsdiff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.javaindex 04eb2f7f0d6..fa602215d26 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudHttp2SolrClient.java@@ -98,6 +98,8 @@ public class CloudHttp2SolrClient extends CloudSolrClient {this.stateProvider = builder.stateProvider;}+ this.collectionStateCache.timeToLiveMs = builder.timeToLiveSeconds * 1000L;+// If caches are expired then they are refreshed after acquiring a lock. Set the number of// locks.this.locks = objectList(builder.parallelCacheRefreshesLocks);@@ -151,6 +153,7 @@ public class CloudHttp2SolrClient extends CloudSolrClient {private ResponseParser responseParser;private long retryExpiryTime =TimeUnit.NANOSECONDS.convert(3, TimeUnit.SECONDS); // 3 seconds or 3 million nanos+ private int timeToLiveSeconds = 60;private int parallelCacheRefreshesLocks = 3;/**@@ -273,6 +276,17 @@ public class CloudHttp2SolrClient extends CloudSolrClient {return this;}+ /**+ * Sets the cache ttl for DocCollection Objects cached.+ *+ * @param timeToLiveSeconds ttl value in seconds+ */+ public Builder withCollectionCacheTtl(int timeToLiveSeconds) {+ assert timeToLiveSeconds > 0;+ this.timeToLiveSeconds = timeToLiveSeconds;+ return this;+ }+public Builder withHttpClient(Http2SolrClient httpClient) {if (this.internalClientBuilder != null) {throw new IllegalStateException(diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudLegacySolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudLegacySolrClient.javaindex 1bdd0636e77..983d959434c 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudLegacySolrClient.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudLegacySolrClient.java@@ -87,6 +87,7 @@ public class CloudLegacySolrClient extends CloudSolrClient {this.stateProvider = builder.stateProvider;}this.retryExpiryTime = builder.retryExpiryTime;+ this.collectionStateCache.timeToLiveMs = builder.timeToLiveSeconds * 1000L;this.clientIsInternal = builder.httpClient == null;this.shutdownLBHttpSolrServer = builder.loadBalancedSolrClient == null;if (builder.lbClientBuilder != null) {@@ -270,6 +271,17 @@ public class CloudLegacySolrClient extends CloudSolrClient {return this;}+ /**+ * Sets the cache ttl for DocCollection Objects cached.+ *+ * @param seconds ttl value in seconds+ */+ public Builder withCollectionCacheTtl(int seconds) {+ assert seconds > 0;+ this.timeToLiveSeconds = seconds;+ return this;+ }+/*** Tells {@link Builder} that created clients should send updates only to shard leaders.*diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.javaindex ccc328ff23b..9c1c1db83ed 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java@@ -188,7 +188,7 @@ public abstract class CloudSolrClient extends SolrClient {final AtomicLong puts = new AtomicLong();final AtomicLong hits = new AtomicLong();final Lock evictLock = new ReentrantLock(true);- protected volatile long timeToLive = 60 * 1000L;+ protected volatile long timeToLiveMs = 60 * 1000L;@Overridepublic ExpiringCachedDocCollection get(Object key) {@@ -199,7 +199,7 @@ public abstract class CloudSolrClient extends SolrClient {evictStale();return null;}- if (val.isExpired(timeToLive)) {+ if (val.isExpired(timeToLiveMs)) {super.remove(key);return null;}@@ -217,7 +217,7 @@ public abstract class CloudSolrClient extends SolrClient {if (!evictLock.tryLock()) return;try {for (Entry<String, ExpiringCachedDocCollection> e : entrySet()) {- if (e.getValue().isExpired(timeToLive)) {+ if (e.getValue().isExpired(timeToLiveMs)) {super.remove(e.getKey());}}@@ -286,10 +286,12 @@ public abstract class CloudSolrClient extends SolrClient {* Sets the cache ttl for DocCollection Objects cached.** @param seconds ttl value in seconds+ * @deprecated use {@link CloudSolrClient.Builder#withCollectionCacheTtl(int)} instead*/+ @Deprecatedpublic void setCollectionCacheTTl(int seconds) {assert seconds > 0;- this.collectionStateCache.timeToLive = seconds * 1000L;+ this.collectionStateCache.timeToLiveMs = seconds * 1000L;}protected abstract LBSolrClient getLbClient();diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.javaindex a54776c4e78..1fed0ca3bcd 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientBuilder.java@@ -28,6 +28,7 @@ import org.apache.solr.client.solrj.request.RequestWriter;@Deprecated(since = "9.0")public abstract class SolrClientBuilder<B extends SolrClientBuilder<B>> {+ protected int timeToLiveSeconds = 60;protected HttpClient httpClient;protected ResponseParser responseParser;protected RequestWriter requestWriter;diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.javaindex 5aac562544f..f994a216c6b 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java@@ -963,11 +963,12 @@ public class CloudHttp2SolrClientTest extends SolrCloudTestCase {try (CloudSolrClient stale_client =new RandomizingCloudSolrClientBuilder(Collections.singletonList(cluster.getZkServer().getZkAddress()), Optional.empty())- .sendDirectUpdatesToAnyShardReplica().withParallelUpdates(true)+ .sendDirectUpdatesToAnyShardReplica()+ // don't let collection cache entries get expired, even on a slow machine...+ .withCollectionCacheTtl(Integer.MAX_VALUE).build()) {- // don't let collection cache entries get expired, even on a slow machine...- stale_client.setCollectionCacheTTl(Integer.MAX_VALUE);+stale_client.setDefaultCollection(COL);// do a query to populate stale_client's cache...diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.javaindex f1e693b994a..61d2a60aaec 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java@@ -968,15 +968,16 @@ public class CloudSolrClientTest extends SolrCloudTestCase {assertEquals(1, slice.getReplicas().size()); // sanity checkfinal String old_leader_core_node_name = slice.getLeader().getName();- // NOTE: creating our own CloudSolrClient whose settings we can muck with...+ // NOTE: creating our own CloudSolrClient with settings for this specific test...try (CloudSolrClient stale_client =new RandomizingCloudSolrClientBuilder(Collections.singletonList(cluster.getZkServer().getZkAddress()), Optional.empty()).sendDirectUpdatesToAnyShardReplica().withParallelUpdates(true)+ // don't let collection cache entries get expired, even on a slow machine...+ .withCollectionCacheTtl(Integer.MAX_VALUE).build()) {- // don't let collection cache entries get expired, even on a slow machine...- stale_client.setCollectionCacheTTl(Integer.MAX_VALUE);+stale_client.setDefaultCollection(COL);// do a query to populate stale_client's cache...