Skip to content

Commit cbef2b7

Browse files
authored
doc: deprecate _primary and _replica shard option (#26792)
Tells v6 users that we are going to remove these options in v7. Relates #26335
1 parent d03e43b commit cbef2b7

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java

+8
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,20 @@ private ShardIterator preferenceActiveShardIterator(IndexShardRoutingTable index
199199
case LOCAL:
200200
return indexShard.preferNodeActiveInitializingShardsIt(Collections.singleton(localNodeId));
201201
case PRIMARY:
202+
deprecationLogger.deprecated("[_primary] has been deprecated in 6.1+, and will be removed in 7.0; " +
203+
"use [_only_nodes] or [_prefer_nodes]");
202204
return indexShard.primaryActiveInitializingShardIt();
203205
case REPLICA:
206+
deprecationLogger.deprecated("[_replica] has been deprecated in 6.1+, and will be removed in 7.0; " +
207+
"use [_only_nodes] or [_prefer_nodes]");
204208
return indexShard.replicaActiveInitializingShardIt();
205209
case PRIMARY_FIRST:
210+
deprecationLogger.deprecated("[_primary_first] has been deprecated in 6.1+, and will be removed in 7.0; " +
211+
"use [_only_nodes] or [_prefer_nodes]");
206212
return indexShard.primaryFirstActiveInitializingShardsIt();
207213
case REPLICA_FIRST:
214+
deprecationLogger.deprecated("[_replica_first] has been deprecated in 6.1+, and will be removed in 7.0; " +
215+
"use [_only_nodes] or [_prefer_nodes]");
208216
return indexShard.replicaFirstActiveInitializingShardsIt();
209217
case ONLY_LOCAL:
210218
return indexShard.onlyNodeActiveInitializingShardsIt(localNodeId);

core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java

+44-3
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ public void testReplicaShardPreferenceIters() throws Exception {
444444

445445
// When replicas haven't initialized, it comes back with the primary first, then initializing replicas
446446
GroupShardsIterator<ShardIterator> shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica_first");
447+
assertWarnings("[_replica_first] has been deprecated in 6.1+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]");
447448
assertThat(shardIterators.size(), equalTo(2)); // two potential shards
448449
ShardIterator iter = shardIterators.iterator().next();
449450
assertThat(iter.size(), equalTo(3)); // three potential candidates for the shard
@@ -463,10 +464,8 @@ public void testReplicaShardPreferenceIters() throws Exception {
463464

464465
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
465466

466-
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
467-
468-
469467
shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica");
468+
assertWarnings("[_replica] has been deprecated in 6.1+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]");
470469
assertThat(shardIterators.size(), equalTo(2)); // two potential shards
471470
iter = shardIterators.iterator().next();
472471
assertThat(iter.size(), equalTo(2)); // two potential replicas for the shard
@@ -479,6 +478,7 @@ public void testReplicaShardPreferenceIters() throws Exception {
479478
assertFalse(routing.primary());
480479

481480
shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica_first");
481+
assertWarnings("[_replica_first] has been deprecated in 6.1+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]");
482482
assertThat(shardIterators.size(), equalTo(2)); // two potential shards
483483
iter = shardIterators.iterator().next();
484484
assertThat(iter.size(), equalTo(3)); // three potential candidates for the shard
@@ -495,4 +495,45 @@ public void testReplicaShardPreferenceIters() throws Exception {
495495
assertTrue(routing.primary());
496496
}
497497

498+
public void testDeprecatedPreferences() throws Exception {
499+
AllocationService strategy = createAllocationService(Settings.builder()
500+
.put("cluster.routing.allocation.node_concurrent_recoveries", 10)
501+
.build());
502+
503+
OperationRouting operationRouting = new OperationRouting(Settings.EMPTY, new ClusterSettings(Settings.EMPTY,
504+
ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
505+
506+
MetaData metaData = MetaData.builder()
507+
.put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(2).numberOfReplicas(2))
508+
.build();
509+
510+
RoutingTable routingTable = RoutingTable.builder()
511+
.addAsNew(metaData.index("test"))
512+
.build();
513+
514+
ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
515+
.metaData(metaData)
516+
.routingTable(routingTable)
517+
.build();
518+
519+
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
520+
.add(newNode("node1"))
521+
.add(newNode("node2"))
522+
.localNodeId("node1")
523+
).build();
524+
525+
clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
526+
527+
operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_primary");
528+
assertWarnings("[_primary] has been deprecated in 6.1+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]");
529+
530+
operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_primary_first");
531+
assertWarnings("[_primary_first] has been deprecated in 6.1+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]");
532+
533+
operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica");
534+
assertWarnings("[_replica] has been deprecated in 6.1+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]");
535+
536+
operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica_first");
537+
assertWarnings("[_replica_first] has been deprecated in 6.1+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]");
538+
}
498539
}

docs/reference/search/request/preference.asciidoc

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@ The `preference` is a query string parameter which can be set to:
99
[horizontal]
1010
`_primary`::
1111
The operation will go and be executed only on the primary
12-
shards.
12+
shards. deprecated[6.1.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`]
1313

1414
`_primary_first`::
1515
The operation will go and be executed on the primary
1616
shard, and if not available (failover), will execute on other shards.
17+
deprecated[6.1.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`]
1718

1819
`_replica`::
1920
The operation will go and be executed only on a replica shard.
21+
deprecated[6.1.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`]
2022

2123
`_replica_first`::
2224
The operation will go and be executed only on a replica shard, and if
2325
not available (failover), will execute on other shards.
26+
deprecated[6.1.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`]
2427

2528
`_local`::
2629
The operation will prefer to be executed on a local
@@ -33,7 +36,7 @@ The `preference` is a query string parameter which can be set to:
3336
`_shards:2,3`::
3437
Restricts the operation to the specified shards. (`2`
3538
and `3` in this case). This preference can be combined with other
36-
preferences but it has to appear first: `_shards:2,3|_primary`
39+
preferences but it has to appear first: `_shards:2,3|_local`
3740

3841
`_only_nodes`::
3942
Restricts the operation to nodes specified in <<cluster,node specification>>

rest-api-spec/src/main/resources/rest-api-spec/test/bulk/20_list_of_strings.yml

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
---
22
"List of strings":
3+
- skip:
4+
version: " - 6.0.99"
5+
reason: '[_primary] shard preference deprecated in 6.1+'
6+
features: "warnings"
7+
38
- do:
49
bulk:
510
refresh: true
@@ -14,6 +19,9 @@
1419
# we count through the primary in case there is a replica that has not yet fully recovered
1520
preference: _primary
1621
index: test_index
22+
warnings:
23+
- "[_primary] has been deprecated in 6.1+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"
24+
1725

1826
- match: {count: 2}
1927

0 commit comments

Comments
 (0)