fixe timing problem causing too long delay during initialization of kelondroTree objects

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2288 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 19 years ago
parent d2bb3f442e
commit 40aa735520

@ -74,7 +74,7 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr
private kelondroIndex initializeRamIndex() throws IOException {
kelondroRowBufferedSet ri = new kelondroRowBufferedSet(new kelondroRow(new int[]{super.row().width(0), 4}), 0);
ri.setOrdering(kelondroNaturalOrder.naturalOrder, 0);
Iterator content = super.col[0].contentNodes();
Iterator content = super.col[0].contentNodes(-1);
kelondroRecords.Node node;
kelondroRow.Entry indexentry;
int i;
@ -100,7 +100,7 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr
private kelondroIndex initializeTreeIndex(File indexfile, long buffersize, long preloadTime) throws IOException {
kelondroTree index = new kelondroTree(indexfile, buffersize, preloadTime, 10, rowdef.width(0), 4, true);
Iterator content = super.col[0].contentNodes();
Iterator content = super.col[0].contentNodes(-1);
kelondroRecords.Node node;
kelondroRow.Entry indexentry;
int i;

@ -428,16 +428,22 @@ public class kelondroRecords {
// pre-load node cache
if ((preloadTime > 0) && (cacheSize > 0)) {
long stop = System.currentTimeMillis() + preloadTime;
Iterator i = contentNodes();
Node n;
int count = 0;
while ((System.currentTimeMillis() < stop) && (cacheHeaders.size() < cacheSize) && (i.hasNext())) {
n = (Node) i.next();
cacheHeaders.addb(n.handle.index, n.headChunk);
count++;
try {
Iterator i = contentNodes(preloadTime);
Node n;
while ((System.currentTimeMillis() < stop) && (cacheHeaders.size() < cacheSize) && (i.hasNext())) {
n = (Node) i.next();
cacheHeaders.addb(n.handle.index, n.headChunk);
count++;
}
cacheHeaders.shape();
logFine("preloaded " + count + " records into cache");
} catch (kelondroException e) {
// the contentNodes iterator had a time-out; we don't do a preload
logFine("could not preload records: " + e.getMessage());
}
cacheHeaders.shape();
logFine("preloaded " + count + " records into cache");
}
}
@ -1000,10 +1006,10 @@ public class kelondroRecords {
}
}
public Iterator contentRows() {
public Iterator contentRows(long maxInitTime) throws kelondroException {
// returns an iterator of kelondroRow.Entry-objects that are not marked as 'deleted'
try {
return new contentRowIterator();
return new contentRowIterator(maxInitTime);
} catch (IOException e) {
return new HashSet().iterator();
}
@ -1015,8 +1021,8 @@ public class kelondroRecords {
private Iterator nodeIterator;
public contentRowIterator() throws IOException {
nodeIterator = contentNodes();
public contentRowIterator(long maxInitTime) throws IOException {
nodeIterator = contentNodes(maxInitTime);
}
public boolean hasNext() {
@ -1037,10 +1043,10 @@ public class kelondroRecords {
}
protected Iterator contentNodes() {
protected Iterator contentNodes(long maxInitTime) throws kelondroException {
// returns an iterator of Node-objects that are not marked as 'deleted'
try {
return new contentNodeIterator();
return new contentNodeIterator(maxInitTime);
} catch (IOException e) {
return new HashSet().iterator();
}
@ -1057,17 +1063,21 @@ public class kelondroRecords {
private int bulksize;
private int bulkstart; // the offset of the bulk array to the node position
public contentNodeIterator() throws IOException {
public contentNodeIterator(long maxInitTime) throws IOException, kelondroException {
pos = new Handle(0);
// initialize set with deleted nodes
// this may last only the given maxInitTime
// if the initTime is exceeded, the method throws an kelondroException
markedDeleted = new HashSet();
long timeLimit = (maxInitTime < 0) ? Long.MAX_VALUE : System.currentTimeMillis() + maxInitTime;
synchronized (USAGE) {
if (USAGE.FREEC != 0) {
Handle h = USAGE.FREEH;
while (h.index != NUL) {
markedDeleted.add(h);
h = new Handle(entryFile.readInt(seekpos(h)));
if (System.currentTimeMillis() > timeLimit) throw new kelondroException(filename, "time limit of " + maxInitTime + " exceeded; > " + markedDeleted.size() + " deleted entries");
}
}
}

@ -89,7 +89,7 @@ public class AssortmentImporter extends AbstractImporter implements dbImporter{
public void run() {
try {
// getting a content interator
Iterator contentIter = this.assortmentFile.content();
Iterator contentIter = this.assortmentFile.content(-1);
while (contentIter.hasNext()) {
this.wordEntityCount++;

@ -266,8 +266,8 @@ public final class plasmaWordIndexAssortment {
}
}
public Iterator content() {
return this.assortments.contentRows();
public Iterator content(long maxInitTime) {
return this.assortments.contentRows(maxInitTime);
}
public int size() {

Loading…
Cancel
Save