From 51267e77434011547d499d9c58df7c478b16ea7e Mon Sep 17 00:00:00 2001 From: Nhat Date: Tue, 26 Sep 2017 11:41:33 -0400 Subject: [PATCH 1/5] doc: deprecate _primary and _replica shard option Related #26335 --- docs/reference/search/request/preference.asciidoc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/reference/search/request/preference.asciidoc b/docs/reference/search/request/preference.asciidoc index d0f60d700a82c..a5a8473df8ab3 100644 --- a/docs/reference/search/request/preference.asciidoc +++ b/docs/reference/search/request/preference.asciidoc @@ -9,18 +9,21 @@ The `preference` is a query string parameter which can be set to: [horizontal] `_primary`:: The operation will go and be executed only on the primary - shards. + shards. The `_primary` option is deprecated in 6.0.0 and will be removed in Elasticsearch 7.0. `_primary_first`:: The operation will go and be executed on the primary shard, and if not available (failover), will execute on other shards. + The `_primary_first` option is deprecated in 6.0.0 and will be removed in Elasticsearch 7.0. `_replica`:: The operation will go and be executed only on a replica shard. + The `_replica` option is deprecated in 6.0.0 and will be removed in Elasticsearch 7.0. `_replica_first`:: The operation will go and be executed only on a replica shard, and if not available (failover), will execute on other shards. + The `_replica_first` option is deprecated in 6.0.0 and will be removed in Elasticsearch 7.0. `_local`:: 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: `_shards:2,3`:: Restricts the operation to the specified shards. (`2` and `3` in this case). This preference can be combined with other - preferences but it has to appear first: `_shards:2,3|_primary` + preferences but it has to appear first: `_shards:2,3|_local` `_only_nodes`:: Restricts the operation to nodes specified in <> From da2457e04c2a318fc626bff6d129ac076179cb6d Mon Sep 17 00:00:00 2001 From: Nhat Date: Tue, 26 Sep 2017 13:22:39 -0400 Subject: [PATCH 2/5] docs: use deprecation syntax --- docs/reference/search/request/preference.asciidoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/reference/search/request/preference.asciidoc b/docs/reference/search/request/preference.asciidoc index a5a8473df8ab3..9e7d3883430a4 100644 --- a/docs/reference/search/request/preference.asciidoc +++ b/docs/reference/search/request/preference.asciidoc @@ -9,21 +9,21 @@ The `preference` is a query string parameter which can be set to: [horizontal] `_primary`:: The operation will go and be executed only on the primary - shards. The `_primary` option is deprecated in 6.0.0 and will be removed in Elasticsearch 7.0. + shards. deprecated[6.0.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`] `_primary_first`:: The operation will go and be executed on the primary shard, and if not available (failover), will execute on other shards. - The `_primary_first` option is deprecated in 6.0.0 and will be removed in Elasticsearch 7.0. + deprecated[6.0.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`] `_replica`:: The operation will go and be executed only on a replica shard. - The `_replica` option is deprecated in 6.0.0 and will be removed in Elasticsearch 7.0. + deprecated[6.0.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`] `_replica_first`:: The operation will go and be executed only on a replica shard, and if not available (failover), will execute on other shards. - The `_replica_first` option is deprecated in 6.0.0 and will be removed in Elasticsearch 7.0. + deprecated[6.0.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`] `_local`:: The operation will prefer to be executed on a local From b9304b33aef551b8dc9c1cf69d6390134fedb524 Mon Sep 17 00:00:00 2001 From: Nhat Date: Wed, 4 Oct 2017 09:15:25 -0400 Subject: [PATCH 3/5] log deprecated options --- .../cluster/routing/OperationRouting.java | 8 ++++ .../structure/RoutingIteratorTests.java | 47 +++++++++++++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java b/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java index 4b3f254c9f5fc..9d89282de4977 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java @@ -199,12 +199,20 @@ private ShardIterator preferenceActiveShardIterator(IndexShardRoutingTable index case LOCAL: return indexShard.preferNodeActiveInitializingShardsIt(Collections.singleton(localNodeId)); case PRIMARY: + deprecationLogger.deprecated("[_primary] has been deprecated in 6.0+, and will be removed in 7.0; " + + "use [_only_nodes] or [_prefer_nodes]"); return indexShard.primaryActiveInitializingShardIt(); case REPLICA: + deprecationLogger.deprecated("[_replica] has been deprecated in 6.0+, and will be removed in 7.0; " + + "use [_only_nodes] or [_prefer_nodes]"); return indexShard.replicaActiveInitializingShardIt(); case PRIMARY_FIRST: + deprecationLogger.deprecated("[_primary_first] has been deprecated in 6.0+, and will be removed in 7.0; " + + "use [_only_nodes] or [_prefer_nodes]"); return indexShard.primaryFirstActiveInitializingShardsIt(); case REPLICA_FIRST: + deprecationLogger.deprecated("[_replica_first] has been deprecated in 6.0+, and will be removed in 7.0; " + + "use [_only_nodes] or [_prefer_nodes]"); return indexShard.replicaFirstActiveInitializingShardsIt(); case ONLY_LOCAL: return indexShard.onlyNodeActiveInitializingShardsIt(localNodeId); diff --git a/core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java b/core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java index 172bcd6bd558b..713a50a4f9c20 100644 --- a/core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java @@ -444,6 +444,7 @@ public void testReplicaShardPreferenceIters() throws Exception { // When replicas haven't initialized, it comes back with the primary first, then initializing replicas GroupShardsIterator shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica_first"); + assertWarnings("[_replica_first] has been deprecated in 6.0+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); assertThat(shardIterators.size(), equalTo(2)); // two potential shards ShardIterator iter = shardIterators.iterator().next(); assertThat(iter.size(), equalTo(3)); // three potential candidates for the shard @@ -463,10 +464,8 @@ public void testReplicaShardPreferenceIters() throws Exception { clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)); - clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)); - - shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica"); + assertWarnings("[_replica] has been deprecated in 6.0+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); assertThat(shardIterators.size(), equalTo(2)); // two potential shards iter = shardIterators.iterator().next(); assertThat(iter.size(), equalTo(2)); // two potential replicas for the shard @@ -479,6 +478,7 @@ public void testReplicaShardPreferenceIters() throws Exception { assertFalse(routing.primary()); shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica_first"); + assertWarnings("[_replica_first] has been deprecated in 6.0+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); assertThat(shardIterators.size(), equalTo(2)); // two potential shards iter = shardIterators.iterator().next(); assertThat(iter.size(), equalTo(3)); // three potential candidates for the shard @@ -495,4 +495,45 @@ public void testReplicaShardPreferenceIters() throws Exception { assertTrue(routing.primary()); } + public void testDeprecatedPreferences() throws Exception { + AllocationService strategy = createAllocationService(Settings.builder() + .put("cluster.routing.allocation.node_concurrent_recoveries", 10) + .build()); + + OperationRouting operationRouting = new OperationRouting(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, + ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); + + MetaData metaData = MetaData.builder() + .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(2).numberOfReplicas(2)) + .build(); + + RoutingTable routingTable = RoutingTable.builder() + .addAsNew(metaData.index("test")) + .build(); + + ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) + .metaData(metaData) + .routingTable(routingTable) + .build(); + + clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() + .add(newNode("node1")) + .add(newNode("node2")) + .localNodeId("node1") + ).build(); + + clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)); + + operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_primary"); + assertWarnings("[_primary] has been deprecated in 6.0+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); + + operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_primary_first"); + assertWarnings("[_primary_first] has been deprecated in 6.0+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); + + operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica"); + assertWarnings("[_replica] has been deprecated in 6.0+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); + + operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica_first"); + assertWarnings("[_replica_first] has been deprecated in 6.0+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); + } } From 92b81f21751c01bf7df555768c2243116ed2edb1 Mon Sep 17 00:00:00 2001 From: Nhat Date: Wed, 4 Oct 2017 11:26:06 -0400 Subject: [PATCH 4/5] fix a rest spec test to expect the warning header --- .../rest-api-spec/test/bulk/20_list_of_strings.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/20_list_of_strings.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/20_list_of_strings.yml index e25626cf3ae28..16a519f16a614 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/20_list_of_strings.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/20_list_of_strings.yml @@ -1,5 +1,10 @@ --- "List of strings": + - skip: + version: " - 5.99.99" + reason: '[_primary] shard preference deprecated in 6.0+' + features: "warnings" + - do: bulk: refresh: true @@ -14,6 +19,9 @@ # we count through the primary in case there is a replica that has not yet fully recovered preference: _primary index: test_index + warnings: + - "[_primary] has been deprecated in 6.0+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]" + - match: {count: 2} From 8b9525bda6cbc9baf99816713fbb2546f1d424bc Mon Sep 17 00:00:00 2001 From: Nhat Date: Wed, 4 Oct 2017 18:50:52 -0400 Subject: [PATCH 5/5] correct the deprecated version: 6.0 -> 6.1 --- .../cluster/routing/OperationRouting.java | 8 ++++---- .../cluster/structure/RoutingIteratorTests.java | 14 +++++++------- docs/reference/search/request/preference.asciidoc | 8 ++++---- .../rest-api-spec/test/bulk/20_list_of_strings.yml | 6 +++--- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java b/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java index 9d89282de4977..45c0144a22597 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java @@ -199,19 +199,19 @@ private ShardIterator preferenceActiveShardIterator(IndexShardRoutingTable index case LOCAL: return indexShard.preferNodeActiveInitializingShardsIt(Collections.singleton(localNodeId)); case PRIMARY: - deprecationLogger.deprecated("[_primary] has been deprecated in 6.0+, and will be removed in 7.0; " + + deprecationLogger.deprecated("[_primary] has been deprecated in 6.1+, and will be removed in 7.0; " + "use [_only_nodes] or [_prefer_nodes]"); return indexShard.primaryActiveInitializingShardIt(); case REPLICA: - deprecationLogger.deprecated("[_replica] has been deprecated in 6.0+, and will be removed in 7.0; " + + deprecationLogger.deprecated("[_replica] has been deprecated in 6.1+, and will be removed in 7.0; " + "use [_only_nodes] or [_prefer_nodes]"); return indexShard.replicaActiveInitializingShardIt(); case PRIMARY_FIRST: - deprecationLogger.deprecated("[_primary_first] has been deprecated in 6.0+, and will be removed in 7.0; " + + deprecationLogger.deprecated("[_primary_first] has been deprecated in 6.1+, and will be removed in 7.0; " + "use [_only_nodes] or [_prefer_nodes]"); return indexShard.primaryFirstActiveInitializingShardsIt(); case REPLICA_FIRST: - deprecationLogger.deprecated("[_replica_first] has been deprecated in 6.0+, and will be removed in 7.0; " + + deprecationLogger.deprecated("[_replica_first] has been deprecated in 6.1+, and will be removed in 7.0; " + "use [_only_nodes] or [_prefer_nodes]"); return indexShard.replicaFirstActiveInitializingShardsIt(); case ONLY_LOCAL: diff --git a/core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java b/core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java index 713a50a4f9c20..05d37365b5c9c 100644 --- a/core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java @@ -444,7 +444,7 @@ public void testReplicaShardPreferenceIters() throws Exception { // When replicas haven't initialized, it comes back with the primary first, then initializing replicas GroupShardsIterator shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica_first"); - assertWarnings("[_replica_first] has been deprecated in 6.0+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); + assertWarnings("[_replica_first] has been deprecated in 6.1+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); assertThat(shardIterators.size(), equalTo(2)); // two potential shards ShardIterator iter = shardIterators.iterator().next(); assertThat(iter.size(), equalTo(3)); // three potential candidates for the shard @@ -465,7 +465,7 @@ public void testReplicaShardPreferenceIters() throws Exception { clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)); shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica"); - assertWarnings("[_replica] has been deprecated in 6.0+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); + assertWarnings("[_replica] has been deprecated in 6.1+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); assertThat(shardIterators.size(), equalTo(2)); // two potential shards iter = shardIterators.iterator().next(); assertThat(iter.size(), equalTo(2)); // two potential replicas for the shard @@ -478,7 +478,7 @@ public void testReplicaShardPreferenceIters() throws Exception { assertFalse(routing.primary()); shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica_first"); - assertWarnings("[_replica_first] has been deprecated in 6.0+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); + assertWarnings("[_replica_first] has been deprecated in 6.1+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); assertThat(shardIterators.size(), equalTo(2)); // two potential shards iter = shardIterators.iterator().next(); assertThat(iter.size(), equalTo(3)); // three potential candidates for the shard @@ -525,15 +525,15 @@ public void testDeprecatedPreferences() throws Exception { clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)); operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_primary"); - assertWarnings("[_primary] has been deprecated in 6.0+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); + assertWarnings("[_primary] has been deprecated in 6.1+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_primary_first"); - assertWarnings("[_primary_first] has been deprecated in 6.0+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); + assertWarnings("[_primary_first] has been deprecated in 6.1+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica"); - assertWarnings("[_replica] has been deprecated in 6.0+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); + assertWarnings("[_replica] has been deprecated in 6.1+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica_first"); - assertWarnings("[_replica_first] has been deprecated in 6.0+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); + assertWarnings("[_replica_first] has been deprecated in 6.1+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]"); } } diff --git a/docs/reference/search/request/preference.asciidoc b/docs/reference/search/request/preference.asciidoc index 9e7d3883430a4..325730f70a981 100644 --- a/docs/reference/search/request/preference.asciidoc +++ b/docs/reference/search/request/preference.asciidoc @@ -9,21 +9,21 @@ The `preference` is a query string parameter which can be set to: [horizontal] `_primary`:: The operation will go and be executed only on the primary - shards. deprecated[6.0.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`] + shards. deprecated[6.1.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`] `_primary_first`:: The operation will go and be executed on the primary shard, and if not available (failover), will execute on other shards. - deprecated[6.0.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`] + deprecated[6.1.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`] `_replica`:: The operation will go and be executed only on a replica shard. - deprecated[6.0.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`] + deprecated[6.1.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`] `_replica_first`:: The operation will go and be executed only on a replica shard, and if not available (failover), will execute on other shards. - deprecated[6.0.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`] + deprecated[6.1.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`] `_local`:: The operation will prefer to be executed on a local diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/20_list_of_strings.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/20_list_of_strings.yml index 16a519f16a614..7dfbce13d7afc 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/20_list_of_strings.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/20_list_of_strings.yml @@ -1,8 +1,8 @@ --- "List of strings": - skip: - version: " - 5.99.99" - reason: '[_primary] shard preference deprecated in 6.0+' + version: " - 6.0.99" + reason: '[_primary] shard preference deprecated in 6.1+' features: "warnings" - do: @@ -20,7 +20,7 @@ preference: _primary index: test_index warnings: - - "[_primary] has been deprecated in 6.0+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]" + - "[_primary] has been deprecated in 6.1+, and will be removed in 7.0; use [_only_nodes] or [_prefer_nodes]" - match: {count: 2}