Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

fix for really bad table iteration implementation: reduction of IO

orbitercdfe8afe3f43
diff --git a/source/de/anomic/yacy/yacyNewsPool.java b/source/de/anomic/yacy/yacyNewsPool.java
index 014a9b17c..56c0a0e55 100644
--- a/source/de/anomic/yacy/yacyNewsPool.java
+++ b/source/de/anomic/yacy/yacyNewsPool.java
@@ -447,6 +447,18 @@ public class yacyNewsPool {
}
return null;
}
+/*
+ * java.io.FileNotFoundException: /home/administrator/yacy/DATA/INDEX/webportal/NETWORK/newsOut.table (Too many open files)
+ at java.io.FileInputStream.open(Native Method)
+ at java.io.FileInputStream.<init>(FileInputStream.java:137)
+ at net.yacy.kelondro.table.ChunkIterator.<init>(ChunkIterator.java:63)
+ at net.yacy.kelondro.table.Table$rowIteratorNoOrder.<init>(Table.java:832)
+ at net.yacy.kelondro.table.Table.rows(Table.java:825)
+ at de.anomic.yacy.yacyNewsQueue$newsIterator.<init>(yacyNewsQueue.java:193)
+ at de.anomic.yacy.yacyNewsQueue.records(yacyNewsQueue.java:183)
+ at de.anomic.yacy.yacyNewsPool.getSpecific(yacyNewsPool.java:440)
+ at yacysearchitem.respond(yacysearchitem.java:119)
+ */
public synchronized yacyNewsDB.Record getByOriginator(final int dbKey, final String category, final String originatorHash) {
final yacyNewsQueue queue = switchQueue(dbKey);
diff --git a/source/net/yacy/kelondro/table/Table.java b/source/net/yacy/kelondro/table/Table.java
index 4b73df1e1..1c86249ee 100644
--- a/source/net/yacy/kelondro/table/Table.java
+++ b/source/net/yacy/kelondro/table/Table.java
@@ -75,7 +75,6 @@ public class Table implements Index, Iterable<Row.Entry> {
private final long minmemremaining; // if less than this memory is remaininig, the memory copy of a table is abandoned
private final int buffersize;
private final Row rowdef;
- private final File tablefile;
private final Row taildef;
private HandleMap index;
private BufferedRecords file;
@@ -90,7 +89,6 @@ public class Table implements Index, Iterable<Row.Entry> {
final boolean exceed134217727) throws RowSpaceExceededException {
useTailCache = true; // fixed for testing
- this.tablefile = tablefile;
this.rowdef = rowdef;
this.buffersize = buffersize;
this.minmemremaining = Math.max(20 * 1024 * 1024, MemoryControl.available() / 10);
@@ -826,10 +824,14 @@ public class Table implements Index, Iterable<Row.Entry> {
}
private class rowIteratorNoOrder implements CloneableIterator<Entry> {
- private final Iterator<byte[]> ri;
+ Iterator<Row.Entry> i;
+ int idx;
+ byte[] key;
public rowIteratorNoOrder() throws IOException {
- ri = new ChunkIterator(tablefile, rowdef.objectsize, rowdef.objectsize);
+ // don't use the ChunkIterator here because it may create too many open files during string load
+ //ri = new ChunkIterator(tablefile, rowdef.objectsize, rowdef.objectsize);
+ i = index.iterator();
}
public CloneableIterator<Entry> clone(Object modifier) {
@@ -842,16 +844,31 @@ public class Table implements Index, Iterable<Row.Entry> {
}
public boolean hasNext() {
- return ri.hasNext();
+ return i.hasNext();
}
public Entry next() {
- byte[] r = ri.next();
- return rowdef.newEntry(r);
+ Row.Entry entry = i.next();
+ if (entry == null) return null;
+ key = entry.getPrimaryKeyBytes();
+ if (key == null) return null;
+ idx = (int) entry.getColLong(1);
+ try {
+ return get(key);
+ } catch (IOException e) {
+ return null;
+ }
}
public void remove() {
- ri.remove();
+ if (key != null) {
+ try {
+ removeInFile(idx);
+ } catch (IOException e) {
+ } catch (RowSpaceExceededException e) {
+ }
+ i.remove();
+ }
}
}