You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2018/08/15 14:03:43 UTC

lucene-solr:branch_7x: SOLR-12665: Autoscaling policy not being refreshed due to caching

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 806d087ad -> 8e75e68a8


SOLR-12665: Autoscaling policy not being refreshed due to caching


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/8e75e68a
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/8e75e68a
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/8e75e68a

Branch: refs/heads/branch_7x
Commit: 8e75e68a8aa32f69999bbb2777f0de03357cc5b2
Parents: 806d087
Author: Noble Paul <no...@apache.org>
Authored: Thu Aug 16 00:02:27 2018 +1000
Committer: Noble Paul <no...@apache.org>
Committed: Thu Aug 16 00:03:29 2018 +1000

----------------------------------------------------------------------
 solr/CHANGES.txt                                  |  2 ++
 .../solr/cloud/autoscaling/TestPolicyCloud.java   | 14 ++++++++++++++
 .../cloud/autoscaling/AutoScalingConfig.java      |  2 +-
 .../client/solrj/cloud/autoscaling/Policy.java    | 18 ++++++++++++------
 .../solrj/cloud/autoscaling/PolicyHelper.java     |  5 +++++
 5 files changed, 34 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/8e75e68a/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 491b06e..d0154ec 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -192,6 +192,8 @@ Bug Fixes
 
 * SOLR-12470: Search Rate Trigger multiple bug fixes, improvements and documentation updates. (ab)
 
+* SOLR-12665: Autoscaling policy not being refreshed due to caching (noble)
+
 Optimizations
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/8e75e68a/solr/core/src/test/org/apache/solr/cloud/autoscaling/TestPolicyCloud.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/autoscaling/TestPolicyCloud.java b/solr/core/src/test/org/apache/solr/cloud/autoscaling/TestPolicyCloud.java
index f1dbad5..88e2b70 100644
--- a/solr/core/src/test/org/apache/solr/cloud/autoscaling/TestPolicyCloud.java
+++ b/solr/core/src/test/org/apache/solr/cloud/autoscaling/TestPolicyCloud.java
@@ -84,6 +84,20 @@ public class TestPolicyCloud extends SolrCloudTestCase {
         "{}".getBytes(StandardCharsets.UTF_8), true);
   }
 
