Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
- better OOM protection - better memory allocation for FlexTable indexes - splitting between static index and dynamic index (only the dynamic part must grow) - to enable a merge-iteration of new splittet index, a huge number of classes needed to be adopted for new iterator classes - added new iterator classes that support cloneable iterators - adopted all iterator classes to implement cloneable itarators
orbiterd755a8026d00
diff --git a/htroot/IndexControl_p.java b/htroot/IndexControl_p.javaindex e927df6d9..e5ae91789 100644--- a/htroot/IndexControl_p.java+++ b/htroot/IndexControl_p.java@@ -64,6 +64,7 @@ import de.anomic.index.indexContainer;import de.anomic.index.indexRWIEntry;import de.anomic.plasma.plasmaURL;import de.anomic.index.indexURLEntry;+import de.anomic.kelondro.kelondroRotateIterator;import de.anomic.net.URL;import de.anomic.plasma.plasmaCondenser;import de.anomic.plasma.plasmaSwitchboard;@@ -363,7 +364,7 @@ public class IndexControl_p {// generate listif (post.containsKey("urlhashsimilar")) {try {- final Iterator entryIt = switchboard.wordIndex.loadedURL.entries(true, true, urlhash);+ final Iterator entryIt = new kelondroRotateIterator(switchboard.wordIndex.loadedURL.entries(true, urlhash));StringBuffer result = new StringBuffer("Sequential List of URL-Hashes:<br>");indexURLEntry entry;int i = 0;diff --git a/htroot/PerformanceMemory_p.html b/htroot/PerformanceMemory_p.htmlindex 77ed44d17..d8c21ecbb 100644--- a/htroot/PerformanceMemory_p.html+++ b/htroot/PerformanceMemory_p.html@@ -76,19 +76,23 @@<tr class="TableHeader" valign="bottom"><td>Table</td><td>Chunk Size</td>- <td>Count</td>- <td>Used Memory</td>+ <td>RO Count</td>+ <td>RO Used Memory</td>+ <td>RW Count</td>+ <td>RW Used Memory</td></tr>#{TableList}#<tr class="TableCellLight"><td align="left" class="TableCellDark">#[tableIndexPath]#</td><td align="right">#[tableIndexChunkSize]#</td>- <td align="right">#[tableIndexCount]#</td>- <td align="right">#[tableIndexMem]# MB</td>+ <td align="right">#[tableROIndexCount]#</td>+ <td align="right">#[tableROIndexMem]# MB</td>+ <td align="right">#[tableRWIndexCount]#</td>+ <td align="right">#[tableRWIndexMem]# MB</td></tr>#{/TableList}#<tr class="TableCellDark">- <td colspan="4">Total Mem = #[TableIndexTotalMem]# MB</td>+ <td colspan="6">Total Mem = #[TableIndexTotalMem]# MB</td></tr></table>diff --git a/htroot/PerformanceMemory_p.java b/htroot/PerformanceMemory_p.javaindex fadb93626..57b827a52 100644--- a/htroot/PerformanceMemory_p.java+++ b/htroot/PerformanceMemory_p.java@@ -116,50 +116,31 @@ public class PerformanceMemory_p {String filename;Map map;int p, c = 0;- long mem, totalmem = 0;+ long ROmem, RWmem, totalmem = 0;while (i.hasNext()) {filename = (String) i.next();map = (Map) kelondroFlexTable.memoryStats(filename);p = filename.indexOf("DATA");- mem = Long.parseLong((String) map.get("tableIndexMem"));- totalmem += mem;+ ROmem = Long.parseLong((String) map.get("tableROIndexMem"));+ RWmem = Long.parseLong((String) map.get("tableRWIndexMem"));+ totalmem += ROmem;+ totalmem += RWmem;prop.put("TableList_" + c + "_tableIndexPath", filename.substring(p));prop.put("TableList_" + c + "_tableIndexChunkSize", map.get("tableIndexChunkSize"));- prop.put("TableList_" + c + "_tableIndexCount", map.get("tableIndexCount"));- prop.put("TableList_" + c + "_tableIndexMem", mem / (1024 * 1024));+ prop.put("TableList_" + c + "_tableROIndexCount", map.get("tableROIndexCount"));+ prop.put("TableList_" + c + "_tableROIndexMem", ROmem / (1024 * 1024));+ prop.put("TableList_" + c + "_tableRWIndexCount", map.get("tableRWIndexCount"));+ prop.put("TableList_" + c + "_tableRWIndexMem", RWmem / (1024 * 1024));c++;}prop.put("TableList", c);prop.put("TableIndexTotalMem", totalmem / (1024 * 1024));-- /*- * <p><strong>FlexTable RAM Index:</strong></p>- <table border="0" cellpadding="2" cellspacing="1">- <tr class="TableHeader" valign="bottom">- <td>Table</td>- <td>Chunk Size</td>- <td>Count</td>- <td>Used Memory</td>- </tr>- #{TableList}#- <tr class="TableCellLight">- <td align="left">#[tableIndexPath]#</td>- <td align="right">#[tableIndexChunkSize]#</td>- <td align="right">#[tableIndexCount]#</td>- <td align="right">#[tableIndexMem]# MB</td>- </tr>- #{/TableList}#- <tr class="TableCellDark">- <td colspan="10">Total Mem = #[TableIndexTotalMem]# MB</td>- </tr>- </table></p>- */-// write node cache tablei = kelondroRecords.filenames();c = 0;totalmem = 0;+ long mem;while (i.hasNext()) {filename = (String) i.next();map = (Map) kelondroRecords.memoryStats(filename);@@ -226,35 +207,7 @@ public class PerformanceMemory_p {prop.put("objectCacheStartShrink", kelondroCache.getMemStartShrink() / (1024 * 1024));prop.put("objectHitCacheTotalMem", totalhitmem / (1024 * 1024));prop.put("objectMissCacheTotalMem", totalmissmem / (1024 * 1024));- /*- #{ObjectList}#- <tr class="TableCellLight">- <td align="left">#[objectHitCachePath]#</td>- <td align="right">#[objectHitChunkSize]#</td>- <td align="right">#[objectHitCacheCount]#</td>- <td align="right">#[objectHitCacheMem]# MB</td>- <td align="right">#[objectHitCacheReadHit]#</td>- <td align="right">#[objectHitCacheReadMiss]#</td>- <td align="right">#[objectHitCacheWriteUnique]#</td>- <td align="right">#[objectHitCacheWriteDouble]#</td>- <td align="right">#[objectHitCacheDeletes]#</td>- <td align="right">#[objectHitCacheFlushes]#</td>- <td align="right">#[objectMissChunkSize]#</td>- <td align="right">#[objectMissCacheCount]#</td>- <td align="right">#[objectMissCacheMem]# MB</td>- <td align="right">#[objectMissCacheReadHit]#</td>- <td align="right">#[objectMissCacheReadMiss]#</td>- <td align="right">#[objectMissCacheWriteUnique]#</td>- <td align="right">#[objectMissCacheWriteDouble]#</td>- <td align="right">#[objectMissCacheDeletes]#</td>- <td align="right">#[objectMissCacheFlushes]#</td>- </tr>- #{/ObjectList}#- <tr class="TableCellDark">- <td colspan="10">Total Mem: #[objectHitCacheTotalMem]# MB (hit), #[objectMissCacheTotalMem]# MB (miss); Stop Grow when #[objectCacheStopGrow]# MB available left; Start Shrink when #[objectCacheStartShrink]# MB availabe left</td>- </tr>- </table></p>- */+// parse initialization memory settingsString Xmx = env.getConfig("javastart_Xmx", "Xmx64m").substring(3);prop.put("Xmx", Xmx.substring(0, Xmx.length() - 1));diff --git a/htroot/PerformanceQueues_p.java b/htroot/PerformanceQueues_p.javaindex 2f3b095ca..0107bd20b 100644--- a/htroot/PerformanceQueues_p.java+++ b/htroot/PerformanceQueues_p.java@@ -173,7 +173,7 @@ public class PerformanceQueues_p {prop.put("table_" + c + "_busysleep", busysleep);prop.put("table_" + c + "_memprereq", memprereq / 1024);// disallow setting of memprereq for indexer to prevent db from throwing OOMs- prop.put("table_" + c + "_disabled", /*(threadName.endsWith("_indexing")) ? 1 :*/ 0);+ prop.put("table_" + c + "_disabled", (threadName.endsWith("_indexing")) ? 1 : 0);c++;}prop.put("table", c);diff --git a/source/dbtest.java b/source/dbtest.javaindex 4bb071c5b..129614913 100644--- a/source/dbtest.java+++ b/source/dbtest.java@@ -17,6 +17,7 @@ import javax.imageio.ImageIO;import de.anomic.kelondro.kelondroBase64Order;import de.anomic.kelondro.kelondroCache;+import de.anomic.kelondro.kelondroCloneableIterator;import de.anomic.kelondro.kelondroFlexSplitTable;import de.anomic.kelondro.kelondroFlexTable;import de.anomic.kelondro.kelondroIndex;@@ -337,9 +338,9 @@ public class dbtest {if (command.equals("list")) {Iterator i = null;- if (table instanceof kelondroSplittedTree) i = ((kelondroSplittedTree) table).rows(true, false, null);- if (table instanceof kelondroTree) i = ((kelondroTree) table).rows(true, false, null);- if (table instanceof dbTable) i = ((dbTable) table).rows(true, false, null);+ if (table instanceof kelondroSplittedTree) i = ((kelondroSplittedTree) table).rows(true, null);+ if (table instanceof kelondroTree) i = ((kelondroTree) table).rows(true, null);+ if (table instanceof dbTable) i = ((dbTable) table).rows(true, null);byte[][] row;while (i.hasNext()) {row = (byte[][]) i.next();@@ -602,7 +603,7 @@ final class dbTable implements kelondroIndex {return null;}- public Iterator rows(boolean up, boolean rotating, byte[] startKey) throws IOException {+ public kelondroCloneableIterator rows(boolean up, byte[] startKey) throws IOException {// Objects are of type byte[][]return null;}diff --git a/source/de/anomic/data/bookmarksDB.java b/source/de/anomic/data/bookmarksDB.javaindex 3cef6f026..04aa5ec51 100644--- a/source/de/anomic/data/bookmarksDB.java+++ b/source/de/anomic/data/bookmarksDB.java@@ -74,6 +74,7 @@ import de.anomic.htmlFilter.htmlFilterContentScraper;import de.anomic.htmlFilter.htmlFilterWriter;import de.anomic.plasma.plasmaCondenser;import de.anomic.plasma.plasmaURL;+import de.anomic.kelondro.kelondroCloneableIterator;import de.anomic.kelondro.kelondroDyn;import de.anomic.kelondro.kelondroException;import de.anomic.kelondro.kelondroMapObjects;@@ -873,7 +874,7 @@ public class bookmarksDB {}}public class tagIterator implements Iterator{- kelondroDyn.dynKeyIterator tagIter;+ kelondroCloneableIterator tagIter;bookmarksDB.Tag nextEntry;public tagIterator(boolean up) throws IOException {flushTagCache(); //XXX: This costs performace :-((diff --git a/source/de/anomic/data/userDB.java b/source/de/anomic/data/userDB.javaindex c25f1c50a..1c74ccf04 100644--- a/source/de/anomic/data/userDB.java+++ b/source/de/anomic/data/userDB.java@@ -56,6 +56,7 @@ import java.util.Random;import de.anomic.http.httpHeader;import de.anomic.kelondro.kelondroBase64Order;+import de.anomic.kelondro.kelondroCloneableIterator;import de.anomic.kelondro.kelondroDyn;import de.anomic.kelondro.kelondroException;import de.anomic.kelondro.kelondroMapObjects;@@ -565,7 +566,7 @@ public final class userDB {public class userIterator implements Iterator {// the iterator iterates all userNames- kelondroDyn.dynKeyIterator userIter;+ kelondroCloneableIterator userIter;userDB.Entry nextEntry;public userIterator(boolean up) throws IOException {diff --git a/source/de/anomic/http/httpc.java b/source/de/anomic/http/httpc.javaindex 825a94f20..abf5ca9ea 100644--- a/source/de/anomic/http/httpc.java+++ b/source/de/anomic/http/httpc.java@@ -920,6 +920,9 @@ public final class httpc {//serverLog.logDebug("HTTPC", handle + " returned GET '" + path + "', time = " + (System.currentTimeMillis() - handle));return r;} catch (Exception e) {+ if (e.getMessage().indexOf("heap space") > 0) {+ e.printStackTrace();+ }throw new IOException(e.getMessage());}}diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.javaindex e771a0644..5f89ecd34 100644--- a/source/de/anomic/http/httpd.java+++ b/source/de/anomic/http/httpd.java@@ -253,7 +253,9 @@ public final class httpd implements serverHandler {// return string in case of any error that occurs during communication// is always (but not only) called if an IO-dependent exception occurrs.this.log.logSevere("Unexpected Error. " + e.getClass().getName(),e);- return "501 Exception occurred: " + e.getMessage();+ String message = e.getMessage();+ if (message.indexOf("heap space") > 0) e.printStackTrace();+ return "501 Exception occurred: " + message;}/**diff --git a/source/de/anomic/index/indexCachedRI.java b/source/de/anomic/index/indexCachedRI.javaindex 12198b445..a9b480d6a 100644--- a/source/de/anomic/index/indexCachedRI.java+++ b/source/de/anomic/index/indexCachedRI.java@@ -34,8 +34,10 @@ import java.util.Map;import java.util.Set;import java.util.TreeSet;+import de.anomic.kelondro.kelondroCloneableIterator;import de.anomic.kelondro.kelondroMergeIterator;import de.anomic.kelondro.kelondroOrder;+import de.anomic.kelondro.kelondroRotateIterator;import de.anomic.kelondro.kelondroRow;import de.anomic.server.logging.serverLog;@@ -254,52 +256,28 @@ public class indexCachedRI implements indexRI {return containers;}- public Iterator wordContainers(String startHash, boolean rot) {+ public kelondroCloneableIterator wordContainers(String startHash, boolean rot) {// returns an iteration of indexContainersreturn wordContainers(startHash, false, rot);}- public Iterator wordContainers(String startHash, boolean ramOnly, boolean rot) {- if (rot) return new rotatingContainerIterator(startHash, ramOnly);+ public kelondroCloneableIterator wordContainers(String startHash, boolean ramOnly, boolean rot) {+ kelondroCloneableIterator i;if (ramOnly) {- return riExtern.wordContainers(startHash, false);- }- return new kelondroMergeIterator(+ i = riExtern.wordContainers(startHash, false);+ } else {+ i = new kelondroMergeIterator(riExtern.wordContainers(startHash, false),backend.wordContainers(startHash, false),new indexContainerOrder(this.indexOrder),indexContainer.containerMergeMethod,true);- }-- private class rotatingContainerIterator implements Iterator {- Iterator i;- boolean ramOnly;-- public rotatingContainerIterator(String startWordHash, boolean ramOnly) {- this.ramOnly = ramOnly;- i = wordContainers(startWordHash, ramOnly);- }-- public void finalize() {- i = null;}-- public boolean hasNext() {- if (i.hasNext()) return true;- else {- i = wordContainers("------------", ramOnly);- return i.hasNext();- }- }-- public Object next() {- return i.next();- }-- public void remove() {- throw new java.lang.UnsupportedOperationException("rotatingWordIterator does not support remove");+ if (rot) {+ return new kelondroRotateIterator(i);+ } else {+ return i;}- } // class rotatingContainerIterator+ }}diff --git a/source/de/anomic/index/indexCollectionRI.java b/source/de/anomic/index/indexCollectionRI.javaindex 6999ae7c9..a7c56dde8 100644--- a/source/de/anomic/index/indexCollectionRI.java+++ b/source/de/anomic/index/indexCollectionRI.java@@ -34,6 +34,7 @@ import java.util.List;import java.util.Set;import de.anomic.kelondro.kelondroBase64Order;+import de.anomic.kelondro.kelondroCloneableIterator;import de.anomic.kelondro.kelondroCollectionIndex;import de.anomic.kelondro.kelondroOutOfLimitsException;import de.anomic.kelondro.kelondroRow;@@ -89,16 +90,24 @@ public class indexCollectionRI implements indexRI {return collectionIndex.minMem();}- public synchronized Iterator wordContainers(String startWordHash, boolean rot) {+ public synchronized kelondroCloneableIterator wordContainers(String startWordHash, boolean rot) {return new wordContainersIterator(startWordHash, rot);}- public class wordContainersIterator implements Iterator {+ public class wordContainersIterator implements kelondroCloneableIterator {private Iterator wci;+ private boolean rot;+ private String startWordHash;public wordContainersIterator(String startWordHash, boolean rot) {- wci = collectionIndex.keycollections(startWordHash.getBytes(), rot);+ this.startWordHash = startWordHash;+ this.rot = rot;+ this.wci = collectionIndex.keycollections(startWordHash.getBytes(), rot);+ }++ public Object clone() {+ return new wordContainersIterator(startWordHash, rot);}public boolean hasNext() {diff --git a/source/de/anomic/index/indexRAMRI.java b/source/de/anomic/index/indexRAMRI.javaindex 66f421b1f..ed7e22198 100644--- a/source/de/anomic/index/indexRAMRI.java+++ b/source/de/anomic/index/indexRAMRI.java@@ -37,6 +37,7 @@ import java.util.TreeMap;import de.anomic.kelondro.kelondroBase64Order;import de.anomic.kelondro.kelondroBufferedRA;+import de.anomic.kelondro.kelondroCloneableIterator;import de.anomic.kelondro.kelondroException;import de.anomic.kelondro.kelondroFixedWidthArray;import de.anomic.kelondro.kelondroMScoreCluster;@@ -274,14 +275,14 @@ public final class indexRAMRI implements indexRI {return cacheIndex.size();}- public synchronized Iterator wordContainers(String startWordHash, boolean rot) {+ public synchronized kelondroCloneableIterator wordContainers(String startWordHash, boolean rot) {// we return an iterator object that creates top-level-clones of the indexContainers// in the cache, so that manipulations of the iterated objects do not change// objects in the cache.return new wordContainerIterator(startWordHash, rot);}- public class wordContainerIterator implements Iterator {+ public class wordContainerIterator implements kelondroCloneableIterator {// this class exists, because the wCache cannot be iterated with rotation// and because every indeContainer Object that is iterated must be returned as top-level-clone@@ -290,13 +291,19 @@ public final class indexRAMRI implements indexRI {private boolean rot;private Iterator iterator;+ private String startWordHash;public wordContainerIterator(String startWordHash, boolean rot) {+ this.startWordHash = startWordHash;this.rot = rot;this.iterator = (startWordHash == null) ? cache.values().iterator() : cache.tailMap(startWordHash).values().iterator();// The collection's iterator will return the values in the order that their corresponding keys appear in the tree.}+ public Object clone() {+ return new wordContainerIterator(startWordHash, rot);+ }+public boolean hasNext() {if (rot) return true;return iterator.hasNext();diff --git a/source/de/anomic/index/indexRI.java b/source/de/anomic/index/indexRI.javaindex dc89e04a0..2b440c4e9 100644--- a/source/de/anomic/index/indexRI.java+++ b/source/de/anomic/index/indexRI.java@@ -28,15 +28,16 @@package de.anomic.index;-import java.util.Iterator;import java.util.Set;+import de.anomic.kelondro.kelondroCloneableIterator;+public interface indexRI {public int size();public int minMem();- public Iterator wordContainers(String startWordHash, boolean rot); // method to replace wordHashes+ public kelondroCloneableIterator wordContainers(String startWordHash, boolean rot); // method to replace wordHashespublic long getUpdateTime(String wordHash);public int indexSize(String wordHash);diff --git a/source/de/anomic/kelondro/kelondroAbstractOrder.java b/source/de/anomic/kelondro/kelondroAbstractOrder.javaindex 4b8e5e07d..b67873536 100644--- a/source/de/anomic/kelondro/kelondroAbstractOrder.java+++ b/source/de/anomic/kelondro/kelondroAbstractOrder.java@@ -70,6 +70,8 @@ public abstract class kelondroAbstractOrder implements kelondroOrder {return compare(((Node) a).getKey(), ((Node) b).getKey());} else if ((a instanceof String) && (b instanceof String)) {return compare(((String) a).getBytes(), ((String) b).getBytes());+ } else if ((a instanceof kelondroRow.Entry) && (b instanceof kelondroRow.Entry)) {+ return compare(((kelondroRow.Entry) a).getColBytes(0), ((kelondroRow.Entry) b).getColBytes(0));} /* else if ((a instanceof Integer) && (b instanceof Integer)) {return ((Integer) a).compareTo((Integer) b);} */ elsediff --git a/source/de/anomic/kelondro/kelondroBytesIntMap.java b/source/de/anomic/kelondro/kelondroBytesIntMap.javaindex b0b4cc369..2f5adfdb8 100644--- a/source/de/anomic/kelondro/kelondroBytesIntMap.java+++ b/source/de/anomic/kelondro/kelondroBytesIntMap.java@@ -25,7 +25,6 @@package de.anomic.kelondro;import java.io.IOException;-import java.util.Iterator;public class kelondroBytesIntMap {@@ -92,11 +91,11 @@ public class kelondroBytesIntMap {return ki.size();}- public synchronized Iterator rows(boolean up, boolean rotating, byte[] firstKey) throws IOException {+ public synchronized kelondroCloneableIterator rows(boolean up, byte[] firstKey) throws IOException {// returns the row-iterator of the underlying kelondroIndex// col[0] = key// col[1] = integer as {b265}- return ki.rows(up, rotating, firstKey);+ return ki.rows(up, firstKey);}public kelondroProfile profile() {diff --git a/source/de/anomic/kelondro/kelondroCache.java b/source/de/anomic/kelondro/kelondroCache.javaindex 016e06ce5..859547cdc 100644--- a/source/de/anomic/kelondro/kelondroCache.java+++ b/source/de/anomic/kelondro/kelondroCache.java@@ -169,7 +169,6 @@ public class kelondroCache implements kelondroIndex {this.cacheFlush++;}writeBufferUnique.clear();- writeBufferUnique.trim();}}@@ -187,9 +186,11 @@ public class kelondroCache implements kelondroIndex {this.cacheFlush++;}i = delete.rows();- while (i.hasNext()) writeBufferUnique.remove(((kelondroRow.Entry) i.next()).getColBytes(0));+ while (i.hasNext()) {+ writeBufferUnique.remove(((kelondroRow.Entry) i.next()).getColBytes(0));+ }delete = null;- writeBufferUnique.trim();+ writeBufferUnique.trim(true);}}@@ -202,7 +203,6 @@ public class kelondroCache implements kelondroIndex {this.cacheFlush++;}writeBufferDoubles.clear();- writeBufferDoubles.trim();}}@@ -222,7 +222,7 @@ public class kelondroCache implements kelondroIndex {i = delete.rows();while (i.hasNext()) writeBufferDoubles.remove(((kelondroRow.Entry) i.next()).getColBytes(0));delete = null;- writeBufferDoubles.trim();+ writeBufferDoubles.trim(true);}}@@ -239,8 +239,9 @@ public class kelondroCache implements kelondroIndex {}private void checkMissSpace() {- if ((readMissCache != null) && (cacheGrowStatus() < 1)- ) {readMissCache.clear(); readMissCache.trim();}+ if ((readMissCache != null) && (cacheGrowStatus() < 1)) {+ readMissCache.clear();+ }}private void checkHitSpace() throws IOException {@@ -249,14 +250,12 @@ public class kelondroCache implements kelondroIndex {if (cacheGrowStatus() < 2) {flushUnique(s / 4); s = sumRecords();}if ((cacheGrowStatus() < 2) && (readHitCache != null)) {readHitCache.clear();- readHitCache.trim();}if (cacheGrowStatus() < 1) {flushUnique();flushDoubles();if (readHitCache != null) {readHitCache.clear();- readHitCache.trim();}}}@@ -625,9 +624,9 @@ public class kelondroCache implements kelondroIndex {return index.row();}- public synchronized Iterator rows(boolean up, boolean rotating, byte[] firstKey) throws IOException {+ public synchronized kelondroCloneableIterator rows(boolean up, byte[] firstKey) throws IOException {flushUnique();- return index.rows(up, rotating, firstKey);+ return index.rows(up, firstKey);}public int size() throws IOException {diff --git a/source/de/anomic/kelondro/kelondroCloneableIterator.java b/source/de/anomic/kelondro/kelondroCloneableIterator.javanew file mode 100644index 000000000..d2845e6e4--- /dev/null+++ b/source/de/anomic/kelondro/kelondroCloneableIterator.java@@ -0,0 +1,35 @@+// kelondroCloneableIterator.java+// (C) 2007 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany+// first published 08.03.2007 on http://www.anomic.de+//+// This is a part of YaCy, a peer-to-peer based web search engine+//+// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $+// $LastChangedRevision: 1986 $+// $LastChangedBy: orbiter $+//+// LICENSE+//+// This program is free software; you can redistribute it and/or modify+// it under the terms of the GNU General Public License as published by+// the Free Software Foundation; either version 2 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU General Public License for more details.+//+// You should have received a copy of the GNU General Public License+// along with this program; if not, write to the Free Software+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA++package de.anomic.kelondro;++import java.util.Iterator;++public interface kelondroCloneableIterator extends Iterator {++ public Object /* instance of kelondroCloneableIterator*/ clone();++}diff --git a/source/de/anomic/kelondro/kelondroCollectionIndex.java b/source/de/anomic/kelondro/kelondroCollectionIndex.javaindex 8848de732..21648ed76 100644--- a/source/de/anomic/kelondro/kelondroCollectionIndex.java+++ b/source/de/anomic/kelondro/kelondroCollectionIndex.java@@ -599,7 +599,7 @@ public class kelondroCollectionIndex {oldcollection.addAllUnique(collection);oldcollection.shape();oldcollection.uniq(); // FIXME: not clear if it would be better to insert the collection with put to avoid double-entries- oldcollection.trim();+ oldcollection.trim(false);// check for size of collection:// if necessary shrink the collection and dump a part of that collection@@ -716,7 +716,7 @@ public class kelondroCollectionIndex {oldcollection.addAllUnique(collection);oldcollection.shape();oldcollection.uniq(); // FIXME: not clear if it would be better to insert the collection with put to avoid double-entries- oldcollection.trim();+ oldcollection.trim(false);collection = oldcollection;// check for size of collection:@@ -845,7 +845,7 @@ public class kelondroCollectionIndex {if ((k instanceof String) && (oldcollection.remove(((String) k).getBytes()) != null)) removed++;}oldcollection.shape();- oldcollection.trim();+ oldcollection.trim(false);if (oldcollection.size() == 0) {// delete the index entry and the array@@ -978,7 +978,8 @@ public class kelondroCollectionIndex {public keycollectionIterator(byte[] startKey, boolean rot) throws IOException {// iterator of {byte[], kelondroRowSet} Objects- indexRowIterator = index.rows(true, rot, startKey);+ kelondroCloneableIterator i = index.rows(true, startKey);+ indexRowIterator = (rot) ? new kelondroRotateIterator(i) : i;}public boolean hasNext() {diff --git a/source/de/anomic/kelondro/kelondroDyn.java b/source/de/anomic/kelondro/kelondroDyn.javaindex b2322de72..6632bfde5 100644--- a/source/de/anomic/kelondro/kelondroDyn.java+++ b/source/de/anomic/kelondro/kelondroDyn.java@@ -159,15 +159,19 @@ public class kelondroDyn {return new String(rawKey, 0, n + 1);}- public class dynKeyIterator implements Iterator {+ public class dynKeyIterator implements kelondroCloneableIterator {// the iterator iterates all keys, which are byte[] objects- Iterator ri;+ kelondroCloneableIterator ri;String nextKey;- public dynKeyIterator(Iterator iter) {+ public dynKeyIterator(kelondroCloneableIterator iter) {ri = iter;nextKey = n();}++ public Object clone() {+ return new dynKeyIterator((kelondroCloneableIterator) ri.clone());+ }public boolean hasNext() {return nextKey != null;@@ -207,14 +211,15 @@ public class kelondroDyn {}}- public synchronized dynKeyIterator dynKeys(boolean up, boolean rotating) throws IOException {+ public synchronized kelondroCloneableIterator dynKeys(boolean up, boolean rotating) throws IOException {// iterates only the keys of the Nodes// enumerated objects are of type String- return new dynKeyIterator(index.rows(up, rotating, null));+ dynKeyIterator i = new dynKeyIterator(index.rows(up, null));+ if (rotating) return new kelondroRotateIterator(i); else return i;}- public synchronized dynKeyIterator dynKeys(boolean up, boolean rotating, byte[] firstKey) throws IOException {- return new dynKeyIterator(index.rows(up, rotating, firstKey));+ public synchronized dynKeyIterator dynKeys(boolean up, byte[] firstKey) throws IOException {+ return new dynKeyIterator(index.rows(up, firstKey));}private byte[] getValueCached(byte[] key) throws IOException {diff --git a/source/de/anomic/kelondro/kelondroFlexSplitTable.java b/source/de/anomic/kelondro/kelondroFlexSplitTable.javaindex 07c3ae947..ee5670839 100644--- a/source/de/anomic/kelondro/kelondroFlexSplitTable.java+++ b/source/de/anomic/kelondro/kelondroFlexSplitTable.java@@ -269,11 +269,11 @@ public class kelondroFlexSplitTable implements kelondroIndex {}}- public synchronized Iterator rows(boolean up, boolean rotating, byte[] firstKey) throws IOException {+ public synchronized kelondroCloneableIterator rows(boolean up, byte[] firstKey) throws IOException {return new rowIter();}- public class rowIter implements Iterator {+ public class rowIter implements kelondroCloneableIterator {Iterator t, tt;@@ -282,6 +282,10 @@ public class kelondroFlexSplitTable implements kelondroIndex {tt = null;}+ public Object clone() {+ return new rowIter();+ }+public boolean hasNext() {return ((t.hasNext()) || ((tt != null) && (tt.hasNext())));}@@ -289,7 +293,7 @@ public class kelondroFlexSplitTable implements kelondroIndex {public Object next() {if ((tt == null) || (!(tt.hasNext()))) {try {- tt = ((kelondroIndex) t.next()).rows(true, false, null);+ tt = ((kelondroIndex) t.next()).rows(true, null);} catch (IOException e) {return null;}diff --git a/source/de/anomic/kelondro/kelondroFlexTable.java b/source/de/anomic/kelondro/kelondroFlexTable.javaindex e7bb35696..89ba8998c 100644--- a/source/de/anomic/kelondro/kelondroFlexTable.java+++ b/source/de/anomic/kelondro/kelondroFlexTable.java@@ -44,7 +44,7 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondrprivate static TreeMap tableTracker = new TreeMap();// class objects- protected kelondroBytesIntMap index;+ protected kelondroBytesIntMap ROindex, RWindex;private boolean RAMIndex;public kelondroFlexTable(File path, String tablename, long preloadTime, kelondroRow rowdef) throws IOException {@@ -81,6 +81,8 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr+ " index entries initialized and sorted from "+ super.col[0].size() + " keys.");RAMIndex = true;+ ROindex = new kelondroBytesIntMap(ki);+ RWindex = new kelondroBytesIntMap(new kelondroRowSet(new kelondroRow(new kelondroColumn[]{super.row().column(0), new kelondroColumn("int c-4 {b256}")}, super.rowdef.objectOrder, super.rowdef.primaryKey), 100));tableTracker.put(this.filename(), this);} else {// too less ram for a ram index@@ -92,16 +94,17 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr} else {// generate new index fileSystem.out.println("*** Generating File index for " + size() + " entries from " + indexfile);- System.out.println("*** Cause: too less RAM (" + serverMemory.available() + " MB) configured. Assign at least " + (neededRAM / 1024 / 1024) + " MB buffersize to enable a RAM index.");+ System.out.println("*** Cause: too less RAM (" + serverMemory.available() + " Bytes) configured. Assign at least " + (neededRAM / 1024 / 1024) + " MB more RAM to enable a RAM index.");ki = initializeTreeIndex(indexfile, preloadTime, rowdef.objectOrder, rowdef.primaryKey);System.out.println(" -done-");System.out.println(ki.size() + " entries indexed from " + super.col[0].size() + " keys.");RAMIndex = false;}+ ROindex = null;+ RWindex = new kelondroBytesIntMap(ki);}// assign index to wrapper- index = new kelondroBytesIntMap(ki);description = "stt=" + Long.toString(System.currentTimeMillis() - start) + ";";super.col[0].setDescription(description.getBytes());}@@ -122,11 +125,11 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr// it is not recommended to implement or use a has predicate unless// it can be ensured that it causes no IOif ((kelondroRecords.debugmode) && (RAMIndex != true)) serverLog.logWarning("kelondroFlexTable", "RAM index warning in file " + super.tablename);- return index.geti(key) >= 0;+ return (RWindex.geti(key) >= 0) || ((ROindex != null) && (ROindex.geti(key) >= 0));}private kelondroIndex initializeRamIndex() {- kelondroRowSet ri = new kelondroRowSet(new kelondroRow(new kelondroColumn[]{super.row().column(0), new kelondroColumn("int c-4 {b256}")}, super.rowdef.objectOrder, super.rowdef.primaryKey), 0);+ kelondroRowSet ri = new kelondroRowSet(new kelondroRow(new kelondroColumn[]{super.row().column(0), new kelondroColumn("int c-4 {b256}")}, super.rowdef.objectOrder, super.rowdef.primaryKey), super.col[0].size() + 1);Iterator content = super.col[0].contentNodes(-1);kelondroRecords.Node node;kelondroRow.Entry indexentry;@@ -149,7 +152,6 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondrSystem.out.print(" -ordering- ");System.out.flush();ri.shape();- ri.trim();return ri;}@@ -183,12 +185,13 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr}public synchronized kelondroRow.Entry get(byte[] key) throws IOException {- int i = index.geti(key);- if (i < 0) return null;+ int pos = RWindex.geti(key);+ if ((pos < 0) && (ROindex != null)) pos = ROindex.geti(key);+ if (pos < 0) return null;// i may be greater than this.size(), because this table may have deleted entries// the deleted entries are subtracted from the 'real' tablesize, so the size may be// smaller than an index to a row entry- return super.get(i);+ return super.get(pos);}public synchronized void putMultiple(List rows, Date entryDate) throws IOException {@@ -203,7 +206,8 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondrwhile (i.hasNext()) {row = (kelondroRow.Entry) i.next();key = row.getColBytes(0);- pos = index.geti(key);+ pos = RWindex.geti(key);+ if ((pos < 0) && (ROindex != null)) pos = ROindex.geti(key);if (pos < 0) {new_rows_sequential.add(row);} else {@@ -225,13 +229,15 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondrassert (row != null);assert (!(serverLog.allZero(row.getColBytes(0))));assert row.bytes().length <= this.rowdef.objectsize;- int i = index.geti(row.getColBytes(0));- if (i < 0) {- index.puti(row.getColBytes(0), super.add(row));+ byte[] key = row.getColBytes(0);+ int pos = RWindex.geti(key);+ if ((pos < 0) && (ROindex != null)) pos = ROindex.geti(key);+ if (pos < 0) {+ RWindex.puti(key, super.add(row));return null;}- kelondroRow.Entry oldentry = super.get(i);- super.set(i, row);+ kelondroRow.Entry oldentry = super.get(pos);+ super.set(pos, row);return oldentry;}@@ -241,7 +247,7 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondrpublic synchronized void addUnique(kelondroRow.Entry row) throws IOException {assert row.bytes().length == this.rowdef.objectsize;- index.addi(row.getColBytes(0), super.add(row));+ RWindex.addi(row.getColBytes(0), super.add(row));}public synchronized void addUniqueMultiple(List rows, Date entryDate) throws IOException {@@ -254,12 +260,13 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondrMap.Entry entry;while (i.hasNext()) {entry = (Map.Entry) i.next();- index.puti((byte[]) entry.getValue(), ((Integer) entry.getKey()).intValue());+ RWindex.puti((byte[]) entry.getValue(), ((Integer) entry.getKey()).intValue());}}public synchronized kelondroRow.Entry remove(byte[] key) throws IOException {- int i = index.removei(key);+ int i = RWindex.removei(key);+ if ((i < 0) && (ROindex != null)) i = ROindex.removei(key); // yes, we are allowed to remove entries from RO partition of the indexif (i < 0) return null;kelondroRow.Entry r;r = super.get(i);@@ -268,7 +275,8 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr}public synchronized kelondroRow.Entry removeOne() throws IOException {- int i = index.removeonei();+ int i = RWindex.removeonei();+ if ((i < 0) && (ROindex != null)) i = ROindex.removeonei();if (i < 0) return null;kelondroRow.Entry r;r = super.get(i);@@ -276,16 +284,26 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondrreturn r;}- public synchronized Iterator rows(boolean up, boolean rotating, byte[] firstKey) throws IOException {- return new rowIterator(up, rotating, firstKey);+ public synchronized kelondroCloneableIterator rows(boolean up, byte[] firstKey) throws IOException {+ return new kelondroMergeIterator(+ new rowIterator(ROindex, up, firstKey),+ new rowIterator(RWindex, up, firstKey),+ row().objectOrder,+ kelondroMergeIterator.simpleMerge,+ up+ );}- public class rowIterator implements Iterator {+ public class rowIterator implements kelondroCloneableIterator {- Iterator indexIterator;+ kelondroCloneableIterator indexIterator;- public rowIterator(boolean up, boolean rotating, byte[] firstKey) throws IOException {- indexIterator = index.rows(up, rotating, firstKey);+ public rowIterator(kelondroBytesIntMap index, boolean up, byte[] firstKey) throws IOException {+ indexIterator = index.rows(up, firstKey);+ }++ public Object clone() {+ return null;}public boolean hasNext() {@@ -317,7 +335,11 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr}public kelondroProfile profile() {- return index.profile();+ if (ROindex == null) {+ return RWindex.profile();+ } else {+ return kelondroProfile.consolidate(ROindex.profile(), RWindex.profile());+ }}public static final Iterator filenames() {@@ -345,9 +367,11 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr// returns statistical data about this objectHashMap map = new HashMap();try {- map.put("tableIndexChunkSize", (!RAMIndex) ? "0" : Integer.toString(index.row().objectsize));- map.put("tableIndexCount", (!RAMIndex) ? "0" : Integer.toString(index.size()));- map.put("tableIndexMem", (!RAMIndex) ? "0" : Integer.toString((int) (index.row().objectsize * index.size() * kelondroRowCollection.growfactor)));+ map.put("tableIndexChunkSize", (!RAMIndex) ? "0" : Integer.toString(RWindex.row().objectsize));+ map.put("tableROIndexCount", ((!RAMIndex) || (ROindex == null)) ? "0" : Integer.toString(ROindex.size()));+ map.put("tableROIndexMem", ((!RAMIndex) || (ROindex == null)) ? "0" : Integer.toString((int) (ROindex.row().objectsize * ROindex.size())));+ map.put("tableRWIndexCount", (!RAMIndex) ? "0" : Integer.toString(RWindex.size()));+ map.put("tableRWIndexMem", (!RAMIndex) ? "0" : Integer.toString((int) (RWindex.row().objectsize * RWindex.size() * kelondroRowCollection.growfactor)));} catch (IOException e) {}return map;@@ -357,7 +381,9 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondrif (tableTracker.remove(this.filename) == null) {serverLog.logWarning("kelondroFlexTable", "close(): file '" + this.filename + "' was not tracked with record tracker.");}- index.close();+ if (ROindex != null) {ROindex.close(); ROindex = null;}+ RWindex.close();+ RWindex = null;super.close();}diff --git a/source/de/anomic/kelondro/kelondroIndex.java b/source/de/anomic/kelondro/kelondroIndex.javaindex 37fa51360..ae7ba343c 100644--- a/source/de/anomic/kelondro/kelondroIndex.java+++ b/source/de/anomic/kelondro/kelondroIndex.java@@ -52,7 +52,6 @@ package de.anomic.kelondro;import java.io.IOException;import java.util.Date;-import java.util.Iterator;import java.util.List;public interface kelondroIndex {@@ -71,6 +70,6 @@ public interface kelondroIndex {public void addUniqueMultiple(List /* of kelondroRow.Entry*/ rows, Date entryDate) throws IOException; // no double-checkpublic kelondroRow.Entry remove(byte[] key) throws IOException;public kelondroRow.Entry removeOne() throws IOException;- public Iterator rows(boolean up, boolean rotating, byte[] firstKey) throws IOException;+ public kelondroCloneableIterator rows(boolean up, byte[] firstKey) throws IOException;public void close() throws IOException;}diff --git a/source/de/anomic/kelondro/kelondroIntBytesMap.java b/source/de/anomic/kelondro/kelondroIntBytesMap.javaindex abfcfa9d5..a45480e2a 100644--- a/source/de/anomic/kelondro/kelondroIntBytesMap.java+++ b/source/de/anomic/kelondro/kelondroIntBytesMap.java@@ -101,7 +101,7 @@ public class kelondroIntBytesMap {public Iterator rows() {try {- return index.rows(true, false, null);+ return index.rows(true, null);} catch (IOException e) {return null;}@@ -110,7 +110,7 @@ public class kelondroIntBytesMap {public void flush() {if (index instanceof kelondroRowSet) {((kelondroRowSet) index).shape();- ((kelondroRowSet) index).trim();+ ((kelondroRowSet) index).trim(true);}}diff --git a/source/de/anomic/kelondro/kelondroMapObjects.java b/source/de/anomic/kelondro/kelondroMapObjects.javaindex 80f263808..987ae6eee 100644--- a/source/de/anomic/kelondro/kelondroMapObjects.java+++ b/source/de/anomic/kelondro/kelondroMapObjects.java@@ -82,7 +82,7 @@ public class kelondroMapObjects extends kelondroObjects {// fill cluster and accumulator with valuesif ((sortfields != null) || (longaccfields != null) || (doubleaccfields != null)) try {- kelondroDyn.dynKeyIterator it = dyn.dynKeys(true, false);+ kelondroCloneableIterator it = dyn.dynKeys(true, false);String mapname;Object cell;long valuel;diff --git a/source/de/anomic/kelondro/kelondroMapTable.java b/source/de/anomic/kelondro/kelondroMapTable.javaindex 96cc9eb95..50aca1779 100644--- a/source/de/anomic/kelondro/kelondroMapTable.java+++ b/source/de/anomic/kelondro/kelondroMapTable.java@@ -141,10 +141,11 @@ public class kelondroMapTable {return table.maps(up, field);}- public synchronized Iterator /* of kelondroRow.Entry-Elements */ rows(String tablename, boolean up, boolean rotating, byte[] firstKey) throws IOException {+ public synchronized kelondroCloneableIterator /* of kelondroRow.Entry-Elements */ rows(String tablename, boolean up, boolean rotating, byte[] firstKey) throws IOException {kelondroIndex tree = (kelondroIndex) tTables.get(tablename);if (tree == null) throw new RuntimeException("kelondroTables.bytes: tree table '" + tablename + "' does not exist.");- return tree.rows(up, rotating, firstKey);+ kelondroCloneableIterator i = tree.rows(up, firstKey);+ if (rotating) return new kelondroRotateIterator(i); else return i;}// if you need the long-values from a row-iteration, please use kelondroRecords.bytes2long to convert from byte[] to longdiff --git a/source/de/anomic/kelondro/kelondroMergeIterator.java b/source/de/anomic/kelondro/kelondroMergeIterator.javaindex 1abdef25d..291ccc55f 100644--- a/source/de/anomic/kelondro/kelondroMergeIterator.java+++ b/source/de/anomic/kelondro/kelondroMergeIterator.java@@ -48,15 +48,15 @@ import java.util.ConcurrentModificationException;import java.util.Iterator;import java.util.Set;-public class kelondroMergeIterator implements Iterator {+public class kelondroMergeIterator implements kelondroCloneableIterator {Comparator comp;- Iterator a, b;+ kelondroCloneableIterator a, b;Object na, nb;Method merger;boolean up;- public kelondroMergeIterator(Iterator a, Iterator b, Comparator c, Method m, boolean up) {+ public kelondroMergeIterator(kelondroCloneableIterator a, kelondroCloneableIterator b, Comparator c, Method m, boolean up) {// this works currently only for String-type key iterationsthis.a = a;this.b = b;@@ -67,6 +67,10 @@ public class kelondroMergeIterator implements Iterator {nextb();}+ public Object clone() {+ return new kelondroMergeIterator((kelondroCloneableIterator) a.clone(), (kelondroCloneableIterator) b.clone(), comp, merger, up);+ }+public void finalize() {// call finalizer of embedded objectsa = null;@@ -150,10 +154,10 @@ public class kelondroMergeIterator implements Iterator {return cascade(iterators.iterator(), c, merger, up);}- private static Iterator cascade(Iterator /*of*/ iiterators, Comparator c, Method merger, boolean up) {+ private static kelondroCloneableIterator cascade(Iterator /*of*/ iiterators, Comparator c, Method merger, boolean up) {if (iiterators == null) return null;if (!(iiterators.hasNext())) return null;- Iterator one = (Iterator) iiterators.next();+ kelondroCloneableIterator one = (kelondroCloneableIterator) iiterators.next();if (!(iiterators.hasNext())) return one;return new kelondroMergeIterator(one, cascade(iiterators, c, merger, up), c, merger, up);}diff --git a/source/de/anomic/kelondro/kelondroObjects.java b/source/de/anomic/kelondro/kelondroObjects.javaindex 274f19637..958789a1f 100644--- a/source/de/anomic/kelondro/kelondroObjects.java+++ b/source/de/anomic/kelondro/kelondroObjects.java@@ -122,14 +122,15 @@ public class kelondroObjects {}}- public synchronized kelondroDyn.dynKeyIterator keys(final boolean up, final boolean rotating) throws IOException {+ public synchronized kelondroCloneableIterator keys(final boolean up, final boolean rotating) throws IOException {// simple enumeration of key names without special orderingreturn dyn.dynKeys(up, rotating);}- public synchronized kelondroDyn.dynKeyIterator keys(final boolean up, final boolean rotating, final byte[] firstKey) throws IOException {+ public synchronized kelondroCloneableIterator keys(final boolean up, final boolean rotating, final byte[] firstKey) throws IOException {// simple enumeration of key names without special ordering- return dyn.dynKeys(up, rotating, firstKey);+ kelondroCloneableIterator i = dyn.dynKeys(up, firstKey);+ if (rotating) return new kelondroRotateIterator(i); else return i;}diff --git a/source/de/anomic/kelondro/kelondroRotateIterator.java b/source/de/anomic/kelondro/kelondroRotateIterator.javanew file mode 100644index 000000000..7318a5a19--- /dev/null+++ b/source/de/anomic/kelondro/kelondroRotateIterator.java@@ -0,0 +1,58 @@+// kelondroRotateIterator.java+// (C) 2007 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany+// first published 08.03.2007 on http://www.anomic.de+//+// This is a part of YaCy, a peer-to-peer based web search engine+//+// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $+// $LastChangedRevision: 1986 $+// $LastChangedBy: orbiter $+//+// LICENSE+//+// This program is free software; you can redistribute it and/or modify+// it under the terms of the GNU General Public License as published by+// the Free Software Foundation; either version 2 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU General Public License for more details.+//+// You should have received a copy of the GNU General Public License+// along with this program; if not, write to the Free Software+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA++package de.anomic.kelondro;++public class kelondroRotateIterator implements kelondroCloneableIterator {++ kelondroCloneableIterator a, clone;++ public kelondroRotateIterator(kelondroCloneableIterator a) {+ // this works currently only for String-type key iterations+ this.a = a;+ this.clone = (kelondroCloneableIterator) a.clone();+ }++ public Object clone() {+ return new kelondroRotateIterator(a);+ }++ public boolean hasNext() {+ return true;+ }++ public Object next() {+ if (!(a.hasNext())) {+ a = (kelondroCloneableIterator) clone.clone();+ }+ return a.next();+ }++ public void remove() {+ a.remove();+ }++}diff --git a/source/de/anomic/kelondro/kelondroRowCollection.java b/source/de/anomic/kelondro/kelondroRowCollection.javaindex 2a40061c8..800822c14 100644--- a/source/de/anomic/kelondro/kelondroRowCollection.java+++ b/source/de/anomic/kelondro/kelondroRowCollection.java@@ -32,6 +32,7 @@ import java.util.List;import java.util.Set;import de.anomic.server.serverFileUtils;+import de.anomic.server.serverMemory;import de.anomic.server.logging.serverLog;public class kelondroRowCollection {@@ -136,7 +137,7 @@ public class kelondroRowCollection {public byte[] exportCollection() {// returns null if the collection is empty- trim();+ trim(false);kelondroRow row = exportRow(chunkcache.length);kelondroRow.Entry entry = row.newEntry();assert (sortBound <= chunkcount) : "sortBound = " + sortBound + ", chunkcount = " + chunkcount;@@ -168,11 +169,13 @@ public class kelondroRowCollection {newChunkcache = null;}- public void trim() {+ public void trim(boolean plusGrowFactor) {if (chunkcache.length == 0) return;synchronized (chunkcache) {int needed = chunkcount * rowdef.objectsize();- if (chunkcache.length == needed) return;+ if (plusGrowFactor) needed = (int) (needed * growfactor);+ if (needed >= chunkcache.length) return; // in case that the growfactor causes that the cache would grow instead of shrink, simply ignore the growfactor+ if (serverMemory.available() + 1000 < needed) return; // if the swap buffer is not available, we must give up. This is not critical. Othervise we provoke a serious problem with OOMbyte[] newChunkcache = new byte[needed];System.arraycopy(chunkcache, 0, newChunkcache, 0, Math.min(chunkcache.length, newChunkcache.length));chunkcache = newChunkcache;diff --git a/source/de/anomic/kelondro/kelondroRowSet.java b/source/de/anomic/kelondro/kelondroRowSet.javaindex 90cc8c792..fae44cd8a 100644--- a/source/de/anomic/kelondro/kelondroRowSet.java+++ b/source/de/anomic/kelondro/kelondroRowSet.java@@ -347,21 +347,20 @@ public class kelondroRowSet extends kelondroRowCollection implements kelondroIndreturn super.rows();}- public Iterator rows(boolean up, boolean rotating, byte[] firstKey) {- return new rowIterator(up, rotating, firstKey);+ public kelondroCloneableIterator rows(boolean up, byte[] firstKey) {+ return new rowIterator(up, firstKey);}- public class rowIterator implements Iterator {+ public class rowIterator implements kelondroCloneableIterator {- private boolean up, rot;+ private boolean up;private byte[] first;private int p, bound;- public rowIterator(boolean up, boolean rotating, byte[] firstKey) {+ public rowIterator(boolean up, byte[] firstKey) {// see that all elements are sortedshape();this.up = up;- this.rot = rotating;this.first = firstKey;this.bound = sortBound;if (first == null) {@@ -371,8 +370,11 @@ public class kelondroRowSet extends kelondroRowCollection implements kelondroInd}}+ public Object clone() {+ return new rowIterator(up, first);+ }+public boolean hasNext() {- if (rot) return true;if (up) {return p < bound;} else {@@ -383,10 +385,6 @@ public class kelondroRowSet extends kelondroRowCollection implements kelondroIndpublic Object next() {kelondroRow.Entry entry = get(p);if (up) p++; else p--;- if (rot) {- if (p == bound) p = 0;- if (p < 0) p = bound - 1;- }return entry;}@@ -399,26 +397,6 @@ public class kelondroRowSet extends kelondroRowCollection implements kelondroInd// just for compatibility with kelondroIndex interface; do nothing}- public final int cacheObjectChunkSize() {- // dummy method- return -1;- }-- public long[] cacheObjectStatus() {- // dummy method- return null;- }-- public final int cacheNodeChunkSize() {- // returns the size that the node cache uses for a single entry- return -1;- }-- public final int[] cacheNodeStatus() {- // a collection of different node cache status values- return new int[]{0,0,0,0,0,0,0,0,0,0};- }-public static void main(String[] args) {/*String[] test = { "eins", "zwei", "drei", "vier", "fuenf", "sechs", "sieben", "acht", "neun", "zehn" };diff --git a/source/de/anomic/kelondro/kelondroSplittedTree.java b/source/de/anomic/kelondro/kelondroSplittedTree.javaindex 49dd9495f..aa118edb6 100644--- a/source/de/anomic/kelondro/kelondroSplittedTree.java+++ b/source/de/anomic/kelondro/kelondroSplittedTree.java@@ -164,27 +164,35 @@ public class kelondroSplittedTree implements kelondroIndex {}}- public Iterator rows(boolean up, boolean rotating, byte[] firstKey) throws IOException {- return new ktfsIterator(up, rotating, firstKey);+ public kelondroCloneableIterator rows(boolean up, byte[] firstKey) throws IOException {+ return new ktfsIterator(up, firstKey);}- public class ktfsIterator implements Iterator {+ public class ktfsIterator implements kelondroCloneableIterator {int c = 0;Iterator ktfsI;- boolean up, rot;+ byte[] firstKey;+ boolean up;- public ktfsIterator(boolean up, boolean rotating, byte[] firstKey) throws IOException {+ public ktfsIterator(boolean up, byte[] firstKey) throws IOException {this.up = up;- this.rot = rotating;+ this.firstKey = firstKey;c = (up) ? 0 : (ff - 1);if (firstKey != null) throw new UnsupportedOperationException("ktfsIterator does not work with a start key");- ktfsI = ktfs[c].rows(up, false, firstKey); // FIXME: this works only correct with firstKey == null+ ktfsI = ktfs[c].rows(up, firstKey); // FIXME: this works only correct with firstKey == null+ }++ public Object clone() {+ try {+ return new ktfsIterator(up, firstKey);+ } catch (IOException e) {+ return null;+ }}public boolean hasNext() {- return ((rot) ||- (ktfsI.hasNext()) ||+ return ((ktfsI.hasNext()) ||((up) && (c < ff)) ||((!(up)) && (c > 0)));}@@ -195,42 +203,24 @@ public class kelondroSplittedTree implements kelondroIndex {if (c < (ff - 1)) {c++;try {- ktfsI = ktfs[c].rows(true, false, null);+ ktfsI = ktfs[c].rows(true, null);} catch (IOException e) {return null;}return ktfsI.next();} else {- if (rot) {- c = 0;- try {- ktfsI = ktfs[c].rows(true, false, null);- } catch (IOException e) {- return null;- }- return ktfsI.next();- }return null;}} else {if (c > 0) {c--;try {- ktfsI = ktfs[c].rows(false, false, null);+ ktfsI = ktfs[c].rows(false, null);} catch (IOException e) {return null;}return ktfsI.next();} else {- if (rot) {- c = ff - 1;- try {- ktfsI = ktfs[c].rows(false, false, null);- } catch (IOException e) {- return null;- }- return ktfsI.next();- }return null;}}diff --git a/source/de/anomic/kelondro/kelondroTree.java b/source/de/anomic/kelondro/kelondroTree.javaindex 57f2dfa9e..f9dda6f36 100644--- a/source/de/anomic/kelondro/kelondroTree.java+++ b/source/de/anomic/kelondro/kelondroTree.java@@ -981,7 +981,7 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {}}- public TreeMap rowMap(boolean up, boolean rotating, byte[] firstKey, boolean including, int count) throws IOException {+ public TreeMap rowMap(boolean up, byte[] firstKey, boolean including, int count) throws IOException {// returns an ordered map of keys/row relations; key objects are of type String, value objects are of type byte[][]kelondroOrder setOrder = (kelondroOrder) row().objectOrder.clone();setOrder.direction(up);@@ -990,7 +990,7 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {Node n;String key;synchronized (this) {- Iterator i = (firstKey == null) ? new nodeIterator(up, rotating) : new nodeIterator(up, rotating, firstKey, including);+ Iterator i = (firstKey == null) ? new nodeIterator(up, false) : new nodeIterator(up, false, firstKey, including);while ((rows.size() < count) && (i.hasNext())) {n = (Node) i.next();if (n == null) return rows;@@ -1018,40 +1018,49 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {return set;}- public Iterator rows(boolean up, boolean rotating, byte[] firstKey) throws IOException {+ public kelondroCloneableIterator rows(boolean up, byte[] firstKey) throws IOException {// iterates the rows of the Nodes// enumerated objects are of type byte[][]// iterates the elements in a sorted way.// if iteration should start at smallest element, set firstKey to null- return new rowIterator(up, rotating, firstKey, this.size());+ return new rowIterator(up, firstKey, this.size());}- public class rowIterator implements Iterator {+ public class rowIterator implements kelondroCloneableIterator {int chunkSize;byte[] start;- boolean inc, rot;+ boolean inc;long count;byte[] lastKey;TreeMap rowBuffer;Iterator bufferIterator;+ long guessedCountLimit;- public rowIterator(boolean up, boolean rotating, byte[] firstKey, long guessedCountLimit) throws IOException {+ public rowIterator(boolean up, byte[] firstKey, long guessedCountLimit) throws IOException {+ this.guessedCountLimit = guessedCountLimit;start = firstKey;inc = up;- rot = rotating;count = 0;lastKey = null;//System.out.println("*** rowIterator: " + filename + ": readAheadChunkSize = " + readAheadChunkSize + ", lastIteratorCount = " + lastIteratorCount);readAheadChunkSize = Math.min(1000, 3 + (int) ((3 * readAheadChunkSize + lastIteratorCount) / 4));chunkSize = (int) Math.min(readAheadChunkSize / 3, guessedCountLimit);- rowBuffer = rowMap(inc, rot, start, true, chunkSize);+ rowBuffer = rowMap(inc, start, true, chunkSize);bufferIterator = rowBuffer.entrySet().iterator();lastIteratorCount = 0;}+ public Object clone() {+ try {+ return new rowIterator(inc, start, guessedCountLimit);+ } catch (IOException e) {+ return null;+ }+ }+public boolean hasNext() {- return ((bufferIterator != null) && (bufferIterator.hasNext()) && ((rot) || (count < size())));+ return ((bufferIterator != null) && (bufferIterator.hasNext()) && (count < size()));}public Object next() {@@ -1064,7 +1073,7 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {// assign next buffer chunktry {lastKey[lastKey.length - 1]++;- rowBuffer = rowMap(inc, rot, lastKey, false, chunkSize);+ rowBuffer = rowMap(inc, lastKey, false, chunkSize);bufferIterator = rowBuffer.entrySet().iterator();} catch (IOException e) {rowBuffer = null;@@ -1284,7 +1293,7 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {} else if (args[0].equals("-n")) {kelondroTree fm = new kelondroTree(new File(args[1]), true, 10, new kelondroRow("byte[] a-4, byte[] b-4", kelondroNaturalOrder.naturalOrder, 0));//byte[][] keys = fm.getSequentialKeys(args[2].getBytes(), 500, true);- Iterator rowIt = fm.rows(true, false, (args[2].length() == 0) ? null : args[2].getBytes());+ Iterator rowIt = fm.rows(true, (args[2].length() == 0) ? null : args[2].getBytes());Vector v = new Vector();while (rowIt.hasNext()) v.add(new String(((byte[][]) rowIt.next())[0]));ret = v.toString().getBytes();@@ -1444,7 +1453,7 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {b = testWord('L'); tt.put(b, b);int c = countElements(tt);System.out.println("elements: " + c);- Iterator i = tt.rows(true, true, testWord('G'));+ Iterator i = tt.rows(true, testWord('G'));for (int j = 0; j < c; j++) {System.out.println("Row " + j + ": " + new String(((kelondroRow.Entry) i.next()).getColBytes(0)));}@@ -1554,7 +1563,7 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {public static int countElements(kelondroTree t) {int count = 0;try {- Iterator iter = t.rows(true, false, null);+ Iterator iter = t.rows(true, null);kelondroRow.Entry row;while (iter.hasNext()) {count++;diff --git a/source/de/anomic/plasma/dbImport/plasmaCrawlNURLImporter.java b/source/de/anomic/plasma/dbImport/plasmaCrawlNURLImporter.javaindex 721656559..08765dd28 100644--- a/source/de/anomic/plasma/dbImport/plasmaCrawlNURLImporter.java+++ b/source/de/anomic/plasma/dbImport/plasmaCrawlNURLImporter.java@@ -118,7 +118,7 @@ public class plasmaCrawlNURLImporter extends AbstractImporter implements dbImpor}// getting an interator and loop through the URL entries- Iterator entryIter = (stackTypes[i] == -1) ? this.importNurlDB.entries(true, false, null) : null;+ Iterator entryIter = (stackTypes[i] == -1) ? this.importNurlDB.entries(true, null) : null;while (true) {String nextHash = null;diff --git a/source/de/anomic/plasma/plasmaCrawlEURL.java b/source/de/anomic/plasma/plasmaCrawlEURL.javaindex 46af6a40e..8fa024db4 100644--- a/source/de/anomic/plasma/plasmaCrawlEURL.java+++ b/source/de/anomic/plasma/plasmaCrawlEURL.java@@ -384,8 +384,8 @@ public class plasmaCrawlEURL {Iterator i;boolean error = false;- public kiter(boolean up, boolean rotating, String firstHash) throws IOException {- i = urlIndexFile.rows(up, rotating, (firstHash == null) ? null : firstHash.getBytes());+ public kiter(boolean up, String firstHash) throws IOException {+ i = urlIndexFile.rows(up, (firstHash == null) ? null : firstHash.getBytes());error = false;}@@ -410,8 +410,8 @@ public class plasmaCrawlEURL {}- public Iterator entries(boolean up, boolean rotating, String firstHash) throws IOException {+ public Iterator entries(boolean up, String firstHash) throws IOException {// enumerates entry elements- return new kiter(up, rotating, firstHash);+ return new kiter(up, firstHash);}}diff --git a/source/de/anomic/plasma/plasmaCrawlLURL.java b/source/de/anomic/plasma/plasmaCrawlLURL.javaindex de9e38e58..ae8f6beab 100644--- a/source/de/anomic/plasma/plasmaCrawlLURL.java+++ b/source/de/anomic/plasma/plasmaCrawlLURL.java@@ -67,6 +67,7 @@ import de.anomic.index.indexURLEntry;import de.anomic.index.indexURLEntryNew;import de.anomic.kelondro.kelondroBitfield;import de.anomic.kelondro.kelondroCache;+import de.anomic.kelondro.kelondroCloneableIterator;import de.anomic.kelondro.kelondroFlexSplitTable;import de.anomic.kelondro.kelondroIndex;import de.anomic.kelondro.kelondroRow;@@ -336,21 +337,33 @@ public final class plasmaCrawlLURL {}}- public Iterator entries(boolean up, boolean rotating, String firstHash) throws IOException {+ public kelondroCloneableIterator entries(boolean up, String firstHash) throws IOException {// enumerates entry elements- return new kiter(up, rotating, firstHash);+ return new kiter(up, firstHash);}- public class kiter implements Iterator {+ public class kiter implements kelondroCloneableIterator {// enumerates entry elementsprivate Iterator iter;private boolean error;+ boolean up;+ String firstHash;- public kiter(boolean up, boolean rotating, String firstHash) throws IOException {- this.iter = plasmaCrawlLURL.this.urlIndexFile.rows(up, rotating, (firstHash == null) ? null : firstHash.getBytes());+ public kiter(boolean up, String firstHash) throws IOException {+ this.up = up;+ this.firstHash = firstHash;+ this.iter = plasmaCrawlLURL.this.urlIndexFile.rows(up, (firstHash == null) ? null : firstHash.getBytes());this.error = false;}+ public Object clone() {+ try {+ return new kiter(up, firstHash);+ } catch (IOException e) {+ return null;+ }+ }+public final boolean hasNext() {if (this.error) { return false; }return this.iter.hasNext();@@ -379,7 +392,7 @@ public final class plasmaCrawlLURL {serverLog log = new serverLog("URLDBCLEANUP");HashSet damagedURLS = new HashSet();try {- Iterator eiter = entries(true, false, null);+ Iterator eiter = entries(true, null);int iteratorCount = 0;while (eiter.hasNext()) try {eiter.next();@@ -469,7 +482,7 @@ public final class plasmaCrawlLURL {public void run() {try {serverLog.logInfo("URLDBCLEANER", "UrldbCleaner-Thread startet");- final Iterator eiter = entries(true, false, null);+ final Iterator eiter = entries(true, null);while (eiter.hasNext() && run) {synchronized (this) {if (this.pause) {@@ -561,7 +574,7 @@ public final class plasmaCrawlLURL {if (args[0].equals("-l")) try {// arg 1 is path to URLCachefinal plasmaCrawlLURL urls = new plasmaCrawlLURL(new File(args[2]), 0);- final Iterator enu = urls.entries(true, false, null);+ final Iterator enu = urls.entries(true, null);while (enu.hasNext()) {System.out.println(((indexURLEntry) enu.next()).toString());}diff --git a/source/de/anomic/plasma/plasmaCrawlNURL.java b/source/de/anomic/plasma/plasmaCrawlNURL.javaindex 7b4314e64..36173430f 100644--- a/source/de/anomic/plasma/plasmaCrawlNURL.java+++ b/source/de/anomic/plasma/plasmaCrawlNURL.java@@ -636,8 +636,8 @@ public class plasmaCrawlNURL {Iterator i;boolean error = false;- public kiter(boolean up, boolean rotating, String firstHash) throws IOException {- i = urlIndexFile.rows(up, rotating, (firstHash == null) ? null : firstHash.getBytes());+ public kiter(boolean up, String firstHash) throws IOException {+ i = urlIndexFile.rows(up, (firstHash == null) ? null : firstHash.getBytes());error = false;}@@ -662,9 +662,9 @@ public class plasmaCrawlNURL {}- public Iterator entries(boolean up, boolean rotating, String firstHash) throws IOException {+ public Iterator entries(boolean up, String firstHash) throws IOException {// enumerates entry elements- return new kiter(up, rotating, firstHash);+ return new kiter(up, firstHash);}}diff --git a/source/de/anomic/plasma/plasmaCrawlProfile.java b/source/de/anomic/plasma/plasmaCrawlProfile.javaindex d2d0a1207..ae703017f 100644--- a/source/de/anomic/plasma/plasmaCrawlProfile.java+++ b/source/de/anomic/plasma/plasmaCrawlProfile.java@@ -49,6 +49,7 @@ import java.util.Iterator;import java.util.Map;import de.anomic.kelondro.kelondroBase64Order;+import de.anomic.kelondro.kelondroCloneableIterator;import de.anomic.kelondro.kelondroDyn;import de.anomic.kelondro.kelondroException;import de.anomic.kelondro.kelondroMapObjects;@@ -102,7 +103,7 @@ public class plasmaCrawlProfile {public class profileIterator implements Iterator {// the iterator iterates all keys, which are byte[] objects- kelondroDyn.dynKeyIterator handleIterator;+ kelondroCloneableIterator handleIterator;String lastkey;public profileIterator(boolean up) throws IOException {handleIterator = profileTable.keys(up, false);diff --git a/source/de/anomic/plasma/plasmaCrawlStacker.java b/source/de/anomic/plasma/plasmaCrawlStacker.javaindex d5af2aaa6..dface406d 100644--- a/source/de/anomic/plasma/plasmaCrawlStacker.java+++ b/source/de/anomic/plasma/plasmaCrawlStacker.java@@ -619,7 +619,7 @@ public final class plasmaCrawlStacker {openDB();try {// loop through the list and fill the messageList with url hashs- Iterator rows = this.urlEntryCache.rows(true, false, null);+ Iterator rows = this.urlEntryCache.rows(true, null);kelondroRow.Entry entry;while (rows.hasNext()) {entry = (kelondroRow.Entry) rows.next();diff --git a/source/de/anomic/plasma/plasmaHTCache.java b/source/de/anomic/plasma/plasmaHTCache.javaindex c014a63c6..4aec520a4 100644--- a/source/de/anomic/plasma/plasmaHTCache.java+++ b/source/de/anomic/plasma/plasmaHTCache.java@@ -172,13 +172,7 @@ public final class plasmaHTCache {}// open the response header database- File dbfile = new File(this.cachePath, "responseHeader.db");- try {- this.responseHeaderDB = new kelondroMapObjects(new kelondroDyn(dbfile, true, true, preloadTime, yacySeedDB.commonHashLength, 150, '#', true, false), 500);- } catch (IOException e) {- this.log.logSevere("the request header database could not be opened: " + e.getMessage());- System.exit(0);- }+ openResponseHeaderDB(preloadTime);// init stackthis.cacheStack = new LinkedList();@@ -193,6 +187,24 @@ public final class plasmaHTCache {this.cacheScanThread = serverInstantThread.oneTimeJob(this, "cacheScan", this.log, 120000);}+ private void resetResponseHeaderDB() {+ if (this.responseHeaderDB != null) try {this.responseHeaderDB.close();} catch (IOException e) {}+ File dbfile = new File(this.cachePath, "responseHeader.db");+ if (dbfile.exists()) dbfile.delete();+ openResponseHeaderDB(0);+ }++ private void openResponseHeaderDB(long preloadTime) {+ // open the response header database+ File dbfile = new File(this.cachePath, "responseHeader.db");+ try {+ this.responseHeaderDB = new kelondroMapObjects(new kelondroDyn(dbfile, true, true, preloadTime, yacySeedDB.commonHashLength, 150, '#', true, false), 500);+ } catch (IOException e) {+ this.log.logSevere("the request header database could not be opened: " + e.getMessage());+ System.exit(0);+ }+ }+private void deleteOldHTCache(File directory) {String[] list = directory.list();if (list != null) {@@ -296,6 +308,7 @@ public final class plasmaHTCache {this.log.logFinest("Trying to remove responseHeader from URL: " + url.toString());this.responseHeaderDB.remove(plasmaURL.urlHash(url));} catch (IOException e) {+ resetResponseHeaderDB();this.log.logInfo("IOExeption removing response header from DB: " + e.getMessage(), e);}return true;@@ -1073,8 +1086,12 @@ public final class plasmaHTCache {public boolean writeResourceInfo() throws IOException {assert(this.nomalizedURLHash != null) : "URL Hash is null";if (this.resInfo == null) return false;-- plasmaHTCache.this.responseHeaderDB.set(this.nomalizedURLHash, this.resInfo.getMap());+ try {+ plasmaHTCache.this.responseHeaderDB.set(this.nomalizedURLHash, this.resInfo.getMap());+ } catch (Exception e) {+ resetResponseHeaderDB();+ return false;+ }return true;}diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.javaindex 1ef3fff90..905cdea50 100644--- a/source/de/anomic/plasma/plasmaSwitchboard.java+++ b/source/de/anomic/plasma/plasmaSwitchboard.java@@ -1038,9 +1038,10 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser// set a minimum amount of memory for the indexer threadlong memprereq = Math.max(getConfigLong(INDEXER_MEMPREREQ, 0), wordIndex.minMem());+ long memprereq1 = memprereq + (memprereq / 8) + 2 * 1024 * 1024;setConfig(INDEXER_MEMPREREQ, memprereq);- kelondroRecords.setCacheGrowStati(memprereq + (memprereq / 8) + 2 * 1024 * 1024, memprereq);- kelondroCache.setCacheGrowStati(memprereq + (memprereq / 8) + 2 * 1024 * 1024, memprereq);+ kelondroRecords.setCacheGrowStati(memprereq1, memprereq);+ kelondroCache.setCacheGrowStati(memprereq1, memprereq);// make parserlog.logConfig("Starting Parser");diff --git a/source/de/anomic/plasma/plasmaWordIndex.java b/source/de/anomic/plasma/plasmaWordIndex.javaindex b8e08639a..19bf32c1b 100644--- a/source/de/anomic/plasma/plasmaWordIndex.java+++ b/source/de/anomic/plasma/plasmaWordIndex.java@@ -46,8 +46,10 @@ import de.anomic.index.indexRWIEntry;import de.anomic.index.indexRWIEntryNew;import de.anomic.index.indexURLEntry;import de.anomic.kelondro.kelondroBase64Order;+import de.anomic.kelondro.kelondroCloneableIterator;import de.anomic.kelondro.kelondroMergeIterator;import de.anomic.kelondro.kelondroOrder;+import de.anomic.kelondro.kelondroRotateIterator;import de.anomic.net.URL;import de.anomic.plasma.urlPattern.plasmaURLPattern;import de.anomic.server.logging.serverLog;@@ -87,7 +89,7 @@ public final class plasmaWordIndex implements indexRI {}public int minMem() {- return dhtOutCache.minMem() + dhtInCache.minMem() + collections.minMem();+ return 2*1024*1024 /* indexing overhead */ + dhtOutCache.minMem() + dhtInCache.minMem() + collections.minMem();}public int maxURLinDHTOutCache() {@@ -458,13 +460,16 @@ public final class plasmaWordIndex implements indexRI {return containers;}-- public Iterator wordContainers(String startHash, boolean ram, boolean rot) {- if (rot) return new rotatingContainerIterator(startHash, ram);- else return wordContainers(startHash, ram);+ public kelondroCloneableIterator wordContainers(String startHash, boolean ram, boolean rot) {+ kelondroCloneableIterator i = wordContainers(startHash, ram);+ if (rot) {+ return new kelondroRotateIterator(i);+ } else {+ return i;+ }}- public Iterator wordContainers(String startWordHash, boolean ram) {+ public kelondroCloneableIterator wordContainers(String startWordHash, boolean ram) {kelondroOrder containerOrder = new indexContainerOrder((kelondroOrder) indexOrder.clone());containerOrder.rotate(startWordHash.getBytes());if (ram) {@@ -479,37 +484,6 @@ public final class plasmaWordIndex implements indexRI {}}- public class rotatingContainerIterator implements Iterator {- Iterator i;- boolean ram;-- public rotatingContainerIterator(String startWordHash, boolean ram) {- this.ram = ram;- i = wordContainers(startWordHash, ram);- }-- public void finalize() {- i = null;- }-- public boolean hasNext() {- if (i.hasNext()) return true;- else {- i = wordContainers("------------", ram);- return i.hasNext();- }- }-- public Object next() {- return i.next();- }-- public void remove() {- throw new java.lang.UnsupportedOperationException("rotatingWordIterator does not support remove");- }- } // class rotatingContainerIterator--// The Cleaner class was provided as "UrldbCleaner" by Hydrox// see http://www.yacy-forum.de/viewtopic.php?p=18093#18093public Cleaner makeCleaner(plasmaCrawlLURL lurl, String startHash) {diff --git a/source/de/anomic/plasma/plasmaWordIndexFileCluster.java b/source/de/anomic/plasma/plasmaWordIndexFileCluster.javaindex 8a35a3d97..4a7a4702b 100644--- a/source/de/anomic/plasma/plasmaWordIndexFileCluster.java+++ b/source/de/anomic/plasma/plasmaWordIndexFileCluster.java@@ -53,6 +53,7 @@ import de.anomic.index.indexContainer;import de.anomic.index.indexRI;import de.anomic.index.indexRWIEntryNew;import de.anomic.index.indexRWIEntryOld;+import de.anomic.kelondro.kelondroCloneableIterator;import de.anomic.kelondro.kelondroException;import de.anomic.kelondro.kelondroNaturalOrder;import de.anomic.yacy.yacySeedDB;@@ -72,23 +73,27 @@ public class plasmaWordIndexFileCluster implements indexRI {return size;}- public Iterator wordContainers(String startHash, boolean rot) {+ public kelondroCloneableIterator wordContainers(String startHash, boolean rot) {return new containerIterator(wordHashes(startHash, rot));}- public class containerIterator implements Iterator {+ public class containerIterator implements kelondroCloneableIterator {// this is a highly inefficient class that is here for the// only case to support a compatible interface until the// new database structure is in place and makes the// plasmaWordIndexFileCluster class superfluous- private Iterator wordIterator;+ private kelondroCloneableIterator wordIterator;- public containerIterator(Iterator wordIterator) {+ public containerIterator(kelondroCloneableIterator wordIterator) {this.wordIterator = wordIterator;}+ public Object clone() {+ return new containerIterator((kelondroCloneableIterator) this.wordIterator.clone());+ }+public boolean hasNext() {return wordIterator.hasNext();}@@ -103,23 +108,27 @@ public class plasmaWordIndexFileCluster implements indexRI {}- public Iterator wordHashes(String startHash, boolean rot) {+ public kelondroCloneableIterator wordHashes(String startHash, boolean rot) {// outdated method: to be replaced by wordContainersreturn wordHashes(startHash, true, rot);}- public Iterator wordHashes(String startHash, boolean up, boolean rot) {+ public kelondroCloneableIterator wordHashes(String startHash, boolean up, boolean rot) {if (rot) throw new UnsupportedOperationException("no rot allowed");return new iterateFiles(startHash, up);}- public class iterateFiles implements Iterator {+ public class iterateFiles implements kelondroCloneableIterator {private final ArrayList hierarchy; // contains TreeSet elements, earch TreeSet contains File Entriesprivate final Comparator comp; // for string-compareprivate String buffer; // the prefetch-buffer+ private String startHash;+ private boolean up;public iterateFiles(String startHash, boolean up) {+ this.startHash = startHash;+ this.up = up;this.hierarchy = new ArrayList();this.comp = new kelondroNaturalOrder(up);@@ -151,6 +160,10 @@ public class plasmaWordIndexFileCluster implements indexRI {}}+ public Object clone() {+ return new iterateFiles(startHash, up);+ }+private synchronized void delete(String pattern, TreeSet names) {String name;while ((names.size() > 0) && (comp.compare((new File(name = (String) names.first())).getName(), pattern) < 0)) names.remove(name);diff --git a/source/de/anomic/server/serverAbstractThread.java b/source/de/anomic/server/serverAbstractThread.javaindex 952616395..569934929 100644--- a/source/de/anomic/server/serverAbstractThread.java+++ b/source/de/anomic/server/serverAbstractThread.java@@ -232,31 +232,6 @@ public abstract class serverAbstractThread extends Thread implements serverThrealogError("thread '" + this.getName() + "': " + e.toString(),e);}}-- private static long[] gcs = new long[5];- private static int gcs_pos = 0;-- private static long runGC() {- long memnow = serverMemory.available();- Runtime.getRuntime().gc();- if (++gcs_pos >= gcs.length) gcs_pos = 0;- return (gcs[gcs_pos] = serverMemory.available() - memnow);- }-- public static long GCAverage() {- long x = 0;- int y = 0;- for (int i=0; i<gcs.length; i++)- if (gcs[i] != 0) {- x += gcs[i];- y++;- }- if (y == 0) {- return 0;- } else {- return x / y;- }- }public void run() {if (startup > 0) {@@ -296,8 +271,7 @@ public abstract class serverAbstractThread extends Thread implements serverThreatimestamp = System.currentTimeMillis();ratz(this.idlePause);idletime += System.currentTimeMillis() - timestamp;- } else if ((memnow = serverMemory.available()) > memprereq ||- ((memnow + GCAverage() > memprereq || GCAverage() == 0) && memnow + runGC() > memprereq)) try {+ } else if ((memnow = serverMemory.available()) > memprereq) try {// do jobtimestamp = System.currentTimeMillis();memstamp0 = serverMemory.used();@@ -331,8 +305,7 @@ public abstract class serverAbstractThread extends Thread implements serverThreabusyCycles++;} else {log.logWarning("Thread '" + this.getName() + "' runs short memory cycle. Free mem: " +- (memnow / 1024) + " KB, needed: " + (memprereq / 1024) + " KB, " +- "GC should provide max. " + (GCAverage() / 1024) + "KB");+ (memnow / 1024) + " KB, needed: " + (memprereq / 1024) + " KB");// omit job, not enough memory// process scheduled pausetimestamp = System.currentTimeMillis();diff --git a/source/de/anomic/server/serverInstantThread.java b/source/de/anomic/server/serverInstantThread.javaindex e8c3400d0..80cf40e7a 100644--- a/source/de/anomic/server/serverInstantThread.java+++ b/source/de/anomic/server/serverInstantThread.java@@ -117,7 +117,9 @@ public final class serverInstantThread extends serverAbstractThread implements sserverLog.logSevere("SERVER", "shutting down thread '" + this.getName() + "'");this.terminate(false);} catch (InvocationTargetException e) {- serverLog.logSevere("SERVER", "Runtime Error in serverInstantThread.job, thread '" + this.getName() + "': " + e.getMessage() + "; target exception: " + e.getTargetException().getMessage(), e.getTargetException());+ String targetException = e.getTargetException().getMessage();+ if (targetException.indexOf("heap space") > 0) e.getTargetException().printStackTrace();+ serverLog.logSevere("SERVER", "Runtime Error in serverInstantThread.job, thread '" + this.getName() + "': " + e.getMessage() + "; target exception: " + targetException, e.getTargetException());e.getTargetException().printStackTrace();} catch (OutOfMemoryError e) {serverLog.logSevere("SERVER", "OutOfMemory Error in serverInstantThread.job, thread '" + this.getName() + "': " + e.getMessage());@@ -141,7 +143,9 @@ public final class serverInstantThread extends serverAbstractThread implements sserverLog.logSevere("SERVER", "shutting down thread '" + this.getName() + "'");this.terminate(false);} catch (InvocationTargetException e) {- serverLog.logSevere("SERVER", "Runtime Error in serverInstantThread.freemem, thread '" + this.getName() + "': " + e.getMessage() + "; target exception: " + e.getTargetException().getMessage(), e.getTargetException());+ String targetException = e.getTargetException().getMessage();+ if (targetException.indexOf("heap space") > 0) e.getTargetException().printStackTrace();+ serverLog.logSevere("SERVER", "Runtime Error in serverInstantThread.freemem, thread '" + this.getName() + "': " + e.getMessage() + "; target exception: " + targetException, e.getTargetException());e.getTargetException().printStackTrace();} catch (OutOfMemoryError e) {serverLog.logSevere("SERVER", "OutOfMemory Error in serverInstantThread.freemem, thread '" + this.getName() + "': " + e.getMessage());diff --git a/source/de/anomic/yacy/yacyNewsDB.java b/source/de/anomic/yacy/yacyNewsDB.javaindex 9c3cc0505..d3356116c 100644--- a/source/de/anomic/yacy/yacyNewsDB.java+++ b/source/de/anomic/yacy/yacyNewsDB.java@@ -112,7 +112,7 @@ public class yacyNewsDB {Iterator rowIterator;public recordIterator() throws IOException {- rowIterator = news.rows(true, false, null);+ rowIterator = news.rows(true, null);}public boolean hasNext() {diff --git a/source/yacy.java b/source/yacy.javaindex 10ea41dbc..c3cc8ee88 100644--- a/source/yacy.java+++ b/source/yacy.java@@ -990,7 +990,7 @@ public final class yacy {int c = 0;long start = System.currentTimeMillis();if (source.equals("lurl")) {- Iterator eiter = sb.wordIndex.loadedURL.entries(true, false, null);+ Iterator eiter = sb.wordIndex.loadedURL.entries(true, null);indexURLEntry entry;while (eiter.hasNext()) {try {@@ -1010,7 +1010,7 @@ public final class yacy {}}if (source.equals("eurl")) {- Iterator eiter = sb.errorURL.entries(true, false, null);+ Iterator eiter = sb.errorURL.entries(true, null);plasmaCrawlEURL.Entry entry;while (eiter.hasNext()) {try {@@ -1029,7 +1029,7 @@ public final class yacy {}}if (source.equals("nurl")) {- Iterator eiter = sb.noticeURL.entries(true, false, null);+ Iterator eiter = sb.noticeURL.entries(true, null);plasmaCrawlNURL.Entry entry;while (eiter.hasNext()) {try {@@ -1102,7 +1102,7 @@ public final class yacy {BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));if (source.equals("lurl")) {- Iterator eiter = sb.wordIndex.loadedURL.entries(true, false, null);+ Iterator eiter = sb.wordIndex.loadedURL.entries(true, null);indexURLEntry entry;while (eiter.hasNext()) {entry = (indexURLEntry) eiter.next();@@ -1119,7 +1119,7 @@ public final class yacy {}}if (source.equals("eurl")) {- Iterator eiter = sb.errorURL.entries(true, false, null);+ Iterator eiter = sb.errorURL.entries(true, null);plasmaCrawlEURL.Entry entry;while (eiter.hasNext()) {entry = (plasmaCrawlEURL.Entry) eiter.next();@@ -1135,7 +1135,7 @@ public final class yacy {}}if (source.equals("nurl")) {- Iterator eiter = sb.noticeURL.entries(true, false, null);+ Iterator eiter = sb.noticeURL.entries(true, null);plasmaCrawlNURL.Entry entry;while (eiter.hasNext()) {entry = (plasmaCrawlNURL.Entry) eiter.next();diff --git a/yacy.init b/yacy.initindex 609ebb4d5..e62eb7552 100644--- a/yacy.init+++ b/yacy.init@@ -496,7 +496,7 @@ xpstopw=true70_cachemanager_memprereq=104857680_indexing_idlesleep=100080_indexing_busysleep=50-80_indexing_memprereq=2097152+80_indexing_memprereq=419430482_crawlstack_idlesleep=500082_crawlstack_busysleep=082_crawlstack_memprereq=1048576