You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2020/07/17 12:06:52 UTC

[lucene-solr] branch jira/solr-14613 updated: SOLR-14613: Use our own ReplicaType and ReplicaState.

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

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


The following commit(s) were added to refs/heads/jira/solr-14613 by this push:
     new ee34b98  SOLR-14613: Use our own ReplicaType and ReplicaState.
ee34b98 is described below

commit ee34b9894227643692192c959cf46b3c4edea63a
Author: Andrzej Bialecki <ab...@apache.org>
AuthorDate: Fri Jul 17 14:06:24 2020 +0200

    SOLR-14613: Use our own ReplicaType and ReplicaState.
---
 .../api/collections/assign/AssignerNodeState.java  |  3 +-
 .../api/collections/assign/AssignerReplica.java    | 10 ++--
 .../cloud/api/collections/assign/ReplicaState.java | 62 ++++++++++++++++++++++
 .../cloud/api/collections/assign/ReplicaType.java  | 47 ++++++++++++++++
 .../policy8x/AssignerClusterStateProvider.java     |  4 +-
 .../assign/policy8x/AssignerNodeStateProvider.java |  4 +-
 .../SolrCloudManagerAssignerClusterState.java      | 25 ++++++---
 7 files changed, 137 insertions(+), 18 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/AssignerNodeState.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/AssignerNodeState.java
index e6bffe1..6f43a6b 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/AssignerNodeState.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/AssignerNodeState.java
@@ -18,7 +18,6 @@ package org.apache.solr.cloud.api.collections.assign;
 
 import java.util.Collection;
 import java.util.Map;
-import java.util.Set;
 
 /**
  *
@@ -30,5 +29,7 @@ public interface AssignerNodeState {
 
   long getFreeDiskGB();
 
+  int getNumCores();
+
   Map<String, Object> getProperties();
 }
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/AssignerReplica.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/AssignerReplica.java
index 03f750c..420d31e 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/AssignerReplica.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/AssignerReplica.java
@@ -28,13 +28,13 @@ public class AssignerReplica {
   private final String collection;
   private final String shard;
   private final String core;
-  private final String type;
-  private final String state;
+  private final ReplicaType type;
+  private final ReplicaState state;
   private final Map<String, Object> properties = new HashMap<>();
 
   public AssignerReplica(String name, String node,
                          String collection, String shard, String core,
-                         String type, String state,
+                         ReplicaType type, ReplicaState state,
                          Map<String, Object> properties) {
     this.name = name;
     this.node = node;
@@ -70,11 +70,11 @@ public class AssignerReplica {
     return core;
   }
 
-  public String getType() {
+  public ReplicaType getType() {
     return type;
   }
 
-  public String getState() {
+  public ReplicaState getState() {
     return state;
   }
 
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/ReplicaState.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/ReplicaState.java
new file mode 100644
index 0000000..1abcdaf
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/ReplicaState.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cloud.api.collections.assign;
+
+import java.util.Locale;
+
+/**
+ *
+ */
+public enum ReplicaState {
+
+  /**
+   * The replica is ready to receive updates and queries.
+   */
+  ACTIVE,
+
+  /**
+   * The first state before {@link ReplicaState#RECOVERING}. A node in this state
+   * should be actively trying to move to {@link ReplicaState#RECOVERING}.
+   */
+  DOWN,
+
+  /**
+   * The node is recovering from the leader. This might involve peer-sync,
+   * full replication or finding out things are already in sync.
+   */
+  RECOVERING,
+
+  /**
+   * Recovery attempts have not worked, something is not right.
+   * <p>
+   * <b>NOTE</b>: This state doesn't matter if the node is not part of
+   * {@code /live_nodes} in ZK; in that case the node is not part of the
+   * cluster and it's state should be discarded.
+   * </p>
+   */
+  RECOVERY_FAILED;
+
+  @Override
+  public String toString() {
+    return super.toString().toLowerCase(Locale.ROOT);
+  }
+
+  /** Converts the state string to a State instance. */
+  public static ReplicaState get(String stateStr) {
+    return stateStr == null ? null : ReplicaState.valueOf(stateStr.toUpperCase(Locale.ROOT));
+  }
+}
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/ReplicaType.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/ReplicaType.java
new file mode 100644
index 0000000..1c260af
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/ReplicaType.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cloud.api.collections.assign;
+
+import java.util.Locale;
+
+/**
+ *
+ */
+public enum ReplicaType {
+  /**
+   * Writes updates to transaction log and indexes locally. Replicas of type {@link ReplicaType#NRT} support NRT (soft commits) and RTG.
+   * Any {@link ReplicaType#NRT} replica can become a leader. A shard leader will forward updates to all active {@link ReplicaType#NRT} and
+   * {@link ReplicaType#TLOG} replicas.
+   */
+  NRT,
+  /**
+   * Writes to transaction log, but not to index, uses replication. Any {@link ReplicaType#TLOG} replica can become leader (by first
+   * applying all local transaction log elements). If a replica is of type {@link ReplicaType#TLOG} but is also the leader, it will behave
+   * as a {@link ReplicaType#NRT}. A shard leader will forward updates to all active {@link ReplicaType#NRT} and {@link ReplicaType#TLOG} replicas.
+   */
+  TLOG,
+  /**
+   * Doesn’t index or writes to transaction log. Just replicates from {@link ReplicaType#NRT} or {@link ReplicaType#TLOG} replicas. {@link ReplicaType#PULL}
+   * replicas can’t become shard leaders (i.e., if there are only pull replicas in the collection at some point, updates will fail
+   * same as if there is no leaders, queries continue to work), so they don’t even participate in elections.
+   */
+  PULL;
+
+  public static ReplicaType get(String name) {
+    return name == null ? ReplicaType.NRT : ReplicaType.valueOf(name.toUpperCase(Locale.ROOT));
+  }
+}
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/policy8x/AssignerClusterStateProvider.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/policy8x/AssignerClusterStateProvider.java
index 6f60e30..92c9245 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/policy8x/AssignerClusterStateProvider.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/policy8x/AssignerClusterStateProvider.java
@@ -37,8 +37,8 @@ public class AssignerClusterStateProvider implements ClusterStateProvider {
         Map<String, Replica> replicas = new HashMap<>();
         shardState.getReplicas().forEach(ar -> {
           Replica r = new Replica(ar.getName(), ar.getNode(), ar.getCollection(), ar.getShard(),
-              ar.getCore(), Replica.State.getState(ar.getState()),
-              Replica.Type.get(ar.getType()), ar.getProperties());
+              ar.getCore(), Replica.State.getState(ar.getState().toString()),
+              Replica.Type.get(ar.getType().toString()), ar.getProperties());
           replicas.put(r.getName(), r);
         });
         Slice slice = new Slice(shard, replicas, shardState.getProperties(), coll);
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/policy8x/AssignerNodeStateProvider.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/policy8x/AssignerNodeStateProvider.java
index 31904ee..e721f09 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/policy8x/AssignerNodeStateProvider.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/policy8x/AssignerNodeStateProvider.java
@@ -43,8 +43,8 @@ public class AssignerNodeStateProvider implements NodeStateProvider {
       Map<String, List<Replica>> perColl = replicas.computeIfAbsent(ar.getCollection(), Utils.NEW_HASHMAP_FUN);
       List<Replica> perShard = perColl.computeIfAbsent(ar.getShard(), Utils.NEW_ARRAYLIST_FUN);
       Replica r = new Replica(ar.getName(), ar.getNode(), ar.getCollection(), ar.getShard(),
-          ar.getCore(), Replica.State.getState(ar.getState()),
-          Replica.Type.get(ar.getType()), ar.getProperties());
+          ar.getCore(), Replica.State.getState(ar.getState().toString()),
+          Replica.Type.get(ar.getType().toString()), ar.getProperties());
       perShard.add(r);
     });
     return replicas;
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/policy8x/SolrCloudManagerAssignerClusterState.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/policy8x/SolrCloudManagerAssignerClusterState.java
index 24f79ea..eddb83c 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/policy8x/SolrCloudManagerAssignerClusterState.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/assign/policy8x/SolrCloudManagerAssignerClusterState.java
@@ -17,6 +17,8 @@ import org.apache.solr.cloud.api.collections.assign.AssignerCollectionState;
 import org.apache.solr.cloud.api.collections.assign.AssignerNodeState;
 import org.apache.solr.cloud.api.collections.assign.AssignerReplica;
 import org.apache.solr.cloud.api.collections.assign.AssignerShardState;
