From c90b4f3bae4a87c8618b91db087cd85ec2e1eab9 Mon Sep 17 00:00:00 2001 From: Clinton Gormley Date: Mon, 14 Mar 2016 09:58:46 +0100 Subject: [PATCH 1/7] Docs: Added note about upgrading from 1.x to 5.x --- docs/reference/migration/index.asciidoc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/reference/migration/index.asciidoc b/docs/reference/migration/index.asciidoc index f8d742b3b67..0dda43da713 100644 --- a/docs/reference/migration/index.asciidoc +++ b/docs/reference/migration/index.asciidoc @@ -8,11 +8,14 @@ your application from one version of Elasticsearch to another. As a general rule: -* Migration between major versions -- e.g. `1.x` to `2.x` -- +* Migration between minor versions -- e.g. `5.x` to `5.y` -- can be + performed by <>. + +* Migration between consecutive major versions -- e.g. `2.x` to `5.x` -- requires a <>. -* Migration between minor versions -- e.g. `1.x` to `1.y` -- can be - performed by <>. +* Migration between non-consecutive major versions -- e.g. `1.x` to `5.x` -- + is not supported. See <> for more info. -- From c3cd8564df0ff836d996a618397a00a8a583abca Mon Sep 17 00:00:00 2001 From: Clinton Gormley Date: Mon, 14 Mar 2016 10:46:31 +0100 Subject: [PATCH 2/7] Corrected regexp syntax docs for COMPLEMENT --- docs/reference/query-dsl/regexp-syntax.asciidoc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/reference/query-dsl/regexp-syntax.asciidoc b/docs/reference/query-dsl/regexp-syntax.asciidoc index e57d0e1c779..68ca5912458 100644 --- a/docs/reference/query-dsl/regexp-syntax.asciidoc +++ b/docs/reference/query-dsl/regexp-syntax.asciidoc @@ -220,12 +220,20 @@ Complement:: -- The complement is probably the most useful option. The shortest pattern that -follows a tilde `"~"` is negated. For the string `"abcdef"`: +follows a tilde `"~"` is negated. For instance, `"ab~cd" means: + +* Starts with `a` +* Followed by `b` +* Followed by a string of any length that it anything but `c` +* Ends with `d` + +For the string `"abcdef"`: ab~df # match - ab~cf # no match - a~(cd)f # match - a~(bc)f # no match + ab~cf # match + ab~cdef # no match + a~(cb)def # match + a~(bc)def # no match Enabled with the `COMPLEMENT` or `ALL` flags. From 31740e279f812f27d7f064e14a361a1213b3cb0f Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 8 Mar 2016 12:50:41 +0100 Subject: [PATCH 3/7] 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 tuple. Closes #17048 --- .../health/TransportClusterHealthAction.java | 4 +- .../admin/cluster/node/stats/NodeStats.java | 2 +- .../shards/ClusterSearchShardsGroup.java | 2 +- .../TransportClusterSearchShardsAction.java | 4 +- .../create/TransportCreateSnapshotAction.java | 2 +- .../state/TransportClusterStateAction.java | 2 +- .../alias/TransportIndicesAliasesAction.java | 4 +- .../exists/TransportAliasesExistAction.java | 4 +- .../alias/get/TransportGetAliasesAction.java | 4 +- .../close/TransportCloseIndexAction.java | 5 +- .../delete/TransportDeleteIndexAction.java | 11 +- .../indices/TransportIndicesExistsAction.java | 4 +- .../types/TransportTypesExistsAction.java | 4 +- .../flush/TransportShardFlushAction.java | 7 +- .../indices/get/TransportGetIndexAction.java | 2 +- .../get/TransportGetFieldMappingsAction.java | 2 +- .../get/TransportGetMappingsAction.java | 2 +- .../mapping/put/PutMappingRequest.java | 24 +++ .../mapping/put/PutMappingRequestBuilder.java | 6 + .../put/TransportPutMappingAction.java | 11 +- .../open/TransportOpenIndexAction.java | 5 +- .../refresh/TransportShardRefreshAction.java | 7 +- .../get/TransportGetSettingsAction.java | 9 +- .../put/TransportUpdateSettingsAction.java | 5 +- .../TransportIndicesShardStoresAction.java | 4 +- .../action/bulk/TransportBulkAction.java | 47 ++-- .../action/bulk/TransportShardBulkAction.java | 7 +- .../action/delete/TransportDeleteAction.java | 4 +- .../action/get/TransportMultiGetAction.java | 2 +- .../action/index/IndexRequest.java | 14 +- .../action/index/TransportIndexAction.java | 11 +- .../TransportMultiPercolateAction.java | 2 +- .../search/AbstractSearchAsyncAction.java | 2 +- .../action/search/TransportSearchAction.java | 2 +- .../broadcast/TransportBroadcastAction.java | 2 +- .../node/TransportBroadcastByNodeAction.java | 3 +- .../info/TransportClusterInfoAction.java | 2 +- .../TransportBroadcastReplicationAction.java | 4 +- .../TransportReplicationAction.java | 6 +- ...ransportInstanceSingleOperationAction.java | 2 +- .../shard/TransportSingleShardAction.java | 2 +- .../TransportMultiTermVectorsAction.java | 2 +- .../cluster/ClusterChangedEvent.java | 4 +- .../ack/IndicesClusterStateUpdateRequest.java | 8 +- .../action/index/MappingUpdatedAction.java | 53 +---- .../action/index/NodeIndexDeletedAction.java | 24 +-- .../metadata/IndexNameExpressionResolver.java | 63 ++++-- .../cluster/metadata/MappingMetaData.java | 14 +- .../cluster/metadata/MetaData.java | 51 +++-- .../metadata/MetaDataDeleteIndexService.java | 36 ++-- .../metadata/MetaDataIndexStateService.java | 47 ++-- .../metadata/MetaDataMappingService.java | 72 +++---- .../MetaDataUpdateSettingsService.java | 62 +++--- .../cluster/routing/IndexRoutingTable.java | 2 +- .../routing/IndexShardRoutingTable.java | 2 +- .../cluster/routing/ShardRouting.java | 2 +- .../routing/allocation/AllocationService.java | 4 +- .../allocator/BalancedShardsAllocator.java | 2 +- ...AllocateStalePrimaryAllocationCommand.java | 2 +- .../decider/AwarenessAllocationDecider.java | 2 +- .../decider/DiskThresholdDecider.java | 2 +- .../decider/EnableAllocationDecider.java | 4 +- .../decider/FilterAllocationDecider.java | 2 +- .../decider/ShardsLimitAllocationDecider.java | 4 +- .../common/io/stream/StreamInput.java | 4 +- .../common/io/stream/Writeable.java | 11 + .../gateway/AsyncShardFetch.java | 2 +- .../org/elasticsearch/gateway/Gateway.java | 7 +- .../gateway/GatewayMetaState.java | 40 ++-- .../gateway/PrimaryShardAllocator.java | 2 +- .../gateway/PriorityComparator.java | 11 +- .../gateway/ReplicaShardAllocator.java | 4 +- ...ransportNodesListGatewayStartedShards.java | 2 +- .../java/org/elasticsearch/index/Index.java | 14 +- .../elasticsearch/index/shard/ShardId.java | 2 +- .../indices/NodeIndicesStats.java | 2 +- .../cluster/IndicesClusterStateService.java | 23 +- .../indices/flush/SyncedFlushService.java | 16 +- .../indices/store/IndicesStore.java | 11 +- .../TransportNodesListShardStoreMetaData.java | 4 +- .../indices/ttl/IndicesTTLService.java | 2 +- .../rest/action/cat/RestIndicesAction.java | 4 +- .../rest/action/cat/RestShardsAction.java | 2 +- .../elasticsearch/search/SearchService.java | 2 +- .../snapshots/RestoreService.java | 9 +- .../snapshots/SnapshotsService.java | 27 +-- .../org/elasticsearch/tribe/TribeService.java | 8 +- .../bulk/TransportBulkActionTookTests.java | 2 +- .../TransportBroadcastByNodeActionTests.java | 2 +- .../TransportReplicationActionTests.java | 4 +- ...ortInstanceSingleOperationActionTests.java | 2 +- .../health/ClusterStateHealthTests.java | 4 +- .../IndexNameExpressionResolverTests.java | 202 +++++++++--------- .../gateway/GatewayMetaStateTests.java | 5 +- .../gateway/PriorityComparatorTests.java | 19 +- .../timestamp/TimestampMappingTests.java | 2 +- .../indices/IndicesOptionsIntegrationIT.java | 3 +- .../indices/settings/UpdateSettingsIT.java | 3 +- .../SharedClusterSnapshotRestoreIT.java | 7 +- .../messy/tests/IndicesRequestTests.java | 4 +- .../index/reindex/TransportReindexAction.java | 4 +- 101 files changed, 629 insertions(+), 555 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java index b5c9577aff7..39d6a8daeb0 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthAction.java @@ -213,7 +213,7 @@ public class TransportClusterHealthAction extends TransportMasterNodeReadAction< } if (request.indices() != null && request.indices().length > 0) { try { - indexNameExpressionResolver.concreteIndices(clusterState, IndicesOptions.strictExpand(), request.indices()); + indexNameExpressionResolver.concreteIndexNames(clusterState, IndicesOptions.strictExpand(), request.indices()); waitForCounter++; } catch (IndexNotFoundException e) { response.setStatus(ClusterHealthStatus.RED); // no indices, make sure its RED @@ -280,7 +280,7 @@ public class TransportClusterHealthAction extends TransportMasterNodeReadAction< String[] concreteIndices; try { - concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request); + concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request); } catch (IndexNotFoundException e) { // one of the specified indices is not there - treat it as RED. ClusterHealthResponse response = new ClusterHealthResponse(clusterName.value(), Strings.EMPTY_ARRAY, clusterState, diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStats.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStats.java index c1d4bb78ba3..db017fd3f6a 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStats.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStats.java @@ -235,7 +235,7 @@ public class NodeStats extends BaseNodeResponse implements ToXContent { breaker = AllCircuitBreakerStats.readOptionalAllCircuitBreakerStats(in); scriptStats = in.readOptionalStreamable(ScriptStats::new); discoveryStats = in.readOptionalStreamable(() -> new DiscoveryStats(null)); - ingestStats = in.readOptionalWritable(IngestStats.PROTO); + ingestStats = in.readOptionalWritable(IngestStats.PROTO::readFrom); } @Override diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsGroup.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsGroup.java index 9f3ccac8f64..1b329d17289 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsGroup.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsGroup.java @@ -67,7 +67,7 @@ public class ClusterSearchShardsGroup implements Streamable, ToXContent { @Override public void readFrom(StreamInput in) throws IOException { - index = Index.readIndex(in); + index = new Index(in); shardId = in.readVInt(); shards = new ShardRouting[in.readVInt()]; for (int i = 0; i < shards.length; i++) { diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java index e6a9d98eb17..f8868e94bf0 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java @@ -59,7 +59,7 @@ public class TransportClusterSearchShardsAction extends TransportMasterNodeReadA @Override 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 @@ -70,7 +70,7 @@ public class TransportClusterSearchShardsAction extends TransportMasterNodeReadA @Override protected void masterOperation(final ClusterSearchShardsRequest request, final ClusterState state, final ActionListener listener) { ClusterState clusterState = clusterService.state(); - String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request); + String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request); Map> routingMap = indexNameExpressionResolver.resolveSearchRouting(state, request.routing(), request.indices()); Set nodeIds = new HashSet<>(); GroupShardsIterator groupShardsIterator = clusterService.operationRouting().searchShards(clusterState, concreteIndices, routingMap, request.preference()); diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/TransportCreateSnapshotAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/TransportCreateSnapshotAction.java index 457b6e69383..3bee1a74e1d 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/TransportCreateSnapshotAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/TransportCreateSnapshotAction.java @@ -66,7 +66,7 @@ public class TransportCreateSnapshotAction extends TransportMasterNodeAction 0) { - String[] indices = indexNameExpressionResolver.concreteIndices(currentState, request); + String[] indices = indexNameExpressionResolver.concreteIndexNames(currentState, request); for (String filteredIndex : indices) { IndexMetaData indexMetaData = currentState.metaData().index(filteredIndex); if (indexMetaData != null) { diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java index d37053e056b..7cb7b225895 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java @@ -90,11 +90,11 @@ public class TransportIndicesAliasesAction extends TransportMasterNodeAction aliases = new HashSet<>(); for (AliasActions action : actions) { //expand indices - String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request.indicesOptions(), action.indices()); + String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request.indicesOptions(), action.indices()); //collect the aliases Collections.addAll(aliases, action.aliases()); 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()); finalAction.index(index); finalAction.alias(alias); diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/alias/exists/TransportAliasesExistAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/alias/exists/TransportAliasesExistAction.java index 5f92587f138..ed14c51d442 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/alias/exists/TransportAliasesExistAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/alias/exists/TransportAliasesExistAction.java @@ -50,7 +50,7 @@ public class TransportAliasesExistAction extends TransportMasterNodeReadAction listener) { - String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); + String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request); boolean result = state.metaData().hasAliases(request.aliases(), concreteIndices); listener.onResponse(new AliasesExistResponse(result)); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java index 9c2c2f03b57..ae9916810d3 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java @@ -53,7 +53,7 @@ public class TransportGetAliasesAction extends TransportMasterNodeReadAction listener) { - String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); + String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request); @SuppressWarnings("unchecked") ImmutableOpenMap> result = (ImmutableOpenMap) state.metaData().findAliases(request.aliases(), concreteIndices); listener.onResponse(new GetAliasesResponse(result)); diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/close/TransportCloseIndexAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/close/TransportCloseIndexAction.java index 5c88a8be3d3..7f77424e84c 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/close/TransportCloseIndexAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/close/TransportCloseIndexAction.java @@ -35,6 +35,7 @@ import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.Index; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -88,12 +89,12 @@ public class TransportCloseIndexAction extends TransportMasterNodeAction listener) { - final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); + final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); CloseIndexClusterStateUpdateRequest updateRequest = new CloseIndexClusterStateUpdateRequest() .ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout()) .indices(concreteIndices); diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/delete/TransportDeleteIndexAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/delete/TransportDeleteIndexAction.java index 28bf46f798f..c5e504b744f 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/delete/TransportDeleteIndexAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/delete/TransportDeleteIndexAction.java @@ -31,10 +31,15 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.MetaDataDeleteIndexService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.Index; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + /** * Delete index action. */ @@ -70,13 +75,13 @@ public class TransportDeleteIndexAction extends TransportMasterNodeAction listener) { - final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); - if (concreteIndices.length == 0) { + final Set concreteIndices = new HashSet<>(Arrays.asList(indexNameExpressionResolver.concreteIndices(state, request))); + if (concreteIndices.isEmpty()) { listener.onResponse(new DeleteIndexResponse(true)); return; } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/TransportIndicesExistsAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/TransportIndicesExistsAction.java index acda370d7ff..08edd16e671 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/TransportIndicesExistsAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/TransportIndicesExistsAction.java @@ -60,7 +60,7 @@ public class TransportIndicesExistsAction extends TransportMasterNodeReadAction< protected ClusterBlockException checkBlock(IndicesExistsRequest request, ClusterState state) { //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()); - 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 @@ -68,7 +68,7 @@ public class TransportIndicesExistsAction extends TransportMasterNodeReadAction< boolean exists; try { // Similar as the previous behaviour, but now also aliases and wildcards are supported. - indexNameExpressionResolver.concreteIndices(state, request); + indexNameExpressionResolver.concreteIndexNames(state, request); exists = true; } catch (IndexNotFoundException e) { exists = false; diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TransportTypesExistsAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TransportTypesExistsAction.java index 2fd92451752..f76b3eb213a 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TransportTypesExistsAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TransportTypesExistsAction.java @@ -57,12 +57,12 @@ public class TransportTypesExistsAction extends TransportMasterNodeReadAction listener) { - String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request.indicesOptions(), request.indices()); + String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request.indicesOptions(), request.indices()); if (concreteIndices.length == 0) { listener.onResponse(new TypesExistsResponse(false)); return; diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportShardFlushAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportShardFlushAction.java index 302bdafc471..5df7e9ad69b 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportShardFlushAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportShardFlushAction.java @@ -46,10 +46,9 @@ public class TransportShardFlushAction extends TransportReplicationAction listener) { ClusterState clusterState = clusterService.state(); - String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request); + String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request); final AtomicInteger indexCounter = new AtomicInteger(); final AtomicInteger completionCounter = new AtomicInteger(concreteIndices.length); final AtomicReferenceArray indexResponses = new AtomicReferenceArray<>(concreteIndices.length); diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java index bff9b4e2ab6..cec337dd54d 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java @@ -52,7 +52,7 @@ public class TransportGetMappingsAction extends TransportClusterInfoAction im private String source; private boolean updateAllTypes = false; + private Index concreteIndex; public PutMappingRequest() { } @@ -90,6 +93,9 @@ public class PutMappingRequest extends AcknowledgedRequest im } else if (source.isEmpty()) { 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; } @@ -102,6 +108,22 @@ public class PutMappingRequest extends AcknowledgedRequest im 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 null if no concrete index is defined + */ + public Index getConcreteIndex() { + return concreteIndex; + } + /** * The indices the mappings will be put. */ @@ -259,6 +281,7 @@ public class PutMappingRequest extends AcknowledgedRequest im source = in.readString(); updateAllTypes = in.readBoolean(); readTimeout(in); + concreteIndex = in.readOptionalWritable(Index::new); } @Override @@ -270,5 +293,6 @@ public class PutMappingRequest extends AcknowledgedRequest im out.writeString(source); out.writeBoolean(updateAllTypes); writeTimeout(out); + out.writeOptionalWriteable(concreteIndex); } } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java index 28f289b86c6..c21c40cf041 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java @@ -23,6 +23,7 @@ import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder; import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.index.Index; import java.util.Map; @@ -40,6 +41,11 @@ public class PutMappingRequestBuilder extends AcknowledgedRequestBuilder diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java index b82c5d3a626..0d8accd7755 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/TransportPutMappingAction.java @@ -31,6 +31,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.MetaDataMappingService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -63,13 +64,19 @@ public class TransportPutMappingAction extends TransportMasterNodeAction listener) { 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() .ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout()) .indices(concreteIndices).type(request.type()) diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/open/TransportOpenIndexAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/open/TransportOpenIndexAction.java index 7ffb30b9534..b354c8bbfce 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/open/TransportOpenIndexAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/open/TransportOpenIndexAction.java @@ -32,6 +32,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.MetaDataIndexStateService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.Index; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -73,12 +74,12 @@ public class TransportOpenIndexAction extends TransportMasterNodeAction listener) { - final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); + final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); OpenIndexClusterStateUpdateRequest updateRequest = new OpenIndexClusterStateUpdateRequest() .ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout()) .indices(concreteIndices); diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportShardRefreshAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportShardRefreshAction.java index 2dd41f7801d..f5149ed8b23 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportShardRefreshAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportShardRefreshAction.java @@ -48,10 +48,9 @@ public class TransportShardRefreshAction extends TransportReplicationAction listener) { - String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); + Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); ImmutableOpenMap.Builder indexToSettingsBuilder = ImmutableOpenMap.builder(); - for (String concreteIndex : concreteIndices) { + for (Index concreteIndex : concreteIndices) { IndexMetaData indexMetaData = state.getMetaData().index(concreteIndex); if (indexMetaData == null) { continue; @@ -93,7 +94,7 @@ public class TransportGetSettingsAction extends TransportMasterNodeReadAction listener) { - final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); + final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); UpdateSettingsClusterStateUpdateRequest clusterStateUpdateRequest = new UpdateSettingsClusterStateUpdateRequest() .indices(concreteIndices) .settings(request.settings()) diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/shards/TransportIndicesShardStoresAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/shards/TransportIndicesShardStoresAction.java index 5e22bc89144..c040085a89e 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/shards/TransportIndicesShardStoresAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/shards/TransportIndicesShardStoresAction.java @@ -87,7 +87,7 @@ public class TransportIndicesShardStoresAction extends TransportMasterNodeReadAc protected void masterOperation(IndicesShardStoresRequest request, ClusterState state, ActionListener listener) { final RoutingTable routingTables = state.routingTable(); final RoutingNodes routingNodes = state.getRoutingNodes(); - final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); + final String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request); final Set shardIdsToFetch = new HashSet<>(); logger.trace("using cluster state version [{}] to determine shards", state.version()); @@ -115,7 +115,7 @@ public class TransportIndicesShardStoresAction extends TransportMasterNodeReadAc @Override 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 { diff --git a/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java b/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java index 707bf8de57f..135147d824c 100644 --- a/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java +++ b/core/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java @@ -47,6 +47,7 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.AtomicArray; +import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.indices.IndexAlreadyExistsException; @@ -245,17 +246,18 @@ public class TransportBulkAction extends HandledTransportAction list = requestsByShard.get(shardId); if (list == null) { @@ -304,7 +306,7 @@ public class TransportBulkAction extends HandledTransportAction list = requestsByShard.get(shardId); if (list == null) { @@ -314,7 +316,7 @@ public class TransportBulkAction extends HandledTransportAction list = requestsByShard.get(shardId); if (list == null) { @@ -356,18 +358,19 @@ public class TransportBulkAction extends HandledTransportAction responses, int idx, final ConcreteIndices concreteIndices, final MetaData metaData) { - String concreteIndex = concreteIndices.getConcreteIndex(request.index()); + Index concreteIndex = concreteIndices.getConcreteIndex(request.index()); Exception unavailableException = null; if (concreteIndex == null) { try { @@ -397,9 +400,9 @@ public class TransportBulkAction extends HandledTransportAction indices = new HashMap<>(); + private final Map indices = new HashMap<>(); ConcreteIndices(ClusterState state, IndexNameExpressionResolver indexNameExpressionResolver) { this.state = state; this.indexNameExpressionResolver = indexNameExpressionResolver; } - String getConcreteIndex(String indexOrAlias) { + Index getConcreteIndex(String indexOrAlias) { return indices.get(indexOrAlias); } - String resolveIfAbsent(DocumentRequest request) { - String concreteIndex = indices.get(request.index()); + Index resolveIfAbsent(DocumentRequest request) { + Index concreteIndex = indices.get(request.index()); if (concreteIndex == null) { concreteIndex = indexNameExpressionResolver.concreteSingleIndex(state, request); indices.put(request.index(), concreteIndex); diff --git a/core/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java b/core/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java index f1eeae35e08..463f4ac23ac 100644 --- a/core/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java +++ b/core/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java @@ -47,7 +47,6 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.engine.Engine; @@ -75,17 +74,19 @@ public class TransportShardBulkAction extends TransportReplicationAction implements Do 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) { // resolve the routing if needed @@ -600,8 +593,7 @@ public class IndexRequest extends ReplicationRequest implements Do // resolve timestamp if provided externally if (timestamp != null) { timestamp = MappingMetaData.Timestamp.parseStringTimestamp(timestamp, - mappingMd != null ? mappingMd.timestamp().dateTimeFormatter() : TimestampFieldMapper.Defaults.DATE_TIME_FORMATTER, - getVersion(metaData, concreteIndex)); + mappingMd != null ? mappingMd.timestamp().dateTimeFormatter() : TimestampFieldMapper.Defaults.DATE_TIME_FORMATTER); } if (mappingMd != null) { // might as well check for routing here @@ -645,7 +637,7 @@ public class IndexRequest extends ReplicationRequest implements Do // assigned again because mappingMd and // mappingMd#timestamp() are not null assert mappingMd != null; - timestamp = MappingMetaData.Timestamp.parseStringTimestamp(defaultTimestamp, mappingMd.timestamp().dateTimeFormatter(), getVersion(metaData, concreteIndex)); + timestamp = MappingMetaData.Timestamp.parseStringTimestamp(defaultTimestamp, mappingMd.timestamp().dateTimeFormatter()); } } } diff --git a/core/src/main/java/org/elasticsearch/action/index/TransportIndexAction.java b/core/src/main/java/org/elasticsearch/action/index/TransportIndexAction.java index fdd018c51f2..0d2e7c2e074 100644 --- a/core/src/main/java/org/elasticsearch/action/index/TransportIndexAction.java +++ b/core/src/main/java/org/elasticsearch/action/index/TransportIndexAction.java @@ -69,6 +69,7 @@ public class TransportIndexAction extends TransportReplicationAction shardOperationOnPrimary(MetaData metaData, IndexRequest request) throws Exception { // 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()); if (mappingMd != null && mappingMd.routing().required()) { if (request.routing() == null) { @@ -205,8 +207,7 @@ public class TransportIndexAction extends TransportReplicationAction // 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 // of just for the _search api - String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request.indicesOptions(), + String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request.indicesOptions(), startTime(), request.indices()); for (String index : concreteIndices) { diff --git a/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java b/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java index e87fa2a345a..0b53008ddf5 100644 --- a/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java @@ -64,7 +64,7 @@ public class TransportSearchAction extends HandledTransportAction> routingMap = indexNameExpressionResolver.resolveSearchRouting(clusterState, searchRequest.routing(), searchRequest.indices()); int shardCount = clusterService.operationRouting().searchShardsCount(clusterState, concreteIndices, routingMap); diff --git a/core/src/main/java/org/elasticsearch/action/support/broadcast/TransportBroadcastAction.java b/core/src/main/java/org/elasticsearch/action/support/broadcast/TransportBroadcastAction.java index e39fb0288ac..f2d7e306c38 100644 --- a/core/src/main/java/org/elasticsearch/action/support/broadcast/TransportBroadcastAction.java +++ b/core/src/main/java/org/elasticsearch/action/support/broadcast/TransportBroadcastAction.java @@ -125,7 +125,7 @@ public abstract class TransportBroadcastAction listener) { - String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); + String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request); doMasterOperation(request, concreteIndices, state, listener); } diff --git a/core/src/main/java/org/elasticsearch/action/support/replication/TransportBroadcastReplicationAction.java b/core/src/main/java/org/elasticsearch/action/support/replication/TransportBroadcastReplicationAction.java index a15819e82c7..8ace072fa88 100644 --- a/core/src/main/java/org/elasticsearch/action/support/replication/TransportBroadcastReplicationAction.java +++ b/core/src/main/java/org/elasticsearch/action/support/replication/TransportBroadcastReplicationAction.java @@ -97,7 +97,7 @@ public abstract class TransportBroadcastReplicationAction shards(Request request, ClusterState clusterState) { List shardIds = new ArrayList<>(); - String[] concreteIndices = indexNameExpressionResolver.concreteIndices(clusterState, request); + String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request); for (String index : concreteIndices) { IndexMetaData indexMetaData = clusterState.metaData().getIndices().get(index); if (indexMetaData != null) { diff --git a/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java b/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java index 69df4e61787..28d21c6dbd9 100644 --- a/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java +++ b/core/src/main/java/org/elasticsearch/action/support/replication/TransportReplicationAction.java @@ -103,7 +103,6 @@ public abstract class TransportReplicationAction request, Supplier replicaRequest, String executor) { super(settings, actionName, threadPool, actionFilters, indexNameExpressionResolver, transportService.getTaskManager()); @@ -121,7 +120,6 @@ public abstract class TransportReplicationAction deleted = null; for (ObjectCursor cursor : previousState.metaData().indices().values()) { IndexMetaData index = cursor.value; - IndexMetaData current = state.metaData().index(index.getIndex().getName()); - if (current == null || index.getIndexUUID().equals(current.getIndexUUID()) == false) { + IndexMetaData current = state.metaData().index(index.getIndex()); + if (current == null) { if (deleted == null) { deleted = new ArrayList<>(); } diff --git a/core/src/main/java/org/elasticsearch/cluster/ack/IndicesClusterStateUpdateRequest.java b/core/src/main/java/org/elasticsearch/cluster/ack/IndicesClusterStateUpdateRequest.java index c691abe5906..33d716cb965 100644 --- a/core/src/main/java/org/elasticsearch/cluster/ack/IndicesClusterStateUpdateRequest.java +++ b/core/src/main/java/org/elasticsearch/cluster/ack/IndicesClusterStateUpdateRequest.java @@ -18,17 +18,19 @@ */ package org.elasticsearch.cluster.ack; +import org.elasticsearch.index.Index; + /** * Base cluster state update request that allows to execute update against multiple indices */ public abstract class IndicesClusterStateUpdateRequest> extends ClusterStateUpdateRequest { - private String[] indices; + private Index[] indices; /** * Returns the indices the operation needs to be executed on */ - public String[] indices() { + public Index[] indices() { return indices; } @@ -36,7 +38,7 @@ public abstract class IndicesClusterStateUpdateRequest actionListener = new ActionListener() { - @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. */ - public void updateMappingOnMasterSynchronously(String index, String type, Mapping mappingUpdate) throws Exception { - updateMappingOnMasterSynchronously(index, type, mappingUpdate, dynamicMappingUpdateTimeout); + public void updateMappingOnMaster(Index index, String type, Mapping mappingUpdate) throws Exception { + updateMappingOnMaster(index, type, mappingUpdate, dynamicMappingUpdateTimeout); } /** @@ -114,19 +85,9 @@ public class MappingUpdatedAction extends AbstractComponent { * {@code timeout}. When this method returns successfully mappings have * 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) { 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); - } } diff --git a/core/src/main/java/org/elasticsearch/cluster/action/index/NodeIndexDeletedAction.java b/core/src/main/java/org/elasticsearch/cluster/action/index/NodeIndexDeletedAction.java index c2c1b468f1b..93fce95fc23 100644 --- a/core/src/main/java/org/elasticsearch/cluster/action/index/NodeIndexDeletedAction.java +++ b/core/src/main/java/org/elasticsearch/cluster/action/index/NodeIndexDeletedAction.java @@ -76,7 +76,7 @@ public class NodeIndexDeletedAction extends AbstractComponent { 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(); transportService.sendRequest(clusterState.nodes().masterNode(), 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 { // 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 @@ -114,9 +114,9 @@ public class NodeIndexDeletedAction extends AbstractComponent { } 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 { @@ -143,13 +143,13 @@ public class NodeIndexDeletedAction extends AbstractComponent { public static class NodeIndexDeletedMessage extends TransportRequest { - String index; + Index index; String nodeId; public NodeIndexDeletedMessage() { } - NodeIndexDeletedMessage(String index, String nodeId) { + NodeIndexDeletedMessage(Index index, String nodeId) { this.index = index; this.nodeId = nodeId; } @@ -157,27 +157,27 @@ public class NodeIndexDeletedAction extends AbstractComponent { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeString(index); + index.writeTo(out); out.writeString(nodeId); } @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - index = in.readString(); + index = new Index(in); nodeId = in.readString(); } } public static class NodeIndexStoreDeletedMessage extends TransportRequest { - String index; + Index index; String nodeId; public NodeIndexStoreDeletedMessage() { } - NodeIndexStoreDeletedMessage(String index, String nodeId) { + NodeIndexStoreDeletedMessage(Index index, String nodeId) { this.index = index; this.nodeId = nodeId; } @@ -185,14 +185,14 @@ public class NodeIndexDeletedAction extends AbstractComponent { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeString(index); + index.writeTo(out); out.writeString(nodeId); } @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - index = in.readString(); + index = new Index(in); nodeId = in.readString(); } } diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java index 9bd4ba6112b..49c057f104d 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java @@ -32,6 +32,7 @@ import org.elasticsearch.common.joda.DateMathParser; import org.elasticsearch.common.joda.FormatDateTimeFormatter; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.indices.IndexClosedException; 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 * 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()); 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 * 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); 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 * 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); - 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) { indexExpressions = new String[]{MetaData.ALL}; } @@ -136,11 +173,11 @@ public class IndexNameExpressionResolver extends AbstractComponent { infe.setResources("index_expression", indexExpressions); throw infe; } else { - return Strings.EMPTY_ARRAY; + return Index.EMPTY_ARRAY; } } - final Set concreteIndices = new HashSet<>(expressions.size()); + final Set concreteIndices = new HashSet<>(expressions.size()); for (String expression : expressions) { AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(expression); if (aliasOrIndex == null) { @@ -169,11 +206,11 @@ public class IndexNameExpressionResolver extends AbstractComponent { throw new IndexClosedException(index.getIndex()); } else { if (options.forbidClosedIndices() == false) { - concreteIndices.add(index.getIndex().getName()); + concreteIndices.add(index.getIndex()); } } } else if (index.getState() == IndexMetaData.State.OPEN) { - concreteIndices.add(index.getIndex().getName()); + concreteIndices.add(index.getIndex()); } else { throw new IllegalStateException("index state [" + index.getState() + "] not supported"); } @@ -185,7 +222,7 @@ public class IndexNameExpressionResolver extends AbstractComponent { infe.setResources("index_expression", indexExpressions); 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 * @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[] indices = concreteIndices(state, request.indicesOptions(), indexExpression); + Index[] indices = concreteIndices(state, request.indicesOptions(), indexExpression); if (indices.length != 1) { 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 true iff the given expression resolves to the given index name otherwise false */ 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) { if (Regex.simpleMatch(index, indexName)) { return true; diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java index a88f1609b9e..10b05c46657 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java @@ -84,20 +84,10 @@ public class MappingMetaData extends AbstractDiffable { private static final FormatDateTimeFormatter EPOCH_MILLIS_PARSER = Joda.forPattern("epoch_millis"); - public static String parseStringTimestamp(String timestampAsString, FormatDateTimeFormatter dateTimeFormatter, - Version version) throws TimestampParsingException { + public static String parseStringTimestamp(String timestampAsString, FormatDateTimeFormatter dateTimeFormatter) throws TimestampParsingException { try { - // no need for unix timestamp parsing in 2.x - FormatDateTimeFormatter formatter = version.onOrAfter(Version.V_2_0_0_beta1) ? dateTimeFormatter : EPOCH_MILLIS_PARSER; - return Long.toString(formatter.parser().parseMillis(timestampAsString)); + return Long.toString(dateTimeFormatter.parser().parseMillis(timestampAsString)); } 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); } } diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java index 4c83f64581e..f802637f22f 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -232,7 +232,7 @@ public class MetaData implements Iterable, Diffable, Fr public boolean equalsAliases(MetaData other) { for (ObjectCursor cursor : other.indices().values()) { IndexMetaData otherIndex = cursor.value; - IndexMetaData thisIndex= index(otherIndex.getIndex()); + IndexMetaData thisIndex = index(otherIndex.getIndex()); if (thisIndex == null) { return false; } @@ -457,7 +457,28 @@ public class MetaData implements Iterable, Diffable, Fr } 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 indices() { @@ -488,20 +509,13 @@ public class MetaData implements Iterable, Diffable, Fr return (T) customs.get(type); } - public int totalNumberOfShards() { + + public int getTotalNumberOfShards() { return this.totalNumberOfShards; } - public int getTotalNumberOfShards() { - return totalNumberOfShards(); - } - - public int numberOfShards() { - return this.numberOfShards; - } - public int getNumberOfShards() { - return numberOfShards(); + return this.numberOfShards; } /** @@ -844,6 +858,19 @@ public class MetaData implements Iterable, Diffable, Fr 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) { indices.remove(index); return this; diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java index 132e46b1e94..5492325b651 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java @@ -35,14 +35,17 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.FutureUtils; import org.elasticsearch.common.util.set.Sets; +import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.snapshots.SnapshotsService; import org.elasticsearch.threadpool.ThreadPool; +import java.util.HashSet; import java.util.Set; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.atomic.AtomicBoolean; 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) { - Set indices = Sets.newHashSet(request.indices); 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 public TimeValue timeout() { @@ -85,23 +87,21 @@ public class MetaDataDeleteIndexService extends AbstractComponent { @Override public ClusterState execute(final ClusterState currentState) { + final MetaData meta = currentState.metaData(); + final Set metaDatas = request.indices.stream().map(i -> meta.getIndexSafe(i)).collect(Collectors.toSet()); // Check if index deletion conflicts with any running snapshots - SnapshotsService.checkIndexDeletion(currentState, indices); - + SnapshotsService.checkIndexDeletion(currentState, metaDatas); + final Set indices = request.indices; 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()); - for (final String index: indices) { - if (!currentState.metaData().hasConcreteIndex(index)) { - throw new IndexNotFoundException(index); - } - + for (final Index index : indices) { + String indexName = index.getName(); logger.debug("[{}] deleting index", index); - - routingTableBuilder.remove(index); - clusterBlocksBuilder.removeIndexBlocks(index); - metaDataBuilder.remove(index); + routingTableBuilder.remove(indexName); + clusterBlocksBuilder.removeIndexBlocks(indexName); + metaDataBuilder.remove(indexName); } // wait for events from all nodes that it has been removed from their respective metadata... 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. final NodeIndexDeletedAction.Listener nodeIndexDeleteListener = new NodeIndexDeletedAction.Listener() { @Override - public void onNodeIndexDeleted(String deleted, String nodeId) { + public void onNodeIndexDeleted(Index deleted, String nodeId) { if (indices.contains(deleted)) { if (counter.decrementAndGet() == 0) { listener.onResponse(new Response(true)); @@ -122,7 +122,7 @@ public class MetaDataDeleteIndexService extends AbstractComponent { } @Override - public void onNodeIndexStoreDeleted(String deleted, String nodeId) { + public void onNodeIndexStoreDeleted(Index deleted, String nodeId) { if (indices.contains(deleted)) { if (counter.decrementAndGet() == 0) { listener.onResponse(new Response(true)); @@ -187,12 +187,12 @@ public class MetaDataDeleteIndexService extends AbstractComponent { public static class Request { - final String[] indices; + final Set indices; TimeValue timeout = TimeValue.timeValueSeconds(10); TimeValue masterTimeout = MasterNodeRequest.DEFAULT_MASTER_NODE_TIMEOUT; - public Request(String[] indices) { + public Request(Set indices) { this.indices = indices; } diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java index 121065bc638..e68b0be36b6 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java @@ -36,6 +36,7 @@ import org.elasticsearch.common.Priority; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.snapshots.RestoreService; @@ -82,15 +83,11 @@ public class MetaDataIndexStateService extends AbstractComponent { @Override public ClusterState execute(ClusterState currentState) { - Set indicesToClose = new HashSet<>(); - for (String index : request.indices()) { - IndexMetaData indexMetaData = currentState.metaData().index(index); - if (indexMetaData == null) { - throw new IndexNotFoundException(index); - } - + Set indicesToClose = new HashSet<>(); + for (Index index : request.indices()) { + final IndexMetaData indexMetaData = currentState.metaData().getIndexSafe(index); 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); // Check if index closing conflicts with any running snapshots SnapshotsService.checkIndexClosing(currentState, indicesToClose); - logger.info("closing indices [{}]", indicesAsString); MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData()); ClusterBlocks.Builder blocksBuilder = ClusterBlocks.builder() .blocks(currentState.blocks()); - for (String index : indicesToClose) { - mdBuilder.put(IndexMetaData.builder(currentState.metaData().index(index)).state(IndexMetaData.State.CLOSE)); - blocksBuilder.addIndexBlock(index, INDEX_CLOSED_BLOCK); + for (IndexMetaData openIndexMetadata : indicesToClose) { + final String indexName = openIndexMetadata.getIndex().getName(); + 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(); RoutingTable.Builder rtBuilder = RoutingTable.builder(currentState.routingTable()); - for (String index : indicesToClose) { - rtBuilder.remove(index); + for (IndexMetaData index : indicesToClose) { + rtBuilder.remove(index.getIndex().getName()); } RoutingAllocation.Result routingResult = allocationService.reroute( @@ -143,14 +140,11 @@ public class MetaDataIndexStateService extends AbstractComponent { @Override public ClusterState execute(ClusterState currentState) { - List indicesToOpen = new ArrayList<>(); - for (String index : request.indices()) { - IndexMetaData indexMetaData = currentState.metaData().index(index); - if (indexMetaData == null) { - throw new IndexNotFoundException(index); - } + List indicesToOpen = new ArrayList<>(); + for (Index index : request.indices()) { + final IndexMetaData indexMetaData = currentState.metaData().getIndexSafe(index); 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()); ClusterBlocks.Builder blocksBuilder = ClusterBlocks.builder() .blocks(currentState.blocks()); - for (String index : indicesToOpen) { - IndexMetaData indexMetaData = IndexMetaData.builder(currentState.metaData().index(index)).state(IndexMetaData.State.OPEN).build(); + for (IndexMetaData closedMetaData : indicesToOpen) { + 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 // We need to check that this index can be upgraded to the current version indexMetaData = metaDataIndexUpgradeService.upgradeIndexMetaData(indexMetaData); 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(); RoutingTable.Builder rtBuilder = RoutingTable.builder(updatedState.routingTable()); - for (String index : indicesToOpen) { - rtBuilder.addAsFromCloseToOpen(updatedState.metaData().index(index)); + for (IndexMetaData index : indicesToOpen) { + rtBuilder.addAsFromCloseToOpen(updatedState.metaData().getIndexSafe(index.getIndex())); } RoutingAllocation.Result routingResult = allocationService.reroute( diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java index 51095a2d0de..a4dbe058395 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataMappingService.java @@ -31,6 +31,7 @@ import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Priority; +import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.inject.Inject; @@ -216,31 +217,23 @@ public class MetaDataMappingService extends AbstractComponent { try { // precreate incoming indices; for (PutMappingClusterStateUpdateRequest request : tasks) { - final List indices = new ArrayList<>(request.indices().length); try { - for (String index : request.indices()) { - final IndexMetaData indexMetaData = currentState.metaData().index(index); - if (indexMetaData != null) { - if (indicesService.hasIndex(indexMetaData.getIndex()) == false) { - // 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 - indicesToClose.add(indexMetaData.getIndex()); - IndexService indexService = indicesService.createIndex(nodeServicesProvider, indexMetaData, - Collections.emptyList()); - // add mappings for all types, we need them for cross-type validation - for (ObjectCursor mapping : indexMetaData.getMappings().values()) { - indexService.mapperService().merge(mapping.value.type(), mapping.value.source(), - MapperService.MergeReason.MAPPING_RECOVERY, request.updateAllTypes()); - } + for (Index index : request.indices()) { + final IndexMetaData indexMetaData = currentState.metaData().getIndexSafe(index); + if (indicesService.hasIndex(indexMetaData.getIndex()) == false) { + // 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 + indicesToClose.add(indexMetaData.getIndex()); + IndexService indexService = indicesService.createIndex(nodeServicesProvider, indexMetaData, + Collections.emptyList()); + // add mappings for all types, we need them for cross-type validation + for (ObjectCursor mapping : indexMetaData.getMappings().values()) { + indexService.mapperService().merge(mapping.value.type(), mapping.value.source(), + 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); } catch (Throwable t) { builder.failure(request, t); @@ -254,13 +247,20 @@ public class MetaDataMappingService extends AbstractComponent { } } - private ClusterState applyRequest(ClusterState currentState, PutMappingClusterStateUpdateRequest request, - List indices) throws IOException { + private ClusterState applyRequest(ClusterState currentState, PutMappingClusterStateUpdateRequest request) throws IOException { String mappingType = request.type(); CompressedXContent mappingUpdateSource = new CompressedXContent(request.source()); final MetaData metaData = currentState.metaData(); - for (Index index : indices) { + final List> updateList = new ArrayList<>(); + for (Index index : request.indices()) { 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 DocumentMapper newMapper; 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. // Also the order of the mappings may be backwards. if (newMapper.parentFieldMapper().active()) { - IndexMetaData indexMetaData = metaData.index(index); for (ObjectCursor mapping : indexMetaData.getMappings().values()) { if (newMapper.parentFieldMapper().type().equals(mapping.value.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 '_'"); } MetaData.Builder builder = MetaData.builder(metaData); - for (Index index : indices) { + for (Tuple toUpdate : updateList) { // do the actual merge here on the master, and update the mapping source - IndexService indexService = indicesService.indexService(index); - if (indexService == null) { // TODO this seems impossible given we use indexServiceSafe above - continue; - } - + // we use the exact same indexService and metadata we used to validate above here to actually apply the update + final IndexService indexService = toUpdate.v1(); + final IndexMetaData indexMetaData = toUpdate.v2(); + final Index index = indexMetaData.getIndex(); CompressedXContent existingSource = null; DocumentMapper existingMapper = indexService.mapperService().documentMapper(mappingType); if (existingMapper != null) { @@ -323,24 +321,20 @@ public class MetaDataMappingService extends AbstractComponent { } else { // use the merged mapping source 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()) { - logger.info("[{}] update_mapping [{}]", index, mergedMapper.type()); + logger.info("{} update_mapping [{}]", index, mergedMapper.type()); } } } else { 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()) { - 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); // Mapping updates on a single type may have side-effects on other types so we need to // update mapping metadata on all types diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java index 2d7ba4c3c05..b2764734469 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java @@ -23,7 +23,6 @@ import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsClusterStateUpdateRequest; import org.elasticsearch.action.admin.indices.upgrade.post.UpgradeSettingsClusterStateUpdateRequest; -import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.AckedClusterStateUpdateTask; import org.elasticsearch.cluster.ClusterChangedEvent; 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.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.index.IndexNotFoundException; +import org.elasticsearch.index.Index; import java.util.ArrayList; 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 final int dataNodeCount = event.state().nodes().dataNodes().size(); - Map> nrReplicasChanged = new HashMap<>(); + Map> nrReplicasChanged = new HashMap<>(); // we need to do this each time in case it was changed by update settings for (final IndexMetaData indexMetaData : event.state().metaData()) { 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.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 for (final Integer fNumberOfReplicas : nrReplicasChanged.keySet()) { Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, fNumberOfReplicas).build(); - final List indices = nrReplicasChanged.get(fNumberOfReplicas); + final List indices = nrReplicasChanged.get(fNumberOfReplicas); 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 .masterNodeTimeout(TimeValue.timeValueMinutes(10)); updateSettings(updateRequest, new ActionListener() { @Override public void onResponse(ClusterStateUpdateResponse response) { - for (String index : indices) { - logger.info("[{}] auto expanded replicas to [{}]", index, fNumberOfReplicas); + for (Index index : indices) { + logger.info("{} auto expanded replicas to [{}]", index, fNumberOfReplicas); } } @Override public void onFailure(Throwable t) { - for (String index : indices) { - logger.warn("[{}] fail to auto expand replicas to [{}]", index, fNumberOfReplicas); + for (Index index : indices) { + logger.warn("{} fail to auto expand replicas to [{}]", index, fNumberOfReplicas); } } }); @@ -188,16 +187,19 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements @Override public ClusterState execute(ClusterState currentState) { - String[] actualIndices = indexNameExpressionResolver.concreteIndices(currentState, IndicesOptions.strictExpand(), request.indices()); RoutingTable.Builder routingTableBuilder = RoutingTable.builder(currentState.routingTable()); MetaData.Builder metaDataBuilder = MetaData.builder(currentState.metaData()); // allow to change any settings to a close index, and only allow dynamic settings to be changed // on an open index - Set openIndices = new HashSet<>(); - Set closeIndices = new HashSet<>(); - for (String index : actualIndices) { - if (currentState.metaData().index(index).getState() == IndexMetaData.State.OPEN) { + Set openIndices = new HashSet<>(); + Set closeIndices = new HashSet<>(); + final String[] actualIndices = new String[request.indices().length]; + 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); } else { 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) { 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 )); } if (!skippedSettigns.getAsMap().isEmpty() && !openIndices.isEmpty()) { 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(), openIndices )); @@ -232,28 +234,22 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements maybeUpdateClusterBlock(actualIndices, blocks, IndexMetaData.INDEX_READ_BLOCK, IndexMetaData.INDEX_BLOCKS_READ_SETTING, openSettings); if (!openIndices.isEmpty()) { - for (String index : openIndices) { - IndexMetaData indexMetaData = metaDataBuilder.get(index); - if (indexMetaData == null) { - throw new IndexNotFoundException(index); - } + for (Index index : openIndices) { + IndexMetaData indexMetaData = metaDataBuilder.getSafe(index); Settings.Builder updates = Settings.builder(); 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)); } } } if (!closeIndices.isEmpty()) { - for (String index : closeIndices) { - IndexMetaData indexMetaData = metaDataBuilder.get(index); - if (indexMetaData == null) { - throw new IndexNotFoundException(index); - } + for (Index index : closeIndices) { + IndexMetaData indexMetaData = metaDataBuilder.getSafe(index); Settings.Builder updates = Settings.builder(); 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)); } } @@ -265,11 +261,11 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements // now, reroute in case things change that require it (like number of replicas) RoutingAllocation.Result routingResult = allocationService.reroute(updatedState, "settings update"); updatedState = ClusterState.builder(updatedState).routingResult(routingResult).build(); - for (String index : openIndices) { - indexScopedSettings.dryRun(updatedState.metaData().index(index).getSettings()); + for (Index index : openIndices) { + indexScopedSettings.dryRun(updatedState.metaData().getIndexSafe(index).getSettings()); } - for (String index : closeIndices) { - indexScopedSettings.dryRun(updatedState.metaData().index(index).getSettings()); + for (Index index : closeIndices) { + indexScopedSettings.dryRun(updatedState.metaData().getIndexSafe(index).getSettings()); } return updatedState; } diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java b/core/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java index 160ccbf06b3..c32d9de363d 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java @@ -313,7 +313,7 @@ public class IndexRoutingTable extends AbstractDiffable imple @Override public IndexRoutingTable readFrom(StreamInput in) throws IOException { - Index index = Index.readIndex(in); + Index index = new Index(in); Builder builder = new Builder(index); int size = in.readVInt(); diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java b/core/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java index bda0a24c9a4..e64f8f5d77c 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java @@ -584,7 +584,7 @@ public class IndexShardRoutingTable implements Iterable { } public static IndexShardRoutingTable readFrom(StreamInput in) throws IOException { - Index index = Index.readIndex(in); + Index index = new Index(in); return readFromThin(in, index); } diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java b/core/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java index cfa33e4f225..a5975deb9cf 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java @@ -328,7 +328,7 @@ public final class ShardRouting implements Streamable, ToXContent { @Override public void readFrom(StreamInput in) throws IOException { - readFrom(in, Index.readIndex(in), in.readVInt()); + readFrom(in, new Index(in), in.readVInt()); } /** diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java index 5c383bcae83..54f9b6855a6 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java @@ -320,7 +320,7 @@ public class AllocationService extends AbstractComponent { public static void updateLeftDelayOfUnassignedShards(RoutingAllocation allocation, Settings settings) { for (ShardRouting shardRouting : allocation.routingNodes().unassigned()) { 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()); } } @@ -340,7 +340,6 @@ public class AllocationService extends AbstractComponent { changed |= failReplicasForUnassignedPrimary(allocation, shardEntry); ShardRouting candidate = allocation.routingNodes().activeReplica(shardEntry); if (candidate != null) { - IndexMetaData index = allocation.metaData().index(candidate.index()); routingNodes.swapPrimaryFlag(shardEntry, candidate); if (candidate.relocatingNodeId() != null) { changed = true; @@ -355,6 +354,7 @@ public class AllocationService extends AbstractComponent { } } } + IndexMetaData index = allocation.metaData().getIndexSafe(candidate.index()); if (IndexMetaData.isIndexUsingShadowReplicas(index.getSettings())) { routingNodes.reinitShadowPrimary(candidate); changed = true; diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java index 26b8b224d78..8102f206799 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java @@ -218,7 +218,7 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards this.threshold = threshold; this.routingNodes = allocation.routingNodes(); metaData = routingNodes.metaData(); - avgShardsPerNode = ((float) metaData.totalNumberOfShards()) / routingNodes.size(); + avgShardsPerNode = ((float) metaData.getTotalNumberOfShards()) / routingNodes.size(); buildModelFromAssigned(); } diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateStalePrimaryAllocationCommand.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateStalePrimaryAllocationCommand.java index 5ccd9e9bb63..f4b1be19af4 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateStalePrimaryAllocationCommand.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateStalePrimaryAllocationCommand.java @@ -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"); } - final IndexMetaData indexMetaData = allocation.metaData().index(shardRouting.getIndexName()); + final IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(shardRouting.index()); if (shardRouting.allocatedPostIndexCreate(indexMetaData) == false) { return explainOrThrowRejectedCommand(explain, allocation, "trying to allocate an existing primary shard [" + index + "][" + shardId + "], while no such shard has ever been active"); diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java index 77613f39084..227ec277469 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java @@ -153,7 +153,7 @@ public class AwarenessAllocationDecider extends AllocationDecider { 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 for (String awarenessAttribute : awarenessAttributes) { // the node the shard exists on must be associated with an awareness attribute diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java index dcb6080bd1e..e2124558f2d 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java @@ -342,7 +342,7 @@ public class DiskThresholdDecider extends AllocationDecider { } // 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); // checks for exact byte comparisons diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationDecider.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationDecider.java index 80dada86022..0b69ba2a19e 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationDecider.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationDecider.java @@ -101,7 +101,7 @@ public class EnableAllocationDecider extends AllocationDecider { 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; if (INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.exists(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"); } - Settings indexSettings = allocation.routingNodes().metaData().index(shardRouting.index()).getSettings(); + Settings indexSettings = allocation.routingNodes().metaData().getIndexSafe(shardRouting.index()).getSettings(); final Rebalance enable; if (INDEX_ROUTING_REBALANCE_ENABLE_SETTING.exists(indexSettings)) { enable = INDEX_ROUTING_REBALANCE_ENABLE_SETTING.get(indexSettings); diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDecider.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDecider.java index c3ff0bb355e..d1aa0d8b583 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDecider.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDecider.java @@ -102,7 +102,7 @@ public class FilterAllocationDecider extends AllocationDecider { Decision decision = shouldClusterFilter(node, allocation); 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; return allocation.decision(Decision.YES, NAME, "node passes include/exclude/require filters"); diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java index ab8be4dc8da..04247525f1d 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java @@ -86,7 +86,7 @@ public class ShardsLimitAllocationDecider extends AllocationDecider { @Override 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); // Capture the limit here in case it changes during this method's // execution @@ -123,7 +123,7 @@ public class ShardsLimitAllocationDecider extends AllocationDecider { @Override 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); // Capture the limit here in case it changes during this method's // execution diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index e84766d021b..aadf2b9145a 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -553,9 +553,9 @@ public abstract class StreamInput extends InputStream { } } - public T readOptionalWritable(T prototype) throws IOException { + public T readOptionalWritable(Writeable.IOFunction provider) throws IOException { if (readBoolean()) { - return (T) prototype.readFrom(this); + return provider.apply(this); } else { return null; } diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/Writeable.java b/core/src/main/java/org/elasticsearch/common/io/stream/Writeable.java index 9ff3de736c5..8f0cb3c96c7 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/Writeable.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/Writeable.java @@ -37,4 +37,15 @@ public interface Writeable extends StreamableReader { * Write this into the {@linkplain StreamOutput}. */ void writeTo(StreamOutput out) throws IOException; + + @FunctionalInterface + interface IOFunction { + /** + * Applies this function to the given argument. + * + * @param t the function argument + * @return the function result + */ + R apply(T t) throws IOException; + } } diff --git a/core/src/main/java/org/elasticsearch/gateway/AsyncShardFetch.java b/core/src/main/java/org/elasticsearch/gateway/AsyncShardFetch.java index 757a78c3b5f..1ccdb43cc45 100644 --- a/core/src/main/java/org/elasticsearch/gateway/AsyncShardFetch.java +++ b/core/src/main/java/org/elasticsearch/gateway/AsyncShardFetch.java @@ -269,7 +269,7 @@ public abstract class AsyncShardFetch implements Rel */ // visible for testing 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); action.list(shardId, indexMetaData, nodesIds, new ActionListener>() { @Override diff --git a/core/src/main/java/org/elasticsearch/gateway/Gateway.java b/core/src/main/java/org/elasticsearch/gateway/Gateway.java index fd3bd9a0b6d..2d1d48cbd83 100644 --- a/core/src/main/java/org/elasticsearch/gateway/Gateway.java +++ b/core/src/main/java/org/elasticsearch/gateway/Gateway.java @@ -34,6 +34,7 @@ import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.Discovery; import org.elasticsearch.env.NodeEnvironment; +import org.elasticsearch.index.Index; import java.nio.file.Path; import java.util.function.Supplier; @@ -79,7 +80,7 @@ public class Gateway extends AbstractComponent implements ClusterStateListener { } } - ObjectFloatHashMap indices = new ObjectFloatHashMap<>(); + ObjectFloatHashMap indices = new ObjectFloatHashMap<>(); MetaData electedGlobalState = null; int found = 0; for (TransportNodesListGatewayMetaState.NodeGatewayMetaState nodeState : nodesState) { @@ -93,7 +94,7 @@ public class Gateway extends AbstractComponent implements ClusterStateListener { electedGlobalState = nodeState.metaData(); } for (ObjectCursor cursor : nodeState.metaData().indices().values()) { - indices.addTo(cursor.value.getIndex().getName(), 1); + indices.addTo(cursor.value.getIndex(), 1); } } if (found < requiredAllocation) { @@ -107,7 +108,7 @@ public class Gateway extends AbstractComponent implements ClusterStateListener { final Object[] keys = indices.keys; for (int i = 0; i < keys.length; i++) { if (keys[i] != null) { - String index = (String) keys[i]; + Index index = (Index) keys[i]; IndexMetaData electedIndexMetaData = null; int indexMetaDataCount = 0; for (TransportNodesListGatewayMetaState.NodeGatewayMetaState nodeState : nodesState) { diff --git a/core/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java b/core/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java index 15277d6fb4f..4f0a3bd714a 100644 --- a/core/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java +++ b/core/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java @@ -35,6 +35,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.env.NodeEnvironment; +import org.elasticsearch.index.Index; import java.nio.file.DirectoryStream; import java.nio.file.Files; @@ -61,7 +62,7 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL @Nullable private volatile MetaData previousMetaData; - private volatile Set previouslyWrittenIndices = emptySet(); + private volatile Set previouslyWrittenIndices = emptySet(); @Inject public GatewayMetaState(Settings settings, NodeEnvironment nodeEnv, MetaStateService metaStateService, @@ -102,7 +103,6 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL @Override public void clusterChanged(ClusterChangedEvent event) { - Set relevantIndices = new HashSet<>(); final ClusterState state = event.state(); if (state.blocks().disableStatePersistence()) { // reset the current metadata, we need to start fresh... @@ -113,7 +113,7 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL MetaData newMetaData = state.metaData(); // we don't check if metaData changed, since we might be called several times and we need to check dangling... - + Set relevantIndices = Collections.emptySet(); 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 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(). // we therefore have to check here if we have shards on disk and add their indices to the previouslyWrittenIndices list if (isDataOnlyNode(state)) { - Set newPreviouslyWrittenIndices = new HashSet<>(previouslyWrittenIndices.size()); + Set newPreviouslyWrittenIndices = new HashSet<>(previouslyWrittenIndices.size()); for (IndexMetaData indexMetaData : newMetaData) { IndexMetaData indexMetaDataOnDisk = null; if (indexMetaData.getState().equals(IndexMetaData.State.CLOSE)) { indexMetaDataOnDisk = metaStateService.loadIndexState(indexMetaData.getIndex().getName()); } if (indexMetaDataOnDisk != null) { - newPreviouslyWrittenIndices.add(indexMetaDataOnDisk.getIndex().getName()); + newPreviouslyWrittenIndices.add(indexMetaDataOnDisk.getIndex()); } } newPreviouslyWrittenIndices.addAll(previouslyWrittenIndices); @@ -152,9 +152,9 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL } } - Iterable writeInfo; + relevantIndices = getRelevantIndices(event.state(), event.previousState(), previouslyWrittenIndices); - writeInfo = resolveStatesToBeWritten(previouslyWrittenIndices, relevantIndices, previousMetaData, event.state().metaData()); + final Iterable writeInfo = resolveStatesToBeWritten(previouslyWrittenIndices, relevantIndices, previousMetaData, event.state().metaData()); // check and write changes in indices for (IndexMetaWriteInfo indexMetaWrite : writeInfo) { try { @@ -173,8 +173,8 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL } } - public static Set getRelevantIndices(ClusterState state, ClusterState previousState, Set previouslyWrittenIndices) { - Set relevantIndices; + public static Set getRelevantIndices(ClusterState state, ClusterState previousState, Set previouslyWrittenIndices) { + Set relevantIndices; if (isDataOnlyNode(state)) { relevantIndices = getRelevantIndicesOnDataOnlyNode(state, previousState, previouslyWrittenIndices); } else if (state.nodes().localNode().masterNode() == true) { @@ -264,10 +264,10 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL * @param newMetaData The new metadata * @return iterable over all indices states that should be written to disk */ - public static Iterable resolveStatesToBeWritten(Set previouslyWrittenIndices, Set potentiallyUnwrittenIndices, MetaData previousMetaData, MetaData newMetaData) { + public static Iterable resolveStatesToBeWritten(Set previouslyWrittenIndices, Set potentiallyUnwrittenIndices, MetaData previousMetaData, MetaData newMetaData) { List indicesToWrite = new ArrayList<>(); - for (String index : potentiallyUnwrittenIndices) { - IndexMetaData newIndexMetaData = newMetaData.index(index); + for (Index index : potentiallyUnwrittenIndices) { + IndexMetaData newIndexMetaData = newMetaData.getIndexSafe(index); IndexMetaData previousIndexMetaData = previousMetaData == null ? null : previousMetaData.index(index); String writeReason = null; if (previouslyWrittenIndices.contains(index) == false || previousIndexMetaData == null) { @@ -282,14 +282,14 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL return indicesToWrite; } - public static Set getRelevantIndicesOnDataOnlyNode(ClusterState state, ClusterState previousState, Set previouslyWrittenIndices) { + public static Set getRelevantIndicesOnDataOnlyNode(ClusterState state, ClusterState previousState, Set previouslyWrittenIndices) { RoutingNode newRoutingNode = state.getRoutingNodes().node(state.nodes().localNodeId()); if (newRoutingNode == null) { throw new IllegalStateException("cluster state does not contain this node - cannot write index meta state"); } - Set indices = new HashSet<>(); + Set indices = new HashSet<>(); 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 for (IndexMetaData indexMetaData : state.metaData()) { @@ -300,19 +300,19 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL if (previousMetaData != null) { isOrWasClosed = isOrWasClosed || previousMetaData.getState().equals(IndexMetaData.State.CLOSE); } - if (previouslyWrittenIndices.contains(indexMetaData.getIndex().getName()) && isOrWasClosed) { - indices.add(indexMetaData.getIndex().getName()); + if (previouslyWrittenIndices.contains(indexMetaData.getIndex()) && isOrWasClosed) { + indices.add(indexMetaData.getIndex()); } } return indices; } - public static Set getRelevantIndicesForMasterEligibleNode(ClusterState state) { - Set relevantIndices; + public static Set getRelevantIndicesForMasterEligibleNode(ClusterState state) { + Set relevantIndices; relevantIndices = new HashSet<>(); // we have to iterate over the metadata to make sure we also capture closed indices for (IndexMetaData indexMetaData : state.metaData()) { - relevantIndices.add(indexMetaData.getIndex().getName()); + relevantIndices.add(indexMetaData.getIndex()); } return relevantIndices; } diff --git a/core/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java b/core/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java index 5f6e50d6fc9..a456da0779d 100644 --- a/core/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java +++ b/core/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java @@ -94,7 +94,7 @@ public abstract class PrimaryShardAllocator extends AbstractComponent { 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 // on cluster restart if we allocate a boat load of shards if (shard.allocatedPostIndexCreate(indexMetaData) == false) { diff --git a/core/src/main/java/org/elasticsearch/gateway/PriorityComparator.java b/core/src/main/java/org/elasticsearch/gateway/PriorityComparator.java index 04f438c70fe..1d24baf561a 100644 --- a/core/src/main/java/org/elasticsearch/gateway/PriorityComparator.java +++ b/core/src/main/java/org/elasticsearch/gateway/PriorityComparator.java @@ -23,6 +23,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.Index; import java.util.Comparator; @@ -42,8 +43,8 @@ public abstract class PriorityComparator implements Comparator { final String o2Index = o2.getIndexName(); int cmp = 0; if (o1Index.equals(o2Index) == false) { - final Settings settingsO1 = getIndexSettings(o1Index); - final Settings settingsO2 = getIndexSettings(o2Index); + final Settings settingsO1 = getIndexSettings(o1.index()); + final Settings settingsO2 = getIndexSettings(o2.index()); cmp = Long.compare(priority(settingsO2), priority(settingsO1)); if (cmp == 0) { cmp = Long.compare(timeCreated(settingsO2), timeCreated(settingsO1)); @@ -63,7 +64,7 @@ public abstract class PriorityComparator implements Comparator { 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. @@ -71,8 +72,8 @@ public abstract class PriorityComparator implements Comparator { public static PriorityComparator getAllocationComparator(final RoutingAllocation allocation) { return new PriorityComparator() { @Override - protected Settings getIndexSettings(String index) { - IndexMetaData indexMetaData = allocation.metaData().index(index); + protected Settings getIndexSettings(Index index) { + IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(index); return indexMetaData.getSettings(); } }; diff --git a/core/src/main/java/org/elasticsearch/gateway/ReplicaShardAllocator.java b/core/src/main/java/org/elasticsearch/gateway/ReplicaShardAllocator.java index c94e1370c01..74511639d47 100644 --- a/core/src/main/java/org/elasticsearch/gateway/ReplicaShardAllocator.java +++ b/core/src/main/java/org/elasticsearch/gateway/ReplicaShardAllocator.java @@ -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... - IndexMetaData indexMetaData = metaData.index(shard.getIndexName()); + IndexMetaData indexMetaData = metaData.getIndexSafe(shard.index()); if (shard.allocatedPostIndexCreate(indexMetaData) == false) { 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... - IndexMetaData indexMetaData = metaData.index(shard.getIndexName()); + IndexMetaData indexMetaData = metaData.getIndexSafe(shard.index()); if (shard.allocatedPostIndexCreate(indexMetaData) == false) { continue; } diff --git a/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java b/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java index 03f8dc81703..d1aa2a8b383 100644 --- a/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java +++ b/core/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java @@ -125,7 +125,7 @@ public class TransportNodesListGatewayStartedShards extends TransportNodesAction logger.trace("{} loading local shard state info", shardId); ShardStateMetaData shardStateMetaData = ShardStateMetaData.FORMAT.loadLatestState(logger, nodeEnv.availableShardPaths(request.shardId)); 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) { ShardPath shardPath = null; try { diff --git a/core/src/main/java/org/elasticsearch/index/Index.java b/core/src/main/java/org/elasticsearch/index/Index.java index 983b977d611..3ffe13e38b1 100644 --- a/core/src/main/java/org/elasticsearch/index/Index.java +++ b/core/src/main/java/org/elasticsearch/index/Index.java @@ -31,7 +31,7 @@ import java.io.IOException; */ public class Index implements Writeable { - private final static Index PROTO = new Index("", ""); + public static final Index[] EMPTY_ARRAY = new Index[0]; private final String name; private final String uuid; @@ -41,6 +41,12 @@ public class Index implements Writeable { this.uuid = uuid.intern(); } + public Index(StreamInput in) throws IOException { + this.name = in.readString(); + this.uuid = in.readString(); + } + + public String getName() { return this.name; } @@ -80,13 +86,9 @@ public class Index implements Writeable { return result; } - public static Index readIndex(StreamInput in) throws IOException { - return PROTO.readFrom(in); - } - @Override public Index readFrom(StreamInput in) throws IOException { - return new Index(in.readString(), in.readString()); + return new Index(in); } @Override diff --git a/core/src/main/java/org/elasticsearch/index/shard/ShardId.java b/core/src/main/java/org/elasticsearch/index/shard/ShardId.java index 3dea5501c62..a9bc63ae44f 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/ShardId.java +++ b/core/src/main/java/org/elasticsearch/index/shard/ShardId.java @@ -98,7 +98,7 @@ public class ShardId implements Streamable, Comparable { @Override public void readFrom(StreamInput in) throws IOException { - index = Index.readIndex(in); + index = new Index(in); shardId = in.readVInt(); hashCode = computeHashCode(); } diff --git a/core/src/main/java/org/elasticsearch/indices/NodeIndicesStats.java b/core/src/main/java/org/elasticsearch/indices/NodeIndicesStats.java index 7d24d4fa897..da8e617759d 100644 --- a/core/src/main/java/org/elasticsearch/indices/NodeIndicesStats.java +++ b/core/src/main/java/org/elasticsearch/indices/NodeIndicesStats.java @@ -172,7 +172,7 @@ public class NodeIndicesStats implements Streamable, ToXContent { int entries = in.readVInt(); statsByShard = new HashMap<>(); for (int i = 0; i < entries; i++) { - Index index = Index.readIndex(in); + Index index = new Index(in); int indexShardListSize = in.readVInt(); List indexShardStats = new ArrayList<>(indexShardListSize); for (int j = 0; j < indexShardListSize; j++) { diff --git a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java index af667f356e8..5d501b65686 100644 --- a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java +++ b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java @@ -188,15 +188,15 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent listener) { final ClusterState state = clusterService.state(); - final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, indicesOptions, aliasesOrIndices); + final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, indicesOptions, aliasesOrIndices); final Map> results = ConcurrentCollections.newConcurrentMap(); int totalNumberOfShards = 0; int numberOfShards = 0; - for (String index : concreteIndices) { - final IndexMetaData indexMetaData = state.metaData().index(index); + for (Index index : concreteIndices) { + final IndexMetaData indexMetaData = state.metaData().getIndexSafe(index); totalNumberOfShards += indexMetaData.getTotalNumberOfShards(); numberOfShards += indexMetaData.getNumberOfShards(); - results.put(index, Collections.synchronizedList(new ArrayList<>())); + results.put(index.getName(), Collections.synchronizedList(new ArrayList<>())); } if (numberOfShards == 0) { @@ -129,8 +130,9 @@ public class SyncedFlushService extends AbstractComponent implements IndexEventL final int finalTotalNumberOfShards = totalNumberOfShards; final CountDown countDown = new CountDown(numberOfShards); - for (final String index : concreteIndices) { - final IndexMetaData indexMetaData = state.metaData().index(index); + for (final Index concreteIndex : concreteIndices) { + final String index = concreteIndex.getName(); + final IndexMetaData indexMetaData = state.metaData().getIndexSafe(concreteIndex); final int indexNumberOfShards = indexMetaData.getNumberOfShards(); for (int shard = 0; shard < indexNumberOfShards; 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 IndexRoutingTable indexRoutingTable = state.routingTable().index(shardId.getIndexName()); 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) { throw new IndexClosedException(shardId.getIndex()); } diff --git a/core/src/main/java/org/elasticsearch/indices/store/IndicesStore.java b/core/src/main/java/org/elasticsearch/indices/store/IndicesStore.java index 6c09a608c2d..5dc8af41e80 100644 --- a/core/src/main/java/org/elasticsearch/indices/store/IndicesStore.java +++ b/core/src/main/java/org/elasticsearch/indices/store/IndicesStore.java @@ -26,6 +26,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateListener; import org.elasticsearch.cluster.ClusterStateObserver; import org.elasticsearch.cluster.ClusterStateUpdateTask; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; @@ -115,7 +116,13 @@ public class IndicesStore extends AbstractComponent implements ClusterStateListe if (shardCanBeDeleted(event.state(), indexShardRoutingTable)) { ShardId shardId = indexShardRoutingTable.shardId(); 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)) { deleteShardIfExistElseWhere(event.state(), indexShardRoutingTable); } @@ -164,7 +171,7 @@ public class IndicesStore extends AbstractComponent implements ClusterStateListe private void deleteShardIfExistElseWhere(ClusterState state, IndexShardRoutingTable indexShardRoutingTable) { List> requests = new ArrayList<>(indexShardRoutingTable.size()); - String indexUUID = state.getMetaData().index(indexShardRoutingTable.shardId().getIndex()).getIndexUUID(); + String indexUUID = indexShardRoutingTable.shardId().getIndex().getUUID(); ClusterName clusterName = state.getClusterName(); for (ShardRouting shardRouting : indexShardRoutingTable) { // Node can't be null, because otherwise shardCanBeDeleted() would have returned false diff --git a/core/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java b/core/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java index e009cbf04d1..0422c0944e2 100644 --- a/core/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java +++ b/core/src/main/java/org/elasticsearch/indices/store/TransportNodesListShardStoreMetaData.java @@ -134,7 +134,7 @@ public class TransportNodesListShardStoreMetaData extends TransportNodesAction(channel) { diff --git a/core/src/main/java/org/elasticsearch/rest/action/cat/RestShardsAction.java b/core/src/main/java/org/elasticsearch/rest/action/cat/RestShardsAction.java index 94a82e8e773..445f7099fef 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/cat/RestShardsAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/cat/RestShardsAction.java @@ -191,7 +191,7 @@ public class RestShardsAction extends AbstractCatAction { table.addCell(shard.getIndexName()); table.addCell(shard.id()); - IndexMetaData indexMeta = state.getState().getMetaData().index(shard.index()); + IndexMetaData indexMeta = state.getState().getMetaData().getIndexSafe(shard.index()); boolean usesShadowReplicas = false; if (indexMeta != null) { usesShadowReplicas = IndexMetaData.isIndexUsingShadowReplicas(indexMeta.getSettings()); diff --git a/core/src/main/java/org/elasticsearch/search/SearchService.java b/core/src/main/java/org/elasticsearch/search/SearchService.java index d7420d315d6..6cd59546d98 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchService.java +++ b/core/src/main/java/org/elasticsearch/search/SearchService.java @@ -195,7 +195,7 @@ public class SearchService extends AbstractLifecycleComponent imp public void afterIndexClosed(Index index, Settings indexSettings) { // 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. - 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) { // 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 diff --git a/core/src/main/java/org/elasticsearch/snapshots/RestoreService.java b/core/src/main/java/org/elasticsearch/snapshots/RestoreService.java index 65fb88d4b64..acbc15be72c 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/RestoreService.java +++ b/core/src/main/java/org/elasticsearch/snapshots/RestoreService.java @@ -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 * 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 indices) { + public static void checkIndexClosing(ClusterState currentState, Set indices) { RestoreInProgress restore = currentState.custom(RestoreInProgress.TYPE); if (restore != null) { - Set indicesToFail = null; + Set indicesToFail = null; for (RestoreInProgress.Entry entry : restore.entries()) { for (ObjectObjectCursor shard : entry.shards()) { 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) { indicesToFail = new HashSet<>(); } - indicesToFail.add(shard.key.getIndexName()); + indicesToFail.add(shard.key.getIndex()); } } } diff --git a/core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java b/core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java index 949befad059..fb878d6cb38 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java +++ b/core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java @@ -51,6 +51,7 @@ import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.snapshots.IndexShardRepository; import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus; @@ -204,7 +205,7 @@ public class SnapshotsService extends AbstractLifecycleComponent indices = Arrays.asList(indexNameExpressionResolver.concreteIndices(currentState, request.indicesOptions(), request.indices())); + List indices = Arrays.asList(indexNameExpressionResolver.concreteIndexNames(currentState, request.indicesOptions(), request.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); snapshots = new SnapshotsInProgress(newSnapshot); @@ -751,7 +752,7 @@ public class SnapshotsService extends AbstractLifecycleComponent closed = new HashSet<>(); for (ObjectObjectCursor entry : shards) { 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()); } else { missing.add(entry.key.getIndex().getName()); @@ -1065,8 +1066,8 @@ public class SnapshotsService extends AbstractLifecycleComponent indices) { - Set indicesToFail = indicesToFailForCloseOrDeletion(currentState, indices); + public static void checkIndexDeletion(ClusterState currentState, Set indices) { + Set indicesToFail = indicesToFailForCloseOrDeletion(currentState, indices); if (indicesToFail != null) { throw new IllegalArgumentException("Cannot delete indices that are being snapshotted: " + indicesToFail + ". Try again after snapshot finishes or cancel the currently running snapshot."); @@ -1077,37 +1078,39 @@ public class SnapshotsService extends AbstractLifecycleComponent indices) { - Set indicesToFail = indicesToFailForCloseOrDeletion(currentState, indices); + public static void checkIndexClosing(ClusterState currentState, Set indices) { + Set indicesToFail = indicesToFailForCloseOrDeletion(currentState, indices); if (indicesToFail != null) { throw new IllegalArgumentException("Cannot close indices that are being snapshotted: " + indicesToFail + ". Try again after snapshot finishes or cancel the currently running snapshot."); } } - private static Set indicesToFailForCloseOrDeletion(ClusterState currentState, Set indices) { + private static Set indicesToFailForCloseOrDeletion(ClusterState currentState, Set indices) { SnapshotsInProgress snapshots = currentState.custom(SnapshotsInProgress.TYPE); - Set indicesToFail = null; + Set indicesToFail = null; if (snapshots != null) { for (final SnapshotsInProgress.Entry entry : snapshots.entries()) { if (entry.partial() == false) { if (entry.state() == State.INIT) { for (String index : entry.indices()) { - if (indices.contains(index)) { + IndexMetaData indexMetaData = currentState.metaData().index(index); + if (indexMetaData != null && indices.contains(indexMetaData)) { if (indicesToFail == null) { indicesToFail = new HashSet<>(); } - indicesToFail.add(index); + indicesToFail.add(indexMetaData.getIndex()); } } } else { for (ObjectObjectCursor shard : entry.shards()) { 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) { indicesToFail = new HashSet<>(); } - indicesToFail.add(shard.key.getIndexName()); + indicesToFail.add(shard.key.getIndex()); } } } diff --git a/core/src/main/java/org/elasticsearch/tribe/TribeService.java b/core/src/main/java/org/elasticsearch/tribe/TribeService.java index bf7983e3c9d..5846b1d5b0f 100644 --- a/core/src/main/java/org/elasticsearch/tribe/TribeService.java +++ b/core/src/main/java/org/elasticsearch/tribe/TribeService.java @@ -405,9 +405,11 @@ public class TribeService extends AbstractLifecycleComponent { if (table == null) { 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 (!droppedIndices.contains(tribeIndex.getIndex().getName())) { + if (!droppedIndices.contains(indexName)) { // a new index, add it, and add the tribe name as a setting clusterStateChanged = true; logger.info("[{}] adding index {}", tribeName, tribeIndex.getIndex()); @@ -425,7 +427,7 @@ public class TribeService extends AbstractLifecycleComponent { logger.info("[{}] dropping index {} due to conflict with [{}]", tribeName, tribeIndex.getIndex(), existingFromTribe); removeIndex(blocks, metaData, routingTable, tribeIndex); - droppedIndices.add(tribeIndex.getIndex().getName()); + droppedIndices.add(indexName); } else if (onConflict.startsWith(ON_CONFLICT_PREFER)) { // on conflict, prefer a tribe... String preferredTribeName = onConflict.substring(ON_CONFLICT_PREFER.length()); diff --git a/core/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTookTests.java b/core/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTookTests.java index 6cd877315cd..d0a0e094dcb 100644 --- a/core/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTookTests.java +++ b/core/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTookTests.java @@ -191,7 +191,7 @@ public class TransportBulkActionTookTests extends ESTestCase { } @Override - public String[] concreteIndices(ClusterState state, IndicesRequest request) { + public String[] concreteIndexNames(ClusterState state, IndicesRequest request) { return request.indices(); } } diff --git a/core/src/test/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeActionTests.java b/core/src/test/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeActionTests.java index 2615e5a0b22..925d4a92901 100644 --- a/core/src/test/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeActionTests.java @@ -168,7 +168,7 @@ public class TransportBroadcastByNodeActionTests extends ESTestCase { } @Override - public String[] concreteIndices(ClusterState state, IndicesRequest request) { + public String[] concreteIndexNames(ClusterState state, IndicesRequest request) { return request.indices(); } } diff --git a/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java b/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java index 3fc33477746..631dad5d66d 100644 --- a/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java @@ -1065,8 +1065,8 @@ public class TransportReplicationActionTests extends ESTestCase { ClusterService clusterService, ThreadPool threadPool) { super(settings, actionName, transportService, clusterService, null, threadPool, - new ShardStateAction(settings, clusterService, transportService, null, null, threadPool), null, - new ActionFilters(new HashSet()), new IndexNameExpressionResolver(Settings.EMPTY), Request::new, Request::new, ThreadPool.Names.SAME); + new ShardStateAction(settings, clusterService, transportService, null, null, threadPool), + new ActionFilters(new HashSet()), new IndexNameExpressionResolver(Settings.EMPTY), Request::new, Request::new, ThreadPool.Names.SAME); } @Override diff --git a/core/src/test/java/org/elasticsearch/action/support/single/instance/TransportInstanceSingleOperationActionTests.java b/core/src/test/java/org/elasticsearch/action/support/single/instance/TransportInstanceSingleOperationActionTests.java index 462a44e08b4..1bf1188ef53 100644 --- a/core/src/test/java/org/elasticsearch/action/support/single/instance/TransportInstanceSingleOperationActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/support/single/instance/TransportInstanceSingleOperationActionTests.java @@ -123,7 +123,7 @@ public class TransportInstanceSingleOperationActionTests extends ESTestCase { } @Override - public String[] concreteIndices(ClusterState state, IndicesRequest request) { + public String[] concreteIndexNames(ClusterState state, IndicesRequest request) { return request.indices(); } } diff --git a/core/src/test/java/org/elasticsearch/cluster/health/ClusterStateHealthTests.java b/core/src/test/java/org/elasticsearch/cluster/health/ClusterStateHealthTests.java index 3562fa313ba..9c0f1014dcf 100644 --- a/core/src/test/java/org/elasticsearch/cluster/health/ClusterStateHealthTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/health/ClusterStateHealthTests.java @@ -64,7 +64,7 @@ public class ClusterStateHealthTests extends ESTestCase { routingTable.add(indexRoutingTable); } 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); logger.info("cluster status: {}, expected {}", clusterStateHealth.getStatus(), counter.status()); clusterStateHealth = maybeSerialize(clusterStateHealth); @@ -91,7 +91,7 @@ public class ClusterStateHealthTests extends ESTestCase { metaData.put(indexMetaData, true); routingTable.add(indexRoutingTable); 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 = maybeSerialize(clusterStateHealth); // currently we have no cluster level validation failures as index validation issues are reported per index. diff --git a/core/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java b/core/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java index 1c61292d87c..0e0c9fb442b 100644 --- a/core/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java @@ -61,79 +61,79 @@ public class IndexNameExpressionResolverTests extends ESTestCase { IndicesOptions[] indicesOptions = new IndicesOptions[]{ IndicesOptions.strictExpandOpen(), IndicesOptions.strictExpand()}; for (IndicesOptions options : indicesOptions) { 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("foo", results[0]); try { - indexNameExpressionResolver.concreteIndices(context, "bar"); + indexNameExpressionResolver.concreteIndexNames(context, "bar"); fail(); } catch (IndexNotFoundException e) { assertThat(e.getIndex().getName(), equalTo("bar")); } - results = indexNameExpressionResolver.concreteIndices(context, "foofoo", "foobar"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo", "foobar"); assertEquals(2, results.length); assertThat(results, arrayContainingInAnyOrder("foofoo", "foobar")); - results = indexNameExpressionResolver.concreteIndices(context, "foofoobar"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar"); assertEquals(new HashSet<>(Arrays.asList("foo", "foobar")), new HashSet<>(Arrays.asList(results))); try { - indexNameExpressionResolver.concreteIndices(context, "bar"); + indexNameExpressionResolver.concreteIndexNames(context, "bar"); fail(); } catch (IndexNotFoundException e) { assertThat(e.getIndex().getName(), equalTo("bar")); } try { - indexNameExpressionResolver.concreteIndices(context, "foo", "bar"); + indexNameExpressionResolver.concreteIndexNames(context, "foo", "bar"); fail(); } catch (IndexNotFoundException e) { assertThat(e.getIndex().getName(), equalTo("bar")); } - results = indexNameExpressionResolver.concreteIndices(context, "barbaz", "foobar"); + results = indexNameExpressionResolver.concreteIndexNames(context, "barbaz", "foobar"); assertEquals(2, results.length); assertThat(results, arrayContainingInAnyOrder("foofoo", "foobar")); try { - indexNameExpressionResolver.concreteIndices(context, "barbaz", "bar"); + indexNameExpressionResolver.concreteIndexNames(context, "barbaz", "bar"); fail(); } catch (IndexNotFoundException e) { assertThat(e.getIndex().getName(), equalTo("bar")); } - results = indexNameExpressionResolver.concreteIndices(context, "baz*"); + results = indexNameExpressionResolver.concreteIndexNames(context, "baz*"); assertThat(results, emptyArray()); - results = indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*"); assertEquals(1, results.length); assertEquals("foo", results[0]); } 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); - results = indexNameExpressionResolver.concreteIndices(context, (String[])null); + results = indexNameExpressionResolver.concreteIndexNames(context, (String[])null); assertEquals(3, results.length); 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); - results = indexNameExpressionResolver.concreteIndices(context, (String[])null); + results = indexNameExpressionResolver.concreteIndexNames(context, (String[])null); assertEquals(4, results.length); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen()); - results = indexNameExpressionResolver.concreteIndices(context, "foofoo*"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*"); assertEquals(3, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo")); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpand()); - results = indexNameExpressionResolver.concreteIndices(context, "foofoo*"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*"); assertEquals(4, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo", "foofoo-closed")); } @@ -150,57 +150,57 @@ public class IndexNameExpressionResolverTests extends ESTestCase { IndicesOptions[] indicesOptions = new IndicesOptions[]{ IndicesOptions.lenientExpandOpen(), lenientExpand}; for (IndicesOptions options : indicesOptions) { 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("foo", results[0]); - results = indexNameExpressionResolver.concreteIndices(context, "bar"); + results = indexNameExpressionResolver.concreteIndexNames(context, "bar"); assertThat(results, emptyArray()); - results = indexNameExpressionResolver.concreteIndices(context, "foofoo", "foobar"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo", "foobar"); assertEquals(2, results.length); assertThat(results, arrayContainingInAnyOrder("foofoo", "foobar")); - results = indexNameExpressionResolver.concreteIndices(context, "foofoobar"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar"); assertEquals(2, results.length); assertEquals(new HashSet<>(Arrays.asList("foo", "foobar")), new HashSet<>(Arrays.asList(results))); - results = indexNameExpressionResolver.concreteIndices(context, "foo", "bar"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "bar"); assertEquals(1, results.length); assertThat(results, arrayContainingInAnyOrder("foo")); - results = indexNameExpressionResolver.concreteIndices(context, "barbaz", "foobar"); + results = indexNameExpressionResolver.concreteIndexNames(context, "barbaz", "foobar"); assertEquals(2, results.length); assertThat(results, arrayContainingInAnyOrder("foofoo", "foobar")); - results = indexNameExpressionResolver.concreteIndices(context, "barbaz", "bar"); + results = indexNameExpressionResolver.concreteIndexNames(context, "barbaz", "bar"); assertEquals(1, results.length); assertThat(results, arrayContainingInAnyOrder("foofoo")); - results = indexNameExpressionResolver.concreteIndices(context, "baz*"); + results = indexNameExpressionResolver.concreteIndexNames(context, "baz*"); assertThat(results, emptyArray()); - results = indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*"); assertEquals(1, results.length); assertEquals("foo", results[0]); } 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); 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); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen()); - results = indexNameExpressionResolver.concreteIndices(context, "foofoo*"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*"); assertEquals(3, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo")); context = new IndexNameExpressionResolver.Context(state, lenientExpand); - results = indexNameExpressionResolver.concreteIndices(context, "foofoo*"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*"); assertEquals(4, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo", "foofoo-closed")); } @@ -219,26 +219,26 @@ public class IndexNameExpressionResolverTests extends ESTestCase { for (IndicesOptions options : indicesOptions) { 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("foo", results[0]); try { - indexNameExpressionResolver.concreteIndices(context, "bar"); + indexNameExpressionResolver.concreteIndexNames(context, "bar"); fail(); } catch(IndexNotFoundException e) { assertThat(e.getIndex().getName(), equalTo("bar")); } try { - indexNameExpressionResolver.concreteIndices(context, "baz*"); + indexNameExpressionResolver.concreteIndexNames(context, "baz*"); fail(); } catch (IndexNotFoundException e) { assertThat(e.getIndex().getName(), equalTo("baz*")); } try { - indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); + indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*"); fail(); } catch (IndexNotFoundException e) { assertThat(e.getIndex().getName(), equalTo("baz*")); @@ -246,11 +246,11 @@ public class IndexNameExpressionResolverTests extends ESTestCase { } 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); context = new IndexNameExpressionResolver.Context(state, expand); - results = indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); + results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(4, results.length); } @@ -264,60 +264,60 @@ public class IndexNameExpressionResolverTests extends ESTestCase { // Only closed IndicesOptions options = IndicesOptions.fromOptions(false, true, false, true); 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("foo", results[0]); - results = indexNameExpressionResolver.concreteIndices(context, "foo*"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foo*"); assertEquals(1, results.length); assertEquals("foo", results[0]); // no wildcards, so wildcard expansion don't apply - results = indexNameExpressionResolver.concreteIndices(context, "bar"); + results = indexNameExpressionResolver.concreteIndexNames(context, "bar"); assertEquals(1, results.length); assertEquals("bar", results[0]); // Only open options = IndicesOptions.fromOptions(false, true, true, false); context = new IndexNameExpressionResolver.Context(state, options); - results = indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); + results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(2, results.length); assertThat(results, arrayContainingInAnyOrder("bar", "foobar")); - results = indexNameExpressionResolver.concreteIndices(context, "foo*"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foo*"); assertEquals(1, results.length); assertEquals("foobar", results[0]); - results = indexNameExpressionResolver.concreteIndices(context, "bar"); + results = indexNameExpressionResolver.concreteIndexNames(context, "bar"); assertEquals(1, results.length); assertEquals("bar", results[0]); // Open and closed options = IndicesOptions.fromOptions(false, true, true, true); context = new IndexNameExpressionResolver.Context(state, options); - results = indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); + results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(3, results.length); assertThat(results, arrayContainingInAnyOrder("bar", "foobar", "foo")); - results = indexNameExpressionResolver.concreteIndices(context, "foo*"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foo*"); assertEquals(2, results.length); assertThat(results, arrayContainingInAnyOrder("foobar", "foo")); - results = indexNameExpressionResolver.concreteIndices(context, "bar"); + results = indexNameExpressionResolver.concreteIndexNames(context, "bar"); assertEquals(1, results.length); assertEquals("bar", results[0]); - results = indexNameExpressionResolver.concreteIndices(context, "-foo*"); + results = indexNameExpressionResolver.concreteIndexNames(context, "-foo*"); assertEquals(1, results.length); assertEquals("bar", results[0]); - results = indexNameExpressionResolver.concreteIndices(context, "-*"); + results = indexNameExpressionResolver.concreteIndexNames(context, "-*"); assertEquals(0, results.length); options = IndicesOptions.fromOptions(false, false, true, true); context = new IndexNameExpressionResolver.Context(state, options); try { - indexNameExpressionResolver.concreteIndices(context, "-*"); + indexNameExpressionResolver.concreteIndexNames(context, "-*"); fail(); } catch (IndexNotFoundException e) { assertThat(e.getResourceId().toString(), equalTo("[-*]")); @@ -336,21 +336,21 @@ public class IndexNameExpressionResolverTests extends ESTestCase { { IndicesOptions noExpandLenient = IndicesOptions.fromOptions(true, true, false, false); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandLenient); - String[] results = indexNameExpressionResolver.concreteIndices(context, "baz*"); + String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*"); assertThat(results, emptyArray()); - results = indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*"); assertEquals(1, results.length); assertEquals("foo", results[0]); - results = indexNameExpressionResolver.concreteIndices(context, "foofoobar"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar"); assertEquals(2, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foobar")); - results = indexNameExpressionResolver.concreteIndices(context, (String[])null); + results = indexNameExpressionResolver.concreteIndexNames(context, (String[])null); assertEquals(0, results.length); - results = indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); + results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(0, results.length); } @@ -359,17 +359,17 @@ public class IndexNameExpressionResolverTests extends ESTestCase { IndicesOptions noExpandDisallowEmpty = IndicesOptions.fromOptions(true, false, false, false); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandDisallowEmpty); try { - indexNameExpressionResolver.concreteIndices(context, "baz*"); + indexNameExpressionResolver.concreteIndexNames(context, "baz*"); fail(); } catch (IndexNotFoundException e) { 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("foo", results[0]); - results = indexNameExpressionResolver.concreteIndices(context, "foofoobar"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar"); assertEquals(2, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foobar")); } @@ -378,17 +378,17 @@ public class IndexNameExpressionResolverTests extends ESTestCase { { IndicesOptions noExpandErrorUnavailable = IndicesOptions.fromOptions(false, true, false, false); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandErrorUnavailable); - String[] results = indexNameExpressionResolver.concreteIndices(context, "baz*"); + String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*"); assertThat(results, emptyArray()); try { - indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); + indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*"); fail(); } catch (IndexNotFoundException e) { assertThat(e.getIndex().getName(), equalTo("baz*")); } - results = indexNameExpressionResolver.concreteIndices(context, "foofoobar"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar"); assertEquals(2, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foobar")); } @@ -398,20 +398,20 @@ public class IndexNameExpressionResolverTests extends ESTestCase { IndicesOptions noExpandStrict = IndicesOptions.fromOptions(false, false, false, false); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandStrict); try { - indexNameExpressionResolver.concreteIndices(context, "baz*"); + indexNameExpressionResolver.concreteIndexNames(context, "baz*"); fail(); } catch (IndexNotFoundException e) { assertThat(e.getIndex().getName(), equalTo("baz*")); } try { - indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); + indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*"); fail(); } catch (IndexNotFoundException e) { assertThat(e.getIndex().getName(), equalTo("baz*")); } - String[] results = indexNameExpressionResolver.concreteIndices(context, "foofoobar"); + String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar"); assertEquals(2, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foobar")); } @@ -429,7 +429,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase { try { IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed()); - indexNameExpressionResolver.concreteIndices(context, "baz*"); + indexNameExpressionResolver.concreteIndexNames(context, "baz*"); fail(); } catch (IndexNotFoundException e) { assertThat(e.getIndex().getName(), equalTo("baz*")); @@ -437,7 +437,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase { try { IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed()); - indexNameExpressionResolver.concreteIndices(context, "foo", "baz*"); + indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*"); fail(); } catch (IndexNotFoundException e) { assertThat(e.getIndex().getName(), equalTo("baz*")); @@ -445,7 +445,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase { try { IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed()); - indexNameExpressionResolver.concreteIndices(context, "foofoobar"); + indexNameExpressionResolver.concreteIndexNames(context, "foofoobar"); fail(); } catch(IllegalArgumentException e) { assertThat(e.getMessage(), containsString("Alias [foofoobar] has more than one indices associated with it")); @@ -453,7 +453,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase { try { IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed()); - indexNameExpressionResolver.concreteIndices(context, "foo", "foofoobar"); + indexNameExpressionResolver.concreteIndexNames(context, "foo", "foofoobar"); fail(); } catch(IllegalArgumentException e) { assertThat(e.getMessage(), containsString("Alias [foofoobar] has more than one indices associated with it")); @@ -461,7 +461,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase { try { IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed()); - indexNameExpressionResolver.concreteIndices(context, "foofoo-closed", "foofoobar"); + indexNameExpressionResolver.concreteIndexNames(context, "foofoo-closed", "foofoobar"); fail(); } catch(IndexClosedException e) { assertThat(e.getMessage(), equalTo("closed")); @@ -469,7 +469,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase { } 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); assertThat(results, arrayContainingInAnyOrder("foo", "foofoo")); } @@ -479,18 +479,18 @@ public class IndexNameExpressionResolverTests extends ESTestCase { IndicesOptions options = IndicesOptions.strictExpandOpen(); 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()); try { - indexNameExpressionResolver.concreteIndices(context, "foo"); + indexNameExpressionResolver.concreteIndexNames(context, "foo"); fail(); } catch (IndexNotFoundException e) { assertThat(e.getIndex().getName(), equalTo("foo")); } - results = indexNameExpressionResolver.concreteIndices(context, "foo*"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foo*"); assertThat(results, emptyArray()); try { - indexNameExpressionResolver.concreteIndices(context, "foo*", "bar"); + indexNameExpressionResolver.concreteIndexNames(context, "foo*", "bar"); fail(); } catch (IndexNotFoundException e) { assertThat(e.getIndex().getName(), equalTo("bar")); @@ -498,18 +498,18 @@ public class IndexNameExpressionResolverTests extends ESTestCase { context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen()); - results = indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); + results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertThat(results, emptyArray()); - results = indexNameExpressionResolver.concreteIndices(context, "foo"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foo"); assertThat(results, emptyArray()); - results = indexNameExpressionResolver.concreteIndices(context, "foo*"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foo*"); assertThat(results, emptyArray()); - results = indexNameExpressionResolver.concreteIndices(context, "foo*", "bar"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foo*", "bar"); assertThat(results, emptyArray()); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, false, true, false)); try { - indexNameExpressionResolver.concreteIndices(context, Strings.EMPTY_ARRAY); + indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); } catch (IndexNotFoundException e) { assertThat(e.getResourceId().toString(), equalTo("[_all]")); } @@ -527,7 +527,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase { IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen()); try { - indexNameExpressionResolver.concreteIndices(context, "testZZZ"); + indexNameExpressionResolver.concreteIndexNames(context, "testZZZ"); fail("Expected IndexNotFoundException"); } catch(IndexNotFoundException e) { 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(); 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() { @@ -552,7 +552,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase { IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen()); try { - indexNameExpressionResolver.concreteIndices(context, "testMo", "testMahdy"); + indexNameExpressionResolver.concreteIndexNames(context, "testMo", "testMahdy"); fail("Expected IndexNotFoundException"); } catch(IndexNotFoundException e) { assertThat(e.getMessage(), is("no such index")); @@ -565,7 +565,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase { .put(indexBuilder("kuku")); ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build(); 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() { @@ -578,13 +578,13 @@ public class IndexNameExpressionResolverTests extends ESTestCase { ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build(); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, false)); - assertThat(newHashSet(indexNameExpressionResolver.concreteIndices(context, "testX*")), equalTo(new HashSet())); + assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testX*")), equalTo(new HashSet())); 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)); - 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)); - 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 if (indicesOptions.allowNoIndices()) { - String[] concreteIndices = indexNameExpressionResolver.concreteIndices(context, allIndices); + String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(context, allIndices); assertThat(concreteIndices, notNullValue()); assertThat(concreteIndices.length, equalTo(0)); } else { @@ -625,7 +625,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase { state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build(); context = new IndexNameExpressionResolver.Context(state, indicesOptions); if (indicesOptions.expandWildcardsOpen() || indicesOptions.expandWildcardsClosed() || indicesOptions.allowNoIndices()) { - String[] concreteIndices = indexNameExpressionResolver.concreteIndices(context, allIndices); + String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(context, allIndices); assertThat(concreteIndices, notNullValue()); int expectedNumberOfIndices = 0; if (indicesOptions.expandWildcardsOpen()) { @@ -646,7 +646,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase { */ private void checkCorrectException(IndexNameExpressionResolver indexNameExpressionResolver, IndexNameExpressionResolver.Context context, String[] allIndices) { try { - indexNameExpressionResolver.concreteIndices(context, allIndices); + indexNameExpressionResolver.concreteIndexNames(context, allIndices); fail("wildcard expansion on should trigger IndexMissingException"); } catch (IndexNotFoundException e) { // expected @@ -668,12 +668,12 @@ public class IndexNameExpressionResolverTests extends ESTestCase { // asking for non existing wildcard pattern should return empty list or exception if (indicesOptions.allowNoIndices()) { - String[] concreteIndices = indexNameExpressionResolver.concreteIndices(context, "Foo*"); + String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(context, "Foo*"); assertThat(concreteIndices, notNullValue()); assertThat(concreteIndices.length, equalTo(0)); } else { try { - indexNameExpressionResolver.concreteIndices(context, "Foo*"); + indexNameExpressionResolver.concreteIndexNames(context, "Foo*"); fail("expecting exception when result empty and allowNoIndicec=false"); } catch (IndexNotFoundException e) { // expected exception @@ -798,51 +798,51 @@ public class IndexNameExpressionResolverTests extends ESTestCase { IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpenAndForbidClosed()); try { - indexNameExpressionResolver.concreteIndices(context, "foo1-closed"); + indexNameExpressionResolver.concreteIndexNames(context, "foo1-closed"); fail("foo1-closed should be closed, but it is open"); } catch (IndexClosedException e) { // expected } try { - indexNameExpressionResolver.concreteIndices(context, "foobar1-closed"); + indexNameExpressionResolver.concreteIndexNames(context, "foobar1-closed"); fail("foo1-closed should be closed, but it is open"); } catch (IndexClosedException e) { // expected } 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()); - results = indexNameExpressionResolver.concreteIndices(context, "foobar1-closed"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foobar1-closed"); assertThat(results, emptyArray()); 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, arrayContaining("foo1-closed")); - results = indexNameExpressionResolver.concreteIndices(context, "foobar1-closed"); + results = indexNameExpressionResolver.concreteIndexNames(context, "foobar1-closed"); assertThat(results, arrayWithSize(1)); assertThat(results, arrayContaining("foo1-closed")); // testing an alias pointing to three indices: context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpenAndForbidClosed()); try { - indexNameExpressionResolver.concreteIndices(context, "foobar2-closed"); + indexNameExpressionResolver.concreteIndexNames(context, "foobar2-closed"); fail("foo2-closed should be closed, but it is open"); } catch (IndexClosedException e) { // expected } 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, arrayContaining("foo3")); 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, arrayContainingInAnyOrder("foo1-closed", "foo2-closed", "foo3")); } @@ -855,7 +855,7 @@ public class IndexNameExpressionResolverTests extends ESTestCase { IndicesOptions.lenientExpandOpen(), IndicesOptions.strictExpandOpenAndForbidClosed()}; for (IndicesOptions options : indicesOptions) { 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"})); } } @@ -875,11 +875,11 @@ public class IndexNameExpressionResolverTests extends ESTestCase { ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build(); 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); context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen()); - strings = indexNameExpressionResolver.concreteIndices(context, "alias-*"); + strings = indexNameExpressionResolver.concreteIndexNames(context, "alias-*"); assertArrayEquals(new String[] {"test-0"}, strings); } diff --git a/core/src/test/java/org/elasticsearch/gateway/GatewayMetaStateTests.java b/core/src/test/java/org/elasticsearch/gateway/GatewayMetaStateTests.java index 422aea70134..4be0cf15afc 100644 --- a/core/src/test/java/org/elasticsearch/gateway/GatewayMetaStateTests.java +++ b/core/src/test/java/org/elasticsearch/gateway/GatewayMetaStateTests.java @@ -28,6 +28,7 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider; +import org.elasticsearch.index.Index; import org.elasticsearch.test.ESAllocationTestCase; import java.util.HashMap; @@ -172,12 +173,12 @@ public class GatewayMetaStateTests extends ESAllocationTestCase { boolean stateInMemory, boolean expectMetaData) throws Exception { MetaData inMemoryMetaData = null; - Set oldIndicesList = emptySet(); + Set oldIndicesList = emptySet(); if (stateInMemory) { inMemoryMetaData = event.previousState().metaData(); oldIndicesList = GatewayMetaState.getRelevantIndices(event.previousState(), event.previousState(), oldIndicesList); } - Set newIndicesList = GatewayMetaState.getRelevantIndices(event.state(),event.previousState(), oldIndicesList); + Set newIndicesList = GatewayMetaState.getRelevantIndices(event.state(),event.previousState(), oldIndicesList); // third, get the actual write info Iterator indices = GatewayMetaState.resolveStatesToBeWritten(oldIndicesList, newIndicesList, inMemoryMetaData, event.state().metaData()).iterator(); diff --git a/core/src/test/java/org/elasticsearch/gateway/PriorityComparatorTests.java b/core/src/test/java/org/elasticsearch/gateway/PriorityComparatorTests.java index 6da00d822a2..bb5a6ff748e 100644 --- a/core/src/test/java/org/elasticsearch/gateway/PriorityComparatorTests.java +++ b/core/src/test/java/org/elasticsearch/gateway/PriorityComparatorTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.cluster.routing.TestShardRouting; import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.Index; import org.elasticsearch.test.ESTestCase; import java.util.Arrays; @@ -37,7 +38,7 @@ import java.util.Map; public class PriorityComparatorTests extends ESTestCase { public void testPreferNewIndices() { - RoutingNodes.UnassignedShards shards = new RoutingNodes.UnassignedShards((RoutingNodes) null); + RoutingNodes.UnassignedShards shards = new RoutingNodes.UnassignedShards(null); List 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"))); @@ -47,11 +48,11 @@ public class PriorityComparatorTests extends ESTestCase { } shards.sort(new PriorityComparator() { @Override - protected Settings getIndexSettings(String index) { - if ("oldest".equals(index)) { + protected Settings getIndexSettings(Index index) { + if ("oldest".equals(index.getName())) { return Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 10) .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) .put(IndexMetaData.SETTING_PRIORITY, 1).build(); } @@ -77,11 +78,11 @@ public class PriorityComparatorTests extends ESTestCase { } shards.sort(new PriorityComparator() { @Override - protected Settings getIndexSettings(String index) { - if ("oldest".equals(index)) { + protected Settings getIndexSettings(Index index) { + if ("oldest".equals(index.getName())) { return Settings.builder().put(IndexMetaData.SETTING_CREATION_DATE, 10) .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) .put(IndexMetaData.SETTING_PRIORITY, 1).build(); } @@ -118,8 +119,8 @@ public class PriorityComparatorTests extends ESTestCase { } shards.sort(new PriorityComparator() { @Override - protected Settings getIndexSettings(String index) { - IndexMeta indexMeta = map.get(index); + protected Settings getIndexSettings(Index index) { + IndexMeta indexMeta = map.get(index.getName()); return indexMeta.settings; } }); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/timestamp/TimestampMappingTests.java b/core/src/test/java/org/elasticsearch/index/mapper/timestamp/TimestampMappingTests.java index d5efd6dcfc3..0a8d75d42f0 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/timestamp/TimestampMappingTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/timestamp/TimestampMappingTests.java @@ -182,7 +182,7 @@ public class TimestampMappingTests extends ESSingleNodeTestCase { IndexRequest request = new IndexRequest("test", "type", "1").source(doc); request.process(metaData, mappingMetaData, true, "test"); 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] diff --git a/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java b/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java index aaac9c0cca4..234311984b9 100644 --- a/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java @@ -65,6 +65,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitC import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.Matchers.startsWith; public class IndicesOptionsIntegrationIT extends ESIntegTestCase { @@ -685,7 +686,7 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase { try { verify(client().admin().indices().prepareUpdateSettings("barbaz").setSettings(Settings.builder().put("e", "f")), false); } 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); } diff --git a/core/src/test/java/org/elasticsearch/indices/settings/UpdateSettingsIT.java b/core/src/test/java/org/elasticsearch/indices/settings/UpdateSettingsIT.java index d85849570cf..642d646fe9e 100644 --- a/core/src/test/java/org/elasticsearch/indices/settings/UpdateSettingsIT.java +++ b/core/src/test/java/org/elasticsearch/indices/settings/UpdateSettingsIT.java @@ -137,7 +137,8 @@ public class UpdateSettingsIT extends ESIntegTestCase { .execute().actionGet(); fail("can't change number of replicas on a closed index"); } 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 } client().admin().indices().prepareUpdateSettings("test") diff --git a/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java b/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java index 5dc6d59692b..5a8d1daf588 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java +++ b/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java @@ -1880,7 +1880,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas client.admin().indices().prepareDelete("test-idx-1").get(); fail("Expected deleting index to fail during snapshot"); } 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 { try { @@ -1888,7 +1888,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas client.admin().indices().prepareClose("test-idx-1").get(); fail("Expected closing index to fail during snapshot"); } 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(); fail("Expected closing index to fail during restore"); } 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 { + // 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"); unblockAllDataNodes("test-repo"); } diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/IndicesRequestTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/IndicesRequestTests.java index 60b9460bb12..80274807b3b 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/IndicesRequestTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/IndicesRequestTests.java @@ -370,7 +370,7 @@ public class IndicesRequestTests extends ESIntegTestCase { internalCluster().clientNodeClient().admin().indices().flush(flushRequest).actionGet(); 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); } @@ -393,7 +393,7 @@ public class IndicesRequestTests extends ESIntegTestCase { internalCluster().clientNodeClient().admin().indices().refresh(refreshRequest).actionGet(); 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); } diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/TransportReindexAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/TransportReindexAction.java index dbe464e98b4..87fa15cd9ac 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/TransportReindexAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/TransportReindexAction.java @@ -96,9 +96,9 @@ public class TransportReindexAction extends HandledTransportAction Date: Mon, 14 Mar 2016 12:24:58 +0100 Subject: [PATCH 4/7] Updated link to Joda time zones --- .../aggregations/bucket/daterange-aggregation.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc b/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc index e649928810b..a69b2b3cb11 100644 --- a/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc @@ -118,7 +118,7 @@ Any characters in the pattern that are not in the ranges of ['a'..'z'] and ['A'. Dates can be converted from another time zone to UTC by specifying the `time_zone` parameter. Time zones may either be specified as an ISO 8601 UTC offset (e.g. +01:00 or -08:00) or as one of -the the http://joda-time.sourceforge.net/timezones.html[time zone ids] from the TZ database. +the http://www.joda.org/joda-time/timezones.html[time zone ids] from the TZ database. The `time_zone` parameter is also applied to rounding in date math expressions. As an example, to round to the beginning of the day in the CET time zone, you can do the following: From 9f382da5d3fc5ad3b44819dfdb0d712965919e49 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 14 Mar 2016 14:27:35 +0100 Subject: [PATCH 5/7] Add better validation error message and a dedicated test --- .../action/admin/indices/mapping/put/PutMappingRequest.java | 2 +- .../admin/indices/mapping/put/PutMappingRequestTests.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java index 9444e322a68..9e33103b371 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java @@ -94,7 +94,7 @@ public class PutMappingRequest extends AcknowledgedRequest im 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); + validationException = addValidationError("either concreteIndices or unresolved indices can be set concrete: [" + concreteIndex + "] and indices: " + indices , validationException); } return validationException; } diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java index 967a9026469..65b9ff0dd22 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.action.admin.indices.mapping.put; import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.index.Index; import org.elasticsearch.test.ESTestCase; public class PutMappingRequestTests extends ESTestCase { @@ -48,5 +49,10 @@ public class PutMappingRequestTests extends ESTestCase { r.source("somevalidmapping"); ex = r.validate(); assertNull("validation should succeed", ex); + + r.setConcreteIndex(new Index("foo", "bar")); + ex = r.validate(); + assertNotNull("source validation should fail", ex); + assertTrue(ex.getMessage().contains("either concreteIndices or unresolved indices can be set")); } } From 0ebcef0bb47154cf5582c9722490ea43d1d3345a Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 14 Mar 2016 14:51:43 +0100 Subject: [PATCH 6/7] wrap line after 140 chars --- .../action/admin/indices/mapping/put/PutMappingRequest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java index 9e33103b371..17fdd6e5f00 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java @@ -94,7 +94,8 @@ public class PutMappingRequest extends AcknowledgedRequest im 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 concrete: [" + concreteIndex + "] and indices: " + indices , validationException); + validationException = addValidationError("either concreteIndices or unresolved indices can be set concrete: [" + concreteIndex + + "] and indices: " + indices , validationException); } return validationException; } From e4bed0c97e7e0acb293624f9601027f8be38c874 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 14 Mar 2016 14:57:43 +0100 Subject: [PATCH 7/7] Improve validation error message on PutMappingRequest --- .../action/admin/indices/mapping/put/PutMappingRequest.java | 5 +++-- .../admin/indices/mapping/put/PutMappingRequestTests.java | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java index 17fdd6e5f00..7b389dba25a 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequest.java @@ -35,6 +35,7 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.Index; import java.io.IOException; +import java.util.Arrays; import java.util.Map; import java.util.Objects; @@ -94,8 +95,8 @@ public class PutMappingRequest extends AcknowledgedRequest im 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 concrete: [" + concreteIndex - + "] and indices: " + indices , validationException); + validationException = addValidationError("either concrete index or unresolved indices can be set, concrete index: [" + + concreteIndex + "] and indices: " + Arrays.asList(indices) , validationException); } return validationException; } diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java index 65b9ff0dd22..04892b82339 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java @@ -53,6 +53,8 @@ public class PutMappingRequestTests extends ESTestCase { r.setConcreteIndex(new Index("foo", "bar")); ex = r.validate(); assertNotNull("source validation should fail", ex); - assertTrue(ex.getMessage().contains("either concreteIndices or unresolved indices can be set")); + assertEquals(ex.getMessage(), + "Validation Failed: 1: either concrete index or unresolved indices can be set," + + " concrete index: [[foo/bar]] and indices: [myindex];"); } }