enhanced Assortment class

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@141 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 20 years ago
parent 9ee3e69021
commit 79be6f003d

@ -168,6 +168,7 @@ public final class plasmaWordIndexAssortment {
if (oldrow != null) throw new RuntimeException("Store to assortment ambiguous");
}
/*
public record read(String wordHash) {
// returns a single word index from assortment database; returns null if index does not exist
//log.logDebug("readAssortment: wordHash=" + wordHash);
@ -208,6 +209,33 @@ public final class plasmaWordIndexAssortment {
resetDatabase();
}
}
*/
public record remove(String wordHash) {
// deletes a word index from assortment database
// and returns the content record
byte[][] row = null;
try {
row = assortments.remove(wordHash.getBytes());
} catch (IOException e) {
log.logFailure("removeAssortment/IO-error: " + e.getMessage() + " - reset assortment-DB");
e.printStackTrace();
resetDatabase();
return null;
} catch (kelondroException e) {
log.logFailure("removeAssortment/kelondro-error: " + e.getMessage() + " - reset assortment-DB");
e.printStackTrace();
resetDatabase();
return null;
}
if (row == null) return null;
long creationTime = kelondroRecords.bytes2long(row[2]);
plasmaWordIndexEntry[] wordEntries = new plasmaWordIndexEntry[this.bufferStructureLength];
for (int i = 0; i < assortmentCapacity; i++) {
wordEntries[i] = new plasmaWordIndexEntry(new String(row[3 + 2 * i]), new String(row[4 + 2 * i]));
}
return new record(wordEntries, creationTime);
}
private void resetDatabase() {
// deletes the assortment database and creates a new one

@ -258,7 +258,7 @@ public final class plasmaWordIndexCache implements plasmaWordIndexInterface {
}
// now decide where to flush that container
plasmaWordIndexAssortment.record singleton = singletons.read(key);
plasmaWordIndexAssortment.record singleton = singletons.remove(key);
if (singleton == null) {
// not found in singletons
if (container.size() == 1) {
@ -273,22 +273,11 @@ public final class plasmaWordIndexCache implements plasmaWordIndexInterface {
// we have a singleton and need to integrate this in the flush
plasmaWordIndexEntry oldEntry = singleton.entries[0];
long oldTime = singleton.creationTime;
if (container.contains(oldEntry.getUrlHash())) {
// we have an double-occurrence
if (container.size() == 1) {
// it is superfluous to flush this, simple do nothing
return 0;
} else {
// we flush to the backend, and the entry from the singletons
singletons.remove(key);
return backend.addEntries(container, java.lang.Math.max(time, oldTime));
}
} else {
// now we have more than one entry
// we must remove the key from the singleton database
singletons.remove(key);
// .. and put it to the container
container.add(oldEntry);
// put new entries to the container
if (!(container.contains(oldEntry.getUrlHash()))) container.add(oldEntry);
// possibly reintegrate
if (reintegrate) {
// put singleton together with container back to ram
synchronized (cache) {
@ -303,19 +292,16 @@ public final class plasmaWordIndexCache implements plasmaWordIndexInterface {
}
}
}
}
private boolean flushFromSingleton(String key) {
// this should only be called if the singleton shall be deleted or returned in an index entity
plasmaWordIndexAssortment.record singleton = singletons.read(key);
plasmaWordIndexAssortment.record singleton = singletons.remove(key);
if (singleton == null) {
return false;
} else {
// we have a singleton
plasmaWordIndexEntry entry = (plasmaWordIndexEntry) singleton.entries[0];
long time = singleton.creationTime;
// remove it from the singleton database
singletons.remove(key);
// integrate it to the backend
return backend.addEntries(plasmaWordIndexEntryContainer.instantContainer(key, entry), time) > 0;
}

Loading…
Cancel
Save