lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [lucene-solr] branch jira/solr-15055-2 updated: SOLR-15055: Remove references to PlacementPlugin from collection commands.
Date Thu, 21 Jan 2021 09:21:01 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/jira/solr-15055-2 by this push:
     new 1497d8c  SOLR-15055: Remove references to PlacementPlugin from collection commands.
1497d8c is described below

commit 1497d8c2cce494f9f271a9ab83b079e6301406f6
Author: Andrzej Bialecki <ab@apache.org>
AuthorDate: Thu Jan 21 10:20:28 2021 +0100

    SOLR-15055: Remove references to PlacementPlugin from collection commands.
---
 .../solr/cloud/api/collections/AddReplicaCmd.java   |  8 ++++----
 .../apache/solr/cloud/api/collections/Assign.java   |  8 +++++---
 .../cloud/api/collections/CreateCollectionCmd.java  | 12 ++++++------
 .../cloud/api/collections/DeleteCollectionCmd.java  |  4 +---
 .../cloud/api/collections/DeleteReplicaCmd.java     | 21 ++++++++++-----------
 .../solr/cloud/api/collections/ReplaceNodeCmd.java  |  2 +-
 .../solr/cloud/api/collections/RestoreCmd.java      |  2 +-
 .../solr/cloud/api/collections/SplitShardCmd.java   |  2 +-
 .../events/impl/CollectionsRepairEventListener.java |  8 +++-----
 9 files changed, 32 insertions(+), 35 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/AddReplicaCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/AddReplicaCmd.java
index b24e442..c3f5004 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/AddReplicaCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/AddReplicaCmd.java
@@ -45,7 +45,6 @@ import org.apache.solr.client.solrj.cloud.SolrCloudManager;
 import org.apache.solr.cloud.ActiveReplicaWatcher;
 import org.apache.solr.cloud.Overseer;
 import org.apache.solr.cloud.api.collections.OverseerCollectionMessageHandler.ShardRequestTracker;
-import org.apache.solr.cluster.placement.PlacementPlugin;
 import org.apache.solr.common.SolrCloseableLatch;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.cloud.ClusterState;
@@ -61,6 +60,7 @@ import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.params.ShardParams;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.Utils;
+import org.apache.solr.core.CoreContainer;
 import org.apache.solr.handler.component.ShardHandler;
 import org.apache.zookeeper.KeeperException;
 import org.slf4j.Logger;
@@ -141,7 +141,7 @@ public class AddReplicaCmd implements OverseerCollectionMessageHandler.Cmd
{
     }
 
     List<CreateReplica> createReplicas = buildReplicaPositions(ocmh.cloudManager, clusterState,
collectionName, message, replicaTypesVsCount,
-        ocmh.overseer.getCoreContainer().getPlacementPluginFactory().createPluginInstance())
+        ocmh.overseer.getCoreContainer())
           .stream()
           .map(replicaPosition -> assignReplicaDetails(ocmh.cloudManager, clusterState,
message, replicaPosition))
           .collect(Collectors.toList());
