Made it mandatory to specify IndicesOptions when calling MetaData#concreteIndices

Removed MetaData#concreteIndices variations that didn't require an IndicesOptions argument. Every caller should specify how indices should be resolved to concrete indices based on the indices options argument.

Closes #6059
This commit is contained in:
javanna 2014-05-06 11:16:32 +02:00 committed by Luca Cavanna
parent 90b547cf2c
commit a8b6f81525
9 changed files with 26 additions and 25 deletions

View File

@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.cluster.health;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.TransportMasterNodeReadOperationAction;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
@ -139,7 +140,7 @@ public class TransportClusterHealthAction extends TransportMasterNodeReadOperati
}
if (request.indices().length > 0) {
try {
clusterState.metaData().concreteIndices(request.indices());
clusterState.metaData().concreteIndices(request.indices(), IndicesOptions.ERROR_UNAVAILABLE_EXPAND_OPEN_CLOSE);
waitForCounter++;
} catch (IndexMissingException e) {
response.status = ClusterHealthStatus.RED; // no indices, make sure its RED
@ -220,7 +221,7 @@ public class TransportClusterHealthAction extends TransportMasterNodeReadOperati
}
String[] concreteIndices;
try {
concreteIndices = clusterState.metaData().concreteIndicesIgnoreMissing(request.indices());
concreteIndices = clusterState.metaData().concreteIndices(request.indices(), IndicesOptions.IGNORE_UNAVAILABLE_EXPAND_OPEN_ONLY);
} catch (IndexMissingException e) {
// one of the specified indices is not there - treat it as RED.
ClusterHealthResponse response = new ClusterHealthResponse(clusterName.value(), Strings.EMPTY_ARRAY, clusterState);

View File

@ -19,15 +19,14 @@
package org.elasticsearch.action.admin.cluster.state;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.TransportMasterNodeReadOperationAction;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.common.inject.Inject;
@ -104,7 +103,7 @@ public class TransportClusterStateAction extends TransportMasterNodeReadOperatio
}
if (request.indices().length > 0) {
String[] indices = currentState.metaData().concreteIndicesIgnoreMissing(request.indices());
String[] indices = currentState.metaData().concreteIndices(request.indices(), IndicesOptions.IGNORE_UNAVAILABLE_EXPAND_OPEN_ONLY);
for (String filteredIndex : indices) {
IndexMetaData indexMetaData = currentState.metaData().index(filteredIndex);
if (indexMetaData != null) {

View File

@ -42,6 +42,16 @@ public class IndicesOptions {
}
}
/**
* Indices option that ignores unavailable indices, allows no indices and expand wildcards to open only indices
*/
public static IndicesOptions IGNORE_UNAVAILABLE_EXPAND_OPEN_ONLY = fromOptions(true, true, true, false);
/**
* Indices option that doesn't ignore unavailable indices, allows no indices and expand wildcards to both open and closed indices
*/
public static IndicesOptions ERROR_UNAVAILABLE_EXPAND_OPEN_CLOSE = fromOptions(false, true, true, true);
private final byte id;
private IndicesOptions(byte id) {

View File

@ -623,20 +623,6 @@ public class MetaData implements Iterable<IndexMetaData> {
return null;
}
/**
* Translates the provided indices (possibly aliased) into actual indices.
*/
public String[] concreteIndices(String[] indices) throws IndexMissingException {
return concreteIndices(indices, IndicesOptions.fromOptions(false, true, true, true));
}
/**
* Translates the provided indices (possibly aliased) into actual indices.
*/
public String[] concreteIndicesIgnoreMissing(String[] indices) {
return concreteIndices(indices, IndicesOptions.fromOptions(true, true, true, false));
}
/**
* Translates the provided indices (possibly aliased) into actual indices.
*/

View File

@ -22,6 +22,7 @@ package org.elasticsearch.cluster.metadata;
import com.google.common.collect.Sets;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsClusterStateUpdateRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.cluster.*;
import org.elasticsearch.cluster.ack.ClusterStateUpdateListener;
import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse;
@ -228,7 +229,7 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
@Override
public ClusterState execute(ClusterState currentState) {
String[] actualIndices = currentState.metaData().concreteIndices(request.indices());
String[] actualIndices = currentState.metaData().concreteIndices(request.indices(), IndicesOptions.ERROR_UNAVAILABLE_EXPAND_OPEN_CLOSE);
RoutingTable.Builder routingTableBuilder = RoutingTable.builder(currentState.routingTable());
MetaData.Builder metaDataBuilder = MetaData.builder(currentState.metaData());

View File

@ -20,6 +20,7 @@
package org.elasticsearch.index.query;
import org.apache.lucene.search.Filter;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.inject.Inject;
@ -145,7 +146,7 @@ public class IndicesFilterParser implements FilterParser {
}
protected boolean matchesIndices(String currentIndex, String... indices) {
final String[] concreteIndices = clusterService.state().metaData().concreteIndicesIgnoreMissing(indices);
final String[] concreteIndices = clusterService.state().metaData().concreteIndices(indices, IndicesOptions.IGNORE_UNAVAILABLE_EXPAND_OPEN_ONLY);
for (String index : concreteIndices) {
if (Regex.simpleMatch(index, currentIndex)) {
return true;

View File

@ -20,6 +20,7 @@
package org.elasticsearch.index.query;
import org.apache.lucene.search.Query;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.inject.Inject;
@ -146,7 +147,7 @@ public class IndicesQueryParser implements QueryParser {
}
protected boolean matchesIndices(String currentIndex, String... indices) {
final String[] concreteIndices = clusterService.state().metaData().concreteIndicesIgnoreMissing(indices);
final String[] concreteIndices = clusterService.state().metaData().concreteIndices(indices, IndicesOptions.IGNORE_UNAVAILABLE_EXPAND_OPEN_ONLY);
for (String index : concreteIndices) {
if (Regex.simpleMatch(index, currentIndex)) {
return true;

View File

@ -27,6 +27,7 @@ import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.action.admin.indices.stats.IndexStats;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.Requests;
import org.elasticsearch.common.Strings;
@ -71,7 +72,7 @@ public class RestIndicesAction extends AbstractCatAction {
client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
@Override
public void processResponse(final ClusterStateResponse clusterStateResponse) {
final String[] concreteIndices = clusterStateResponse.getState().metaData().concreteIndicesIgnoreMissing(indices);
final String[] concreteIndices = clusterStateResponse.getState().metaData().concreteIndices(indices, IndicesOptions.IGNORE_UNAVAILABLE_EXPAND_OPEN_ONLY);
ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(concreteIndices);
clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local()));
client.admin().cluster().health(clusterHealthRequest, new RestActionListener<ClusterHealthResponse>(channel) {

View File

@ -24,6 +24,7 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.admin.cluster.health.ClusterIndexHealth;
import org.elasticsearch.action.admin.cluster.health.ClusterShardHealth;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.routing.*;
@ -188,7 +189,7 @@ public class ClusterHealthResponsesTests extends ElasticsearchTestCase {
routingTable.add(indexRoutingTable);
}
ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build();
ClusterHealthResponse clusterHealth = new ClusterHealthResponse("bla", clusterState.metaData().concreteIndices(null), clusterState);
ClusterHealthResponse clusterHealth = new ClusterHealthResponse("bla", clusterState.metaData().concreteIndices(null, IndicesOptions.ERROR_UNAVAILABLE_EXPAND_OPEN_CLOSE), clusterState);
logger.info("cluster status: {}, expected {}", clusterHealth.getStatus(), counter.status());
assertClusterHealth(clusterHealth, counter);
@ -209,7 +210,7 @@ public class ClusterHealthResponsesTests extends ElasticsearchTestCase {
metaData.put(indexMetaData, true);
routingTable.add(indexRoutingTable);
ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable).build();
ClusterHealthResponse clusterHealth = new ClusterHealthResponse("bla", clusterState.metaData().concreteIndices(null), clusterState);
ClusterHealthResponse clusterHealth = new ClusterHealthResponse("bla", clusterState.metaData().concreteIndices(null, IndicesOptions.ERROR_UNAVAILABLE_EXPAND_OPEN_CLOSE), clusterState);
// currently we have no cluster level validation failures as index validation issues are reported per index.
assertThat(clusterHealth.getValidationFailures(), Matchers.hasSize(0));
}