From 771225ccc9dfc5eef5ccbca4dfbd2fc2400be39a Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Tue, 1 May 2012 16:36:05 +0300 Subject: [PATCH] add logging with a reason why the cache is cleared (filter and field) --- .../cache/clear/TransportClearIndicesCacheAction.java | 10 +++++----- .../java/org/elasticsearch/index/cache/IndexCache.java | 6 +++--- .../index/cache/field/data/FieldDataCache.java | 4 ++-- .../cache/field/data/none/NoneFieldDataCache.java | 4 ++-- .../field/data/resident/ResidentFieldDataCache.java | 2 +- .../support/AbstractConcurrentMapFieldDataCache.java | 8 +++++--- .../elasticsearch/index/cache/filter/FilterCache.java | 2 +- .../index/cache/filter/none/NoneFilterCache.java | 2 +- .../cache/filter/weighted/WeightedFilterCache.java | 5 +++-- 9 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java index 9421d51e1bb..85b1a7edfa9 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/TransportClearIndicesCacheAction.java @@ -122,15 +122,15 @@ public class TransportClearIndicesCacheAction extends TransportBroadcastOperatio boolean clearedAtLeastOne = false; if (request.filterCache()) { clearedAtLeastOne = true; - service.cache().filter().clear(); + service.cache().filter().clear("api"); } if (request.fieldDataCache()) { clearedAtLeastOne = true; if (request.fields() == null || request.fields().length == 0) { - service.cache().fieldData().clear(); + service.cache().fieldData().clear("api"); } else { for (String field : request.fields()) { - service.cache().fieldData().clear(field); + service.cache().fieldData().clear("api", field); } } } @@ -146,10 +146,10 @@ public class TransportClearIndicesCacheAction extends TransportBroadcastOperatio if (request.fields() != null && request.fields().length > 0) { // only clear caches relating to the specified fields for (String field : request.fields()) { - service.cache().fieldData().clear(field); + service.cache().fieldData().clear("api", field); } } else { - service.cache().clear(); + service.cache().clear("api"); } } service.cache().invalidateCache(); diff --git a/src/main/java/org/elasticsearch/index/cache/IndexCache.java b/src/main/java/org/elasticsearch/index/cache/IndexCache.java index 4fb3d8e028a..de39944c2c5 100644 --- a/src/main/java/org/elasticsearch/index/cache/IndexCache.java +++ b/src/main/java/org/elasticsearch/index/cache/IndexCache.java @@ -138,9 +138,9 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo bloomCache.clear(reader); } - public void clear() { - filterCache.clear(); - fieldDataCache.clear(); + public void clear(String reason) { + filterCache.clear(reason); + fieldDataCache.clear(reason); idCache.clear(); queryParserCache.clear(); bloomCache.clear(); diff --git a/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCache.java b/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCache.java index dd2088b4f6f..d0deeea4b41 100644 --- a/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCache.java +++ b/src/main/java/org/elasticsearch/index/cache/field/data/FieldDataCache.java @@ -36,9 +36,9 @@ public interface FieldDataCache extends IndexComponent, CloseableComponent { String type(); - void clear(String fieldName); + void clear(String reason, String fieldName); - void clear(); + void clear(String reason); void clear(IndexReader reader); diff --git a/src/main/java/org/elasticsearch/index/cache/field/data/none/NoneFieldDataCache.java b/src/main/java/org/elasticsearch/index/cache/field/data/none/NoneFieldDataCache.java index e723786db51..c6350907963 100644 --- a/src/main/java/org/elasticsearch/index/cache/field/data/none/NoneFieldDataCache.java +++ b/src/main/java/org/elasticsearch/index/cache/field/data/none/NoneFieldDataCache.java @@ -54,12 +54,12 @@ public class NoneFieldDataCache extends AbstractIndexComponent implements FieldD } @Override - public void clear(String fieldName) { + public void clear(String reason, String fieldName) { } @Override - public void clear() { + public void clear(String reason) { } @Override diff --git a/src/main/java/org/elasticsearch/index/cache/field/data/resident/ResidentFieldDataCache.java b/src/main/java/org/elasticsearch/index/cache/field/data/resident/ResidentFieldDataCache.java index 8f8414e124c..d46d7593c94 100644 --- a/src/main/java/org/elasticsearch/index/cache/field/data/resident/ResidentFieldDataCache.java +++ b/src/main/java/org/elasticsearch/index/cache/field/data/resident/ResidentFieldDataCache.java @@ -125,7 +125,7 @@ public class ResidentFieldDataCache extends AbstractConcurrentMapFieldDataCache ResidentFieldDataCache.this.expire = expire; } if (changed) { - clear(); + clear("update_settings"); } } } diff --git a/src/main/java/org/elasticsearch/index/cache/field/data/support/AbstractConcurrentMapFieldDataCache.java b/src/main/java/org/elasticsearch/index/cache/field/data/support/AbstractConcurrentMapFieldDataCache.java index 07ce023a1cb..8382463d78f 100644 --- a/src/main/java/org/elasticsearch/index/cache/field/data/support/AbstractConcurrentMapFieldDataCache.java +++ b/src/main/java/org/elasticsearch/index/cache/field/data/support/AbstractConcurrentMapFieldDataCache.java @@ -53,18 +53,20 @@ public abstract class AbstractConcurrentMapFieldDataCache extends AbstractIndexC @Override public void close() throws ElasticSearchException { - clear(); + clear("close"); } @Override - public void clear(String fieldName) { + public void clear(String reason, String fieldName) { + logger.debug("clearing field [{}] cache, reason [{}]", fieldName, reason); for (Map.Entry> entry : cache.entrySet()) { entry.getValue().invalidate(fieldName); } } @Override - public void clear() { + public void clear(String reason) { + logger.debug("full cache clear, reason [{}]", reason); cache.clear(); } diff --git a/src/main/java/org/elasticsearch/index/cache/filter/FilterCache.java b/src/main/java/org/elasticsearch/index/cache/filter/FilterCache.java index e5b86bdb909..c5df2d84cea 100644 --- a/src/main/java/org/elasticsearch/index/cache/filter/FilterCache.java +++ b/src/main/java/org/elasticsearch/index/cache/filter/FilterCache.java @@ -47,7 +47,7 @@ public interface FilterCache extends IndexComponent, CloseableComponent { void clear(IndexReader reader); - void clear(); + void clear(String reason); EntriesStats entriesStats(); diff --git a/src/main/java/org/elasticsearch/index/cache/filter/none/NoneFilterCache.java b/src/main/java/org/elasticsearch/index/cache/filter/none/NoneFilterCache.java index 9d9333e35d0..5e365fb3d24 100644 --- a/src/main/java/org/elasticsearch/index/cache/filter/none/NoneFilterCache.java +++ b/src/main/java/org/elasticsearch/index/cache/filter/none/NoneFilterCache.java @@ -60,7 +60,7 @@ public class NoneFilterCache extends AbstractIndexComponent implements FilterCac } @Override - public void clear() { + public void clear(String reason) { // nothing to do here } diff --git a/src/main/java/org/elasticsearch/index/cache/filter/weighted/WeightedFilterCache.java b/src/main/java/org/elasticsearch/index/cache/filter/weighted/WeightedFilterCache.java index 0b11e4dd08c..8c14b8cd6c9 100644 --- a/src/main/java/org/elasticsearch/index/cache/filter/weighted/WeightedFilterCache.java +++ b/src/main/java/org/elasticsearch/index/cache/filter/weighted/WeightedFilterCache.java @@ -70,12 +70,13 @@ public class WeightedFilterCache extends AbstractIndexComponent implements Filte @Override public void close() throws ElasticSearchException { - clear(); + clear("close"); indicesFilterCache.removeRemovalListener(index.name()); } @Override - public void clear() { + public void clear(String reason) { + logger.debug("full cache clear, reason [{}]", reason); for (Object readerKey : seenReaders.keySet()) { Boolean removed = seenReaders.remove(readerKey); if (removed == null) {