fix for (false) oom

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7484 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent d2eb2fe8d9
commit 6083f2f171

@ -51,7 +51,7 @@ import net.yacy.kelondro.util.MemoryControl;
public class HeapReader { public class HeapReader {
public final static long keepFreeMem = 20 * 1024 * 1024; //public final static long keepFreeMem = 20 * 1024 * 1024;
// input values // input values
protected int keylength; // the length of the primary key protected int keylength; // the length of the primary key
@ -414,12 +414,18 @@ public class HeapReader {
index.remove(key); index.remove(key);
return null; return null;
} }
if (MemoryControl.available() < len * 2 + keepFreeMem) { long memr = len + index.row().primaryKeyLength + 64;
if (!MemoryControl.request(len * 2 + keepFreeMem, true)) throw new RowSpaceExceededException(len * 2 + keepFreeMem, "HeapReader.get()"); // not enough memory available for this blob if (MemoryControl.available() < memr) {
if (!MemoryControl.request(memr, true)) throw new RowSpaceExceededException(memr, "HeapReader.get()/check"); // not enough memory available for this blob
} }
// read the key // read the key
final byte[] keyf = new byte[index.row().primaryKeyLength]; byte[] keyf;
try {
keyf = new byte[index.row().primaryKeyLength];
} catch (OutOfMemoryError e) {
throw new RowSpaceExceededException(index.row().primaryKeyLength, "HeapReader.get()/keyf");
}
file.readFully(keyf, 0, keyf.length); file.readFully(keyf, 0, keyf.length);
if (!this.ordering.equal(key, keyf)) { if (!this.ordering.equal(key, keyf)) {
// verification of the indexed access failed. we must re-read the index // verification of the indexed access failed. we must re-read the index
@ -435,7 +441,12 @@ public class HeapReader {
} }
// read the blob // read the blob
byte[] blob = new byte[len]; byte[] blob;
try {
blob = new byte[len];
} catch (OutOfMemoryError e) {
throw new RowSpaceExceededException(len, "HeapReader.get()/blob");
}
file.readFully(blob, 0, blob.length); file.readFully(blob, 0, blob.length);
return blob; return blob;

@ -177,7 +177,7 @@ public class MapHeap implements Map<byte[], Map<String, String>> {
synchronized (this) { synchronized (this) {
// remove from cache // remove from cache
cache.remove(key); if (cache != null) cache.remove(key);
// remove from file // remove from file
blob.delete(key); blob.delete(key);

@ -276,8 +276,8 @@ public class RowCollection implements Iterable<Row.Entry>, Cloneable {
if (allocram == 0) return; if (allocram == 0) return;
assert chunkcache.length < elements * rowdef.objectsize : "wrong alloc computation (1): elements * rowdef.objectsize = " + (elements * rowdef.objectsize) + ", chunkcache.length = " + chunkcache.length; assert chunkcache.length < elements * rowdef.objectsize : "wrong alloc computation (1): elements * rowdef.objectsize = " + (elements * rowdef.objectsize) + ", chunkcache.length = " + chunkcache.length;
assert allocram > chunkcache.length : "wrong alloc computation (2): allocram = " + allocram + ", chunkcache.length = " + chunkcache.length; assert allocram > chunkcache.length : "wrong alloc computation (2): allocram = " + allocram + ", chunkcache.length = " + chunkcache.length;
if (allocram > Integer.MAX_VALUE || !MemoryControl.request(allocram, true)) if (allocram > Integer.MAX_VALUE || !MemoryControl.request(allocram + 32, true))
throw new RowSpaceExceededException(allocram, "RowCollection grow"); throw new RowSpaceExceededException(allocram + 32, "RowCollection grow");
try { try {
final byte[] newChunkcache = new byte[(int) allocram]; // increase space final byte[] newChunkcache = new byte[(int) allocram]; // increase space
System.arraycopy(chunkcache, 0, newChunkcache, 0, chunkcache.length); System.arraycopy(chunkcache, 0, newChunkcache, 0, chunkcache.length);

Loading…
Cancel
Save