You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ep...@apache.org on 2023/01/02 14:22:59 UTC

[solr] branch branch_9x updated: SOLR-10464: setCollectionCacheTTL should be deprecated in favor of Solr Client Builder methods (#1247)

This is an automated email from the ASF dual-hosted git repository.

epugh pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 440905d0075 SOLR-10464: setCollectionCacheTTL should be deprecated in favor of Solr Client Builder methods (#1247)
440905d0075 is described below

commit 440905d00758295bb0372e2329c9111b655e5444
Author: Eric Pugh <ep...@opensourceconnections.com>
AuthorDate: Mon Jan 2 09:22:24 2023 -0500

    SOLR-10464: setCollectionCacheTTL should be deprecated in favor of Solr Client Builder methods (#1247)
    
    migrated parameter to builder, changing it to withCollectionCacheTtl from setCollectionCacheTtl
---
 solr/CHANGES.txt                                           |  3 +++
 .../solr/client/solrj/impl/CloudHttp2SolrClient.java       | 14 ++++++++++++++
 .../solr/client/solrj/impl/CloudLegacySolrClient.java      | 12 ++++++++++++
 .../org/apache/solr/client/solrj/impl/CloudSolrClient.java | 10 ++++++----
 .../apache/solr/client/solrj/impl/SolrClientBuilder.java   |  1 +
 .../solr/client/solrj/impl/CloudHttp2SolrClientTest.java   |  7 ++++---
 .../apache/solr/client/solrj/impl/CloudSolrClientTest.java |  7 ++++---
 7 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index c9a456cb744..d9f827639b5 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -74,6 +74,9 @@ Improvements
 
 * SOLR-10462: Introduce Builder setter for pollQueueTime on ConcurrentUpdateHttp2SolrClient.  Deprecated 
   direct 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 urlParamNames
   to clarify they are parameter names, not the values. Deprecated direct setter setQueryParams and addQueryParams 
diff --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.java
index 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.java
index 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.java
index 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;
 
     @Override
     public 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
    */
+  @Deprecated
   public 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.java
index 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.java
index 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.java
index 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 check
     final 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...