@@ -302,7 +302,7 @@ public class AddReplicaCmd implements OverseerCollectionMessageHandler.Cmd
{
   public static List<ReplicaPosition> buildReplicaPositions(SolrCloudManager cloudManager,
ClusterState clusterState,
                                                             String collectionName, ZkNodeProps
message,
                                                             EnumMap<Replica.Type, Integer>
replicaTypeVsCount,
-                                                            PlacementPlugin placementPlugin)
throws IOException, InterruptedException {
+                                                            CoreContainer coreContainer)
throws IOException, InterruptedException {
     boolean skipCreateReplicaInClusterState = message.getBool(SKIP_CREATE_REPLICA_IN_CLUSTER_STATE,
false);
     boolean skipNodeAssignment = message.getBool(CollectionAdminParams.SKIP_NODE_ASSIGNMENT,
false);
     String sliceName = message.getStr(SHARD_ID_PROP);
@@ -326,7 +326,7 @@ public class AddReplicaCmd implements OverseerCollectionMessageHandler.Cmd
{
     if (!skipCreateReplicaInClusterState && !skipNodeAssignment) {
 
       positions = Assign.getNodesForNewReplicas(clusterState, collection.getName(), sliceName,
numNrtReplicas,
-                    numTlogReplicas, numPullReplicas, createNodeSetStr, cloudManager, placementPlugin);
+                    numTlogReplicas, numPullReplicas, createNodeSetStr, cloudManager, coreContainer);
     }
 
     if (positions == null)  {
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/Assign.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/Assign.java
index 3c40d46..48aadbd 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/Assign.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/Assign.java
@@ -51,6 +51,7 @@ import org.apache.solr.common.cloud.Slice;
 import org.apache.solr.common.cloud.ZkNodeProps;
 import org.apache.solr.common.cloud.ZkStateReader;
 import org.apache.solr.common.util.StrUtils;
+import org.apache.solr.core.CoreContainer;
 import org.apache.solr.util.NumberUtils;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
@@ -270,7 +271,7 @@ public class Assign {
   public static List<ReplicaPosition> getNodesForNewReplicas(ClusterState clusterState,
String collectionName,
                                                           String shard, int nrtReplicas,
int tlogReplicas, int pullReplicas,
                                                           Object createNodeSet, SolrCloudManager
cloudManager,
-                                                          PlacementPlugin placementPlugin)
throws IOException, InterruptedException, AssignmentException {
+                                                          CoreContainer coreContainer) throws
IOException, InterruptedException, AssignmentException {
     log.debug("getNodesForNewReplicas() shard: {} , nrtReplicas : {} , tlogReplicas: {} ,
pullReplicas: {} , createNodeSet {}"
         , shard, nrtReplicas, tlogReplicas, pullReplicas, createNodeSet);
     DocCollection coll = clusterState.getCollection(collectionName);
@@ -296,7 +297,7 @@ public class Assign {
         .assignPullReplicas(pullReplicas)
         .onNodes(createNodeList)
         .build();
-    AssignStrategy assignStrategy = createAssignStrategy(placementPlugin, clusterState, coll);
+    AssignStrategy assignStrategy = createAssignStrategy(coreContainer, clusterState, coll);
     return assignStrategy.assign(cloudManager, assignRequest);
   }
 
@@ -509,7 +510,8 @@ public class Assign {
    * <p>If {@link PlacementPlugin} instance is null this call will return {@link LegacyAssignStrategy},
otherwise
    * {@link PlacementPluginAssignStrategy} will be used.</p>
    */
-  public static AssignStrategy createAssignStrategy(PlacementPlugin placementPlugin, ClusterState
clusterState, DocCollection collection) {
+  public static AssignStrategy createAssignStrategy(CoreContainer coreContainer, ClusterState
clusterState, DocCollection collection) {
+    PlacementPlugin placementPlugin = coreContainer.getPlacementPluginFactory().createPluginInstance();
     if (placementPlugin != null) {
       // If a cluster wide placement plugin is configured (and that's the only way to define
a placement plugin)
       return new PlacementPluginAssignStrategy(collection, placementPlugin);
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java
b/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java
index 2e2a06c..d9de9a5 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java
@@ -41,7 +41,6 @@ import org.apache.solr.cloud.Overseer;
 import org.apache.solr.cloud.ZkController;
 import org.apache.solr.cloud.api.collections.OverseerCollectionMessageHandler.ShardRequestTracker;
 import org.apache.solr.cloud.overseer.ClusterStateMutator;
-import org.apache.solr.cluster.placement.PlacementPlugin;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrException.ErrorCode;
 import org.apache.solr.common.cloud.Aliases;
@@ -63,6 +62,7 @@ import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SimpleOrderedMap;
 import org.apache.solr.common.util.TimeSource;
 import org.apache.solr.common.util.Utils;
+import org.apache.solr.core.CoreContainer;
 import org.apache.solr.handler.component.ShardHandler;
 import org.apache.solr.handler.component.ShardRequest;
 import org.apache.solr.util.TimeOut;
@@ -169,8 +169,8 @@ public class CreateCollectionCmd implements OverseerCollectionMessageHandler.Cmd
 
       List<ReplicaPosition> replicaPositions = null;
       try {
-        replicaPositions = buildReplicaPositions(ocmh.cloudManager, clusterState, clusterState.getCollection(collectionName),
-            message, shardNames, ocmh.overseer.getCoreContainer().getPlacementPluginFactory().createPluginInstance());
+        replicaPositions = buildReplicaPositions(ocmh.overseer.getCoreContainer(), ocmh.cloudManager,
clusterState, clusterState.getCollection(collectionName),
+            message, shardNames);
       } catch (Assign.AssignmentException e) {
         ZkNodeProps deleteMessage = new ZkNodeProps("name", collectionName);
         new DeleteCollectionCmd(ocmh).call(clusterState, deleteMessage, results);
@@ -288,10 +288,10 @@ public class CreateCollectionCmd implements OverseerCollectionMessageHandler.Cmd
     }
   }
 
-  private static List<ReplicaPosition> buildReplicaPositions(SolrCloudManager cloudManager,
ClusterState clusterState,
+  private static List<ReplicaPosition> buildReplicaPositions(CoreContainer coreContainer,
SolrCloudManager cloudManager, ClusterState clusterState,
                                                              DocCollection docCollection,
                                                              ZkNodeProps message,
-                                                             List<String> shardNames,
PlacementPlugin placementPlugin) throws IOException, InterruptedException, Assign.AssignmentException
{
+                                                             List<String> shardNames)
throws IOException, InterruptedException, Assign.AssignmentException {
     final String collectionName = message.getStr(NAME);
     // look at the replication factor and see if it matches reality
     // if it does not, find best nodes to create more cores
@@ -330,7 +330,7 @@ public class CreateCollectionCmd implements OverseerCollectionMessageHandler.Cmd
           .assignPullReplicas(numPullReplicas)
           .onNodes(nodeList)
           .build();
-      Assign.AssignStrategy assignStrategy = Assign.createAssignStrategy(placementPlugin,
clusterState, docCollection);
+      Assign.AssignStrategy assignStrategy = Assign.createAssignStrategy(coreContainer, clusterState,
docCollection);
       replicaPositions = assignStrategy.assign(cloudManager, assignRequest);
     }
     return replicaPositions;
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteCollectionCmd.java
b/solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteCollectionCmd.java
index 4f189db..0e1e1f5 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteCollectionCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteCollectionCmd.java
@@ -29,7 +29,6 @@ import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 import org.apache.solr.cloud.Overseer;
-import org.apache.solr.cluster.placement.PlacementPlugin;
 import org.apache.solr.common.NonExistentCoreException;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.cloud.Aliases;
@@ -93,10 +92,9 @@ public class DeleteCollectionCmd implements OverseerCollectionMessageHandler.Cmd
       collection = extCollection;
     }
 
-    PlacementPlugin placementPlugin = ocmh.overseer.getCoreContainer().getPlacementPluginFactory().createPluginInstance();
     // verify the placement modifications caused by the deletion are allowed
     DocCollection coll = state.getCollection(collection);
-    Assign.AssignStrategy assignStrategy = Assign.createAssignStrategy(placementPlugin, state,
coll);
+    Assign.AssignStrategy assignStrategy = Assign.createAssignStrategy(ocmh.overseer.getCoreContainer(),
state, coll);
     assignStrategy.verifyDeleteCollection(ocmh.cloudManager, coll);
 
     final boolean deleteHistory = message.getBool(CoreAdminParams.DELETE_METRICS_HISTORY,
true);
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteReplicaCmd.java
b/solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteReplicaCmd.java
index 1d4eede..76fa1b2 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteReplicaCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/DeleteReplicaCmd.java
@@ -35,7 +35,6 @@ import java.util.concurrent.Callable;
 
 import org.apache.solr.cloud.api.collections.OverseerCollectionMessageHandler.Cmd;
 import org.apache.solr.cloud.api.collections.OverseerCollectionMessageHandler.ShardRequestTracker;
-import org.apache.solr.cluster.placement.PlacementPlugin;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.cloud.ClusterState;
 import org.apache.solr.common.cloud.DocCollection;
@@ -77,10 +76,9 @@ public class DeleteReplicaCmd implements Cmd {
     }
     boolean parallel = message.getBool("parallel", false);
 
-    PlacementPlugin placementPlugin = ocmh.overseer.getCoreContainer().getPlacementPluginFactory().createPluginInstance();
     //If a count is specified the strategy needs be different
     if (message.getStr(COUNT_PROP) != null) {
-      deleteReplicaBasedOnCount(clusterState, message, results, onComplete, parallel, placementPlugin);
+      deleteReplicaBasedOnCount(clusterState, message, results, onComplete, parallel);
       return;
     }
 
@@ -104,7 +102,7 @@ public class DeleteReplicaCmd implements Cmd {
       throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
               "Invalid shard name : " +  shard + " in collection : " +  collectionName);
     }
-    deleteCore(clusterState, coll, shard, replicaName, message, results, onComplete, parallel,
placementPlugin);
+    deleteCore(clusterState, coll, shard, replicaName, message, results, onComplete, parallel,
true);
   }
 
 
@@ -117,8 +115,7 @@ public class DeleteReplicaCmd implements Cmd {
                                  ZkNodeProps message,
                                  @SuppressWarnings({"rawtypes"})NamedList results,
                                  Runnable onComplete,
-                                 boolean parallel,
-                                 PlacementPlugin placementPlugin)
+                                 boolean parallel)
           throws KeeperException, IOException, InterruptedException {
     ocmh.checkRequired(message, COLLECTION_PROP, COUNT_PROP);
     int count = Integer.parseInt(message.getStr(COUNT_PROP));
@@ -150,7 +147,7 @@ public class DeleteReplicaCmd implements Cmd {
     }
 
     // verify that all replicas can be deleted
-    Assign.AssignStrategy assignStrategy = Assign.createAssignStrategy(placementPlugin, clusterState,
coll);
+    Assign.AssignStrategy assignStrategy = Assign.createAssignStrategy(ocmh.overseer.getCoreContainer(),
clusterState, coll);
     for (Map.Entry<Slice, Set<String>> entry : shardToReplicasMapping.entrySet())
{
       Slice shardSlice = entry.getKey();
       String shardId = shardSlice.getName();
@@ -166,7 +163,7 @@ public class DeleteReplicaCmd implements Cmd {
       for (String replica: replicas) {
         log.debug("Deleting replica {}  for shard {} based on count {}", replica, shardId,
count);
         // don't verify with the placement plugin - we already did it
-        deleteCore(clusterState, coll, shardId, replica, message, results, onComplete, parallel,
null);
+        deleteCore(clusterState, coll, shardId, replica, message, results, onComplete, parallel,
false);
       }
       results.add("shard_id", shardId);
       results.add("replicas_deleted", replicas);
@@ -231,7 +228,7 @@ public class DeleteReplicaCmd implements Cmd {
                   @SuppressWarnings({"rawtypes"})NamedList results,
                   Runnable onComplete,
                   boolean parallel,
-                  PlacementPlugin placementPlugin) throws KeeperException, IOException, InterruptedException
{
+                  boolean verifyPlacement) throws KeeperException, IOException, InterruptedException
{
 
     Slice slice = coll.getSlice(shardId);
     Replica replica = slice.getReplica(replicaName);
@@ -252,8 +249,10 @@ public class DeleteReplicaCmd implements Cmd {
     }
 
     // verify that we are allowed to delete this replica
-    Assign.AssignStrategy assignStrategy = Assign.createAssignStrategy(placementPlugin, clusterState,
coll);
-    assignStrategy.verifyDeleteReplicas(ocmh.cloudManager, coll, shardId, Set.of(replicaName));
+    if (verifyPlacement) {
+      Assign.AssignStrategy assignStrategy = Assign.createAssignStrategy(ocmh.overseer.getCoreContainer(),
clusterState, coll);
+      assignStrategy.verifyDeleteReplicas(ocmh.cloudManager, coll, shardId, Set.of(replicaName));
+    }
 
     ShardHandler shardHandler = ocmh.shardHandlerFactory.getShardHandler();
     String core = replica.getStr(ZkStateReader.CORE_NAME_PROP);
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/ReplaceNodeCmd.java
b/solr/core/src/java/org/apache/solr/cloud/api/collections/ReplaceNodeCmd.java
index 271677f..7140946 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/ReplaceNodeCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/ReplaceNodeCmd.java
@@ -121,7 +121,7 @@ public class ReplaceNodeCmd implements OverseerCollectionMessageHandler.Cmd
{
               .onNodes(new ArrayList<>(ocmh.cloudManager.getClusterStateProvider().getLiveNodes()))
               .build();
           Assign.AssignStrategy assignStrategy = Assign.createAssignStrategy(
-              ocmh.overseer.getCoreContainer().getPlacementPluginFactory().createPluginInstance(),
+              ocmh.overseer.getCoreContainer(),
               clusterState, clusterState.getCollection(sourceCollection));
           targetNode = assignStrategy.assign(ocmh.cloudManager, assignRequest).get(0).node;
         }
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/RestoreCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/RestoreCmd.java
index c7c941a..03cb47a 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/RestoreCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/RestoreCmd.java
@@ -230,7 +230,7 @@ public class RestoreCmd implements OverseerCollectionMessageHandler.Cmd
{
             .onNodes(nodeList)
             .build();
     Assign.AssignStrategy assignStrategy = Assign.createAssignStrategy(
-        ocmh.overseer.getCoreContainer().getPlacementPluginFactory().createPluginInstance(),
+        ocmh.overseer.getCoreContainer(),
         clusterState, restoreCollection);
     List<ReplicaPosition> replicaPositions = assignStrategy.assign(ocmh.cloudManager,
assignRequest);
 
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/SplitShardCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/SplitShardCmd.java
index e622e84..ff9df3b 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/SplitShardCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/SplitShardCmd.java
@@ -436,7 +436,7 @@ public class SplitShardCmd implements OverseerCollectionMessageHandler.Cmd
{
           .onNodes(new ArrayList<>(clusterState.getLiveNodes()))
           .build();
       Assign.AssignStrategy assignStrategy = Assign.createAssignStrategy(
-          ocmh.overseer.getCoreContainer().getPlacementPluginFactory().createPluginInstance(),
+          ocmh.overseer.getCoreContainer(),
           clusterState, collection);
       List<ReplicaPosition> replicaPositions = assignStrategy.assign(ocmh.cloudManager,
assignRequest);
       t.stop();
diff --git a/solr/core/src/java/org/apache/solr/cluster/events/impl/CollectionsRepairEventListener.java
b/solr/core/src/java/org/apache/solr/cluster/events/impl/CollectionsRepairEventListener.java
index 8984d1d..be4533b 100644
--- a/solr/core/src/java/org/apache/solr/cluster/events/impl/CollectionsRepairEventListener.java
+++ b/solr/core/src/java/org/apache/solr/cluster/events/impl/CollectionsRepairEventListener.java
@@ -41,8 +41,6 @@ import org.apache.solr.cloud.api.collections.Assign;
 import org.apache.solr.cluster.events.ClusterEvent;
 import org.apache.solr.cluster.events.ClusterEventListener;
 import org.apache.solr.cluster.events.NodesDownEvent;
-import org.apache.solr.cluster.placement.PlacementPluginConfig;
-import org.apache.solr.cluster.placement.PlacementPluginFactory;
 import org.apache.solr.common.cloud.ClusterState;
 import org.apache.solr.common.cloud.Replica;
 import org.apache.solr.common.cloud.ReplicaPosition;
@@ -72,18 +70,18 @@ public class CollectionsRepairEventListener implements ClusterEventListener,
Clu
 
   private final SolrClient solrClient;
   private final SolrCloudManager solrCloudManager;
+  private final CoreContainer cc;
 
   private State state = State.STOPPED;
 
   private int waitForSecond = DEFAULT_WAIT_FOR_SEC;
 
   private ScheduledThreadPoolExecutor waitForExecutor;
-  private final PlacementPluginFactory<? extends PlacementPluginConfig> placementPluginFactory;
 
   public CollectionsRepairEventListener(CoreContainer cc) {
+    this.cc = cc;
     this.solrClient = cc.getSolrClientCache().getCloudSolrClient(cc.getZkController().getZkClient().getZkServerAddress());
     this.solrCloudManager = cc.getZkController().getSolrCloudManager();
-    this.placementPluginFactory = cc.getPlacementPluginFactory();
   }
 
   @VisibleForTesting
@@ -169,7 +167,7 @@ public class CollectionsRepairEventListener implements ClusterEventListener,
Clu
                 .incrementAndGet();
           }
         });
-        Assign.AssignStrategy assignStrategy = Assign.createAssignStrategy(placementPluginFactory.createPluginInstance(),
clusterState, coll);
+        Assign.AssignStrategy assignStrategy = Assign.createAssignStrategy(cc, clusterState,
coll);
         lostReplicas.forEach((shard, types) -> {
           Assign.AssignRequestBuilder assignRequestBuilder = new Assign.AssignRequestBuilder()
               .forCollection(coll.getName())


Mime
View raw message