Apache Solr open-source search software
SOLR-7132: The Collections API ADDREPLICA command property.name is not reflected in the clusterstate until after Solr restarts
Erick Erickson63da283f049a
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex ca733be5798..91485d86814 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -218,6 +218,9 @@ Bug Fixes* SOLR-7143: MoreLikeThis Query parser should handle multiple field names(Jens Wille, Anshum Gupta)+* SOLR-7132: The Collections API ADDREPLICA command property.name is not reflected+ in the clusterstate until after Solr restarts (Erick Erickson)+Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.javaindex f76e9143d9e..3647e7352cd 100644--- a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java+++ b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java@@ -2493,6 +2493,9 @@ public class OverseerCollectionProcessor implements Runnable, Closeable {String node = message.getStr("node");String shard = message.getStr(SHARD_ID_PROP);String coreName = message.getStr(CoreAdminParams.NAME);+ if (StringUtils.isBlank(coreName)) {+ coreName = message.getStr(CoreAdminParams.PROPERTY_PREFIX + CoreAdminParams.NAME);+ }final String asyncId = message.getStr(ASYNC);@@ -2507,7 +2510,6 @@ public class OverseerCollectionProcessor implements Runnable, Closeable {ShardHandler shardHandler = shardHandlerFactory.getShardHandler();if (node == null) {-node = getNodesForNewShard(clusterState, collection, shard, 1, null,overseer.getZkController().getCoreContainer()).get(0).nodeName;log.info("Node not provided, Identified {} for creating new replica", node);diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.javaindex 9d1cfd036f3..0af432335be 100644--- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java@@ -475,18 +475,18 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBaif (secondConfigSet) {createCmd.setCollectionConfigName("conf1");}-+makeRequest(getBaseUrl((HttpSolrClient) clients.get(1)), createCmd);// try and create a SolrCore with no collection namecreateCmd.setCollection(null);createCmd.setCoreName("corewithnocollection2");-+makeRequest(getBaseUrl((HttpSolrClient) clients.get(1)), createCmd);// in both cases, the collection should have default to the core namecloudClient.getZkStateReader().updateClusterState(true);- assertTrue( cloudClient.getZkStateReader().getClusterState().hasCollection("corewithnocollection"));+ assertTrue(cloudClient.getZkStateReader().getClusterState().hasCollection("corewithnocollection"));assertTrue(cloudClient.getZkStateReader().getClusterState().hasCollection("corewithnocollection2"));}@@ -1098,45 +1098,22 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBaString newReplicaName = Assign.assignNode(collectionName, client.getZkStateReader().getClusterState());ArrayList<String> nodeList = new ArrayList<>(client.getZkStateReader().getClusterState().getLiveNodes());Collections.shuffle(nodeList, random());- CollectionAdminRequest.AddReplica addReplica = new CollectionAdminRequest.AddReplica();- addReplica.setCollectionName(collectionName);- addReplica.setShardName("shard1");- addReplica.setNode(nodeList.get(0));- client.request(addReplica);-- long timeout = System.currentTimeMillis() + 3000;- Replica newReplica = null;-- for (; System.currentTimeMillis() < timeout; ) {- Slice slice = client.getZkStateReader().getClusterState().getSlice(collectionName, "shard1");- newReplica = slice.getReplica(newReplicaName);- }- assertNotNull(newReplica);+ Replica newReplica = doAddReplica(collectionName, "shard1",+ Assign.assignNode(collectionName, client.getZkStateReader().getClusterState()),+ nodeList.get(0), client, null);log.info("newReplica {},\n{} ", newReplica, client.getZkStateReader().getBaseUrlForNodeName(nodeList.get(0)));assertEquals("Replica should be created on the right node",client.getZkStateReader().getBaseUrlForNodeName(nodeList.get(0)), newReplica.getStr(ZkStateReader.BASE_URL_PROP));- newReplicaName = Assign.assignNode(collectionName, client.getZkStateReader().getClusterState());- addReplica = new CollectionAdminRequest.AddReplica();- addReplica.setCollectionName(collectionName);- addReplica.setShardName("shard2");Properties props = new Properties();String instancePathStr = createTempDir().toString();props.put(CoreAdminParams.INSTANCE_DIR, instancePathStr); //Use name via the property.instanceDir method- addReplica.setProperties(props);- client.request(addReplica);-- timeout = System.currentTimeMillis() + 3000;- newReplica = null;-- for (; System.currentTimeMillis() < timeout; ) {- Slice slice = client.getZkStateReader().getClusterState().getSlice(collectionName, "shard2");- newReplica = slice.getReplica(newReplicaName);- }-+ newReplica = doAddReplica(collectionName, "shard2",+ Assign.assignNode(collectionName, client.getZkStateReader().getClusterState()),+ null, client, props);assertNotNull(newReplica);HttpSolrClient coreclient = new HttpSolrClient(newReplica.getStr(ZkStateReader.BASE_URL_PROP));@@ -1160,9 +1137,44 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa} catch (SolrException e) {assertTrue(e.getMessage().contains("Another replica with the same core name already exists for this collection"));}+++ // Check that specifying property.name works. DO NOT remove this when the "name" property is deprecated+ // for ADDREPLICA, this is "property.name". See SOLR-7132+ props = new Properties();+ props.put(CoreAdminParams.NAME, "propertyDotName");++ newReplica = doAddReplica(collectionName, "shard1",+ Assign.assignNode(collectionName, client.getZkStateReader().getClusterState()),+ nodeList.get(0), client, props);+ assertEquals("'core' should be 'propertyDotName' ", "propertyDotName", newReplica.getStr("core"));}}+ private Replica doAddReplica(String collectionName, String shard, String newReplicaName, String node,+ CloudSolrClient client, Properties props) throws IOException, SolrServerException {+ CollectionAdminRequest.AddReplica addReplica = new CollectionAdminRequest.AddReplica();++ addReplica.setCollectionName(collectionName);+ addReplica.setShardName(shard);+ if (node != null) {+ addReplica.setNode(node);+ }+ if (props != null) {+ addReplica.setProperties(props);+ }+ client.request(addReplica);+ long timeout = System.currentTimeMillis() + 3000;+ Replica newReplica = null;++ for (; System.currentTimeMillis() < timeout; ) {+ Slice slice = client.getZkStateReader().getClusterState().getSlice(collectionName, shard);+ newReplica = slice.getReplica(newReplicaName);+ }++ assertNotNull(newReplica);+ return newReplica;+ }@Overrideprotected QueryResponse queryServer(ModifiableSolrParams params) throws SolrServerException, IOException {