From 7ec9bef0c31f339343488e15009fb5f9937170bd Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Fri, 8 Jun 2012 17:14:09 +0200 Subject: [PATCH] fix for OOM --- source/net/yacy/kelondro/table/Table.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/source/net/yacy/kelondro/table/Table.java b/source/net/yacy/kelondro/table/Table.java index 8ea1f6cbc..ed9b95f38 100644 --- a/source/net/yacy/kelondro/table/Table.java +++ b/source/net/yacy/kelondro/table/Table.java @@ -124,8 +124,15 @@ public class Table implements Index, Iterable { // initialize index and copy table final int records = Math.max(fileSize, initialSpace); final long neededRAM4table = 200L * 1024L * 1024L + records * (rowdef.objectsize + rowdef.primaryKeyLength) * 3L / 2L; - this.table = ((exceed134217727 || neededRAM4table < maxarraylength) && useTailCache && MemoryControl.available() > neededRAM4table) ? - new RowSet(this.taildef, records) : null; + this.table = null; + try { + this.table = ((exceed134217727 || neededRAM4table < maxarraylength) && + useTailCache && MemoryControl.request(neededRAM4table, true)) ? new RowSet(this.taildef, records) : null; + } catch (RowSpaceExceededException e) { + this.table = null; + } catch (Throwable e) { + this.table = null; + } Log.logInfo("TABLE", "initialization of " + tablefile.getName() + ". table copy: " + ((this.table == null) ? "no" : "yes") + ", available RAM: " + (MemoryControl.available() / 1024 / 1024) + "MB, needed: " + (neededRAM4table/1024/1024 + 200) + "MB, allocating space for " + records + " entries"); final long neededRAM4index = 200L * 1024L * 1024L + records * rowdef.primaryKeyLength * 3L / 2L; if (!MemoryControl.request(neededRAM4index, true)) {