fix for OOM case when a kelondroTree Node cache grows

See also: http://www.yacy-forum.de/viewtopic.php?p=33275#33275

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3499 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 18 years ago
parent b374812f01
commit 602ac42010

@ -36,6 +36,7 @@ import java.util.Map;
import java.util.TreeMap;
import de.anomic.kelondro.kelondroRow.Entry;
import de.anomic.server.serverMemory;
public class kelondroCache implements kelondroIndex {
@ -157,7 +158,7 @@ public class kelondroCache implements kelondroIndex {
}
private int cacheGrowStatus() {
return kelondroRecords.cacheGrowStatus(memStopGrow, memStartShrink);
return kelondroRecords.cacheGrowStatus(serverMemory.available(), memStopGrow, memStartShrink);
}
private void flushUnique() throws IOException {

@ -24,87 +24,68 @@
package de.anomic.kelondro;
import java.io.IOException;
import java.util.Iterator;
//import java.util.Random;
public class kelondroIntBytesMap {
private kelondroIndex index;
private kelondroRowSet index;
public kelondroIntBytesMap(int payloadSize, int initSize) {
index = new kelondroRowSet(new kelondroRow("Cardinal key-4 {b256}, byte[] payload-" + payloadSize, kelondroNaturalOrder.naturalOrder, 0), initSize);
}
public int size() {
try {
return index.size();
} catch (IOException e) {
return 0;
}
return index.size();
}
public long memoryNeededForGrow() {
return index.memoryNeededForGrow();
}
public byte[] getb(int ii) {
kelondroRow.Entry indexentry;
try {indexentry = index.get(kelondroNaturalOrder.encodeLong((long) ii, 4));} catch (IOException e) {return null;}
indexentry = index.get(kelondroNaturalOrder.encodeLong((long) ii, 4));
if (indexentry == null) return null;
return indexentry.getColBytes(1);
}
public void addb(int ii, byte[] value) {
kelondroRow.Entry newentry;
try {
newentry = index.row().newEntry();
newentry.setCol(0, (long) ii);
newentry.setCol(1, value);
index.addUnique(newentry);
} catch (IOException e) {}
newentry = index.row().newEntry();
newentry.setCol(0, (long) ii);
newentry.setCol(1, value);
index.addUnique(newentry);
}
public byte[] putb(int ii, byte[] value) {
kelondroRow.Entry newentry;
try {
newentry = index.row().newEntry();
newentry.setCol(0, (long) ii);
newentry.setCol(1, value);
kelondroRow.Entry oldentry = index.put(newentry);
if (oldentry == null) return null;
return oldentry.getColBytes(1);
} catch (IOException e) {
return null;
}
newentry = index.row().newEntry();
newentry.setCol(0, (long) ii);
newentry.setCol(1, value);
kelondroRow.Entry oldentry = index.put(newentry);
if (oldentry == null) return null;
return oldentry.getColBytes(1);
}
public byte[] removeb(int ii) {
try {
if (index.size() == 0) return null;
kelondroRow.Entry indexentry = index.remove(kelondroNaturalOrder.encodeLong((long) ii, 4));
if (indexentry == null) return null;
return indexentry.getColBytes(1);
} catch (IOException e) {
return null;
}
if (index.size() == 0) return null;
kelondroRow.Entry indexentry = index.remove(kelondroNaturalOrder.encodeLong((long) ii, 4));
if (indexentry == null) return null;
return indexentry.getColBytes(1);
}
public byte[] removeoneb() {
try {
if (index.size() == 0) return null;
kelondroRow.Entry indexentry = index.removeOne();
if (indexentry == null) return null;
return indexentry.getColBytes(1);
} catch (IOException e) {
return null;
}
if (index.size() == 0) return null;
kelondroRow.Entry indexentry = index.removeOne();
if (indexentry == null) return null;
return indexentry.getColBytes(1);
}
public Iterator rows() {
try {
return index.rows(true, null);
} catch (IOException e) {
return null;
}
return index.rows(true, null);
}
public void flush() {

@ -685,15 +685,16 @@ public class kelondroRecords {
}
private int cacheGrowStatus() {
return cacheGrowStatus(memStopGrow, memStartShrink);
long available = serverMemory.available();
if ((cacheHeaders != null) && (available < cacheHeaders.memoryNeededForGrow())) return 0;
return cacheGrowStatus(available, memStopGrow, memStartShrink);
}
public static final int cacheGrowStatus(long stopGrow, long startShrink) {
public static final int cacheGrowStatus(long available, long stopGrow, long startShrink) {
// returns either 0, 1 or 2:
// 0: cache is not allowed to grow, but shall shrink
// 1: cache is allowed to grow, but need not to shrink
// 2: cache is allowed to grow and must not shrink
long available = serverMemory.available();
if (available > stopGrow) return 2;
if (available > startShrink) return 1;
return 0;

@ -169,6 +169,10 @@ public class kelondroRowCollection {
newChunkcache = null;
}
public final long memoryNeededForGrow() {
return (long) ((((long) (chunkcount + 1)) * ((long) rowdef.objectsize())) * growfactor);
}
public synchronized void trim(boolean plusGrowFactor) {
if (chunkcache.length == 0)
return;

Loading…
Cancel
Save