Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-17024: Remove deprecated 'collectionDefaults' support (#2002)

Jason Gerlowski22271d73c8cb
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index a10005c443c..dc634381da6 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -96,7 +96,7 @@ Dependency Upgrades
Other Changes
---------------------
-(No changes)
+* SOLR-17024: Remove support for the long-defunct "collectionDefaults" clusterprops key (Jason Gerlowski)
================== 9.4.0 ==================
New Features
diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java
index 30d9339d50c..4877b27aee6 100644
--- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java
@@ -17,7 +17,6 @@
package org.apache.solr.cloud;
import static java.util.Arrays.asList;
-import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_DEF;
import static org.apache.solr.common.cloud.ZkStateReader.NRT_REPLICAS;
import static org.apache.solr.common.cloud.ZkStateReader.NUM_SHARDS_PROP;
import static org.apache.solr.common.params.CollectionAdminParams.COLLECTION;
@@ -127,114 +126,6 @@ public class CollectionsAPISolrJTest extends SolrCloudTestCase {
(n, c) -> c == null);
}
- @Test
- public void testCreateCollWithDefaultClusterPropertiesOldFormat() throws Exception {
- String COLL_NAME = "CollWithDefaultClusterProperties";
- try {
- V2Response rsp =
- new V2Request.Builder("/cluster")
- .withMethod(SolrRequest.METHOD.POST)
- .withPayload(
- "{set-obj-property:{collectionDefaults:{numShards : 2 , nrtReplicas : 2}}}")
- .build()
- .process(cluster.getSolrClient());
-
- for (int i = 0; i < 300; i++) {
- Map<?, ?> m = cluster.getZkStateReader().getClusterProperty(COLLECTION_DEF, null);
- if (m != null) break;
- Thread.sleep(10);
- }
- Object clusterProperty =
- cluster
- .getZkStateReader()
- .getClusterProperty(List.of(DEFAULTS, COLLECTION, NUM_SHARDS_PROP), null);
- assertEquals("2", String.valueOf(clusterProperty));
- clusterProperty =
- cluster
- .getZkStateReader()
- .getClusterProperty(List.of(DEFAULTS, COLLECTION, NRT_REPLICAS), null);
- assertEquals("2", String.valueOf(clusterProperty));
- CollectionAdminResponse response =
- CollectionAdminRequest.createCollection(COLL_NAME, "conf", null, null, null, null)
- .process(cluster.getSolrClient());
- assertEquals(0, response.getStatus());
- assertTrue(response.isSuccess());
-
- cluster.waitForActiveCollection(COLL_NAME, 2, 4);
-
- DocCollection coll = cluster.getSolrClient().getClusterState().getCollection(COLL_NAME);
- Map<String, Slice> slices = coll.getSlicesMap();
- assertEquals(2, slices.size());
- for (Slice slice : slices.values()) {
- assertEquals(2, slice.getReplicas().size());
- }
- CollectionAdminRequest.deleteCollection(COLL_NAME).process(cluster.getSolrClient());
-
- // unset only a single value using old format
- rsp =
- new V2Request.Builder("/cluster")
- .withMethod(SolrRequest.METHOD.POST)
- .withPayload(
- "{\n"
- + " \"set-obj-property\": {\n"
- + " \"collectionDefaults\": {\n"
- + " \"nrtReplicas\": null\n"
- + " }\n"
- + " }\n"
- + "}")
- .build()
- .process(cluster.getSolrClient());
- // assert that it is really gone in both old and new paths
- // we use a timeout so that the change made in ZK is reflected in the watched copy inside
- // ZkStateReader
- TimeOut timeOut = new TimeOut(5, TimeUnit.SECONDS, new TimeSource.NanoTimeSource());
- while (!timeOut.hasTimedOut()) {
- clusterProperty =
- cluster
- .getZkStateReader()
- .getClusterProperty(List.of(DEFAULTS, COLLECTION, NRT_REPLICAS), null);
- if (clusterProperty == null) break;
- }
- assertNull(clusterProperty);
- clusterProperty =
- cluster
- .getZkStateReader()
- .getClusterProperty(List.of(COLLECTION_DEF, NRT_REPLICAS), null);
- assertNull(clusterProperty);
-
- // delete all defaults the old way
- rsp =
- new V2Request.Builder("/cluster")
- .withMethod(SolrRequest.METHOD.POST)
- .withPayload("{set-obj-property:{collectionDefaults:null}}")
- .build()
- .process(cluster.getSolrClient());
- // assert that it is really gone in both old and new paths
- timeOut = new TimeOut(5, TimeUnit.SECONDS, new TimeSource.NanoTimeSource());
- while (!timeOut.hasTimedOut()) {
- clusterProperty =
- cluster
- .getZkStateReader()
- .getClusterProperty(List.of(DEFAULTS, COLLECTION, NUM_SHARDS_PROP), null);
- if (clusterProperty == null) break;
- }
- assertNull(clusterProperty);
- clusterProperty =
- cluster
- .getZkStateReader()
- .getClusterProperty(List.of(COLLECTION_DEF, NUM_SHARDS_PROP), null);
- assertNull(clusterProperty);
- } finally {
- // clean up in case there was an exception during the test
- V2Response rsp =
- new V2Request.Builder("/cluster")
- .withMethod(SolrRequest.METHOD.POST)
- .withPayload("{set-obj-property:{collectionDefaults: null}}")
- .build()
- .process(cluster.getSolrClient());
- }
- }
-
@Test
public void testCreateCollWithDefaultClusterPropertiesNewFormat() throws Exception {
String COLL_NAME = "CollWithDefaultClusterProperties";
@@ -248,7 +139,7 @@ public class CollectionsAPISolrJTest extends SolrCloudTestCase {
.process(cluster.getSolrClient());
for (int i = 0; i < 300; i++) {
- Map<?, ?> m = cluster.getZkStateReader().getClusterProperty(COLLECTION_DEF, null);
+ Map<?, ?> m = cluster.getZkStateReader().getClusterProperty(DEFAULTS, null);
if (m != null) break;
Thread.sleep(10);
}
@@ -322,11 +213,6 @@ public class CollectionsAPISolrJTest extends SolrCloudTestCase {
if (clusterProperty == null) break;
}
assertNull(clusterProperty);
- clusterProperty =
- cluster
- .getZkStateReader()
- .getClusterProperty(List.of(COLLECTION_DEF, NUM_SHARDS_PROP), null);
- assertNull(clusterProperty);
} finally {
V2Response rsp =
new V2Request.Builder("/cluster")
diff --git a/solr/core/src/test/org/apache/solr/util/TestUtils.java b/solr/core/src/test/org/apache/solr/util/TestUtils.java
index 949c2dc15fe..e05f3130360 100644
--- a/solr/core/src/test/org/apache/solr/util/TestUtils.java
+++ b/solr/core/src/test/org/apache/solr/util/TestUtils.java
@@ -18,9 +18,10 @@ package org.apache.solr.util;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.asList;
-import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_DEF;
+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.NUM_SHARDS_PROP;
+import static org.apache.solr.common.params.CollectionAdminParams.DEFAULTS;
import static org.apache.solr.common.util.Utils.fromJSONString;
import java.io.ByteArrayOutputStream;
@@ -287,8 +288,10 @@ public class TestUtils extends SolrTestCaseJ4 {
Utils.mergeJson(
sink,
(Map<String, Object>)
- Utils.fromJSONString("collectionDefaults:{numShards:3 , nrtReplicas:2}")));
- assertEquals(3L, Utils.getObjectByPath(sink, true, List.of(COLLECTION_DEF, NUM_SHARDS_PROP)));
- assertEquals(2L, Utils.getObjectByPath(sink, true, List.of(COLLECTION_DEF, NRT_REPLICAS)));
+ Utils.fromJSONString("defaults: {collection: {numShards:3 , nrtReplicas:2}}")));
+ assertEquals(
+ 3L, Utils.getObjectByPath(sink, true, List.of(DEFAULTS, COLLECTION_PROP, NUM_SHARDS_PROP)));
+ assertEquals(
+ 2L, Utils.getObjectByPath(sink, true, List.of(DEFAULTS, COLLECTION_PROP, NRT_REPLICAS)));
}
}
diff --git a/solr/solr-ref-guide/modules/deployment-guide/pages/cluster-node-management.adoc b/solr/solr-ref-guide/modules/deployment-guide/pages/cluster-node-management.adoc
index 117d066add4..4e5e02430ca 100644
--- a/solr/solr-ref-guide/modules/deployment-guide/pages/cluster-node-management.adoc
+++ b/solr/solr-ref-guide/modules/deployment-guide/pages/cluster-node-management.adoc
@@ -335,12 +335,6 @@ curl -X POST -H 'Content-type:application/json' --data-binary '
}' http://localhost:8983/api/cluster
----
-NOTE: Until Solr 7.5, cluster properties supported a `collectionDefaults` key which is now deprecated and
-replaced with `defaults`.
-Using the `collectionDefaults` parameter in Solr 7.4 or 7.5 will continue to work
- but the format of the properties will automatically be converted to the new nested structure.
-Support for the "collectionDefaults" key will be removed in Solr 9.
-
=== Default Shard Preferences
Using the `defaultShardPreferences` parameter, you can implement rack or availability zone awareness.
diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ClusterProperties.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ClusterProperties.java
index 84e5cf462e4..38e9e046266 100644
--- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ClusterProperties.java
+++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ClusterProperties.java
@@ -17,8 +17,6 @@
package org.apache.solr.common.cloud;
-import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_DEF;
-
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
@@ -28,7 +26,6 @@ import java.util.List;
import java.util.Map;
import org.apache.solr.common.MapWriter;
import org.apache.solr.common.SolrException;
-import org.apache.solr.common.params.CollectionAdminParams;
import org.apache.solr.common.util.Utils;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
@@ -98,7 +95,7 @@ public class ClusterProperties {
Map<String, Object> properties =
(Map<String, Object>)
Utils.fromJSON(client.getData(ZkStateReader.CLUSTER_PROPS, null, new Stat(), true));
- return convertCollectionDefaultsToNestedFormat(properties);
+ return properties;
} catch (KeeperException.NoNodeException e) {
return Collections.emptyMap();
} catch (KeeperException | InterruptedException e) {
@@ -111,13 +108,10 @@ public class ClusterProperties {
client.atomicUpdate(
ZkStateReader.CLUSTER_PROPS,
zkData -> {
- if (zkData == null)
- return Utils.toJSON(convertCollectionDefaultsToNestedFormat(properties));
+ if (zkData == null) return Utils.toJSON(properties);
@SuppressWarnings({"unchecked"})
Map<String, Object> zkJson = (Map<String, Object>) Utils.fromJSON(zkData);
- zkJson = convertCollectionDefaultsToNestedFormat(zkJson);
- boolean modified =
- Utils.mergeJson(zkJson, convertCollectionDefaultsToNestedFormat(properties));
+ boolean modified = Utils.mergeJson(zkJson, properties);
return modified ? Utils.toJSON(zkJson) : null;
});
}
@@ -145,43 +139,6 @@ public class ClusterProperties {
});
}
- /**
- * See SOLR-12827 for background. We auto convert any "collectionDefaults" keys to
- * "defaults/collection" format. This method will modify the given map and return the same object.
- * Remove this method in Solr 9.
- *
- * @param properties the properties to be converted
- * @return the converted map
- */
- @SuppressWarnings({"unchecked"})
- static Map<String, Object> convertCollectionDefaultsToNestedFormat(
- Map<String, Object> properties) {
- if (properties.containsKey(COLLECTION_DEF)) {
- Map<String, Object> values = (Map<String, Object>) properties.remove(COLLECTION_DEF);
- if (values != null) {
- properties.putIfAbsent(CollectionAdminParams.DEFAULTS, new LinkedHashMap<>());
- Map<String, Object> defaults =
- (Map<String, Object>) properties.get(CollectionAdminParams.DEFAULTS);
- defaults.compute(
- CollectionAdminParams.COLLECTION,
- (k, v) -> {
- if (v == null) return values;
- else {
- ((Map) v).putAll(values);
- return v;
- }
- });
- } else {
- // explicitly set to null, so set null in the nested format as well
- properties.putIfAbsent(CollectionAdminParams.DEFAULTS, new LinkedHashMap<>());
- Map<String, Object> defaults =
- (Map<String, Object>) properties.get(CollectionAdminParams.DEFAULTS);
- defaults.put(CollectionAdminParams.COLLECTION, null);
- }
- }
- return properties;
- }
-
/**
* This method sets a cluster property.
*
diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkStateReader.java
index f6b736620ae..d6904d5bfcd 100644
--- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkStateReader.java
+++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkStateReader.java
@@ -141,11 +141,6 @@ public class ZkStateReader implements SolrCloseable {
public static final String CONFIGS_ZKNODE = "/configs";
public static final String CONFIGNAME_PROP = "configName";
- /**
- * @deprecated use {@link org.apache.solr.common.params.CollectionAdminParams#DEFAULTS} instead.
- */
- @Deprecated public static final String COLLECTION_DEF = "collectionDefaults";
-
public static final String URL_SCHEME = "urlScheme";
public static final String HTTP = "http";
public static final String HTTPS = "https";
@@ -1136,6 +1131,7 @@ public class ZkStateReader implements SolrCloseable {
loadClusterProperties();
};
+ @SuppressWarnings("unchecked")
private void loadClusterProperties() {
try {
while (true) {
@@ -1143,10 +1139,7 @@ public class ZkStateReader implements SolrCloseable {
byte[] data =
zkClient.getData(
ZkStateReader.CLUSTER_PROPS, clusterPropertiesWatcher, new Stat(), true);
- @SuppressWarnings("unchecked")
- Map<String, Object> properties = (Map<String, Object>) Utils.fromJSON(data);
- this.clusterProperties =
- ClusterProperties.convertCollectionDefaultsToNestedFormat(properties);
+ this.clusterProperties = (Map<String, Object>) Utils.fromJSON(data);
log.debug("Loaded cluster properties: {}", this.clusterProperties);
for (ClusterPropertiesListener listener : clusterPropertiesListeners) {