Apache Solr open-source search software
SOLR-7499: Deprecate the 'name' parameter from the ADDREPLICA Collection API call
Varun Thackerf7dd8e3805a8
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 5dbe8eee0cd..0af7fdb958e 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -100,6 +100,9 @@ Upgrading from Solr 5.2* class TransformerWithContext is deprecated . Use DocTransformer directly+* The "name" parameter in ADDREPLICA Collections API call has be deprecated. One cannot specify+ the core name for a replica. See SOLR-7499 for more info.+Detailed Change List----------------------@@ -232,6 +235,9 @@ Other Changes* SOLR-7629: Have RulesTest consider disk space limitations of where the test isbeing run (Christine Poerschke via Ramkumar Aiyengar)+* The "name" parameter in ADDREPLICA Collections API call has be deprecated. One cannot specify+ the core name for a replica. See SOLR-7499 for more info. (Varun Thacker, noble, Erick Erickson)+================== 5.2.1 ==================Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this releasediff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.javaindex fb9c2af63a4..4df04ede8cc 100644--- a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java+++ b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java@@ -2520,7 +2520,7 @@ public class OverseerCollectionProcessor implements Runnable, Closeable {String replicaName = collection + "_" + shard + "_replica" + replicaNum;boolean exists = false;for (Replica replica : slice.getReplicas()) {- if (replicaName.equals(replica.getStr("core"))) {+ if (replicaName.equals(replica.getStr(CORE_NAME_PROP))) {exists = true;break;}@@ -2529,6 +2529,17 @@ public class OverseerCollectionProcessor implements Runnable, Closeable {else break;}coreName = collection + "_" + shard + "_replica" + replicaNum;+ } else {+ //Validate that the core name is unique in that collection+ for (Slice slice : coll.getSlices()) {+ for (Replica replica : slice.getReplicas()) {+ String replicaCoreName = replica.getStr(CORE_NAME_PROP);+ if (coreName.equals(replicaCoreName)) {+ throw new SolrException(ErrorCode.BAD_REQUEST, "Another replica with the same core name already exists" ++ " for this collection");+ }+ }+ }}ModifiableSolrParams params = new ModifiableSolrParams();diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.javaindex 2bdc29448c6..9d1cfd036f3 100644--- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java@@ -84,6 +84,7 @@ import org.junit.Test;import static org.apache.solr.cloud.OverseerCollectionProcessor.NUM_SLICES;import static org.apache.solr.common.cloud.ZkNodeProps.makeMap;+import static org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP;import static org.apache.solr.common.cloud.ZkStateReader.MAX_SHARDS_PER_NODE;import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;@@ -1143,8 +1144,23 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBaNamedList<Object> coreStatus = status.getCoreStatus(newReplica.getStr("core"));String instanceDirStr = (String) coreStatus.get("instanceDir");assertEquals(Paths.get(instanceDirStr).toString(), instancePathStr);- }+ //Test to make sure we can't create another replica with an existing core_name of that collection+ String coreName = newReplica.getStr(CORE_NAME_PROP);+ ModifiableSolrParams params = new ModifiableSolrParams();+ params.set("action", "addreplica");+ params.set("collection", collectionName);+ params.set("shard", "shard1");+ params.set("name", coreName);+ QueryRequest request = new QueryRequest(params);+ request.setPath("/admin/collections");+ try {+ client.request(request);+ fail("AddReplica call should not have been successful");+ } catch (SolrException e) {+ assertTrue(e.getMessage().contains("Another replica with the same core name already exists for this collection"));+ }+ }}@Override