SOLR-14035: Remove deprecated preferLocalShards=true support in favour of the shards.preference=replica.location:local alternative.

(Alex Bulygin via Christine Poerschke)
This commit is contained in:
Christine Poerschke 2020-11-19 17:57:47 +00:00
parent af0455ac83
commit c4d4767bca
10 changed files with 30 additions and 101 deletions

View File

@ -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 execution

View File

@ -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 -->
<!--

View File

@ -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",

View File

@ -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
}}}}
}
----

View File

@ -150,10 +150,6 @@ Each shard serves top-level query requests and then makes sub-requests to all of
For 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 Parameter
Solr 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.

View File

@ -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,

View File

@ -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";

View File

@ -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 collection
CollectionAdminRequest.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);

View File

@ -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 collection
CollectionAdminRequest.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);

View File

@ -31,8 +31,6 @@ public class CommonParamsTest extends SolrTestCase
public 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); }
}