diff --git a/source/de/anomic/crawler/IndexingStack.java b/source/de/anomic/crawler/IndexingStack.java index df9c7bc05..6a491e8c9 100644 --- a/source/de/anomic/crawler/IndexingStack.java +++ b/source/de/anomic/crawler/IndexingStack.java @@ -78,7 +78,7 @@ public class IndexingStack { NaturalOrder.naturalOrder ); - public int size() { + public synchronized int size() { return (sbQueueStack == null) ? 0 : sbQueueStack.size(); } @@ -98,33 +98,33 @@ public class IndexingStack { } public synchronized QueueEntry pop() throws IOException { - synchronized (sbQueueStack) { - int sizeBefore; - while ((sizeBefore = sbQueueStack.size()) > 0) { - Row.Entry b = sbQueueStack.pot(); - if (b == null) { - Log.logInfo("IndexingStack", "sbQueueStack.pot() == null"); - if (sbQueueStack.size() < sizeBefore) continue; - Log.logSevere("IndexingStack", "sbQueueStack does not shrink after pot() == null; trying pop()"); - } - if (sbQueueStack.size() < sizeBefore) { - return new QueueEntry(b); - } else { - Log.logSevere("IndexingStack", "sbQueueStack does not shrink after pot() != null; trying pop()"); - } - sizeBefore = sbQueueStack.size(); - b = sbQueueStack.pop(); - if (b == null) { - Log.logInfo("IndexingStack", "sbQueueStack.pop() == null"); - if (sbQueueStack.size() < sizeBefore) continue; - Log.logSevere("IndexingStack", "sbQueueStack does not shrink after pop() == null; failed"); - return null; - } - return new QueueEntry(b); - } - Log.logInfo("IndexingStack", "sbQueueStack.size() == 0"); - return null; + if (sbQueueStack == null) return null; + // this shall not return null because it may cause a emergency reset! + int sizeBefore; + while ((sizeBefore = sbQueueStack.size()) > 0) { + Row.Entry b = sbQueueStack.pot(); + if (b == null) { + Log.logInfo("IndexingStack", "sbQueueStack.pot() == null"); + if (sbQueueStack.size() < sizeBefore) continue; + Log.logSevere("IndexingStack", "sbQueueStack does not shrink after pot() == null; trying pop()"); + } + if (sbQueueStack.size() < sizeBefore) { + return new QueueEntry(b); + } else { + Log.logSevere("IndexingStack", "sbQueueStack does not shrink after pot() != null; trying pop()"); + } + sizeBefore = sbQueueStack.size(); + b = sbQueueStack.pop(); + if (b == null) { + Log.logInfo("IndexingStack", "sbQueueStack.pop() == null"); + if (sbQueueStack.size() < sizeBefore) continue; + Log.logSevere("IndexingStack", "sbQueueStack does not shrink after pop() == null; failed"); + return null; + } + return new QueueEntry(b); } + Log.logInfo("IndexingStack", "sbQueueStack.size() == 0"); + return null; } public synchronized QueueEntry remove(final String urlHash) { diff --git a/source/de/anomic/kelondro/blob/BLOBHeap.java b/source/de/anomic/kelondro/blob/BLOBHeap.java index bb8fc0ead..19536142c 100755 --- a/source/de/anomic/kelondro/blob/BLOBHeap.java +++ b/source/de/anomic/kelondro/blob/BLOBHeap.java @@ -246,7 +246,7 @@ public final class BLOBHeap extends BLOBHeapModifier implements BLOB { /** * close the BLOB table */ - public synchronized void close() { + public synchronized void close(boolean writeIDX) { if (file != null) { try { flushBuffer(); @@ -255,7 +255,7 @@ public final class BLOBHeap extends BLOBHeapModifier implements BLOB { } } this.buffer = null; - super.close(); + super.close(writeIDX); assert file == null; } @@ -443,7 +443,7 @@ public final class BLOBHeap extends BLOBHeapModifier implements BLOB { heap.remove("aaaaaaaaaaab".getBytes()); heap.remove("aaaaaaaaaaac".getBytes()); heap.put("aaaaaaaaaaaX".getBytes(), "WXYZ".getBytes()); - heap.close(); + heap.close(true); } catch (final IOException e) { e.printStackTrace(); } diff --git a/source/de/anomic/kelondro/blob/BLOBHeapModifier.java b/source/de/anomic/kelondro/blob/BLOBHeapModifier.java index df440512d..d21e147ae 100644 --- a/source/de/anomic/kelondro/blob/BLOBHeapModifier.java +++ b/source/de/anomic/kelondro/blob/BLOBHeapModifier.java @@ -105,10 +105,7 @@ public class BLOBHeapModifier extends HeapReader implements BLOB { */ public synchronized void close(boolean writeIDX) { shrinkWithGapsAtEnd(); - if (file != null) { - file.close(); - } - file = null; + super.close(writeIDX); if (writeIDX && index != null && free != null && (index.size() > 3 || free.size() > 3)) { // now we can create a dump of the index and the gap information @@ -134,9 +131,9 @@ public class BLOBHeapModifier extends HeapReader implements BLOB { } } else { // this is small.. just free resources, do not write index - free.clear(); + if (free != null) free.clear(); free = null; - index.close(); + if (index != null) index.close(); index = null; } } diff --git a/source/de/anomic/kelondro/blob/HeapReader.java b/source/de/anomic/kelondro/blob/HeapReader.java index 0b7613261..86a9bb4c1 100644 --- a/source/de/anomic/kelondro/blob/HeapReader.java +++ b/source/de/anomic/kelondro/blob/HeapReader.java @@ -290,7 +290,7 @@ public class HeapReader { /** * close the BLOB table */ - public synchronized void close() { + public synchronized void close(boolean writeIDX) { if (file != null) file.close(); file = null; heapFile = null; diff --git a/source/de/anomic/kelondro/table/Stack.java b/source/de/anomic/kelondro/table/Stack.java index b2e0f9524..02542f7d9 100644 --- a/source/de/anomic/kelondro/table/Stack.java +++ b/source/de/anomic/kelondro/table/Stack.java @@ -68,6 +68,8 @@ public final class Stack extends FullRecords { try { return new Stack(file, rowdef); } catch (final IOException e) { + Log.logSevere("Stack", "Stack file open failed, deleting stack file " + file.toString()); + e.printStackTrace(); FileUtils.deletedelete(file); try { return new Stack(file, rowdef); @@ -205,7 +207,7 @@ public final class Stack extends FullRecords { return row().newEntry(n.getValueRow()); } - void unlinkNode(final Node n) throws IOException { + private void unlinkNode(final Node n) throws IOException { // join chaines over node final RecordHandle l = n.getOHHandle(left); final RecordHandle r = n.getOHHandle(right); @@ -291,12 +293,6 @@ public final class Stack extends FullRecords { } } - public String hp(final RecordHandle h) { - if (h == null) - return "NULL"; - return h.toString(); - } - public void print() throws IOException { super.print(); final Iterator it = stackIterator(true); diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.java index 201dd66a1..e8cd367a2 100644 --- a/source/de/anomic/plasma/plasmaSwitchboard.java +++ b/source/de/anomic/plasma/plasmaSwitchboard.java @@ -1233,6 +1233,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch