Resolve index names to Index instances early

Today index names are often resolved lazily, only when they are really
needed. This can be problematic especially when it gets to mapping updates
etc. when a node sends a mapping update to the master but while the request
is in-flight the index changes for whatever reason we would still apply the update
since we use the name of the index to identify the index in the clusterstate.
The problem is that index names can be reused which happens in practice and sometimes
even in a automated way rendering this problem as realistic.
In this change we resolve the index including it's UUID as early as possible in places
where changes to the clusterstate are possible. For instance mapping updates on a node use a
concrete index rather than it's name and the master will fail the mapping update iff
the index can't be found by it's <name, uuid> tuple.

Closes #17048
This commit is contained in:
Simon Willnauer 2016-03-08 12:50:41 +01:00
parent c90b4f3bae
commit 31740e279f
101 changed files with 629 additions and 555 deletions

View File

@ -213,7 +213,7 @@ public class TransportClusterHealthAction extends TransportMasterNodeReadAction<
} }
if (request.indices() != null && request.indices().length > 0) { if (request.indices() != null && request.indices().length > 0) {
try { try {
indexNameExpressionResolver.concreteIndices(clusterState, IndicesOptions.strictExpand(), request.indices()); indexNameExpressionResolver.concreteIndexNames(clusterState, IndicesOptions.strictExpand(), request.indices());
waitForCounter++; waitForCounter++;
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
response.setStatus(ClusterHealthStatus.RED); // no indices, make sure its RED response.setStatus(ClusterHealthStatus.RED); // no indices, make sure its RED
@ -280,7 +280,7 @@ public class TransportClusterHealthAction extends TransportMasterNodeReadAction<
String[] concreteIndices; String[] concreteIndices;
try { try {
concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request); concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request);
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
// one of the specified indices is not there - treat it as RED. // one of the specified indices is not there - treat it as RED.
ClusterHealthResponse response = new ClusterHealthResponse(clusterName.value(), Strings.EMPTY_ARRAY, clusterState, ClusterHealthResponse response = new ClusterHealthResponse(clusterName.value(), Strings.EMPTY_ARRAY, clusterState,

View File

@ -235,7 +235,7 @@ public class NodeStats extends BaseNodeResponse implements ToXContent {
breaker = AllCircuitBreakerStats.readOptionalAllCircuitBreakerStats(in); breaker = AllCircuitBreakerStats.readOptionalAllCircuitBreakerStats(in);
scriptStats = in.readOptionalStreamable(ScriptStats::new); scriptStats = in.readOptionalStreamable(ScriptStats::new);
discoveryStats = in.readOptionalStreamable(() -> new DiscoveryStats(null)); discoveryStats = in.readOptionalStreamable(() -> new DiscoveryStats(null));
ingestStats = in.readOptionalWritable(IngestStats.PROTO); ingestStats = in.readOptionalWritable(IngestStats.PROTO::readFrom);
} }
@Override @Override

View File

@ -67,7 +67,7 @@ public class ClusterSearchShardsGroup implements Streamable, ToXContent {
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
index = Index.readIndex(in); index = new Index(in);
shardId = in.readVInt(); shardId = in.readVInt();
shards = new ShardRouting[in.readVInt()]; shards = new ShardRouting[in.readVInt()];
for (int i = 0; i < shards.length; i++) { for (int i = 0; i < shards.length; i++) {

View File

@ -59,7 +59,7 @@ public class TransportClusterSearchShardsAction extends TransportMasterNodeReadA
@Override @Override
protected ClusterBlockException checkBlock(ClusterSearchShardsRequest request, ClusterState state) { protected ClusterBlockException checkBlock(ClusterSearchShardsRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndices(state, request)); return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request));
} }
@Override @Override
@ -70,7 +70,7 @@ public class TransportClusterSearchShardsAction extends TransportMasterNodeReadA
@Override @Override
protected void masterOperation(final ClusterSearchShardsRequest request, final ClusterState state, final ActionListener<ClusterSearchShardsResponse> listener) { protected void masterOperation(final ClusterSearchShardsRequest request, final ClusterState state, final ActionListener<ClusterSearchShardsResponse> listener) {
ClusterState clusterState = clusterService.state(); ClusterState clusterState = clusterService.state();
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request);
Map<String, Set<String>> routingMap = indexNameExpressionResolver.resolveSearchRouting(state, request.routing(), request.indices()); Map<String, Set<String>> routingMap = indexNameExpressionResolver.resolveSearchRouting(state, request.routing(), request.indices());
Set<String> nodeIds = new HashSet<>(); Set<String> nodeIds = new HashSet<>();
GroupShardsIterator groupShardsIterator = clusterService.operationRouting().searchShards(clusterState, concreteIndices, routingMap, request.preference()); GroupShardsIterator groupShardsIterator = clusterService.operationRouting().searchShards(clusterState, concreteIndices, routingMap, request.preference());

View File

@ -66,7 +66,7 @@ public class TransportCreateSnapshotAction extends TransportMasterNodeAction<Cre
if (clusterBlockException != null) { if (clusterBlockException != null) {
return clusterBlockException; return clusterBlockException;
} }
return state.blocks().indicesBlockedException(ClusterBlockLevel.READ, indexNameExpressionResolver.concreteIndices(state, request)); return state.blocks().indicesBlockedException(ClusterBlockLevel.READ, indexNameExpressionResolver.concreteIndexNames(state, request));
} }
@Override @Override

View File

@ -106,7 +106,7 @@ public class TransportClusterStateAction extends TransportMasterNodeReadAction<C
} }
if (request.indices().length > 0) { if (request.indices().length > 0) {
String[] indices = indexNameExpressionResolver.concreteIndices(currentState, request); String[] indices = indexNameExpressionResolver.concreteIndexNames(currentState, request);
for (String filteredIndex : indices) { for (String filteredIndex : indices) {
IndexMetaData indexMetaData = currentState.metaData().index(filteredIndex); IndexMetaData indexMetaData = currentState.metaData().index(filteredIndex);
if (indexMetaData != null) { if (indexMetaData != null) {

View File

@ -90,11 +90,11 @@ public class TransportIndicesAliasesAction extends TransportMasterNodeAction<Ind
Set<String> aliases = new HashSet<>(); Set<String> aliases = new HashSet<>();
for (AliasActions action : actions) { for (AliasActions action : actions) {
//expand indices //expand indices
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request.indicesOptions(), action.indices()); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request.indicesOptions(), action.indices());
//collect the aliases //collect the aliases
Collections.addAll(aliases, action.aliases()); Collections.addAll(aliases, action.aliases());
for (String index : concreteIndices) { for (String index : concreteIndices) {
for (String alias : action.concreteAliases(state.metaData(), index)) { for (String alias : action.concreteAliases(state.metaData(), index)) {
AliasAction finalAction = new AliasAction(action.aliasAction()); AliasAction finalAction = new AliasAction(action.aliasAction());
finalAction.index(index); finalAction.index(index);
finalAction.alias(alias); finalAction.alias(alias);

View File

@ -50,7 +50,7 @@ public class TransportAliasesExistAction extends TransportMasterNodeReadAction<G
@Override @Override
protected ClusterBlockException checkBlock(GetAliasesRequest request, ClusterState state) { protected ClusterBlockException checkBlock(GetAliasesRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndices(state, request)); return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request));
} }
@Override @Override
@ -60,7 +60,7 @@ public class TransportAliasesExistAction extends TransportMasterNodeReadAction<G
@Override @Override
protected void masterOperation(GetAliasesRequest request, ClusterState state, ActionListener<AliasesExistResponse> listener) { protected void masterOperation(GetAliasesRequest request, ClusterState state, ActionListener<AliasesExistResponse> listener) {
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request);
boolean result = state.metaData().hasAliases(request.aliases(), concreteIndices); boolean result = state.metaData().hasAliases(request.aliases(), concreteIndices);
listener.onResponse(new AliasesExistResponse(result)); listener.onResponse(new AliasesExistResponse(result));
} }

View File

@ -53,7 +53,7 @@ public class TransportGetAliasesAction extends TransportMasterNodeReadAction<Get
@Override @Override
protected ClusterBlockException checkBlock(GetAliasesRequest request, ClusterState state) { protected ClusterBlockException checkBlock(GetAliasesRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndices(state, request)); return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request));
} }
@Override @Override
@ -63,7 +63,7 @@ public class TransportGetAliasesAction extends TransportMasterNodeReadAction<Get
@Override @Override
protected void masterOperation(GetAliasesRequest request, ClusterState state, ActionListener<GetAliasesResponse> listener) { protected void masterOperation(GetAliasesRequest request, ClusterState state, ActionListener<GetAliasesResponse> listener) {
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ImmutableOpenMap<String, List<AliasMetaData>> result = (ImmutableOpenMap) state.metaData().findAliases(request.aliases(), concreteIndices); ImmutableOpenMap<String, List<AliasMetaData>> result = (ImmutableOpenMap) state.metaData().findAliases(request.aliases(), concreteIndices);
listener.onResponse(new GetAliasesResponse(result)); listener.onResponse(new GetAliasesResponse(result));

View File

@ -35,6 +35,7 @@ import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.tasks.Task; import org.elasticsearch.tasks.Task;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
@ -88,12 +89,12 @@ public class TransportCloseIndexAction extends TransportMasterNodeAction<CloseIn
@Override @Override
protected ClusterBlockException checkBlock(CloseIndexRequest request, ClusterState state) { protected ClusterBlockException checkBlock(CloseIndexRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indexNameExpressionResolver.concreteIndices(state, request)); return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indexNameExpressionResolver.concreteIndexNames(state, request));
} }
@Override @Override
protected void masterOperation(final CloseIndexRequest request, final ClusterState state, final ActionListener<CloseIndexResponse> listener) { protected void masterOperation(final CloseIndexRequest request, final ClusterState state, final ActionListener<CloseIndexResponse> listener) {
final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request);
CloseIndexClusterStateUpdateRequest updateRequest = new CloseIndexClusterStateUpdateRequest() CloseIndexClusterStateUpdateRequest updateRequest = new CloseIndexClusterStateUpdateRequest()
.ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout()) .ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout())
.indices(concreteIndices); .indices(concreteIndices);

View File

@ -31,10 +31,15 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.metadata.MetaDataDeleteIndexService; import org.elasticsearch.cluster.metadata.MetaDataDeleteIndexService;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.tasks.Task; import org.elasticsearch.tasks.Task;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/** /**
* Delete index action. * Delete index action.
*/ */
@ -70,13 +75,13 @@ public class TransportDeleteIndexAction extends TransportMasterNodeAction<Delete
@Override @Override
protected ClusterBlockException checkBlock(DeleteIndexRequest request, ClusterState state) { protected ClusterBlockException checkBlock(DeleteIndexRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indexNameExpressionResolver.concreteIndices(state, request)); return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indexNameExpressionResolver.concreteIndexNames(state, request));
} }
@Override @Override
protected void masterOperation(final DeleteIndexRequest request, final ClusterState state, final ActionListener<DeleteIndexResponse> listener) { protected void masterOperation(final DeleteIndexRequest request, final ClusterState state, final ActionListener<DeleteIndexResponse> listener) {
final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); final Set<Index> concreteIndices = new HashSet<>(Arrays.asList(indexNameExpressionResolver.concreteIndices(state, request)));
if (concreteIndices.length == 0) { if (concreteIndices.isEmpty()) {
listener.onResponse(new DeleteIndexResponse(true)); listener.onResponse(new DeleteIndexResponse(true));
return; return;
} }

View File

@ -60,7 +60,7 @@ public class TransportIndicesExistsAction extends TransportMasterNodeReadAction<
protected ClusterBlockException checkBlock(IndicesExistsRequest request, ClusterState state) { protected ClusterBlockException checkBlock(IndicesExistsRequest request, ClusterState state) {
//make sure through indices options that the concrete indices call never throws IndexMissingException //make sure through indices options that the concrete indices call never throws IndexMissingException
IndicesOptions indicesOptions = IndicesOptions.fromOptions(true, true, request.indicesOptions().expandWildcardsOpen(), request.indicesOptions().expandWildcardsClosed()); IndicesOptions indicesOptions = IndicesOptions.fromOptions(true, true, request.indicesOptions().expandWildcardsOpen(), request.indicesOptions().expandWildcardsClosed());
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndices(state, indicesOptions, request.indices())); return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, indicesOptions, request.indices()));
} }
@Override @Override
@ -68,7 +68,7 @@ public class TransportIndicesExistsAction extends TransportMasterNodeReadAction<
boolean exists; boolean exists;
try { try {
// Similar as the previous behaviour, but now also aliases and wildcards are supported. // Similar as the previous behaviour, but now also aliases and wildcards are supported.
indexNameExpressionResolver.concreteIndices(state, request); indexNameExpressionResolver.concreteIndexNames(state, request);
exists = true; exists = true;
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
exists = false; exists = false;

View File

@ -57,12 +57,12 @@ public class TransportTypesExistsAction extends TransportMasterNodeReadAction<Ty
@Override @Override
protected ClusterBlockException checkBlock(TypesExistsRequest request, ClusterState state) { protected ClusterBlockException checkBlock(TypesExistsRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndices(state, request)); return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request));
} }
@Override @Override
protected void masterOperation(final TypesExistsRequest request, final ClusterState state, final ActionListener<TypesExistsResponse> listener) { protected void masterOperation(final TypesExistsRequest request, final ClusterState state, final ActionListener<TypesExistsResponse> listener) {
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request.indicesOptions(), request.indices()); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request.indicesOptions(), request.indices());
if (concreteIndices.length == 0) { if (concreteIndices.length == 0) {
listener.onResponse(new TypesExistsResponse(false)); listener.onResponse(new TypesExistsResponse(false));
return; return;

View File

@ -46,10 +46,9 @@ public class TransportShardFlushAction extends TransportReplicationAction<ShardF
@Inject @Inject
public TransportShardFlushAction(Settings settings, TransportService transportService, ClusterService clusterService, public TransportShardFlushAction(Settings settings, TransportService transportService, ClusterService clusterService,
IndicesService indicesService, ThreadPool threadPool, ShardStateAction shardStateAction, IndicesService indicesService, ThreadPool threadPool, ShardStateAction shardStateAction,
MappingUpdatedAction mappingUpdatedAction, ActionFilters actionFilters, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
IndexNameExpressionResolver indexNameExpressionResolver) { super(settings, NAME, transportService, clusterService, indicesService, threadPool, shardStateAction,
super(settings, NAME, transportService, clusterService, indicesService, threadPool, shardStateAction, mappingUpdatedAction, actionFilters, indexNameExpressionResolver, ShardFlushRequest::new, ShardFlushRequest::new, ThreadPool.Names.FLUSH);
actionFilters, indexNameExpressionResolver, ShardFlushRequest::new, ShardFlushRequest::new, ThreadPool.Names.FLUSH);
} }
@Override @Override

View File

@ -60,7 +60,7 @@ public class TransportGetIndexAction extends TransportClusterInfoAction<GetIndex
@Override @Override
protected ClusterBlockException checkBlock(GetIndexRequest request, ClusterState state) { protected ClusterBlockException checkBlock(GetIndexRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndices(state, request)); return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request));
} }
@Override @Override

View File

@ -56,7 +56,7 @@ public class TransportGetFieldMappingsAction extends HandledTransportAction<GetF
@Override @Override
protected void doExecute(GetFieldMappingsRequest request, final ActionListener<GetFieldMappingsResponse> listener) { protected void doExecute(GetFieldMappingsRequest request, final ActionListener<GetFieldMappingsResponse> listener) {
ClusterState clusterState = clusterService.state(); ClusterState clusterState = clusterService.state();
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request);
final AtomicInteger indexCounter = new AtomicInteger(); final AtomicInteger indexCounter = new AtomicInteger();
final AtomicInteger completionCounter = new AtomicInteger(concreteIndices.length); final AtomicInteger completionCounter = new AtomicInteger(concreteIndices.length);
final AtomicReferenceArray<Object> indexResponses = new AtomicReferenceArray<>(concreteIndices.length); final AtomicReferenceArray<Object> indexResponses = new AtomicReferenceArray<>(concreteIndices.length);

View File

@ -52,7 +52,7 @@ public class TransportGetMappingsAction extends TransportClusterInfoAction<GetMa
@Override @Override
protected ClusterBlockException checkBlock(GetMappingsRequest request, ClusterState state) { protected ClusterBlockException checkBlock(GetMappingsRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndices(state, request)); return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request));
} }
@Override @Override

View File

@ -32,9 +32,11 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.Index;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import static org.elasticsearch.action.ValidateActions.addValidationError; import static org.elasticsearch.action.ValidateActions.addValidationError;
@ -65,6 +67,7 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
private String source; private String source;
private boolean updateAllTypes = false; private boolean updateAllTypes = false;
private Index concreteIndex;
public PutMappingRequest() { public PutMappingRequest() {
} }
@ -90,6 +93,9 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
} else if (source.isEmpty()) { } else if (source.isEmpty()) {
validationException = addValidationError("mapping source is empty", validationException); validationException = addValidationError("mapping source is empty", validationException);
} }
if (concreteIndex != null && (indices != null && indices.length > 0)) {
validationException = addValidationError("either concreteIndices or unresolved indices can be set", validationException);
}
return validationException; return validationException;
} }
@ -102,6 +108,22 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
return this; return this;
} }
/**
* Sets a concrete index for this put mapping request.
*/
public PutMappingRequest setConcreteIndex(Index index) {
Objects.requireNonNull(indices, "index must not be null");
this.concreteIndex = index;
return this;
}
/**
* Returns a concrete index for this mapping or <code>null</code> if no concrete index is defined
*/
public Index getConcreteIndex() {
return concreteIndex;
}
/** /**
* The indices the mappings will be put. * The indices the mappings will be put.
*/ */
@ -259,6 +281,7 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
source = in.readString(); source = in.readString();
updateAllTypes = in.readBoolean(); updateAllTypes = in.readBoolean();
readTimeout(in); readTimeout(in);
concreteIndex = in.readOptionalWritable(Index::new);
} }
@Override @Override
@ -270,5 +293,6 @@ public class PutMappingRequest extends AcknowledgedRequest<PutMappingRequest> im
out.writeString(source); out.writeString(source);
out.writeBoolean(updateAllTypes); out.writeBoolean(updateAllTypes);
writeTimeout(out); writeTimeout(out);
out.writeOptionalWriteable(concreteIndex);
} }
} }

View File

