Apache Nutch is an extensible and scalable web crawler
NUTCH-761 Avoid cloning CrawlDatum in CrawlDbReducer.
Andrzej Bialeckic94ae776d8e0
diff --git a/CHANGES.txt b/CHANGES.txtindex 40889cdf6..41661e3e3 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -2,6 +2,8 @@ Nutch Change LogUnreleased Changes+* NUTCH-761 Avoid cloning CrawlDatum in CrawlDbReducer (Julien Nioche, ab)+* NUTCH-753 Prevent new Fetcher from retrieving the robots twice (Julien Nioche via ab)* NUTCH-773 - Some minor bugs in AbstractFetchSchedule (Reinhard Schwab via ab)diff --git a/src/java/org/apache/nutch/crawl/CrawlDbReducer.java b/src/java/org/apache/nutch/crawl/CrawlDbReducer.javaindex dc2c0a692..7e64fa576 100644--- a/src/java/org/apache/nutch/crawl/CrawlDbReducer.java+++ b/src/java/org/apache/nutch/crawl/CrawlDbReducer.java@@ -64,13 +64,20 @@ public class CrawlDbReducer implements Reducer<Text, CrawlDatum, Text, CrawlDatuboolean fetchSet = false;boolean oldSet = false;byte[] signature = null;+ boolean multiple = false; // avoid deep copy when only single value existslinked.clear();while (values.hasNext()) {CrawlDatum datum = (CrawlDatum)values.next();+ if (!multiple && values.hasNext()) multiple = true;if (CrawlDatum.hasDbStatus(datum)) {if (!oldSet) {- old.set(datum);+ if (multiple) {+ old.set(datum);+ } else {+ // no need for a deep copy - this is the only value+ old = datum;+ }oldSet = true;} else {// always take the latest version@@ -81,7 +88,11 @@ public class CrawlDbReducer implements Reducer<Text, CrawlDatum, Text, CrawlDatuif (CrawlDatum.hasFetchStatus(datum)) {if (!fetchSet) {- fetch.set(datum);+ if (multiple) {+ fetch.set(datum);+ } else {+ fetch = datum;+ }fetchSet = true;} else {// always take the latest version@@ -92,8 +103,13 @@ public class CrawlDbReducer implements Reducer<Text, CrawlDatum, Text, CrawlDatuswitch (datum.getStatus()) { // collect other infocase CrawlDatum.STATUS_LINKED:- CrawlDatum link = new CrawlDatum();- link.set(datum);+ CrawlDatum link;+ if (multiple) {+ link = new CrawlDatum();+ link.set(datum);+ } else {+ link = datum;+ }linked.add(link);break;case CrawlDatum.STATUS_SIGNATURE:@@ -115,10 +131,11 @@ public class CrawlDbReducer implements Reducer<Text, CrawlDatum, Text, CrawlDatu// still no new data - record only unchanged old data, if exists, and returnif (!fetchSet) {- if (oldSet) // at this point at least "old" should be present+ if (oldSet) {// at this point at least "old" should be presentoutput.collect(key, old);- else+ } else {LOG.warn("Missing fetch and old value, signature=" + signature);+ }return;}