Apache Nutch is an extensible and scalable web crawler
NUTCH-1194 Generator: CrawlDB lock should be released earlier - release CrawlDb lock after select step, in case, generated items are not marked in CrawlDb (generate.update.crawldb is false)
Sebastian Nagel814f8b997ddb
diff --git a/src/java/org/apache/nutch/crawl/Generator.java b/src/java/org/apache/nutch/crawl/Generator.javaindex 5dcd2ea45..04c2ae8ca 100644--- a/src/java/org/apache/nutch/crawl/Generator.java+++ b/src/java/org/apache/nutch/crawl/Generator.java@@ -841,6 +841,14 @@ public class Generator extends NutchTool implements Tool {String.format(Locale.ROOT, "%6d", counter.getValue()),counter.getName());}+ if (!getConf().getBoolean(GENERATE_UPDATE_CRAWLDB, false)) {+ /*+ * generated items are not marked in CrawlDb, and CrawlDb will not+ * accessed anymore: we already can release the lock+ */+ LockUtil.removeLockFile(getConf(), lock);+ lock = null;+ }// read the subdirectories generated in the temp// output and turn them into segments@@ -858,15 +866,13 @@ public class Generator extends NutchTool implements Tool {}} catch (Exception e) {LOG.warn("Generator: exception while partitioning segments, exiting ...");- LockUtil.removeLockFile(getConf(), lock);- fs.delete(tempDir, true);+ NutchJob.cleanupAfterFailure(tempDir, lock, fs);return null;}if (generatedSegments.size() == 0) {LOG.warn("Generator: 0 records selected for fetching, exiting ...");- LockUtil.removeLockFile(getConf(), lock);- fs.delete(tempDir, true);+ NutchJob.cleanupAfterFailure(tempDir, lock, fs);return null;}@@ -913,7 +919,9 @@ public class Generator extends NutchTool implements Tool {fs.delete(tempDir2, true);}- LockUtil.removeLockFile(getConf(), lock);+ if (lock != null) {+ LockUtil.removeLockFile(getConf(), lock);+ }fs.delete(tempDir, true);long end = System.currentTimeMillis();diff --git a/src/java/org/apache/nutch/util/NutchJob.java b/src/java/org/apache/nutch/util/NutchJob.javaindex 991e50692..13257d2ba 100644--- a/src/java/org/apache/nutch/util/NutchJob.java+++ b/src/java/org/apache/nutch/util/NutchJob.java@@ -41,7 +41,15 @@ public class NutchJob extends Job {return Job.getInstance(conf);}- /*+ /**+ * Clean up the file system in case of a job failure.+ */+ public static void cleanupAfterFailure(Path tempDir, FileSystem fs)+ throws IOException {+ cleanupAfterFailure(tempDir, null, fs);+ }++ /*** Clean up the file system in case of a job failure.*/public static void cleanupAfterFailure(Path tempDir, Path lock, FileSystem fs)@@ -50,7 +58,9 @@ public class NutchJob extends Job {if (fs.exists(tempDir)) {fs.delete(tempDir, true);}- LockUtil.removeLockFile(fs, lock);+ if (lock != null) {+ LockUtil.removeLockFile(fs, lock);+ }} catch (IOException e) {LOG.error("NutchJob cleanup failed: {}", e.getMessage());throw e;