Apache Lucene open-source search software
LUCENE-2449: fix DBLRU cache to clone key when it promotes an entry during lookup
Michael McCandless712ce48d6757
diff --git a/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictReader.java b/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictReader.javaindex 647e4d0c9ec..82af25fe634 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictReader.java+++ b/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictReader.java@@ -296,7 +296,7 @@ public class StandardTermsDictReader extends FieldsProducer {fieldTerm.term = term;TermState cachedState;if (useCache) {- cachedState = termsCache.get(new FieldAndTerm(fieldTerm));+ cachedState = termsCache.get(fieldTerm);if (cachedState != null) {state.copy(cachedState);seekPending = true;diff --git a/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java b/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.javaindex 5074f20820b..a0dd7c19f08 100644--- a/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java+++ b/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java@@ -28,8 +28,9 @@ import java.util.Map;* <p>At any given time, one hash is primary and the other* is secondary. {@link #get} first checks primary, and if* that's a miss, checks secondary. If secondary has the- * entry, it's promoted to primary. Once primary is full,- * the secondary is cleared and the two are swapped.</p>+ * entry, it's promoted to primary (<b>NOTE</b>: the key is+ * cloned at this point). Once primary is full, the+ * secondary is cleared and the two are swapped.</p>** <p>This is not as space efficient as other possible* concurrent approaches (see LUCENE-2075): to achieve@@ -41,7 +42,7 @@ import java.util.Map;* @lucene.internal*/-final public class DoubleBarrelLRUCache<K,V> {+final public class DoubleBarrelLRUCache<K extends DoubleBarrelLRUCache.CloneableKey,V> {public static abstract class CloneableKey {abstract public Object clone();@@ -60,6 +61,7 @@ final public class DoubleBarrelLRUCache<K,V> {cache2 = new ConcurrentHashMap<K,V>();}+ @SuppressWarnings("unchecked")public V get(K key) {final Map<K,V> primary;final Map<K,V> secondary;@@ -78,7 +80,7 @@ final public class DoubleBarrelLRUCache<K,V> {result = secondary.get(key);if (result != null) {// Promote to primary- put(key, result);+ put((K) key.clone(), result);}}return result;