mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-24 05:44:59 +00:00
Allow routing table to be filtered by index pattern
Before this commit when an index pattern is used to filter the cluster state, only indices metadata are populated and routing table is just empty. This commit aligns the behavior of the filtering of cluster state's routing table with the filtering of cluster state's metadata so that coherent data are returned for both routing table & metadata when index pattern is requested.
This commit is contained in:
parent
bf51247ec0
commit
7d4f557aa3
@ -81,7 +81,8 @@ public class TransportClusterStateAction extends TransportMasterNodeReadAction<C
|
||||
if (request.routingTable()) {
|
||||
if (request.indices().length > 0) {
|
||||
RoutingTable.Builder routingTableBuilder = RoutingTable.builder();
|
||||
for (String filteredIndex : request.indices()) {
|
||||
String[] indices = indexNameExpressionResolver.concreteIndexNames(currentState, request);
|
||||
for (String filteredIndex : indices) {
|
||||
if (currentState.routingTable().getIndicesRouting().containsKey(filteredIndex)) {
|
||||
routingTableBuilder.add(currentState.routingTable().getIndicesRouting().get(filteredIndex));
|
||||
}
|
||||
|
@ -26,7 +26,11 @@ import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.Requests;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.UUIDs;
|
||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
@ -112,18 +116,38 @@ public class SimpleClusterStateIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testThatFilteringByIndexWorksForMetadataAndRoutingTable() throws Exception {
|
||||
ClusterStateResponse clusterStateResponseFiltered = client().admin().cluster().prepareState().clear()
|
||||
.setMetaData(true).setRoutingTable(true).setIndices("foo", "fuu", "non-existent").get();
|
||||
testFilteringByIndexWorks(new String[]{"foo", "fuu", "non-existent"}, new String[]{"foo", "fuu"});
|
||||
testFilteringByIndexWorks(new String[]{"baz"}, new String[]{"baz"});
|
||||
testFilteringByIndexWorks(new String[]{"f*"}, new String[]{"foo", "fuu"});
|
||||
testFilteringByIndexWorks(new String[]{"b*"}, new String[]{"baz"});
|
||||
testFilteringByIndexWorks(new String[]{"*u"}, new String[]{"fuu"});
|
||||
|
||||
// metadata
|
||||
assertThat(clusterStateResponseFiltered.getState().metaData().indices().size(), is(2));
|
||||
assertThat(clusterStateResponseFiltered.getState().metaData().indices(), CollectionAssertions.hasKey("foo"));
|
||||
assertThat(clusterStateResponseFiltered.getState().metaData().indices(), CollectionAssertions.hasKey("fuu"));
|
||||
String[] randomIndices = randomFrom(new String[]{"*"}, new String[]{MetaData.ALL}, Strings.EMPTY_ARRAY, new String[]{"f*", "b*"});
|
||||
testFilteringByIndexWorks(randomIndices, new String[]{"foo", "fuu", "baz"});
|
||||
}
|
||||
|
||||
// routing table
|
||||
assertThat(clusterStateResponseFiltered.getState().routingTable().hasIndex("foo"), is(true));
|
||||
assertThat(clusterStateResponseFiltered.getState().routingTable().hasIndex("fuu"), is(true));
|
||||
assertThat(clusterStateResponseFiltered.getState().routingTable().hasIndex("baz"), is(false));
|
||||
/**
|
||||
* Retrieves the cluster state for the given indices and then checks
|
||||
* that the cluster state returns coherent data for both routing table and metadata.
|
||||
*/
|
||||
private void testFilteringByIndexWorks(String[] indices, String[] expected) {
|
||||
ClusterStateResponse clusterState = client().admin().cluster().prepareState()
|
||||
.clear()
|
||||
.setMetaData(true)
|
||||
.setRoutingTable(true)
|
||||
.setIndices(indices)
|
||||
.get();
|
||||
|
||||
ImmutableOpenMap<String, IndexMetaData> metaData = clusterState.getState().getMetaData().indices();
|
||||
assertThat(metaData.size(), is(expected.length));
|
||||
|
||||
RoutingTable routingTable = clusterState.getState().getRoutingTable();
|
||||
assertThat(routingTable.indicesRouting().size(), is(expected.length));
|
||||
|
||||
for (String expectedIndex : expected) {
|
||||
assertThat(metaData, CollectionAssertions.hasKey(expectedIndex));
|
||||
assertThat(routingTable.hasIndex(expectedIndex), is(true));
|
||||
}
|
||||
}
|
||||
|
||||
public void testLargeClusterStatePublishing() throws Exception {
|
||||
|
@ -130,3 +130,34 @@ setup:
|
||||
- is_true: metadata
|
||||
- is_true: routing_table
|
||||
- is_true: routing_nodes
|
||||
|
||||
---
|
||||
"Filtering the cluster state by indices using wildcards should work in routing table and metadata":
|
||||
- do:
|
||||
index:
|
||||
index: index1
|
||||
type: type
|
||||
id: testing_document
|
||||
body:
|
||||
"text" : "The quick brown fox is brown."
|
||||
|
||||
- do:
|
||||
index:
|
||||
index: index2
|
||||
type: type
|
||||
id: testing_document
|
||||
body:
|
||||
"text" : "The quick brown fox is brown."
|
||||
|
||||
- do:
|
||||
cluster.state:
|
||||
metric: [ routing_table, metadata ]
|
||||
index: [ index* ]
|
||||
|
||||
- is_false: metadata.indices.testidx
|
||||
- is_false: routing_table.indices.testidx
|
||||
|
||||
- is_true: metadata.indices.index1
|
||||
- is_true: routing_table.indices.index1
|
||||
- is_true: metadata.indices.index2
|
||||
- is_true: routing_table.indices.index2
|
||||
|
Loading…
x
Reference in New Issue
Block a user