- removed synchronization during index dump and index cleaning

- added semaphores to synchronize index dump and index cleaning for each process separately

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6767 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 15 years ago
parent 95f31da8da
commit 31e29a8831

@ -30,6 +30,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Semaphore;
import de.anomic.yacy.graphics.ProfilingGraph; import de.anomic.yacy.graphics.ProfilingGraph;
@ -71,7 +72,8 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu
private final long targetFileSize, maxFileSize; private final long targetFileSize, maxFileSize;
private final int writeBufferSize; private final int writeBufferSize;
private final ARC<ByteArray, Integer> countCache; private final ARC<ByteArray, Integer> countCache;
private boolean cleanerRunning = false; private Semaphore dumperSemaphore = new Semaphore(1);
private Semaphore cleanerSemaphore = new Semaphore(1);
public IndexCell( public IndexCell(
final File cellPath, final File cellPath,
@ -382,29 +384,41 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu
this.countCache.clear(); this.countCache.clear();
// dump the cache if necessary // dump the cache if necessary
if (this.ram.size() >= this.maxRamEntries || (this.ram.size() > 3000 && !MemoryControl.request(80L * 1024L * 1024L, false))) synchronized (this) { if (this.dumperSemaphore.availablePermits() > 0 &&
if (this.ram.size() >= this.maxRamEntries || (this.ram.size() > 3000 && !MemoryControl.request(80L * 1024L * 1024L, false))) { (this.ram.size() >= this.maxRamEntries ||
// dump the ram (this.ram.size() > 3000 && !MemoryControl.request(80L * 1024L * 1024L, false)))) {
File dumpFile = this.array.newContainerBLOBFile(); try {
// a critical point: when the ram is handed to the dump job, this.dumperSemaphore.acquire(); // only one may pass
// dont write into it any more. Use a fresh one instead if (this.ram.size() >= this.maxRamEntries || (this.ram.size() > 3000 && !MemoryControl.request(80L * 1024L * 1024L, false))) {
ReferenceContainerCache<ReferenceType> ramdump = this.ram; // dump the ram
// get a fresh ram cache File dumpFile = this.array.newContainerBLOBFile();
this.ram = new ReferenceContainerCache<ReferenceType>(factory, this.array.rowdef(), this.array.ordering()); // a critical point: when the ram is handed to the dump job,
// dump the buffer // dont write into it any more. Use a fresh one instead
merger.dump(ramdump, dumpFile, array); ReferenceContainerCache<ReferenceType> ramdump = this.ram;
// get a fresh ram cache
this.ram = new ReferenceContainerCache<ReferenceType>(factory, this.array.rowdef(), this.array.ordering());
// dump the buffer
merger.dump(ramdump, dumpFile, array);
}
this.dumperSemaphore.release();
} catch (InterruptedException e) {
Log.logException(e);
} }
} }
// clean-up the cache // clean-up the cache
if (!this.cleanerRunning && (this.array.entries() > 50 || this.lastCleanup + cleanupCycle < System.currentTimeMillis())) synchronized (this) { if (this.cleanerSemaphore.availablePermits() > 0 &&
if (this.array.entries() > 50 || (this.lastCleanup + cleanupCycle < System.currentTimeMillis())) try { (this.array.entries() > 50 ||
this.cleanerRunning = true; this.lastCleanup + cleanupCycle < System.currentTimeMillis())) {
//System.out.println("----cleanup check"); try {
this.array.shrink(this.targetFileSize, this.maxFileSize); this.cleanerSemaphore.acquire();
this.lastCleanup = System.currentTimeMillis(); if (this.array.entries() > 50 || (this.lastCleanup + cleanupCycle < System.currentTimeMillis())) {
} finally { this.array.shrink(this.targetFileSize, this.maxFileSize);
this.cleanerRunning = false; this.lastCleanup = System.currentTimeMillis();
}
this.cleanerSemaphore.release();
} catch (InterruptedException e) {
Log.logException(e);
} }
} }
} }

Loading…
Cancel
Save