You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2010/05/07 20:22:36 UTC
svn commit: r942166 - in /lucene/dev/trunk/lucene/src:
java/org/apache/lucene/index/codecs/preflex/
java/org/apache/lucene/index/codecs/standard/ java/org/apache/lucene/util/
java/org/apache/lucene/util/cache/ test/org/apache/lucene/util/cache/
Author: mikemccand
Date: Fri May 7 18:22:35 2010
New Revision: 942166
URL: http://svn.apache.org/viewvc?rev=942166&view=rev
Log:
LUCENE-2451: remove dead code in oal.util.cache; keep only DBLRUCache
Added:
lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java
- copied, changed from r942059, lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/cache/DoubleBarrelLRUCache.java
Removed:
lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/cache/
lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/cache/BaseTestLRU.java
lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/cache/TestSimpleLRUCache.java
Modified:
lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java
lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictReader.java
lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/cache/TestDoubleBarrelLRUCache.java
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java?rev=942166&r1=942165&r2=942166&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java Fri May 7 18:22:35 2010
@@ -26,7 +26,6 @@ import org.apache.lucene.index.IndexFile
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.CloseableThreadLocal;
import org.apache.lucene.util.cache.DoubleBarrelLRUCache;
-import org.apache.lucene.util.cache.Cache;
/** This stores a monotonically increasing set of <Term, TermInfo> pairs in a
* Directory. Pairs are accessed either by Term or by ordinal position the
@@ -62,7 +61,7 @@ public final class TermInfosReader {
}
}
- private final Cache<Term,TermInfoAndOrd> termsCache = new DoubleBarrelLRUCache<Term,TermInfoAndOrd>(DEFAULT_CACHE_SIZE);
+ private final DoubleBarrelLRUCache<Term,TermInfoAndOrd> termsCache = new DoubleBarrelLRUCache<Term,TermInfoAndOrd>(DEFAULT_CACHE_SIZE);
/**
* Per-thread resources managed by ThreadLocal
@@ -146,7 +145,6 @@ public final class TermInfosReader {
if (origEnum != null)
origEnum.close();
threadResources.close();
- termsCache.close();
}
/** Returns the number of term/value pairs in the set. */
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictReader.java?rev=942166&r1=942165&r2=942166&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictReader.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictReader.java Fri May 7 18:22:35 2010
@@ -37,7 +37,6 @@ import org.apache.lucene.index.codecs.Fi
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.cache.Cache;
import org.apache.lucene.util.cache.DoubleBarrelLRUCache;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.CodecUtil;
@@ -68,7 +67,7 @@ public class StandardTermsDictReader ext
private final Comparator<BytesRef> termComp;
// Caches the most recently looked-up field + terms:
- private final Cache<FieldAndTerm,TermState> termsCache;
+ private final DoubleBarrelLRUCache<FieldAndTerm,TermState> termsCache;
// Reads the terms index
private StandardTermsIndexReader indexReader;
Copied: lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java (from r942059, lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/cache/DoubleBarrelLRUCache.java)
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java?p2=lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java&p1=lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/cache/DoubleBarrelLRUCache.java&r1=942059&r2=942166&rev=942166&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/cache/DoubleBarrelLRUCache.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java Fri May 7 18:22:35 2010
@@ -41,7 +41,7 @@ import java.util.Map;
* @lucene.internal
*/
-final public class DoubleBarrelLRUCache<K,V> extends Cache<K,V> {
+final public class DoubleBarrelLRUCache<K,V> {
private final Map<K,V> cache1;
private final Map<K,V> cache2;
private final AtomicInteger countdown;
@@ -55,17 +55,7 @@ final public class DoubleBarrelLRUCache<
cache2 = new ConcurrentHashMap<K,V>();
}
- @Override
- public boolean containsKey(Object k) {
- return false;
- }
-
- @Override
- public void close() {
- }
-
- @Override @SuppressWarnings("unchecked")
- public V get(Object key) {
+ public V get(K key) {
final Map<K,V> primary;
final Map<K,V> secondary;
if (swapped) {
@@ -83,13 +73,12 @@ final public class DoubleBarrelLRUCache<
result = secondary.get(key);
if (result != null) {
// Promote to primary
- put((K) key, result);
+ put(key, result);
}
}
return result;
}
- @Override
public void put(K key, V value) {
final Map<K,V> primary;
final Map<K,V> secondary;
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/cache/TestDoubleBarrelLRUCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/cache/TestDoubleBarrelLRUCache.java?rev=942166&r1=942165&r2=942166&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/cache/TestDoubleBarrelLRUCache.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/cache/TestDoubleBarrelLRUCache.java Fri May 7 18:22:35 2010
@@ -17,8 +17,45 @@ package org.apache.lucene.util.cache;
* limitations under the License.
*/
-public class TestDoubleBarrelLRUCache extends BaseTestLRU {
+import org.apache.lucene.util.LuceneTestCase;
+public class TestDoubleBarrelLRUCache extends LuceneTestCase {
+
+ private void testCache(DoubleBarrelLRUCache<Integer,Object> cache, int n) throws Exception {
+ Object dummy = new Object();
+
+ for (int i = 0; i < n; i++) {
+ cache.put(Integer.valueOf(i), dummy);
+ }
+
+ // access every 2nd item in cache
+ for (int i = 0; i < n; i+=2) {
+ assertNotNull(cache.get(Integer.valueOf(i)));
+ }
+
+ // add n/2 elements to cache, the ones that weren't
+ // touched in the previous loop should now be thrown away
+ for (int i = n; i < n + (n / 2); i++) {
+ cache.put(Integer.valueOf(i), dummy);
+ }
+
+ // access every 4th item in cache
+ for (int i = 0; i < n; i+=4) {
+ assertNotNull(cache.get(Integer.valueOf(i)));
+ }
+
+ // add 3/4n elements to cache, the ones that weren't
+ // touched in the previous loops should now be thrown away
+ for (int i = n; i < n + (n * 3 / 4); i++) {
+ cache.put(Integer.valueOf(i), dummy);
+ }
+
+ // access every 4th item in cache
+ for (int i = 0; i < n; i+=4) {
+ assertNotNull(cache.get(Integer.valueOf(i)));
+ }
+ }
+
public void testLRUCache() throws Exception {
final int n = 100;
testCache(new DoubleBarrelLRUCache<Integer,Object>(n), n);
@@ -26,11 +63,11 @@ public class TestDoubleBarrelLRUCache ex
private class CacheThread extends Thread {
private final Object[] objs;
- private final Cache<Object,Object> c;
+ private final DoubleBarrelLRUCache<Object,Object> c;
private final long endTime;
volatile boolean failed;
- public CacheThread(Cache<Object,Object> c,
+ public CacheThread(DoubleBarrelLRUCache<Object,Object> c,
Object[] objs, long endTime) {
this.c = c;
this.objs = objs;
@@ -81,7 +118,7 @@ public class TestDoubleBarrelLRUCache ex
final int CACHE_SIZE = 512;
final int OBJ_COUNT = 3*CACHE_SIZE;
- Cache<Object,Object> c = new DoubleBarrelLRUCache<Object,Object>(1024);
+ DoubleBarrelLRUCache<Object,Object> c = new DoubleBarrelLRUCache<Object,Object>(1024);
Object[] objs = new Object[OBJ_COUNT];
for(int i=0;i<OBJ_COUNT;i++) {