From d42531e1b208b056ba82dc25041fcfaf3c5de91e Mon Sep 17 00:00:00 2001 From: orbiter Date: Sat, 29 Oct 2005 13:53:32 +0000 Subject: [PATCH] added auto-reset for NURL-DBs git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1004 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/plasma/plasmaCrawlNURL.java | 57 +++++++++++++++----- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/source/de/anomic/plasma/plasmaCrawlNURL.java b/source/de/anomic/plasma/plasmaCrawlNURL.java index 12461e415..bdd354858 100644 --- a/source/de/anomic/plasma/plasmaCrawlNURL.java +++ b/source/de/anomic/plasma/plasmaCrawlNURL.java @@ -96,23 +96,18 @@ public class plasmaCrawlNURL extends plasmaURL { private kelondroStack musicStack; // links pointing to music resources private final HashSet stackIndex; // to find out if a specific link is already on any stack - + private File cacheStacksPath; + private int bufferkb; + public plasmaCrawlNURL(File cacheStacksPath, int bufferkb) throws IOException { super(); - - + this.cacheStacksPath = cacheStacksPath; + this.bufferkb = bufferkb; + // create a stack for newly entered entries if (!(cacheStacksPath.exists())) cacheStacksPath.mkdir(); // make the path - File cacheFile = new File(cacheStacksPath, "urlNotice1.db"); - if (cacheFile.exists()) { - // open existing cache - urlHashCache = new kelondroTree(cacheFile, bufferkb * 0x400); - } else { - // create new cache - cacheFile.getParentFile().mkdirs(); - urlHashCache = new kelondroTree(cacheFile, bufferkb * 0x400, ce); - } + openHashCache(); File coreStackFile = new File(cacheStacksPath, "urlNoticeLocal0.stack"); File limitStackFile = new File(cacheStacksPath, "urlNoticeLimit0.stack"); @@ -134,6 +129,28 @@ public class plasmaCrawlNURL extends plasmaURL { new initStackIndex().start(); } + private void openHashCache() throws IOException { + File cacheFile = new File(cacheStacksPath, "urlNotice1.db"); + if (cacheFile.exists()) { + // open existing cache + urlHashCache = new kelondroTree(cacheFile, bufferkb * 0x400); + } else { + // create new cache + cacheFile.getParentFile().mkdirs(); + urlHashCache = new kelondroTree(cacheFile, bufferkb * 0x400, ce); + } + } + + private void resetHashCache() throws IOException { + if (urlHashCache != null) { + try {urlHashCache.close();} catch (IOException e) {} + urlHashCache = null; + File cacheFile = new File(cacheStacksPath, "urlNotice1.db"); + cacheFile.delete(); + } + openHashCache(); + } + public void close() { coreStack.close(); try { @@ -451,9 +468,21 @@ public class plasmaCrawlNURL extends plasmaURL { }; urlHashCache.put(entry); } catch (IOException e) { - serverLog.logSevere("PLASMA", "INTERNAL ERROR AT plasmaNURL:store:" + e.toString()); + serverLog.logSevere("PLASMA", "INTERNAL ERROR AT plasmaNURL:store:" + e.toString() + ", resetting NURL-DB"); + try { + resetHashCache(); + } catch (IOException ee) { + serverLog.logSevere("PLASMA", "INTERNAL ERROR AT plasmaNURL:store:" + e.toString() + ", reset of NURL-DB failed"); + System.exit(0); // this is REALLY severe + } } catch (kelondroException e) { - serverLog.logSevere("PLASMA", "plasmaCrawlNURL.store failed: " + e.getMessage()); + serverLog.logSevere("PLASMA", "plasmaCrawlNURL.store failed: " + e.toString() + ", resetting NURL-DB"); + try { + resetHashCache(); + } catch (IOException ee) { + serverLog.logSevere("PLASMA", "INTERNAL ERROR AT plasmaNURL:store:" + e.toString() + ", reset of NURL-DB failed"); + System.exit(0); // this is REALLY severe + } } }