Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
fix for OOM case when a kelondroTree Node cache grows See also: http://www.yacy-forum.de/viewtopic.php?p=33275#33275
orbiter602ac4201062
diff --git a/source/de/anomic/kelondro/kelondroCache.java b/source/de/anomic/kelondro/kelondroCache.javaindex 0a260715b..ac0572f06 100644--- a/source/de/anomic/kelondro/kelondroCache.java+++ b/source/de/anomic/kelondro/kelondroCache.java@@ -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 {diff --git a/source/de/anomic/kelondro/kelondroIntBytesMap.java b/source/de/anomic/kelondro/kelondroIntBytesMap.javaindex afc9a899c..6fda2f02d 100644--- a/source/de/anomic/kelondro/kelondroIntBytesMap.java+++ b/source/de/anomic/kelondro/kelondroIntBytesMap.java@@ -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() {diff --git a/source/de/anomic/kelondro/kelondroRecords.java b/source/de/anomic/kelondro/kelondroRecords.javaindex 1c9ac7581..b0b8c6468 100644--- a/source/de/anomic/kelondro/kelondroRecords.java+++ b/source/de/anomic/kelondro/kelondroRecords.java@@ -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;diff --git a/source/de/anomic/kelondro/kelondroRowCollection.java b/source/de/anomic/kelondro/kelondroRowCollection.javaindex 6e7db1518..ac689083a 100644--- a/source/de/anomic/kelondro/kelondroRowCollection.java+++ b/source/de/anomic/kelondro/kelondroRowCollection.java@@ -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;