mirror of https://github.com/apache/lucene.git
SOLR-1572: ConcurrentLRUCache Integer.MAX_INT to Long
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@881906 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cb500c0534
commit
05b4be62ec
|
@ -54,6 +54,10 @@ Bug Fixes
|
||||||
to the original ValueSource.getValues(reader) so custom sources
|
to the original ValueSource.getValues(reader) so custom sources
|
||||||
will work. (yonik)
|
will work. (yonik)
|
||||||
|
|
||||||
|
* SOLR-1572: FastLRUCache correctly implemented the LRU policy only
|
||||||
|
for the first 2B accesses. (yonik)
|
||||||
|
|
||||||
|
|
||||||
Other Changes
|
Other Changes
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
|
|
@ -106,8 +106,11 @@ public class ConcurrentLRUCache<K,V> {
|
||||||
if (val == null) return null;
|
if (val == null) return null;
|
||||||
CacheEntry e = new CacheEntry(key, val, stats.accessCounter.incrementAndGet());
|
CacheEntry e = new CacheEntry(key, val, stats.accessCounter.incrementAndGet());
|
||||||
CacheEntry oldCacheEntry = map.put(key, e);
|
CacheEntry oldCacheEntry = map.put(key, e);
|
||||||
|
int currentSize;
|
||||||
if (oldCacheEntry == null) {
|
if (oldCacheEntry == null) {
|
||||||
stats.size.incrementAndGet();
|
currentSize = stats.size.incrementAndGet();
|
||||||
|
} else {
|
||||||
|
currentSize = stats.size.get();
|
||||||
}
|
}
|
||||||
if (islive) {
|
if (islive) {
|
||||||
stats.putCounter.incrementAndGet();
|
stats.putCounter.incrementAndGet();
|
||||||
|
@ -125,7 +128,7 @@ public class ConcurrentLRUCache<K,V> {
|
||||||
//
|
//
|
||||||
// Thread safety note: isCleaning read is piggybacked (comes after) other volatile reads
|
// Thread safety note: isCleaning read is piggybacked (comes after) other volatile reads
|
||||||
// in this method.
|
// in this method.
|
||||||
if (stats.size.get() > upperWaterMark && !isCleaning) {
|
if (currentSize > upperWaterMark && !isCleaning) {
|
||||||
if (newThreadForCleanup) {
|
if (newThreadForCleanup) {
|
||||||
new Thread() {
|
new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -174,7 +177,7 @@ public class ConcurrentLRUCache<K,V> {
|
||||||
int numKept = 0;
|
int numKept = 0;
|
||||||
long newestEntry = timeCurrent;
|
long newestEntry = timeCurrent;
|
||||||
long newNewestEntry = -1;
|
long newNewestEntry = -1;
|
||||||
long newOldestEntry = Integer.MAX_VALUE;
|
long newOldestEntry = Long.MAX_VALUE;
|
||||||
|
|
||||||
int wantToKeep = lowerWaterMark;
|
int wantToKeep = lowerWaterMark;
|
||||||
int wantToRemove = sz - lowerWaterMark;
|
int wantToRemove = sz - lowerWaterMark;
|
||||||
|
@ -222,8 +225,8 @@ public class ConcurrentLRUCache<K,V> {
|
||||||
// over the values we collected, with updated min and max values.
|
// over the values we collected, with updated min and max values.
|
||||||
while (sz - numRemoved > acceptableWaterMark && --numPasses>=0) {
|
while (sz - numRemoved > acceptableWaterMark && --numPasses>=0) {
|
||||||
|
|
||||||
oldestEntry = newOldestEntry == Integer.MAX_VALUE ? oldestEntry : newOldestEntry;
|
oldestEntry = newOldestEntry == Long.MAX_VALUE ? oldestEntry : newOldestEntry;
|
||||||
newOldestEntry = Integer.MAX_VALUE;
|
newOldestEntry = Long.MAX_VALUE;
|
||||||
newestEntry = newNewestEntry;
|
newestEntry = newNewestEntry;
|
||||||
newNewestEntry = -1;
|
newNewestEntry = -1;
|
||||||
wantToKeep = lowerWaterMark - numKept;
|
wantToKeep = lowerWaterMark - numKept;
|
||||||
|
@ -270,8 +273,8 @@ public class ConcurrentLRUCache<K,V> {
|
||||||
// inserting into a priority queue
|
// inserting into a priority queue
|
||||||
if (sz - numRemoved > acceptableWaterMark) {
|
if (sz - numRemoved > acceptableWaterMark) {
|
||||||
|
|
||||||
oldestEntry = newOldestEntry == Integer.MAX_VALUE ? oldestEntry : newOldestEntry;
|
oldestEntry = newOldestEntry == Long.MAX_VALUE ? oldestEntry : newOldestEntry;
|
||||||
newOldestEntry = Integer.MAX_VALUE;
|
newOldestEntry = Long.MAX_VALUE;
|
||||||
newestEntry = newNewestEntry;
|
newestEntry = newNewestEntry;
|
||||||
newNewestEntry = -1;
|
newNewestEntry = -1;
|
||||||
wantToKeep = lowerWaterMark - numKept;
|
wantToKeep = lowerWaterMark - numKept;
|
||||||
|
@ -338,7 +341,7 @@ public class ConcurrentLRUCache<K,V> {
|
||||||
// System.out.println("items removed:" + numRemoved + " numKept=" + numKept + " initialQueueSize="+ wantToRemove + " finalQueueSize=" + queue.size() + " sz-numRemoved=" + (sz-numRemoved));
|
// 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;
|
this.oldestEntry = oldestEntry;
|
||||||
} finally {
|
} finally {
|
||||||
isCleaning = false; // set before markAndSweep.unlock() for visibility
|
isCleaning = false; // set before markAndSweep.unlock() for visibility
|
||||||
|
|
Loading…
Reference in New Issue