Apache Solr open-source search software
SOLR-15653: Fix collection creation race that assumes a local clusterstate when the collection has only just been created.
Mark Millerbafbdb23bd3e
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 6d6819aea49..fb0b6faff16 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -384,6 +384,8 @@ Bug Fixes* SOLR-15628: The SolrException.log() helper method has been fixed to correctly passes the Throwable to the Logger w/o stringification (hossman)+* SOLR-15653: Fix collection creation race that assumes a local clusterstate when the collection has only just been created. (Mark Miller)+================== 8.10.0 ==================Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.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.javaindex 87d1dc1350d..b399ed432d3 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@@ -177,7 +177,7 @@ public class Assign {}private static int defaultCounterValue(DocCollection collection, boolean newCollection, String shard) {- if (newCollection) return 0;+ if (newCollection || collection == null) return 0;int defaultValue;if (collection.getSlice(shard) != null && collection.getSlice(shard).getReplicas().isEmpty()) {@@ -201,20 +201,20 @@ public class Assign {return defaultValue;}- public static String buildSolrCoreName(DistribStateManager stateManager, DocCollection collection, String shard, Replica.Type type, boolean newCollection) {- Slice slice = collection.getSlice(shard);+ public static String buildSolrCoreName(DistribStateManager stateManager, String collectionName, DocCollection collection, String shard, Replica.Type type, boolean newCollection) {+int defaultValue = defaultCounterValue(collection, newCollection, shard);- int replicaNum = incAndGetId(stateManager, collection.getName(), defaultValue);- String coreName = buildSolrCoreName(collection.getName(), shard, type, replicaNum);- while (existCoreName(coreName, slice)) {- replicaNum = incAndGetId(stateManager, collection.getName(), defaultValue);- coreName = buildSolrCoreName(collection.getName(), shard, type, replicaNum);+ int replicaNum = incAndGetId(stateManager, collectionName, defaultValue);+ String coreName = buildSolrCoreName(collectionName, shard, type, replicaNum);+ while (collection != null && existCoreName(coreName, collection.getSlice(shard))) {+ replicaNum = incAndGetId(stateManager, collectionName, defaultValue);+ coreName = buildSolrCoreName(collectionName, shard, type, replicaNum);}return coreName;}public static String buildSolrCoreName(DistribStateManager stateManager, DocCollection collection, String shard, Replica.Type type) {- return buildSolrCoreName(stateManager, collection, shard, type, false);+ return buildSolrCoreName(stateManager, collection.getName(), collection, shard, type, false);}private static boolean existCoreName(String coreName, Slice slice) {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.javaindex 04cb7b846ed..45211d4513a 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@@ -231,8 +231,8 @@ public class CreateCollectionCmd implements CollApiCmds.CollectionApiCommand {for (ReplicaPosition replicaPosition : replicaPositions) {String nodeName = replicaPosition.node;- String coreName = Assign.buildSolrCoreName(ccc.getSolrCloudManager().getDistribStateManager(),- ccc.getSolrCloudManager().getClusterStateProvider().getClusterState().getCollection(collectionName),+ String coreName = Assign.buildSolrCoreName(ccc.getSolrCloudManager().getDistribStateManager(), collectionName,+ ccc.getSolrCloudManager().getClusterStateProvider().getClusterState().getCollectionOrNull(collectionName),replicaPosition.shard, replicaPosition.type, true);if (log.isDebugEnabled()) {log.debug(formatString("Creating core {0} as part of shard {1} of collection {2} on {3}"