Skip to content

Commit

Permalink
fixe timing problem causing too long delay during initialization of k…
Browse files Browse the repository at this point in the history
…elondroTree objects

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2288 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Jul 11, 2006
1 parent d2bb3f4 commit 40aa735
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
4 changes: 2 additions & 2 deletions source/de/anomic/kelondro/kelondroFlexTable.java
Expand Up @@ -74,7 +74,7 @@ public kelondroFlexTable(File path, String tablename, long buffersize, long prel
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;
Expand All @@ -100,7 +100,7 @@ private kelondroIndex initializeRamIndex() throws IOException {

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;
Expand Down
40 changes: 25 additions & 15 deletions source/de/anomic/kelondro/kelondroRecords.java
Expand Up @@ -428,16 +428,22 @@ private void initCache(long buffersize, long preloadTime) {
// 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");

}
}

Expand Down Expand Up @@ -1000,10 +1006,10 @@ private void dispose(Handle h) throws IOException {
}
}

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();
}
Expand All @@ -1015,8 +1021,8 @@ public class contentRowIterator implements Iterator {

private Iterator nodeIterator;

public contentRowIterator() throws IOException {
nodeIterator = contentNodes();
public contentRowIterator(long maxInitTime) throws IOException {
nodeIterator = contentNodes(maxInitTime);
}

public boolean hasNext() {
Expand All @@ -1037,10 +1043,10 @@ public void remove() {

}

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();
}
Expand All @@ -1057,17 +1063,21 @@ protected class contentNodeIterator implements Iterator {
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");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/de/anomic/plasma/dbImport/AssortmentImporter.java
Expand Up @@ -89,7 +89,7 @@ public String getStatus() {
public void run() {
try {
// getting a content interator
Iterator contentIter = this.assortmentFile.content();
Iterator contentIter = this.assortmentFile.content(-1);
while (contentIter.hasNext()) {
this.wordEntityCount++;

Expand Down
4 changes: 2 additions & 2 deletions source/de/anomic/plasma/plasmaWordIndexAssortment.java
Expand Up @@ -266,8 +266,8 @@ public Iterator hashes(String startWordHash, boolean up, boolean rot) throws IOE
}
}

public Iterator content() {
return this.assortments.contentRows();
public Iterator content(long maxInitTime) {
return this.assortments.contentRows(maxInitTime);
}

public int size() {
Expand Down

0 comments on commit 40aa735

Please sign in to comment.