Apache Lucene open-source search software
SOLR-11990: Create Collection API now waits for the updated state of the withCollection to be visible after setting the COLOCATED_WITH value
Shalin Shekhar Mangar6e21cb3aa945
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 45ced2b674d..e8f100f8aa8 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@@ -30,6 +30,7 @@ import java.util.Map;import java.util.NoSuchElementException;import java.util.Properties;import java.util.concurrent.TimeUnit;+import java.util.concurrent.TimeoutException;import java.util.concurrent.atomic.AtomicReference;import org.apache.solr.client.solrj.cloud.DistribStateManager;@@ -80,6 +81,7 @@ import static org.apache.solr.common.cloud.ZkStateReader.PULL_REPLICAS;import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;import static org.apache.solr.common.cloud.ZkStateReader.TLOG_REPLICAS;import static org.apache.solr.common.params.CollectionAdminParams.COLL_CONF;+import static org.apache.solr.common.params.CollectionAdminParams.COLOCATED_WITH;import static org.apache.solr.common.params.CollectionParams.CollectionAction.ADDREPLICA;import static org.apache.solr.common.params.CollectionParams.CollectionAction.MODIFYCOLLECTION;import static org.apache.solr.common.params.CommonAdminParams.ASYNC;@@ -304,6 +306,13 @@ public class CreateCollectionCmd implements OverseerCollectionMessageHandler.CmdZkStateReader.COLLECTION_PROP, withCollection,CollectionAdminParams.COLOCATED_WITH, collectionName);Overseer.getStateUpdateQueue(zkStateReader.getZkClient()).offer(Utils.toJSON(props));+ try {+ zkStateReader.waitForState(withCollection, 5, TimeUnit.SECONDS, (liveNodes, collectionState) -> collectionName.equals(collectionState.getStr(COLOCATED_WITH)));+ } catch (TimeoutException e) {+ log.warn("Timed out waiting to see the " + COLOCATED_WITH + " property set on collection: " + withCollection);+ // maybe the overseer queue is backed up, we don't want to fail the create request+ // because of this time out, continue+ }}} catch (SolrException ex) {diff --git a/solr/core/src/test/org/apache/solr/cloud/TestWithCollection.java b/solr/core/src/test/org/apache/solr/cloud/TestWithCollection.javaindex a4816a01b56..01753e08c54 100644--- a/solr/core/src/test/org/apache/solr/cloud/TestWithCollection.java+++ b/solr/core/src/test/org/apache/solr/cloud/TestWithCollection.java@@ -33,6 +33,7 @@ import org.apache.solr.client.solrj.embedded.JettySolrRunner;import org.apache.solr.client.solrj.impl.CloudSolrClient;import org.apache.solr.client.solrj.impl.HttpSolrClient;import org.apache.solr.client.solrj.request.CollectionAdminRequest;+import org.apache.solr.client.solrj.response.CollectionAdminResponse;import org.apache.solr.cloud.autoscaling.ActionContext;import org.apache.solr.cloud.autoscaling.ComputePlanAction;import org.apache.solr.cloud.autoscaling.ExecutePlanAction;@@ -59,7 +60,7 @@ import static org.apache.solr.common.params.CollectionAdminParams.WITH_COLLECTIO** See SOLR-11990 for more details.*/-@LogLevel("org.apache.solr.cloud.autoscaling=TRACE;org.apache.solr.client.solrj.cloud.autoscaling=DEBUG")+@LogLevel("org.apache.solr.cloud.autoscaling=TRACE;org.apache.solr.client.solrj.cloud.autoscaling=DEBUG;org.apache.solr.cloud.overseer=DEBUG")public class TestWithCollection extends SolrCloudTestCase {private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());@@ -186,7 +187,8 @@ public class TestWithCollection extends SolrCloudTestCase {.setWithCollection(abc).process(solrClient);try {- CollectionAdminRequest.deleteCollection(abc).process(solrClient);+ CollectionAdminResponse response = CollectionAdminRequest.deleteCollection(abc).process(solrClient);+ fail("Deleting collection: " + abc + " should have failed with an exception. Instead response was: " + response.getResponse());} catch (HttpSolrClient.RemoteSolrException e) {assertTrue(e.getMessage().contains("is co-located with collection"));}@@ -205,7 +207,8 @@ public class TestWithCollection extends SolrCloudTestCase {.process(solrClient);// sanity checktry {- CollectionAdminRequest.deleteCollection(abc).process(solrClient);+ CollectionAdminResponse response = CollectionAdminRequest.deleteCollection(abc).process(solrClient);+ fail("Deleting collection: " + abc + " should have failed with an exception. Instead response was: " + response.getResponse());} catch (HttpSolrClient.RemoteSolrException e) {assertTrue(e.getMessage().contains("is co-located with collection"));}