Clear Cache API: Add specific cache clear for `id`, `filter`, `field_data`, `bloom`, closes #716.

This commit is contained in:
kimchy 2011-02-23 21:17:09 +02:00
parent 8371920a89
commit 5082ad6d11
5 changed files with 103 additions and 11 deletions

View File

@ -31,7 +31,10 @@ import java.io.IOException;
*/
public class ClearIndicesCacheRequest extends BroadcastOperationRequest {
private boolean filterCache = true;
private boolean filterCache = false;
private boolean fieldDataCache = false;
private boolean idCache = false;
private boolean bloomCache = false;
ClearIndicesCacheRequest() {
}
@ -62,21 +65,51 @@ public class ClearIndicesCacheRequest extends BroadcastOperationRequest {
return filterCache;
}
/**
* Should the filter cache be cleared or not. Defaults to <tt>true</tt>.
*/
public ClearIndicesCacheRequest filterCache(boolean filterCache) {
this.filterCache = filterCache;
return this;
}
public boolean fieldDataCache() {
return this.fieldDataCache;
}
public ClearIndicesCacheRequest fieldDataCache(boolean fieldDataCache) {
this.fieldDataCache = fieldDataCache;
return this;
}
public boolean idCache() {
return this.idCache;
}
public ClearIndicesCacheRequest idCache(boolean idCache) {
this.idCache = idCache;
return this;
}
public boolean bloomCache() {
return this.bloomCache;
}
public ClearIndicesCacheRequest bloomCache(boolean bloomCache) {
this.bloomCache = bloomCache;
return this;
}
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
filterCache = in.readBoolean();
fieldDataCache = in.readBoolean();
idCache = in.readBoolean();
bloomCache = in.readBoolean();
}
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeBoolean(filterCache);
out.writeBoolean(fieldDataCache);
out.writeBoolean(idCache);
out.writeBoolean(bloomCache);
}
}

View File

@ -30,7 +30,10 @@ import java.io.IOException;
*/
class ShardClearIndicesCacheRequest extends BroadcastShardOperationRequest {
private boolean filterCache = true;
private boolean filterCache = false;
private boolean fieldDataCache = false;
private boolean idCache = false;
private boolean bloomCache = false;
ShardClearIndicesCacheRequest() {
}
@ -38,12 +41,27 @@ class ShardClearIndicesCacheRequest extends BroadcastShardOperationRequest {
public ShardClearIndicesCacheRequest(String index, int shardId, ClearIndicesCacheRequest request) {
super(index, shardId);
filterCache = request.filterCache();
fieldDataCache = request.fieldDataCache();
idCache = request.idCache();
bloomCache = request.bloomCache();
}
public boolean filterCache() {
return filterCache;
}
public boolean fieldDataCache() {
return this.fieldDataCache;
}
public boolean idCache() {
return this.idCache;
}
public boolean bloomCache() {
return this.bloomCache;
}
public ShardClearIndicesCacheRequest waitForOperations(boolean waitForOperations) {
this.filterCache = waitForOperations;
return this;
@ -52,10 +70,16 @@ class ShardClearIndicesCacheRequest extends BroadcastShardOperationRequest {
@Override public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
filterCache = in.readBoolean();
fieldDataCache = in.readBoolean();
idCache = in.readBoolean();
bloomCache = in.readBoolean();
}
@Override public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeBoolean(filterCache);
out.writeBoolean(fieldDataCache);
out.writeBoolean(idCache);
out.writeBoolean(bloomCache);
}
}

View File

@ -111,10 +111,30 @@ public class TransportClearIndicesCacheAction extends TransportBroadcastOperatio
}
@Override protected ShardClearIndicesCacheResponse shardOperation(ShardClearIndicesCacheRequest request) throws ElasticSearchException {
// TODO we can optimize to go to a single node where the index exists
IndexService service = indicesService.indexService(request.index());
if (service != null) {
service.cache().clear();
// we always clear the query cache
service.cache().queryParserCache().clear();
boolean clearedAtLeastOne = false;
if (request.filterCache()) {
clearedAtLeastOne = true;
service.cache().filter().clear();
}
if (request.fieldDataCache()) {
clearedAtLeastOne = true;
service.cache().fieldData().clear();
}
if (request.idCache()) {
clearedAtLeastOne = true;
service.cache().idCache().clear();
}
if (request.bloomCache()) {
clearedAtLeastOne = true;
service.cache().bloomCache().clear();
}
if (!clearedAtLeastOne) {
service.cache().clear();
}
}
return new ShardClearIndicesCacheResponse(request.index(), request.shardId());
}

View File

@ -40,14 +40,26 @@ public class ClearIndicesCacheRequestBuilder extends BaseIndicesRequestBuilder<C
return this;
}
/**
* Should the filter cache be cleared or not. Defaults to <tt>true</tt>.
*/
public ClearIndicesCacheRequestBuilder setFilterCache(boolean filterCache) {
request.filterCache(filterCache);
return this;
}
public ClearIndicesCacheRequestBuilder setFieldDataCache(boolean fieldDataCache) {
request.fieldDataCache(fieldDataCache);
return this;
}
public ClearIndicesCacheRequestBuilder setIdCache(boolean idCache) {
request.idCache(idCache);
return this;
}
public ClearIndicesCacheRequestBuilder setBloomCache(boolean bloomCache) {
request.bloomCache(bloomCache);
return this;
}
/**
* Should the listener be called on a separate thread if needed.
*/

View File

@ -54,7 +54,10 @@ public class RestClearIndicesCacheAction extends BaseRestHandler {
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
ClearIndicesCacheRequest clearIndicesCacheRequest = new ClearIndicesCacheRequest(RestActions.splitIndices(request.param("index")));
try {
clearIndicesCacheRequest.filterCache(request.paramAsBoolean("filter_cache", clearIndicesCacheRequest.filterCache()));
clearIndicesCacheRequest.filterCache(request.paramAsBoolean("filter", clearIndicesCacheRequest.filterCache()));
clearIndicesCacheRequest.fieldDataCache(request.paramAsBoolean("field_data", clearIndicesCacheRequest.fieldDataCache()));
clearIndicesCacheRequest.idCache(request.paramAsBoolean("id", clearIndicesCacheRequest.idCache()));
clearIndicesCacheRequest.bloomCache(request.paramAsBoolean("bloom", clearIndicesCacheRequest.bloomCache()));
// we just send back a response, no need to fork a listener
clearIndicesCacheRequest.listenerThreaded(false);