Skip to content

Commit 06fa432

Browse files
committed
SOLR-17915: Add shards.preference=replica.location:host (#3654)
(cherry picked from commit aa81f20)
1 parent 68651f6 commit 06fa432

12 files changed

Lines changed: 382 additions & 131 deletions

File tree

solr/CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ https://github.com/apache/solr/blob/main/solr/solr-ref-guide/modules/upgrade-not
77
================== 9.10.0 ==================
88
New Features
99
---------------------
10-
(No changes)
10+
* SOLR-17915: shards.preference=replica.location now supports the "host" option for routing to replicas on the same host. (Houston Putman)
1111

1212
Improvements
1313
---------------------

solr/core/src/java/org/apache/solr/handler/StreamHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw
213213
.toString(),
214214
zkController.getNodeName(),
215215
zkController.getBaseUrl(),
216+
zkController.getHostName(),
216217
zkController.getSysPropsCacher());
217218
} else {
218219
requestReplicaListTransformerGenerator = new RequestReplicaListTransformerGenerator();

solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ protected ReplicaListTransformer getReplicaListTransformer(final SolrQueryReques
409409
.toString(),
410410
zkController.getNodeName(),
411411
zkController.getBaseUrl(),
412+
zkController.getHostName(),
412413
zkController.getSysPropsCacher());
413414
} else {
414415
return requestReplicaListTransformerGenerator.getReplicaListTransformer(params);

solr/solr-ref-guide/modules/deployment-guide/pages/solrcloud-distributed-requests.adoc

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,22 +183,26 @@ One or more replica types that are preferred.
183183
Any combination of `PULL`, `TLOG` and `NRT` is allowed.
184184

185185
`replica.location`::
186-
One or more replica locations that are preferred.
187-
+
188-
A location starts with `http://hostname:port`.
189-
Matching is done for the given string as a prefix, so it's possible to e.g., leave out the port.
190-
+
191-
A special value `local` may be used to denote any local replica running on the same Solr instance as the one handling the query.
186+
Prefer replicas that match the given location. Available options are:
187+
- `local` - Replicas in the same Solr instance as the one handling the query.
192188
This is useful when a query requests many fields or large fields to be returned per document because it avoids moving large amounts of data over the network when it is available locally.
193189
In addition, this feature can be useful for minimizing the impact of a problematic replica with degraded performance, as it reduces the likelihood that the degraded replica will be hit by other healthy replicas.
194190
+
195191
The value of `replica.location:local` diminishes as the number of shards (that have no locally-available replicas) in a collection increases because the query controller will have to direct the query to non-local replicas for most of the shards.
196192
+
197193
In other words, this feature is mostly useful for optimizing queries directed towards collections with a small number of shards and many replicas.
194+
- `host` - Replicas in Solr instances running on the same host as the one handling the query.
195+
This can be useful in many of the same ways as `local`, but can help spare network costs when multiple Solr instances are running per host.
198196
+
199-
Also, this option should only be used if you are load balancing requests across all nodes that host replicas for the collection you are querying, as Solr's `CloudSolrClient` will do.
197+
As the number of shards grows, `replica.location:host` may be more useful than `replica.location:local`, since it is more likely that all shards can be found on the same host than all shards being found in the same Solr instance.
198+
- `_host-prefix_` - A replica location starts with `http://hostname:port`, i.e. `replica.location:http://hostname:port`.
199+
Matching is done for the given string as a prefix, so it's possible to e.g., leave out the port.
200+
201+
IMPORTANT: The `local` and `host` options should only be used if you are load balancing requests across all nodes that host replicas for the collection you are querying, as Solr's `CloudSolrClient` will do.
200202
If not load-balancing, this feature can introduce a hotspot in the cluster since queries won't be evenly distributed across the cluster.
201203

204+
NOTE: The `local` and `host` options are equivalent when only 1 Solr node is running on each host. This is also true in a setup like Kubernetes where each Solr node has a unique hostname.
205+
202206
`replica.base`::
203207
Applied after sorting by inherent replica attributes, this property defines a fallback ordering among sets of preference-equivalent replicas; if specified, only one value may be specified for this property, and it must be specified last.
204208
+
@@ -252,10 +256,10 @@ shards.preference=replica.location:local
252256
[source,text]
253257
shards.preference=replica.location:http://server1,replica.location:http://server2
254258

255-
* Prefer PULL replicas if available, otherwise TLOG replicas, and local replicas among those:
259+
* Prefer PULL replicas if available, otherwise TLOG replicas, and among those, replicas on the same host:
256260
+
257261
[source,text]
258-
shards.preference=replica.type:PULL,replica.type:TLOG,replica.location:local
262+
shards.preference=replica.type:PULL,replica.type:TLOG,replica.location:host
259263

260264
* Prefer local replicas, and among them PULL replicas when available, otherwise TLOG replicas:
261265
+
@@ -352,7 +356,7 @@ For example, the following line makes Solr use the `ExactStatsCache` implementat
352356

353357
The query param distrib.statsCache defaults to `true`. If set to `false`, distributed calls to fetch global term stats is turned off for this query. This can reduce overhead for queries that do not utilize distributed IDF for score calculation.
354358

355-
[source,xml]
359+
[source,plain]
356360
----
357361
http://localhost:8987/solr/collection1/select?q=*%3A*&wt=json&fq={!terms f=id}id1,id2&distrib.statsCache=false
358362
----

solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2822,7 +2822,7 @@ public void testTupleStreamGetShardsPreference() throws Exception {
28222822
streamContext.setSolrClientCache(new SolrClientCache());
28232823
streamContext.setRequestReplicaListTransformerGenerator(
28242824
new RequestReplicaListTransformerGenerator(
2825-
ShardParams.SHARDS_PREFERENCE_REPLICA_TYPE + ":TLOG", null, null, null));
2825+
ShardParams.SHARDS_PREFERENCE_REPLICA_TYPE + ":TLOG", null, null, null, null));
28262826

28272827
streamContext.setRequestParams(
28282828
params(ShardParams.SHARDS_PREFERENCE, ShardParams.SHARDS_PREFERENCE_REPLICA_TYPE + ":nrt"));

0 commit comments

Comments
 (0)