From dd8e9e293093ef73b6cbd20afe3f09765b9bec59 Mon Sep 17 00:00:00 2001 From: fjy Date: Tue, 8 Apr 2014 16:23:24 -0700 Subject: [PATCH] fix concurrent modification exceptions in local cache --- .../java/io/druid/client/cache/MapCache.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/io/druid/client/cache/MapCache.java b/server/src/main/java/io/druid/client/cache/MapCache.java index fd03fac61d7..5221fd0ca91 100644 --- a/server/src/main/java/io/druid/client/cache/MapCache.java +++ b/server/src/main/java/io/druid/client/cache/MapCache.java @@ -77,7 +77,10 @@ public class MapCache implements Cache @Override public byte[] get(NamedKey key) { - final byte[] retVal = baseMap.get(computeKey(getNamespaceId(key.namespace), key.key)); + final byte[] retVal; + synchronized (clearLock) { + retVal = baseMap.get(computeKey(getNamespaceId(key.namespace), key.key)); + } if (retVal == null) { missCount.incrementAndGet(); } else { @@ -90,7 +93,7 @@ public class MapCache implements Cache public void put(NamedKey key, byte[] value) { synchronized (clearLock) { - baseMap.put(computeKey(getNamespaceId(key.namespace), key.key), value); + baseMap.put(computeKey(getNamespaceId(key.namespace), key.key), value); } } @@ -98,7 +101,7 @@ public class MapCache implements Cache public Map getBulk(Iterable keys) { Map retVal = Maps.newHashMap(); - for(NamedKey key : keys) { + for (NamedKey key : keys) { retVal.put(key, get(key)); } return retVal; @@ -110,7 +113,9 @@ public class MapCache implements Cache byte[] idBytes; synchronized (namespaceId) { idBytes = getNamespaceId(namespace); - if(idBytes == null) return; + if (idBytes == null) { + return; + } namespaceId.remove(namespace); } @@ -150,7 +155,8 @@ public class MapCache implements Cache return retVal; } - public boolean isLocal() { + public boolean isLocal() + { return true; } }