add logging with a reason why the cache is cleared (filter and field)

This commit is contained in:
Shay Banon 2012-05-01 16:36:05 +03:00
parent d01f925000
commit 771225ccc9
9 changed files with 23 additions and 20 deletions

View File

@ -122,15 +122,15 @@ public class TransportClearIndicesCacheAction extends TransportBroadcastOperatio
boolean clearedAtLeastOne = false; boolean clearedAtLeastOne = false;
if (request.filterCache()) { if (request.filterCache()) {
clearedAtLeastOne = true; clearedAtLeastOne = true;
service.cache().filter().clear(); service.cache().filter().clear("api");
} }
if (request.fieldDataCache()) { if (request.fieldDataCache()) {
clearedAtLeastOne = true; clearedAtLeastOne = true;
if (request.fields() == null || request.fields().length == 0) { if (request.fields() == null || request.fields().length == 0) {
service.cache().fieldData().clear(); service.cache().fieldData().clear("api");
} else { } else {
for (String field : request.fields()) { 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) { if (request.fields() != null && request.fields().length > 0) {
// only clear caches relating to the specified fields // only clear caches relating to the specified fields
for (String field : request.fields()) { for (String field : request.fields()) {
service.cache().fieldData().clear(field); service.cache().fieldData().clear("api", field);
} }
} else { } else {
service.cache().clear(); service.cache().clear("api");
} }
} }
service.cache().invalidateCache(); service.cache().invalidateCache();

View File

@ -138,9 +138,9 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo
bloomCache.clear(reader); bloomCache.clear(reader);
} }
public void clear() { public void clear(String reason) {
filterCache.clear(); filterCache.clear(reason);
fieldDataCache.clear(); fieldDataCache.clear(reason);
idCache.clear(); idCache.clear();
queryParserCache.clear(); queryParserCache.clear();
bloomCache.clear(); bloomCache.clear();

View File

@ -36,9 +36,9 @@ public interface FieldDataCache extends IndexComponent, CloseableComponent {
String type(); String type();
void clear(String fieldName); void clear(String reason, String fieldName);
void clear(); void clear(String reason);
void clear(IndexReader reader); void clear(IndexReader reader);

View File

@ -54,12 +54,12 @@ public class NoneFieldDataCache extends AbstractIndexComponent implements FieldD
} }
@Override @Override
public void clear(String fieldName) { public void clear(String reason, String fieldName) {
} }
@Override @Override
public void clear() { public void clear(String reason) {
} }
@Override @Override

View File

@ -125,7 +125,7 @@ public class ResidentFieldDataCache extends AbstractConcurrentMapFieldDataCache
ResidentFieldDataCache.this.expire = expire; ResidentFieldDataCache.this.expire = expire;
} }
if (changed) { if (changed) {
clear(); clear("update_settings");
} }
} }
} }

View File

@ -53,18 +53,20 @@ public abstract class AbstractConcurrentMapFieldDataCache extends AbstractIndexC
@Override @Override
public void close() throws ElasticSearchException { public void close() throws ElasticSearchException {
clear(); clear("close");
} }
@Override @Override
public void clear(String fieldName) { public void clear(String reason, String fieldName) {
logger.debug("clearing field [{}] cache, reason [{}]", fieldName, reason);
for (Map.Entry<Object, Cache<String, FieldData>> entry : cache.entrySet()) { for (Map.Entry<Object, Cache<String, FieldData>> entry : cache.entrySet()) {
entry.getValue().invalidate(fieldName); entry.getValue().invalidate(fieldName);
} }
} }
@Override @Override
public void clear() { public void clear(String reason) {
logger.debug("full cache clear, reason [{}]", reason);
cache.clear(); cache.clear();
} }

View File

@ -47,7 +47,7 @@ public interface FilterCache extends IndexComponent, CloseableComponent {
void clear(IndexReader reader); void clear(IndexReader reader);
void clear(); void clear(String reason);
EntriesStats entriesStats(); EntriesStats entriesStats();

View File

@ -60,7 +60,7 @@ public class NoneFilterCache extends AbstractIndexComponent implements FilterCac
} }
@Override @Override
public void clear() { public void clear(String reason) {
// nothing to do here // nothing to do here
} }

View File

@ -70,12 +70,13 @@ public class WeightedFilterCache extends AbstractIndexComponent implements Filte
@Override @Override
public void close() throws ElasticSearchException { public void close() throws ElasticSearchException {
clear(); clear("close");
indicesFilterCache.removeRemovalListener(index.name()); indicesFilterCache.removeRemovalListener(index.name());
} }
@Override @Override
public void clear() { public void clear(String reason) {
logger.debug("full cache clear, reason [{}]", reason);
for (Object readerKey : seenReaders.keySet()) { for (Object readerKey : seenReaders.keySet()) {
Boolean removed = seenReaders.remove(readerKey); Boolean removed = seenReaders.remove(readerKey);
if (removed == null) { if (removed == null) {