@ -23,6 +23,7 @@ import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder; import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.Index;
import java.util.Map; import java.util.Map;
@ -40,6 +41,11 @@ public class PutMappingRequestBuilder extends AcknowledgedRequestBuilder<PutMapp
return this; return this;
} }
public PutMappingRequestBuilder setConcreteIndex(Index index) {
request.setConcreteIndex(index);
return this;
}
/** /**
* Specifies what type of requested indices to ignore and wildcard indices expressions. * Specifies what type of requested indices to ignore and wildcard indices expressions.
* <p> * <p>

View File

@ -31,6 +31,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.metadata.MetaDataMappingService; import org.elasticsearch.cluster.metadata.MetaDataMappingService;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
@ -63,13 +64,19 @@ public class TransportPutMappingAction extends TransportMasterNodeAction<PutMapp
@Override @Override
protected ClusterBlockException checkBlock(PutMappingRequest request, ClusterState state) { protected ClusterBlockException checkBlock(PutMappingRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indexNameExpressionResolver.concreteIndices(state, request)); String[] indices;
if (request.getConcreteIndex() == null) {
indices = indexNameExpressionResolver.concreteIndexNames(state, request);
} else {
indices = new String[] {request.getConcreteIndex().getName()};
}
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indices);
} }
@Override @Override
protected void masterOperation(final PutMappingRequest request, final ClusterState state, final ActionListener<PutMappingResponse> listener) { protected void masterOperation(final PutMappingRequest request, final ClusterState state, final ActionListener<PutMappingResponse> listener) {
try { try {
final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); final Index[] concreteIndices = request.getConcreteIndex() == null ? indexNameExpressionResolver.concreteIndices(state, request) : new Index[] {request.getConcreteIndex()};
PutMappingClusterStateUpdateRequest updateRequest = new PutMappingClusterStateUpdateRequest() PutMappingClusterStateUpdateRequest updateRequest = new PutMappingClusterStateUpdateRequest()
.ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout()) .ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout())
.indices(concreteIndices).type(request.type()) .indices(concreteIndices).type(request.type())

View File

@ -32,6 +32,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.metadata.MetaDataIndexStateService; import org.elasticsearch.cluster.metadata.MetaDataIndexStateService;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.tasks.Task; import org.elasticsearch.tasks.Task;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
@ -73,12 +74,12 @@ public class TransportOpenIndexAction extends TransportMasterNodeAction<OpenInde
@Override @Override
protected ClusterBlockException checkBlock(OpenIndexRequest request, ClusterState state) { protected ClusterBlockException checkBlock(OpenIndexRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indexNameExpressionResolver.concreteIndices(state, request)); return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indexNameExpressionResolver.concreteIndexNames(state, request));
} }
@Override @Override
protected void masterOperation(final OpenIndexRequest request, final ClusterState state, final ActionListener<OpenIndexResponse> listener) { protected void masterOperation(final OpenIndexRequest request, final ClusterState state, final ActionListener<OpenIndexResponse> listener) {
final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request);
OpenIndexClusterStateUpdateRequest updateRequest = new OpenIndexClusterStateUpdateRequest() OpenIndexClusterStateUpdateRequest updateRequest = new OpenIndexClusterStateUpdateRequest()
.ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout()) .ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout())
.indices(concreteIndices); .indices(concreteIndices);

View File

@ -48,10 +48,9 @@ public class TransportShardRefreshAction extends TransportReplicationAction<Basi
@Inject @Inject
public TransportShardRefreshAction(Settings settings, TransportService transportService, ClusterService clusterService, public TransportShardRefreshAction(Settings settings, TransportService transportService, ClusterService clusterService,
IndicesService indicesService, ThreadPool threadPool, ShardStateAction shardStateAction, IndicesService indicesService, ThreadPool threadPool, ShardStateAction shardStateAction,
MappingUpdatedAction mappingUpdatedAction, ActionFilters actionFilters, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
IndexNameExpressionResolver indexNameExpressionResolver) { super(settings, NAME, transportService, clusterService, indicesService, threadPool, shardStateAction,
super(settings, NAME, transportService, clusterService, indicesService, threadPool, shardStateAction, mappingUpdatedAction, actionFilters, indexNameExpressionResolver, BasicReplicationRequest::new, BasicReplicationRequest::new, ThreadPool.Names.REFRESH);
actionFilters, indexNameExpressionResolver, BasicReplicationRequest::new, BasicReplicationRequest::new, ThreadPool.Names.REFRESH);
} }
@Override @Override

View File

@ -34,6 +34,7 @@ import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.util.CollectionUtils; import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.index.Index;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
@ -61,7 +62,7 @@ public class TransportGetSettingsAction extends TransportMasterNodeReadAction<Ge
@Override @Override
protected ClusterBlockException checkBlock(GetSettingsRequest request, ClusterState state) { protected ClusterBlockException checkBlock(GetSettingsRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndices(state, request)); return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request));
} }
@ -72,9 +73,9 @@ public class TransportGetSettingsAction extends TransportMasterNodeReadAction<Ge
@Override @Override
protected void masterOperation(GetSettingsRequest request, ClusterState state, ActionListener<GetSettingsResponse> listener) { protected void masterOperation(GetSettingsRequest request, ClusterState state, ActionListener<GetSettingsResponse> listener) {
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request);
ImmutableOpenMap.Builder<String, Settings> indexToSettingsBuilder = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder<String, Settings> indexToSettingsBuilder = ImmutableOpenMap.builder();
for (String concreteIndex : concreteIndices) { for (Index concreteIndex : concreteIndices) {
IndexMetaData indexMetaData = state.getMetaData().index(concreteIndex); IndexMetaData indexMetaData = state.getMetaData().index(concreteIndex);
if (indexMetaData == null) { if (indexMetaData == null) {
continue; continue;
@ -93,7 +94,7 @@ public class TransportGetSettingsAction extends TransportMasterNodeReadAction<Ge
} }
settings = settingsBuilder.build(); settings = settingsBuilder.build();
} }
indexToSettingsBuilder.put(concreteIndex, settings); indexToSettingsBuilder.put(concreteIndex.getName(), settings);
} }
listener.onResponse(new GetSettingsResponse(indexToSettingsBuilder.build())); listener.onResponse(new GetSettingsResponse(indexToSettingsBuilder.build()));
} }

View File

@ -32,6 +32,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.metadata.MetaDataUpdateSettingsService; import org.elasticsearch.cluster.metadata.MetaDataUpdateSettingsService;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
@ -65,7 +66,7 @@ public class TransportUpdateSettingsAction extends TransportMasterNodeAction<Upd
if (request.settings().getAsMap().size() == 1 && IndexMetaData.INDEX_BLOCKS_METADATA_SETTING.exists(request.settings()) || IndexMetaData.INDEX_READ_ONLY_SETTING.exists(request.settings())) { if (request.settings().getAsMap().size() == 1 && IndexMetaData.INDEX_BLOCKS_METADATA_SETTING.exists(request.settings()) || IndexMetaData.INDEX_READ_ONLY_SETTING.exists(request.settings())) {
return null; return null;
} }
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indexNameExpressionResolver.concreteIndices(state, request)); return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indexNameExpressionResolver.concreteIndexNames(state, request));
} }
@Override @Override
@ -75,7 +76,7 @@ public class TransportUpdateSettingsAction extends TransportMasterNodeAction<Upd
@Override @Override
protected void masterOperation(final UpdateSettingsRequest request, final ClusterState state, final ActionListener<UpdateSettingsResponse> listener) { protected void masterOperation(final UpdateSettingsRequest request, final ClusterState state, final ActionListener<UpdateSettingsResponse> listener) {
final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request);
UpdateSettingsClusterStateUpdateRequest clusterStateUpdateRequest = new UpdateSettingsClusterStateUpdateRequest() UpdateSettingsClusterStateUpdateRequest clusterStateUpdateRequest = new UpdateSettingsClusterStateUpdateRequest()
.indices(concreteIndices) .indices(concreteIndices)
.settings(request.settings()) .settings(request.settings())

View File

@ -87,7 +87,7 @@ public class TransportIndicesShardStoresAction extends TransportMasterNodeReadAc
protected void masterOperation(IndicesShardStoresRequest request, ClusterState state, ActionListener<IndicesShardStoresResponse> listener) { protected void masterOperation(IndicesShardStoresRequest request, ClusterState state, ActionListener<IndicesShardStoresResponse> listener) {
final RoutingTable routingTables = state.routingTable(); final RoutingTable routingTables = state.routingTable();
final RoutingNodes routingNodes = state.getRoutingNodes(); final RoutingNodes routingNodes = state.getRoutingNodes();
final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); final String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request);
final Set<ShardId> shardIdsToFetch = new HashSet<>(); final Set<ShardId> shardIdsToFetch = new HashSet<>();
logger.trace("using cluster state version [{}] to determine shards", state.version()); logger.trace("using cluster state version [{}] to determine shards", state.version());
@ -115,7 +115,7 @@ public class TransportIndicesShardStoresAction extends TransportMasterNodeReadAc
@Override @Override
protected ClusterBlockException checkBlock(IndicesShardStoresRequest request, ClusterState state) { protected ClusterBlockException checkBlock(IndicesShardStoresRequest request, ClusterState state) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndices(state, request)); return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request));
} }
private class AsyncShardStoresInfoFetches { private class AsyncShardStoresInfoFetches {

View File

@ -47,6 +47,7 @@ import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.AtomicArray; import org.elasticsearch.common.util.concurrent.AtomicArray;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.IndexAlreadyExistsException; import org.elasticsearch.indices.IndexAlreadyExistsException;
@ -245,17 +246,18 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
if (addFailureIfIndexIsUnavailable(documentRequest, bulkRequest, responses, i, concreteIndices, metaData)) { if (addFailureIfIndexIsUnavailable(documentRequest, bulkRequest, responses, i, concreteIndices, metaData)) {
continue; continue;
} }
String concreteIndex = concreteIndices.resolveIfAbsent(documentRequest); Index concreteIndex = concreteIndices.resolveIfAbsent(documentRequest);
if (request instanceof IndexRequest) { if (request instanceof IndexRequest) {
IndexRequest indexRequest = (IndexRequest) request; IndexRequest indexRequest = (IndexRequest) request;
MappingMetaData mappingMd = null; MappingMetaData mappingMd = null;
if (metaData.hasIndex(concreteIndex)) { final IndexMetaData indexMetaData = metaData.index(concreteIndex);
mappingMd = metaData.index(concreteIndex).mappingOrDefault(indexRequest.type()); if (indexMetaData != null) {
mappingMd = indexMetaData.mappingOrDefault(indexRequest.type());
} }
try { try {
indexRequest.process(metaData, mappingMd, allowIdGeneration, concreteIndex); indexRequest.process(metaData, mappingMd, allowIdGeneration, concreteIndex.getName());
} catch (ElasticsearchParseException | RoutingMissingException e) { } catch (ElasticsearchParseException | RoutingMissingException e) {
BulkItemResponse.Failure failure = new BulkItemResponse.Failure(concreteIndex, indexRequest.type(), indexRequest.id(), e); BulkItemResponse.Failure failure = new BulkItemResponse.Failure(concreteIndex.getName(), indexRequest.type(), indexRequest.id(), e);
BulkItemResponse bulkItemResponse = new BulkItemResponse(i, "index", failure); BulkItemResponse bulkItemResponse = new BulkItemResponse(i, "index", failure);
responses.set(i, bulkItemResponse); responses.set(i, bulkItemResponse);
// make sure the request gets never processed again // make sure the request gets never processed again
@ -263,9 +265,9 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
} }
} else if (request instanceof DeleteRequest) { } else if (request instanceof DeleteRequest) {
try { try {
TransportDeleteAction.resolveAndValidateRouting(metaData, concreteIndex, (DeleteRequest)request); TransportDeleteAction.resolveAndValidateRouting(metaData, concreteIndex.getName(), (DeleteRequest)request);
} catch(RoutingMissingException e) { } catch(RoutingMissingException e) {
BulkItemResponse.Failure failure = new BulkItemResponse.Failure(concreteIndex, documentRequest.type(), documentRequest.id(), e); BulkItemResponse.Failure failure = new BulkItemResponse.Failure(concreteIndex.getName(), documentRequest.type(), documentRequest.id(), e);
BulkItemResponse bulkItemResponse = new BulkItemResponse(i, "delete", failure); BulkItemResponse bulkItemResponse = new BulkItemResponse(i, "delete", failure);
responses.set(i, bulkItemResponse); responses.set(i, bulkItemResponse);
// make sure the request gets never processed again // make sure the request gets never processed again
@ -274,9 +276,9 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
} else if (request instanceof UpdateRequest) { } else if (request instanceof UpdateRequest) {
try { try {
TransportUpdateAction.resolveAndValidateRouting(metaData, concreteIndex, (UpdateRequest)request); TransportUpdateAction.resolveAndValidateRouting(metaData, concreteIndex.getName(), (UpdateRequest)request);
} catch(RoutingMissingException e) { } catch(RoutingMissingException e) {
BulkItemResponse.Failure failure = new BulkItemResponse.Failure(concreteIndex, documentRequest.type(), documentRequest.id(), e); BulkItemResponse.Failure failure = new BulkItemResponse.Failure(concreteIndex.getName(), documentRequest.type(), documentRequest.id(), e);
BulkItemResponse bulkItemResponse = new BulkItemResponse(i, "update", failure); BulkItemResponse bulkItemResponse = new BulkItemResponse(i, "update", failure);
responses.set(i, bulkItemResponse); responses.set(i, bulkItemResponse);
// make sure the request gets never processed again // make sure the request gets never processed again
@ -294,7 +296,7 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
ActionRequest request = bulkRequest.requests.get(i); ActionRequest request = bulkRequest.requests.get(i);
if (request instanceof IndexRequest) { if (request instanceof IndexRequest) {
IndexRequest indexRequest = (IndexRequest) request; IndexRequest indexRequest = (IndexRequest) request;
String concreteIndex = concreteIndices.getConcreteIndex(indexRequest.index()); String concreteIndex = concreteIndices.getConcreteIndex(indexRequest.index()).getName();
ShardId shardId = clusterService.operationRouting().indexShards(clusterState, concreteIndex, indexRequest.type(), indexRequest.id(), indexRequest.routing()).shardId(); ShardId shardId = clusterService.operationRouting().indexShards(clusterState, concreteIndex, indexRequest.type(), indexRequest.id(), indexRequest.routing()).shardId();
List<BulkItemRequest> list = requestsByShard.get(shardId); List<BulkItemRequest> list = requestsByShard.get(shardId);
if (list == null) { if (list == null) {
@ -304,7 +306,7 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
list.add(new BulkItemRequest(i, request)); list.add(new BulkItemRequest(i, request));
} else if (request instanceof DeleteRequest) { } else if (request instanceof DeleteRequest) {
DeleteRequest deleteRequest = (DeleteRequest) request; DeleteRequest deleteRequest = (DeleteRequest) request;
String concreteIndex = concreteIndices.getConcreteIndex(deleteRequest.index()); String concreteIndex = concreteIndices.getConcreteIndex(deleteRequest.index()).getName();
ShardId shardId = clusterService.operationRouting().indexShards(clusterState, concreteIndex, deleteRequest.type(), deleteRequest.id(), deleteRequest.routing()).shardId(); ShardId shardId = clusterService.operationRouting().indexShards(clusterState, concreteIndex, deleteRequest.type(), deleteRequest.id(), deleteRequest.routing()).shardId();
List<BulkItemRequest> list = requestsByShard.get(shardId); List<BulkItemRequest> list = requestsByShard.get(shardId);
if (list == null) { if (list == null) {
@ -314,7 +316,7 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
list.add(new BulkItemRequest(i, request)); list.add(new BulkItemRequest(i, request));
} else if (request instanceof UpdateRequest) { } else if (request instanceof UpdateRequest) {
UpdateRequest updateRequest = (UpdateRequest) request; UpdateRequest updateRequest = (UpdateRequest) request;
String concreteIndex = concreteIndices.getConcreteIndex(updateRequest.index()); String concreteIndex = concreteIndices.getConcreteIndex(updateRequest.index()).getName();
ShardId shardId = clusterService.operationRouting().indexShards(clusterState, concreteIndex, updateRequest.type(), updateRequest.id(), updateRequest.routing()).shardId(); ShardId shardId = clusterService.operationRouting().indexShards(clusterState, concreteIndex, updateRequest.type(), updateRequest.id(), updateRequest.routing()).shardId();
List<BulkItemRequest> list = requestsByShard.get(shardId); List<BulkItemRequest> list = requestsByShard.get(shardId);
if (list == null) { if (list == null) {
@ -356,18 +358,19 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
public void onFailure(Throwable e) { public void onFailure(Throwable e) {
// create failures for all relevant requests // create failures for all relevant requests
for (BulkItemRequest request : requests) { for (BulkItemRequest request : requests) {
final String indexName = concreteIndices.getConcreteIndex(request.index()).getName();
if (request.request() instanceof IndexRequest) { if (request.request() instanceof IndexRequest) {
IndexRequest indexRequest = (IndexRequest) request.request(); IndexRequest indexRequest = (IndexRequest) request.request();
responses.set(request.id(), new BulkItemResponse(request.id(), indexRequest.opType().toString().toLowerCase(Locale.ENGLISH), responses.set(request.id(), new BulkItemResponse(request.id(), indexRequest.opType().toString().toLowerCase(Locale.ENGLISH),
new BulkItemResponse.Failure(concreteIndices.getConcreteIndex(indexRequest.index()), indexRequest.type(), indexRequest.id(), e))); new BulkItemResponse.Failure(indexName, indexRequest.type(), indexRequest.id(), e)));
} else if (request.request() instanceof DeleteRequest) { } else if (request.request() instanceof DeleteRequest) {
DeleteRequest deleteRequest = (DeleteRequest) request.request(); DeleteRequest deleteRequest = (DeleteRequest) request.request();
responses.set(request.id(), new BulkItemResponse(request.id(), "delete", responses.set(request.id(), new BulkItemResponse(request.id(), "delete",
new BulkItemResponse.Failure(concreteIndices.getConcreteIndex(deleteRequest.index()), deleteRequest.type(), deleteRequest.id(), e))); new BulkItemResponse.Failure(indexName, deleteRequest.type(), deleteRequest.id(), e)));
} else if (request.request() instanceof UpdateRequest) { } else if (request.request() instanceof UpdateRequest) {
UpdateRequest updateRequest = (UpdateRequest) request.request(); UpdateRequest updateRequest = (UpdateRequest) request.request();
responses.set(request.id(), new BulkItemResponse(request.id(), "update", responses.set(request.id(), new BulkItemResponse(request.id(), "update",
new BulkItemResponse.Failure(concreteIndices.getConcreteIndex(updateRequest.index()), updateRequest.type(), updateRequest.id(), e))); new BulkItemResponse.Failure(indexName, updateRequest.type(), updateRequest.id(), e)));
} }
} }
if (counter.decrementAndGet() == 0) { if (counter.decrementAndGet() == 0) {
@ -385,7 +388,7 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
private boolean addFailureIfIndexIsUnavailable(DocumentRequest request, BulkRequest bulkRequest, AtomicArray<BulkItemResponse> responses, int idx, private boolean addFailureIfIndexIsUnavailable(DocumentRequest request, BulkRequest bulkRequest, AtomicArray<BulkItemResponse> responses, int idx,
final ConcreteIndices concreteIndices, final ConcreteIndices concreteIndices,
final MetaData metaData) { final MetaData metaData) {
String concreteIndex = concreteIndices.getConcreteIndex(request.index()); Index concreteIndex = concreteIndices.getConcreteIndex(request.index());
Exception unavailableException = null; Exception unavailableException = null;
if (concreteIndex == null) { if (concreteIndex == null) {
try { try {
@ -397,9 +400,9 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
} }
} }
if (unavailableException == null) { if (unavailableException == null) {
IndexMetaData indexMetaData = metaData.index(concreteIndex); IndexMetaData indexMetaData = metaData.getIndexSafe(concreteIndex);
if (indexMetaData.getState() == IndexMetaData.State.CLOSE) { if (indexMetaData.getState() == IndexMetaData.State.CLOSE) {
unavailableException = new IndexClosedException(metaData.index(request.index()).getIndex()); unavailableException = new IndexClosedException(concreteIndex);
} }
} }
if (unavailableException != null) { if (unavailableException != null) {
@ -425,19 +428,19 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
private static class ConcreteIndices { private static class ConcreteIndices {
private final ClusterState state; private final ClusterState state;
private final IndexNameExpressionResolver indexNameExpressionResolver; private final IndexNameExpressionResolver indexNameExpressionResolver;
private final Map<String, String> indices = new HashMap<>(); private final Map<String, Index> indices = new HashMap<>();
ConcreteIndices(ClusterState state, IndexNameExpressionResolver indexNameExpressionResolver) { ConcreteIndices(ClusterState state, IndexNameExpressionResolver indexNameExpressionResolver) {
this.state = state; this.state = state;
this.indexNameExpressionResolver = indexNameExpressionResolver; this.indexNameExpressionResolver = indexNameExpressionResolver;
} }
String getConcreteIndex(String indexOrAlias) { Index getConcreteIndex(String indexOrAlias) {
return indices.get(indexOrAlias); return indices.get(indexOrAlias);
} }
String resolveIfAbsent(DocumentRequest request) { Index resolveIfAbsent(DocumentRequest request) {
String concreteIndex = indices.get(request.index()); Index concreteIndex = indices.get(request.index());
if (concreteIndex == null) { if (concreteIndex == null) {
concreteIndex = indexNameExpressionResolver.concreteSingleIndex(state, request); concreteIndex = indexNameExpressionResolver.concreteSingleIndex(state, request);
indices.put(request.index(), concreteIndex); indices.put(request.index(), concreteIndex);

View File

@ -47,7 +47,6 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexService; import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.VersionType; import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.engine.Engine;
@ -75,17 +74,19 @@ public class TransportShardBulkAction extends TransportReplicationAction<BulkSha
private final UpdateHelper updateHelper; private final UpdateHelper updateHelper;
private final boolean allowIdGeneration; private final boolean allowIdGeneration;
private final MappingUpdatedAction mappingUpdatedAction;
@Inject @Inject
public TransportShardBulkAction(Settings settings, TransportService transportService, ClusterService clusterService, public TransportShardBulkAction(Settings settings, TransportService transportService, ClusterService clusterService,
IndicesService indicesService, ThreadPool threadPool, ShardStateAction shardStateAction, IndicesService indicesService, ThreadPool threadPool, ShardStateAction shardStateAction,
MappingUpdatedAction mappingUpdatedAction, UpdateHelper updateHelper, ActionFilters actionFilters, MappingUpdatedAction mappingUpdatedAction, UpdateHelper updateHelper, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver) { IndexNameExpressionResolver indexNameExpressionResolver) {
super(settings, ACTION_NAME, transportService, clusterService, indicesService, threadPool, shardStateAction, mappingUpdatedAction, super(settings, ACTION_NAME, transportService, clusterService, indicesService, threadPool, shardStateAction,
actionFilters, indexNameExpressionResolver, actionFilters, indexNameExpressionResolver,
BulkShardRequest::new, BulkShardRequest::new, ThreadPool.Names.BULK); BulkShardRequest::new, BulkShardRequest::new, ThreadPool.Names.BULK);
this.updateHelper = updateHelper; this.updateHelper = updateHelper;
this.allowIdGeneration = settings.getAsBoolean("action.allow_id_generation", true); this.allowIdGeneration = settings.getAsBoolean("action.allow_id_generation", true);
this.mappingUpdatedAction = mappingUpdatedAction;
} }
@Override @Override

View File

@ -60,10 +60,10 @@ public class TransportDeleteAction extends TransportReplicationAction<DeleteRequ
public TransportDeleteAction(Settings settings, TransportService transportService, ClusterService clusterService, public TransportDeleteAction(Settings settings, TransportService transportService, ClusterService clusterService,
IndicesService indicesService, ThreadPool threadPool, ShardStateAction shardStateAction, IndicesService indicesService, ThreadPool threadPool, ShardStateAction shardStateAction,
TransportCreateIndexAction createIndexAction, ActionFilters actionFilters, TransportCreateIndexAction createIndexAction, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver, MappingUpdatedAction mappingUpdatedAction, IndexNameExpressionResolver indexNameExpressionResolver,
AutoCreateIndex autoCreateIndex) { AutoCreateIndex autoCreateIndex) {
super(settings, DeleteAction.NAME, transportService, clusterService, indicesService, threadPool, shardStateAction, super(settings, DeleteAction.NAME, transportService, clusterService, indicesService, threadPool, shardStateAction,
mappingUpdatedAction, actionFilters, indexNameExpressionResolver, actionFilters, indexNameExpressionResolver,
DeleteRequest::new, DeleteRequest::new, ThreadPool.Names.INDEX); DeleteRequest::new, DeleteRequest::new, ThreadPool.Names.INDEX);
this.createIndexAction = createIndexAction; this.createIndexAction = createIndexAction;
this.autoCreateIndex = autoCreateIndex; this.autoCreateIndex = autoCreateIndex;

View File

@ -69,7 +69,7 @@ public class TransportMultiGetAction extends HandledTransportAction<MultiGetRequ
continue; continue;
} }
item.routing(clusterState.metaData().resolveIndexRouting(item.parent(), item.routing(), item.index())); item.routing(clusterState.metaData().resolveIndexRouting(item.parent(), item.routing(), item.index()));
String concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, item); String concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, item).getName();
if (item.routing() == null && clusterState.getMetaData().routingRequired(concreteSingleIndex, item.type())) { if (item.routing() == null && clusterState.getMetaData().routingRequired(concreteSingleIndex, item.type())) {
responses.set(i, new MultiGetItemResponse(null, new MultiGetResponse.Failure(concreteSingleIndex, item.type(), item.id(), responses.set(i, new MultiGetItemResponse(null, new MultiGetResponse.Failure(concreteSingleIndex, item.type(), item.id(),
new IllegalArgumentException("routing is required for [" + concreteSingleIndex + "]/[" + item.type() + "]/[" + item.id() + "]")))); new IllegalArgumentException("routing is required for [" + concreteSingleIndex + "]/[" + item.type() + "]/[" + item.id() + "]"))));

View File

@ -42,6 +42,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.VersionType; import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.mapper.internal.TimestampFieldMapper; import org.elasticsearch.index.mapper.internal.TimestampFieldMapper;
@ -584,14 +585,6 @@ public class IndexRequest extends ReplicationRequest<IndexRequest> implements Do
return this.versionType; return this.versionType;
} }
private Version getVersion(MetaData metaData, String concreteIndex) {
// this can go away in 3.0 but is here now for easy backporting - since in 2.x we need the version on the timestamp stuff
final IndexMetaData indexMetaData = metaData.getIndices().get(concreteIndex);
if (indexMetaData == null) {
throw new IndexNotFoundException(concreteIndex);
}
return Version.indexCreated(indexMetaData.getSettings());
}
public void process(MetaData metaData, @Nullable MappingMetaData mappingMd, boolean allowIdGeneration, String concreteIndex) { public void process(MetaData metaData, @Nullable MappingMetaData mappingMd, boolean allowIdGeneration, String concreteIndex) {
// resolve the routing if needed // resolve the routing if needed
@ -600,8 +593,7 @@ public class IndexRequest extends ReplicationRequest<IndexRequest> implements Do
// resolve timestamp if provided externally // resolve timestamp if provided externally
if (timestamp != null) { if (timestamp != null) {
timestamp = MappingMetaData.Timestamp.parseStringTimestamp(timestamp, timestamp = MappingMetaData.Timestamp.parseStringTimestamp(timestamp,
mappingMd != null ? mappingMd.timestamp().dateTimeFormatter() : TimestampFieldMapper.Defaults.DATE_TIME_FORMATTER, mappingMd != null ? mappingMd.timestamp().dateTimeFormatter() : TimestampFieldMapper.Defaults.DATE_TIME_FORMATTER);
getVersion(metaData, concreteIndex));
} }
if (mappingMd != null) { if (mappingMd != null) {
// might as well check for routing here // might as well check for routing here
@ -645,7 +637,7 @@ public class IndexRequest extends ReplicationRequest<IndexRequest> implements Do
// assigned again because mappingMd and // assigned again because mappingMd and
// mappingMd#timestamp() are not null // mappingMd#timestamp() are not null
assert mappingMd != null; assert mappingMd != null;
timestamp = MappingMetaData.Timestamp.parseStringTimestamp(defaultTimestamp, mappingMd.timestamp().dateTimeFormatter(), getVersion(metaData, concreteIndex)); timestamp = MappingMetaData.Timestamp.parseStringTimestamp(defaultTimestamp, mappingMd.timestamp().dateTimeFormatter());
} }
} }
} }

View File

@ -69,6 +69,7 @@ public class TransportIndexAction extends TransportReplicationAction<IndexReques
private final TransportCreateIndexAction createIndexAction; private final TransportCreateIndexAction createIndexAction;
private final ClusterService clusterService; private final ClusterService clusterService;
private final MappingUpdatedAction mappingUpdatedAction;
@Inject @Inject
public TransportIndexAction(Settings settings, TransportService transportService, ClusterService clusterService, public TransportIndexAction(Settings settings, TransportService transportService, ClusterService clusterService,
@ -76,8 +77,9 @@ public class TransportIndexAction extends TransportReplicationAction<IndexReques
TransportCreateIndexAction createIndexAction, MappingUpdatedAction mappingUpdatedAction, TransportCreateIndexAction createIndexAction, MappingUpdatedAction mappingUpdatedAction,
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
AutoCreateIndex autoCreateIndex) { AutoCreateIndex autoCreateIndex) {
super(settings, IndexAction.NAME, transportService, clusterService, indicesService, threadPool, shardStateAction, mappingUpdatedAction, super(settings, IndexAction.NAME, transportService, clusterService, indicesService, threadPool, shardStateAction,
actionFilters, indexNameExpressionResolver, IndexRequest::new, IndexRequest::new, ThreadPool.Names.INDEX); actionFilters, indexNameExpressionResolver, IndexRequest::new, IndexRequest::new, ThreadPool.Names.INDEX);
this.mappingUpdatedAction = mappingUpdatedAction;
this.createIndexAction = createIndexAction; this.createIndexAction = createIndexAction;
this.autoCreateIndex = autoCreateIndex; this.autoCreateIndex = autoCreateIndex;
this.allowIdGeneration = settings.getAsBoolean("action.allow_id_generation", true); this.allowIdGeneration = settings.getAsBoolean("action.allow_id_generation", true);
@ -143,7 +145,7 @@ public class TransportIndexAction extends TransportReplicationAction<IndexReques
protected Tuple<IndexResponse, IndexRequest> shardOperationOnPrimary(MetaData metaData, IndexRequest request) throws Exception { protected Tuple<IndexResponse, IndexRequest> shardOperationOnPrimary(MetaData metaData, IndexRequest request) throws Exception {
// validate, if routing is required, that we got routing // validate, if routing is required, that we got routing
IndexMetaData indexMetaData = metaData.index(request.shardId().getIndex()); IndexMetaData indexMetaData = metaData.getIndexSafe(request.shardId().getIndex());
MappingMetaData mappingMd = indexMetaData.mappingOrDefault(request.type()); MappingMetaData mappingMd = indexMetaData.mappingOrDefault(request.type());
if (mappingMd != null && mappingMd.routing().required()) { if (mappingMd != null && mappingMd.routing().required()) {
if (request.routing() == null) { if (request.routing() == null) {
@ -205,8 +207,7 @@ public class TransportIndexAction extends TransportReplicationAction<IndexReques
Mapping update = operation.parsedDoc().dynamicMappingsUpdate(); Mapping update = operation.parsedDoc().dynamicMappingsUpdate();
final ShardId shardId = indexShard.shardId(); final ShardId shardId = indexShard.shardId();
if (update != null) { if (update != null) {
final String indexName = shardId.getIndexName(); mappingUpdatedAction.updateMappingOnMaster(shardId.getIndex(), request.type(), update);
mappingUpdatedAction.updateMappingOnMasterSynchronously(indexName, request.type(), update);
operation = prepareIndexOperationOnPrimary(request, indexShard); operation = prepareIndexOperationOnPrimary(request, indexShard);
update = operation.parsedDoc().dynamicMappingsUpdate(); update = operation.parsedDoc().dynamicMappingsUpdate();
if (update != null) { if (update != null) {

View File

@ -173,7 +173,7 @@ public class TransportMultiPercolateAction extends HandledTransportAction<MultiP
PercolateRequest percolateRequest = (PercolateRequest) element; PercolateRequest percolateRequest = (PercolateRequest) element;
String[] concreteIndices; String[] concreteIndices;
try { try {
concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, percolateRequest); concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, percolateRequest);
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
reducedResponses.set(slot, e); reducedResponses.set(slot, e);
responsesByItemAndShard.set(slot, new AtomicReferenceArray(0)); responsesByItemAndShard.set(slot, new AtomicReferenceArray(0));

View File

@ -96,7 +96,7 @@ abstract class AbstractSearchAsyncAction<FirstResult extends SearchPhaseResult>
// TODO: I think startTime() should become part of ActionRequest and that should be used both for index name // TODO: I think startTime() should become part of ActionRequest and that should be used both for index name
// date math expressions and $now in scripts. This way all apis will deal with now in the same way instead // date math expressions and $now in scripts. This way all apis will deal with now in the same way instead
// of just for the _search api // of just for the _search api
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request.indicesOptions(), String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request.indicesOptions(),
startTime(), request.indices()); startTime(), request.indices());
for (String index : concreteIndices) { for (String index : concreteIndices) {

View File

@ -64,7 +64,7 @@ public class TransportSearchAction extends HandledTransportAction<SearchRequest,
// optimize search type for cases where there is only one shard group to search on // optimize search type for cases where there is only one shard group to search on
try { try {
ClusterState clusterState = clusterService.state(); ClusterState clusterState = clusterService.state();
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, searchRequest); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, searchRequest);
Map<String, Set<String>> routingMap = indexNameExpressionResolver.resolveSearchRouting(clusterState, Map<String, Set<String>> routingMap = indexNameExpressionResolver.resolveSearchRouting(clusterState,
searchRequest.routing(), searchRequest.indices()); searchRequest.routing(), searchRequest.indices());
int shardCount = clusterService.operationRouting().searchShardsCount(clusterState, concreteIndices, routingMap); int shardCount = clusterService.operationRouting().searchShardsCount(clusterState, concreteIndices, routingMap);

View File

@ -125,7 +125,7 @@ public abstract class TransportBroadcastAction<Request extends BroadcastRequest<
throw blockException; throw blockException;
} }
// update to concrete indices // update to concrete indices
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request);
blockException = checkRequestBlock(clusterState, request, concreteIndices); blockException = checkRequestBlock(clusterState, request, concreteIndices);
if (blockException != null) { if (blockException != null) {
throw blockException; throw blockException;

View File

@ -51,7 +51,6 @@ import org.elasticsearch.transport.BaseTransportResponseHandler;
import org.elasticsearch.transport.NodeShouldNotConnectException; import org.elasticsearch.transport.NodeShouldNotConnectException;
import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportChannel;
import org.elasticsearch.transport.TransportException; import org.elasticsearch.transport.TransportException;
import org.elasticsearch.transport.TransportRequest;
import org.elasticsearch.transport.TransportRequestHandler; import org.elasticsearch.transport.TransportRequestHandler;
import org.elasticsearch.transport.TransportResponse; import org.elasticsearch.transport.TransportResponse;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
@ -241,7 +240,7 @@ public abstract class TransportBroadcastByNodeAction<Request extends BroadcastRe
throw globalBlockException; throw globalBlockException;
} }
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request);
ClusterBlockException requestBlockException = checkRequestBlock(clusterState, request, concreteIndices); ClusterBlockException requestBlockException = checkRequestBlock(clusterState, request, concreteIndices);
if (requestBlockException != null) { if (requestBlockException != null) {
throw requestBlockException; throw requestBlockException;

View File

@ -50,7 +50,7 @@ public abstract class TransportClusterInfoAction<Request extends ClusterInfoRequ
@Override @Override
protected final void masterOperation(final Request request, final ClusterState state, final ActionListener<Response> listener) { protected final void masterOperation(final Request request, final ClusterState state, final ActionListener<Response> listener) {
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request);
doMasterOperation(request, concreteIndices, state, listener); doMasterOperation(request, concreteIndices, state, listener);
} }

View File

@ -97,7 +97,7 @@ public abstract class TransportBroadcastReplicationAction<Request extends Broadc
@Override @Override
public void onFailure(Throwable e) { public void onFailure(Throwable e) {
logger.trace("{}: got failure from {}", actionName, shardId); logger.trace("{}: got failure from {}", actionName, shardId);
int totalNumCopies = clusterState.getMetaData().index(shardId.getIndexName()).getNumberOfReplicas() + 1; int totalNumCopies = clusterState.getMetaData().getIndexSafe(shardId.getIndex()).getNumberOfReplicas() + 1;
ShardResponse shardResponse = newShardResponse(); ShardResponse shardResponse = newShardResponse();
ReplicationResponse.ShardInfo.Failure[] failures; ReplicationResponse.ShardInfo.Failure[] failures;
if (TransportActions.isShardNotAvailableException(e)) { if (TransportActions.isShardNotAvailableException(e)) {
@ -130,7 +130,7 @@ public abstract class TransportBroadcastReplicationAction<Request extends Broadc
*/ */
protected List<ShardId> shards(Request request, ClusterState clusterState) { protected List<ShardId> shards(Request request, ClusterState clusterState) {
List<ShardId> shardIds = new ArrayList<>(); List<ShardId> shardIds = new ArrayList<>();
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request);
for (String index : concreteIndices) { for (String index : concreteIndices) {
IndexMetaData indexMetaData = clusterState.metaData().getIndices().get(index); IndexMetaData indexMetaData = clusterState.metaData().getIndices().get(index);
if (indexMetaData != null) { if (indexMetaData != null) {

View File

@ -103,7 +103,6 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
protected final ShardStateAction shardStateAction; protected final ShardStateAction shardStateAction;
protected final WriteConsistencyLevel defaultWriteConsistencyLevel; protected final WriteConsistencyLevel defaultWriteConsistencyLevel;
protected final TransportRequestOptions transportOptions; protected final TransportRequestOptions transportOptions;
protected final MappingUpdatedAction mappingUpdatedAction;
final String transportReplicaAction; final String transportReplicaAction;
final String transportPrimaryAction; final String transportPrimaryAction;
@ -113,7 +112,7 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
protected TransportReplicationAction(Settings settings, String actionName, TransportService transportService, protected TransportReplicationAction(Settings settings, String actionName, TransportService transportService,
ClusterService clusterService, IndicesService indicesService, ClusterService clusterService, IndicesService indicesService,
ThreadPool threadPool, ShardStateAction shardStateAction, ThreadPool threadPool, ShardStateAction shardStateAction,
MappingUpdatedAction mappingUpdatedAction, ActionFilters actionFilters, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver, Supplier<Request> request, IndexNameExpressionResolver indexNameExpressionResolver, Supplier<Request> request,
Supplier<ReplicaRequest> replicaRequest, String executor) { Supplier<ReplicaRequest> replicaRequest, String executor) {
super(settings, actionName, threadPool, actionFilters, indexNameExpressionResolver, transportService.getTaskManager()); super(settings, actionName, threadPool, actionFilters, indexNameExpressionResolver, transportService.getTaskManager());
@ -121,7 +120,6 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
this.clusterService = clusterService; this.clusterService = clusterService;
this.indicesService = indicesService; this.indicesService = indicesService;
this.shardStateAction = shardStateAction; this.shardStateAction = shardStateAction;
this.mappingUpdatedAction = mappingUpdatedAction;
this.transportPrimaryAction = actionName + "[p]"; this.transportPrimaryAction = actionName + "[p]";
this.transportReplicaAction = actionName + "[r]"; this.transportReplicaAction = actionName + "[r]";
@ -525,7 +523,7 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
} }
private String concreteIndex(ClusterState state) { private String concreteIndex(ClusterState state) {
return resolveIndex() ? indexNameExpressionResolver.concreteSingleIndex(state, request) : request.index(); return resolveIndex() ? indexNameExpressionResolver.concreteSingleIndex(state, request).getName() : request.index();
} }
private ShardRouting primary(ClusterState state) { private ShardRouting primary(ClusterState state) {

View File

@ -138,7 +138,7 @@ public abstract class TransportInstanceSingleOperationAction<Request extends Ins
throw blockException; throw blockException;
} }
} }
request.concreteIndex(indexNameExpressionResolver.concreteSingleIndex(observer.observedState(), request)); request.concreteIndex(indexNameExpressionResolver.concreteSingleIndex(observer.observedState(), request).getName());
resolveRequest(observer.observedState(), request); resolveRequest(observer.observedState(), request);
blockException = checkRequestBlock(observer.observedState(), request); blockException = checkRequestBlock(observer.observedState(), request);
if (blockException != null) { if (blockException != null) {

View File

@ -141,7 +141,7 @@ public abstract class TransportSingleShardAction<Request extends SingleShardRequ
String concreteSingleIndex; String concreteSingleIndex;
if (resolveIndex(request)) { if (resolveIndex(request)) {
concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, request); concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, request).getName();
} else { } else {
concreteSingleIndex = request.index(); concreteSingleIndex = request.index();
} }

View File

@ -72,7 +72,7 @@ public class TransportMultiTermVectorsAction extends HandledTransportAction<Mult
termVectorsRequest.type(), termVectorsRequest.id(), new IndexNotFoundException(termVectorsRequest.index())))); termVectorsRequest.type(), termVectorsRequest.id(), new IndexNotFoundException(termVectorsRequest.index()))));
continue; continue;
} }
String concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, (DocumentRequest) termVectorsRequest); String concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, termVectorsRequest).getName();
if (termVectorsRequest.routing() == null && clusterState.getMetaData().routingRequired(concreteSingleIndex, termVectorsRequest.type())) { if (termVectorsRequest.routing() == null && clusterState.getMetaData().routingRequired(concreteSingleIndex, termVectorsRequest.type())) {
responses.set(i, new MultiTermVectorsItemResponse(null, new MultiTermVectorsResponse.Failure(concreteSingleIndex, termVectorsRequest.type(), termVectorsRequest.id(), responses.set(i, new MultiTermVectorsItemResponse(null, new MultiTermVectorsResponse.Failure(concreteSingleIndex, termVectorsRequest.type(), termVectorsRequest.id(),
new IllegalArgumentException("routing is required for [" + concreteSingleIndex + "]/[" + termVectorsRequest.type() + "]/[" + termVectorsRequest.id() + "]")))); new IllegalArgumentException("routing is required for [" + concreteSingleIndex + "]/[" + termVectorsRequest.type() + "]/[" + termVectorsRequest.id() + "]"))));

View File

@ -135,8 +135,8 @@ public class ClusterChangedEvent {
List<Index> deleted = null; List<Index> deleted = null;
for (ObjectCursor<IndexMetaData> cursor : previousState.metaData().indices().values()) { for (ObjectCursor<IndexMetaData> cursor : previousState.metaData().indices().values()) {
IndexMetaData index = cursor.value; IndexMetaData index = cursor.value;
IndexMetaData current = state.metaData().index(index.getIndex().getName()); IndexMetaData current = state.metaData().index(index.getIndex());
if (current == null || index.getIndexUUID().equals(current.getIndexUUID()) == false) { if (current == null) {
if (deleted == null) { if (deleted == null) {
deleted = new ArrayList<>(); deleted = new ArrayList<>();
} }

View File

@ -18,17 +18,19 @@
*/ */
package org.elasticsearch.cluster.ack; package org.elasticsearch.cluster.ack;
import org.elasticsearch.index.Index;
/** /**
* Base cluster state update request that allows to execute update against multiple indices * Base cluster state update request that allows to execute update against multiple indices
*/ */
public abstract class IndicesClusterStateUpdateRequest<T extends IndicesClusterStateUpdateRequest<T>> extends ClusterStateUpdateRequest<T> { public abstract class IndicesClusterStateUpdateRequest<T extends IndicesClusterStateUpdateRequest<T>> extends ClusterStateUpdateRequest<T> {
private String[] indices; private Index[] indices;
/** /**
* Returns the indices the operation needs to be executed on * Returns the indices the operation needs to be executed on
*/ */
public String[] indices() { public Index[] indices() {
return indices; return indices;
} }
@ -36,7 +38,7 @@ public abstract class IndicesClusterStateUpdateRequest<T extends IndicesClusterS
* Sets the indices the operation needs to be executed on * Sets the indices the operation needs to be executed on
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public T indices(String[] indices) { public T indices(Index[] indices) {
this.indices = indices; this.indices = indices;
return (T)this; return (T)this;
} }

View File

@ -19,9 +19,7 @@
package org.elasticsearch.cluster.action.index; package org.elasticsearch.cluster.action.index;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
@ -31,6 +29,7 @@ import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.Mapping; import org.elasticsearch.index.mapper.Mapping;
@ -65,48 +64,20 @@ public class MappingUpdatedAction extends AbstractComponent {
this.client = client.admin().indices(); this.client = client.admin().indices();
} }
private PutMappingRequestBuilder updateMappingRequest(String index, String type, Mapping mappingUpdate, final TimeValue timeout) { private PutMappingRequestBuilder updateMappingRequest(Index index, String type, Mapping mappingUpdate, final TimeValue timeout) {
if (type.equals(MapperService.DEFAULT_MAPPING)) { if (type.equals(MapperService.DEFAULT_MAPPING)) {
throw new IllegalArgumentException("_default_ mapping should not be updated"); throw new IllegalArgumentException("_default_ mapping should not be updated");
} }
return client.preparePutMapping(index).setType(type).setSource(mappingUpdate.toString()) return client.preparePutMapping().setConcreteIndex(index).setType(type).setSource(mappingUpdate.toString())
.setMasterNodeTimeout(timeout).setTimeout(timeout); .setMasterNodeTimeout(timeout).setTimeout(timeout);
} }
public void updateMappingOnMaster(String index, String type, Mapping mappingUpdate, final TimeValue timeout, final MappingUpdateListener listener) {
final PutMappingRequestBuilder request = updateMappingRequest(index, type, mappingUpdate, timeout);
if (listener == null) {
request.execute();
} else {
final ActionListener<PutMappingResponse> actionListener = new ActionListener<PutMappingResponse>() {
@Override
public void onResponse(PutMappingResponse response) {
if (response.isAcknowledged()) {
listener.onMappingUpdate();
} else {
listener.onFailure(new TimeoutException("Failed to acknowledge the mapping response within [" + timeout + "]"));
}
}
@Override
public void onFailure(Throwable e) {
listener.onFailure(e);
}
};
request.execute(actionListener);
}
}
public void updateMappingOnMasterAsynchronously(String index, String type, Mapping mappingUpdate) throws Exception {
updateMappingOnMaster(index, type, mappingUpdate, dynamicMappingUpdateTimeout, null);
}
/** /**
* Same as {@link #updateMappingOnMasterSynchronously(String, String, Mapping, TimeValue)} * Same as {@link #updateMappingOnMaster(Index, String, Mapping, TimeValue)}
* using the default timeout. * using the default timeout.
*/ */
public void updateMappingOnMasterSynchronously(String index, String type, Mapping mappingUpdate) throws Exception { public void updateMappingOnMaster(Index index, String type, Mapping mappingUpdate) throws Exception {
updateMappingOnMasterSynchronously(index, type, mappingUpdate, dynamicMappingUpdateTimeout); updateMappingOnMaster(index, type, mappingUpdate, dynamicMappingUpdateTimeout);
} }
/** /**
@ -114,19 +85,9 @@ public class MappingUpdatedAction extends AbstractComponent {
* {@code timeout}. When this method returns successfully mappings have * {@code timeout}. When this method returns successfully mappings have
* been applied to the master node and propagated to data nodes. * been applied to the master node and propagated to data nodes.
*/ */
public void updateMappingOnMasterSynchronously(String index, String type, Mapping mappingUpdate, TimeValue timeout) throws Exception { public void updateMappingOnMaster(Index index, String type, Mapping mappingUpdate, TimeValue timeout) throws Exception {
if (updateMappingRequest(index, type, mappingUpdate, timeout).get().isAcknowledged() == false) { if (updateMappingRequest(index, type, mappingUpdate, timeout).get().isAcknowledged() == false) {
throw new TimeoutException("Failed to acknowledge mapping update within [" + timeout + "]"); throw new TimeoutException("Failed to acknowledge mapping update within [" + timeout + "]");
} }
} }
/**
* A listener to be notified when the mappings were updated
*/
public static interface MappingUpdateListener {
void onMappingUpdate();
void onFailure(Throwable t);
}
} }

View File

@ -76,7 +76,7 @@ public class NodeIndexDeletedAction extends AbstractComponent {
listeners.remove(listener); listeners.remove(listener);
} }
public void nodeIndexDeleted(final ClusterState clusterState, final String index, final IndexSettings indexSettings, final String nodeId) { public void nodeIndexDeleted(final ClusterState clusterState, final Index index, final IndexSettings indexSettings, final String nodeId) {
final DiscoveryNodes nodes = clusterState.nodes(); final DiscoveryNodes nodes = clusterState.nodes();
transportService.sendRequest(clusterState.nodes().masterNode(), transportService.sendRequest(clusterState.nodes().masterNode(),
INDEX_DELETED_ACTION_NAME, new NodeIndexDeletedMessage(index, nodeId), EmptyTransportResponseHandler.INSTANCE_SAME); INDEX_DELETED_ACTION_NAME, new NodeIndexDeletedMessage(index, nodeId), EmptyTransportResponseHandler.INSTANCE_SAME);
@ -97,7 +97,7 @@ public class NodeIndexDeletedAction extends AbstractComponent {
}); });
} }
private void lockIndexAndAck(String index, DiscoveryNodes nodes, String nodeId, ClusterState clusterState, IndexSettings indexSettings) throws IOException { private void lockIndexAndAck(Index index, DiscoveryNodes nodes, String nodeId, ClusterState clusterState, IndexSettings indexSettings) throws IOException {
try { try {
// we are waiting until we can lock the index / all shards on the node and then we ack the delete of the store to the // we are waiting until we can lock the index / all shards on the node and then we ack the delete of the store to the
// master. If we can't acquire the locks here immediately there might be a shard of this index still holding on to the lock // master. If we can't acquire the locks here immediately there might be a shard of this index still holding on to the lock
@ -114,9 +114,9 @@ public class NodeIndexDeletedAction extends AbstractComponent {
} }
public interface Listener { public interface Listener {
void onNodeIndexDeleted(String index, String nodeId); void onNodeIndexDeleted(Index index, String nodeId);
void onNodeIndexStoreDeleted(String index, String nodeId); void onNodeIndexStoreDeleted(Index index, String nodeId);
} }
private class NodeIndexDeletedTransportHandler implements TransportRequestHandler<NodeIndexDeletedMessage> { private class NodeIndexDeletedTransportHandler implements TransportRequestHandler<NodeIndexDeletedMessage> {
@ -143,13 +143,13 @@ public class NodeIndexDeletedAction extends AbstractComponent {
public static class NodeIndexDeletedMessage extends TransportRequest { public static class NodeIndexDeletedMessage extends TransportRequest {
String index; Index index;
String nodeId; String nodeId;
public NodeIndexDeletedMessage() { public NodeIndexDeletedMessage() {
} }
NodeIndexDeletedMessage(String index, String nodeId) { NodeIndexDeletedMessage(Index index, String nodeId) {
this.index = index; this.index = index;
this.nodeId = nodeId; this.nodeId = nodeId;
} }
@ -157,27 +157,27 @@ public class NodeIndexDeletedAction extends AbstractComponent {
@Override @Override
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out); super.writeTo(out);
out.writeString(index); index.writeTo(out);
out.writeString(nodeId); out.writeString(nodeId);
} }
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); super.readFrom(in);
index = in.readString(); index = new Index(in);
nodeId = in.readString(); nodeId = in.readString();
} }
} }
public static class NodeIndexStoreDeletedMessage extends TransportRequest { public static class NodeIndexStoreDeletedMessage extends TransportRequest {
String index; Index index;
String nodeId; String nodeId;
public NodeIndexStoreDeletedMessage() { public NodeIndexStoreDeletedMessage() {
} }
NodeIndexStoreDeletedMessage(String index, String nodeId) { NodeIndexStoreDeletedMessage(Index index, String nodeId) {
this.index = index; this.index = index;
this.nodeId = nodeId; this.nodeId = nodeId;
} }
@ -185,14 +185,14 @@ public class NodeIndexDeletedAction extends AbstractComponent {
@Override @Override
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out); super.writeTo(out);
out.writeString(index); index.writeTo(out);
out.writeString(nodeId); out.writeString(nodeId);
} }
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); super.readFrom(in);
index = in.readString(); index = new Index(in);
nodeId = in.readString(); nodeId = in.readString();
} }
} }

