SOLR-13368: Tentative fix for a race condition in managed schema initialization.

This commit is contained in:
Andrzej Bialecki 2019-04-08 10:47:29 +02:00
parent ef7be67ba1
commit 0859be134d
2 changed files with 26 additions and 1 deletions

View File

@ -172,8 +172,10 @@ public class ManagedIndexSchemaFactory extends IndexSchemaFactory implements Sol
managedSchemaResourceName, schemaZkVersion, getSchemaUpdateLock());
if (shouldUpgrade) {
// Persist the managed schema if it doesn't already exist
synchronized (schema.getSchemaUpdateLock()) {
upgradeToManagedSchema();
}
}
return schema;
}

View File

@ -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());
}
}