Apache Solr open-source search software
SOLR-14035: Remove deprecated preferLocalShards=true support in favour of the shards.preference=replica.location:local alternative. (Alex Bulygin via Christine Poerschke)
Christine Poerschkec4d4767bca19
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 7b470931c6f..a9b2514e4fb 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -153,6 +153,9 @@ Other Changes* SOLR-14949: Ability to customize docker image name/base image (Houston Putman)+* SOLR-14035: Remove deprecated preferLocalShards=true support in favour of the shards.preference=replica.location:local alternative.+ (Alex Bulygin via Christine Poerschke)+Bug Fixes---------------------* SOLR-14546: Fix for a relatively hard to hit issue in OverseerTaskProcessor that could lead to out of order executiondiff --git a/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml b/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xmlindex ed00a3a9899..8fea9ca8d49 100644--- a/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml+++ b/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml@@ -757,7 +757,6 @@<lst name="defaults"><str name="echoParams">explicit</str><int name="rows">10</int>- <bool name="preferLocalShards">false</bool></lst><!-- "appends" example to ensure only products in stock are returned when using this Search Handler --><!--diff --git a/solr/solr-ref-guide/src/common-query-parameters.adoc b/solr/solr-ref-guide/src/common-query-parameters.adocindex 8f12c431d08..64b8d2aefbb 100644--- a/solr/solr-ref-guide/src/common-query-parameters.adoc+++ b/solr/solr-ref-guide/src/common-query-parameters.adoc@@ -347,7 +347,6 @@ This is what happens if a similar request is sent that adds `echoParams=all` to"params": {"q": "solr","df": "text",- "preferLocalShards": "false","indent": "true","echoParams": "all","rows": "10",diff --git a/solr/solr-ref-guide/src/config-api.adoc b/solr/solr-ref-guide/src/config-api.adocindex 529d2719ab4..0235a5e2111 100644--- a/solr/solr-ref-guide/src/config-api.adoc+++ b/solr/solr-ref-guide/src/config-api.adoc@@ -126,8 +126,7 @@ The output of this command will look similar to:"class": "solr.SearchHandler","defaults":{"echoParams": "explicit",- "rows":10,- "preferLocalShards":false+ "rows":10}}}}}----diff --git a/solr/solr-ref-guide/src/distributed-requests.adoc b/solr/solr-ref-guide/src/distributed-requests.adocindex e916537bb48..52c2d89bcd8 100644--- a/solr/solr-ref-guide/src/distributed-requests.adoc+++ b/solr/solr-ref-guide/src/distributed-requests.adoc@@ -150,10 +150,6 @@ Each shard serves top-level query requests and then makes sub-requests to all ofFor example, a deadlock might occur in the case of two shards, each with just a single thread to service HTTP requests. Both threads could receive a top-level request concurrently, and make sub-requests to each other. Because there are no more remaining threads to service requests, the incoming requests will be blocked until the other pending requests are finished, but they will not finish since they are waiting for the sub-requests. By ensuring that Solr is configured to handle a sufficient number of threads, you can avoid deadlock situations like this.-== preferLocalShards Parameter--Deprecated, use `shards.preference=replica.location:local` instead (see below).-== shards.preference ParameterSolr allows you to pass an optional string parameter named `shards.preference` to indicate that a distributed query should sort the available replicas in the given order of precedence within each shard.diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/routing/RequestReplicaListTransformerGenerator.java b/solr/solrj/src/java/org/apache/solr/client/solrj/routing/RequestReplicaListTransformerGenerator.javaindex a6bd477fae8..12883722a1f 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/routing/RequestReplicaListTransformerGenerator.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/routing/RequestReplicaListTransformerGenerator.java@@ -26,7 +26,6 @@ import java.util.Random;import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrException.ErrorCode;import org.apache.solr.common.cloud.NodesSysPropsCacher;-import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.params.ShardParams;import org.apache.solr.common.params.SolrParams;import org.slf4j.Logger;@@ -81,23 +80,11 @@ public class RequestReplicaListTransformerGenerator {}public ReplicaListTransformer getReplicaListTransformer(final SolrParams requestParams, String defaultShardPreferences, String nodeName, String localHostAddress, NodesSysPropsCacher sysPropsCacher) {- @SuppressWarnings("deprecation")- final boolean preferLocalShards = requestParams.getBool(CommonParams.PREFER_LOCAL_SHARDS, false);defaultShardPreferences = Objects.requireNonNullElse(defaultShardPreferences, this.defaultShardPreferences);final String shardsPreferenceSpec = requestParams.get(ShardParams.SHARDS_PREFERENCE, defaultShardPreferences);- if (preferLocalShards || !shardsPreferenceSpec.isEmpty()) {- if (preferLocalShards && !shardsPreferenceSpec.isEmpty()) {- throw new SolrException(- ErrorCode.BAD_REQUEST,- "preferLocalShards is deprecated and must not be used with shards.preference"- );- }+ if (!shardsPreferenceSpec.isEmpty()) {List<PreferenceRule> preferenceRules = PreferenceRule.from(shardsPreferenceSpec);- if (preferLocalShards) {- preferenceRules.add(new PreferenceRule(ShardParams.SHARDS_PREFERENCE_REPLICA_LOCATION, ShardParams.REPLICA_LOCAL));- }-NodePreferenceRulesComparator replicaComp =new NodePreferenceRulesComparator(preferenceRules,diff --git a/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java b/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.javaindex 0a18e604f40..144622cb901 100644--- a/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java+++ b/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java@@ -278,13 +278,6 @@ public interface CommonParams {*/String REQUEST_PURPOSE = "requestPurpose";- /**- * When querying a node, prefer local node's cores for distributed queries.- * @deprecated Use {@code ShardParams.SHARDS_PREFERENCE}- */- @Deprecated // SOLR-14035- String PREFER_LOCAL_SHARDS = "preferLocalShards";-String JAVABIN = "javabin";String JSON = "json";diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.javaindex 1696d2c515c..8185e46c99b 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java@@ -413,18 +413,18 @@ public class CloudHttp2SolrClientTest extends SolrCloudTestCase {}/**- * Tests if the specification of 'preferLocalShards' in the query-params+ * Tests if the specification of 'shards.preference=replica.location:local' in the query-params* limits the distributed query to locally hosted shards only*/@Test// commented 4-Sep-2018 @LuceneTestCase.BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 2-Aug-2018- public void preferLocalShardsTest() throws Exception {+ public void queryWithLocalShardsPreferenceRulesTest() throws Exception {String collectionName = "localShardsTestColl";int liveNodes = cluster.getJettySolrRunners().size();- // For preferLocalShards to succeed in a test, every shard should have+ // For this case every shard should have// all its cores on the same node.// Hence the below configuration for our collectionCollectionAdminRequest.createCollection(collectionName, "conf", liveNodes, liveNodes)@@ -437,25 +437,17 @@ public class CloudHttp2SolrClientTest extends SolrCloudTestCase {.add(id, "3", "a_t", "hello2").commit(getRandomClient(), collectionName);- // Run the actual test for 'preferLocalShards'- queryWithShardsPreferenceRules(getRandomClient(), false, collectionName);- queryWithShardsPreferenceRules(getRandomClient(), true, collectionName);+ queryWithShardsPreferenceRules(getRandomClient(), collectionName);}@SuppressWarnings("deprecation")private void queryWithShardsPreferenceRules(CloudHttp2SolrClient cloudClient,- boolean useShardsPreference,- String collectionName)- throws Exception+ String collectionName) throws Exception{SolrQuery qRequest = new SolrQuery("*:*");ModifiableSolrParams qParams = new ModifiableSolrParams();- if (useShardsPreference) {- qParams.add(ShardParams.SHARDS_PREFERENCE, ShardParams.SHARDS_PREFERENCE_REPLICA_LOCATION + ":" + ShardParams.REPLICA_LOCAL);- } else {- qParams.add(CommonParams.PREFER_LOCAL_SHARDS, "true");- }+ qParams.add(ShardParams.SHARDS_PREFERENCE, ShardParams.SHARDS_PREFERENCE_REPLICA_LOCATION + ":" + ShardParams.REPLICA_LOCAL);qParams.add(ShardParams.SHARDS_INFO, "true");qRequest.add(qParams);@@ -985,26 +977,18 @@ public class CloudHttp2SolrClientTest extends SolrCloudTestCase {.commit(getRandomClient(), collectionName);// Run the actual tests for 'shards.preference=replica.type:*'- queryWithPreferReplicaTypes(getRandomClient(), "PULL", false, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "PULL|TLOG", false, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "TLOG", false, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "TLOG|PULL", false, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "NRT", false, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "NRT|PULL", false, collectionName);- // Test to verify that preferLocalShards=true doesn't break this- queryWithPreferReplicaTypes(getRandomClient(), "PULL", true, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "PULL|TLOG", true, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "TLOG", true, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "TLOG|PULL", true, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "NRT", false, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "NRT|PULL", true, collectionName);+ queryWithPreferReplicaTypes(getRandomClient(), "PULL", collectionName);+ queryWithPreferReplicaTypes(getRandomClient(), "PULL|TLOG", collectionName);+ queryWithPreferReplicaTypes(getRandomClient(), "TLOG", collectionName);+ queryWithPreferReplicaTypes(getRandomClient(), "TLOG|PULL", collectionName);+ queryWithPreferReplicaTypes(getRandomClient(), "NRT", collectionName);+ queryWithPreferReplicaTypes(getRandomClient(), "NRT|PULL", collectionName);CollectionAdminRequest.deleteCollection(collectionName).processAndWait(cluster.getSolrClient(), TIMEOUT);}private void queryWithPreferReplicaTypes(CloudHttp2SolrClient cloudClient,String preferReplicaTypes,- boolean preferLocalShards,String collectionName)throws Exception{@@ -1021,13 +1005,7 @@ public class CloudHttp2SolrClientTest extends SolrCloudTestCase {rule.append(':');rule.append(type);});- if (preferLocalShards) {- if (rule.length() != 0) {- rule.append(',');- }- rule.append(ShardParams.SHARDS_PREFERENCE_REPLICA_LOCATION);- rule.append(":local");- }+qParams.add(ShardParams.SHARDS_PREFERENCE, rule.toString());qParams.add(ShardParams.SHARDS_INFO, "true");qRequest.add(qParams);diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.javaindex 68747a44183..8180358e386 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java@@ -399,18 +399,18 @@ public class CloudSolrClientTest extends SolrCloudTestCase {}/**- * Tests if the specification of 'preferLocalShards' in the query-params+ * Tests if the specification of 'shards.preference=replica.location:local' in the query-params* limits the distributed query to locally hosted shards only*/@Test// commented 4-Sep-2018 @LuceneTestCase.BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 2-Aug-2018- public void preferLocalShardsTest() throws Exception {+ public void queryWithLocalShardsPreferenceRulesTest() throws Exception {String collectionName = "localShardsTestColl";int liveNodes = cluster.getJettySolrRunners().size();- // For preferLocalShards to succeed in a test, every shard should have+ // For this case every shard should have// all its cores on the same node.// Hence the below configuration for our collectionCollectionAdminRequest.createCollection(collectionName, "conf", liveNodes, liveNodes)@@ -423,25 +423,17 @@ public class CloudSolrClientTest extends SolrCloudTestCase {.add(id, "3", "a_t", "hello2").commit(getRandomClient(), collectionName);- // Run the actual test for 'preferLocalShards'- queryWithShardsPreferenceRules(getRandomClient(), false, collectionName);- queryWithShardsPreferenceRules(getRandomClient(), true, collectionName);+ queryWithShardsPreferenceRules(getRandomClient(), collectionName);}@SuppressWarnings("deprecation")private void queryWithShardsPreferenceRules(CloudSolrClient cloudClient,- boolean useShardsPreference,- String collectionName)- throws Exception+ String collectionName) throws Exception{SolrQuery qRequest = new SolrQuery("*:*");ModifiableSolrParams qParams = new ModifiableSolrParams();- if (useShardsPreference) {- qParams.add(ShardParams.SHARDS_PREFERENCE, ShardParams.SHARDS_PREFERENCE_REPLICA_LOCATION + ":" + ShardParams.REPLICA_LOCAL);- } else {- qParams.add(CommonParams.PREFER_LOCAL_SHARDS, "true");- }+ qParams.add(ShardParams.SHARDS_PREFERENCE, ShardParams.SHARDS_PREFERENCE_REPLICA_LOCATION + ":" + ShardParams.REPLICA_LOCAL);qParams.add(ShardParams.SHARDS_INFO, "true");qRequest.add(qParams);@@ -953,26 +945,18 @@ public class CloudSolrClientTest extends SolrCloudTestCase {.commit(getRandomClient(), collectionName);// Run the actual tests for 'shards.preference=replica.type:*'- queryWithPreferReplicaTypes(getRandomClient(), "PULL", false, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "PULL|TLOG", false, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "TLOG", false, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "TLOG|PULL", false, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "NRT", false, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "NRT|PULL", false, collectionName);- // Test to verify that preferLocalShards=true doesn't break this- queryWithPreferReplicaTypes(getRandomClient(), "PULL", true, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "PULL|TLOG", true, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "TLOG", true, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "TLOG|PULL", true, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "NRT", false, collectionName);- queryWithPreferReplicaTypes(getRandomClient(), "NRT|PULL", true, collectionName);+ queryWithPreferReplicaTypes(getRandomClient(), "PULL", collectionName);+ queryWithPreferReplicaTypes(getRandomClient(), "PULL|TLOG", collectionName);+ queryWithPreferReplicaTypes(getRandomClient(), "TLOG", collectionName);+ queryWithPreferReplicaTypes(getRandomClient(), "TLOG|PULL", collectionName);+ queryWithPreferReplicaTypes(getRandomClient(), "NRT", collectionName);+ queryWithPreferReplicaTypes(getRandomClient(), "NRT|PULL", collectionName);CollectionAdminRequest.deleteCollection(collectionName).processAndWait(cluster.getSolrClient(), TIMEOUT);}private void queryWithPreferReplicaTypes(CloudSolrClient cloudClient,String preferReplicaTypes,- boolean preferLocalShards,String collectionName)throws Exception{@@ -989,13 +973,6 @@ public class CloudSolrClientTest extends SolrCloudTestCase {rule.append(':');rule.append(type);});- if (preferLocalShards) {- if (rule.length() != 0) {- rule.append(',');- }- rule.append(ShardParams.SHARDS_PREFERENCE_REPLICA_LOCATION);- rule.append(":local");- }qParams.add(ShardParams.SHARDS_PREFERENCE, rule.toString());qParams.add(ShardParams.SHARDS_INFO, "true");qRequest.add(qParams);diff --git a/solr/solrj/src/test/org/apache/solr/common/params/CommonParamsTest.java b/solr/solrj/src/test/org/apache/solr/common/params/CommonParamsTest.javaindex c3846373504..cd6421ef9a7 100755--- a/solr/solrj/src/test/org/apache/solr/common/params/CommonParamsTest.java+++ b/solr/solrj/src/test/org/apache/solr/common/params/CommonParamsTest.java@@ -31,8 +31,6 @@ public class CommonParamsTest extends SolrTestCasepublic void testRows() { assertEquals("rows", CommonParams.ROWS); }public void testRowsDefault() { assertEquals(10, CommonParams.ROWS_DEFAULT); }-- public void testPreferLocalShards() { assertEquals("preferLocalShards", CommonParams.PREFER_LOCAL_SHARDS); }public void testMinExactCount() { assertEquals("minExactCount", CommonParams.MIN_EXACT_COUNT); }}