+import org.apache.solr.cloud.api.collections.assign.ReplicaState;
+import org.apache.solr.cloud.api.collections.assign.ReplicaType;
 import org.apache.solr.common.cloud.ClusterState;
 import org.apache.solr.common.cloud.DocCollection;
 import org.apache.solr.common.cloud.Replica;
@@ -60,20 +62,22 @@ public class SolrCloudManagerAssignerClusterState implements AssignerClusterStat
   public AssignerNodeState getNodeState(String nodeName, Collection<String> nodeKeys, Collection<String> replicaKeys) {
     final NodeStateProvider nodeStateProvider = cloudManager.getNodeStateProvider();
     return new AssignerNodeState() {
-      @Override
-      public Collection<AssignerReplica> getReplicas() {
-        Map<String, Map<String, List<Replica>>> replicaInfos = nodeStateProvider.getReplicaInfo(nodeName, replicaKeys);
-        List<AssignerReplica> replicas = new ArrayList<>();
+      Map<String, Map<String, List<Replica>>> replicaInfos = nodeStateProvider.getReplicaInfo(nodeName, replicaKeys);
+      List<AssignerReplica> replicas = new ArrayList<>();
+      {
         replicaInfos.forEach((coll, shards) -> {
           shards.forEach((shard, infos) -> {
             infos.forEach(info -> {
               AssignerReplica ar = new AssignerReplica(info.getName(), info.getNodeName(), info.getCollection(),
-                  info.getShard(), info.getCoreName(), info.getType().toString(), info.getState().toString(),
-                  info.getProperties());
+                  info.getShard(), info.getCoreName(), ReplicaType.get(info.getType().toString()),
+                  ReplicaState.get(info.getState().toString()), info.getProperties());
               replicas.add(ar);
             });
           });
         });
+      }
+      @Override
+      public Collection<AssignerReplica> getReplicas() {
         return replicas;
       }
 
@@ -88,6 +92,11 @@ public class SolrCloudManagerAssignerClusterState implements AssignerClusterStat
       }
 
       @Override
+      public int getNumCores() {
+        return replicas.size();
+      }
+
+      @Override
       public Map<String, Object> getProperties() {
         return nodeStateProvider.getNodeValues(nodeName, nodeKeys);
       }
@@ -133,8 +142,8 @@ public class SolrCloudManagerAssignerClusterState implements AssignerClusterStat
                     r.getCollection(),
                     r.getShard(),
                     r.getCoreName(),
-                    r.getType().toString(),
-                    r.getState().toString(),
+                    ReplicaType.get(r.getType().toString()),
+                    ReplicaState.get(r.getState().toString()),
                     r.getProperties())).collect(Collectors.toList());
           }