Route custom preferences to search replicas#22394
Conversation
PR Reviewer Guide 🔍(Review updated until commit 5a5085c)Here are some key observations to aid the review process:
|
07ba930 to
be08d05
Compare
|
Persistent review updated to latest commit be08d05 |
PR Code Suggestions ✨Latest suggestions up to 5a5085c Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit e4f6a6d
Suggestions up to commit be08d05
|
be08d05 to
e4f6a6d
Compare
|
Persistent review updated to latest commit e4f6a6d |
|
❌ Gradle check result for e4f6a6d: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
When strict search-replica routing is enabled (cluster.routing.search_replica.strict, default true) and an index has search replicas, search traffic should stay isolated on those replicas. Previously only an empty preference was confined to search replicas; a caller-supplied custom preference (one that does not start with '_') fell through to routing across primaries and writer replicas, breaking the isolation guarantee. Custom preferences are now also confined to search replicas while preserving preference-based consistency: the preference hash seeds search-replica selection so the same key resolves to the same replica. Explicit '_' preferences (e.g. _primary) still override, and realtime GET is unaffected. Signed-off-by: Suraj Soni <suraj.soni@glean.com>
e4f6a6d to
5a5085c
Compare
|
Persistent review updated to latest commit 5a5085c |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #22394 +/- ##
============================================
- Coverage 73.52% 73.48% -0.05%
+ Complexity 76254 76224 -30
============================================
Files 6076 6076
Lines 345790 345794 +4
Branches 49762 49763 +1
============================================
- Hits 254236 254100 -136
- Misses 71371 71485 +114
- Partials 20183 20209 +26 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
When strict search-replica routing is enabled (
cluster.routing.search_replica.strict, defaulttrue) and an index has search replicas, search traffic is expected to stay isolated on those search replicas, keeping it off the primary/writer copies.Today that isolation only holds when the request has no preference.
OperationRouting#searchShardsforced an empty preference onto_search_replica, but a caller-supplied custom preference (a non-_key, typically used for session-consistent routing) fell through toactiveInitializingShardsIt(...), which spreads across primaries and writer replicas. So a custom preference silently disabled the strict search-replica isolation.This change makes the search-replica target the default whenever strict routing applies and the index has search replicas, covering both the empty-preference and custom-preference cases:
searchShards(defaultToSearchReplicas = isStrictSearchOnlyShardRouting && numberOfSearchOnlyReplicas > 0) and passed intopreferenceActiveShardIterator.IndexShardRoutingTable#searchReplicaActiveInitializingShardIt(int seed), so the same key resolves to the same search replica across requests._preferences (e.g._primary,_only_nodes) still override, since they are handled before the default kicks in.getShards) is unaffected — it passesfalse, so it can still reach the primary/writer replicas.Behavior note (weighted routing): when a custom preference is now confined to search replicas, weighted/AZ routing is not applied to that selection. This matches the existing behavior of the explicit
_search_replicapreference (which also bypasses weighted routing), so it is internally consistent; but for clusters relying on weighted routing, custom-preference searches against search replicas will not honor those weights.Related Issues
#22395
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.