Apache Nutch is an extensible and scalable web crawler
NUTCH-1101 Option to purge db_gone records from CrawlDB
Markus Jelsmac0e6212d7fd2
diff --git a/CHANGES.txt b/CHANGES.txtindex f736e47df..8abf3cf6a 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -2,6 +2,8 @@ Nutch Change LogRelease 1.4 - Current development+* NUTCH-1101 Option to purge db_gone records with updatedb (markus)+* NUTCH-1096 Empty (not null) ContentLength results in failure of fetch (Ferdy Galema via jnioche)* NUTCH-1073 Rename parameters 'fetcher.threads.per.host.by.ip' and 'fetcher.threads.per.host' (jnioche)diff --git a/conf/nutch-default.xml b/conf/nutch-default.xmlindex 3837382ca..17f54e348 100644--- a/conf/nutch-default.xml+++ b/conf/nutch-default.xml@@ -403,6 +403,14 @@</description></property>+<property>+ <name>db.update.purge.404</name>+ <value>false</value>+ <description>If true, updatedb will add purge records with status DB_GONE+ from the CrawlDB.+ </description>+</property>+<property><name>db.update.max.inlinks</name><value>10000</value>diff --git a/src/java/org/apache/nutch/crawl/CrawlDb.java b/src/java/org/apache/nutch/crawl/CrawlDb.javaindex 4d144545b..e9c611eba 100644--- a/src/java/org/apache/nutch/crawl/CrawlDb.java+++ b/src/java/org/apache/nutch/crawl/CrawlDb.java@@ -46,6 +46,8 @@ public class CrawlDb extends Configured implements Tool {public static final String CRAWLDB_ADDITIONS_ALLOWED = "db.update.additions.allowed";+ public static final String CRAWLDB_PURGE_404 = "db.update.purge.404";+public static final String CURRENT_NAME = "current";public static final String LOCK_NAME = ".locked";@@ -57,7 +59,7 @@ public class CrawlDb extends Configured implements Tool {}public void update(Path crawlDb, Path[] segments, boolean normalize, boolean filter) throws IOException {- boolean additionsAllowed = getConf().getBoolean(CRAWLDB_ADDITIONS_ALLOWED, true);+ boolean additionsAllowed = getConf().getBoolean(CRAWLDB_ADDITIONS_ALLOWED, true);update(crawlDb, segments, normalize, filter, additionsAllowed, false);}@@ -67,6 +69,14 @@ public class CrawlDb extends Configured implements Tool {LockUtil.createLockFile(fs, lock, force);SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");long start = System.currentTimeMillis();++ JobConf job = CrawlDb.createJob(getConf(), crawlDb);+ job.setBoolean(CRAWLDB_ADDITIONS_ALLOWED, additionsAllowed);+ job.setBoolean(CrawlDbFilter.URL_FILTERING, filter);+ job.setBoolean(CrawlDbFilter.URL_NORMALIZING, normalize);++ boolean url404Purging = job.getBoolean(CRAWLDB_PURGE_404, false);+if (LOG.isInfoEnabled()) {LOG.info("CrawlDb update: starting at " + sdf.format(start));LOG.info("CrawlDb update: db: " + crawlDb);@@ -74,12 +84,9 @@ public class CrawlDb extends Configured implements Tool {LOG.info("CrawlDb update: additions allowed: " + additionsAllowed);LOG.info("CrawlDb update: URL normalizing: " + normalize);LOG.info("CrawlDb update: URL filtering: " + filter);+ LOG.info("CrawlDb update: 404 purging: " + url404Purging);}- JobConf job = CrawlDb.createJob(getConf(), crawlDb);- job.setBoolean(CRAWLDB_ADDITIONS_ALLOWED, additionsAllowed);- job.setBoolean(CrawlDbFilter.URL_FILTERING, filter);- job.setBoolean(CrawlDbFilter.URL_NORMALIZING, normalize);for (int i = 0; i < segments.length; i++) {Path fetch = new Path(segments[i], CrawlDatum.FETCH_DIR_NAME);Path parse = new Path(segments[i], CrawlDatum.PARSE_DIR_NAME);@@ -166,11 +173,13 @@ public class CrawlDb extends Configured implements Tool {System.err.println("\t-normalize\tuse URLNormalizer on urls in CrawlDb and segment (usually not needed)");System.err.println("\t-filter\tuse URLFilters on urls in CrawlDb and segment");System.err.println("\t-noAdditions\tonly update already existing URLs, don't add any newly discovered URLs");+return -1;}boolean normalize = false;boolean filter = false;boolean force = false;+ boolean url404Purging = false;final FileSystem fs = FileSystem.get(getConf());boolean additionsAllowed = getConf().getBoolean(CRAWLDB_ADDITIONS_ALLOWED, true);HashSet<Path> dirs = new HashSet<Path>();diff --git a/src/java/org/apache/nutch/crawl/CrawlDbFilter.java b/src/java/org/apache/nutch/crawl/CrawlDbFilter.javaindex a1db9e8f5..938dd6895 100644--- a/src/java/org/apache/nutch/crawl/CrawlDbFilter.java+++ b/src/java/org/apache/nutch/crawl/CrawlDbFilter.java@@ -46,6 +46,8 @@ public class CrawlDbFilter implements Mapper<Text, CrawlDatum, Text, CrawlDatum>private boolean urlNormalizers;+ private boolean url404Purging;+private URLFilters filters;private URLNormalizers normalizers;@@ -57,6 +59,8 @@ public class CrawlDbFilter implements Mapper<Text, CrawlDatum, Text, CrawlDatum>public void configure(JobConf job) {urlFiltering = job.getBoolean(URL_FILTERING, false);urlNormalizers = job.getBoolean(URL_NORMALIZING, false);+ url404Purging = job.getBoolean(CrawlDb.CRAWLDB_PURGE_404, false);+if (urlFiltering) {filters = new URLFilters(job);}@@ -75,6 +79,11 @@ public class CrawlDbFilter implements Mapper<Text, CrawlDatum, Text, CrawlDatum>Reporter reporter) throws IOException {String url = key.toString();++ // https://issues.apache.org/jira/browse/NUTCH-1101 check status first, cheaper than normalizing or filtering+ if (url404Purging && CrawlDatum.STATUS_DB_GONE == value.getStatus()) {+ url = null;+ }if (urlNormalizers) {try {url = normalizers.normalize(url, scope); // normalize the url