Author: yonik
Date: Wed Nov 18 20:00:34 2009
New Revision: 881906
URL: http://svn.apache.org/viewvc?rev=881906&view=rev
Log:
SOLR-1572: ConcurrentLRUCache Integer.MAX_INT to Long
Modified:
lucene/solr/trunk/CHANGES.txt
lucene/solr/trunk/src/common/org/apache/solr/common/util/ConcurrentLRUCache.java
Modified: lucene/solr/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=881906&r1=881905&r2=881906&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Wed Nov 18 20:00:34 2009
@@ -54,6 +54,10 @@
to the original ValueSource.getValues(reader) so custom sources
will work. (yonik)
+* SOLR-1572: FastLRUCache correctly implemented the LRU policy only
+ for the first 2B accesses. (yonik)
+
+
Other Changes
----------------------
Modified:
lucene/solr/trunk/src/common/org/apache/solr/common/util/ConcurrentLRUCache.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/common/org/apache/solr/common/util/ConcurrentLRUCache.java?rev=881906&r1=881905&r2=881906&view=diff
==============================================================================
---
lucene/solr/trunk/src/common/org/apache/solr/common/util/ConcurrentLRUCache.java
(original)
+++
lucene/solr/trunk/src/common/org/apache/solr/common/util/ConcurrentLRUCache.java
Wed Nov 18 20:00:34 2009
@@ -106,8 +106,11 @@
if (val == null) return null;
CacheEntry e = new CacheEntry(key, val,
stats.accessCounter.incrementAndGet());
CacheEntry oldCacheEntry = map.put(key, e);
+ int currentSize;
if (oldCacheEntry == null) {
- stats.size.incrementAndGet();
+ currentSize = stats.size.incrementAndGet();
+ } else {
+ currentSize = stats.size.get();
}
if (islive) {
stats.putCounter.incrementAndGet();
@@ -125,7 +128,7 @@
//
// Thread safety note: isCleaning read is piggybacked (comes after) other
volatile reads
// in this method.
- if (stats.size.get() > upperWaterMark && !isCleaning) {
+ if (currentSize > upperWaterMark && !isCleaning) {
if (newThreadForCleanup) {
new Thread() {
public void run() {
@@ -174,7 +177,7 @@
int numKept = 0;
long newestEntry = timeCurrent;
long newNewestEntry = -1;
- long newOldestEntry = Integer.MAX_VALUE;
+ long newOldestEntry = Long.MAX_VALUE;
int wantToKeep = lowerWaterMark;
int wantToRemove = sz - lowerWaterMark;
@@ -222,8 +225,8 @@
// over the values we collected, with updated min and max values.
while (sz - numRemoved > acceptableWaterMark && --numPasses>=0) {
- oldestEntry = newOldestEntry == Integer.MAX_VALUE ? oldestEntry :
newOldestEntry;
- newOldestEntry = Integer.MAX_VALUE;
+ oldestEntry = newOldestEntry == Long.MAX_VALUE ? oldestEntry :
newOldestEntry;
+ newOldestEntry = Long.MAX_VALUE;
newestEntry = newNewestEntry;
newNewestEntry = -1;
wantToKeep = lowerWaterMark - numKept;
@@ -270,8 +273,8 @@
// inserting into a priority queue
if (sz - numRemoved > acceptableWaterMark) {
- oldestEntry = newOldestEntry == Integer.MAX_VALUE ? oldestEntry :
newOldestEntry;
- newOldestEntry = Integer.MAX_VALUE;
+ oldestEntry = newOldestEntry == Long.MAX_VALUE ? oldestEntry :
newOldestEntry;
+ newOldestEntry = Long.MAX_VALUE;
newestEntry = newNewestEntry;
newNewestEntry = -1;
wantToKeep = lowerWaterMark - numKept;
@@ -338,7 +341,7 @@
// System.out.println("items removed:" + numRemoved + " numKept=" +
numKept + " initialQueueSize="+ wantToRemove + " finalQueueSize=" +
queue.size() + " sz-numRemoved=" + (sz-numRemoved));
}
- oldestEntry = newOldestEntry == Integer.MAX_VALUE ? oldestEntry :
newOldestEntry;
+ oldestEntry = newOldestEntry == Long.MAX_VALUE ? oldestEntry :
newOldestEntry;
this.oldestEntry = oldestEntry;
} finally {
isCleaning = false; // set before markAndSweep.unlock() for visibility