View File

@ -32,6 +32,7 @@ import org.elasticsearch.common.joda.DateMathParser;
import org.elasticsearch.common.joda.FormatDateTimeFormatter; import org.elasticsearch.common.joda.FormatDateTimeFormatter;
import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.indices.IndexClosedException; import org.elasticsearch.indices.IndexClosedException;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
@ -65,11 +66,20 @@ public class IndexNameExpressionResolver extends AbstractComponent {
); );
} }
/**
* Same as {@link #concreteIndexNames(ClusterState, IndicesOptions, String...)}, but the index expressions and options
* are encapsulated in the specified request.
*/
public String[] concreteIndexNames(ClusterState state, IndicesRequest request) {
Context context = new Context(state, request.indicesOptions());
return concreteIndexNames(context, request.indices());
}
/** /**
* Same as {@link #concreteIndices(ClusterState, IndicesOptions, String...)}, but the index expressions and options * Same as {@link #concreteIndices(ClusterState, IndicesOptions, String...)}, but the index expressions and options
* are encapsulated in the specified request. * are encapsulated in the specified request.
*/ */
public String[] concreteIndices(ClusterState state, IndicesRequest request) { public Index[] concreteIndices(ClusterState state, IndicesRequest request) {
Context context = new Context(state, request.indicesOptions()); Context context = new Context(state, request.indicesOptions());
return concreteIndices(context, request.indices()); return concreteIndices(context, request.indices());
} }
@ -87,7 +97,25 @@ public class IndexNameExpressionResolver extends AbstractComponent {
* @throws IllegalArgumentException if one of the aliases resolve to multiple indices and the provided * @throws IllegalArgumentException if one of the aliases resolve to multiple indices and the provided
* indices options in the context don't allow such a case. * indices options in the context don't allow such a case.
*/ */
public String[] concreteIndices(ClusterState state, IndicesOptions options, String... indexExpressions) { public String[] concreteIndexNames(ClusterState state, IndicesOptions options, String... indexExpressions) {
Context context = new Context(state, options);
return concreteIndexNames(context, indexExpressions);
}
/**
* Translates the provided index expression into actual concrete indices, properly deduplicated.
*
* @param state the cluster state containing all the data to resolve to expressions to concrete indices
* @param options defines how the aliases or indices need to be resolved to concrete indices
* @param indexExpressions expressions that can be resolved to alias or index names.
* @return the resolved concrete indices based on the cluster state, indices options and index expressions
* @throws IndexNotFoundException if one of the index expressions is pointing to a missing index or alias and the
* provided indices options in the context don't allow such a case, or if the final result of the indices resolution
* contains no indices and the indices options in the context don't allow such a case.
* @throws IllegalArgumentException if one of the aliases resolve to multiple indices and the provided
* indices options in the context don't allow such a case.
*/
public Index[] concreteIndices(ClusterState state, IndicesOptions options, String... indexExpressions) {
Context context = new Context(state, options); Context context = new Context(state, options);
return concreteIndices(context, indexExpressions); return concreteIndices(context, indexExpressions);
} }
@ -105,12 +133,21 @@ public class IndexNameExpressionResolver extends AbstractComponent {
* @throws IllegalArgumentException if one of the aliases resolve to multiple indices and the provided * @throws IllegalArgumentException if one of the aliases resolve to multiple indices and the provided
* indices options in the context don't allow such a case. * indices options in the context don't allow such a case.
*/ */
public String[] concreteIndices(ClusterState state, IndicesOptions options, long startTime, String... indexExpressions) { public String[] concreteIndexNames(ClusterState state, IndicesOptions options, long startTime, String... indexExpressions) {
Context context = new Context(state, options, startTime); Context context = new Context(state, options, startTime);
return concreteIndices(context, indexExpressions); return concreteIndexNames(context, indexExpressions);
} }
String[] concreteIndices(Context context, String... indexExpressions) { String[] concreteIndexNames(Context context, String... indexExpressions) {
Index[] indexes = concreteIndices(context, indexExpressions);
String[] names = new String[indexes.length];
for (int i = 0; i < indexes.length; i++) {
names[i] = indexes[i].getName();
}
return names;
}
Index[] concreteIndices(Context context, String... indexExpressions) {
if (indexExpressions == null || indexExpressions.length == 0) { if (indexExpressions == null || indexExpressions.length == 0) {
indexExpressions = new String[]{MetaData.ALL}; indexExpressions = new String[]{MetaData.ALL};
} }
@ -136,11 +173,11 @@ public class IndexNameExpressionResolver extends AbstractComponent {
infe.setResources("index_expression", indexExpressions); infe.setResources("index_expression", indexExpressions);
throw infe; throw infe;
} else { } else {
return Strings.EMPTY_ARRAY; return Index.EMPTY_ARRAY;
} }
} }
final Set<String> concreteIndices = new HashSet<>(expressions.size()); final Set<Index> concreteIndices = new HashSet<>(expressions.size());
for (String expression : expressions) { for (String expression : expressions) {
AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(expression); AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(expression);
if (aliasOrIndex == null) { if (aliasOrIndex == null) {
@ -169,11 +206,11 @@ public class IndexNameExpressionResolver extends AbstractComponent {
throw new IndexClosedException(index.getIndex()); throw new IndexClosedException(index.getIndex());
} else { } else {
if (options.forbidClosedIndices() == false) { if (options.forbidClosedIndices() == false) {
concreteIndices.add(index.getIndex().getName()); concreteIndices.add(index.getIndex());
} }
} }
} else if (index.getState() == IndexMetaData.State.OPEN) { } else if (index.getState() == IndexMetaData.State.OPEN) {
concreteIndices.add(index.getIndex().getName()); concreteIndices.add(index.getIndex());
} else { } else {
throw new IllegalStateException("index state [" + index.getState() + "] not supported"); throw new IllegalStateException("index state [" + index.getState() + "] not supported");
} }
@ -185,7 +222,7 @@ public class IndexNameExpressionResolver extends AbstractComponent {
infe.setResources("index_expression", indexExpressions); infe.setResources("index_expression", indexExpressions);
throw infe; throw infe;
} }
return concreteIndices.toArray(new String[concreteIndices.size()]); return concreteIndices.toArray(new Index[concreteIndices.size()]);
} }
/** /**
@ -200,9 +237,9 @@ public class IndexNameExpressionResolver extends AbstractComponent {
* @throws IllegalArgumentException if the index resolution lead to more than one index * @throws IllegalArgumentException if the index resolution lead to more than one index
* @return the concrete index obtained as a result of the index resolution * @return the concrete index obtained as a result of the index resolution
*/ */
public String concreteSingleIndex(ClusterState state, IndicesRequest request) { public Index concreteSingleIndex(ClusterState state, IndicesRequest request) {
String indexExpression = request.indices() != null && request.indices().length > 0 ? request.indices()[0] : null; String indexExpression = request.indices() != null && request.indices().length > 0 ? request.indices()[0] : null;
String[] indices = concreteIndices(state, request.indicesOptions(), indexExpression); Index[] indices = concreteIndices(state, request.indicesOptions(), indexExpression);
if (indices.length != 1) { if (indices.length != 1) {
throw new IllegalArgumentException("unable to return a single index as the index and options provided got resolved to multiple indices"); throw new IllegalArgumentException("unable to return a single index as the index and options provided got resolved to multiple indices");
} }
@ -867,7 +904,7 @@ public class IndexNameExpressionResolver extends AbstractComponent {
* Returns <code>true</code> iff the given expression resolves to the given index name otherwise <code>false</code> * Returns <code>true</code> iff the given expression resolves to the given index name otherwise <code>false</code>
*/ */
public final boolean matchesIndex(String indexName, String expression, ClusterState state) { public final boolean matchesIndex(String indexName, String expression, ClusterState state) {
final String[] concreteIndices = concreteIndices(state, IndicesOptions.lenientExpandOpen(), expression); final String[] concreteIndices = concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), expression);
for (String index : concreteIndices) { for (String index : concreteIndices) {
if (Regex.simpleMatch(index, indexName)) { if (Regex.simpleMatch(index, indexName)) {
return true; return true;

View File

@ -84,20 +84,10 @@ public class MappingMetaData extends AbstractDiffable<MappingMetaData> {
private static final FormatDateTimeFormatter EPOCH_MILLIS_PARSER = Joda.forPattern("epoch_millis"); private static final FormatDateTimeFormatter EPOCH_MILLIS_PARSER = Joda.forPattern("epoch_millis");
public static String parseStringTimestamp(String timestampAsString, FormatDateTimeFormatter dateTimeFormatter, public static String parseStringTimestamp(String timestampAsString, FormatDateTimeFormatter dateTimeFormatter) throws TimestampParsingException {
Version version) throws TimestampParsingException {
try { try {
// no need for unix timestamp parsing in 2.x return Long.toString(dateTimeFormatter.parser().parseMillis(timestampAsString));
FormatDateTimeFormatter formatter = version.onOrAfter(Version.V_2_0_0_beta1) ? dateTimeFormatter : EPOCH_MILLIS_PARSER;
return Long.toString(formatter.parser().parseMillis(timestampAsString));
} catch (RuntimeException e) { } catch (RuntimeException e) {
if (version.before(Version.V_2_0_0_beta1)) {
try {
return Long.toString(dateTimeFormatter.parser().parseMillis(timestampAsString));
} catch (RuntimeException e1) {
throw new TimestampParsingException(timestampAsString, e1);
}
}
throw new TimestampParsingException(timestampAsString, e); throw new TimestampParsingException(timestampAsString, e);
} }
} }

View File

@ -232,7 +232,7 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, Fr
public boolean equalsAliases(MetaData other) { public boolean equalsAliases(MetaData other) {
for (ObjectCursor<IndexMetaData> cursor : other.indices().values()) { for (ObjectCursor<IndexMetaData> cursor : other.indices().values()) {
IndexMetaData otherIndex = cursor.value; IndexMetaData otherIndex = cursor.value;
IndexMetaData thisIndex= index(otherIndex.getIndex()); IndexMetaData thisIndex = index(otherIndex.getIndex());
if (thisIndex == null) { if (thisIndex == null) {
return false; return false;
} }
@ -457,7 +457,28 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, Fr
} }
public IndexMetaData index(Index index) { public IndexMetaData index(Index index) {
return index(index.getName()); IndexMetaData metaData = index(index.getName());
if (metaData != null && metaData.getIndexUUID().equals(index.getUUID())) {
return metaData;
}
return null;
}
/**
* Returns the {@link IndexMetaData} for this index.
* @throws IndexNotFoundException if no metadata for this index is found
*/
public IndexMetaData getIndexSafe(Index index) {
IndexMetaData metaData = index(index.getName());
if (metaData != null) {
if(metaData.getIndexUUID().equals(index.getUUID())) {
return metaData;
}
throw new IndexNotFoundException(index,
new IllegalStateException("index uuid doesn't match expected: [" + index.getUUID()
+ "] but got: [" + metaData.getIndexUUID() +"]"));
}
throw new IndexNotFoundException(index);
} }
public ImmutableOpenMap<String, IndexMetaData> indices() { public ImmutableOpenMap<String, IndexMetaData> indices() {
@ -488,20 +509,13 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, Fr
return (T) customs.get(type); return (T) customs.get(type);
} }
public int totalNumberOfShards() {
public int getTotalNumberOfShards() {
return this.totalNumberOfShards; return this.totalNumberOfShards;
} }
public int getTotalNumberOfShards() {
return totalNumberOfShards();
}
public int numberOfShards() {
return this.numberOfShards;
}
public int getNumberOfShards() { public int getNumberOfShards() {
return numberOfShards(); return this.numberOfShards;
} }
/** /**
@ -844,6 +858,19 @@ public class MetaData implements Iterable<IndexMetaData>, Diffable<MetaData>, Fr
return indices.get(index); return indices.get(index);
} }
public IndexMetaData getSafe(Index index) {
IndexMetaData indexMetaData = get(index.getName());
if (indexMetaData != null) {
if(indexMetaData.getIndexUUID().equals(index.getUUID())) {
return indexMetaData;
}
throw new IndexNotFoundException(index,
new IllegalStateException("index uuid doesn't match expected: [" + index.getUUID()
+ "] but got: [" + indexMetaData.getIndexUUID() +"]"));
}
throw new IndexNotFoundException(index);
}
public Builder remove(String index) { public Builder remove(String index) {
indices.remove(index); indices.remove(index);
return this; return this;

View File

@ -35,14 +35,17 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.FutureUtils; import org.elasticsearch.common.util.concurrent.FutureUtils;
import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.snapshots.SnapshotsService; import org.elasticsearch.snapshots.SnapshotsService;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/** /**
* *
@ -68,10 +71,9 @@ public class MetaDataDeleteIndexService extends AbstractComponent {
} }
public void deleteIndices(final Request request, final Listener userListener) { public void deleteIndices(final Request request, final Listener userListener) {
Set<String> indices = Sets.newHashSet(request.indices);
final DeleteIndexListener listener = new DeleteIndexListener(userListener); final DeleteIndexListener listener = new DeleteIndexListener(userListener);
clusterService.submitStateUpdateTask("delete-index " + indices, new ClusterStateUpdateTask(Priority.URGENT) { clusterService.submitStateUpdateTask("delete-index " + request.indices, new ClusterStateUpdateTask(Priority.URGENT) {
@Override @Override
public TimeValue timeout() { public TimeValue timeout() {
@ -85,23 +87,21 @@ public class MetaDataDeleteIndexService extends AbstractComponent {
@Override @Override
public ClusterState execute(final ClusterState currentState) { public ClusterState execute(final ClusterState currentState) {
final MetaData meta = currentState.metaData();
final Set<IndexMetaData> metaDatas = request.indices.stream().map(i -> meta.getIndexSafe(i)).collect(Collectors.toSet());
// Check if index deletion conflicts with any running snapshots // Check if index deletion conflicts with any running snapshots
SnapshotsService.checkIndexDeletion(currentState, indices); SnapshotsService.checkIndexDeletion(currentState, metaDatas);
final Set<Index> indices = request.indices;
RoutingTable.Builder routingTableBuilder = RoutingTable.builder(currentState.routingTable()); RoutingTable.Builder routingTableBuilder = RoutingTable.builder(currentState.routingTable());
MetaData.Builder metaDataBuilder = MetaData.builder(currentState.metaData()); MetaData.Builder metaDataBuilder = MetaData.builder(meta);
ClusterBlocks.Builder clusterBlocksBuilder = ClusterBlocks.builder().blocks(currentState.blocks()); ClusterBlocks.Builder clusterBlocksBuilder = ClusterBlocks.builder().blocks(currentState.blocks());
for (final String index: indices) { for (final Index index : indices) {
if (!currentState.metaData().hasConcreteIndex(index)) { String indexName = index.getName();
throw new IndexNotFoundException(index);
}
logger.debug("[{}] deleting index", index); logger.debug("[{}] deleting index", index);
routingTableBuilder.remove(indexName);
routingTableBuilder.remove(index); clusterBlocksBuilder.removeIndexBlocks(indexName);
clusterBlocksBuilder.removeIndexBlocks(index); metaDataBuilder.remove(indexName);
metaDataBuilder.remove(index);
} }
// wait for events from all nodes that it has been removed from their respective metadata... // wait for events from all nodes that it has been removed from their respective metadata...
int count = currentState.nodes().size(); int count = currentState.nodes().size();
@ -112,7 +112,7 @@ public class MetaDataDeleteIndexService extends AbstractComponent {
// this listener will be notified once we get back a notification based on the cluster state change below. // this listener will be notified once we get back a notification based on the cluster state change below.
final NodeIndexDeletedAction.Listener nodeIndexDeleteListener = new NodeIndexDeletedAction.Listener() { final NodeIndexDeletedAction.Listener nodeIndexDeleteListener = new NodeIndexDeletedAction.Listener() {
@Override @Override
public void onNodeIndexDeleted(String deleted, String nodeId) { public void onNodeIndexDeleted(Index deleted, String nodeId) {
if (indices.contains(deleted)) { if (indices.contains(deleted)) {
if (counter.decrementAndGet() == 0) { if (counter.decrementAndGet() == 0) {
listener.onResponse(new Response(true)); listener.onResponse(new Response(true));
@ -122,7 +122,7 @@ public class MetaDataDeleteIndexService extends AbstractComponent {
} }
@Override @Override
public void onNodeIndexStoreDeleted(String deleted, String nodeId) { public void onNodeIndexStoreDeleted(Index deleted, String nodeId) {
if (indices.contains(deleted)) { if (indices.contains(deleted)) {
if (counter.decrementAndGet() == 0) { if (counter.decrementAndGet() == 0) {
listener.onResponse(new Response(true)); listener.onResponse(new Response(true));
@ -187,12 +187,12 @@ public class MetaDataDeleteIndexService extends AbstractComponent {
public static class Request { public static class Request {
final String[] indices; final Set<Index> indices;
TimeValue timeout = TimeValue.timeValueSeconds(10); TimeValue timeout = TimeValue.timeValueSeconds(10);
TimeValue masterTimeout = MasterNodeRequest.DEFAULT_MASTER_NODE_TIMEOUT; TimeValue masterTimeout = MasterNodeRequest.DEFAULT_MASTER_NODE_TIMEOUT;
public Request(String[] indices) { public Request(Set<Index> indices) {
this.indices = indices; this.indices = indices;
} }

View File

@ -36,6 +36,7 @@ import org.elasticsearch.common.Priority;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.snapshots.RestoreService; import org.elasticsearch.snapshots.RestoreService;
@ -82,15 +83,11 @@ public class MetaDataIndexStateService extends AbstractComponent {
@Override @Override
public ClusterState execute(ClusterState currentState) { public ClusterState execute(ClusterState currentState) {
Set<String> indicesToClose = new HashSet<>(); Set<IndexMetaData> indicesToClose = new HashSet<>();
for (String index : request.indices()) { for (Index index : request.indices()) {
IndexMetaData indexMetaData = currentState.metaData().index(index); final IndexMetaData indexMetaData = currentState.metaData().getIndexSafe(index);
if (indexMetaData == null) {
throw new IndexNotFoundException(index);
}
if (indexMetaData.getState() != IndexMetaData.State.CLOSE) { if (indexMetaData.getState() != IndexMetaData.State.CLOSE) {
indicesToClose.add(index); indicesToClose.add(indexMetaData);
} }
} }
@ -102,22 +99,22 @@ public class MetaDataIndexStateService extends AbstractComponent {
RestoreService.checkIndexClosing(currentState, indicesToClose); RestoreService.checkIndexClosing(currentState, indicesToClose);
// Check if index closing conflicts with any running snapshots // Check if index closing conflicts with any running snapshots
SnapshotsService.checkIndexClosing(currentState, indicesToClose); SnapshotsService.checkIndexClosing(currentState, indicesToClose);
logger.info("closing indices [{}]", indicesAsString); logger.info("closing indices [{}]", indicesAsString);
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData()); MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
ClusterBlocks.Builder blocksBuilder = ClusterBlocks.builder() ClusterBlocks.Builder blocksBuilder = ClusterBlocks.builder()
.blocks(currentState.blocks()); .blocks(currentState.blocks());
for (String index : indicesToClose) { for (IndexMetaData openIndexMetadata : indicesToClose) {
mdBuilder.put(IndexMetaData.builder(currentState.metaData().index(index)).state(IndexMetaData.State.CLOSE)); final String indexName = openIndexMetadata.getIndex().getName();
blocksBuilder.addIndexBlock(index, INDEX_CLOSED_BLOCK); mdBuilder.put(IndexMetaData.builder(openIndexMetadata).state(IndexMetaData.State.CLOSE));
blocksBuilder.addIndexBlock(indexName, INDEX_CLOSED_BLOCK);
} }
ClusterState updatedState = ClusterState.builder(currentState).metaData(mdBuilder).blocks(blocksBuilder).build(); ClusterState updatedState = ClusterState.builder(currentState).metaData(mdBuilder).blocks(blocksBuilder).build();
RoutingTable.Builder rtBuilder = RoutingTable.builder(currentState.routingTable()); RoutingTable.Builder rtBuilder = RoutingTable.builder(currentState.routingTable());
for (String index : indicesToClose) { for (IndexMetaData index : indicesToClose) {
rtBuilder.remove(index); rtBuilder.remove(index.getIndex().getName());
} }
RoutingAllocation.Result routingResult = allocationService.reroute( RoutingAllocation.Result routingResult = allocationService.reroute(
@ -143,14 +140,11 @@ public class MetaDataIndexStateService extends AbstractComponent {
@Override @Override
public ClusterState execute(ClusterState currentState) { public ClusterState execute(ClusterState currentState) {
List<String> indicesToOpen = new ArrayList<>(); List<IndexMetaData> indicesToOpen = new ArrayList<>();
for (String index : request.indices()) { for (Index index : request.indices()) {
IndexMetaData indexMetaData = currentState.metaData().index(index); final IndexMetaData indexMetaData = currentState.metaData().getIndexSafe(index);
if (indexMetaData == null) {
throw new IndexNotFoundException(index);
}
if (indexMetaData.getState() != IndexMetaData.State.OPEN) { if (indexMetaData.getState() != IndexMetaData.State.OPEN) {
indicesToOpen.add(index); indicesToOpen.add(indexMetaData);
} }
} }
@ -163,20 +157,21 @@ public class MetaDataIndexStateService extends AbstractComponent {
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData()); MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
ClusterBlocks.Builder blocksBuilder = ClusterBlocks.builder() ClusterBlocks.Builder blocksBuilder = ClusterBlocks.builder()
.blocks(currentState.blocks()); .blocks(currentState.blocks());
for (String index : indicesToOpen) { for (IndexMetaData closedMetaData : indicesToOpen) {
IndexMetaData indexMetaData = IndexMetaData.builder(currentState.metaData().index(index)).state(IndexMetaData.State.OPEN).build(); final String indexName = closedMetaData.getIndex().getName();
IndexMetaData indexMetaData = IndexMetaData.builder(closedMetaData).state(IndexMetaData.State.OPEN).build();
// The index might be closed because we couldn't import it due to old incompatible version // The index might be closed because we couldn't import it due to old incompatible version
// We need to check that this index can be upgraded to the current version // We need to check that this index can be upgraded to the current version
indexMetaData = metaDataIndexUpgradeService.upgradeIndexMetaData(indexMetaData); indexMetaData = metaDataIndexUpgradeService.upgradeIndexMetaData(indexMetaData);
mdBuilder.put(indexMetaData, true); mdBuilder.put(indexMetaData, true);
blocksBuilder.removeIndexBlock(index, INDEX_CLOSED_BLOCK); blocksBuilder.removeIndexBlock(indexName, INDEX_CLOSED_BLOCK);
} }
ClusterState updatedState = ClusterState.builder(currentState).metaData(mdBuilder).blocks(blocksBuilder).build(); ClusterState updatedState = ClusterState.builder(currentState).metaData(mdBuilder).blocks(blocksBuilder).build();
RoutingTable.Builder rtBuilder = RoutingTable.builder(updatedState.routingTable()); RoutingTable.Builder rtBuilder = RoutingTable.builder(updatedState.routingTable());
for (String index : indicesToOpen) { for (IndexMetaData index : indicesToOpen) {
rtBuilder.addAsFromCloseToOpen(updatedState.metaData().index(index)); rtBuilder.addAsFromCloseToOpen(updatedState.metaData().getIndexSafe(index.getIndex()));
} }
RoutingAllocation.Result routingResult = allocationService.reroute( RoutingAllocation.Result routingResult = allocationService.reroute(

View File

@ -31,6 +31,7 @@ import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Priority; import org.elasticsearch.common.Priority;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
@ -216,31 +217,23 @@ public class MetaDataMappingService extends AbstractComponent {
try { try {
// precreate incoming indices; // precreate incoming indices;
for (PutMappingClusterStateUpdateRequest request : tasks) { for (PutMappingClusterStateUpdateRequest request : tasks) {
final List<Index> indices = new ArrayList<>(request.indices().length);
try { try {
for (String index : request.indices()) { for (Index index : request.indices()) {
final IndexMetaData indexMetaData = currentState.metaData().index(index); final IndexMetaData indexMetaData = currentState.metaData().getIndexSafe(index);
if (indexMetaData != null) { if (indicesService.hasIndex(indexMetaData.getIndex()) == false) {
if (indicesService.hasIndex(indexMetaData.getIndex()) == false) { // if the index does not exists we create it once, add all types to the mapper service and
// if the index does not exists we create it once, add all types to the mapper service and // close it later once we are done with mapping update
// close it later once we are done with mapping update indicesToClose.add(indexMetaData.getIndex());
indicesToClose.add(indexMetaData.getIndex()); IndexService indexService = indicesService.createIndex(nodeServicesProvider, indexMetaData,
IndexService indexService = indicesService.createIndex(nodeServicesProvider, indexMetaData, Collections.emptyList());
Collections.emptyList()); // add mappings for all types, we need them for cross-type validation
// add mappings for all types, we need them for cross-type validation for (ObjectCursor<MappingMetaData> mapping : indexMetaData.getMappings().values()) {
for (ObjectCursor<MappingMetaData> mapping : indexMetaData.getMappings().values()) { indexService.mapperService().merge(mapping.value.type(), mapping.value.source(),
indexService.mapperService().merge(mapping.value.type(), mapping.value.source(), MapperService.MergeReason.MAPPING_RECOVERY, request.updateAllTypes());
MapperService.MergeReason.MAPPING_RECOVERY, request.updateAllTypes());
}
} }
indices.add(indexMetaData.getIndex());
} else {
// we didn't find the index in the clusterstate - maybe it was deleted
// NOTE: this doesn't fail the entire batch only the current PutMapping request we are processing
throw new IndexNotFoundException(index);
} }
} }
currentState = applyRequest(currentState, request, indices); currentState = applyRequest(currentState, request);
builder.success(request); builder.success(request);
} catch (Throwable t) { } catch (Throwable t) {
builder.failure(request, t); builder.failure(request, t);
@ -254,13 +247,20 @@ public class MetaDataMappingService extends AbstractComponent {
} }
} }
private ClusterState applyRequest(ClusterState currentState, PutMappingClusterStateUpdateRequest request, private ClusterState applyRequest(ClusterState currentState, PutMappingClusterStateUpdateRequest request) throws IOException {
List<Index> indices) throws IOException {
String mappingType = request.type(); String mappingType = request.type();
CompressedXContent mappingUpdateSource = new CompressedXContent(request.source()); CompressedXContent mappingUpdateSource = new CompressedXContent(request.source());
final MetaData metaData = currentState.metaData(); final MetaData metaData = currentState.metaData();
for (Index index : indices) { final List<Tuple<IndexService, IndexMetaData>> updateList = new ArrayList<>();
for (Index index : request.indices()) {
IndexService indexService = indicesService.indexServiceSafe(index); IndexService indexService = indicesService.indexServiceSafe(index);
// IMPORTANT: always get the metadata from the state since it get's batched
// and if we pull it from the indexService we might miss an update etc.
final IndexMetaData indexMetaData = currentState.getMetaData().getIndexSafe(index);
// this is paranoia... just to be sure we use the exact same indexService and metadata tuple on the update that
// we used for the validation, it makes this mechanism little less scary (a little)
updateList.add(new Tuple<>(indexService, indexMetaData));
// try and parse it (no need to add it here) so we can bail early in case of parsing exception // try and parse it (no need to add it here) so we can bail early in case of parsing exception
DocumentMapper newMapper; DocumentMapper newMapper;
DocumentMapper existingMapper = indexService.mapperService().documentMapper(request.type()); DocumentMapper existingMapper = indexService.mapperService().documentMapper(request.type());
@ -281,7 +281,6 @@ public class MetaDataMappingService extends AbstractComponent {
// and a put mapping api call, so we don't which type did exist before. // and a put mapping api call, so we don't which type did exist before.
// Also the order of the mappings may be backwards. // Also the order of the mappings may be backwards.
if (newMapper.parentFieldMapper().active()) { if (newMapper.parentFieldMapper().active()) {
IndexMetaData indexMetaData = metaData.index(index);
for (ObjectCursor<MappingMetaData> mapping : indexMetaData.getMappings().values()) { for (ObjectCursor<MappingMetaData> mapping : indexMetaData.getMappings().values()) {
if (newMapper.parentFieldMapper().type().equals(mapping.value.type())) { if (newMapper.parentFieldMapper().type().equals(mapping.value.type())) {
throw new IllegalArgumentException("can't add a _parent field that points to an already existing type"); throw new IllegalArgumentException("can't add a _parent field that points to an already existing type");
@ -302,13 +301,12 @@ public class MetaDataMappingService extends AbstractComponent {
throw new InvalidTypeNameException("Document mapping type name can't start with '_'"); throw new InvalidTypeNameException("Document mapping type name can't start with '_'");
} }
MetaData.Builder builder = MetaData.builder(metaData); MetaData.Builder builder = MetaData.builder(metaData);
for (Index index : indices) { for (Tuple<IndexService, IndexMetaData> toUpdate : updateList) {
// do the actual merge here on the master, and update the mapping source // do the actual merge here on the master, and update the mapping source
IndexService indexService = indicesService.indexService(index); // we use the exact same indexService and metadata we used to validate above here to actually apply the update
if (indexService == null) { // TODO this seems impossible given we use indexServiceSafe above final IndexService indexService = toUpdate.v1();
continue; final IndexMetaData indexMetaData = toUpdate.v2();
} final Index index = indexMetaData.getIndex();
CompressedXContent existingSource = null; CompressedXContent existingSource = null;
DocumentMapper existingMapper = indexService.mapperService().documentMapper(mappingType); DocumentMapper existingMapper = indexService.mapperService().documentMapper(mappingType);
if (existingMapper != null) { if (existingMapper != null) {
@ -323,24 +321,20 @@ public class MetaDataMappingService extends AbstractComponent {
} else { } else {
// use the merged mapping source // use the merged mapping source
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("[{}] update_mapping [{}] with source [{}]", index, mergedMapper.type(), updatedSource); logger.debug("{} update_mapping [{}] with source [{}]", index, mergedMapper.type(), updatedSource);
} else if (logger.isInfoEnabled()) { } else if (logger.isInfoEnabled()) {
logger.info("[{}] update_mapping [{}]", index, mergedMapper.type()); logger.info("{} update_mapping [{}]", index, mergedMapper.type());
} }
} }
} else { } else {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("[{}] create_mapping [{}] with source [{}]", index, mappingType, updatedSource); logger.debug("{} create_mapping [{}] with source [{}]", index, mappingType, updatedSource);
} else if (logger.isInfoEnabled()) { } else if (logger.isInfoEnabled()) {
logger.info("[{}] create_mapping [{}]", index, mappingType); logger.info("{} create_mapping [{}]", index, mappingType);
} }
} }
IndexMetaData indexMetaData = metaData.index(index);
if (indexMetaData == null) {
throw new IndexNotFoundException(index);
}
IndexMetaData.Builder indexMetaDataBuilder = IndexMetaData.builder(indexMetaData); IndexMetaData.Builder indexMetaDataBuilder = IndexMetaData.builder(indexMetaData);
// Mapping updates on a single type may have side-effects on other types so we need to // Mapping updates on a single type may have side-effects on other types so we need to
// update mapping metadata on all types // update mapping metadata on all types

View File

@ -23,7 +23,6 @@ import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsClusterStateUpdateRequest; import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsClusterStateUpdateRequest;
import org.elasticsearch.action.admin.indices.upgrade.post.UpgradeSettingsClusterStateUpdateRequest; import org.elasticsearch.action.admin.indices.upgrade.post.UpgradeSettingsClusterStateUpdateRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.cluster.AckedClusterStateUpdateTask; import org.elasticsearch.cluster.AckedClusterStateUpdateTask;
import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterService;
@ -43,7 +42,7 @@ import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.Index;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -86,7 +85,7 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
// we will want to know this for translating "all" to a number // we will want to know this for translating "all" to a number
final int dataNodeCount = event.state().nodes().dataNodes().size(); final int dataNodeCount = event.state().nodes().dataNodes().size();
Map<Integer, List<String>> nrReplicasChanged = new HashMap<>(); Map<Integer, List<Index>> nrReplicasChanged = new HashMap<>();
// we need to do this each time in case it was changed by update settings // we need to do this each time in case it was changed by update settings
for (final IndexMetaData indexMetaData : event.state().metaData()) { for (final IndexMetaData indexMetaData : event.state().metaData()) {
AutoExpandReplicas autoExpandReplicas = IndexMetaData.INDEX_AUTO_EXPAND_REPLICAS_SETTING.get(indexMetaData.getSettings()); AutoExpandReplicas autoExpandReplicas = IndexMetaData.INDEX_AUTO_EXPAND_REPLICAS_SETTING.get(indexMetaData.getSettings());
@ -117,7 +116,7 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
nrReplicasChanged.put(numberOfReplicas, new ArrayList<>()); nrReplicasChanged.put(numberOfReplicas, new ArrayList<>());
} }
nrReplicasChanged.get(numberOfReplicas).add(indexMetaData.getIndex().getName()); nrReplicasChanged.get(numberOfReplicas).add(indexMetaData.getIndex());
} }
} }
} }
@ -126,25 +125,25 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
// update settings and kick of a reroute (implicit) for them to take effect // update settings and kick of a reroute (implicit) for them to take effect
for (final Integer fNumberOfReplicas : nrReplicasChanged.keySet()) { for (final Integer fNumberOfReplicas : nrReplicasChanged.keySet()) {
Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, fNumberOfReplicas).build(); Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, fNumberOfReplicas).build();
final List<String> indices = nrReplicasChanged.get(fNumberOfReplicas); final List<Index> indices = nrReplicasChanged.get(fNumberOfReplicas);
UpdateSettingsClusterStateUpdateRequest updateRequest = new UpdateSettingsClusterStateUpdateRequest() UpdateSettingsClusterStateUpdateRequest updateRequest = new UpdateSettingsClusterStateUpdateRequest()
.indices(indices.toArray(new String[indices.size()])).settings(settings) .indices(indices.toArray(new Index[indices.size()])).settings(settings)
.ackTimeout(TimeValue.timeValueMillis(0)) //no need to wait for ack here .ackTimeout(TimeValue.timeValueMillis(0)) //no need to wait for ack here
.masterNodeTimeout(TimeValue.timeValueMinutes(10)); .masterNodeTimeout(TimeValue.timeValueMinutes(10));
updateSettings(updateRequest, new ActionListener<ClusterStateUpdateResponse>() { updateSettings(updateRequest, new ActionListener<ClusterStateUpdateResponse>() {
@Override @Override
public void onResponse(ClusterStateUpdateResponse response) { public void onResponse(ClusterStateUpdateResponse response) {
for (String index : indices) { for (Index index : indices) {
logger.info("[{}] auto expanded replicas to [{}]", index, fNumberOfReplicas); logger.info("{} auto expanded replicas to [{}]", index, fNumberOfReplicas);
} }
} }
@Override @Override
public void onFailure(Throwable t) { public void onFailure(Throwable t) {
for (String index : indices) { for (Index index : indices) {
logger.warn("[{}] fail to auto expand replicas to [{}]", index, fNumberOfReplicas); logger.warn("{} fail to auto expand replicas to [{}]", index, fNumberOfReplicas);
} }
} }
}); });
@ -188,16 +187,19 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
@Override @Override
public ClusterState execute(ClusterState currentState) { public ClusterState execute(ClusterState currentState) {
String[] actualIndices = indexNameExpressionResolver.concreteIndices(currentState, IndicesOptions.strictExpand(), request.indices());
RoutingTable.Builder routingTableBuilder = RoutingTable.builder(currentState.routingTable()); RoutingTable.Builder routingTableBuilder = RoutingTable.builder(currentState.routingTable());
MetaData.Builder metaDataBuilder = MetaData.builder(currentState.metaData()); MetaData.Builder metaDataBuilder = MetaData.builder(currentState.metaData());
// allow to change any settings to a close index, and only allow dynamic settings to be changed // allow to change any settings to a close index, and only allow dynamic settings to be changed
// on an open index // on an open index
Set<String> openIndices = new HashSet<>(); Set<Index> openIndices = new HashSet<>();
Set<String> closeIndices = new HashSet<>(); Set<Index> closeIndices = new HashSet<>();
for (String index : actualIndices) { final String[] actualIndices = new String[request.indices().length];
if (currentState.metaData().index(index).getState() == IndexMetaData.State.OPEN) { for (int i = 0; i < request.indices().length; i++) {
Index index = request.indices()[i];
actualIndices[i] = index.getName();
final IndexMetaData metaData = currentState.metaData().getIndexSafe(index);
if (metaData.getState() == IndexMetaData.State.OPEN) {
openIndices.add(index); openIndices.add(index);
} else { } else {
closeIndices.add(index); closeIndices.add(index);
@ -206,13 +208,13 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
if (closeIndices.size() > 0 && closedSettings.get(IndexMetaData.SETTING_NUMBER_OF_REPLICAS) != null) { if (closeIndices.size() > 0 && closedSettings.get(IndexMetaData.SETTING_NUMBER_OF_REPLICAS) != null) {
throw new IllegalArgumentException(String.format(Locale.ROOT, throw new IllegalArgumentException(String.format(Locale.ROOT,
"Can't update [%s] on closed indices [%s] - can leave index in an unopenable state", IndexMetaData.SETTING_NUMBER_OF_REPLICAS, "Can't update [%s] on closed indices %s - can leave index in an unopenable state", IndexMetaData.SETTING_NUMBER_OF_REPLICAS,
closeIndices closeIndices
)); ));
} }
if (!skippedSettigns.getAsMap().isEmpty() && !openIndices.isEmpty()) { if (!skippedSettigns.getAsMap().isEmpty() && !openIndices.isEmpty()) {
throw new IllegalArgumentException(String.format(Locale.ROOT, throw new IllegalArgumentException(String.format(Locale.ROOT,
"Can't update non dynamic settings[%s] for open indices [%s]", "Can't update non dynamic settings [%s] for open indices %s",
skippedSettigns.getAsMap().keySet(), skippedSettigns.getAsMap().keySet(),
openIndices openIndices
)); ));
@ -232,28 +234,22 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
maybeUpdateClusterBlock(actualIndices, blocks, IndexMetaData.INDEX_READ_BLOCK, IndexMetaData.INDEX_BLOCKS_READ_SETTING, openSettings); maybeUpdateClusterBlock(actualIndices, blocks, IndexMetaData.INDEX_READ_BLOCK, IndexMetaData.INDEX_BLOCKS_READ_SETTING, openSettings);
if (!openIndices.isEmpty()) { if (!openIndices.isEmpty()) {
for (String index : openIndices) { for (Index index : openIndices) {
IndexMetaData indexMetaData = metaDataBuilder.get(index); IndexMetaData indexMetaData = metaDataBuilder.getSafe(index);
if (indexMetaData == null) {
throw new IndexNotFoundException(index);
}
Settings.Builder updates = Settings.builder(); Settings.Builder updates = Settings.builder();
Settings.Builder indexSettings = Settings.builder().put(indexMetaData.getSettings()); Settings.Builder indexSettings = Settings.builder().put(indexMetaData.getSettings());
if (indexScopedSettings.updateDynamicSettings(openSettings, indexSettings, updates, index)) { if (indexScopedSettings.updateDynamicSettings(openSettings, indexSettings, updates, index.getName())) {
metaDataBuilder.put(IndexMetaData.builder(indexMetaData).settings(indexSettings)); metaDataBuilder.put(IndexMetaData.builder(indexMetaData).settings(indexSettings));
} }
} }
} }
if (!closeIndices.isEmpty()) { if (!closeIndices.isEmpty()) {
for (String index : closeIndices) { for (Index index : closeIndices) {
IndexMetaData indexMetaData = metaDataBuilder.get(index); IndexMetaData indexMetaData = metaDataBuilder.getSafe(index);
if (indexMetaData == null) {
throw new IndexNotFoundException(index);
}
Settings.Builder updates = Settings.builder(); Settings.Builder updates = Settings.builder();
Settings.Builder indexSettings = Settings.builder().put(indexMetaData.getSettings()); Settings.Builder indexSettings = Settings.builder().put(indexMetaData.getSettings());
if (indexScopedSettings.updateSettings(closedSettings, indexSettings, updates, index)) { if (indexScopedSettings.updateSettings(closedSettings, indexSettings, updates, index.getName())) {
metaDataBuilder.put(IndexMetaData.builder(indexMetaData).settings(indexSettings)); metaDataBuilder.put(IndexMetaData.builder(indexMetaData).settings(indexSettings));
} }
} }
@ -265,11 +261,11 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
// now, reroute in case things change that require it (like number of replicas) // now, reroute in case things change that require it (like number of replicas)
RoutingAllocation.Result routingResult = allocationService.reroute(updatedState, "settings update"); RoutingAllocation.Result routingResult = allocationService.reroute(updatedState, "settings update");
updatedState = ClusterState.builder(updatedState).routingResult(routingResult).build(); updatedState = ClusterState.builder(updatedState).routingResult(routingResult).build();
for (String index : openIndices) { for (Index index : openIndices) {
indexScopedSettings.dryRun(updatedState.metaData().index(index).getSettings()); indexScopedSettings.dryRun(updatedState.metaData().getIndexSafe(index).getSettings());
} }
for (String index : closeIndices) { for (Index index : closeIndices) {
indexScopedSettings.dryRun(updatedState.metaData().index(index).getSettings()); indexScopedSettings.dryRun(updatedState.metaData().getIndexSafe(index).getSettings());
} }
return updatedState; return updatedState;
} }

View File

@ -313,7 +313,7 @@ public class IndexRoutingTable extends AbstractDiffable<IndexRoutingTable> imple
@Override @Override
public IndexRoutingTable readFrom(StreamInput in) throws IOException { public IndexRoutingTable readFrom(StreamInput in) throws IOException {
Index index = Index.readIndex(in); Index index = new Index(in);
Builder builder = new Builder(index); Builder builder = new Builder(index);
int size = in.readVInt(); int size = in.readVInt();

View File

@ -584,7 +584,7 @@ public class IndexShardRoutingTable implements Iterable<ShardRouting> {
} }
public static IndexShardRoutingTable readFrom(StreamInput in) throws IOException { public static IndexShardRoutingTable readFrom(StreamInput in) throws IOException {
Index index = Index.readIndex(in); Index index = new Index(in);
return readFromThin(in, index); return readFromThin(in, index);
} }

View File

@ -328,7 +328,7 @@ public final class ShardRouting implements Streamable, ToXContent {
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
readFrom(in, Index.readIndex(in), in.readVInt()); readFrom(in, new Index(in), in.readVInt());
} }
/** /**

View File

@ -320,7 +320,7 @@ public class AllocationService extends AbstractComponent {
public static void updateLeftDelayOfUnassignedShards(RoutingAllocation allocation, Settings settings) { public static void updateLeftDelayOfUnassignedShards(RoutingAllocation allocation, Settings settings) {
for (ShardRouting shardRouting : allocation.routingNodes().unassigned()) { for (ShardRouting shardRouting : allocation.routingNodes().unassigned()) {
final MetaData metaData = allocation.metaData(); final MetaData metaData = allocation.metaData();
final IndexMetaData indexMetaData = metaData.index(shardRouting.index()); final IndexMetaData indexMetaData = metaData.getIndexSafe(shardRouting.index());
shardRouting.unassignedInfo().updateDelay(allocation.getCurrentNanoTime(), settings, indexMetaData.getSettings()); shardRouting.unassignedInfo().updateDelay(allocation.getCurrentNanoTime(), settings, indexMetaData.getSettings());
} }
} }
@ -340,7 +340,6 @@ public class AllocationService extends AbstractComponent {
changed |= failReplicasForUnassignedPrimary(allocation, shardEntry); changed |= failReplicasForUnassignedPrimary(allocation, shardEntry);
ShardRouting candidate = allocation.routingNodes().activeReplica(shardEntry); ShardRouting candidate = allocation.routingNodes().activeReplica(shardEntry);
if (candidate != null) { if (candidate != null) {
IndexMetaData index = allocation.metaData().index(candidate.index());
routingNodes.swapPrimaryFlag(shardEntry, candidate); routingNodes.swapPrimaryFlag(shardEntry, candidate);
if (candidate.relocatingNodeId() != null) { if (candidate.relocatingNodeId() != null) {
changed = true; changed = true;
@ -355,6 +354,7 @@ public class AllocationService extends AbstractComponent {
} }
} }
} }
IndexMetaData index = allocation.metaData().getIndexSafe(candidate.index());
if (IndexMetaData.isIndexUsingShadowReplicas(index.getSettings())) { if (IndexMetaData.isIndexUsingShadowReplicas(index.getSettings())) {
routingNodes.reinitShadowPrimary(candidate); routingNodes.reinitShadowPrimary(candidate);
changed = true; changed = true;

View File

@ -218,7 +218,7 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards
this.threshold = threshold; this.threshold = threshold;
this.routingNodes = allocation.routingNodes(); this.routingNodes = allocation.routingNodes();
metaData = routingNodes.metaData(); metaData = routingNodes.metaData();
avgShardsPerNode = ((float) metaData.totalNumberOfShards()) / routingNodes.size(); avgShardsPerNode = ((float) metaData.getTotalNumberOfShards()) / routingNodes.size();
buildModelFromAssigned(); buildModelFromAssigned();
} }

View File

@ -112,7 +112,7 @@ public class AllocateStalePrimaryAllocationCommand extends BasePrimaryAllocation
"allocating an empty primary for [" + index + "][" + shardId + "] can result in data loss. Please confirm by setting the accept_data_loss parameter to true"); "allocating an empty primary for [" + index + "][" + shardId + "] can result in data loss. Please confirm by setting the accept_data_loss parameter to true");
} }
final IndexMetaData indexMetaData = allocation.metaData().index(shardRouting.getIndexName()); final IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(shardRouting.index());
if (shardRouting.allocatedPostIndexCreate(indexMetaData) == false) { if (shardRouting.allocatedPostIndexCreate(indexMetaData) == false) {
return explainOrThrowRejectedCommand(explain, allocation, return explainOrThrowRejectedCommand(explain, allocation,
"trying to allocate an existing primary shard [" + index + "][" + shardId + "], while no such shard has ever been active"); "trying to allocate an existing primary shard [" + index + "][" + shardId + "], while no such shard has ever been active");

View File

@ -153,7 +153,7 @@ public class AwarenessAllocationDecider extends AllocationDecider {
return allocation.decision(Decision.YES, NAME, "no allocation awareness enabled"); return allocation.decision(Decision.YES, NAME, "no allocation awareness enabled");
} }
IndexMetaData indexMetaData = allocation.metaData().index(shardRouting.index()); IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(shardRouting.index());
int shardCount = indexMetaData.getNumberOfReplicas() + 1; // 1 for primary int shardCount = indexMetaData.getNumberOfReplicas() + 1; // 1 for primary
for (String awarenessAttribute : awarenessAttributes) { for (String awarenessAttribute : awarenessAttributes) {
// the node the shard exists on must be associated with an awareness attribute // the node the shard exists on must be associated with an awareness attribute

View File

@ -342,7 +342,7 @@ public class DiskThresholdDecider extends AllocationDecider {
} }
// a flag for whether the primary shard has been previously allocated // a flag for whether the primary shard has been previously allocated
IndexMetaData indexMetaData = allocation.metaData().index(shardRouting.getIndexName()); IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(shardRouting.index());
boolean primaryHasBeenAllocated = shardRouting.primary() && shardRouting.allocatedPostIndexCreate(indexMetaData); boolean primaryHasBeenAllocated = shardRouting.primary() && shardRouting.allocatedPostIndexCreate(indexMetaData);
// checks for exact byte comparisons // checks for exact byte comparisons

View File

@ -101,7 +101,7 @@ public class EnableAllocationDecider extends AllocationDecider {
return allocation.decision(Decision.YES, NAME, "allocation disabling is ignored"); return allocation.decision(Decision.YES, NAME, "allocation disabling is ignored");
} }
final IndexMetaData indexMetaData = allocation.metaData().index(shardRouting.getIndexName()); final IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(shardRouting.index());
final Allocation enable; final Allocation enable;
if (INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.exists(indexMetaData.getSettings())) { if (INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.exists(indexMetaData.getSettings())) {
enable = INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.get(indexMetaData.getSettings()); enable = INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.get(indexMetaData.getSettings());
@ -136,7 +136,7 @@ public class EnableAllocationDecider extends AllocationDecider {
return allocation.decision(Decision.YES, NAME, "rebalance disabling is ignored"); return allocation.decision(Decision.YES, NAME, "rebalance disabling is ignored");
} }
Settings indexSettings = allocation.routingNodes().metaData().index(shardRouting.index()).getSettings(); Settings indexSettings = allocation.routingNodes().metaData().getIndexSafe(shardRouting.index()).getSettings();
final Rebalance enable; final Rebalance enable;
if (INDEX_ROUTING_REBALANCE_ENABLE_SETTING.exists(indexSettings)) { if (INDEX_ROUTING_REBALANCE_ENABLE_SETTING.exists(indexSettings)) {
enable = INDEX_ROUTING_REBALANCE_ENABLE_SETTING.get(indexSettings); enable = INDEX_ROUTING_REBALANCE_ENABLE_SETTING.get(indexSettings);

View File

@ -102,7 +102,7 @@ public class FilterAllocationDecider extends AllocationDecider {
Decision decision = shouldClusterFilter(node, allocation); Decision decision = shouldClusterFilter(node, allocation);
if (decision != null) return decision; if (decision != null) return decision;
decision = shouldIndexFilter(allocation.routingNodes().metaData().index(shardRouting.index()), node, allocation); decision = shouldIndexFilter(allocation.routingNodes().metaData().getIndexSafe(shardRouting.index()), node, allocation);
if (decision != null) return decision; if (decision != null) return decision;
return allocation.decision(Decision.YES, NAME, "node passes include/exclude/require filters"); return allocation.decision(Decision.YES, NAME, "node passes include/exclude/require filters");

View File

@ -86,7 +86,7 @@ public class ShardsLimitAllocationDecider extends AllocationDecider {
@Override @Override
public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
IndexMetaData indexMd = allocation.routingNodes().metaData().index(shardRouting.index()); IndexMetaData indexMd = allocation.routingNodes().metaData().getIndexSafe(shardRouting.index());
final int indexShardLimit = INDEX_TOTAL_SHARDS_PER_NODE_SETTING.get(indexMd.getSettings(), settings); final int indexShardLimit = INDEX_TOTAL_SHARDS_PER_NODE_SETTING.get(indexMd.getSettings(), settings);
// Capture the limit here in case it changes during this method's // Capture the limit here in case it changes during this method's
// execution // execution
@ -123,7 +123,7 @@ public class ShardsLimitAllocationDecider extends AllocationDecider {
@Override @Override
public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
IndexMetaData indexMd = allocation.routingNodes().metaData().index(shardRouting.index()); IndexMetaData indexMd = allocation.routingNodes().metaData().getIndexSafe(shardRouting.index());
final int indexShardLimit = INDEX_TOTAL_SHARDS_PER_NODE_SETTING.get(indexMd.getSettings(), settings); final int indexShardLimit = INDEX_TOTAL_SHARDS_PER_NODE_SETTING.get(indexMd.getSettings(), settings);
// Capture the limit here in case it changes during this method's // Capture the limit here in case it changes during this method's
// execution // execution

View File

@ -553,9 +553,9 @@ public abstract class StreamInput extends InputStream {
} }
} }
public <T extends Writeable> T readOptionalWritable(T prototype) throws IOException { public <T extends Writeable> T readOptionalWritable(Writeable.IOFunction<StreamInput, T> provider) throws IOException {
if (readBoolean()) { if (readBoolean()) {
return (T) prototype.readFrom(this); return provider.apply(this);
} else { } else {
return null; return null;
} }

View File

@ -37,4 +37,15 @@ public interface Writeable<T> extends StreamableReader<T> {
* Write this into the {@linkplain StreamOutput}. * Write this into the {@linkplain StreamOutput}.
*/ */
void writeTo(StreamOutput out) throws IOException; void writeTo(StreamOutput out) throws IOException;
@FunctionalInterface
interface IOFunction<T, R> {
/**
* Applies this function to the given argument.
*
* @param t the function argument
* @return the function result
*/
R apply(T t) throws IOException;
}
} }

View File

@ -269,7 +269,7 @@ public abstract class AsyncShardFetch<T extends BaseNodeResponse> implements Rel
*/ */
// visible for testing // visible for testing
void asyncFetch(final ShardId shardId, final String[] nodesIds, final MetaData metaData) { void asyncFetch(final ShardId shardId, final String[] nodesIds, final MetaData metaData) {
IndexMetaData indexMetaData = metaData.index(shardId.getIndex()); IndexMetaData indexMetaData = metaData.getIndexSafe(shardId.getIndex());
logger.trace("{} fetching [{}] from {}", shardId, type, nodesIds); logger.trace("{} fetching [{}] from {}", shardId, type, nodesIds);
action.list(shardId, indexMetaData, nodesIds, new ActionListener<BaseNodesResponse<T>>() { action.list(shardId, indexMetaData, nodesIds, new ActionListener<BaseNodesResponse<T>>() {
@Override @Override

View File

@ -34,6 +34,7 @@ import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.discovery.Discovery; import org.elasticsearch.discovery.Discovery;
import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.index.Index;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -79,7 +80,7 @@ public class Gateway extends AbstractComponent implements ClusterStateListener {
} }
} }
ObjectFloatHashMap<String> indices = new ObjectFloatHashMap<>(); ObjectFloatHashMap<Index> indices = new ObjectFloatHashMap<>();
MetaData electedGlobalState = null; MetaData electedGlobalState = null;
int found = 0; int found = 0;
for (TransportNodesListGatewayMetaState.NodeGatewayMetaState nodeState : nodesState) { for (TransportNodesListGatewayMetaState.NodeGatewayMetaState nodeState : nodesState) {
@ -93,7 +94,7 @@ public class Gateway extends AbstractComponent implements ClusterStateListener {
electedGlobalState = nodeState.metaData(); electedGlobalState = nodeState.metaData();
} }
for (ObjectCursor<IndexMetaData> cursor : nodeState.metaData().indices().values()) { for (ObjectCursor<IndexMetaData> cursor : nodeState.metaData().indices().values()) {
indices.addTo(cursor.value.getIndex().getName(), 1); indices.addTo(cursor.value.getIndex(), 1);
} }
} }
if (found < requiredAllocation) { if (found < requiredAllocation) {
@ -107,7 +108,7 @@ public class Gateway extends AbstractComponent implements ClusterStateListener {
final Object[] keys = indices.keys; final Object[] keys = indices.keys;
for (int i = 0; i < keys.length; i++) { for (int i = 0; i < keys.length; i++) {
if (keys[i] != null) { if (keys[i] != null) {
String index = (String) keys[i]; Index index = (Index) keys[i];
IndexMetaData electedIndexMetaData = null; IndexMetaData electedIndexMetaData = null;
int indexMetaDataCount = 0; int indexMetaDataCount = 0;
for (TransportNodesListGatewayMetaState.NodeGatewayMetaState nodeState : nodesState) { for (TransportNodesListGatewayMetaState.NodeGatewayMetaState nodeState : nodesState) {

View File

@ -35,6 +35,7 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.index.Index;
import java.nio.file.DirectoryStream; import java.nio.file.DirectoryStream;
import java.nio.file.Files; import java.nio.file.Files;
@ -61,7 +62,7 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
@Nullable @Nullable
private volatile MetaData previousMetaData; private volatile MetaData previousMetaData;
private volatile Set<String> previouslyWrittenIndices = emptySet(); private volatile Set<Index> previouslyWrittenIndices = emptySet();
@Inject @Inject
public GatewayMetaState(Settings settings, NodeEnvironment nodeEnv, MetaStateService metaStateService, public GatewayMetaState(Settings settings, NodeEnvironment nodeEnv, MetaStateService metaStateService,
@ -102,7 +103,6 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
@Override @Override
public void clusterChanged(ClusterChangedEvent event) { public void clusterChanged(ClusterChangedEvent event) {
Set<String> relevantIndices = new HashSet<>();
final ClusterState state = event.state(); final ClusterState state = event.state();
if (state.blocks().disableStatePersistence()) { if (state.blocks().disableStatePersistence()) {
// reset the current metadata, we need to start fresh... // reset the current metadata, we need to start fresh...
@ -113,7 +113,7 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
MetaData newMetaData = state.metaData(); MetaData newMetaData = state.metaData();
// we don't check if metaData changed, since we might be called several times and we need to check dangling... // we don't check if metaData changed, since we might be called several times and we need to check dangling...
Set<Index> relevantIndices = Collections.emptySet();
boolean success = true; boolean success = true;
// write the state if this node is a master eligible node or if it is a data node and has shards allocated on it // write the state if this node is a master eligible node or if it is a data node and has shards allocated on it
if (state.nodes().localNode().masterNode() || state.nodes().localNode().dataNode()) { if (state.nodes().localNode().masterNode() || state.nodes().localNode().dataNode()) {
@ -126,14 +126,14 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
// persistence was disabled or the node was restarted), see getRelevantIndicesOnDataOnlyNode(). // persistence was disabled or the node was restarted), see getRelevantIndicesOnDataOnlyNode().
// we therefore have to check here if we have shards on disk and add their indices to the previouslyWrittenIndices list // we therefore have to check here if we have shards on disk and add their indices to the previouslyWrittenIndices list
if (isDataOnlyNode(state)) { if (isDataOnlyNode(state)) {
Set<String> newPreviouslyWrittenIndices = new HashSet<>(previouslyWrittenIndices.size()); Set<Index> newPreviouslyWrittenIndices = new HashSet<>(previouslyWrittenIndices.size());
for (IndexMetaData indexMetaData : newMetaData) { for (IndexMetaData indexMetaData : newMetaData) {
IndexMetaData indexMetaDataOnDisk = null; IndexMetaData indexMetaDataOnDisk = null;
if (indexMetaData.getState().equals(IndexMetaData.State.CLOSE)) { if (indexMetaData.getState().equals(IndexMetaData.State.CLOSE)) {
indexMetaDataOnDisk = metaStateService.loadIndexState(indexMetaData.getIndex().getName()); indexMetaDataOnDisk = metaStateService.loadIndexState(indexMetaData.getIndex().getName());
} }
if (indexMetaDataOnDisk != null) { if (indexMetaDataOnDisk != null) {
newPreviouslyWrittenIndices.add(indexMetaDataOnDisk.getIndex().getName()); newPreviouslyWrittenIndices.add(indexMetaDataOnDisk.getIndex());
} }
} }
newPreviouslyWrittenIndices.addAll(previouslyWrittenIndices); newPreviouslyWrittenIndices.addAll(previouslyWrittenIndices);
@ -152,9 +152,9 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
} }
} }
Iterable<IndexMetaWriteInfo> writeInfo;
relevantIndices = getRelevantIndices(event.state(), event.previousState(), previouslyWrittenIndices); relevantIndices = getRelevantIndices(event.state(), event.previousState(), previouslyWrittenIndices);
writeInfo = resolveStatesToBeWritten(previouslyWrittenIndices, relevantIndices, previousMetaData, event.state().metaData()); final Iterable<IndexMetaWriteInfo> writeInfo = resolveStatesToBeWritten(previouslyWrittenIndices, relevantIndices, previousMetaData, event.state().metaData());
// check and write changes in indices // check and write changes in indices
for (IndexMetaWriteInfo indexMetaWrite : writeInfo) { for (IndexMetaWriteInfo indexMetaWrite : writeInfo) {
try { try {
@ -173,8 +173,8 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
} }
} }
public static Set<String> getRelevantIndices(ClusterState state, ClusterState previousState, Set<String> previouslyWrittenIndices) { public static Set<Index> getRelevantIndices(ClusterState state, ClusterState previousState, Set<Index> previouslyWrittenIndices) {
Set<String> relevantIndices; Set<Index> relevantIndices;
if (isDataOnlyNode(state)) { if (isDataOnlyNode(state)) {
relevantIndices = getRelevantIndicesOnDataOnlyNode(state, previousState, previouslyWrittenIndices); relevantIndices = getRelevantIndicesOnDataOnlyNode(state, previousState, previouslyWrittenIndices);
} else if (state.nodes().localNode().masterNode() == true) { } else if (state.nodes().localNode().masterNode() == true) {
@ -264,10 +264,10 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
* @param newMetaData The new metadata * @param newMetaData The new metadata
* @return iterable over all indices states that should be written to disk * @return iterable over all indices states that should be written to disk
*/ */
public static Iterable<GatewayMetaState.IndexMetaWriteInfo> resolveStatesToBeWritten(Set<String> previouslyWrittenIndices, Set<String> potentiallyUnwrittenIndices, MetaData previousMetaData, MetaData newMetaData) { public static Iterable<GatewayMetaState.IndexMetaWriteInfo> resolveStatesToBeWritten(Set<Index> previouslyWrittenIndices, Set<Index> potentiallyUnwrittenIndices, MetaData previousMetaData, MetaData newMetaData) {
List<GatewayMetaState.IndexMetaWriteInfo> indicesToWrite = new ArrayList<>(); List<GatewayMetaState.IndexMetaWriteInfo> indicesToWrite = new ArrayList<>();
for (String index : potentiallyUnwrittenIndices) { for (Index index : potentiallyUnwrittenIndices) {
IndexMetaData newIndexMetaData = newMetaData.index(index); IndexMetaData newIndexMetaData = newMetaData.getIndexSafe(index);
IndexMetaData previousIndexMetaData = previousMetaData == null ? null : previousMetaData.index(index); IndexMetaData previousIndexMetaData = previousMetaData == null ? null : previousMetaData.index(index);
String writeReason = null; String writeReason = null;
if (previouslyWrittenIndices.contains(index) == false || previousIndexMetaData == null) { if (previouslyWrittenIndices.contains(index) == false || previousIndexMetaData == null) {
@ -282,14 +282,14 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
return indicesToWrite; return indicesToWrite;
} }
public static Set<String> getRelevantIndicesOnDataOnlyNode(ClusterState state, ClusterState previousState, Set<String> previouslyWrittenIndices) { public static Set<Index> getRelevantIndicesOnDataOnlyNode(ClusterState state, ClusterState previousState, Set<Index> previouslyWrittenIndices) {
RoutingNode newRoutingNode = state.getRoutingNodes().node(state.nodes().localNodeId()); RoutingNode newRoutingNode = state.getRoutingNodes().node(state.nodes().localNodeId());
if (newRoutingNode == null) { if (newRoutingNode == null) {
throw new IllegalStateException("cluster state does not contain this node - cannot write index meta state"); throw new IllegalStateException("cluster state does not contain this node - cannot write index meta state");
} }
Set<String> indices = new HashSet<>(); Set<Index> indices = new HashSet<>();
for (ShardRouting routing : newRoutingNode) { for (ShardRouting routing : newRoutingNode) {
indices.add(routing.index().getName()); indices.add(routing.index());
} }
// we have to check the meta data also: closed indices will not appear in the routing table, but we must still write the state if we have it written on disk previously // we have to check the meta data also: closed indices will not appear in the routing table, but we must still write the state if we have it written on disk previously
for (IndexMetaData indexMetaData : state.metaData()) { for (IndexMetaData indexMetaData : state.metaData()) {
@ -300,19 +300,19 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
if (previousMetaData != null) { if (previousMetaData != null) {
isOrWasClosed = isOrWasClosed || previousMetaData.getState().equals(IndexMetaData.State.CLOSE); isOrWasClosed = isOrWasClosed || previousMetaData.getState().equals(IndexMetaData.State.CLOSE);
} }
if (previouslyWrittenIndices.contains(indexMetaData.getIndex().getName()) && isOrWasClosed) { if (previouslyWrittenIndices.contains(indexMetaData.getIndex()) && isOrWasClosed) {
indices.add(indexMetaData.getIndex().getName()); indices.add(indexMetaData.getIndex());
} }
} }
return indices; return indices;
} }
public static Set<String> getRelevantIndicesForMasterEligibleNode(ClusterState state) { public static Set<Index> getRelevantIndicesForMasterEligibleNode(ClusterState state) {
Set<String> relevantIndices; Set<Index> relevantIndices;
relevantIndices = new HashSet<>(); relevantIndices = new HashSet<>();
// we have to iterate over the metadata to make sure we also capture closed indices // we have to iterate over the metadata to make sure we also capture closed indices
for (IndexMetaData indexMetaData : state.metaData()) { for (IndexMetaData indexMetaData : state.metaData()) {
relevantIndices.add(indexMetaData.getIndex().getName()); relevantIndices.add(indexMetaData.getIndex());
} }
return relevantIndices; return relevantIndices;
} }

View File

@ -94,7 +94,7 @@ public abstract class PrimaryShardAllocator extends AbstractComponent {
continue; continue;
} }
final IndexMetaData indexMetaData = metaData.index(shard.getIndexName()); final IndexMetaData indexMetaData = metaData.getIndexSafe(shard.index());
// don't go wild here and create a new IndexSetting object for every shard this could cause a lot of garbage // don't go wild here and create a new IndexSetting object for every shard this could cause a lot of garbage
// on cluster restart if we allocate a boat load of shards // on cluster restart if we allocate a boat load of shards
if (shard.allocatedPostIndexCreate(indexMetaData) == false) { if (shard.allocatedPostIndexCreate(indexMetaData) == false) {

View File

@ -23,6 +23,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import java.util.Comparator; import java.util.Comparator;
@ -42,8 +43,8 @@ public abstract class PriorityComparator implements Comparator<ShardRouting> {
final String o2Index = o2.getIndexName(); final String o2Index = o2.getIndexName();
int cmp = 0; int cmp = 0;
if (o1Index.equals(o2Index) == false) { if (o1Index.equals(o2Index) == false) {
final Settings settingsO1 = getIndexSettings(o1Index); final Settings settingsO1 = getIndexSettings(o1.index());
final Settings settingsO2 = getIndexSettings(o2Index); final Settings settingsO2 = getIndexSettings(o2.index());
cmp = Long.compare(priority(settingsO2), priority(settingsO1)); cmp = Long.compare(priority(settingsO2), priority(settingsO1));
if (cmp == 0) { if (cmp == 0) {
cmp = Long.compare(timeCreated(settingsO2), timeCreated(settingsO1)); cmp = Long.compare(timeCreated(settingsO2), timeCreated(settingsO1));
@ -63,7 +64,7 @@ public abstract class PriorityComparator implements Comparator<ShardRouting> {
return settings.getAsLong(IndexMetaData.SETTING_CREATION_DATE, -1L); return settings.getAsLong(IndexMetaData.SETTING_CREATION_DATE, -1L);
} }
protected abstract Settings getIndexSettings(String index); protected abstract Settings getIndexSettings(Index index);
/** /**
* Returns a PriorityComparator that uses the RoutingAllocation index metadata to access the index setting per index. * Returns a PriorityComparator that uses the RoutingAllocation index metadata to access the index setting per index.
@ -71,8 +72,8 @@ public abstract class PriorityComparator implements Comparator<ShardRouting> {
public static PriorityComparator getAllocationComparator(final RoutingAllocation allocation) { public static PriorityComparator getAllocationComparator(final RoutingAllocation allocation) {
return new PriorityComparator() { return new PriorityComparator() {
@Override @Override
protected Settings getIndexSettings(String index) { protected Settings getIndexSettings(Index index) {
IndexMetaData indexMetaData = allocation.metaData().index(index); IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(index);
return indexMetaData.getSettings(); return indexMetaData.getSettings();
} }
}; };

View File

@ -74,7 +74,7 @@ public abstract class ReplicaShardAllocator extends AbstractComponent {
} }
// if we are allocating a replica because of index creation, no need to go and find a copy, there isn't one... // if we are allocating a replica because of index creation, no need to go and find a copy, there isn't one...
IndexMetaData indexMetaData = metaData.index(shard.getIndexName()); IndexMetaData indexMetaData = metaData.getIndexSafe(shard.index());
if (shard.allocatedPostIndexCreate(indexMetaData) == false) { if (shard.allocatedPostIndexCreate(indexMetaData) == false) {
continue; continue;
} }
@ -129,7 +129,7 @@ public abstract class ReplicaShardAllocator extends AbstractComponent {
} }
// if we are allocating a replica because of index creation, no need to go and find a copy, there isn't one... // if we are allocating a replica because of index creation, no need to go and find a copy, there isn't one...
IndexMetaData indexMetaData = metaData.index(shard.getIndexName()); IndexMetaData indexMetaData = metaData.getIndexSafe(shard.index());
if (shard.allocatedPostIndexCreate(indexMetaData) == false) { if (shard.allocatedPostIndexCreate(indexMetaData) == false) {
continue; continue;
} }

View File

@ -125,7 +125,7 @@ public class TransportNodesListGatewayStartedShards extends TransportNodesAction
logger.trace("{} loading local shard state info", shardId); logger.trace("{} loading local shard state info", shardId);
ShardStateMetaData shardStateMetaData = ShardStateMetaData.FORMAT.loadLatestState(logger, nodeEnv.availableShardPaths(request.shardId)); ShardStateMetaData shardStateMetaData = ShardStateMetaData.FORMAT.loadLatestState(logger, nodeEnv.availableShardPaths(request.shardId));
if (shardStateMetaData != null) { if (shardStateMetaData != null) {
final IndexMetaData metaData = clusterService.state().metaData().index(shardId.getIndexName()); // it's a mystery why this is sometimes null final IndexMetaData metaData = clusterService.state().metaData().index(shardId.getIndex()); // it's a mystery why this is sometimes null
if (metaData != null) { if (metaData != null) {
ShardPath shardPath = null; ShardPath shardPath = null;
try { try {

View File

@ -31,7 +31,7 @@ import java.io.IOException;
*/ */
public class Index implements Writeable<Index> { public class Index implements Writeable<Index> {
private final static Index PROTO = new Index("", ""); public static final Index[] EMPTY_ARRAY = new Index[0];
private final String name; private final String name;
private final String uuid; private final String uuid;
@ -41,6 +41,12 @@ public class Index implements Writeable<Index> {
this.uuid = uuid.intern(); this.uuid = uuid.intern();
} }
public Index(StreamInput in) throws IOException {
this.name = in.readString();
this.uuid = in.readString();
}
public String getName() { public String getName() {
return this.name; return this.name;
} }
@ -80,13 +86,9 @@ public class Index implements Writeable<Index> {
return result; return result;
} }
public static Index readIndex(StreamInput in) throws IOException {
return PROTO.readFrom(in);
}
@Override @Override
public Index readFrom(StreamInput in) throws IOException { public Index readFrom(StreamInput in) throws IOException {
return new Index(in.readString(), in.readString()); return new Index(in);
} }
@Override @Override

View File

@ -98,7 +98,7 @@ public class ShardId implements Streamable, Comparable<ShardId> {
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
index = Index.readIndex(in); index = new Index(in);
shardId = in.readVInt(); shardId = in.readVInt();
hashCode = computeHashCode(); hashCode = computeHashCode();
} }

View File

@ -172,7 +172,7 @@ public class NodeIndicesStats implements Streamable, ToXContent {
int entries = in.readVInt(); int entries = in.readVInt();
statsByShard = new HashMap<>(); statsByShard = new HashMap<>();
for (int i = 0; i < entries; i++) { for (int i = 0; i < entries; i++) {
Index index = Index.readIndex(in); Index index = new Index(in);
int indexShardListSize = in.readVInt(); int indexShardListSize = in.readVInt();
List<IndexShardStats> indexShardStats = new ArrayList<>(indexShardListSize); List<IndexShardStats> indexShardStats = new ArrayList<>(indexShardListSize);
for (int j = 0; j < indexShardListSize; j++) { for (int j = 0; j < indexShardListSize; j++) {

View File

@ -188,15 +188,15 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
// handle closed indices, since they are not allocated on a node once they are closed // handle closed indices, since they are not allocated on a node once they are closed
// so applyDeletedIndices might not take them into account // so applyDeletedIndices might not take them into account
for (IndexService indexService : indicesService) { for (IndexService indexService : indicesService) {
String index = indexService.index().getName(); Index index = indexService.index();
IndexMetaData indexMetaData = event.state().metaData().index(index); IndexMetaData indexMetaData = event.state().metaData().index(index);
if (indexMetaData != null && indexMetaData.getState() == IndexMetaData.State.CLOSE) { if (indexMetaData != null && indexMetaData.getState() == IndexMetaData.State.CLOSE) {
for (Integer shardId : indexService.shardIds()) { for (Integer shardId : indexService.shardIds()) {
logger.debug("[{}][{}] removing shard (index is closed)", index, shardId); logger.debug("{}[{}] removing shard (index is closed)", index, shardId);
try { try {
indexService.removeShard(shardId, "removing shard (index is closed)"); indexService.removeShard(shardId, "removing shard (index is closed)");
} catch (Throwable e) { } catch (Throwable e) {
logger.warn("[{}] failed to remove shard (index is closed)", e, index); logger.warn("{} failed to remove shard (index is closed)", e, index);
} }
} }
} }
@ -238,13 +238,12 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
indexSettings = idxService.getIndexSettings(); indexSettings = idxService.getIndexSettings();
deleteIndex(index, "index no longer part of the metadata"); deleteIndex(index, "index no longer part of the metadata");
} else { } else {
final IndexMetaData metaData = previousState.metaData().index(index); final IndexMetaData metaData = previousState.metaData().getIndexSafe(index);
assert metaData != null;
indexSettings = new IndexSettings(metaData, settings); indexSettings = new IndexSettings(metaData, settings);
indicesService.deleteClosedIndex("closed index no longer part of the metadata", metaData, event.state()); indicesService.deleteClosedIndex("closed index no longer part of the metadata", metaData, event.state());
} }
try { try {
nodeIndexDeletedAction.nodeIndexDeleted(event.state(), index.getName(), indexSettings, localNodeId); nodeIndexDeletedAction.nodeIndexDeleted(event.state(), index, indexSettings, localNodeId);
} catch (Throwable e) { } catch (Throwable e) {
logger.debug("failed to send to master index {} deleted event", e, index); logger.debug("failed to send to master index {} deleted event", e, index);
} }
@ -260,15 +259,15 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
} }
IntHashSet newShardIds = new IntHashSet(); IntHashSet newShardIds = new IntHashSet();
for (IndexService indexService : indicesService) { for (IndexService indexService : indicesService) {
String indexName = indexService.index().getName(); Index index = indexService.index();
IndexMetaData indexMetaData = event.state().metaData().index(indexName); IndexMetaData indexMetaData = event.state().metaData().getIndexSafe(index);
if (indexMetaData == null) { if (indexMetaData == null) {
continue; continue;
} }
// now, go over and delete shards that needs to get deleted // now, go over and delete shards that needs to get deleted
newShardIds.clear(); newShardIds.clear();
for (ShardRouting shard : routingNode) { for (ShardRouting shard : routingNode) {
if (shard.index().getName().equals(indexName)) { if (shard.index().equals(index)) {
newShardIds.add(shard.id()); newShardIds.add(shard.id());
} }
} }
@ -276,14 +275,14 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
if (!newShardIds.contains(existingShardId)) { if (!newShardIds.contains(existingShardId)) {
if (indexMetaData.getState() == IndexMetaData.State.CLOSE) { if (indexMetaData.getState() == IndexMetaData.State.CLOSE) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("[{}][{}] removing shard (index is closed)", indexName, existingShardId); logger.debug("{}[{}] removing shard (index is closed)", index, existingShardId);
} }
indexService.removeShard(existingShardId, "removing shard (index is closed)"); indexService.removeShard(existingShardId, "removing shard (index is closed)");
} else { } else {
// we can just remove the shard, without cleaning it locally, since we will clean it // we can just remove the shard, without cleaning it locally, since we will clean it
// when all shards are allocated in the IndicesStore // when all shards are allocated in the IndicesStore
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("[{}][{}] removing shard (not allocated)", indexName, existingShardId); logger.debug("{}[{}] removing shard (not allocated)", index, existingShardId);
} }
indexService.removeShard(existingShardId, "removing shard (not allocated)"); indexService.removeShard(existingShardId, "removing shard (not allocated)");
} }
@ -300,7 +299,7 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
} }
for (ShardRouting shard : routingNode) { for (ShardRouting shard : routingNode) {
if (!indicesService.hasIndex(shard.index())) { if (!indicesService.hasIndex(shard.index())) {
final IndexMetaData indexMetaData = event.state().metaData().index(shard.index()); final IndexMetaData indexMetaData = event.state().metaData().getIndexSafe(shard.index());
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("[{}] creating index", indexMetaData.getIndex()); logger.debug("[{}] creating index", indexMetaData.getIndex());
} }

View File

@ -39,6 +39,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections; import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.common.util.concurrent.CountDown; import org.elasticsearch.common.util.concurrent.CountDown;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.IndexService; import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.engine.Engine;
@ -111,15 +112,15 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
*/ */
public void attemptSyncedFlush(final String[] aliasesOrIndices, IndicesOptions indicesOptions, final ActionListener<SyncedFlushResponse> listener) { public void attemptSyncedFlush(final String[] aliasesOrIndices, IndicesOptions indicesOptions, final ActionListener<SyncedFlushResponse> listener) {
final ClusterState state = clusterService.state(); final ClusterState state = clusterService.state();
final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, indicesOptions, aliasesOrIndices); final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, indicesOptions, aliasesOrIndices);
final Map<String, List<ShardsSyncedFlushResult>> results = ConcurrentCollections.newConcurrentMap(); final Map<String, List<ShardsSyncedFlushResult>> results = ConcurrentCollections.newConcurrentMap();
int totalNumberOfShards = 0; int totalNumberOfShards = 0;
int numberOfShards = 0; int numberOfShards = 0;
for (String index : concreteIndices) { for (Index index : concreteIndices) {
final IndexMetaData indexMetaData = state.metaData().index(index); final IndexMetaData indexMetaData = state.metaData().getIndexSafe(index);
totalNumberOfShards += indexMetaData.getTotalNumberOfShards(); totalNumberOfShards += indexMetaData.getTotalNumberOfShards();
numberOfShards += indexMetaData.getNumberOfShards(); numberOfShards += indexMetaData.getNumberOfShards();
results.put(index, Collections.synchronizedList(new ArrayList<>())); results.put(index.getName(), Collections.synchronizedList(new ArrayList<>()));
} }
if (numberOfShards == 0) { if (numberOfShards == 0) {
@ -129,8 +130,9 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
final int finalTotalNumberOfShards = totalNumberOfShards; final int finalTotalNumberOfShards = totalNumberOfShards;
final CountDown countDown = new CountDown(numberOfShards); final CountDown countDown = new CountDown(numberOfShards);
for (final String index : concreteIndices) { for (final Index concreteIndex : concreteIndices) {
final IndexMetaData indexMetaData = state.metaData().index(index); final String index = concreteIndex.getName();
final IndexMetaData indexMetaData = state.metaData().getIndexSafe(concreteIndex);
final int indexNumberOfShards = indexMetaData.getNumberOfShards(); final int indexNumberOfShards = indexMetaData.getNumberOfShards();
for (int shard = 0; shard < indexNumberOfShards; shard++) { for (int shard = 0; shard < indexNumberOfShards; shard++) {
final ShardId shardId = new ShardId(indexMetaData.getIndex(), shard); final ShardId shardId = new ShardId(indexMetaData.getIndex(), shard);
@ -240,7 +242,7 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL
final IndexShardRoutingTable getShardRoutingTable(ShardId shardId, ClusterState state) { final IndexShardRoutingTable getShardRoutingTable(ShardId shardId, ClusterState state) {
final IndexRoutingTable indexRoutingTable = state.routingTable().index(shardId.getIndexName()); final IndexRoutingTable indexRoutingTable = state.routingTable().index(shardId.getIndexName());
if (indexRoutingTable == null) { if (indexRoutingTable == null) {
IndexMetaData index = state.getMetaData().index(shardId.getIndexName()); IndexMetaData index = state.getMetaData().index(shardId.getIndex());
if (index != null && index.getState() == IndexMetaData.State.CLOSE) { if (index != null && index.getState() == IndexMetaData.State.CLOSE) {
throw new IndexClosedException(shardId.getIndex()); throw new IndexClosedException(shardId.getIndex());
} }

View File

@ -26,6 +26,7 @@ import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ClusterStateListener; import org.elasticsearch.cluster.ClusterStateListener;
import org.elasticsearch.cluster.ClusterStateObserver; import org.elasticsearch.cluster.ClusterStateObserver;
import org.elasticsearch.cluster.ClusterStateUpdateTask; import org.elasticsearch.cluster.ClusterStateUpdateTask;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexRoutingTable;
import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
@ -115,7 +116,13 @@ public class IndicesStore extends AbstractComponent implements ClusterStateListe
if (shardCanBeDeleted(event.state(), indexShardRoutingTable)) { if (shardCanBeDeleted(event.state(), indexShardRoutingTable)) {
ShardId shardId = indexShardRoutingTable.shardId(); ShardId shardId = indexShardRoutingTable.shardId();
IndexService indexService = indicesService.indexService(indexRoutingTable.getIndex()); IndexService indexService = indicesService.indexService(indexRoutingTable.getIndex());
IndexSettings indexSettings = indexService != null ? indexService.getIndexSettings() : new IndexSettings(event.state().getMetaData().index(indexRoutingTable.getIndex()), settings); final IndexSettings indexSettings;
if (indexService == null) {
IndexMetaData indexMetaData = event.state().getMetaData().getIndexSafe(indexRoutingTable.getIndex());
indexSettings = new IndexSettings(indexMetaData, settings);
} else {
indexSettings = indexService.getIndexSettings();
}
if (indicesService.canDeleteShardContent(shardId, indexSettings)) { if (indicesService.canDeleteShardContent(shardId, indexSettings)) {
deleteShardIfExistElseWhere(event.state(), indexShardRoutingTable); deleteShardIfExistElseWhere(event.state(), indexShardRoutingTable);
} }
@ -164,7 +171,7 @@ public class IndicesStore extends AbstractComponent implements ClusterStateListe
private void deleteShardIfExistElseWhere(ClusterState state, IndexShardRoutingTable indexShardRoutingTable) { private void deleteShardIfExistElseWhere(ClusterState state, IndexShardRoutingTable indexShardRoutingTable) {
List<Tuple<DiscoveryNode, ShardActiveRequest>> requests = new ArrayList<>(indexShardRoutingTable.size()); List<Tuple<DiscoveryNode, ShardActiveRequest>> requests = new ArrayList<>(indexShardRoutingTable.size());
String indexUUID = state.getMetaData().index(indexShardRoutingTable.shardId().getIndex()).getIndexUUID(); String indexUUID = indexShardRoutingTable.shardId().getIndex().getUUID();
ClusterName clusterName = state.getClusterName(); ClusterName clusterName = state.getClusterName();
for (ShardRouting shardRouting : indexShardRoutingTable) { for (ShardRouting shardRouting : indexShardRoutingTable) {
// Node can't be null, because otherwise shardCanBeDeleted() would have returned false // Node can't be null, because otherwise shardCanBeDeleted() would have returned false

View File

@ -134,7 +134,7 @@ public class TransportNodesListShardStoreMetaData extends TransportNodesAction<T
return new NodeStoreFilesMetaData(clusterService.localNode(), null); return new NodeStoreFilesMetaData(clusterService.localNode(), null);
} }
} }
IndexMetaData metaData = clusterService.state().metaData().index(request.shardId.getIndexName()); IndexMetaData metaData = clusterService.state().metaData().index(request.shardId.getIndex());
if (metaData == null) { if (metaData == null) {
return new NodeStoreFilesMetaData(clusterService.localNode(), null); return new NodeStoreFilesMetaData(clusterService.localNode(), null);
} }
@ -165,7 +165,7 @@ public class TransportNodesListShardStoreMetaData extends TransportNodesAction<T
} }
} }
// try and see if we an list unallocated // try and see if we an list unallocated
IndexMetaData metaData = clusterService.state().metaData().index(shardId.getIndexName()); IndexMetaData metaData = clusterService.state().metaData().index(shardId.getIndex());
if (metaData == null) { if (metaData == null) {
return new StoreFilesMetaData(false, shardId, Store.MetadataSnapshot.EMPTY); return new StoreFilesMetaData(false, shardId, Store.MetadataSnapshot.EMPTY);
} }

View File

@ -162,7 +162,7 @@ public class IndicesTTLService extends AbstractLifecycleComponent<IndicesTTLServ
MetaData metaData = clusterService.state().metaData(); MetaData metaData = clusterService.state().metaData();
for (IndexService indexService : indicesService) { for (IndexService indexService : indicesService) {
// check the value of disable_purge for this index // check the value of disable_purge for this index
IndexMetaData indexMetaData = metaData.index(indexService.index().getName()); IndexMetaData indexMetaData = metaData.index(indexService.index());
if (indexMetaData == null) { if (indexMetaData == null) {
continue; continue;
} }

View File

@ -83,8 +83,8 @@ public class RestIndicesAction extends AbstractCatAction {
public void processResponse(final ClusterStateResponse clusterStateResponse) { public void processResponse(final ClusterStateResponse clusterStateResponse) {
ClusterState state = clusterStateResponse.getState(); ClusterState state = clusterStateResponse.getState();
final IndicesOptions concreteIndicesOptions = IndicesOptions.fromOptions(false, true, true, true); final IndicesOptions concreteIndicesOptions = IndicesOptions.fromOptions(false, true, true, true);
final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, concreteIndicesOptions, indices); final String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, concreteIndicesOptions, indices);
final String[] openIndices = indexNameExpressionResolver.concreteIndices(state, IndicesOptions.lenientExpandOpen(), indices); final String[] openIndices = indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), indices);
ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(openIndices); ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(openIndices);
clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local())); clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local()));
client.admin().cluster().health(clusterHealthRequest, new RestActionListener<ClusterHealthResponse>(channel) { client.admin().cluster().health(clusterHealthRequest, new RestActionListener<ClusterHealthResponse>(channel) {

View File

@ -191,7 +191,7 @@ public class RestShardsAction extends AbstractCatAction {
table.addCell(shard.getIndexName()); table.addCell(shard.getIndexName());
table.addCell(shard.id()); table.addCell(shard.id());
IndexMetaData indexMeta = state.getState().getMetaData().index(shard.index()); IndexMetaData indexMeta = state.getState().getMetaData().getIndexSafe(shard.index());
boolean usesShadowReplicas = false; boolean usesShadowReplicas = false;
if (indexMeta != null) { if (indexMeta != null) {
usesShadowReplicas = IndexMetaData.isIndexUsingShadowReplicas(indexMeta.getSettings()); usesShadowReplicas = IndexMetaData.isIndexUsingShadowReplicas(indexMeta.getSettings());

View File

@ -195,7 +195,7 @@ public class SearchService extends AbstractLifecycleComponent<SearchService> imp
public void afterIndexClosed(Index index, Settings indexSettings) { public void afterIndexClosed(Index index, Settings indexSettings) {
// once an index is closed we can just clean up all the pending search context information // once an index is closed we can just clean up all the pending search context information
// to release memory and let references to the filesystem go etc. // to release memory and let references to the filesystem go etc.
IndexMetaData idxMeta = SearchService.this.clusterService.state().metaData().index(index.getName()); IndexMetaData idxMeta = SearchService.this.clusterService.state().metaData().index(index);
if (idxMeta != null && idxMeta.getState() == IndexMetaData.State.CLOSE) { if (idxMeta != null && idxMeta.getState() == IndexMetaData.State.CLOSE) {
// we need to check if it's really closed // we need to check if it's really closed
// since sometimes due to a relocation we already closed the shard and that causes the index to be closed // since sometimes due to a relocation we already closed the shard and that causes the index to be closed

View File

@ -778,18 +778,19 @@ public class RestoreService extends AbstractComponent implements ClusterStateLis
* Check if any of the indices to be closed are currently being restored from a snapshot and fail closing if such an index * Check if any of the indices to be closed are currently being restored from a snapshot and fail closing if such an index
* is found as closing an index that is being restored makes the index unusable (it cannot be recovered). * is found as closing an index that is being restored makes the index unusable (it cannot be recovered).
*/ */
public static void checkIndexClosing(ClusterState currentState, Set<String> indices) { public static void checkIndexClosing(ClusterState currentState, Set<IndexMetaData> indices) {
RestoreInProgress restore = currentState.custom(RestoreInProgress.TYPE); RestoreInProgress restore = currentState.custom(RestoreInProgress.TYPE);
if (restore != null) { if (restore != null) {
Set<String> indicesToFail = null; Set<Index> indicesToFail = null;
for (RestoreInProgress.Entry entry : restore.entries()) { for (RestoreInProgress.Entry entry : restore.entries()) {
for (ObjectObjectCursor<ShardId, RestoreInProgress.ShardRestoreStatus> shard : entry.shards()) { for (ObjectObjectCursor<ShardId, RestoreInProgress.ShardRestoreStatus> shard : entry.shards()) {
if (!shard.value.state().completed()) { if (!shard.value.state().completed()) {
if (indices.contains(shard.key.getIndexName())) { IndexMetaData indexMetaData = currentState.metaData().index(shard.key.getIndex());
if (indexMetaData != null && indices.contains(indexMetaData)) {
if (indicesToFail == null) { if (indicesToFail == null) {
indicesToFail = new HashSet<>(); indicesToFail = new HashSet<>();
} }
indicesToFail.add(shard.key.getIndexName()); indicesToFail.add(shard.key.getIndex());
} }
} }
} }

View File

@ -51,6 +51,7 @@ import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.snapshots.IndexShardRepository; import org.elasticsearch.index.snapshots.IndexShardRepository;
import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus; import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus;
@ -204,7 +205,7 @@ public class SnapshotsService extends AbstractLifecycleComponent<SnapshotsServic
SnapshotsInProgress snapshots = currentState.custom(SnapshotsInProgress.TYPE); SnapshotsInProgress snapshots = currentState.custom(SnapshotsInProgress.TYPE);
if (snapshots == null || snapshots.entries().isEmpty()) { if (snapshots == null || snapshots.entries().isEmpty()) {
// Store newSnapshot here to be processed in clusterStateProcessed // Store newSnapshot here to be processed in clusterStateProcessed
List<String> indices = Arrays.asList(indexNameExpressionResolver.concreteIndices(currentState, request.indicesOptions(), request.indices())); List<String> indices = Arrays.asList(indexNameExpressionResolver.concreteIndexNames(currentState, request.indicesOptions(), request.indices()));
logger.trace("[{}][{}] creating snapshot for indices [{}]", request.repository(), request.name(), indices); logger.trace("[{}][{}] creating snapshot for indices [{}]", request.repository(), request.name(), indices);
newSnapshot = new SnapshotsInProgress.Entry(snapshotId, request.includeGlobalState(), request.partial(), State.INIT, indices, System.currentTimeMillis(), null); newSnapshot = new SnapshotsInProgress.Entry(snapshotId, request.includeGlobalState(), request.partial(), State.INIT, indices, System.currentTimeMillis(), null);
snapshots = new SnapshotsInProgress(newSnapshot); snapshots = new SnapshotsInProgress(newSnapshot);
@ -751,7 +752,7 @@ public class SnapshotsService extends AbstractLifecycleComponent<SnapshotsServic
Set<String> closed = new HashSet<>(); Set<String> closed = new HashSet<>();
for (ObjectObjectCursor<ShardId, SnapshotsInProgress.ShardSnapshotStatus> entry : shards) { for (ObjectObjectCursor<ShardId, SnapshotsInProgress.ShardSnapshotStatus> entry : shards) {
if (entry.value.state() == State.MISSING) { if (entry.value.state() == State.MISSING) {
if (metaData.hasIndex(entry.key.getIndex().getName()) && metaData.index(entry.key.getIndex()).getState() == IndexMetaData.State.CLOSE) { if (metaData.hasIndex(entry.key.getIndex().getName()) && metaData.getIndexSafe(entry.key.getIndex()).getState() == IndexMetaData.State.CLOSE) {
closed.add(entry.key.getIndex().getName()); closed.add(entry.key.getIndex().getName());
} else { } else {
missing.add(entry.key.getIndex().getName()); missing.add(entry.key.getIndex().getName());
@ -1065,8 +1066,8 @@ public class SnapshotsService extends AbstractLifecycleComponent<SnapshotsServic
* Check if any of the indices to be deleted are currently being snapshotted. Fail as deleting an index that is being * Check if any of the indices to be deleted are currently being snapshotted. Fail as deleting an index that is being
* snapshotted (with partial == false) makes the snapshot fail. * snapshotted (with partial == false) makes the snapshot fail.
*/ */
public static void checkIndexDeletion(ClusterState currentState, Set<String> indices) { public static void checkIndexDeletion(ClusterState currentState, Set<IndexMetaData> indices) {
Set<String> indicesToFail = indicesToFailForCloseOrDeletion(currentState, indices); Set<Index> indicesToFail = indicesToFailForCloseOrDeletion(currentState, indices);
if (indicesToFail != null) { if (indicesToFail != null) {
throw new IllegalArgumentException("Cannot delete indices that are being snapshotted: " + indicesToFail + throw new IllegalArgumentException("Cannot delete indices that are being snapshotted: " + indicesToFail +
". Try again after snapshot finishes or cancel the currently running snapshot."); ". Try again after snapshot finishes or cancel the currently running snapshot.");
@ -1077,37 +1078,39 @@ public class SnapshotsService extends AbstractLifecycleComponent<SnapshotsServic
* Check if any of the indices to be closed are currently being snapshotted. Fail as closing an index that is being * Check if any of the indices to be closed are currently being snapshotted. Fail as closing an index that is being
* snapshotted (with partial == false) makes the snapshot fail. * snapshotted (with partial == false) makes the snapshot fail.
*/ */
public static void checkIndexClosing(ClusterState currentState, Set<String> indices) { public static void checkIndexClosing(ClusterState currentState, Set<IndexMetaData> indices) {
Set<String> indicesToFail = indicesToFailForCloseOrDeletion(currentState, indices); Set<Index> indicesToFail = indicesToFailForCloseOrDeletion(currentState, indices);
if (indicesToFail != null) { if (indicesToFail != null) {
throw new IllegalArgumentException("Cannot close indices that are being snapshotted: " + indicesToFail + throw new IllegalArgumentException("Cannot close indices that are being snapshotted: " + indicesToFail +
". Try again after snapshot finishes or cancel the currently running snapshot."); ". Try again after snapshot finishes or cancel the currently running snapshot.");
} }
} }
private static Set<String> indicesToFailForCloseOrDeletion(ClusterState currentState, Set<String> indices) { private static Set<Index> indicesToFailForCloseOrDeletion(ClusterState currentState, Set<IndexMetaData> indices) {
SnapshotsInProgress snapshots = currentState.custom(SnapshotsInProgress.TYPE); SnapshotsInProgress snapshots = currentState.custom(SnapshotsInProgress.TYPE);
Set<String> indicesToFail = null; Set<Index> indicesToFail = null;
if (snapshots != null) { if (snapshots != null) {
for (final SnapshotsInProgress.Entry entry : snapshots.entries()) { for (final SnapshotsInProgress.Entry entry : snapshots.entries()) {
if (entry.partial() == false) { if (entry.partial() == false) {
if (entry.state() == State.INIT) { if (entry.state() == State.INIT) {
for (String index : entry.indices()) { for (String index : entry.indices()) {
if (indices.contains(index)) { IndexMetaData indexMetaData = currentState.metaData().index(index);
if (indexMetaData != null && indices.contains(indexMetaData)) {
if (indicesToFail == null) { if (indicesToFail == null) {
indicesToFail = new HashSet<>(); indicesToFail = new HashSet<>();
} }
indicesToFail.add(index); indicesToFail.add(indexMetaData.getIndex());
} }
} }
} else { } else {
for (ObjectObjectCursor<ShardId, SnapshotsInProgress.ShardSnapshotStatus> shard : entry.shards()) { for (ObjectObjectCursor<ShardId, SnapshotsInProgress.ShardSnapshotStatus> shard : entry.shards()) {
if (!shard.value.state().completed()) { if (!shard.value.state().completed()) {
if (indices.contains(shard.key.getIndexName())) { IndexMetaData indexMetaData = currentState.metaData().index(shard.key.getIndex());
if (indexMetaData != null && indices.contains(indexMetaData)) {
if (indicesToFail == null) { if (indicesToFail == null) {
indicesToFail = new HashSet<>(); indicesToFail = new HashSet<>();
} }
indicesToFail.add(shard.key.getIndexName()); indicesToFail.add(shard.key.getIndex());
} }
} }
} }

View File

@ -405,9 +405,11 @@ public class TribeService extends AbstractLifecycleComponent<TribeService> {
if (table == null) { if (table == null) {
continue; continue;
} }
final IndexMetaData indexMetaData = currentState.metaData().index(tribeIndex.getIndex()); //NOTE: we have to use the index name here since UUID are different even if the name is the same
final String indexName = tribeIndex.getIndex().getName();
final IndexMetaData indexMetaData = currentState.metaData().index(indexName);
if (indexMetaData == null) { if (indexMetaData == null) {
if (!droppedIndices.contains(tribeIndex.getIndex().getName())) { if (!droppedIndices.contains(indexName)) {
// a new index, add it, and add the tribe name as a setting // a new index, add it, and add the tribe name as a setting
clusterStateChanged = true; clusterStateChanged = true;
logger.info("[{}] adding index {}", tribeName, tribeIndex.getIndex()); logger.info("[{}] adding index {}", tribeName, tribeIndex.getIndex());
@ -425,7 +427,7 @@ public class TribeService extends AbstractLifecycleComponent<TribeService> {
logger.info("[{}] dropping index {} due to conflict with [{}]", tribeName, tribeIndex.getIndex(), logger.info("[{}] dropping index {} due to conflict with [{}]", tribeName, tribeIndex.getIndex(),
existingFromTribe); existingFromTribe);
removeIndex(blocks, metaData, routingTable, tribeIndex); removeIndex(blocks, metaData, routingTable, tribeIndex);
droppedIndices.add(tribeIndex.getIndex().getName()); droppedIndices.add(indexName);
} else if (onConflict.startsWith(ON_CONFLICT_PREFER)) { } else if (onConflict.startsWith(ON_CONFLICT_PREFER)) {
// on conflict, prefer a tribe... // on conflict, prefer a tribe...
String preferredTribeName = onConflict.substring(ON_CONFLICT_PREFER.length()); String preferredTribeName = onConflict.substring(ON_CONFLICT_PREFER.length());

View File

@ -191,7 +191,7 @@ public class TransportBulkActionTookTests extends ESTestCase {
} }
@Override @Override
public String[] concreteIndices(ClusterState state, IndicesRequest request) { public String[] concreteIndexNames(ClusterState state, IndicesRequest request) {
return request.indices(); return request.indices();
} }
} }

View File

@ -168,7 +168,7 @@ public class TransportBroadcastByNodeActionTests extends ESTestCase {
} }
@Override @Override
public String[] concreteIndices(ClusterState state, IndicesRequest request) { public String[] concreteIndexNames(ClusterState state, IndicesRequest request) {
return request.indices(); return request.indices();
} }
} }

View File

@ -1065,8 +1065,8 @@ public class TransportReplicationActionTests extends ESTestCase {
ClusterService clusterService, ClusterService clusterService,
ThreadPool threadPool) { ThreadPool threadPool) {
super(settings, actionName, transportService, clusterService, null, threadPool, super(settings, actionName, transportService, clusterService, null, threadPool,
new ShardStateAction(settings, clusterService, transportService, null, null, threadPool), null, new ShardStateAction(settings, clusterService, transportService, null, null, threadPool),
new ActionFilters(new HashSet<ActionFilter>()), new IndexNameExpressionResolver(Settings.EMPTY), Request::new, Request::new, ThreadPool.Names.SAME); new ActionFilters(new HashSet<ActionFilter>()), new IndexNameExpressionResolver(Settings.EMPTY), Request::new, Request::new, ThreadPool.Names.SAME);
} }
@Override @Override

View File

@ -123,7 +123,7 @@ public class TransportInstanceSingleOperationActionTests extends ESTestCase {
} }
@Override @Override
public String[] concreteIndices(ClusterState state, IndicesRequest request) { public String[] concreteIndexNames(ClusterState state, IndicesRequest request) {
return request.indices(); return request.indices();
} }
} }

View File

@ -64,7 +64,7 @@ public class ClusterStateHealthTests extends ESTestCase {
routingTable.add(indexRoutingTable); routingTable.add(indexRoutingTable);
} }
ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable.build()).build(); ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable.build()).build();
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, IndicesOptions.strictExpand(), (String[]) null); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, IndicesOptions.strictExpand(), (String[]) null);
ClusterStateHealth clusterStateHealth = new ClusterStateHealth(clusterState, concreteIndices); ClusterStateHealth clusterStateHealth = new ClusterStateHealth(clusterState, concreteIndices);
logger.info("cluster status: {}, expected {}", clusterStateHealth.getStatus(), counter.status()); logger.info("cluster status: {}, expected {}", clusterStateHealth.getStatus(), counter.status());
clusterStateHealth = maybeSerialize(clusterStateHealth); clusterStateHealth = maybeSerialize(clusterStateHealth);
@ -91,7 +91,7 @@ public class ClusterStateHealthTests extends ESTestCase {
metaData.put(indexMetaData, true); metaData.put(indexMetaData, true);
routingTable.add(indexRoutingTable); routingTable.add(indexRoutingTable);
ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable.build()).build(); ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).routingTable(routingTable.build()).build();
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, IndicesOptions.strictExpand(), (String[]) null); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, IndicesOptions.strictExpand(), (String[]) null);
ClusterStateHealth clusterStateHealth = new ClusterStateHealth(clusterState, concreteIndices); ClusterStateHealth clusterStateHealth = new ClusterStateHealth(clusterState, concreteIndices);
clusterStateHealth = maybeSerialize(clusterStateHealth); clusterStateHealth = maybeSerialize(clusterStateHealth);
// currently we have no cluster level validation failures as index validation issues are reported per index. // currently we have no cluster level validation failures as index validation issues are reported per index.

View File

@ -61,79 +61,79 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
IndicesOptions[] indicesOptions = new IndicesOptions[]{ IndicesOptions.strictExpandOpen(), IndicesOptions.strictExpand()}; IndicesOptions[] indicesOptions = new IndicesOptions[]{ IndicesOptions.strictExpandOpen(), IndicesOptions.strictExpand()};
for (IndicesOptions options : indicesOptions) { for (IndicesOptions options : indicesOptions) {
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options);
String[] results = indexNameExpressionResolver.concreteIndices(context, "foo"); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo");
assertEquals(1, results.length); assertEquals(1, results.length);
assertEquals("foo", results[0]); assertEquals("foo", results[0]);
try { try {
indexNameExpressionResolver.concreteIndices(context, "bar"); indexNameExpressionResolver.concreteIndexNames(context, "bar");
fail(); fail();
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("bar")); assertThat(e.getIndex().getName(), equalTo("bar"));
} }
results = indexNameExpressionResolver.concreteIndices(context, "foofoo", "foobar"); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo", "foobar");
assertEquals(2, results.length); assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foofoo", "foobar")); assertThat(results, arrayContainingInAnyOrder("foofoo", "foobar"));
results = indexNameExpressionResolver.concreteIndices(context, "foofoobar"); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
assertEquals(new HashSet<>(Arrays.asList("foo", "foobar")), assertEquals(new HashSet<>(Arrays.asList("foo", "foobar")),
new HashSet<>(Arrays.asList(results))); new HashSet<>(Arrays.asList(results)));
try { try {
indexNameExpressionResolver.concreteIndices(context, "bar"); indexNameExpressionResolver.concreteIndexNames(context, "bar");
fail(); fail();
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("bar")); assertThat(e.getIndex().getName(), equalTo("bar"));
} }
try { try {
indexNameExpressionResolver.concreteIndices(context, "foo", "bar"); indexNameExpressionResolver.concreteIndexNames(context, "foo", "bar");
fail(); fail();
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("bar")); assertThat(e.getIndex().getName(), equalTo("bar"));
} }
results = indexNameExpressionResolver.concreteIndices(context, "barbaz", "foobar"); results = indexNameExpressionResolver.concreteIndexNames(context, "barbaz", "foobar");
assertEquals(2, results.length); assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foofoo", "foobar")); assertThat(results, arrayContainingInAnyOrder("foofoo", "foobar"));
try { try {
indexNameExpressionResolver.concreteIndices(context, "barbaz", "bar"); indexNameExpressionResolver.concreteIndexNames(context, "barbaz", "bar");
fail(); fail();
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("bar")); assertThat(e.getIndex().getName(), equalTo("bar"));
} }
results = indexNameExpressionResolver.concreteIndices(context, "baz*"); results = indexNameExpressionResolver.concreteIndexNames(context, "baz*");
assertThat(results, emptyArray()); assertThat(results, emptyArray());
results = indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
assertEquals(1, results.length); assertEquals(1, results.length);
assertEquals("foo", results[0]); assertEquals("foo", results[0]);
} }
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen()); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen());
String[] results = indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertEquals(3, results.length); assertEquals(3, results.length);
results = indexNameExpressionResolver.concreteIndices(context, (String[])null); results = indexNameExpressionResolver.concreteIndexNames(context, (String[])null);
assertEquals(3, results.length); assertEquals(3, results.length);
context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpand()); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpand());
results = indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertEquals(4, results.length); assertEquals(4, results.length);
results = indexNameExpressionResolver.concreteIndices(context, (String[])null); results = indexNameExpressionResolver.concreteIndexNames(context, (String[])null);
assertEquals(4, results.length); assertEquals(4, results.length);
context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen()); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen());
results = indexNameExpressionResolver.concreteIndices(context, "foofoo*"); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*");
assertEquals(3, results.length); assertEquals(3, results.length);
assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo")); assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo"));
context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpand()); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpand());
results = indexNameExpressionResolver.concreteIndices(context, "foofoo*"); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*");
assertEquals(4, results.length); assertEquals(4, results.length);
assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo", "foofoo-closed")); assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo", "foofoo-closed"));
} }
@ -150,57 +150,57 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
IndicesOptions[] indicesOptions = new IndicesOptions[]{ IndicesOptions.lenientExpandOpen(), lenientExpand}; IndicesOptions[] indicesOptions = new IndicesOptions[]{ IndicesOptions.lenientExpandOpen(), lenientExpand};
for (IndicesOptions options : indicesOptions) { for (IndicesOptions options : indicesOptions) {
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options);
String[] results = indexNameExpressionResolver.concreteIndices(context, "foo"); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo");
assertEquals(1, results.length); assertEquals(1, results.length);
assertEquals("foo", results[0]); assertEquals("foo", results[0]);
results = indexNameExpressionResolver.concreteIndices(context, "bar"); results = indexNameExpressionResolver.concreteIndexNames(context, "bar");
assertThat(results, emptyArray()); assertThat(results, emptyArray());
results = indexNameExpressionResolver.concreteIndices(context, "foofoo", "foobar"); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo", "foobar");
assertEquals(2, results.length); assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foofoo", "foobar")); assertThat(results, arrayContainingInAnyOrder("foofoo", "foobar"));
results = indexNameExpressionResolver.concreteIndices(context, "foofoobar"); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
assertEquals(2, results.length); assertEquals(2, results.length);
assertEquals(new HashSet<>(Arrays.asList("foo", "foobar")), assertEquals(new HashSet<>(Arrays.asList("foo", "foobar")),
new HashSet<>(Arrays.asList(results))); new HashSet<>(Arrays.asList(results)));
results = indexNameExpressionResolver.concreteIndices(context, "foo", "bar"); results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "bar");
assertEquals(1, results.length); assertEquals(1, results.length);
assertThat(results, arrayContainingInAnyOrder("foo")); assertThat(results, arrayContainingInAnyOrder("foo"));
results = indexNameExpressionResolver.concreteIndices(context, "barbaz", "foobar"); results = indexNameExpressionResolver.concreteIndexNames(context, "barbaz", "foobar");
assertEquals(2, results.length); assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foofoo", "foobar")); assertThat(results, arrayContainingInAnyOrder("foofoo", "foobar"));
results = indexNameExpressionResolver.concreteIndices(context, "barbaz", "bar"); results = indexNameExpressionResolver.concreteIndexNames(context, "barbaz", "bar");
assertEquals(1, results.length); assertEquals(1, results.length);
assertThat(results, arrayContainingInAnyOrder("foofoo")); assertThat(results, arrayContainingInAnyOrder("foofoo"));
results = indexNameExpressionResolver.concreteIndices(context, "baz*"); results = indexNameExpressionResolver.concreteIndexNames(context, "baz*");
assertThat(results, emptyArray()); assertThat(results, emptyArray());
results = indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
assertEquals(1, results.length); assertEquals(1, results.length);
assertEquals("foo", results[0]); assertEquals("foo", results[0]);
} }
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen()); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen());
String[] results = indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertEquals(3, results.length); assertEquals(3, results.length);
context = new IndexNameExpressionResolver.Context(state, lenientExpand); context = new IndexNameExpressionResolver.Context(state, lenientExpand);
results = indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertEquals(Arrays.toString(results), 4, results.length); assertEquals(Arrays.toString(results), 4, results.length);
context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen()); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen());
results = indexNameExpressionResolver.concreteIndices(context, "foofoo*"); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*");
assertEquals(3, results.length); assertEquals(3, results.length);
assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo")); assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo"));
context = new IndexNameExpressionResolver.Context(state, lenientExpand); context = new IndexNameExpressionResolver.Context(state, lenientExpand);
results = indexNameExpressionResolver.concreteIndices(context, "foofoo*"); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*");
assertEquals(4, results.length); assertEquals(4, results.length);
assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo", "foofoo-closed")); assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo", "foofoo-closed"));
} }
@ -219,26 +219,26 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
for (IndicesOptions options : indicesOptions) { for (IndicesOptions options : indicesOptions) {
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options);
String[] results = indexNameExpressionResolver.concreteIndices(context, "foo"); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo");
assertEquals(1, results.length); assertEquals(1, results.length);
assertEquals("foo", results[0]); assertEquals("foo", results[0]);
try { try {
indexNameExpressionResolver.concreteIndices(context, "bar"); indexNameExpressionResolver.concreteIndexNames(context, "bar");
fail(); fail();
} catch(IndexNotFoundException e) { } catch(IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("bar")); assertThat(e.getIndex().getName(), equalTo("bar"));
} }
try { try {
indexNameExpressionResolver.concreteIndices(context, "baz*"); indexNameExpressionResolver.concreteIndexNames(context, "baz*");
fail(); fail();
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("baz*")); assertThat(e.getIndex().getName(), equalTo("baz*"));
} }
try { try {
indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
fail(); fail();
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("baz*")); assertThat(e.getIndex().getName(), equalTo("baz*"));
@ -246,11 +246,11 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
} }
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, expandOpen); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, expandOpen);
String[] results = indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertEquals(3, results.length); assertEquals(3, results.length);
context = new IndexNameExpressionResolver.Context(state, expand); context = new IndexNameExpressionResolver.Context(state, expand);
results = indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertEquals(4, results.length); assertEquals(4, results.length);
} }
@ -264,60 +264,60 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
// Only closed // Only closed
IndicesOptions options = IndicesOptions.fromOptions(false, true, false, true); IndicesOptions options = IndicesOptions.fromOptions(false, true, false, true);
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options);
String[] results = indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertEquals(1, results.length); assertEquals(1, results.length);
assertEquals("foo", results[0]); assertEquals("foo", results[0]);
results = indexNameExpressionResolver.concreteIndices(context, "foo*"); results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
assertEquals(1, results.length); assertEquals(1, results.length);
assertEquals("foo", results[0]); assertEquals("foo", results[0]);
// no wildcards, so wildcard expansion don't apply // no wildcards, so wildcard expansion don't apply
results = indexNameExpressionResolver.concreteIndices(context, "bar"); results = indexNameExpressionResolver.concreteIndexNames(context, "bar");
assertEquals(1, results.length); assertEquals(1, results.length);
assertEquals("bar", results[0]); assertEquals("bar", results[0]);
// Only open // Only open
options = IndicesOptions.fromOptions(false, true, true, false); options = IndicesOptions.fromOptions(false, true, true, false);
context = new IndexNameExpressionResolver.Context(state, options); context = new IndexNameExpressionResolver.Context(state, options);
results = indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertEquals(2, results.length); assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("bar", "foobar")); assertThat(results, arrayContainingInAnyOrder("bar", "foobar"));
results = indexNameExpressionResolver.concreteIndices(context, "foo*"); results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
assertEquals(1, results.length); assertEquals(1, results.length);
assertEquals("foobar", results[0]); assertEquals("foobar", results[0]);
results = indexNameExpressionResolver.concreteIndices(context, "bar"); results = indexNameExpressionResolver.concreteIndexNames(context, "bar");
assertEquals(1, results.length); assertEquals(1, results.length);
assertEquals("bar", results[0]); assertEquals("bar", results[0]);
// Open and closed // Open and closed
options = IndicesOptions.fromOptions(false, true, true, true); options = IndicesOptions.fromOptions(false, true, true, true);
context = new IndexNameExpressionResolver.Context(state, options); context = new IndexNameExpressionResolver.Context(state, options);
results = indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertEquals(3, results.length); assertEquals(3, results.length);
assertThat(results, arrayContainingInAnyOrder("bar", "foobar", "foo")); assertThat(results, arrayContainingInAnyOrder("bar", "foobar", "foo"));
results = indexNameExpressionResolver.concreteIndices(context, "foo*"); results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
assertEquals(2, results.length); assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foobar", "foo")); assertThat(results, arrayContainingInAnyOrder("foobar", "foo"));
results = indexNameExpressionResolver.concreteIndices(context, "bar"); results = indexNameExpressionResolver.concreteIndexNames(context, "bar");
assertEquals(1, results.length); assertEquals(1, results.length);
assertEquals("bar", results[0]); assertEquals("bar", results[0]);
results = indexNameExpressionResolver.concreteIndices(context, "-foo*"); results = indexNameExpressionResolver.concreteIndexNames(context, "-foo*");
assertEquals(1, results.length); assertEquals(1, results.length);
assertEquals("bar", results[0]); assertEquals("bar", results[0]);
results = indexNameExpressionResolver.concreteIndices(context, "-*"); results = indexNameExpressionResolver.concreteIndexNames(context, "-*");
assertEquals(0, results.length); assertEquals(0, results.length);
options = IndicesOptions.fromOptions(false, false, true, true); options = IndicesOptions.fromOptions(false, false, true, true);
context = new IndexNameExpressionResolver.Context(state, options); context = new IndexNameExpressionResolver.Context(state, options);
try { try {
indexNameExpressionResolver.concreteIndices(context, "-*"); indexNameExpressionResolver.concreteIndexNames(context, "-*");
fail(); fail();
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
assertThat(e.getResourceId().toString(), equalTo("[-*]")); assertThat(e.getResourceId().toString(), equalTo("[-*]"));
@ -336,21 +336,21 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
{ {
IndicesOptions noExpandLenient = IndicesOptions.fromOptions(true, true, false, false); IndicesOptions noExpandLenient = IndicesOptions.fromOptions(true, true, false, false);
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandLenient); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandLenient);
String[] results = indexNameExpressionResolver.concreteIndices(context, "baz*"); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*");
assertThat(results, emptyArray()); assertThat(results, emptyArray());
results = indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
assertEquals(1, results.length); assertEquals(1, results.length);
assertEquals("foo", results[0]); assertEquals("foo", results[0]);
results = indexNameExpressionResolver.concreteIndices(context, "foofoobar"); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
assertEquals(2, results.length); assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foo", "foobar")); assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
results = indexNameExpressionResolver.concreteIndices(context, (String[])null); results = indexNameExpressionResolver.concreteIndexNames(context, (String[])null);
assertEquals(0, results.length); assertEquals(0, results.length);
results = indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertEquals(0, results.length); assertEquals(0, results.length);
} }
@ -359,17 +359,17 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
IndicesOptions noExpandDisallowEmpty = IndicesOptions.fromOptions(true, false, false, false); IndicesOptions noExpandDisallowEmpty = IndicesOptions.fromOptions(true, false, false, false);
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandDisallowEmpty); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandDisallowEmpty);
try { try {
indexNameExpressionResolver.concreteIndices(context, "baz*"); indexNameExpressionResolver.concreteIndexNames(context, "baz*");
fail(); fail();
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("baz*")); assertThat(e.getIndex().getName(), equalTo("baz*"));
} }
String[] results = indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
assertEquals(1, results.length); assertEquals(1, results.length);
assertEquals("foo", results[0]); assertEquals("foo", results[0]);
results = indexNameExpressionResolver.concreteIndices(context, "foofoobar"); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
assertEquals(2, results.length); assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foo", "foobar")); assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
} }
@ -378,17 +378,17 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
{ {
IndicesOptions noExpandErrorUnavailable = IndicesOptions.fromOptions(false, true, false, false); IndicesOptions noExpandErrorUnavailable = IndicesOptions.fromOptions(false, true, false, false);
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandErrorUnavailable); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandErrorUnavailable);
String[] results = indexNameExpressionResolver.concreteIndices(context, "baz*"); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*");
assertThat(results, emptyArray()); assertThat(results, emptyArray());
try { try {
indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
fail(); fail();
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("baz*")); assertThat(e.getIndex().getName(), equalTo("baz*"));
} }
results = indexNameExpressionResolver.concreteIndices(context, "foofoobar"); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
assertEquals(2, results.length); assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foo", "foobar")); assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
} }
@ -398,20 +398,20 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
IndicesOptions noExpandStrict = IndicesOptions.fromOptions(false, false, false, false); IndicesOptions noExpandStrict = IndicesOptions.fromOptions(false, false, false, false);
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandStrict); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandStrict);
try { try {
indexNameExpressionResolver.concreteIndices(context, "baz*"); indexNameExpressionResolver.concreteIndexNames(context, "baz*");
fail(); fail();
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("baz*")); assertThat(e.getIndex().getName(), equalTo("baz*"));
} }
try { try {
indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
fail(); fail();
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("baz*")); assertThat(e.getIndex().getName(), equalTo("baz*"));
} }
String[] results = indexNameExpressionResolver.concreteIndices(context, "foofoobar"); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
assertEquals(2, results.length); assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foo", "foobar")); assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
} }
@ -429,7 +429,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
try { try {
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed()); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
indexNameExpressionResolver.concreteIndices(context, "baz*"); indexNameExpressionResolver.concreteIndexNames(context, "baz*");
fail(); fail();
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("baz*")); assertThat(e.getIndex().getName(), equalTo("baz*"));
@ -437,7 +437,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
try { try {
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed()); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
fail(); fail();
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("baz*")); assertThat(e.getIndex().getName(), equalTo("baz*"));
@ -445,7 +445,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
try { try {
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed()); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
indexNameExpressionResolver.concreteIndices(context, "foofoobar"); indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
fail(); fail();
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("Alias [foofoobar] has more than one indices associated with it")); assertThat(e.getMessage(), containsString("Alias [foofoobar] has more than one indices associated with it"));
@ -453,7 +453,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
try { try {
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed()); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
indexNameExpressionResolver.concreteIndices(context, "foo", "foofoobar"); indexNameExpressionResolver.concreteIndexNames(context, "foo", "foofoobar");
fail(); fail();
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("Alias [foofoobar] has more than one indices associated with it")); assertThat(e.getMessage(), containsString("Alias [foofoobar] has more than one indices associated with it"));
@ -461,7 +461,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
try { try {
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed()); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
indexNameExpressionResolver.concreteIndices(context, "foofoo-closed", "foofoobar"); indexNameExpressionResolver.concreteIndexNames(context, "foofoo-closed", "foofoobar");
fail(); fail();
} catch(IndexClosedException e) { } catch(IndexClosedException e) {
assertThat(e.getMessage(), equalTo("closed")); assertThat(e.getMessage(), equalTo("closed"));
@ -469,7 +469,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
} }
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed()); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
String[] results = indexNameExpressionResolver.concreteIndices(context, "foo", "barbaz"); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "barbaz");
assertEquals(2, results.length); assertEquals(2, results.length);
assertThat(results, arrayContainingInAnyOrder("foo", "foofoo")); assertThat(results, arrayContainingInAnyOrder("foo", "foofoo"));
} }
@ -479,18 +479,18 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
IndicesOptions options = IndicesOptions.strictExpandOpen(); IndicesOptions options = IndicesOptions.strictExpandOpen();
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options);
String[] results = indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertThat(results, emptyArray()); assertThat(results, emptyArray());
try { try {
indexNameExpressionResolver.concreteIndices(context, "foo"); indexNameExpressionResolver.concreteIndexNames(context, "foo");
fail(); fail();
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("foo")); assertThat(e.getIndex().getName(), equalTo("foo"));
} }
results = indexNameExpressionResolver.concreteIndices(context, "foo*"); results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
assertThat(results, emptyArray()); assertThat(results, emptyArray());
try { try {
indexNameExpressionResolver.concreteIndices(context, "foo*", "bar"); indexNameExpressionResolver.concreteIndexNames(context, "foo*", "bar");
fail(); fail();
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
assertThat(e.getIndex().getName(), equalTo("bar")); assertThat(e.getIndex().getName(), equalTo("bar"));
@ -498,18 +498,18 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen()); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen());
results = indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
assertThat(results, emptyArray()); assertThat(results, emptyArray());
results = indexNameExpressionResolver.concreteIndices(context, "foo"); results = indexNameExpressionResolver.concreteIndexNames(context, "foo");
assertThat(results, emptyArray()); assertThat(results, emptyArray());
results = indexNameExpressionResolver.concreteIndices(context, "foo*"); results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
assertThat(results, emptyArray()); assertThat(results, emptyArray());
results = indexNameExpressionResolver.concreteIndices(context, "foo*", "bar"); results = indexNameExpressionResolver.concreteIndexNames(context, "foo*", "bar");
assertThat(results, emptyArray()); assertThat(results, emptyArray());
context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, false, true, false)); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, false, true, false));
try { try {
indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
assertThat(e.getResourceId().toString(), equalTo("[_all]")); assertThat(e.getResourceId().toString(), equalTo("[_all]"));
} }
@ -527,7 +527,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen()); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen());
try { try {
indexNameExpressionResolver.concreteIndices(context, "testZZZ"); indexNameExpressionResolver.concreteIndexNames(context, "testZZZ");
fail("Expected IndexNotFoundException"); fail("Expected IndexNotFoundException");
} catch(IndexNotFoundException e) { } catch(IndexNotFoundException e) {
assertThat(e.getMessage(), is("no such index")); assertThat(e.getMessage(), is("no such index"));
@ -541,7 +541,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build(); ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen()); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen());
assertThat(newHashSet(indexNameExpressionResolver.concreteIndices(context, "testXXX", "testZZZ")), equalTo(newHashSet("testXXX"))); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testXXX", "testZZZ")), equalTo(newHashSet("testXXX")));
} }
public void testConcreteIndicesIgnoreIndicesAllMissing() { public void testConcreteIndicesIgnoreIndicesAllMissing() {
@ -552,7 +552,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen()); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen());
try { try {
indexNameExpressionResolver.concreteIndices(context, "testMo", "testMahdy"); indexNameExpressionResolver.concreteIndexNames(context, "testMo", "testMahdy");
fail("Expected IndexNotFoundException"); fail("Expected IndexNotFoundException");
} catch(IndexNotFoundException e) { } catch(IndexNotFoundException e) {
assertThat(e.getMessage(), is("no such index")); assertThat(e.getMessage(), is("no such index"));
@ -565,7 +565,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
.put(indexBuilder("kuku")); .put(indexBuilder("kuku"));
ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build(); ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen()); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen());
assertThat(newHashSet(indexNameExpressionResolver.concreteIndices(context, new String[]{})), equalTo(newHashSet("kuku", "testXXX"))); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, new String[]{})), equalTo(newHashSet("kuku", "testXXX")));
} }
public void testConcreteIndicesWildcardExpansion() { public void testConcreteIndicesWildcardExpansion() {
@ -578,13 +578,13 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build(); ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, false)); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, false));
assertThat(newHashSet(indexNameExpressionResolver.concreteIndices(context, "testX*")), equalTo(new HashSet<String>())); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testX*")), equalTo(new HashSet<String>()));
context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, false)); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, false));
assertThat(newHashSet(indexNameExpressionResolver.concreteIndices(context, "testX*")), equalTo(newHashSet("testXXX", "testXXY"))); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testX*")), equalTo(newHashSet("testXXX", "testXXY")));
context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, true)); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, true));
assertThat(newHashSet(indexNameExpressionResolver.concreteIndices(context, "testX*")), equalTo(newHashSet("testXYY"))); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testX*")), equalTo(newHashSet("testXYY")));
context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, true)); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, true));
assertThat(newHashSet(indexNameExpressionResolver.concreteIndices(context, "testX*")), equalTo(newHashSet("testXXX", "testXXY", "testXYY"))); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testX*")), equalTo(newHashSet("testXXX", "testXXY", "testXYY")));
} }
/** /**
@ -610,7 +610,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
// with no indices, asking for all indices should return empty list or exception, depending on indices options // with no indices, asking for all indices should return empty list or exception, depending on indices options
if (indicesOptions.allowNoIndices()) { if (indicesOptions.allowNoIndices()) {
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(context, allIndices); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(context, allIndices);
assertThat(concreteIndices, notNullValue()); assertThat(concreteIndices, notNullValue());
assertThat(concreteIndices.length, equalTo(0)); assertThat(concreteIndices.length, equalTo(0));
} else { } else {
@ -625,7 +625,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build(); state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
context = new IndexNameExpressionResolver.Context(state, indicesOptions); context = new IndexNameExpressionResolver.Context(state, indicesOptions);
if (indicesOptions.expandWildcardsOpen() || indicesOptions.expandWildcardsClosed() || indicesOptions.allowNoIndices()) { if (indicesOptions.expandWildcardsOpen() || indicesOptions.expandWildcardsClosed() || indicesOptions.allowNoIndices()) {
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(context, allIndices); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(context, allIndices);
assertThat(concreteIndices, notNullValue()); assertThat(concreteIndices, notNullValue());
int expectedNumberOfIndices = 0; int expectedNumberOfIndices = 0;
if (indicesOptions.expandWildcardsOpen()) { if (indicesOptions.expandWildcardsOpen()) {
@ -646,7 +646,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
*/ */
private void checkCorrectException(IndexNameExpressionResolver indexNameExpressionResolver, IndexNameExpressionResolver.Context context, String[] allIndices) { private void checkCorrectException(IndexNameExpressionResolver indexNameExpressionResolver, IndexNameExpressionResolver.Context context, String[] allIndices) {
try { try {
indexNameExpressionResolver.concreteIndices(context, allIndices); indexNameExpressionResolver.concreteIndexNames(context, allIndices);
fail("wildcard expansion on should trigger IndexMissingException"); fail("wildcard expansion on should trigger IndexMissingException");
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
// expected // expected
@ -668,12 +668,12 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
// asking for non existing wildcard pattern should return empty list or exception // asking for non existing wildcard pattern should return empty list or exception
if (indicesOptions.allowNoIndices()) { if (indicesOptions.allowNoIndices()) {
String[] concreteIndices = indexNameExpressionResolver.concreteIndices(context, "Foo*"); String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(context, "Foo*");
assertThat(concreteIndices, notNullValue()); assertThat(concreteIndices, notNullValue());
assertThat(concreteIndices.length, equalTo(0)); assertThat(concreteIndices.length, equalTo(0));
} else { } else {
try { try {
indexNameExpressionResolver.concreteIndices(context, "Foo*"); indexNameExpressionResolver.concreteIndexNames(context, "Foo*");
fail("expecting exception when result empty and allowNoIndicec=false"); fail("expecting exception when result empty and allowNoIndicec=false");
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
// expected exception // expected exception
@ -798,51 +798,51 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpenAndForbidClosed()); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpenAndForbidClosed());
try { try {
indexNameExpressionResolver.concreteIndices(context, "foo1-closed"); indexNameExpressionResolver.concreteIndexNames(context, "foo1-closed");
fail("foo1-closed should be closed, but it is open"); fail("foo1-closed should be closed, but it is open");
} catch (IndexClosedException e) { } catch (IndexClosedException e) {
// expected // expected
} }
try { try {
indexNameExpressionResolver.concreteIndices(context, "foobar1-closed"); indexNameExpressionResolver.concreteIndexNames(context, "foobar1-closed");
fail("foo1-closed should be closed, but it is open"); fail("foo1-closed should be closed, but it is open");
} catch (IndexClosedException e) { } catch (IndexClosedException e) {
// expected // expected
} }
context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, context.getOptions().allowNoIndices(), context.getOptions().expandWildcardsOpen(), context.getOptions().expandWildcardsClosed(), context.getOptions())); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, context.getOptions().allowNoIndices(), context.getOptions().expandWildcardsOpen(), context.getOptions().expandWildcardsClosed(), context.getOptions()));
String[] results = indexNameExpressionResolver.concreteIndices(context, "foo1-closed"); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo1-closed");
assertThat(results, emptyArray()); assertThat(results, emptyArray());
results = indexNameExpressionResolver.concreteIndices(context, "foobar1-closed"); results = indexNameExpressionResolver.concreteIndexNames(context, "foobar1-closed");
assertThat(results, emptyArray()); assertThat(results, emptyArray());
context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen()); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen());
results = indexNameExpressionResolver.concreteIndices(context, "foo1-closed"); results = indexNameExpressionResolver.concreteIndexNames(context, "foo1-closed");
assertThat(results, arrayWithSize(1)); assertThat(results, arrayWithSize(1));
assertThat(results, arrayContaining("foo1-closed")); assertThat(results, arrayContaining("foo1-closed"));
results = indexNameExpressionResolver.concreteIndices(context, "foobar1-closed"); results = indexNameExpressionResolver.concreteIndexNames(context, "foobar1-closed");
assertThat(results, arrayWithSize(1)); assertThat(results, arrayWithSize(1));
assertThat(results, arrayContaining("foo1-closed")); assertThat(results, arrayContaining("foo1-closed"));
// testing an alias pointing to three indices: // testing an alias pointing to three indices:
context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpenAndForbidClosed()); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpenAndForbidClosed());
try { try {
indexNameExpressionResolver.concreteIndices(context, "foobar2-closed"); indexNameExpressionResolver.concreteIndexNames(context, "foobar2-closed");
fail("foo2-closed should be closed, but it is open"); fail("foo2-closed should be closed, but it is open");
} catch (IndexClosedException e) { } catch (IndexClosedException e) {
// expected // expected
} }
context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, context.getOptions().allowNoIndices(), context.getOptions().expandWildcardsOpen(), context.getOptions().expandWildcardsClosed(), context.getOptions())); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, context.getOptions().allowNoIndices(), context.getOptions().expandWildcardsOpen(), context.getOptions().expandWildcardsClosed(), context.getOptions()));
results = indexNameExpressionResolver.concreteIndices(context, "foobar2-closed"); results = indexNameExpressionResolver.concreteIndexNames(context, "foobar2-closed");
assertThat(results, arrayWithSize(1)); assertThat(results, arrayWithSize(1));
assertThat(results, arrayContaining("foo3")); assertThat(results, arrayContaining("foo3"));
context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen()); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen());
results = indexNameExpressionResolver.concreteIndices(context, "foobar2-closed"); results = indexNameExpressionResolver.concreteIndexNames(context, "foobar2-closed");
assertThat(results, arrayWithSize(3)); assertThat(results, arrayWithSize(3));
assertThat(results, arrayContainingInAnyOrder("foo1-closed", "foo2-closed", "foo3")); assertThat(results, arrayContainingInAnyOrder("foo1-closed", "foo2-closed", "foo3"));
} }
@ -855,7 +855,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
IndicesOptions.lenientExpandOpen(), IndicesOptions.strictExpandOpenAndForbidClosed()}; IndicesOptions.lenientExpandOpen(), IndicesOptions.strictExpandOpenAndForbidClosed()};
for (IndicesOptions options : indicesOptions) { for (IndicesOptions options : indicesOptions) {
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options);
String[] results = indexNameExpressionResolver.concreteIndices(context, "index1", "index1", "alias1"); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "index1", "index1", "alias1");
assertThat(results, equalTo(new String[]{"index1"})); assertThat(results, equalTo(new String[]{"index1"}));
} }
} }
@ -875,11 +875,11 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build(); ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen()); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen());
String[] strings = indexNameExpressionResolver.concreteIndices(context, "alias-*"); String[] strings = indexNameExpressionResolver.concreteIndexNames(context, "alias-*");
assertArrayEquals(new String[] {"test-0"}, strings); assertArrayEquals(new String[] {"test-0"}, strings);
context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen()); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen());
strings = indexNameExpressionResolver.concreteIndices(context, "alias-*"); strings = indexNameExpressionResolver.concreteIndexNames(context, "alias-*");
assertArrayEquals(new String[] {"test-0"}, strings); assertArrayEquals(new String[] {"test-0"}, strings);
} }

