Implement sharing of ioDispatcher for term & citation index

as proposed in ioDispatcher description
pull/8/head
reger 10 years ago
parent 17e820cfd7
commit d882991bc5

@ -93,10 +93,10 @@ public class IODispatcher extends Thread {
// check if the dispatcher is running // check if the dispatcher is running
if (isAlive()) { if (isAlive()) {
try { try {
this.dumpQueue.put(job); this.dumpQueue.add(job);
log.info("appended dump job for file " + file.getName()); log.info("appended dump job for file " + file.getName());
} catch (final InterruptedException e) { } catch (final IllegalStateException e) {
ConcurrentLog.logException(e); log.warn("could not append dump job, emergency dump of file " + file.getName());
cache.dump(file, (int) Math.min(MemoryControl.available() / 3, this.writeBufferSize), true); cache.dump(file, (int) Math.min(MemoryControl.available() / 3, this.writeBufferSize), true);
} finally { } finally {
this.controlQueue.release(); this.controlQueue.release();
@ -130,8 +130,8 @@ public class IODispatcher extends Thread {
} else { } else {
log.info("appended merge job of files " + f1.getName() + ", " + f2.getName() + " to " + newFile.getName()); log.info("appended merge job of files " + f1.getName() + ", " + f2.getName() + " to " + newFile.getName());
} }
} catch (final Exception e) { // because mergeQueue size is 1, IllegalStateException could happen frequently (serial execution ensured in run() ) } catch (final IllegalStateException e) { // because mergeQueue size is 1, IllegalStateException could happen frequently (serial execution ensured in run() )
log.warn("Could not add merge job to queue: " + e.getMessage(), e); log.warn("Could not add merge job to queue: " + e.getMessage());
} finally { } finally {
this.controlQueue.release(); this.controlQueue.release();
} }
@ -195,9 +195,7 @@ public class IODispatcher extends Thread {
log.info("caught termination signal"); log.info("caught termination signal");
break; break;
} }
log.severe("main loop in bad state, dumpQueue.size() = " + this.dumpQueue.size() + ", mergeQueue.size() = " + this.mergeQueue.size() + ", controlQueue.availablePermits() = " + this.controlQueue.availablePermits() + ", MemoryControl.shortStatus() = " + MemoryControl.shortStatus());
assert false : "this process statt should not be reached"; // this should never happen
} catch (final Throwable e) { } catch (final Throwable e) {
log.severe("main run job failed (X)", e); log.severe("main run job failed (X)", e);
} }

@ -72,7 +72,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu
private ReferenceContainerCache<ReferenceType> ram; private ReferenceContainerCache<ReferenceType> ram;
private final ComparableARC<byte[], Integer> countCache; private final ComparableARC<byte[], Integer> countCache;
private int maxRamEntries; private int maxRamEntries;
private final IODispatcher merger; private IODispatcher merger; // pointer to shared merger
private long lastCleanup; private long lastCleanup;
private long lastDump; private long lastDump;
private final long targetFileSize, maxFileSize; private final long targetFileSize, maxFileSize;
@ -90,16 +90,16 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu
final int maxRamEntries, final int maxRamEntries,
final long targetFileSize, final long targetFileSize,
final long maxFileSize, final long maxFileSize,
final int writeBufferSize final int writeBufferSize,
final IODispatcher merger
) throws IOException { ) throws IOException {
super(factory); super(factory);
this.merger = new IODispatcher(2, 1, writeBufferSize); this.merger = merger;
this.array = new ReferenceContainerArray<ReferenceType>(cellPath, prefix, factory, termOrder, termSize); this.array = new ReferenceContainerArray<ReferenceType>(cellPath, prefix, factory, termOrder, termSize);
this.ram = new ReferenceContainerCache<ReferenceType>(factory, termOrder, termSize); this.ram = new ReferenceContainerCache<ReferenceType>(factory, termOrder, termSize);
this.countCache = new ComparableARC<byte[], Integer>(1000, termOrder); this.countCache = new ComparableARC<byte[], Integer>(1000, termOrder);
this.maxRamEntries = maxRamEntries; this.maxRamEntries = maxRamEntries;
this.merger.start();
this.lastCleanup = System.currentTimeMillis(); this.lastCleanup = System.currentTimeMillis();
this.lastDump = System.currentTimeMillis(); this.lastDump = System.currentTimeMillis();
this.targetFileSize = targetFileSize; this.targetFileSize = targetFileSize;
@ -600,7 +600,6 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu
// close all // close all
this.flushShallRun = false; this.flushShallRun = false;
if (this.flushThread != null) try { this.flushThread.join(); } catch (final InterruptedException e) {} if (this.flushThread != null) try { this.flushThread.join(); } catch (final InterruptedException e) {}
this.merger.terminate();
this.ram.close(); this.ram.close();
this.array.close(); this.array.close();
} }

