Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clear query builder rewrite cache by endpoint #12

Merged
merged 1 commit into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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