View File

@ -28,6 +28,7 @@ import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.cluster.routing.allocation.AllocationService;
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
import org.elasticsearch.index.Index;
import org.elasticsearch.test.ESAllocationTestCase; import org.elasticsearch.test.ESAllocationTestCase;
import java.util.HashMap; import java.util.HashMap;
@ -172,12 +173,12 @@ public class GatewayMetaStateTests extends ESAllocationTestCase {
boolean stateInMemory, boolean stateInMemory,
boolean expectMetaData) throws Exception { boolean expectMetaData) throws Exception {
MetaData inMemoryMetaData = null; MetaData inMemoryMetaData = null;
Set<String> oldIndicesList = emptySet(); Set<Index> oldIndicesList = emptySet();
if (stateInMemory) { if (stateInMemory) {
inMemoryMetaData = event.previousState().metaData(); inMemoryMetaData = event.previousState().metaData();
oldIndicesList = GatewayMetaState.getRelevantIndices(event.previousState(), event.previousState(), oldIndicesList); oldIndicesList = GatewayMetaState.getRelevantIndices(event.previousState(), event.previousState(), oldIndicesList);
} }
Set<String> newIndicesList = GatewayMetaState.getRelevantIndices(event.state(),event.previousState(), oldIndicesList); Set<Index> newIndicesList = GatewayMetaState.getRelevantIndices(event.state(),event.previousState(), oldIndicesList);
// third, get the actual write info // third, get the actual write info
Iterator<GatewayMetaState.IndexMetaWriteInfo> indices = GatewayMetaState.resolveStatesToBeWritten(oldIndicesList, newIndicesList, inMemoryMetaData, event.state().metaData()).iterator(); Iterator<GatewayMetaState.IndexMetaWriteInfo> indices = GatewayMetaState.resolveStatesToBeWritten(oldIndicesList, newIndicesList, inMemoryMetaData, event.state().metaData()).iterator();

View File

@ -25,6 +25,7 @@ import org.elasticsearch.cluster.routing.ShardRoutingState;
import org.elasticsearch.cluster.routing.TestShardRouting; import org.elasticsearch.cluster.routing.TestShardRouting;
import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.cluster.routing.UnassignedInfo;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import java.util.Arrays; import java.util.Arrays;
@ -37,7 +38,7 @@ import java.util.Map;
public class PriorityComparatorTests extends ESTestCase { public class PriorityComparatorTests extends ESTestCase {
public void testPreferNewIndices() { public void testPreferNewIndices() {
RoutingNodes.UnassignedShards shards = new RoutingNodes.UnassignedShards((RoutingNodes) null); RoutingNodes.UnassignedShards shards = new RoutingNodes.UnassignedShards(null);
List<ShardRouting> shardRoutings = Arrays.asList(TestShardRouting.newShardRouting("oldest", 0, null, null, null, List<ShardRouting> shardRoutings = Arrays.asList(TestShardRouting.newShardRouting("oldest", 0, null, null, null,
randomBoolean(), ShardRoutingState.UNASSIGNED, new UnassignedInfo(randomFrom(UnassignedInfo.Reason.values()), "foobar")), TestShardRouting.newShardRouting("newest", 0, null, null, null, randomBoolean(), ShardRoutingState.UNASSIGNED, new UnassignedInfo(randomFrom(UnassignedInfo.Reason.values()), "foobar")), TestShardRouting.newShardRouting("newest", 0, null, null, null,
randomBoolean(), ShardRoutingState.UNASSIGNED, new UnassignedInfo(randomFrom(UnassignedInfo.Reason.values()), "foobar"))); randomBoolean(), ShardRoutingState.UNASSIGNED, new UnassignedInfo(randomFrom(UnassignedInfo.Reason.values()), "foobar")));
@ -47,11 +48,11 @@ public class PriorityComparatorTests extends ESTestCase {
} }
shards.sort(new PriorityComparator() { shards.sort(new PriorityComparator() {
@Override @Override
protected Settings getIndexSettings(String index) { protected Settings getIndexSettings(Index index) {
if ("oldest".equals(index)) { if ("oldest".equals(index.getName())) {
return Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 10) return Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 10)
.put(IndexMetaData.SETTING_PRIORITY, 1).build(); .put(IndexMetaData.SETTING_PRIORITY, 1).build();
} else if ("newest".equals(index)) { } else if ("newest".equals(index.getName())) {
return Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 100) return Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 100)
.put(IndexMetaData.SETTING_PRIORITY, 1).build(); .put(IndexMetaData.SETTING_PRIORITY, 1).build();
} }
@ -77,11 +78,11 @@ public class PriorityComparatorTests extends ESTestCase {
} }
shards.sort(new PriorityComparator() { shards.sort(new PriorityComparator() {
@Override @Override
protected Settings getIndexSettings(String index) { protected Settings getIndexSettings(Index index) {
if ("oldest".equals(index)) { if ("oldest".equals(index.getName())) {
return Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 10) return Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 10)
.put(IndexMetaData.SETTING_PRIORITY, 100).build(); .put(IndexMetaData.SETTING_PRIORITY, 100).build();
} else if ("newest".equals(index)) { } else if ("newest".equals(index.getName())) {
return Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 100) return Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 100)
.put(IndexMetaData.SETTING_PRIORITY, 1).build(); .put(IndexMetaData.SETTING_PRIORITY, 1).build();
} }
@ -118,8 +119,8 @@ public class PriorityComparatorTests extends ESTestCase {
} }
shards.sort(new PriorityComparator() { shards.sort(new PriorityComparator() {
@Override @Override
protected Settings getIndexSettings(String index) { protected Settings getIndexSettings(Index index) {
IndexMeta indexMeta = map.get(index); IndexMeta indexMeta = map.get(index.getName());
return indexMeta.settings; return indexMeta.settings;
} }
}); });

View File

@ -182,7 +182,7 @@ public class TimestampMappingTests extends ESSingleNodeTestCase {
IndexRequest request = new IndexRequest("test", "type", "1").source(doc); IndexRequest request = new IndexRequest("test", "type", "1").source(doc);
request.process(metaData, mappingMetaData, true, "test"); request.process(metaData, mappingMetaData, true, "test");
assertThat(request.timestamp(), notNullValue()); assertThat(request.timestamp(), notNullValue());
assertThat(request.timestamp(), is(MappingMetaData.Timestamp.parseStringTimestamp("1970-01-01", Joda.forPattern("YYYY-MM-dd"), Version.CURRENT))); assertThat(request.timestamp(), is(MappingMetaData.Timestamp.parseStringTimestamp("1970-01-01", Joda.forPattern("YYYY-MM-dd"))));
} }
// Issue 4718: was throwing a TimestampParsingException: failed to parse timestamp [null] // Issue 4718: was throwing a TimestampParsingException: failed to parse timestamp [null]

View File

@ -65,6 +65,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitC
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;
public class IndicesOptionsIntegrationIT extends ESIntegTestCase { public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
@ -685,7 +686,7 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
try { try {
verify(client().admin().indices().prepareUpdateSettings("barbaz").setSettings(Settings.builder().put("e", "f")), false); verify(client().admin().indices().prepareUpdateSettings("barbaz").setSettings(Settings.builder().put("e", "f")), false);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
assertThat(e.getMessage(), equalTo("Can't update non dynamic settings[[index.e]] for open indices [[barbaz]]")); assertThat(e.getMessage(), startsWith("Can't update non dynamic settings [[index.e]] for open indices [[barbaz"));
} }
verify(client().admin().indices().prepareUpdateSettings("baz*").setSettings(Settings.builder().put("a", "b")), true); verify(client().admin().indices().prepareUpdateSettings("baz*").setSettings(Settings.builder().put("a", "b")), true);
} }

View File

@ -137,7 +137,8 @@ public class UpdateSettingsIT extends ESIntegTestCase {
.execute().actionGet(); .execute().actionGet();
fail("can't change number of replicas on a closed index"); fail("can't change number of replicas on a closed index");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
assertEquals(ex.getMessage(), "Can't update [index.number_of_replicas] on closed indices [[test]] - can leave index in an unopenable state"); assertTrue(ex.getMessage(), ex.getMessage().startsWith("Can't update [index.number_of_replicas] on closed indices [[test/"));
assertTrue(ex.getMessage(), ex.getMessage().endsWith("]] - can leave index in an unopenable state"));
// expected // expected
} }
client().admin().indices().prepareUpdateSettings("test") client().admin().indices().prepareUpdateSettings("test")

View File

@ -1880,7 +1880,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
client.admin().indices().prepareDelete("test-idx-1").get(); client.admin().indices().prepareDelete("test-idx-1").get();
fail("Expected deleting index to fail during snapshot"); fail("Expected deleting index to fail during snapshot");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("Cannot delete indices that are being snapshotted: [test-idx-1]")); assertThat(e.getMessage(), containsString("Cannot delete indices that are being snapshotted: [[test-idx-1/"));
} }
} else { } else {
try { try {
@ -1888,7 +1888,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
client.admin().indices().prepareClose("test-idx-1").get(); client.admin().indices().prepareClose("test-idx-1").get();
fail("Expected closing index to fail during snapshot"); fail("Expected closing index to fail during snapshot");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("Cannot close indices that are being snapshotted: [test-idx-1]")); assertThat(e.getMessage(), containsString("Cannot close indices that are being snapshotted: [[test-idx-1/"));
} }
} }
} }
@ -1964,9 +1964,10 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
client.admin().indices().prepareClose("test-idx-1").get(); client.admin().indices().prepareClose("test-idx-1").get();
fail("Expected closing index to fail during restore"); fail("Expected closing index to fail during restore");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("Cannot close indices that are being restored: [test-idx-1]")); assertThat(e.getMessage(), containsString("Cannot close indices that are being restored: [[test-idx-1/"));
} }
} finally { } finally {
// unblock even if the try block fails otherwise we will get bogus failures when we delete all indices in test teardown.
logger.info("--> unblocking all data nodes"); logger.info("--> unblocking all data nodes");
unblockAllDataNodes("test-repo"); unblockAllDataNodes("test-repo");
} }