@ -73,6 +73,7 @@ import net.yacy.kelondro.data.word.WordReference;
import net.yacy.kelondro.data.word.WordReferenceFactory; import net.yacy.kelondro.data.word.WordReferenceFactory;
import net.yacy.kelondro.data.word.WordReferenceRow; import net.yacy.kelondro.data.word.WordReferenceRow;
import net.yacy.kelondro.index.RowHandleSet; import net.yacy.kelondro.index.RowHandleSet;
import net.yacy.kelondro.rwi.IODispatcher;
import net.yacy.kelondro.rwi.IndexCell; import net.yacy.kelondro.rwi.IndexCell;
import net.yacy.kelondro.rwi.ReferenceContainer; import net.yacy.kelondro.rwi.ReferenceContainer;
import net.yacy.kelondro.rwi.ReferenceFactory; import net.yacy.kelondro.rwi.ReferenceFactory;
@ -120,6 +121,7 @@ public class Segment {
protected IndexCell<WordReference> termIndex; protected IndexCell<WordReference> termIndex;
protected IndexCell<CitationReference> urlCitationIndex; protected IndexCell<CitationReference> urlCitationIndex;
protected IndexTable firstSeenIndex; protected IndexTable firstSeenIndex;
protected IODispatcher merger = null; // shared iodispatcher for kelondro indexes
/** /**
* create a new Segment * create a new Segment
@ -148,6 +150,11 @@ public class Segment {
public void connectRWI(final int entityCacheMaxSize, final long maxFileSize) throws IOException { public void connectRWI(final int entityCacheMaxSize, final long maxFileSize) throws IOException {
if (this.termIndex != null) return; if (this.termIndex != null) return;
if (this.merger == null) { // init shared iodispatcher if none running
this.merger = new IODispatcher(2, 2, writeBufferSize);
this.merger.start();
}
this.termIndex = new IndexCell<WordReference>( this.termIndex = new IndexCell<WordReference>(
new File(this.segmentPath, "default"), new File(this.segmentPath, "default"),
termIndexName, termIndexName,
@ -157,7 +164,8 @@ public class Segment {
entityCacheMaxSize, entityCacheMaxSize,
targetFileSize, targetFileSize,
maxFileSize, maxFileSize,
writeBufferSize); writeBufferSize,
merger);
} }
public void disconnectRWI() { public void disconnectRWI() {
@ -172,6 +180,11 @@ public class Segment {
public void connectCitation(final int entityCacheMaxSize, final long maxFileSize) throws IOException { public void connectCitation(final int entityCacheMaxSize, final long maxFileSize) throws IOException {
if (this.urlCitationIndex != null) return; if (this.urlCitationIndex != null) return;
if (this.merger == null) { // init shared iodispatcher if none running
this.merger = new IODispatcher(2,2,writeBufferSize);
this.merger.start();
}
this.urlCitationIndex = new IndexCell<CitationReference>( this.urlCitationIndex = new IndexCell<CitationReference>(
new File(this.segmentPath, "default"), new File(this.segmentPath, "default"),
citationIndexName, citationIndexName,
@ -181,7 +194,8 @@ public class Segment {
entityCacheMaxSize, entityCacheMaxSize,
targetFileSize, targetFileSize,
maxFileSize, maxFileSize,
writeBufferSize); writeBufferSize,
merger);
} }
public void disconnectCitation() { public void disconnectCitation() {
@ -468,6 +482,10 @@ public class Segment {
if (this.fulltext != null) this.fulltext.close(); if (this.fulltext != null) this.fulltext.close();
if (this.urlCitationIndex != null) this.urlCitationIndex.close(); if (this.urlCitationIndex != null) this.urlCitationIndex.close();
if (this.firstSeenIndex != null) this.firstSeenIndex.close(); if (this.firstSeenIndex != null) this.firstSeenIndex.close();
if (this.merger != null) {
this.merger.terminate();
this.merger = null;
}
} }
private static String votedLanguage( private static String votedLanguage(

Loading…
Cancel
Save