Skip to content

Commit

Permalink
Deprecate the 'local' parameter of /_cat/shards (#62197)
Browse files Browse the repository at this point in the history
  • Loading branch information
boicehuang authored Oct 29, 2020
1 parent f40d858 commit 7d65278
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
7 changes: 5 additions & 2 deletions docs/reference/cat/shards.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ Reason the shard is unassigned. Returned values are:

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

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

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

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

The following request returns the `unassigned.reason` column, which indicates
why a shard is unassigned.
why a shard is unassigned.


[source,console]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@
},
"local":{
"type":"boolean",
"description":"Return local information, do not retrieve the state from master node (default: false)"
"description":"Return local information, do not retrieve the state from master node (default: false)",
"deprecated":{
"version":"8.0.0",
"description":"This parameter does not affect the request. It will be removed in a future release."
}
},
"master_timeout":{
"type":"time",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.elasticsearch.cluster.routing.UnassignedInfo;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.Table;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.bulk.stats.BulkStats;
import org.elasticsearch.index.cache.query.QueryCacheStats;
Expand Down Expand Up @@ -60,6 +61,8 @@
import static org.elasticsearch.rest.RestRequest.Method.GET;

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

@Override
public List<Route> routes() {
Expand Down Expand Up @@ -87,6 +90,9 @@ protected void documentation(StringBuilder sb) {
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
if (request.hasParam("local")) {
DEPRECATION_LOGGER.deprecate("local", LOCAL_DEPRECATED_MESSAGE);
}
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
clusterStateRequest.clear().nodes(true).routingTable(true).indices(indices);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.elasticsearch.action.admin.indices.stats.IndexStats;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.action.admin.indices.stats.ShardStats;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes;
Expand All @@ -33,9 +34,12 @@
import org.elasticsearch.cluster.routing.ShardRoutingState;
import org.elasticsearch.cluster.routing.TestShardRouting;
import org.elasticsearch.common.Table;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.shard.ShardPath;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.rest.FakeRestRequest;
import org.elasticsearch.threadpool.TestThreadPool;
import org.junit.Before;

import java.nio.file.Path;
import java.util.ArrayList;
Expand All @@ -50,6 +54,13 @@

public class RestShardsActionTests extends ESTestCase {

private RestShardsAction action;

@Before
public void setUpAction() {
action = new RestShardsAction();
}

public void testBuildTable() {
final int numShards = randomIntBetween(1, 5);
DiscoveryNode localNode = new DiscoveryNode("local", buildNewFakeTransportAddress(), Version.CURRENT);
Expand Down Expand Up @@ -118,4 +129,16 @@ public void testBuildTable() {
assertThat(row.get(70).value, equalTo(shardStats.getStatePath()));
}
}

public void testCatNodesWithLocalDeprecationWarning() {
TestThreadPool threadPool = new TestThreadPool(RestNodesActionTests.class.getName());
NodeClient client = new NodeClient(Settings.EMPTY, threadPool);
FakeRestRequest request = new FakeRestRequest();
request.params().put("local", randomFrom("", "true", "false"));

action.doCatRequest(request, client);
assertWarnings(RestShardsAction.LOCAL_DEPRECATED_MESSAGE);

terminate(threadPool);
}
}

0 comments on commit 7d65278

Please sign in to comment.