View File

@ -370,7 +370,7 @@ public class IndicesRequestTests extends ESIntegTestCase {
internalCluster().clientNodeClient().admin().indices().flush(flushRequest).actionGet(); internalCluster().clientNodeClient().admin().indices().flush(flushRequest).actionGet();
clearInterceptedActions(); clearInterceptedActions();
String[] indices = new IndexNameExpressionResolver(Settings.EMPTY).concreteIndices(client().admin().cluster().prepareState().get().getState(), flushRequest); String[] indices = new IndexNameExpressionResolver(Settings.EMPTY).concreteIndexNames(client().admin().cluster().prepareState().get().getState(), flushRequest);
assertIndicesSubset(Arrays.asList(indices), indexShardActions); assertIndicesSubset(Arrays.asList(indices), indexShardActions);
} }
@ -393,7 +393,7 @@ public class IndicesRequestTests extends ESIntegTestCase {
internalCluster().clientNodeClient().admin().indices().refresh(refreshRequest).actionGet(); internalCluster().clientNodeClient().admin().indices().refresh(refreshRequest).actionGet();
clearInterceptedActions(); clearInterceptedActions();
String[] indices = new IndexNameExpressionResolver(Settings.EMPTY).concreteIndices(client().admin().cluster().prepareState().get().getState(), refreshRequest); String[] indices = new IndexNameExpressionResolver(Settings.EMPTY).concreteIndexNames(client().admin().cluster().prepareState().get().getState(), refreshRequest);
assertIndicesSubset(Arrays.asList(indices), indexShardActions); assertIndicesSubset(Arrays.asList(indices), indexShardActions);
} }

Some files were not shown because too many files have changed in this diff Show More