mirror of https://github.com/apache/lucene.git
SOLR-9832: Schema modifications are not immediately visible on the coordinating node
This commit is contained in:
parent
2e948fea30
commit
bf3a3137be
|
@ -220,6 +220,8 @@ Bug Fixes
|
|||
|
||||
* SOLR-9616: Solr throws exception when expand=true on empty index (Timo Hund via Ishan Chattopadhyaya)
|
||||
|
||||
* SOLR-9832: Schema modifications are not immediately visible on the coordinating node. (Steve Rowe)
|
||||
|
||||
Other Changes
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -119,7 +119,6 @@ import org.apache.solr.schema.FieldType;
|
|||
import org.apache.solr.schema.IndexSchema;
|
||||
import org.apache.solr.schema.IndexSchemaFactory;
|
||||
import org.apache.solr.schema.ManagedIndexSchema;
|
||||
import org.apache.solr.schema.SchemaManager;
|
||||
import org.apache.solr.schema.SimilarityFactory;
|
||||
import org.apache.solr.search.QParserPlugin;
|
||||
import org.apache.solr.search.SolrFieldCacheMBean;
|
||||
|
@ -2720,13 +2719,6 @@ public final class SolrCore implements SolrInfoMBean, Closeable {
|
|||
if (checkStale(zkClient, overlayPath, solrConfigversion) ||
|
||||
checkStale(zkClient, solrConfigPath, overlayVersion) ||
|
||||
checkStale(zkClient, managedSchmaResourcePath, managedSchemaVersion)) {
|
||||
|
||||
try (SolrCore solrCore = cc.solrCores.getCoreFromAnyList(coreName, true)) {
|
||||
solrCore.setLatestSchema(SchemaManager.getFreshManagedSchema(solrCore));
|
||||
} catch (Exception e) {
|
||||
log.warn("", SolrZkClient.checkInterrupted(e));
|
||||
}
|
||||
|
||||
log.info("core reload {}", coreName);
|
||||
try {
|
||||
cc.reload(coreName);
|
||||
|
|
|
@ -377,6 +377,18 @@ public class ManagedIndexSchemaFactory extends IndexSchemaFactory implements Sol
|
|||
this.zkIndexSchemaReader = new ZkIndexSchemaReader(this, core);
|
||||
ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader)loader;
|
||||
zkLoader.setZkIndexSchemaReader(this.zkIndexSchemaReader);
|
||||
try {
|
||||
zkIndexSchemaReader.refreshSchemaFromZk(-1); // update immediately if newer is available
|
||||
core.setLatestSchema(getSchema());
|
||||
} catch (KeeperException e) {
|
||||
String msg = "Error attempting to access " + zkLoader.getConfigSetZkPath() + "/" + managedSchemaResourceName;
|
||||
log.error(msg, e);
|
||||
throw new SolrException(ErrorCode.SERVER_ERROR, msg, e);
|
||||
} catch (InterruptedException e) {
|
||||
// Restore the interrupted status
|
||||
Thread.currentThread().interrupt();
|
||||
log.warn("", e);
|
||||
}
|
||||
} else {
|
||||
this.zkIndexSchemaReader = null;
|
||||
}
|
||||
|
|
|
@ -133,8 +133,8 @@ public class SchemaManager {
|
|||
try {
|
||||
int latestVersion = ZkController.persistConfigResourceToZooKeeper(zkLoader, managedIndexSchema.getSchemaZkVersion(),
|
||||
managedIndexSchema.getResourceName(), sw.toString().getBytes(StandardCharsets.UTF_8), true);
|
||||
req.getCore().getCoreDescriptor().getCoreContainer().reload(req.getCore().getName());
|
||||
waitForOtherReplicasToUpdate(timeOut, latestVersion);
|
||||
core.setLatestSchema(managedIndexSchema);
|
||||
return Collections.emptyList();
|
||||
} catch (ZkController.ResourceModifiedInZkException e) {
|
||||
log.info("Schema was modified by another node. Retrying..");
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.solr.schema;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.solr.client.solrj.SolrClient;
|
||||
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
||||
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
|
||||
import org.apache.solr.client.solrj.request.schema.SchemaRequest;
|
||||
import org.apache.solr.client.solrj.response.schema.SchemaResponse;
|
||||
import org.apache.solr.cloud.SolrCloudTestCase;
|
||||
import org.apache.solr.common.cloud.DocCollection;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ManagedSchemaRoundRobinCloudTest extends SolrCloudTestCase {
|
||||
private static final String COLLECTION = "managed_coll";
|
||||
private static final String CONFIG = "cloud-managed";
|
||||
private static final String FIELD_PREFIX = "NumberedField_";
|
||||
private static final int NUM_SHARDS = 2;
|
||||
private static final int NUM_FIELDS_TO_ADD = 10;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupCluster() throws Exception {
|
||||
System.setProperty("managed.schema.mutable", "true");
|
||||
configureCluster(NUM_SHARDS).addConfig(CONFIG, configset(CONFIG)).configure();
|
||||
CollectionAdminRequest.createCollection(COLLECTION, CONFIG, NUM_SHARDS, 1)
|
||||
.setMaxShardsPerNode(1)
|
||||
.process(cluster.getSolrClient());
|
||||
cluster.getSolrClient().waitForState(COLLECTION, DEFAULT_TIMEOUT, TimeUnit.SECONDS,
|
||||
(n, c) -> DocCollection.isFullyActive(n, c, NUM_SHARDS, 1));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void clearSysProps() throws Exception {
|
||||
System.clearProperty("managed.schema.mutable");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddFieldsRoundRobin() throws Exception {
|
||||
List<HttpSolrClient> clients = new ArrayList<>(NUM_SHARDS);
|
||||
try {
|
||||
for (int shardNum = 0 ; shardNum < NUM_SHARDS ; ++shardNum) {
|
||||
clients.add(getHttpSolrClient(cluster.getJettySolrRunners().get(shardNum).getBaseUrl().toString()));
|
||||
}
|
||||
int shardNum = 0;
|
||||
for (int fieldNum = 0 ; fieldNum < NUM_FIELDS_TO_ADD ; ++fieldNum) {
|
||||
addField(clients.get(shardNum), keyValueArrayToMap("name", FIELD_PREFIX + fieldNum, "type", "string"));
|
||||
if (++shardNum == NUM_SHARDS) {
|
||||
shardNum = 0;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
for (int shardNum = 0 ; shardNum < NUM_SHARDS ; ++shardNum) {
|
||||
clients.get(shardNum).close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addField(SolrClient client, Map<String,Object> field) throws Exception {
|
||||
SchemaResponse.UpdateResponse addFieldResponse = new SchemaRequest.AddField(field).process(client, COLLECTION);
|
||||
assertNotNull(addFieldResponse);
|
||||
assertEquals(0, addFieldResponse.getStatus());
|
||||
assertNull(addFieldResponse.getResponse().get("errors"));
|
||||
String fieldName = field.get("name").toString();
|
||||
SchemaResponse.FieldResponse fieldResponse = new SchemaRequest.Field(fieldName).process(client, COLLECTION);
|
||||
assertNotNull(fieldResponse);
|
||||
assertEquals(0, fieldResponse.getStatus());
|
||||
}
|
||||
|
||||
private Map<String,Object> keyValueArrayToMap(String... alternatingKeysAndValues) {
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
for (int i = 0 ; i < alternatingKeysAndValues.length ; i += 2)
|
||||
map.put(alternatingKeysAndValues[i], alternatingKeysAndValues[i + 1]);
|
||||
return map;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue