From 0859be134db8abb5d7cf68dd49baa51acf8d0c44 Mon Sep 17 00:00:00 2001 From: Andrzej Bialecki Date: Mon, 8 Apr 2019 10:47:29 +0200 Subject: [PATCH] SOLR-13368: Tentative fix for a race condition in managed schema initialization. --- .../schema/ManagedIndexSchemaFactory.java | 4 +++- .../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 72c3d6f087a..eb730595684 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 14f1525cd05..6635764d0db 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 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()); + + } + }