From fd574880fcf7cd7a14e25087029a47a7ae3aca1b Mon Sep 17 00:00:00 2001 From: kimchy Date: Thu, 1 Apr 2010 12:25:51 +0300 Subject: [PATCH] Clear Indices Cache API: Allow to clear indices cache, closes #101 --- .../action/TransportActionModule.java | 2 + .../action/TransportActions.java | 4 + .../cache/clear/ClearIndicesCacheRequest.java | 82 ++++++++++++ .../clear/ClearIndicesCacheResponse.java | 52 ++++++++ .../clear/ShardClearIndicesCacheRequest.java | 61 +++++++++ .../clear/ShardClearIndicesCacheResponse.java | 47 +++++++ .../TransportClearIndicesCacheAction.java | 117 ++++++++++++++++++ .../broadcast/BroadcastOperationRequest.java | 1 + .../client/IndicesAdminClient.java | 22 +++- .../org/elasticsearch/client/Requests.java | 13 +- .../server/ServerIndicesAdminClient.java | 18 ++- .../action/ClientTransportActionModule.java | 2 + ...lientTransportClearIndicesCacheAction.java | 42 +++++++ .../InternalTransportIndicesAdminClient.java | 27 +++- .../elasticsearch/index/cache/IndexCache.java | 51 ++++++++ .../index/cache/IndexCacheModule.java | 42 +++++++ .../index/cache/filter/FilterCache.java | 2 + .../cache/filter/none/NoneFilterCache.java | 4 + .../AbstractConcurrentMapFilterCache.java | 4 + .../index/query/IndexQueryParserService.java | 10 +- .../query/json/FieldJsonQueryParser.java | 2 +- .../query/json/JsonIndexQueryParser.java | 10 +- .../query/json/JsonQueryParseContext.java | 17 ++- .../MoreLikeThisFieldJsonQueryParser.java | 2 +- .../query/json/PrefixJsonFilterParser.java | 2 +- .../query/json/PrefixJsonQueryParser.java | 2 +- .../json/QueryStringJsonQueryParser.java | 6 +- .../query/json/RangeJsonFilterParser.java | 2 +- .../query/json/RangeJsonQueryParser.java | 2 +- .../query/json/SpanTermJsonQueryParser.java | 2 +- .../query/json/TermJsonFilterParser.java | 2 +- .../index/query/json/TermJsonQueryParser.java | 2 +- .../query/json/TermsJsonFilterParser.java | 2 +- .../query/json/WildcardJsonQueryParser.java | 2 +- .../query/support/MapperQueryParser.java | 18 +-- .../support/MultiFieldMapperQueryParser.java | 6 +- .../index/query/support/QueryParsers.java | 18 +-- .../index/service/IndexService.java | 4 +- .../index/service/InternalIndexService.java | 12 +- .../shard/service/InternalIndexShard.java | 12 +- .../indices/InternalIndicesService.java | 4 +- .../rest/action/RestActionModule.java | 2 + .../clear/RestClearIndicesCacheAction.java | 98 +++++++++++++++ .../search/internal/SearchContext.java | 2 +- .../json/SimpleJsonIndexQueryParserTests.java | 4 +- .../index/shard/SimpleIndexShardTests.java | 9 +- .../aliases/IndexAliasesTests.java | 4 +- .../document/DocumentActionsTests.java | 6 + 48 files changed, 770 insertions(+), 87 deletions(-) create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequest.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheResponse.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ShardClearIndicesCacheRequest.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ShardClearIndicesCacheResponse.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/cache/clear/ClientTransportClearIndicesCacheAction.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/IndexCache.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/IndexCacheModule.java create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/cache/clear/RestClearIndicesCacheAction.java diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActionModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActionModule.java index 494802c2d11..4d2cfe02f54 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActionModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActionModule.java @@ -30,6 +30,7 @@ import org.elasticsearch.action.admin.cluster.ping.replication.TransportShardRep import org.elasticsearch.action.admin.cluster.ping.single.TransportSinglePingAction; import org.elasticsearch.action.admin.cluster.state.TransportClusterStateAction; import org.elasticsearch.action.admin.indices.alias.TransportIndicesAliasesAction; +import org.elasticsearch.action.admin.indices.cache.clear.TransportClearIndicesCacheAction; import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction; import org.elasticsearch.action.admin.indices.delete.TransportDeleteIndexAction; import org.elasticsearch.action.admin.indices.flush.TransportFlushAction; @@ -84,6 +85,7 @@ public class TransportActionModule extends AbstractModule { bind(TransportRefreshAction.class).asEagerSingleton(); bind(TransportFlushAction.class).asEagerSingleton(); bind(TransportOptimizeAction.class).asEagerSingleton(); + bind(TransportClearIndicesCacheAction.class).asEagerSingleton(); bind(TransportIndexAction.class).asEagerSingleton(); bind(TransportGetAction.class).asEagerSingleton(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActions.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActions.java index 3594a844648..dd1f71c3787 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActions.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActions.java @@ -60,6 +60,10 @@ public class TransportActions { public static class Mapping { public static final String PUT = "indices/mapping/put"; } + + public static class Cache { + public static final String CLEAR = "indices/cache/clear"; + } } public static class Cluster { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequest.java new file mode 100644 index 00000000000..ddc4ac58a26 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheRequest.java @@ -0,0 +1,82 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.action.admin.indices.cache.clear; + +import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest; +import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; +import org.elasticsearch.util.io.stream.StreamInput; +import org.elasticsearch.util.io.stream.StreamOutput; + +import java.io.IOException; + +/** + * @author kimchy (shay.banon) + */ +public class ClearIndicesCacheRequest extends BroadcastOperationRequest { + + private boolean filterCache = true; + + ClearIndicesCacheRequest() { + } + + public ClearIndicesCacheRequest(String... indices) { + super(indices, null); + // we want to do the refresh in parallel on local shards... + operationThreading(BroadcastOperationThreading.THREAD_PER_SHARD); + } + + /** + * Should the listener be called on a separate thread if needed. + */ + @Override public ClearIndicesCacheRequest listenerThreaded(boolean threadedListener) { + super.listenerThreaded(threadedListener); + return this; + } + + /** + * Controls the operation threading model. + */ + @Override public ClearIndicesCacheRequest operationThreading(BroadcastOperationThreading operationThreading) { + super.operationThreading(operationThreading); + return this; + } + + public boolean filterCache() { + return filterCache; + } + + /** + * Should the filter cache be cleared or not. Defaults to true. + */ + public ClearIndicesCacheRequest filterCache(boolean filterCache) { + this.filterCache = filterCache; + return this; + } + + public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); + filterCache = in.readBoolean(); + } + + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeBoolean(filterCache); + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheResponse.java new file mode 100644 index 00000000000..06acdd2018a --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheResponse.java @@ -0,0 +1,52 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.action.admin.indices.cache.clear; + +import org.elasticsearch.action.ShardOperationFailedException; +import org.elasticsearch.action.support.broadcast.BroadcastOperationResponse; +import org.elasticsearch.util.io.stream.StreamInput; +import org.elasticsearch.util.io.stream.StreamOutput; + +import java.io.IOException; +import java.util.List; + +/** + * The response of a refresh action. + * + * @author kimchy (shay.banon) + */ +public class ClearIndicesCacheResponse extends BroadcastOperationResponse { + + ClearIndicesCacheResponse() { + + } + + ClearIndicesCacheResponse(int successfulShards, int failedShards, List shardFailures) { + super(successfulShards, failedShards, shardFailures); + } + + @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); + } + + @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ShardClearIndicesCacheRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ShardClearIndicesCacheRequest.java new file mode 100644 index 00000000000..3d75b2bfb8b --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ShardClearIndicesCacheRequest.java @@ -0,0 +1,61 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.action.admin.indices.cache.clear; + +import org.elasticsearch.action.support.broadcast.BroadcastShardOperationRequest; +import org.elasticsearch.util.io.stream.StreamInput; +import org.elasticsearch.util.io.stream.StreamOutput; + +import java.io.IOException; + +/** + * @author kimchy (shay.banon) + */ +class ShardClearIndicesCacheRequest extends BroadcastShardOperationRequest { + + private boolean filterCache = true; + + ShardClearIndicesCacheRequest() { + } + + public ShardClearIndicesCacheRequest(String index, int shardId, ClearIndicesCacheRequest request) { + super(index, shardId); + filterCache = request.filterCache(); + } + + public boolean filterCache() { + return filterCache; + } + + public ShardClearIndicesCacheRequest waitForOperations(boolean waitForOperations) { + this.filterCache = waitForOperations; + return this; + } + + @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); + filterCache = in.readBoolean(); + } + + @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeBoolean(filterCache); + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ShardClearIndicesCacheResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ShardClearIndicesCacheResponse.java new file mode 100644 index 00000000000..707f037d9fa --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ShardClearIndicesCacheResponse.java @@ -0,0 +1,47 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.action.admin.indices.cache.clear; + +import org.elasticsearch.action.support.broadcast.BroadcastShardOperationResponse; +import org.elasticsearch.util.io.stream.StreamInput; +import org.elasticsearch.util.io.stream.StreamOutput; + +import java.io.IOException; + +/** + * @author kimchy (shay.banon) + */ +class ShardClearIndicesCacheResponse extends BroadcastShardOperationResponse { + + ShardClearIndicesCacheResponse() { + } + + public ShardClearIndicesCacheResponse(String index, int shardId) { + super(index, shardId); + } + + @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); + } + + @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java new file mode 100644 index 00000000000..54407b6c14a --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java @@ -0,0 +1,117 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.action.admin.indices.cache.clear; + +import com.google.inject.Inject; +import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.action.ShardOperationFailedException; +import org.elasticsearch.action.TransportActions; +import org.elasticsearch.action.support.DefaultShardOperationFailedException; +import org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException; +import org.elasticsearch.action.support.broadcast.TransportBroadcastOperationAction; +import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.routing.GroupShardsIterator; +import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.index.cache.IndexCache; +import org.elasticsearch.indices.IndicesService; +import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.TransportService; +import org.elasticsearch.util.settings.Settings; + +import java.util.List; +import java.util.concurrent.atomic.AtomicReferenceArray; + +import static com.google.common.collect.Lists.*; + +/** + * Indices clear cache action. + * + * @author kimchy (shay.banon) + */ +public class TransportClearIndicesCacheAction extends TransportBroadcastOperationAction { + + @Inject public TransportClearIndicesCacheAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, + TransportService transportService, IndicesService indicesService) { + super(settings, threadPool, clusterService, transportService, indicesService); + } + + @Override protected String transportAction() { + return TransportActions.Admin.Indices.Cache.CLEAR; + } + + @Override protected String transportShardAction() { + return "indices/cache/clear/shard"; + } + + + @Override protected ClearIndicesCacheRequest newRequest() { + return new ClearIndicesCacheRequest(); + } + + @Override protected ClearIndicesCacheResponse newResponse(ClearIndicesCacheRequest request, AtomicReferenceArray shardsResponses, ClusterState clusterState) { + int successfulShards = 0; + int failedShards = 0; + List shardFailures = null; + for (int i = 0; i < shardsResponses.length(); i++) { + Object shardResponse = shardsResponses.get(i); + if (shardResponse == null) { + failedShards++; + } else if (shardResponse instanceof BroadcastShardOperationFailedException) { + failedShards++; + if (shardFailures == null) { + shardFailures = newArrayList(); + } + shardFailures.add(new DefaultShardOperationFailedException((BroadcastShardOperationFailedException) shardResponse)); + } else { + successfulShards++; + } + } + return new ClearIndicesCacheResponse(successfulShards, failedShards, shardFailures); + } + + @Override protected ShardClearIndicesCacheRequest newShardRequest() { + return new ShardClearIndicesCacheRequest(); + } + + @Override protected ShardClearIndicesCacheRequest newShardRequest(ShardRouting shard, ClearIndicesCacheRequest request) { + return new ShardClearIndicesCacheRequest(shard.index(), shard.id(), request); + } + + @Override protected ShardClearIndicesCacheResponse newShardResponse() { + return new ShardClearIndicesCacheResponse(); + } + + @Override protected ShardClearIndicesCacheResponse shardOperation(ShardClearIndicesCacheRequest request) throws ElasticSearchException { + // TODO we can optimize to go to a single node where the index exists + IndexCache cache = indicesService.indexServiceSafe(request.index()).cache(); + if (request.filterCache()) { + cache.filter().clear(); + } + return new ShardClearIndicesCacheResponse(request.index(), request.shardId()); + } + + /** + * The refresh request works against *all* shards. + */ + @Override protected GroupShardsIterator shards(ClearIndicesCacheRequest request, ClusterState clusterState) { + return clusterState.routingTable().allShardsGrouped(request.indices()); + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequest.java index a1be5e53b8f..dbe955e3a0c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequest.java @@ -46,6 +46,7 @@ public abstract class BroadcastOperationRequest implements ActionRequest { protected BroadcastOperationRequest(String[] indices, @Nullable String queryHint) { this.indices = indices; + this.queryHint = queryHint; } public String[] indices() { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/IndicesAdminClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/IndicesAdminClient.java index 17f51015fba..e571b6405fb 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/IndicesAdminClient.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/IndicesAdminClient.java @@ -23,6 +23,8 @@ import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; @@ -199,7 +201,7 @@ public interface IndicesAdminClient { * @return The result future * @see Requests#indexAliasesRequest() */ - ActionFuture indicesAliases(IndicesAliasesRequest request); + ActionFuture aliases(IndicesAliasesRequest request); /** * Allows to add/remove aliases from indices. @@ -209,4 +211,22 @@ public interface IndicesAdminClient { * @see Requests#indexAliasesRequest() */ void aliases(IndicesAliasesRequest request, ActionListener listener); + + /** + * Clear indices cache. + * + * @param request The clear indices cache request + * @return The result future + * @see Requests#clearIndicesCache(String...) + */ + ActionFuture clearCache(ClearIndicesCacheRequest request); + + /** + * Clear indices cache. + * + * @param request The clear indices cache request + * @param listener A listener to be notified with a result + * @see Requests#clearIndicesCache(String...) + */ + void clearCache(ClearIndicesCacheRequest request, ActionListener listener); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/Requests.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/Requests.java index f9027e6047f..0bb1cb5ab4f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/Requests.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/Requests.java @@ -27,6 +27,7 @@ import org.elasticsearch.action.admin.cluster.ping.replication.ReplicationPingRe import org.elasticsearch.action.admin.cluster.ping.single.SinglePingRequest; import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.flush.FlushRequest; @@ -248,7 +249,7 @@ public class Requests { /** * Creates a gateway snapshot indices request. * - * @param indices The indices the delete by query against. Use null or _all to execute against all indices + * @param indices The indices the gateway wil be performed ont. Use null or _all to execute against all indices * @return The gateway snapshot request * @see org.elasticsearch.client.IndicesAdminClient#gatewaySnapshot(org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotRequest) */ @@ -256,6 +257,16 @@ public class Requests { return new GatewaySnapshotRequest(indices); } + /** + * Creates a clean indices cache request. + * + * @param indices The indices the gateway wil be performed ont. Use null or _all to execute against all indices + * @return The request + */ + public static ClearIndicesCacheRequest clearIndicesCache(String... indices) { + return new ClearIndicesCacheRequest(indices); + } + /** * Creates a cluster state request. * diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/server/ServerIndicesAdminClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/server/ServerIndicesAdminClient.java index 247d230018f..ae3f5b3f0c0 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/server/ServerIndicesAdminClient.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/server/ServerIndicesAdminClient.java @@ -25,6 +25,9 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; import org.elasticsearch.action.admin.indices.alias.TransportIndicesAliasesAction; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse; +import org.elasticsearch.action.admin.indices.cache.clear.TransportClearIndicesCacheAction; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction; @@ -76,11 +79,13 @@ public class ServerIndicesAdminClient extends AbstractComponent implements Indic private final TransportIndicesAliasesAction indicesAliasesAction; + private final TransportClearIndicesCacheAction clearIndicesCacheAction; + @Inject public ServerIndicesAdminClient(Settings settings, TransportIndicesStatusAction indicesStatusAction, TransportCreateIndexAction createIndexAction, TransportDeleteIndexAction deleteIndexAction, TransportRefreshAction refreshAction, TransportFlushAction flushAction, TransportOptimizeAction optimizeAction, TransportPutMappingAction putMappingAction, TransportGatewaySnapshotAction gatewaySnapshotAction, - TransportIndicesAliasesAction indicesAliasesAction) { + TransportIndicesAliasesAction indicesAliasesAction, TransportClearIndicesCacheAction clearIndicesCacheAction) { super(settings); this.indicesStatusAction = indicesStatusAction; this.createIndexAction = createIndexAction; @@ -91,6 +96,7 @@ public class ServerIndicesAdminClient extends AbstractComponent implements Indic this.putMappingAction = putMappingAction; this.gatewaySnapshotAction = gatewaySnapshotAction; this.indicesAliasesAction = indicesAliasesAction; + this.clearIndicesCacheAction = clearIndicesCacheAction; } @Override public ActionFuture status(IndicesStatusRequest request) { @@ -157,11 +163,19 @@ public class ServerIndicesAdminClient extends AbstractComponent implements Indic gatewaySnapshotAction.execute(request, listener); } - @Override public ActionFuture indicesAliases(IndicesAliasesRequest request) { + @Override public ActionFuture aliases(IndicesAliasesRequest request) { return indicesAliasesAction.execute(request); } @Override public void aliases(IndicesAliasesRequest request, ActionListener listener) { indicesAliasesAction.execute(request, listener); } + + @Override public ActionFuture clearCache(ClearIndicesCacheRequest request) { + return clearIndicesCacheAction.execute(request); + } + + @Override public void clearCache(ClearIndicesCacheRequest request, ActionListener listener) { + clearIndicesCacheAction.execute(request, listener); + } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/ClientTransportActionModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/ClientTransportActionModule.java index 7d70a3b5237..113a2232f4e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/ClientTransportActionModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/ClientTransportActionModule.java @@ -28,6 +28,7 @@ import org.elasticsearch.client.transport.action.admin.cluster.ping.replication. import org.elasticsearch.client.transport.action.admin.cluster.ping.single.ClientTransportSinglePingAction; import org.elasticsearch.client.transport.action.admin.cluster.state.ClientTransportClusterStateAction; import org.elasticsearch.client.transport.action.admin.indices.alias.ClientTransportIndicesAliasesAction; +import org.elasticsearch.client.transport.action.admin.indices.cache.clear.ClientTransportClearIndicesCacheAction; import org.elasticsearch.client.transport.action.admin.indices.create.ClientTransportCreateIndexAction; import org.elasticsearch.client.transport.action.admin.indices.delete.ClientTransportDeleteIndexAction; import org.elasticsearch.client.transport.action.admin.indices.flush.ClientTransportFlushAction; @@ -69,6 +70,7 @@ public class ClientTransportActionModule extends AbstractModule { bind(ClientTransportPutMappingAction.class).asEagerSingleton(); bind(ClientTransportGatewaySnapshotAction.class).asEagerSingleton(); bind(ClientTransportIndicesAliasesAction.class).asEagerSingleton(); + bind(ClientTransportClearIndicesCacheAction.class).asEagerSingleton(); bind(ClientTransportNodesInfoAction.class).asEagerSingleton(); bind(ClientTransportNodesShutdownAction.class).asEagerSingleton(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/cache/clear/ClientTransportClearIndicesCacheAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/cache/clear/ClientTransportClearIndicesCacheAction.java new file mode 100644 index 00000000000..b2b8adbf829 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/indices/cache/clear/ClientTransportClearIndicesCacheAction.java @@ -0,0 +1,42 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.client.transport.action.admin.indices.cache.clear; + +import com.google.inject.Inject; +import org.elasticsearch.action.TransportActions; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse; +import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.transport.TransportService; +import org.elasticsearch.util.settings.Settings; + +/** + * @author kimchy (shay.banon) + */ +public class ClientTransportClearIndicesCacheAction extends BaseClientTransportAction { + + @Inject public ClientTransportClearIndicesCacheAction(Settings settings, TransportService transportService) { + super(settings, transportService, ClearIndicesCacheResponse.class); + } + + @Override protected String action() { + return TransportActions.Admin.Indices.Cache.CLEAR; + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java index a21daf9ecfb..d55ab7210b8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java @@ -25,6 +25,8 @@ import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; @@ -44,6 +46,7 @@ import org.elasticsearch.action.admin.indices.status.IndicesStatusResponse; import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.client.transport.TransportClientNodesService; import org.elasticsearch.client.transport.action.admin.indices.alias.ClientTransportIndicesAliasesAction; +import org.elasticsearch.client.transport.action.admin.indices.cache.clear.ClientTransportClearIndicesCacheAction; import org.elasticsearch.client.transport.action.admin.indices.create.ClientTransportCreateIndexAction; import org.elasticsearch.client.transport.action.admin.indices.delete.ClientTransportDeleteIndexAction; import org.elasticsearch.client.transport.action.admin.indices.flush.ClientTransportFlushAction; @@ -81,12 +84,14 @@ public class InternalTransportIndicesAdminClient extends AbstractComponent imple private final ClientTransportIndicesAliasesAction indicesAliasesAction; + private final ClientTransportClearIndicesCacheAction clearIndicesCacheAction; + @Inject public InternalTransportIndicesAdminClient(Settings settings, TransportClientNodesService nodesService, ClientTransportIndicesStatusAction indicesStatusAction, ClientTransportCreateIndexAction createIndexAction, ClientTransportDeleteIndexAction deleteIndexAction, ClientTransportRefreshAction refreshAction, ClientTransportFlushAction flushAction, ClientTransportOptimizeAction optimizeAction, ClientTransportPutMappingAction putMappingAction, ClientTransportGatewaySnapshotAction gatewaySnapshotAction, - ClientTransportIndicesAliasesAction indicesAliasesAction) { + ClientTransportIndicesAliasesAction indicesAliasesAction, ClientTransportClearIndicesCacheAction clearIndicesCacheAction) { super(settings); this.nodesService = nodesService; this.indicesStatusAction = indicesStatusAction; @@ -98,6 +103,7 @@ public class InternalTransportIndicesAdminClient extends AbstractComponent imple this.putMappingAction = putMappingAction; this.gatewaySnapshotAction = gatewaySnapshotAction; this.indicesAliasesAction = indicesAliasesAction; + this.clearIndicesCacheAction = clearIndicesCacheAction; } @Override public ActionFuture status(final IndicesStatusRequest request) { @@ -236,7 +242,7 @@ public class InternalTransportIndicesAdminClient extends AbstractComponent imple }); } - @Override public ActionFuture indicesAliases(final IndicesAliasesRequest request) { + @Override public ActionFuture aliases(final IndicesAliasesRequest request) { return nodesService.execute(new TransportClientNodesService.NodeCallback>() { @Override public ActionFuture doWithNode(Node node) throws ElasticSearchException { return indicesAliasesAction.execute(node, request); @@ -252,4 +258,21 @@ public class InternalTransportIndicesAdminClient extends AbstractComponent imple } }); } + + @Override public ActionFuture clearCache(final ClearIndicesCacheRequest request) { + return nodesService.execute(new TransportClientNodesService.NodeCallback>() { + @Override public ActionFuture doWithNode(Node node) throws ElasticSearchException { + return clearIndicesCacheAction.execute(node, request); + } + }); + } + + @Override public void clearCache(final ClearIndicesCacheRequest request, final ActionListener listener) { + nodesService.execute(new TransportClientNodesService.NodeCallback() { + @Override public Void doWithNode(Node node) throws ElasticSearchException { + clearIndicesCacheAction.execute(node, request, listener); + return null; + } + }); + } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/IndexCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/IndexCache.java new file mode 100644 index 00000000000..b5a5aefe80a --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/IndexCache.java @@ -0,0 +1,51 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.cache; + +import com.google.inject.Inject; +import org.elasticsearch.index.AbstractIndexComponent; +import org.elasticsearch.index.Index; +import org.elasticsearch.index.cache.filter.FilterCache; +import org.elasticsearch.index.cache.filter.none.NoneFilterCache; +import org.elasticsearch.index.settings.IndexSettings; +import org.elasticsearch.util.settings.Settings; + +import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; + +/** + * @author kimchy (shay.banon) + */ +public class IndexCache extends AbstractIndexComponent { + + private final FilterCache filterCache; + + public IndexCache(Index index) { + this(index, EMPTY_SETTINGS, new NoneFilterCache(index, EMPTY_SETTINGS)); + } + + @Inject public IndexCache(Index index, @IndexSettings Settings indexSettings, FilterCache filterCache) { + super(index, indexSettings); + this.filterCache = filterCache; + } + + public FilterCache filter() { + return filterCache; + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/IndexCacheModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/IndexCacheModule.java new file mode 100644 index 00000000000..6244ac71a0e --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/IndexCacheModule.java @@ -0,0 +1,42 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.cache; + +import com.google.inject.AbstractModule; +import org.elasticsearch.index.cache.filter.FilterCacheModule; +import org.elasticsearch.util.settings.Settings; + +/** + * @author kimchy (shay.banon) + */ +public class IndexCacheModule extends AbstractModule { + + private final Settings settings; + + public IndexCacheModule(Settings settings) { + this.settings = settings; + } + + @Override protected void configure() { + new FilterCacheModule(settings).configure(binder()); + + bind(IndexCache.class).asEagerSingleton(); + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/filter/FilterCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/filter/FilterCache.java index 2f04aea5c8f..ec224196de5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/filter/FilterCache.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/filter/FilterCache.java @@ -31,4 +31,6 @@ public interface FilterCache extends IndexComponent, CloseableComponent { String type(); Filter cache(Filter filterToCache); + + void clear(); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/filter/none/NoneFilterCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/filter/none/NoneFilterCache.java index 084a6ecc184..60a8db2ede2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/filter/none/NoneFilterCache.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/filter/none/NoneFilterCache.java @@ -48,4 +48,8 @@ public class NoneFilterCache extends AbstractIndexComponent implements FilterCac @Override public Filter cache(Filter filterToCache) { return filterToCache; } + + @Override public void clear() { + // nothing to do here + } } \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/filter/support/AbstractConcurrentMapFilterCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/filter/support/AbstractConcurrentMapFilterCache.java index 43ab6acaa1a..43b1e27ee06 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/filter/support/AbstractConcurrentMapFilterCache.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/filter/support/AbstractConcurrentMapFilterCache.java @@ -65,6 +65,10 @@ public abstract class AbstractConcurrentMapFilterCache extends AbstractIndexComp cache.clear(); } + @Override public void clear() { + cache.clear(); + } + @Override public Filter cache(Filter filterToCache) { return new FilterCacheFilterWrapper(filterToCache); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java index 64dfcbda3f8..8eb08926ace 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/IndexQueryParserService.java @@ -24,7 +24,7 @@ import com.google.inject.Inject; import org.elasticsearch.index.AbstractIndexComponent; import org.elasticsearch.index.Index; import org.elasticsearch.index.analysis.AnalysisService; -import org.elasticsearch.index.cache.filter.FilterCache; +import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.query.json.JsonIndexQueryParser; import org.elasticsearch.index.settings.IndexSettings; @@ -51,12 +51,12 @@ public class IndexQueryParserService extends AbstractIndexComponent { private final Map indexQueryParsers; - public IndexQueryParserService(Index index, MapperService mapperService, FilterCache filterCache, AnalysisService analysisService) { - this(index, ImmutableSettings.Builder.EMPTY_SETTINGS, mapperService, filterCache, analysisService, null, null); + public IndexQueryParserService(Index index, MapperService mapperService, IndexCache indexCache, AnalysisService analysisService) { + this(index, ImmutableSettings.Builder.EMPTY_SETTINGS, mapperService, indexCache, analysisService, null, null); } @Inject public IndexQueryParserService(Index index, @IndexSettings Settings indexSettings, - MapperService mapperService, FilterCache filterCache, + MapperService mapperService, IndexCache indexCache, AnalysisService analysisService, @Nullable SimilarityService similarityService, @Nullable Map indexQueryParsersFactories) { @@ -76,7 +76,7 @@ public class IndexQueryParserService extends AbstractIndexComponent { } } if (!qparsers.containsKey(Defaults.DEFAULT)) { - IndexQueryParser defaultQueryParser = new JsonIndexQueryParser(index, indexSettings, mapperService, filterCache, analysisService, similarityService, null, null, Defaults.DEFAULT, null); + IndexQueryParser defaultQueryParser = new JsonIndexQueryParser(index, indexSettings, mapperService, indexCache, analysisService, similarityService, null, null, Defaults.DEFAULT, null); qparsers.put(Defaults.DEFAULT, defaultQueryParser); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/FieldJsonQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/FieldJsonQueryParser.java index ec6b1ffab91..02f8ff2f202 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/FieldJsonQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/FieldJsonQueryParser.java @@ -173,7 +173,7 @@ public class FieldJsonQueryParser extends AbstractIndexComponent implements Json throw new QueryParsingException(index, "No value specified for term query"); } - MapperQueryParser queryParser = new MapperQueryParser(fieldName, analyzer, parseContext.mapperService(), parseContext.filterCache()); + MapperQueryParser queryParser = new MapperQueryParser(fieldName, analyzer, parseContext.mapperService(), parseContext.indexCache()); queryParser.setEnablePositionIncrements(enablePositionIncrements); queryParser.setLowercaseExpandedTerms(lowercaseExpandedTerms); queryParser.setPhraseSlop(phraseSlop); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/JsonIndexQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/JsonIndexQueryParser.java index 280d95f083f..20191bed7d7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/JsonIndexQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/JsonIndexQueryParser.java @@ -28,7 +28,7 @@ import org.elasticsearch.ElasticSearchException; import org.elasticsearch.index.AbstractIndexComponent; import org.elasticsearch.index.Index; import org.elasticsearch.index.analysis.AnalysisService; -import org.elasticsearch.index.cache.filter.FilterCache; +import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.query.IndexQueryParser; import org.elasticsearch.index.query.QueryBuilder; @@ -61,7 +61,7 @@ public class JsonIndexQueryParser extends AbstractIndexComponent implements Inde private ThreadLocal> cache = new ThreadLocal>() { @Override protected ThreadLocals.CleanableValue initialValue() { - return new ThreadLocals.CleanableValue(new JsonQueryParseContext(index, queryParserRegistry, mapperService, similarityService, filterCache)); + return new ThreadLocals.CleanableValue(new JsonQueryParseContext(index, queryParserRegistry, mapperService, similarityService, indexCache)); } }; @@ -73,13 +73,13 @@ public class JsonIndexQueryParser extends AbstractIndexComponent implements Inde private final SimilarityService similarityService; - private final FilterCache filterCache; + private final IndexCache indexCache; private final JsonQueryParserRegistry queryParserRegistry; @Inject public JsonIndexQueryParser(Index index, @IndexSettings Settings indexSettings, - MapperService mapperService, FilterCache filterCache, + MapperService mapperService, IndexCache indexCache, AnalysisService analysisService, @Nullable SimilarityService similarityService, @Nullable Map jsonQueryParsers, @Nullable Map jsonFilterParsers, @@ -88,7 +88,7 @@ public class JsonIndexQueryParser extends AbstractIndexComponent implements Inde this.name = name; this.mapperService = mapperService; this.similarityService = similarityService; - this.filterCache = filterCache; + this.indexCache = indexCache; List queryParsers = newArrayList(); if (jsonQueryParsers != null) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/JsonQueryParseContext.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/JsonQueryParseContext.java index b60c60abe7e..2d8f05a6d67 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/JsonQueryParseContext.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/JsonQueryParseContext.java @@ -25,7 +25,7 @@ import org.apache.lucene.search.Similarity; import org.codehaus.jackson.JsonParser; import org.codehaus.jackson.JsonToken; import org.elasticsearch.index.Index; -import org.elasticsearch.index.cache.filter.FilterCache; +import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.FieldMappers; import org.elasticsearch.index.mapper.MapperService; @@ -46,19 +46,19 @@ public class JsonQueryParseContext { private final SimilarityService similarityService; - private final FilterCache filterCache; + private final IndexCache indexCache; private final JsonQueryParserRegistry queryParserRegistry; private JsonParser jp; public JsonQueryParseContext(Index index, JsonQueryParserRegistry queryParserRegistry, - MapperService mapperService, SimilarityService similarityService, FilterCache filterCache) { + MapperService mapperService, SimilarityService similarityService, IndexCache indexCache) { this.index = index; this.queryParserRegistry = queryParserRegistry; this.mapperService = mapperService; this.similarityService = similarityService; - this.filterCache = filterCache; + this.indexCache = indexCache; } public void reset(JsonParser jp) { @@ -81,15 +81,12 @@ public class JsonQueryParseContext { return similarityService != null ? similarityService.defaultSearchSimilarity() : null; } - public FilterCache filterCache() { - return filterCache; + public IndexCache indexCache() { + return indexCache; } public Filter cacheFilterIfPossible(Filter filter) { - if (filterCache == null) { - return filter; - } - return filterCache.cache(filter); + return indexCache.filter().cache(filter); } public Query parseInnerQuery() throws IOException, QueryParsingException { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/MoreLikeThisFieldJsonQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/MoreLikeThisFieldJsonQueryParser.java index 96315248c3d..2bcd2698fb5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/MoreLikeThisFieldJsonQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/MoreLikeThisFieldJsonQueryParser.java @@ -149,6 +149,6 @@ public class MoreLikeThisFieldJsonQueryParser extends AbstractIndexComponent imp mltQuery.setAnalyzer(parseContext.mapperService().searchAnalyzer()); } mltQuery.setMoreLikeFields(new String[]{fieldName}); - return wrapSmartNameQuery(mltQuery, smartNameFieldMappers, parseContext.filterCache()); + return wrapSmartNameQuery(mltQuery, smartNameFieldMappers, parseContext.indexCache()); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/PrefixJsonFilterParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/PrefixJsonFilterParser.java index 8f9776f9d63..1a4d8835ea9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/PrefixJsonFilterParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/PrefixJsonFilterParser.java @@ -75,6 +75,6 @@ public class PrefixJsonFilterParser extends AbstractIndexComponent implements Js Filter prefixFilter = new PrefixFilter(new Term(fieldName, value)); prefixFilter = parseContext.cacheFilterIfPossible(prefixFilter); - return wrapSmartNameFilter(prefixFilter, smartNameFieldMappers, parseContext.filterCache()); + return wrapSmartNameFilter(prefixFilter, smartNameFieldMappers, parseContext.indexCache()); } } \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/PrefixJsonQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/PrefixJsonQueryParser.java index 7061a88e8e2..5e4554cb062 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/PrefixJsonQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/PrefixJsonQueryParser.java @@ -104,6 +104,6 @@ public class PrefixJsonQueryParser extends AbstractIndexComponent implements Jso PrefixQuery query = new PrefixQuery(new Term(fieldName, value)); query.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT); query.setBoost(boost); - return wrapSmartNameQuery(query, smartNameFieldMappers, parseContext.filterCache()); + return wrapSmartNameQuery(query, smartNameFieldMappers, parseContext.indexCache()); } } \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/QueryStringJsonQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/QueryStringJsonQueryParser.java index 92662fe251a..0e4e688694b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/QueryStringJsonQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/QueryStringJsonQueryParser.java @@ -211,15 +211,15 @@ public class QueryStringJsonQueryParser extends AbstractIndexComponent implement MapperQueryParser queryParser; if (fields != null) { if (fields.size() == 1) { - queryParser = new MapperQueryParser(fields.get(0), analyzer, parseContext.mapperService(), parseContext.filterCache()); + queryParser = new MapperQueryParser(fields.get(0), analyzer, parseContext.mapperService(), parseContext.indexCache()); } else { - MultiFieldMapperQueryParser mQueryParser = new MultiFieldMapperQueryParser(fields, boosts, analyzer, parseContext.mapperService(), parseContext.filterCache()); + MultiFieldMapperQueryParser mQueryParser = new MultiFieldMapperQueryParser(fields, boosts, analyzer, parseContext.mapperService(), parseContext.indexCache()); mQueryParser.setTieBreaker(tieBreaker); mQueryParser.setUseDisMax(useDisMax); queryParser = mQueryParser; } } else { - queryParser = new MapperQueryParser(defaultField, analyzer, parseContext.mapperService(), parseContext.filterCache()); + queryParser = new MapperQueryParser(defaultField, analyzer, parseContext.mapperService(), parseContext.indexCache()); } queryParser.setEnablePositionIncrements(enablePositionIncrements); queryParser.setLowercaseExpandedTerms(lowercaseExpandedTerms); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/RangeJsonFilterParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/RangeJsonFilterParser.java index 743e57ae7ef..6c6fe2cd91b 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/RangeJsonFilterParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/RangeJsonFilterParser.java @@ -118,6 +118,6 @@ public class RangeJsonFilterParser extends AbstractIndexComponent implements Jso if (filter == null) { filter = new TermRangeFilter(fieldName, from, to, includeLower, includeUpper); } - return wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext.filterCache()); + return wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext.indexCache()); } } \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/RangeJsonQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/RangeJsonQueryParser.java index 67bfc377afa..0a1f2e461a2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/RangeJsonQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/RangeJsonQueryParser.java @@ -122,6 +122,6 @@ public class RangeJsonQueryParser extends AbstractIndexComponent implements Json query = new TermRangeQuery(fieldName, from, to, includeLower, includeUpper); } query.setBoost(boost); - return wrapSmartNameQuery(query, smartNameFieldMappers, parseContext.filterCache()); + return wrapSmartNameQuery(query, smartNameFieldMappers, parseContext.indexCache()); } } \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/SpanTermJsonQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/SpanTermJsonQueryParser.java index 342c6195ec0..7dd91bec5c4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/SpanTermJsonQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/SpanTermJsonQueryParser.java @@ -102,6 +102,6 @@ public class SpanTermJsonQueryParser extends AbstractIndexComponent implements J SpanTermQuery query = new SpanTermQuery(new Term(fieldName, value)); query.setBoost(boost); - return wrapSmartNameQuery(query, smartNameFieldMappers, parseContext.filterCache()); + return wrapSmartNameQuery(query, smartNameFieldMappers, parseContext.indexCache()); } } \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/TermJsonFilterParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/TermJsonFilterParser.java index 34a53e3d4ed..8cdbd2de7f2 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/TermJsonFilterParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/TermJsonFilterParser.java @@ -79,6 +79,6 @@ public class TermJsonFilterParser extends AbstractIndexComponent implements Json filter = new TermFilter(new Term(fieldName, value)); } filter = parseContext.cacheFilterIfPossible(filter); - return wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext.filterCache()); + return wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext.indexCache()); } } \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/TermJsonQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/TermJsonQueryParser.java index 10189c5e262..258b8d60ed7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/TermJsonQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/TermJsonQueryParser.java @@ -100,6 +100,6 @@ public class TermJsonQueryParser extends AbstractIndexComponent implements JsonQ query = new TermQuery(new Term(fieldName, value)); } query.setBoost(boost); - return wrapSmartNameQuery(query, smartNameFieldMappers, parseContext.filterCache()); + return wrapSmartNameQuery(query, smartNameFieldMappers, parseContext.indexCache()); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/TermsJsonFilterParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/TermsJsonFilterParser.java index 612f6c50b60..bf2eb106f21 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/TermsJsonFilterParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/TermsJsonFilterParser.java @@ -88,6 +88,6 @@ public class TermsJsonFilterParser extends AbstractIndexComponent implements Jso Filter filter = parseContext.cacheFilterIfPossible(termsFilter); - return wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext.filterCache()); + return wrapSmartNameFilter(filter, smartNameFieldMappers, parseContext.indexCache()); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/WildcardJsonQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/WildcardJsonQueryParser.java index 52bc7c93f60..ec695c1b9a9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/WildcardJsonQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/json/WildcardJsonQueryParser.java @@ -101,6 +101,6 @@ public class WildcardJsonQueryParser extends AbstractIndexComponent implements J WildcardQuery query = new WildcardQuery(new Term(fieldName, value)); query.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT); query.setBoost(boost); - return wrapSmartNameQuery(query, smartNameFieldMappers, parseContext.filterCache()); + return wrapSmartNameQuery(query, smartNameFieldMappers, parseContext.indexCache()); } } \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/support/MapperQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/support/MapperQueryParser.java index e9503b3b63d..402ea2ed0a5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/support/MapperQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/support/MapperQueryParser.java @@ -27,7 +27,7 @@ import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.MultiTermQuery; import org.apache.lucene.search.Query; import org.apache.lucene.util.Version; -import org.elasticsearch.index.cache.filter.FilterCache; +import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.FieldMappers; import org.elasticsearch.index.mapper.MapperService; @@ -51,16 +51,16 @@ public class MapperQueryParser extends QueryParser { private final MapperService mapperService; - private final FilterCache filterCache; + private final IndexCache indexCache; private FieldMapper currentMapper; public MapperQueryParser(String defaultField, Analyzer analyzer, @Nullable MapperService mapperService, - @Nullable FilterCache filterCache) { + @Nullable IndexCache indexCache) { super(Version.LUCENE_CURRENT, defaultField, analyzer); this.mapperService = mapperService; - this.filterCache = filterCache; + this.indexCache = indexCache; setMultiTermRewriteMethod(MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT); } @@ -87,7 +87,7 @@ public class MapperQueryParser extends QueryParser { } else { query = super.getFieldQuery(currentMapper.names().indexName(), queryText); } - return wrapSmartNameQuery(query, fieldMappers, filterCache); + return wrapSmartNameQuery(query, fieldMappers, indexCache); } } } @@ -108,7 +108,7 @@ public class MapperQueryParser extends QueryParser { currentMapper = fieldMappers.fieldMappers().mapper(); if (currentMapper != null) { Query rangeQuery = currentMapper.rangeQuery(part1, part2, inclusive, inclusive); - return wrapSmartNameQuery(rangeQuery, fieldMappers, filterCache); + return wrapSmartNameQuery(rangeQuery, fieldMappers, indexCache); } } } @@ -125,7 +125,7 @@ public class MapperQueryParser extends QueryParser { if (currentMapper != null) { indexedNameField = currentMapper.names().indexName(); } - return wrapSmartNameQuery(super.getPrefixQuery(indexedNameField, termStr), fieldMappers, filterCache); + return wrapSmartNameQuery(super.getPrefixQuery(indexedNameField, termStr), fieldMappers, indexCache); } } return super.getPrefixQuery(indexedNameField, termStr); @@ -141,7 +141,7 @@ public class MapperQueryParser extends QueryParser { if (currentMapper != null) { indexedNameField = currentMapper.names().indexName(); } - return wrapSmartNameQuery(super.getFuzzyQuery(indexedNameField, termStr, minSimilarity), fieldMappers, filterCache); + return wrapSmartNameQuery(super.getFuzzyQuery(indexedNameField, termStr, minSimilarity), fieldMappers, indexCache); } } return super.getFuzzyQuery(indexedNameField, termStr, minSimilarity); @@ -157,7 +157,7 @@ public class MapperQueryParser extends QueryParser { if (currentMapper != null) { indexedNameField = currentMapper.names().indexName(); } - return wrapSmartNameQuery(super.getWildcardQuery(indexedNameField, termStr), fieldMappers, filterCache); + return wrapSmartNameQuery(super.getWildcardQuery(indexedNameField, termStr), fieldMappers, indexCache); } } return super.getWildcardQuery(indexedNameField, termStr); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/support/MultiFieldMapperQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/support/MultiFieldMapperQueryParser.java index 24cc6cdb648..c7ea608def6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/support/MultiFieldMapperQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/support/MultiFieldMapperQueryParser.java @@ -22,7 +22,7 @@ package org.elasticsearch.index.query.support; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.queryParser.ParseException; import org.apache.lucene.search.*; -import org.elasticsearch.index.cache.filter.FilterCache; +import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.util.Nullable; import org.elasticsearch.util.trove.ExtTObjectFloatHashMap; @@ -43,8 +43,8 @@ public class MultiFieldMapperQueryParser extends MapperQueryParser { private boolean useDisMax = true; - public MultiFieldMapperQueryParser(List fields, @Nullable ExtTObjectFloatHashMap boosts, Analyzer analyzer, @Nullable MapperService mapperService, @Nullable FilterCache filterCache) { - super(null, analyzer, mapperService, filterCache); + public MultiFieldMapperQueryParser(List fields, @Nullable ExtTObjectFloatHashMap boosts, Analyzer analyzer, @Nullable MapperService mapperService, @Nullable IndexCache indexCache) { + super(null, analyzer, mapperService, indexCache); this.fields = fields; this.boosts = boosts; if (this.boosts != null) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/support/QueryParsers.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/support/QueryParsers.java index 2f8bbc91de9..6fe70e302c1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/support/QueryParsers.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/support/QueryParsers.java @@ -20,7 +20,7 @@ package org.elasticsearch.index.query.support; import org.apache.lucene.search.*; -import org.elasticsearch.index.cache.filter.FilterCache; +import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.util.Nullable; @@ -36,7 +36,7 @@ public final class QueryParsers { } public static Query wrapSmartNameQuery(Query query, @Nullable MapperService.SmartNameFieldMappers smartFieldMappers, - @Nullable FilterCache filterCache) { + @Nullable IndexCache indexCache) { if (smartFieldMappers == null) { return query; } @@ -45,14 +45,14 @@ public final class QueryParsers { } DocumentMapper docMapper = smartFieldMappers.docMapper(); Filter typeFilter = new TermFilter(docMapper.typeMapper().term(docMapper.type())); - if (filterCache != null) { - typeFilter = filterCache.cache(typeFilter); + if (indexCache != null) { + typeFilter = indexCache.filter().cache(typeFilter); } return new FilteredQuery(query, typeFilter); } public static Filter wrapSmartNameFilter(Filter filter, @Nullable MapperService.SmartNameFieldMappers smartFieldMappers, - @Nullable FilterCache filterCache) { + @Nullable IndexCache indexCache) { if (smartFieldMappers == null) { return filter; } @@ -62,15 +62,15 @@ public final class QueryParsers { DocumentMapper docMapper = smartFieldMappers.docMapper(); BooleanFilter booleanFilter = new BooleanFilter(); Filter typeFilter = new TermFilter(docMapper.typeMapper().term(docMapper.type())); - if (filterCache != null) { - typeFilter = filterCache.cache(typeFilter); + if (indexCache != null) { + typeFilter = indexCache.filter().cache(typeFilter); } booleanFilter.add(new FilterClause(typeFilter, BooleanClause.Occur.MUST)); booleanFilter.add(new FilterClause(filter, BooleanClause.Occur.MUST)); Filter result = booleanFilter; - if (filterCache != null) { - result = filterCache.cache(result); + if (indexCache != null) { + result = indexCache.filter().cache(result); } return result; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/service/IndexService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/service/IndexService.java index 97a537d40b7..3e50ae4b5d4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/service/IndexService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/service/IndexService.java @@ -24,7 +24,7 @@ import org.elasticsearch.ElasticSearchException; import org.elasticsearch.index.IndexComponent; import org.elasticsearch.index.IndexLifecycle; import org.elasticsearch.index.IndexShardMissingException; -import org.elasticsearch.index.cache.filter.FilterCache; +import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.query.IndexQueryParserService; import org.elasticsearch.index.routing.OperationRouting; @@ -42,7 +42,7 @@ public interface IndexService extends IndexComponent, Iterable, Clos Injector injector(); - FilterCache filterCache(); + IndexCache cache(); OperationRouting operationRouting(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/service/InternalIndexService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/service/InternalIndexService.java index 49a299fb9ae..3b825dfff16 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/service/InternalIndexService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/service/InternalIndexService.java @@ -25,7 +25,7 @@ import com.google.inject.Inject; import com.google.inject.Injector; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.index.*; -import org.elasticsearch.index.cache.filter.FilterCache; +import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.deletionpolicy.DeletionPolicyModule; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.engine.EngineModule; @@ -79,7 +79,7 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde private final SimilarityService similarityService; - private final FilterCache filterCache; + private final IndexCache indexCache; private final OperationRouting operationRouting; @@ -89,14 +89,14 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde @Inject public InternalIndexService(Injector injector, Index index, @IndexSettings Settings indexSettings, MapperService mapperService, IndexQueryParserService queryParserService, SimilarityService similarityService, - FilterCache filterCache, OperationRouting operationRouting) { + IndexCache indexCache, OperationRouting operationRouting) { super(index, indexSettings); this.injector = injector; this.indexSettings = indexSettings; this.mapperService = mapperService; this.queryParserService = queryParserService; this.similarityService = similarityService; - this.filterCache = filterCache; + this.indexCache = indexCache; this.operationRouting = operationRouting; this.pluginsService = injector.getInstance(PluginsService.class); @@ -134,8 +134,8 @@ public class InternalIndexService extends AbstractIndexComponent implements Inde return injector; } - @Override public FilterCache filterCache() { - return filterCache; + @Override public IndexCache cache() { + return indexCache; } @Override public OperationRouting operationRouting() { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java index 2a9dbc06647..a13d5e16141 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java @@ -27,7 +27,7 @@ import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.cluster.routing.ShardRouting; -import org.elasticsearch.index.cache.filter.FilterCache; +import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.engine.EngineException; import org.elasticsearch.index.engine.ScheduledRefreshableEngine; @@ -69,7 +69,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I private final IndexQueryParserService queryParserService; - private final FilterCache filterCache; + private final IndexCache indexCache; private final Store store; @@ -86,7 +86,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I private volatile ShardRouting shardRouting; @Inject public InternalIndexShard(ShardId shardId, @IndexSettings Settings indexSettings, Store store, Engine engine, Translog translog, - ThreadPool threadPool, MapperService mapperService, IndexQueryParserService queryParserService, FilterCache filterCache) { + ThreadPool threadPool, MapperService mapperService, IndexQueryParserService queryParserService, IndexCache indexCache) { super(shardId, indexSettings); this.store = store; this.engine = engine; @@ -94,7 +94,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I this.threadPool = threadPool; this.mapperService = mapperService; this.queryParserService = queryParserService; - this.filterCache = filterCache; + this.indexCache = indexCache; state = IndexShardState.CREATED; logger.debug("Moved to state [CREATED]"); } @@ -491,7 +491,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I throw new TypeMissingException(shardId.index(), type); } Filter typeFilter = new TermFilter(docMapper.typeMapper().term(docMapper.type())); - typeFilter = filterCache.cache(typeFilter); + typeFilter = indexCache.filter().cache(typeFilter); query = new FilteredQuery(query, typeFilter); } else { BooleanFilter booleanFilter = new BooleanFilter(); @@ -501,7 +501,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I throw new TypeMissingException(shardId.index(), type); } Filter typeFilter = new TermFilter(docMapper.typeMapper().term(docMapper.type())); - typeFilter = filterCache.cache(typeFilter); + typeFilter = indexCache.filter().cache(typeFilter); booleanFilter.add(new FilterClause(typeFilter, BooleanClause.Occur.SHOULD)); } query = new FilteredQuery(query, booleanFilter); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java index 4697a10fe48..3f48d75eca7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java @@ -30,8 +30,8 @@ import org.elasticsearch.gateway.Gateway; import org.elasticsearch.index.*; import org.elasticsearch.index.analysis.AnalysisModule; import org.elasticsearch.index.analysis.AnalysisService; +import org.elasticsearch.index.cache.IndexCacheModule; import org.elasticsearch.index.cache.filter.FilterCache; -import org.elasticsearch.index.cache.filter.FilterCacheModule; import org.elasticsearch.index.gateway.IndexGateway; import org.elasticsearch.index.gateway.IndexGatewayModule; import org.elasticsearch.index.mapper.MapperServiceModule; @@ -165,7 +165,7 @@ public class InternalIndicesService extends AbstractLifecycleComponent() { + @Override public void onResponse(ClearIndicesCacheResponse response) { + try { + JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); + builder.startObject(); + builder.field("ok", true); + + buildBroadcastShardsHeader(builder, response); + + builder.endObject(); + channel.sendResponse(new JsonRestResponse(request, OK, builder)); + } catch (Exception e) { + onFailure(e); + } + } + + @Override public void onFailure(Throwable e) { + try { + channel.sendResponse(new JsonThrowableRestResponse(request, e)); + } catch (IOException e1) { + logger.error("Failed to send failure response", e1); + } + } + }); + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/SearchContext.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/SearchContext.java index 936065522ef..b0442157349 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/SearchContext.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/internal/SearchContext.java @@ -205,7 +205,7 @@ public class SearchContext implements Releasable { } public FilterCache filterCache() { - return indexService.filterCache(); + return indexService.cache().filter(); } public TimeValue timeout() { diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/json/SimpleJsonIndexQueryParserTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/json/SimpleJsonIndexQueryParserTests.java index 94f96fcc327..4e9f16d57ad 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/json/SimpleJsonIndexQueryParserTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/json/SimpleJsonIndexQueryParserTests.java @@ -26,7 +26,7 @@ import org.apache.lucene.util.NumericUtils; import org.elasticsearch.env.Environment; import org.elasticsearch.index.Index; import org.elasticsearch.index.analysis.AnalysisService; -import org.elasticsearch.index.cache.filter.none.NoneFilterCache; +import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.query.IndexQueryParser; import org.elasticsearch.util.lucene.search.MoreLikeThisQuery; @@ -757,7 +757,7 @@ public class SimpleJsonIndexQueryParserTests { private JsonIndexQueryParser newQueryParser() throws IOException { return new JsonIndexQueryParser(new Index("test"), EMPTY_SETTINGS, - newMapperService(), new NoneFilterCache(index, EMPTY_SETTINGS), new AnalysisService(index), null, null, null, "test", null); + newMapperService(), new IndexCache(index), new AnalysisService(index), null, null, null, "test", null); } private MapperService newMapperService() throws IOException { diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/shard/SimpleIndexShardTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/shard/SimpleIndexShardTests.java index bd4c722e394..624ccf1c68c 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/shard/SimpleIndexShardTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/shard/SimpleIndexShardTests.java @@ -21,8 +21,7 @@ package org.elasticsearch.index.shard; import org.elasticsearch.env.Environment; import org.elasticsearch.index.analysis.AnalysisService; -import org.elasticsearch.index.cache.filter.FilterCache; -import org.elasticsearch.index.cache.filter.none.NoneFilterCache; +import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.deletionpolicy.KeepOnlyLastDeletionPolicy; import org.elasticsearch.index.deletionpolicy.SnapshotDeletionPolicy; import org.elasticsearch.index.engine.Engine; @@ -65,8 +64,8 @@ public class SimpleIndexShardTests { ShardId shardId = new ShardId("test", 1); AnalysisService analysisService = new AnalysisService(shardId.index()); MapperService mapperService = new MapperService(shardId.index(), settings, environment, analysisService); - IndexQueryParserService queryParserService = new IndexQueryParserService(shardId.index(), mapperService, new NoneFilterCache(shardId.index(), EMPTY_SETTINGS), analysisService); - FilterCache filterCache = new NoneFilterCache(shardId.index(), settings); + IndexQueryParserService queryParserService = new IndexQueryParserService(shardId.index(), mapperService, new IndexCache(shardId.index()), analysisService); + IndexCache indexCache = new IndexCache(shardId.index()); SnapshotDeletionPolicy policy = new SnapshotDeletionPolicy(new KeepOnlyLastDeletionPolicy(shardId, settings)); Store store = new RamStore(shardId, settings); @@ -77,7 +76,7 @@ public class SimpleIndexShardTests { threadPool = new ScalingThreadPool(); - indexShard = new InternalIndexShard(shardId, EMPTY_SETTINGS, store, engine, translog, threadPool, mapperService, queryParserService, filterCache).start(); + indexShard = new InternalIndexShard(shardId, EMPTY_SETTINGS, store, engine, translog, threadPool, mapperService, queryParserService, indexCache).start(); } @AfterMethod public void tearDown() { diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/aliases/IndexAliasesTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/aliases/IndexAliasesTests.java index 83a7d77f354..5214afe00c4 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/aliases/IndexAliasesTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/aliases/IndexAliasesTests.java @@ -83,7 +83,7 @@ public class IndexAliasesTests extends AbstractServersTests { } logger.info("Aliasing index [test] with [alias1]"); - client1.admin().indices().indicesAliases(indexAliasesRequest().addAlias("test", "alias1")).actionGet(); + client1.admin().indices().aliases(indexAliasesRequest().addAlias("test", "alias1")).actionGet(); Thread.sleep(300); logger.info("Indexing against [alias1], should work now"); @@ -100,7 +100,7 @@ public class IndexAliasesTests extends AbstractServersTests { assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN)); logger.info("Remove [alias1], Aliasing index [test_x] with [alias1]"); - client1.admin().indices().indicesAliases(indexAliasesRequest().removeAlias("test", "alias1").addAlias("test_x", "alias1")).actionGet(); + client1.admin().indices().aliases(indexAliasesRequest().removeAlias("test", "alias1").addAlias("test_x", "alias1")).actionGet(); Thread.sleep(300); logger.info("Indexing against [alias1], should work against [test_x]"); diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/document/DocumentActionsTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/document/DocumentActionsTests.java index 4c4eb9b7ea7..1578b6e9fda 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/document/DocumentActionsTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/document/DocumentActionsTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.test.integration.document; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse; import org.elasticsearch.action.admin.indices.flush.FlushResponse; import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; @@ -100,6 +101,11 @@ public class DocumentActionsTests extends AbstractServersTests { assertThat(refreshResponse.successfulShards(), equalTo(10)); assertThat(refreshResponse.failedShards(), equalTo(0)); + logger.info("Clearing cache"); + ClearIndicesCacheResponse clearIndicesCacheResponse = client1.admin().indices().clearCache(clearIndicesCache("test")).actionGet(); + assertThat(clearIndicesCacheResponse.successfulShards(), equalTo(10)); + assertThat(clearIndicesCacheResponse.failedShards(), equalTo(0)); + logger.info("Optimizing"); OptimizeResponse optimizeResponse = client1.admin().indices().optimize(optimizeRequest("test")).actionGet(); assertThat(optimizeResponse.successfulShards(), equalTo(10));