better oom-awareness of miss-cache in cache

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6338 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
orbiter 2009-09-22 15:01:29 +00:00
parent 3e9dcfc204
commit efa7fb34f0

View File

@ -142,16 +142,19 @@ public class Cache implements ObjectIndex {
} }
/**
* checks for space in the miss cache
* @return true if it is allowed to write into this cache
*/
private boolean checkMissSpace() { private boolean checkMissSpace() {
// returns true if it is allowed to write into this cache // returns true if it is allowed to write into this cache
long available = MemoryControl.available(); if (readMissCache == null) return false;
if (available - 2 * 1024 * 1024 < readMissCache.memoryNeededForGrow()) { long available = MemoryControl.available();
if (readMissCache != null) { if (available - 2 * 1024 * 1024 < readMissCache.memoryNeededForGrow()) {
readMissCache.clear(); readMissCache.clear();
} }
return false; available = MemoryControl.available();
} return (available - 2 * 1024 * 1024 > readMissCache.memoryNeededForGrow());
return true;
} }
/** /**
@ -161,11 +164,11 @@ public class Cache implements ObjectIndex {
private boolean checkHitSpace() { private boolean checkHitSpace() {
// returns true if it is allowed to write into this cache // returns true if it is allowed to write into this cache
if (readHitCache == null) return false; if (readHitCache == null) return false;
long available = MemoryControl.available(); long available = MemoryControl.available();
if (available - 2 * 1024 * 1024 < readHitCache.memoryNeededForGrow()) { if (available - 2 * 1024 * 1024 < readHitCache.memoryNeededForGrow()) {
readHitCache.clear(); readHitCache.clear();
} }
available = MemoryControl.available(); available = MemoryControl.available();
return (available - 2 * 1024 * 1024 > readHitCache.memoryNeededForGrow()); return (available - 2 * 1024 * 1024 > readHitCache.memoryNeededForGrow());
} }
@ -231,7 +234,7 @@ public class Cache implements ObjectIndex {
entry = index.get(key); entry = index.get(key);
// learn from result // learn from result
if (entry == null) { if (entry == null) {
if ((checkMissSpace()) && (readMissCache != null)) { if (checkMissSpace()) {
final Row.Entry dummy = readMissCache.replace(readMissCache.row().newEntry(key)); final Row.Entry dummy = readMissCache.replace(readMissCache.row().newEntry(key));
if (dummy == null) this.hasnotUnique++; else this.hasnotDouble++; if (dummy == null) this.hasnotUnique++; else this.hasnotDouble++;
} }
@ -377,7 +380,7 @@ public class Cache implements ObjectIndex {
checkMissSpace(); checkMissSpace();
// add entry to miss-cache // 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 // 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)); final Row.Entry dummy = readMissCache.replace(readMissCache.row().newEntry(key));
if (dummy == null) { if (dummy == null) {
@ -409,7 +412,7 @@ public class Cache implements ObjectIndex {
final Row.Entry entry = index.removeOne(); final Row.Entry entry = index.removeOne();
if (entry == null) return null; if (entry == null) return null;
final byte[] key = entry.getPrimaryKeyBytes(); final byte[] key = entry.getPrimaryKeyBytes();
if (readMissCache != null) { if (checkMissSpace()) {
final Row.Entry dummy = readMissCache.replace(readMissCache.row().newEntry(key)); final Row.Entry dummy = readMissCache.replace(readMissCache.row().newEntry(key));
if (dummy == null) this.hasnotUnique++; else this.hasnotDouble++; if (dummy == null) this.hasnotUnique++; else this.hasnotDouble++;
} }
@ -444,10 +447,10 @@ public class Cache implements ObjectIndex {
return index.filename(); return index.filename();
} }
public void clear() throws IOException { public void clear() throws IOException {
this.index.clear(); this.index.clear();
init(); init();
} }
public void deleteOnExit() { public void deleteOnExit() {
this.index.deleteOnExit(); this.index.deleteOnExit();