diff --git a/source/de/anomic/plasma/plasmaWordIndexAssortment.java b/source/de/anomic/plasma/plasmaWordIndexAssortment.java index 6023bc85a..e7b339511 100644 --- a/source/de/anomic/plasma/plasmaWordIndexAssortment.java +++ b/source/de/anomic/plasma/plasmaWordIndexAssortment.java @@ -167,7 +167,8 @@ 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 diff --git a/source/de/anomic/plasma/plasmaWordIndexCache.java b/source/de/anomic/plasma/plasmaWordIndexCache.java index 52ac659ea..6db3246d4 100644 --- a/source/de/anomic/plasma/plasmaWordIndexCache.java +++ b/source/de/anomic/plasma/plasmaWordIndexCache.java @@ -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,49 +273,35 @@ 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); - if (reintegrate) { - // put singleton together with container back to ram - synchronized (cache) { - cache.put(key, container); - hashScore.setScore(key, container.size()); - hashDate.put(key, new Long(time)); - } - return -1; - } else { - // add this to the backend - return backend.addEntries(container, java.lang.Math.max(time, oldTime)); - } + + // 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) { + cache.put(key, container); + hashScore.setScore(key, container.size()); + hashDate.put(key, new Long(time)); + } + return -1; + } else { + // add this to the backend + return backend.addEntries(container, java.lang.Math.max(time, oldTime)); } } } 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; }