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 2021/02/12 07:05:24 UTC

[lucene-solr] branch jira/solr15138_8x updated: cleanup

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

noble pushed a commit to branch jira/solr15138_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/jira/solr15138_8x by this push:
     new 0ebba4c  cleanup
0ebba4c is described below

commit 0ebba4c42fe1ade43953b7520f5cd134c02382de
Author: Noble Paul <no...@gmail.com>
AuthorDate: Fri Feb 12 18:04:51 2021 +1100

    cleanup
---
 solr/core/src/java/org/apache/solr/cloud/Overseer.java |  9 ++-------
 .../apache/solr/cloud/RefreshCollectionMessage.java    | 16 +++++-----------
 .../org/apache/solr/common/cloud/PerReplicaStates.java | 11 +++++------
 .../apache/solr/common/cloud/PerReplicaStatesOps.java  | 18 +++++++++---------
 4 files changed, 21 insertions(+), 33 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/cloud/Overseer.java b/solr/core/src/java/org/apache/solr/cloud/Overseer.java
index a10e8a6..4ca5703 100644
--- a/solr/core/src/java/org/apache/solr/cloud/Overseer.java
+++ b/solr/core/src/java/org/apache/solr/cloud/Overseer.java
@@ -265,9 +265,7 @@ public class Overseer implements SolrCloseable {
                 while (unprocessedMessages.size() > 0) {
                   clusterState = zkStateWriter.writePendingUpdates();
                   Message m = unprocessedMessages.remove(0);
-                  if (m instanceof RefreshCollectionMessage) {
-                    clusterState = ((RefreshCollectionMessage) m).run(clusterState, Overseer.this);
-                  }
+                  clusterState = m.run(clusterState, Overseer.this);
                 }
                 // The callback always be called on this thread
                 clusterState = processQueueItem(message, clusterState, zkStateWriter, true, () -> {
@@ -1036,11 +1034,8 @@ public class Overseer implements SolrCloseable {
   }
 
   public interface Message {
-    Operation getOperation();
+    ClusterState run(ClusterState clusterState, Overseer overseer) throws Exception;
 
-    enum Operation {
-      REFRESH_COLL;
-    }
   }
 
 }
diff --git a/solr/core/src/java/org/apache/solr/cloud/RefreshCollectionMessage.java b/solr/core/src/java/org/apache/solr/cloud/RefreshCollectionMessage.java
index 5375322..d7d8e7b 100644
--- a/solr/core/src/java/org/apache/solr/cloud/RefreshCollectionMessage.java
+++ b/solr/core/src/java/org/apache/solr/cloud/RefreshCollectionMessage.java
@@ -24,35 +24,29 @@ import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.data.Stat;
 
 /**
- * Refresh the ClusterState for a given collection
+ * Refresh the Cluster State for a given collection
+ *
  */
 public class RefreshCollectionMessage implements Overseer.Message {
-  public final Operation operation;
   public final String collection;
 
   public RefreshCollectionMessage(String collection) {
-    this.operation = Operation.REFRESH_COLL;
     this.collection = collection;
   }
 
-  ClusterState run(ClusterState clusterState, Overseer overseer) throws InterruptedException, KeeperException {
+  public ClusterState run(ClusterState clusterState, Overseer overseer) throws Exception {
     Stat stat = overseer.getZkStateReader().getZkClient().exists(ZkStateReader.getCollectionPath(collection), null, true);
     if (stat == null) {
-      // collection does not exist
+      //collection does not exist
       return clusterState.copyWith(collection, null);
     }
     DocCollection coll = clusterState.getCollectionOrNull(collection);
     if (coll != null && !coll.isModified(stat.getVersion(), stat.getCversion())) {
-      // our state is up to date
+      //our state is up to date
       return clusterState;
     } else {
       coll = ZkStateReader.getCollectionLive(overseer.getZkStateReader(), collection);
       return clusterState.copyWith(collection, coll);
     }
   }
-
-  @Override
-  public Operation getOperation() {
-    return operation;
-  }
 }
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/PerReplicaStates.java b/solr/solrj/src/java/org/apache/solr/common/cloud/PerReplicaStates.java
index 4fdfc32..975f654 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/PerReplicaStates.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/PerReplicaStates.java
@@ -68,7 +68,7 @@ public class PerReplicaStates implements ReflectMapWriter {
   @JsonProperty
   public final SimpleMap<State> states;
 
-  private volatile AtomicBoolean allActive;
+  private Boolean allActive;
 
   /**
    * Construct with data read from ZK
@@ -98,13 +98,12 @@ public class PerReplicaStates implements ReflectMapWriter {
   /** Check and return if all replicas are ACTIVE
    */
   public boolean allActive() {
-    if (this.allActive != null) return allActive.get();
-    boolean[] result = new boolean[]{true};
+    if (this.allActive != null) return allActive;
+    AtomicBoolean result = new AtomicBoolean(true);
     states.forEachEntry((r, s) -> {
-      if (s.state != Replica.State.ACTIVE) result[0] = false;
+      if (s.state != Replica.State.ACTIVE) result.set(false);
     });
-    this.allActive.set(result[0]);
-    return this.allActive.get();
+    return this.allActive = result.get();
   }
 
   /**Get the changed replicas
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/PerReplicaStatesOps.java b/solr/solrj/src/java/org/apache/solr/common/cloud/PerReplicaStatesOps.java
index 69c6a6a..40079cb 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/PerReplicaStatesOps.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/PerReplicaStatesOps.java
@@ -116,7 +116,7 @@ public class PerReplicaStatesOps {
   public static PerReplicaStatesOps flipState(String replica, Replica.State newState, PerReplicaStates rs) {
     return new PerReplicaStatesOps(prs -> {
       List<PerReplicaStates.Operation> operations = new ArrayList<>(2);
-      PerReplicaStates.State existing = rs.get(replica);
+      PerReplicaStates.State existing = prs.get(replica);
       if (existing == null) {
         operations.add(new PerReplicaStates.Operation(PerReplicaStates.Operation.Type.ADD, new PerReplicaStates.State(replica, newState, Boolean.FALSE, 0)));
       } else {
@@ -124,7 +124,7 @@ public class PerReplicaStatesOps {
         addDeleteStaleNodes(operations, existing);
       }
       if (log.isDebugEnabled()) {
-        log.debug("flipState on {}, {} -> {}, ops :{}", rs.path, replica, newState, operations);
+        log.debug("flipState on {}, {} -> {}, ops :{}", prs.path, replica, newState, operations);
       }
       return operations;
     }).init(rs);
@@ -160,7 +160,7 @@ public class PerReplicaStatesOps {
     return new PerReplicaStatesOps(prs -> {
       List<PerReplicaStates.Operation> ops = new ArrayList<>();
       if (next != null) {
-        PerReplicaStates.State st = rs.get(next);
+        PerReplicaStates.State st = prs.get(next);
         if (st != null) {
           if (!st.isLeader) {
             ops.add(new PerReplicaStates.Operation(PerReplicaStates.Operation.Type.ADD, new PerReplicaStates.State(st.replica, Replica.State.ACTIVE, Boolean.TRUE, st.version + 1)));
@@ -176,7 +176,7 @@ public class PerReplicaStatesOps {
 
       //now go through all other replicas and unset previous leader
       for (String r : allReplicas) {
-        PerReplicaStates.State st = rs.get(r);
+        PerReplicaStates.State st = prs.get(r);
         if (st == null) continue;//unlikely
         if (!Objects.equals(r, next)) {
           if (st.isLeader) {
@@ -187,7 +187,7 @@ public class PerReplicaStatesOps {
         }
       }
       if (log.isDebugEnabled()) {
-        log.debug("flipLeader on:{}, {} -> {}, ops: {}", rs.path, allReplicas, next, ops);
+        log.debug("flipLeader on:{}, {} -> {}, ops: {}", prs.path, allReplicas, next, ops);
       }
       return ops;
     }).init(rs);
@@ -201,10 +201,10 @@ public class PerReplicaStatesOps {
   public static PerReplicaStatesOps deleteReplica(String replica, PerReplicaStates rs) {
     return new PerReplicaStatesOps(prs -> {
       List<PerReplicaStates.Operation> result;
-      if (rs == null) {
+      if (prs == null) {
         result = Collections.emptyList();
       } else {
-        PerReplicaStates.State state = rs.get(replica);
+        PerReplicaStates.State state = prs.get(replica);
         result = addDeleteStaleNodes(new ArrayList<>(), state);
       }
       return result;
@@ -223,7 +223,7 @@ public class PerReplicaStatesOps {
     return new PerReplicaStatesOps(prs -> {
       List<PerReplicaStates.Operation> operations = new ArrayList<>();
       for (String replica : replicas) {
-        PerReplicaStates.State r = rs.get(replica);
+        PerReplicaStates.State r = prs.get(replica);
         if (r != null) {
           if (r.state == Replica.State.DOWN && !r.isLeader) continue;
           operations.add(new PerReplicaStates.Operation(PerReplicaStates.Operation.Type.ADD, new PerReplicaStates.State(replica, Replica.State.DOWN, Boolean.FALSE, r.version + 1)));
@@ -233,7 +233,7 @@ public class PerReplicaStatesOps {
         }
       }
       if (log.isDebugEnabled()) {
-        log.debug("for coll: {} down replicas {}, ops {}", rs, replicas, operations);
+        log.debug("for coll: {} down replicas {}, ops {}", prs, replicas, operations);
       }
       return operations;
     }).init(rs);