Skip to content

Commit

Permalink
better oom-awareness of miss-cache in cache
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6338 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Sep 22, 2009
1 parent 3e9dcfc commit efa7fb3
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions source/de/anomic/kelondro/index/Cache.java
Expand Up @@ -142,16 +142,19 @@ private final Map<String, String> memoryStats() {
}


/**
* checks for space in the miss cache
* @return true if it is allowed to write into this cache
*/
private boolean checkMissSpace() {
// returns true if it is allowed to write into this cache
long available = MemoryControl.available();
if (available - 2 * 1024 * 1024 < readMissCache.memoryNeededForGrow()) {
if (readMissCache != null) {
readMissCache.clear();
}
return false;
}
return true;
if (readMissCache == null) return false;
long available = MemoryControl.available();
if (available - 2 * 1024 * 1024 < readMissCache.memoryNeededForGrow()) {
readMissCache.clear();
}
available = MemoryControl.available();
return (available - 2 * 1024 * 1024 > readMissCache.memoryNeededForGrow());
}

/**
Expand All @@ -161,11 +164,11 @@ private boolean checkMissSpace() {
private boolean checkHitSpace() {
// returns true if it is allowed to write into this cache
if (readHitCache == null) return false;
long available = MemoryControl.available();
if (available - 2 * 1024 * 1024 < readHitCache.memoryNeededForGrow()) {
readHitCache.clear();
}
available = MemoryControl.available();
long available = MemoryControl.available();
if (available - 2 * 1024 * 1024 < readHitCache.memoryNeededForGrow()) {
readHitCache.clear();
}
available = MemoryControl.available();
return (available - 2 * 1024 * 1024 > readHitCache.memoryNeededForGrow());
}

Expand Down Expand Up @@ -231,7 +234,7 @@ public synchronized Row.Entry get(final byte[] key) throws IOException {
entry = index.get(key);
// learn from result
if (entry == null) {
if ((checkMissSpace()) && (readMissCache != null)) {
if (checkMissSpace()) {
final Row.Entry dummy = readMissCache.replace(readMissCache.row().newEntry(key));
if (dummy == null) this.hasnotUnique++; else this.hasnotDouble++;
}
Expand Down Expand Up @@ -377,7 +380,7 @@ public synchronized Row.Entry remove(final byte[] key) throws IOException {
checkMissSpace();

// add entry to miss-cache
if (readMissCache != null) {
if (checkMissSpace()) {
// set the miss cache; if there was already an entry we know that the return value must be null
final Row.Entry dummy = readMissCache.replace(readMissCache.row().newEntry(key));
if (dummy == null) {
Expand Down Expand Up @@ -409,7 +412,7 @@ public synchronized Row.Entry removeOne() throws IOException {
final Row.Entry entry = index.removeOne();
if (entry == null) return null;
final byte[] key = entry.getPrimaryKeyBytes();
if (readMissCache != null) {
if (checkMissSpace()) {
final Row.Entry dummy = readMissCache.replace(readMissCache.row().newEntry(key));
if (dummy == null) this.hasnotUnique++; else this.hasnotDouble++;
}
Expand Down Expand Up @@ -444,10 +447,10 @@ public String filename() {
return index.filename();
}

public void clear() throws IOException {
this.index.clear();
init();
}
public void clear() throws IOException {
this.index.clear();
init();
}

public void deleteOnExit() {
this.index.deleteOnExit();
Expand Down

0 comments on commit efa7fb3

Please sign in to comment.