Skip to content

Commit 7d65278

Browse files
authored
Deprecate the 'local' parameter of /_cat/shards (#62197)
1 parent f40d858 commit 7d65278

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

docs/reference/cat/shards.asciidoc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,10 @@ Reason the shard is unassigned. Returned values are:
273273

274274
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=help]
275275

276-
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=local]
276+
`local`::
277+
(Optional, boolean)
278+
+
279+
deprecated::[7.10.0,"This parameter does not affect the request. It will be removed in a future release."]
277280

278281
include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]
279282

@@ -378,7 +381,7 @@ my-index-000001 0 r INITIALIZING 0 14.3mb 192.168.56.30 bGG90GE
378381
===== Example with reasons for unassigned shards
379382

380383
The following request returns the `unassigned.reason` column, which indicates
381-
why a shard is unassigned.
384+
why a shard is unassigned.
382385

383386

384387
[source,console]

rest-api-spec/src/main/resources/rest-api-spec/api/cat.shards.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@
5151
},
5252
"local":{
5353
"type":"boolean",
54-
"description":"Return local information, do not retrieve the state from master node (default: false)"
54+
"description":"Return local information, do not retrieve the state from master node (default: false)",
55+
"deprecated":{
56+
"version":"8.0.0",
57+
"description":"This parameter does not affect the request. It will be removed in a future release."
58+
}
5559
},
5660
"master_timeout":{
5761
"type":"time",

server/src/main/java/org/elasticsearch/rest/action/cat/RestShardsAction.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.cluster.routing.UnassignedInfo;
3131
import org.elasticsearch.common.Strings;
3232
import org.elasticsearch.common.Table;
33+
import org.elasticsearch.common.logging.DeprecationLogger;
3334
import org.elasticsearch.common.unit.TimeValue;
3435
import org.elasticsearch.index.bulk.stats.BulkStats;
3536
import org.elasticsearch.index.cache.query.QueryCacheStats;
@@ -60,6 +61,8 @@
6061
import static org.elasticsearch.rest.RestRequest.Method.GET;
6162

6263
public class RestShardsAction extends AbstractCatAction {
64+
private static final DeprecationLogger DEPRECATION_LOGGER = DeprecationLogger.getLogger(RestShardsAction.class);
65+
static final String LOCAL_DEPRECATED_MESSAGE = "The parameter [local] is deprecated and will be removed in a future release.";
6366

6467
@Override
6568
public List<Route> routes() {
@@ -87,6 +90,9 @@ protected void documentation(StringBuilder sb) {
8790
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
8891
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
8992
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
93+
if (request.hasParam("local")) {
94+
DEPRECATION_LOGGER.deprecate("local", LOCAL_DEPRECATED_MESSAGE);
95+
}
9096
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
9197
clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
9298
clusterStateRequest.clear().nodes(true).routingTable(true).indices(indices);

server/src/test/java/org/elasticsearch/rest/action/cat/RestShardsActionTests.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.elasticsearch.action.admin.indices.stats.IndexStats;
2626
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
2727
import org.elasticsearch.action.admin.indices.stats.ShardStats;
28+
import org.elasticsearch.client.node.NodeClient;
2829
import org.elasticsearch.cluster.ClusterState;
2930
import org.elasticsearch.cluster.node.DiscoveryNode;
3031
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -33,9 +34,12 @@
3334
import org.elasticsearch.cluster.routing.ShardRoutingState;
3435
import org.elasticsearch.cluster.routing.TestShardRouting;
3536
import org.elasticsearch.common.Table;
37+
import org.elasticsearch.common.settings.Settings;
3638
import org.elasticsearch.index.shard.ShardPath;
3739
import org.elasticsearch.test.ESTestCase;
3840
import org.elasticsearch.test.rest.FakeRestRequest;
41+
import org.elasticsearch.threadpool.TestThreadPool;
42+
import org.junit.Before;
3943

4044
import java.nio.file.Path;
4145
import java.util.ArrayList;
@@ -50,6 +54,13 @@
5054

5155
public class RestShardsActionTests extends ESTestCase {
5256

57+
private RestShardsAction action;
58+
59+
@Before
60+
public void setUpAction() {
61+
action = new RestShardsAction();
62+
}
63+
5364
public void testBuildTable() {
5465
final int numShards = randomIntBetween(1, 5);
5566
DiscoveryNode localNode = new DiscoveryNode("local", buildNewFakeTransportAddress(), Version.CURRENT);
@@ -118,4 +129,16 @@ public void testBuildTable() {
118129
assertThat(row.get(70).value, equalTo(shardStats.getStatePath()));
119130
}
120131
}
132+
133+
public void testCatNodesWithLocalDeprecationWarning() {
134+
TestThreadPool threadPool = new TestThreadPool(RestNodesActionTests.class.getName());
135+
NodeClient client = new NodeClient(Settings.EMPTY, threadPool);
136+
FakeRestRequest request = new FakeRestRequest();
137+
request.params().put("local", randomFrom("", "true", "false"));
138+
139+
action.doCatRequest(request, client);
140+
assertWarnings(RestShardsAction.LOCAL_DEPRECATED_MESSAGE);
141+
142+
terminate(threadPool);
143+
}
121144
}

0 commit comments

Comments
 (0)