some bugfixes to database close() methods

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6023 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 16 years ago
parent a0c53abbe1
commit 42ae40b9f6

@ -78,7 +78,7 @@ public class IndexingStack {
NaturalOrder.naturalOrder NaturalOrder.naturalOrder
); );
public int size() { public synchronized int size() {
return (sbQueueStack == null) ? 0 : sbQueueStack.size(); return (sbQueueStack == null) ? 0 : sbQueueStack.size();
} }
@ -98,33 +98,33 @@ public class IndexingStack {
} }
public synchronized QueueEntry pop() throws IOException { public synchronized QueueEntry pop() throws IOException {
synchronized (sbQueueStack) { if (sbQueueStack == null) return null;
int sizeBefore; // this shall not return null because it may cause a emergency reset!
while ((sizeBefore = sbQueueStack.size()) > 0) { int sizeBefore;
Row.Entry b = sbQueueStack.pot(); while ((sizeBefore = sbQueueStack.size()) > 0) {
if (b == null) { Row.Entry b = sbQueueStack.pot();
Log.logInfo("IndexingStack", "sbQueueStack.pot() == null"); if (b == null) {
if (sbQueueStack.size() < sizeBefore) continue; Log.logInfo("IndexingStack", "sbQueueStack.pot() == null");
Log.logSevere("IndexingStack", "sbQueueStack does not shrink after pot() == null; trying pop()"); 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); if (sbQueueStack.size() < sizeBefore) {
} else { return new QueueEntry(b);
Log.logSevere("IndexingStack", "sbQueueStack does not shrink after pot() != null; trying pop()"); } else {
} Log.logSevere("IndexingStack", "sbQueueStack does not shrink after pot() != null; trying pop()");
sizeBefore = sbQueueStack.size(); }
b = sbQueueStack.pop(); sizeBefore = sbQueueStack.size();
if (b == null) { b = sbQueueStack.pop();
Log.logInfo("IndexingStack", "sbQueueStack.pop() == null"); if (b == null) {
if (sbQueueStack.size() < sizeBefore) continue; Log.logInfo("IndexingStack", "sbQueueStack.pop() == null");
Log.logSevere("IndexingStack", "sbQueueStack does not shrink after pop() == null; failed"); if (sbQueueStack.size() < sizeBefore) continue;
return null; Log.logSevere("IndexingStack", "sbQueueStack does not shrink after pop() == null; failed");
} return null;
return new QueueEntry(b); }
} return new QueueEntry(b);
Log.logInfo("IndexingStack", "sbQueueStack.size() == 0");
return null;
} }
Log.logInfo("IndexingStack", "sbQueueStack.size() == 0");
return null;
} }
public synchronized QueueEntry remove(final String urlHash) { public synchronized QueueEntry remove(final String urlHash) {

@ -246,7 +246,7 @@ public final class BLOBHeap extends BLOBHeapModifier implements BLOB {
/** /**
* close the BLOB table * close the BLOB table
*/ */
public synchronized void close() { public synchronized void close(boolean writeIDX) {
if (file != null) { if (file != null) {
try { try {
flushBuffer(); flushBuffer();
@ -255,7 +255,7 @@ public final class BLOBHeap extends BLOBHeapModifier implements BLOB {
} }
} }
this.buffer = null; this.buffer = null;
super.close(); super.close(writeIDX);
assert file == null; assert file == null;
} }
@ -443,7 +443,7 @@ public final class BLOBHeap extends BLOBHeapModifier implements BLOB {
heap.remove("aaaaaaaaaaab".getBytes()); heap.remove("aaaaaaaaaaab".getBytes());
heap.remove("aaaaaaaaaaac".getBytes()); heap.remove("aaaaaaaaaaac".getBytes());
heap.put("aaaaaaaaaaaX".getBytes(), "WXYZ".getBytes()); heap.put("aaaaaaaaaaaX".getBytes(), "WXYZ".getBytes());
heap.close(); heap.close(true);
} catch (final IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

@ -105,10 +105,7 @@ public class BLOBHeapModifier extends HeapReader implements BLOB {
*/ */
public synchronized void close(boolean writeIDX) { public synchronized void close(boolean writeIDX) {
shrinkWithGapsAtEnd(); shrinkWithGapsAtEnd();
if (file != null) { super.close(writeIDX);
file.close();
}
file = null;
if (writeIDX && index != null && free != null && (index.size() > 3 || free.size() > 3)) { 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 // 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 { } else {
// this is small.. just free resources, do not write index // this is small.. just free resources, do not write index
free.clear(); if (free != null) free.clear();
free = null; free = null;
index.close(); if (index != null) index.close();
index = null; index = null;
} }
} }

@ -290,7 +290,7 @@ public class HeapReader {
/** /**
* close the BLOB table * close the BLOB table
*/ */
public synchronized void close() { public synchronized void close(boolean writeIDX) {
if (file != null) file.close(); if (file != null) file.close();
file = null; file = null;
heapFile = null; heapFile = null;

@ -68,6 +68,8 @@ public final class Stack extends FullRecords {
try { try {
return new Stack(file, rowdef); return new Stack(file, rowdef);
} catch (final IOException e) { } catch (final IOException e) {
Log.logSevere("Stack", "Stack file open failed, deleting stack file " + file.toString());
e.printStackTrace();
FileUtils.deletedelete(file); FileUtils.deletedelete(file);
try { try {
return new Stack(file, rowdef); return new Stack(file, rowdef);
@ -205,7 +207,7 @@ public final class Stack extends FullRecords {
return row().newEntry(n.getValueRow()); return row().newEntry(n.getValueRow());
} }
void unlinkNode(final Node n) throws IOException { private void unlinkNode(final Node n) throws IOException {
// join chaines over node // join chaines over node
final RecordHandle l = n.getOHHandle(left); final RecordHandle l = n.getOHHandle(left);
final RecordHandle r = n.getOHHandle(right); 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 { public void print() throws IOException {
super.print(); super.print();
final Iterator<Row.Entry> it = stackIterator(true); final Iterator<Row.Entry> it = stackIterator(true);

@ -1233,6 +1233,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.
", remoteStackSize=" + crawlQueues.noticeURL.stackSize(NoticedURL.STACK_TYPE_REMOTE)); ", remoteStackSize=" + crawlQueues.noticeURL.stackSize(NoticedURL.STACK_TYPE_REMOTE));
try { try {
final int sizeBefore = crawler.queuePreStack.size(); final int sizeBefore = crawler.queuePreStack.size();
if (sizeBefore == 0) return null;
nextentry = crawler.queuePreStack.pop(); nextentry = crawler.queuePreStack.pop();
if (nextentry == null) { if (nextentry == null) {
log.logWarning("deQueue: null entry on queue stack."); log.logWarning("deQueue: null entry on queue stack.");

Loading…
Cancel
Save