+  public void testCreateCollection() throws Exception  {
+    String commands =  "{ set-cluster-policy: [ {cores: '0', node: '#ANY'} ] }"; // disallow replica placement anywhere
+    cluster.getSolrClient().request(createAutoScalingRequest(SolrRequest.METHOD.POST, commands));
+    String collectionName = "testCreateCollection";
+    expectThrows(HttpSolrClient.RemoteSolrException.class,
+        () -> CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1).process(cluster.getSolrClient()));
+
+    CollectionAdminRequest.deleteCollection(collectionName).processAndWait(cluster.getSolrClient(), 60);
+
+    commands =  "{ set-cluster-policy: [ {cores: '<2', node: '#ANY'} ] }";
+    cluster.getSolrClient().request(createAutoScalingRequest(SolrRequest.METHOD.POST, commands));
+    CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1).process(cluster.getSolrClient());
+  }
+
   public void testDataProviderPerReplicaDetails() throws Exception {
     CollectionAdminRequest.createCollection("perReplicaDataColl", "conf", 1, 5)
         .process(cluster.getSolrClient());

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/8e75e68a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/AutoScalingConfig.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/AutoScalingConfig.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/AutoScalingConfig.java
index 01f9199..6a71875 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/AutoScalingConfig.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/AutoScalingConfig.java
@@ -350,7 +350,7 @@ public class AutoScalingConfig implements MapWriter {
   public Policy getPolicy() {
     if (policy == null) {
       if (jsonMap != null) {
-        policy = new Policy(jsonMap);
+        policy = new Policy(jsonMap, zkVersion);
       } else {
         policy = new Policy();
       }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/8e75e68a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Policy.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Policy.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Policy.java
index 8b0a956..525728e 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Policy.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/Policy.java
@@ -93,13 +93,18 @@ public class Policy implements MapWriter {
   final List<Preference> clusterPreferences;
   final List<Pair<String, Type>> params;
   final List<String> perReplicaAttributes;
+  final int zkVersion;
 
   public Policy() {
     this(Collections.emptyMap());
   }
 
-  @SuppressWarnings("unchecked")
   public Policy(Map<String, Object> jsonMap) {
+    this(jsonMap, 0);
+  }
+  @SuppressWarnings("unchecked")
+  public Policy(Map<String, Object> jsonMap, int version) {
+    this.zkVersion = version;
     int[] idx = new int[1];
     List<Preference> initialClusterPreferences = ((List<Map<String, Object>>) jsonMap.getOrDefault(CLUSTER_PREFERENCES, emptyList())).stream()
         .map(m -> new Preference(m, idx[0]++))
@@ -150,7 +155,8 @@ public class Policy implements MapWriter {
         .collect(Collectors.toList());
   }
 
-  private Policy(Map<String, List<Clause>> policies, List<Clause> clusterPolicy, List<Preference> clusterPreferences) {
+  private Policy(Map<String, List<Clause>> policies, List<Clause> clusterPolicy, List<Preference> clusterPreferences, int version) {
+    this.zkVersion = version;
     this.policies = policies != null ? Collections.unmodifiableMap(policies) : Collections.emptyMap();
     this.clusterPolicy = clusterPolicy != null ? Collections.unmodifiableList(clusterPolicy) : Collections.emptyList();
     this.clusterPreferences = clusterPreferences != null ? Collections.unmodifiableList(clusterPreferences) : DEFAULT_PREFERENCES;
@@ -177,19 +183,19 @@ public class Policy implements MapWriter {
   }
 
   public Policy withPolicies(Map<String, List<Clause>> policies) {
-    return new Policy(policies, clusterPolicy, clusterPreferences);
+    return new Policy(policies, clusterPolicy, clusterPreferences, 0);
   }
 
   public Policy withClusterPreferences(List<Preference> clusterPreferences) {
-    return new Policy(policies, clusterPolicy, clusterPreferences);
+    return new Policy(policies, clusterPolicy, clusterPreferences, 0);
   }
 
   public Policy withClusterPolicy(List<Clause> clusterPolicy) {
-    return new Policy(policies, clusterPolicy, clusterPreferences);
+    return new Policy(policies, clusterPolicy, clusterPreferences, 0);
   }
 
   public Policy withParams(List<String> params) {
-    return new Policy(policies, clusterPolicy, clusterPreferences);
+    return new Policy(policies, clusterPolicy, clusterPreferences, 0);
   }
 
   public List<Clause> getClusterPolicy() {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/8e75e68a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/PolicyHelper.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/PolicyHelper.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/PolicyHelper.java
index ab48163..8661ad9 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/PolicyHelper.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/PolicyHelper.java
@@ -316,6 +316,7 @@ public class PolicyHelper {
       TimeSource timeSource = cloudManager.getTimeSource();
       synchronized (lockObj) {
         if (sessionWrapper.status == Status.NULL ||
+            sessionWrapper.zkVersion != cloudManager.getDistribStateManager().getAutoScalingConfig().getZkVersion() ||
             TimeUnit.SECONDS.convert(timeSource.getTimeNs() - sessionWrapper.lastUpdateTime, TimeUnit.NANOSECONDS) > SESSION_EXPIRY) {
           //no session available or the session is expired
           return createSession(cloudManager);
@@ -407,6 +408,7 @@ public class PolicyHelper {
     public Status status;
     private final SessionRef ref;
     private AtomicInteger refCount = new AtomicInteger();
+    public final long zkVersion;
 
     public long getCreateTime() {
       return createTime;
@@ -423,6 +425,9 @@ public class PolicyHelper {
       this.session = session;
       this.status = Status.UNUSED;
       this.ref = ref;
+      this.zkVersion = session == null ?
+          0 :
+          session.getPolicy().zkVersion;
     }
 
     public Policy.Session get() {