From 47843e69e272466b2d3e5c3a91fd14092b37c047 Mon Sep 17 00:00:00 2001 From: orbiter Date: Mon, 23 Jan 2006 12:41:08 +0000 Subject: [PATCH] auto-reset for switchboard queue stack bugfix for http://www.yacy-forum.de/viewtopic.php?p=15684#15684 git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1414 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- .../de/anomic/kelondro/kelondroRecords.java | 7 ++-- .../anomic/plasma/plasmaSwitchboardQueue.java | 32 +++++++++++++++---- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/source/de/anomic/kelondro/kelondroRecords.java b/source/de/anomic/kelondro/kelondroRecords.java index 0a91be231..1e0fb6e58 100644 --- a/source/de/anomic/kelondro/kelondroRecords.java +++ b/source/de/anomic/kelondro/kelondroRecords.java @@ -543,10 +543,8 @@ public class kelondroRecords { // values can be written using the setValues() method // but we expect that values are already there in the file ready to // be read which we do not here - if (handle == null) - throw new IllegalArgumentException("INTERNAL ERROR: node handle is null."); - if (handle.index >= USAGE.allCount()) - throw new kelondroException(filename, "INTERNAL ERROR: node handle index exceeds size."); + if (handle == null) throw new kelondroException(filename, "INTERNAL ERROR: node handle is null."); + if (handle.index >= USAGE.allCount()) throw new kelondroException(filename, "INTERNAL ERROR: node handle index exceeds size."); // use given handle this.handle = new Handle(handle.index); @@ -564,6 +562,7 @@ public class kelondroRecords { //assert (handle.index < USAGE.allCount()) : "node handle too high: " + handle.index + ", USEDC=" + USAGE.USEDC + ", FREEC=" + USAGE.FREEC; // the parentNode can be given if an auto-fix in the following case is wanted + if (handle == null) throw new kelondroException(filename, "INTERNAL ERROR: node handle is null."); if (handle.index >= USAGE.allCount()) { if (parentNode == null) { throw new kelondroException(filename, "INTERNAL ERROR, Node/init: node handle index exceeds size. No auto-fix node was submitted. This is a serious failure."); diff --git a/source/de/anomic/plasma/plasmaSwitchboardQueue.java b/source/de/anomic/plasma/plasmaSwitchboardQueue.java index 0af5869aa..958b649f2 100644 --- a/source/de/anomic/plasma/plasmaSwitchboardQueue.java +++ b/source/de/anomic/plasma/plasmaSwitchboardQueue.java @@ -53,6 +53,7 @@ import java.util.Date; import de.anomic.htmlFilter.htmlFilterContentScraper; import de.anomic.http.httpHeader; import de.anomic.kelondro.kelondroBase64Order; +import de.anomic.kelondro.kelondroException; import de.anomic.kelondro.kelondroStack; import de.anomic.server.serverDate; import de.anomic.server.logging.serverLog; @@ -64,12 +65,18 @@ public class plasmaSwitchboardQueue { private plasmaCrawlProfile profiles; private plasmaHTCache htCache; private plasmaCrawlLURL lurls; - + private File sbQueueStackPath; + public plasmaSwitchboardQueue(plasmaHTCache htCache, plasmaCrawlLURL lurls, File sbQueueStackPath, plasmaCrawlProfile profiles) { + this.sbQueueStackPath = sbQueueStackPath; this.profiles = profiles; this.htCache = htCache; this.lurls = lurls; + initQueueStack(); + } + + private void initQueueStack() { if (sbQueueStackPath.exists()) try { sbQueueStack = new kelondroStack(sbQueueStackPath, 0); } catch (IOException e) { @@ -97,7 +104,13 @@ public class plasmaSwitchboardQueue { }, true); } } - + + private void resetQueueStack() { + try {sbQueueStack.close();} catch (Exception e) {} + if (sbQueueStackPath.exists()) sbQueueStackPath.delete(); + initQueueStack(); + } + public int size() { return sbQueueStack.size(); } @@ -135,13 +148,18 @@ public class plasmaSwitchboardQueue { } public ArrayList list(int index) throws IOException { - if ((index==0) && (sbQueueStack.size()==0)) return new ArrayList(0); + if ((index == 0) && (sbQueueStack.size() == 0)) return new ArrayList(0); if ((index < 0) || (index >= sbQueueStack.size())) throw new ArrayIndexOutOfBoundsException(); - ArrayList list = sbQueueStack.botList(index); - for (int i=0; i < list.size(); i++) { - list.set(i,new Entry((byte[][])list.get(i))); + try { + ArrayList list = sbQueueStack.botList(index); + for (int i = 0; i < list.size(); i++) { + list.set(i, new Entry((byte[][]) list.get(i))); + } + return list; + } catch (kelondroException e) { + resetQueueStack(); + return new ArrayList(); } - return list; } public void clear() throws IOException {