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 2019/04/08 08:50:44 UTC

[lucene-solr] branch master updated: SOLR-13368: Tentative fix for a race condition in managed schema initialization.

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 0859be1  SOLR-13368: Tentative fix for a race condition in managed schema initialization.
0859be1 is described below

commit 0859be134db8abb5d7cf68dd49baa51acf8d0c44
Author: Andrzej Bialecki <ab...@apache.org>
AuthorDate: Mon Apr 8 10:47:29 2019 +0200

    SOLR-13368: Tentative fix for a race condition in managed schema initialization.
---
 .../solr/schema/ManagedIndexSchemaFactory.java     |  4 +++-
 .../apache/solr/schema/TestManagedSchemaAPI.java   | 23 ++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java
index 72c3d6f..eb73059 100644
--- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java
+++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java
@@ -172,7 +172,9 @@ public class ManagedIndexSchemaFactory extends IndexSchemaFactory implements Sol
                                     managedSchemaResourceName, schemaZkVersion, getSchemaUpdateLock());
     if (shouldUpgrade) {
       // Persist the managed schema if it doesn't already exist
-      upgradeToManagedSchema();
+      synchronized (schema.getSchemaUpdateLock()) {
+        upgradeToManagedSchema();
+      }
     }
 
     return schema;
diff --git a/solr/core/src/test/org/apache/solr/schema/TestManagedSchemaAPI.java b/solr/core/src/test/org/apache/solr/schema/TestManagedSchemaAPI.java
index 14f1525..6635764 100644
--- a/solr/core/src/test/org/apache/solr/schema/TestManagedSchemaAPI.java
+++ b/solr/core/src/test/org/apache/solr/schema/TestManagedSchemaAPI.java
@@ -52,6 +52,7 @@ public class TestManagedSchemaAPI extends SolrCloudTestCase {
     String collection = "testschemaapi";
     CollectionAdminRequest.createCollection(collection, "conf1", 1, 2)
         .process(cluster.getSolrClient());
+    testModifyField(collection);
     testReloadAndAddSimple(collection);
     testAddFieldAndDocument(collection);
   }
@@ -99,4 +100,26 @@ public class TestManagedSchemaAPI extends SolrCloudTestCase {
     log.info("added new field="+fieldName);
   }
 
+  private void testModifyField(String collection) throws IOException, SolrServerException {
+    CloudSolrClient cloudClient = cluster.getSolrClient();
+
+    SolrInputDocument doc = new SolrInputDocument("id", "3");
+    cloudClient.add(collection, doc);
+    cloudClient.commit(collection);
+
+    String fieldName = "id";
+    SchemaRequest.Field getFieldRequest = new SchemaRequest.Field(fieldName);
+    SchemaResponse.FieldResponse getFieldResponse = getFieldRequest.process(cloudClient, collection);
+    Map<String, Object> field = getFieldResponse.getField();
+    field.put("docValues", true);
+    SchemaRequest.ReplaceField replaceRequest = new SchemaRequest.ReplaceField(field);
+    SchemaResponse.UpdateResponse replaceResponse = replaceRequest.process(cloudClient, collection);
+    assertNull(replaceResponse.getResponse().get("errors"));
+    CollectionAdminRequest.Reload reloadRequest = CollectionAdminRequest.reloadCollection(collection);
+    CollectionAdminResponse response = reloadRequest.process(cloudClient);
+    assertEquals(0, response.getStatus());
+    assertTrue(response.isSuccess());
+
+  }
+
 }