Apache Solr open-source search software
SOLR-16871: Synchronize on a larger block to avoid race condition in CoordinatorHttpSolrCall init (#1800)
patsonlukccc7ca65f12e
diff --git a/solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java b/solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.javaindex cadb5a735c5..82664b23623 100644--- a/solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java+++ b/solr/core/src/java/org/apache/solr/servlet/CoordinatorHttpSolrCall.java@@ -91,40 +91,44 @@ public class CoordinatorHttpSolrCall extends HttpSolrCall {String syntheticCollectionName = getSyntheticCollectionName(confName);DocCollection syntheticColl = clusterState.getCollectionOrNull(syntheticCollectionName);- if (syntheticColl == null) {- // no synthetic collection for this config, let's create one- if (log.isInfoEnabled()) {- log.info(- "synthetic collection: {} does not exist, creating.. ", syntheticCollectionName);- }+ synchronized (CoordinatorHttpSolrCall.class) {+ if (syntheticColl == null) {+ // no synthetic collection for this config, let's create one+ if (log.isInfoEnabled()) {+ log.info(+ "synthetic collection: {} does not exist, creating.. ", syntheticCollectionName);+ }- SolrException createException = null;- try {- createColl(syntheticCollectionName, solrCall.cores, confName);- } catch (SolrException exception) {- // concurrent requests could have created the collection hence causing collection exists- // exception- createException = exception;- } finally {- syntheticColl =- zkStateReader.getClusterState().getCollectionOrNull(syntheticCollectionName);- }+ SolrException createException = null;+ try {+ createColl(syntheticCollectionName, solrCall.cores, confName);+ } catch (SolrException exception) {+ // concurrent requests could have created the collection hence causing collection+ // exists+ // exception+ createException = exception;+ } finally {+ syntheticColl =+ zkStateReader.getClusterState().getCollectionOrNull(syntheticCollectionName);+ }- // then indeed the collection was not created properly, either by this or other concurrent- // requests- if (syntheticColl == null) {- if (createException != null) {- throw createException; // rethrow the exception since such collection was not created- } else {- throw new SolrException(- SolrException.ErrorCode.SERVER_ERROR,- "Could not locate synthetic collection ["- + syntheticCollectionName- + "] after creation!");+ // then indeed the collection was not created properly, either by this or other+ // concurrent+ // requests+ if (syntheticColl == null) {+ if (createException != null) {+ throw createException; // rethrow the exception since such collection was not+ // created+ } else {+ throw new SolrException(+ SolrException.ErrorCode.SERVER_ERROR,+ "Could not locate synthetic collection ["+ + syntheticCollectionName+ + "] after creation!");+ }}}- }- synchronized (CoordinatorHttpSolrCall.class) {+// get docCollection again to ensure we get the fresh statesyntheticColl =zkStateReader.getClusterState().getCollectionOrNull(syntheticCollectionName);