Skip to content

Commit

Permalink
Merge pull request #12 from rahul1193/spr/terms-lookup-cache
Browse files Browse the repository at this point in the history
clear query builder rewrite cache by endpoint
  • Loading branch information
rahulanishetty authored Jun 27, 2017
2 parents 77aba56 + 3492449 commit 8e9769f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class ClearIndicesCacheRequest extends BroadcastRequest<ClearIndicesCache
private boolean recycler = false;
private boolean requestCache = false;
private boolean parsedQueryCache = false;
private boolean queryBuilderRewriteCache = false;
private String[] fields = null;


Expand Down Expand Up @@ -95,6 +96,15 @@ public boolean parsedQueryCache(){
return parsedQueryCache;
}

public ClearIndicesCacheRequest queryBuilderRewriteCache(boolean queryBuilderRewriteCache){
this.queryBuilderRewriteCache = queryBuilderRewriteCache;
return this;
}

public boolean queryBuilderRewriteCache(){
return parsedQueryCache;
}

public boolean recycler() {
return this.recycler;
}
Expand All @@ -108,6 +118,7 @@ public void readFrom(StreamInput in) throws IOException {
fields = in.readStringArray();
requestCache = in.readBoolean();
parsedQueryCache = in.readBoolean();
queryBuilderRewriteCache = in.readBoolean();
}

@Override
Expand All @@ -119,5 +130,6 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeStringArrayNullable(fields);
out.writeBoolean(requestCache);
out.writeBoolean(parsedQueryCache);
out.writeBoolean(queryBuilderRewriteCache);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.elasticsearch.action.admin.indices.cache.clear;

import com.spr.elasticsearch.index.query.ParsedQueryCache;
import com.spr.elasticsearch.index.query.QueryBuilderRewriteCache;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.broadcast.node.TransportBroadcastByNodeAction;
Expand Down Expand Up @@ -55,7 +56,7 @@ public TransportClearIndicesCacheAction(Settings settings, ThreadPool threadPool
TransportService transportService, IndicesService indicesService, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver) {
super(settings, ClearIndicesCacheAction.NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver,
ClearIndicesCacheRequest::new, ThreadPool.Names.MANAGEMENT, false);
ClearIndicesCacheRequest::new, ThreadPool.Names.MANAGEMENT, false);
this.indicesService = indicesService;
}

Expand Down Expand Up @@ -106,6 +107,11 @@ protected EmptyResult shardOperation(ClearIndicesCacheRequest request, ShardRout
service.parsedQueryCache().ifPresent(ParsedQueryCache::clear);
}

if (request.queryBuilderRewriteCache()) {
clearedAtLeastOne = true;
service.queryBuilderRewriteCache().ifPresent(QueryBuilderRewriteCache::clear);
}

if (request.recycler()) {
logger.debug("Clear CacheRecycler on index [{}]", service.index());
clearedAtLeastOne = true;
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/org/elasticsearch/index/IndexService.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ public Optional<ParsedQueryCache> parsedQueryCache() {
return Optional.ofNullable(parsedQueryCache);
}

public Optional<QueryBuilderRewriteCache> queryBuilderRewriteCache() {
return Optional.ofNullable(queryBuilderRewriteCache);
}

public IndexFieldDataService fieldData() {
return indexFieldData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ public RestClearIndicesCacheAction(Settings settings, RestController controller)
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
ClearIndicesCacheRequest clearIndicesCacheRequest = new ClearIndicesCacheRequest(
Strings.splitStringByCommaToArray(request.param("index")));
Strings.splitStringByCommaToArray(request.param("index")));
clearIndicesCacheRequest.indicesOptions(IndicesOptions.fromRequest(request, clearIndicesCacheRequest.indicesOptions()));
fromRequest(request, clearIndicesCacheRequest);
return channel ->
client.admin().indices().clearCache(clearIndicesCacheRequest, new RestBuilderListener<ClearIndicesCacheResponse>(channel) {
@Override
public RestResponse buildResponse(ClearIndicesCacheResponse response, XContentBuilder builder) throws Exception {
builder.startObject();
buildBroadcastShardsHeader(builder, request, response);
builder.endObject();
return new BytesRestResponse(OK, builder);
}
});
client.admin().indices().clearCache(clearIndicesCacheRequest, new RestBuilderListener<ClearIndicesCacheResponse>(channel) {
@Override
public RestResponse buildResponse(ClearIndicesCacheResponse response, XContentBuilder builder) throws Exception {
builder.startObject();
buildBroadcastShardsHeader(builder, request, response);
builder.endObject();
return new BytesRestResponse(OK, builder);
}
});
}

@Override
Expand All @@ -86,9 +86,12 @@ public static ClearIndicesCacheRequest fromRequest(final RestRequest request, Cl
if (Fields.RECYCLER.match(entry.getKey())) {
clearIndicesCacheRequest.recycler(request.paramAsBoolean(entry.getKey(), clearIndicesCacheRequest.recycler()));
}
if(Fields.PARSED_QUERY_CACHE.match(entry.getKey())) {
if (Fields.PARSED_QUERY_CACHE.match(entry.getKey())) {
clearIndicesCacheRequest.parsedQueryCache(request.paramAsBoolean(entry.getKey(), clearIndicesCacheRequest.parsedQueryCache()));
}
if (Fields.QUERY_BUILDER_CACHE.match(entry.getKey())) {
clearIndicesCacheRequest.queryBuilderRewriteCache(request.paramAsBoolean(entry.getKey(), clearIndicesCacheRequest.queryBuilderRewriteCache()));
}
if (Fields.FIELDS.match(entry.getKey())) {
clearIndicesCacheRequest.fields(request.paramAsStringArray(entry.getKey(), clearIndicesCacheRequest.fields()));
}
Expand All @@ -102,6 +105,7 @@ public static class Fields {
public static final ParseField REQUEST = new ParseField("request", "request_cache");
public static final ParseField FIELD_DATA = new ParseField("field_data", "fielddata");
public static final ParseField PARSED_QUERY_CACHE = new ParseField("parsed_query", "parsed_query_cache");
public static final ParseField QUERY_BUILDER_CACHE = new ParseField("query_builder", "query_builder_cache");
public static final ParseField RECYCLER = new ParseField("recycler");
public static final ParseField FIELDS = new ParseField("fields");
}
Expand Down

0 comments on commit 8e9769f

Please sign in to comment.