Skip to content

Apache Lucene open-source search software

SOLR-12507: Modify collection API should support un-setting properties

Shalin Shekhar Mangarfabc408d3b67
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 62112ba28b4..ee85050de3e 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -84,6 +84,8 @@ New Features
* SOLR-11578: Solr 7 Admin UI (Cloud > Graph) should reflect the Replica type to give a more accurate representation
of the cluster. (Rhoit Singh via Erick Erickson)
+* SOLR-12507: Modify collection API should support un-setting properties. (shalin)
+
Bug Fixes
----------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/AddReplicaCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/AddReplicaCmd.java
index 83242ddac32..c07a85adb02 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/AddReplicaCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/AddReplicaCmd.java
@@ -52,7 +52,7 @@ import org.apache.solr.handler.component.ShardHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.apache.solr.cloud.api.collections.OverseerCollectionMessageHandler.COLL_CONF;
+import static org.apache.solr.common.params.CollectionAdminParams.COLL_CONF;
import static org.apache.solr.cloud.api.collections.OverseerCollectionMessageHandler.SKIP_CREATE_REPLICA_IN_CLUSTER_STATE;
import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_PROP;
import static org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP;
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/BackupCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/BackupCmd.java
index 7589c5570ca..c8e99dce4ce 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/BackupCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/BackupCmd.java
@@ -115,7 +115,7 @@ public class BackupCmd implements OverseerCollectionMessageHandler.Cmd {
properties.put(BackupManager.BACKUP_NAME_PROP, backupName);
properties.put(BackupManager.COLLECTION_NAME_PROP, collectionName);
- properties.put(OverseerCollectionMessageHandler.COLL_CONF, configName);
+ properties.put(CollectionAdminParams.COLL_CONF, configName);
properties.put(BackupManager.START_TIME_PROP, startTime.toString());
properties.put(BackupManager.INDEX_VERSION_PROP, Version.LATEST.toString());
//TODO: Add MD5 of the configset. If during restore the same name configset exists then we can compare checksums to see if they are the same.
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java
index a00de2b6e86..a776820817f 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java
@@ -73,7 +73,7 @@ import org.apache.zookeeper.KeeperException.NoNodeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.apache.solr.cloud.api.collections.OverseerCollectionMessageHandler.COLL_CONF;
+import static org.apache.solr.common.params.CollectionAdminParams.COLL_CONF;
import static org.apache.solr.common.cloud.ZkStateReader.MAX_SHARDS_PER_NODE;
import static org.apache.solr.common.cloud.ZkStateReader.NRT_REPLICAS;
import static org.apache.solr.common.cloud.ZkStateReader.PULL_REPLICAS;
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/MaintainRoutedAliasCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/MaintainRoutedAliasCmd.java
index d5edfa6bb2e..083571c00b6 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/MaintainRoutedAliasCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/MaintainRoutedAliasCmd.java
@@ -49,7 +49,7 @@ import org.apache.solr.util.DateMathParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.apache.solr.cloud.api.collections.OverseerCollectionMessageHandler.COLL_CONF;
+import static org.apache.solr.common.params.CollectionAdminParams.COLL_CONF;
import static org.apache.solr.cloud.api.collections.TimeRoutedAlias.CREATE_COLLECTION_PREFIX;
import static org.apache.solr.cloud.api.collections.TimeRoutedAlias.ROUTED_ALIAS_NAME_CORE_PROP;
import static org.apache.solr.common.params.CommonParams.NAME;
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/MigrateCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/MigrateCmd.java
index 4edc363a69e..882c7ef4107 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/MigrateCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/MigrateCmd.java
@@ -36,6 +36,7 @@ import org.apache.solr.common.cloud.RoutingRule;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.cloud.ZkNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
+import org.apache.solr.common.params.CollectionAdminParams;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
@@ -210,7 +211,7 @@ public class MigrateCmd implements OverseerCollectionMessageHandler.Cmd {
NAME, tempSourceCollectionName,
NRT_REPLICAS, 1,
OverseerCollectionMessageHandler.NUM_SLICES, 1,
- OverseerCollectionMessageHandler.COLL_CONF, configName,
+ CollectionAdminParams.COLL_CONF, configName,
OverseerCollectionMessageHandler.CREATE_NODE_SET, sourceLeader.getNodeName());
if (asyncId != null) {
String internalAsyncId = asyncId + Math.abs(System.nanoTime());
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerCollectionMessageHandler.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerCollectionMessageHandler.java
index fed92540b92..7f38c30523f 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerCollectionMessageHandler.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerCollectionMessageHandler.java
@@ -105,6 +105,7 @@ import static org.apache.solr.common.cloud.ZkStateReader.REJOIN_AT_HEAD_PROP;
import static org.apache.solr.common.cloud.ZkStateReader.REPLICA_PROP;
import static org.apache.solr.common.cloud.ZkStateReader.SHARD_ID_PROP;
import static org.apache.solr.common.params.CollectionAdminParams.COLLECTION;
+import static org.apache.solr.common.params.CollectionAdminParams.PROPERTY_UNSET;
import static org.apache.solr.common.params.CollectionParams.CollectionAction.*;
import static org.apache.solr.common.params.CommonAdminParams.ASYNC;
import static org.apache.solr.common.params.CommonParams.NAME;
@@ -129,8 +130,6 @@ public class OverseerCollectionMessageHandler implements OverseerMessageHandler,
public static final String REQUESTID = "requestid";
- public static final String COLL_CONF = "collection.configName";
-
public static final String COLL_PROP_PREFIX = "property.";
public static final String ONLY_IF_DOWN = "onlyIfDown";
@@ -141,7 +140,7 @@ public class OverseerCollectionMessageHandler implements OverseerMessageHandler,
static final String SKIP_CREATE_REPLICA_IN_CLUSTER_STATE = "skipCreateReplicaInClusterState";
- public static final Map<String, Object> COLL_PROPS = Collections.unmodifiableMap(makeMap(
+ public static final Map<String, Object> COLLECTION_PROPS_AND_DEFAULTS = Collections.unmodifiableMap(makeMap(
ROUTER, DocRouter.DEFAULT_NAME,
ZkStateReader.REPLICATION_FACTOR, "1",
ZkStateReader.NRT_REPLICAS, "1",
@@ -628,7 +627,7 @@ public class OverseerCollectionMessageHandler implements OverseerMessageHandler,
final String collectionName = message.getStr(ZkStateReader.COLLECTION_PROP);
//the rest of the processing is based on writing cluster state properties
//remove the property here to avoid any errors down the pipeline due to this property appearing
- String configName = (String) message.getProperties().remove(COLL_CONF);
+ String configName = (String) message.getProperties().remove(CollectionAdminParams.COLL_CONF);
if(configName != null) {
validateConfigOrThrowSolrException(configName);
@@ -638,7 +637,7 @@ public class OverseerCollectionMessageHandler implements OverseerMessageHandler,
reloadCollection(null, new ZkNodeProps(NAME, collectionName), results);
}
- overseer.getStateUpdateQueue(zkStateReader.getZkClient()).offer(Utils.toJSON(message));
+ Overseer.getStateUpdateQueue(zkStateReader.getZkClient()).offer(Utils.toJSON(message));
TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS, timeSource);
boolean areChangesVisible = true;
@@ -647,12 +646,19 @@ public class OverseerCollectionMessageHandler implements OverseerMessageHandler,
areChangesVisible = true;
for (Map.Entry<String,Object> updateEntry : message.getProperties().entrySet()) {
String updateKey = updateEntry.getKey();
+
if (!updateKey.equals(ZkStateReader.COLLECTION_PROP)
&& !updateKey.equals(Overseer.QUEUE_OPERATION)
+ && !updateKey.equals(PROPERTY_UNSET) // handled below in a separate conditional
&& !collection.get(updateKey).equals(updateEntry.getValue())){
areChangesVisible = false;
break;
}
+
+ if (updateKey.equals(PROPERTY_UNSET) && collection.containsKey((String) updateEntry.getValue())) {
+ areChangesVisible = false;
+ break;
+ }
}
if (areChangesVisible) break;
timeout.sleep(100);
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/RestoreCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/RestoreCmd.java
index 2b57111aa8f..d082ac337c5 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/RestoreCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/RestoreCmd.java
@@ -47,6 +47,7 @@ import org.apache.solr.common.cloud.ReplicaPosition;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.cloud.ZkNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
+import org.apache.solr.common.params.CollectionAdminParams;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
@@ -137,8 +138,8 @@ public class RestoreCmd implements OverseerCollectionMessageHandler.Cmd {
}
//Upload the configs
- String configName = (String) properties.get(OverseerCollectionMessageHandler.COLL_CONF);
- String restoreConfigName = message.getStr(OverseerCollectionMessageHandler.COLL_CONF, configName);
+ String configName = (String) properties.get(CollectionAdminParams.COLL_CONF);
+ String restoreConfigName = message.getStr(CollectionAdminParams.COLL_CONF, configName);
if (zkStateReader.getConfigManager().configExists(restoreConfigName)) {
log.info("Using existing config {}", restoreConfigName);
//TODO add overwrite option?
@@ -165,7 +166,7 @@ public class RestoreCmd implements OverseerCollectionMessageHandler.Cmd {
properties.put(MAX_SHARDS_PER_NODE, maxShardsPerNode);
// inherit settings from input API, defaulting to the backup's setting. Ex: replicationFactor
- for (String collProp : OverseerCollectionMessageHandler.COLL_PROPS.keySet()) {
+ for (String collProp : OverseerCollectionMessageHandler.COLLECTION_PROPS_AND_DEFAULTS.keySet()) {
Object val = message.getProperties().getOrDefault(collProp, backupCollectionState.get(collProp));
if (val != null && propMap.get(collProp) == null) {
propMap.put(collProp, val);
@@ -174,7 +175,7 @@ public class RestoreCmd implements OverseerCollectionMessageHandler.Cmd {
propMap.put(NAME, restoreCollectionName);
propMap.put(OverseerCollectionMessageHandler.CREATE_NODE_SET, OverseerCollectionMessageHandler.CREATE_NODE_SET_EMPTY); //no cores
- propMap.put(OverseerCollectionMessageHandler.COLL_CONF, restoreConfigName);
+ propMap.put(CollectionAdminParams.COLL_CONF, restoreConfigName);
// router.*
@SuppressWarnings("unchecked")
diff --git a/solr/core/src/java/org/apache/solr/cloud/overseer/ClusterStateMutator.java b/solr/core/src/java/org/apache/solr/cloud/overseer/ClusterStateMutator.java
index 7bbe9f1aad2..80f24454ce7 100644
--- a/solr/core/src/java/org/apache/solr/cloud/overseer/ClusterStateMutator.java
+++ b/solr/core/src/java/org/apache/solr/cloud/overseer/ClusterStateMutator.java
@@ -95,10 +95,10 @@ public class ClusterStateMutator {
Map<String, Object> collectionProps = new HashMap<>();
- for (Map.Entry<String, Object> e : OverseerCollectionMessageHandler.COLL_PROPS.entrySet()) {
+ for (Map.Entry<String, Object> e : OverseerCollectionMessageHandler.COLLECTION_PROPS_AND_DEFAULTS.entrySet()) {
Object val = message.get(e.getKey());
if (val == null) {
- val = OverseerCollectionMessageHandler.COLL_PROPS.get(e.getKey());
+ val = OverseerCollectionMessageHandler.COLLECTION_PROPS_AND_DEFAULTS.get(e.getKey());
}
if (val != null) collectionProps.put(e.getKey(), val);
}
diff --git a/solr/core/src/java/org/apache/solr/cloud/overseer/CollectionMutator.java b/solr/core/src/java/org/apache/solr/cloud/overseer/CollectionMutator.java
index 5ce537f96bb..609d3e53252 100644
--- a/solr/core/src/java/org/apache/solr/cloud/overseer/CollectionMutator.java
+++ b/solr/core/src/java/org/apache/solr/cloud/overseer/CollectionMutator.java
@@ -17,7 +17,6 @@
package org.apache.solr.cloud.overseer;
import java.lang.invoke.MethodHandles;
-
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -25,6 +24,7 @@ import java.util.Map;
import org.apache.solr.client.solrj.cloud.DistribStateManager;
import org.apache.solr.client.solrj.cloud.SolrCloudManager;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.common.cloud.ClusterState;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.ImplicitDocRouter;
@@ -33,13 +33,13 @@ import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.cloud.ZkNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.util.Utils;
-import org.apache.solr.handler.admin.CollectionsHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_PROP;
import static org.apache.solr.common.cloud.ZkStateReader.NRT_REPLICAS;
import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
+import static org.apache.solr.common.params.CollectionAdminParams.PROPERTY_UNSET;
import static org.apache.solr.common.params.CommonParams.NAME;
public class CollectionMutator {
@@ -102,27 +102,31 @@ public class CollectionMutator {
return new ZkWriteCommand(collection, newCollection);
}
- public ZkWriteCommand modifyCollection(final ClusterState clusterState, ZkNodeProps message){
+ public ZkWriteCommand modifyCollection(final ClusterState clusterState, ZkNodeProps message) {
if (!checkCollectionKeyExistence(message)) return ZkStateWriter.NO_OP;
DocCollection coll = clusterState.getCollection(message.getStr(COLLECTION_PROP));
Map<String, Object> m = coll.shallowCopy();
boolean hasAnyOps = false;
- for (String prop : CollectionsHandler.MODIFIABLE_COLL_PROPS) {
- if (message.get(prop) != null) {
+ for (String prop : CollectionAdminRequest.MODIFIABLE_COLLECTION_PROPERTIES) {
+ if (message.containsKey(prop)) {
hasAnyOps = true;
- m.put(prop,message.get(prop));
+ if (PROPERTY_UNSET.equals(prop)) {
+ m.remove(message.getStr(prop));
+ } else {
+ m.put(prop, message.get(prop));
+ }
if (prop == REPLICATION_FACTOR) { //SOLR-11676 : keep NRT_REPLICAS and REPLICATION_FACTOR in sync
m.put(NRT_REPLICAS, message.get(REPLICATION_FACTOR));
}
}
}
-
- if(!hasAnyOps) {
+
+ if (!hasAnyOps) {
return ZkStateWriter.NO_OP;
}
-
+
return new ZkWriteCommand(coll.getName(),
- new DocCollection(coll.getName(),coll.getSlicesMap(),m,coll.getRouter(),coll.getZNodeVersion(),coll.getZNode()));
+ new DocCollection(coll.getName(), coll.getSlicesMap(), m, coll.getRouter(), coll.getZNodeVersion(), coll.getZNode()));
}
public static DocCollection updateSlice(String collectionName, DocCollection collection, Slice slice) {
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java
index 556abba967b..da7308e6987 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java
@@ -41,6 +41,7 @@ import org.apache.solr.api.Api;
import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.CoreAdminRequest.RequestSyncShard;
import org.apache.solr.client.solrj.response.RequestStatusState;
import org.apache.solr.client.solrj.util.SolrIdentifierValidator;
@@ -103,7 +104,7 @@ import static org.apache.solr.client.solrj.response.RequestStatusState.NOT_FOUND
import static org.apache.solr.client.solrj.response.RequestStatusState.RUNNING;
import static org.apache.solr.client.solrj.response.RequestStatusState.SUBMITTED;
import static org.apache.solr.cloud.Overseer.QUEUE_OPERATION;
-import static org.apache.solr.cloud.api.collections.OverseerCollectionMessageHandler.COLL_CONF;
+import static org.apache.solr.common.params.CollectionAdminParams.COLL_CONF;
import static org.apache.solr.cloud.api.collections.OverseerCollectionMessageHandler.COLL_PROP_PREFIX;
import static org.apache.solr.cloud.api.collections.OverseerCollectionMessageHandler.CREATE_NODE_SET;
import static org.apache.solr.cloud.api.collections.OverseerCollectionMessageHandler.CREATE_NODE_SET_EMPTY;
@@ -915,13 +916,13 @@ public class CollectionsHandler extends RequestHandlerBase implements Permission
return null;
}),
MODIFYCOLLECTION_OP(MODIFYCOLLECTION, (req, rsp, h) -> {
- Map<String, Object> m = copy(req.getParams(), null, MODIFIABLE_COLL_PROPS);
+ Map<String, Object> m = copy(req.getParams(), null, CollectionAdminRequest.MODIFIABLE_COLLECTION_PROPERTIES);
if (m.isEmpty()) throw new SolrException(ErrorCode.BAD_REQUEST,
- formatString("no supported values provided rule, snitch, maxShardsPerNode, replicationFactor, collection.configName"));
+ formatString("no supported values provided %s", CollectionAdminRequest.MODIFIABLE_COLLECTION_PROPERTIES));
copy(req.getParams().required(), m, COLLECTION_PROP);
addMapObject(m, RULE);
addMapObject(m, SNITCH);
- for (String prop : MODIFIABLE_COLL_PROPS) DocCollection.verifyProp(m, prop);
+ for (String prop : CollectionAdminRequest.MODIFIABLE_COLLECTION_PROPERTIES) DocCollection.verifyProp(m, prop);
verifyRuleParams(h.coreContainer, m);
if (m.get(REPLICATION_FACTOR) != null) {
m.put(NRT_REPLICAS, m.get(REPLICATION_FACTOR));
@@ -1343,15 +1344,6 @@ public class CollectionsHandler extends RequestHandlerBase implements Permission
}
- public static final List<String> MODIFIABLE_COLL_PROPS = Arrays.asList(
- RULE,
- SNITCH,
- REPLICATION_FACTOR,
- MAX_SHARDS_PER_NODE,
- AUTO_ADD_REPLICAS,
- POLICY,
- COLL_CONF);
-
@Override
public Collection<Api> getApis() {
return v2Handler.getApis();
diff --git a/solr/core/src/test/org/apache/solr/cloud/OverseerTaskQueueTest.java b/solr/core/src/test/org/apache/solr/cloud/OverseerTaskQueueTest.java
index 9a86912d561..5f20d7d4acd 100644
--- a/solr/core/src/test/org/apache/solr/cloud/OverseerTaskQueueTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/OverseerTaskQueueTest.java
@@ -24,6 +24,7 @@ import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.client.solrj.response.SolrResponseBase;
import org.apache.solr.cloud.api.collections.OverseerCollectionMessageHandler;
import org.apache.solr.common.cloud.ZkStateReader;
+import org.apache.solr.common.params.CollectionAdminParams;
import org.apache.solr.common.params.CommonAdminParams;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.util.Utils;
@@ -51,7 +52,7 @@ public class OverseerTaskQueueTest extends DistributedQueueTest {
// Put an expected Overseer task onto the queue
final Map<String, Object> props = new HashMap<>();
props.put(CommonParams.NAME, "coll1");
- props.put(OverseerCollectionMessageHandler.COLL_CONF, "myconf");
+ props.put(CollectionAdminParams.COLL_CONF, "myconf");
props.put(OverseerCollectionMessageHandler.NUM_SLICES, 1);
props.put(ZkStateReader.REPLICATION_FACTOR, 3);
props.put(CommonAdminParams.ASYNC, requestId);
diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionAPI.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionAPI.java
index 40047f74a29..8a3eb81b28d 100644
--- a/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionAPI.java
+++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionAPI.java
@@ -96,6 +96,65 @@ public class TestCollectionAPI extends ReplicaPropertiesBase {
testCollectionCreationShardNameValidation();
testAliasCreationNameValidation();
testShardCreationNameValidation();
+ testModifyCollection(); // deletes replicationFactor property from collections, be careful adding new tests after this one!
+ }
+
+ private void testModifyCollection() throws Exception {
+ try (CloudSolrClient client = createCloudClient(null)) {
+ ModifiableSolrParams params = new ModifiableSolrParams();
+ params.set("action", CollectionParams.CollectionAction.MODIFYCOLLECTION.toString());
+ params.set("collection", COLLECTION_NAME);
+ params.set("replicationFactor", 25);
+ SolrRequest request = new QueryRequest(params);
+ request.setPath("/admin/collections");
+
+ client.request(request);
+ NamedList<Object> rsp = CollectionAdminRequest.getClusterStatus().setCollectionName(COLLECTION_NAME)
+ .process(client).getResponse();
+ NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
+ assertNotNull("Cluster state should not be null", cluster);
+ NamedList<Object> collections = (NamedList<Object>) cluster.get("collections");
+ assertNotNull("Collections should not be null in cluster state", collections);
+ assertEquals(1, collections.size());
+ Map<String, Object> collection = (Map<String, Object>) collections.get(COLLECTION_NAME);
+ int replicationFactor = Integer.parseInt(collection.get("replicationFactor").toString());
+ assertEquals(25, replicationFactor);
+
+ params = new ModifiableSolrParams();
+ params.set("action", CollectionParams.CollectionAction.MODIFYCOLLECTION.toString());
+ params.set("collection", COLLECTION_NAME);
+ params.set("property.unset", "replicationFactor");
+ request = new QueryRequest(params);
+ request.setPath("/admin/collections");
+
+ client.request(request);
+
+ rsp = CollectionAdminRequest.getClusterStatus().setCollectionName(COLLECTION_NAME)
+ .process(client).getResponse();
+ System.out.println(rsp);
+ cluster = (NamedList<Object>) rsp.get("cluster");
+ assertNotNull("Cluster state should not be null", cluster);
+ collections = (NamedList<Object>) cluster.get("collections");
+ assertNotNull("Collections should not be null in cluster state", collections);
+ assertEquals(1, collections.size());
+ collection = (Map<String, Object>) collections.get(COLLECTION_NAME);
+ assertNull(collection.get("replicationFactor"));
+
+ params = new ModifiableSolrParams();
+ params.set("action", CollectionParams.CollectionAction.MODIFYCOLLECTION.toString());
+ params.set("collection", COLLECTION_NAME);
+ params.set("property.unset", "non_existent_property");
+ request = new QueryRequest(params);
+ request.setPath("/admin/collections");
+
+ try {
+ client.request(request);
+ fail("Trying to unset an unknown property should have failed");
+ } catch (RemoteSolrException e) {
+ // expected
+ assertTrue(e.getMessage().contains("The value for property.unset must be one of"));
+ }
+ }
}
private void testReplicationFactorValidaton() throws Exception {
diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/TestHdfsCloudBackupRestore.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/TestHdfsCloudBackupRestore.java
index 85ed8a8a22c..1b2ed4cca88 100644
--- a/solr/core/src/test/org/apache/solr/cloud/api/collections/TestHdfsCloudBackupRestore.java
+++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/TestHdfsCloudBackupRestore.java
@@ -48,7 +48,7 @@ import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.apache.solr.cloud.api.collections.OverseerCollectionMessageHandler.COLL_CONF;
+import static org.apache.solr.common.params.CollectionAdminParams.COLL_CONF;
import static org.apache.solr.core.backup.BackupManager.BACKUP_NAME_PROP;
import static org.apache.solr.core.backup.BackupManager.BACKUP_PROPS_FILE;
import static org.apache.solr.core.backup.BackupManager.COLLECTION_NAME_PROP;
diff --git a/solr/core/src/test/org/apache/solr/cloud/cdcr/BaseCdcrDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/cdcr/BaseCdcrDistributedZkTest.java
index 4e4a2999aab..6858e916f4b 100644
--- a/solr/core/src/test/org/apache/solr/cloud/cdcr/BaseCdcrDistributedZkTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/cdcr/BaseCdcrDistributedZkTest.java
@@ -447,7 +447,7 @@ public class BaseCdcrDistributedZkTest extends AbstractDistribZkTestBase {
}
Integer replicationFactor = (Integer) collectionProps.get(REPLICATION_FACTOR);
if (replicationFactor == null) {
- replicationFactor = (Integer) OverseerCollectionMessageHandler.COLL_PROPS.get(REPLICATION_FACTOR);
+ replicationFactor = (Integer) OverseerCollectionMessageHandler.COLLECTION_PROPS_AND_DEFAULTS.get(REPLICATION_FACTOR);
}
if (confSetName != null) {
diff --git a/solr/solr-ref-guide/src/collections-api.adoc b/solr/solr-ref-guide/src/collections-api.adoc
index 3581ba76535..fd6e65b67ea 100644
--- a/solr/solr-ref-guide/src/collections-api.adoc
+++ b/solr/solr-ref-guide/src/collections-api.adoc
@@ -156,7 +156,7 @@ http://localhost:8983/solr/admin/collections?action=CREATE&name=newCollection&nu
[[modifycollection]]
== MODIFYCOLLECTION: Modify Attributes of a Collection
-`/admin/collections?action=MODIFYCOLLECTION&collection=_<collection-name>&<attribute-name>=<attribute-value>&<another-attribute-name>=<another-value>_`
+`/admin/collections?action=MODIFYCOLLECTION&collection=_<collection-name>&<attribute-name>=<attribute-value>&<another-attribute-name>=<another-value>_&property.unset=<yet_another_attribute_name>`
It's possible to edit multiple attributes at a time. Changing these values only updates the z-node on ZooKeeper, they do not change the topology of the collection. For instance, increasing `replicationFactor` will _not_ automatically add more replicas to the collection but _will_ allow more ADDREPLICA commands to succeed.
@@ -166,8 +166,13 @@ It's possible to edit multiple attributes at a time. Changing these values only
The name of the collection to be modified. This parameter is required.
`_attribute_=_value_`::
-Key-value pairs of attribute names and attribute values. At least one of these is required.
+Key-value pairs of attribute names and attribute values.
+
+`property.unset=_attribute_`::
+Unsets (or deletes) the given attribute from the collection.
+
+At least one of either `_attribute_` or `property.unset` parameters is required.
+
The attributes that can be modified are:
* maxShardsPerNode
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
index 78c21b32077..01f3928cb91 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java
@@ -17,6 +17,7 @@
package org.apache.solr.client.solrj.request;
import java.io.IOException;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -52,9 +53,16 @@ import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import static org.apache.solr.client.solrj.cloud.autoscaling.Policy.POLICY;
+import static org.apache.solr.common.cloud.DocCollection.RULE;
+import static org.apache.solr.common.cloud.DocCollection.SNITCH;
+import static org.apache.solr.common.cloud.ZkStateReader.AUTO_ADD_REPLICAS;
+import static org.apache.solr.common.cloud.ZkStateReader.MAX_SHARDS_PER_NODE;
+import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
+import static org.apache.solr.common.params.CollectionAdminParams.COLL_CONF;
import static org.apache.solr.common.params.CollectionAdminParams.COUNT_PROP;
import static org.apache.solr.common.params.CollectionAdminParams.CREATE_NODE_SET_PARAM;
import static org.apache.solr.common.params.CollectionAdminParams.CREATE_NODE_SET_SHUFFLE_PARAM;
+import static org.apache.solr.common.params.CollectionAdminParams.PROPERTY_UNSET;
/**
* This class is experimental and subject to change.
@@ -63,6 +71,19 @@ import static org.apache.solr.common.params.CollectionAdminParams.CREATE_NODE_SE
*/
public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> extends SolrRequest<T> implements V2RequestSupport, MapWriter {
+ /**
+ * The set of modifiable collection properties
+ */
+ public static final java.util.List<String> MODIFIABLE_COLLECTION_PROPERTIES = Arrays.asList(
+ RULE,
+ SNITCH,
+ REPLICATION_FACTOR,
+ MAX_SHARDS_PER_NODE,
+ AUTO_ADD_REPLICAS,
+ POLICY,
+ COLL_CONF,
+ PROPERTY_UNSET);
+
protected final CollectionAction action;
private static String PROPERTY_PREFIX = "property.";
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java b/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java
index 4c12d9c639b..992d8342d7c 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java
@@ -34,12 +34,14 @@ import org.apache.solr.common.SolrException.ErrorCode;
import org.noggit.JSONUtil;
import org.noggit.JSONWriter;
+import static org.apache.solr.client.solrj.request.CollectionAdminRequest.MODIFIABLE_COLLECTION_PROPERTIES;
import static org.apache.solr.common.cloud.ZkStateReader.AUTO_ADD_REPLICAS;
import static org.apache.solr.common.cloud.ZkStateReader.MAX_SHARDS_PER_NODE;
import static org.apache.solr.common.cloud.ZkStateReader.NRT_REPLICAS;
import static org.apache.solr.common.cloud.ZkStateReader.PULL_REPLICAS;
import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
import static org.apache.solr.common.cloud.ZkStateReader.TLOG_REPLICAS;
+import static org.apache.solr.common.params.CollectionAdminParams.PROPERTY_UNSET;
/**
* Models a Collection in zookeeper (but that Java name is obviously taken, hence "DocCollection")
@@ -149,6 +151,10 @@ public class DocCollection extends ZkNodeProps implements Iterable<Slice> {
case "snitch":
case "rule":
return (List) o;
+ case PROPERTY_UNSET:
+ if (!MODIFIABLE_COLLECTION_PROPERTIES.contains(o.toString())) {
+ throw new IllegalArgumentException("The value for " + PROPERTY_UNSET + " must be one of: " + MODIFIABLE_COLLECTION_PROPERTIES);
+ }
default:
return o;
}
diff --git a/solr/solrj/src/java/org/apache/solr/common/params/CollectionAdminParams.java b/solr/solrj/src/java/org/apache/solr/common/params/CollectionAdminParams.java
index cdd9458592f..307e2215f54 100644
--- a/solr/solrj/src/java/org/apache/solr/common/params/CollectionAdminParams.java
+++ b/solr/solrj/src/java/org/apache/solr/common/params/CollectionAdminParams.java
@@ -74,4 +74,14 @@ public interface CollectionAdminParams {
* Value of collection property to set
*/
public static final String PROPERTY_VALUE = "propertyValue";
+
+ /**
+ * Parameter used by the Modify Collection API to remove values
+ */
+ public static final String PROPERTY_UNSET = "property.unset";
+
+ /**
+ * The name of the config set to be used for a collection
+ */
+ public static final String COLL_CONF = "collection.configName";
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
index c92329c80a0..fc645c7d19f 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
@@ -1633,7 +1633,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
numNrtReplicas = (Integer) collectionProps.get(ZkStateReader.REPLICATION_FACTOR);
}
if(numNrtReplicas == null){
- numNrtReplicas = (Integer) OverseerCollectionMessageHandler.COLL_PROPS.get(ZkStateReader.REPLICATION_FACTOR);
+ numNrtReplicas = (Integer) OverseerCollectionMessageHandler.COLLECTION_PROPS_AND_DEFAULTS.get(ZkStateReader.REPLICATION_FACTOR);
}
if (numNrtReplicas == null) {
numNrtReplicas = Integer.valueOf(0);