Apache Nutch is an extensible and scalable web crawler
NUTCH-584 - urls missing from fetchlists.
Andrzej Bialeckid074e30acca2
diff --git a/CHANGES.txt b/CHANGES.txtindex 796a112b2..0d24330b5 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -189,6 +189,8 @@ Unreleased changes (1.0-dev)65. NUTCH-597 - NPE in Fetcher2 (Remco Verhoef via ab)+66. NUTCH-584 - urls missing from fetchlist (Ruslan Ermilov, ab)+Release 0.9 - 2007-04-02diff --git a/src/java/org/apache/nutch/crawl/Generator.java b/src/java/org/apache/nutch/crawl/Generator.javaindex 1a100b3dd..9e5090064 100644--- a/src/java/org/apache/nutch/crawl/Generator.java+++ b/src/java/org/apache/nutch/crawl/Generator.java@@ -267,9 +267,23 @@ public class Generator extends ToolBase {public void map(WritableComparable key, Writable value, OutputCollector output, Reporter reporter) throws IOException {SelectorEntry entry = (SelectorEntry)value;- output.collect(entry.url, entry.datum);+ output.collect(entry.url, entry);}}++ public static class PartitionReducer extends MapReduceBase implements Reducer {++ public void reduce(WritableComparable key, Iterator values,+ OutputCollector output, Reporter reporter) throws IOException {+ // if using HashComparator, we get only one input key in case of hash collision+ // so use only URLs from values+ while (values.hasNext()) {+ SelectorEntry entry = (SelectorEntry)values.next();+ output.collect(entry.url, entry.datum);+ }+ }++ }/** Sort fetch lists by hash of URL. */public static class HashComparator extends WritableComparator {@@ -457,7 +471,10 @@ public class Generator extends ToolBase {job.setInputFormat(SequenceFileInputFormat.class);job.setMapperClass(SelectorInverseMapper.class);+ job.setMapOutputKeyClass(Text.class);+ job.setMapOutputValueClass(SelectorEntry.class);job.setPartitionerClass(PartitionUrlByHost.class);+ job.setReducerClass(PartitionReducer.class);job.setNumReduceTasks(numLists);job.setOutputPath(output);diff --git a/src/java/org/apache/nutch/tools/FreeGenerator.java b/src/java/org/apache/nutch/tools/FreeGenerator.javaindex ed8bafb58..3414c2821 100644--- a/src/java/org/apache/nutch/tools/FreeGenerator.java+++ b/src/java/org/apache/nutch/tools/FreeGenerator.java@@ -18,7 +18,9 @@package org.apache.nutch.tools;import java.io.IOException;+import java.util.HashMap;import java.util.Iterator;+import java.util.Map.Entry;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;@@ -77,6 +79,8 @@ public class FreeGenerator extends ToolBase {normalizers = new URLNormalizers(job, URLNormalizers.SCOPE_INJECT);}}++ Generator.SelectorEntry entry = new Generator.SelectorEntry();public void map(WritableComparable key, Writable value, OutputCollector output, Reporter reporter) throws IOException {// value is a line of text@@ -102,12 +106,22 @@ public class FreeGenerator extends ToolBase {}return;}- output.collect(url, datum);+ entry.datum = datum;+ entry.url = url;+ output.collect(url, entry);}public void reduce(WritableComparable key, Iterator values, OutputCollector output, Reporter reporter) throws IOException {- // pick just one (discard duplicates)- output.collect(key, (Writable)values.next());+ // pick unique urls from values - discard the reduce key due to hash collisions+ HashMap<Text, CrawlDatum> unique = new HashMap<Text, CrawlDatum>();+ while (values.hasNext()) {+ Generator.SelectorEntry entry = (Generator.SelectorEntry)values.next();+ unique.put(entry.url, entry.datum);+ }+ // output unique urls+ for (Entry<Text, CrawlDatum> e : unique.entrySet()) {+ output.collect(e.getKey(), e.getValue());+ }}}@@ -142,6 +156,8 @@ public class FreeGenerator extends ToolBase {job.addInputPath(new Path(args[0]));job.setInputFormat(TextInputFormat.class);job.setMapperClass(FG.class);+ job.setMapOutputKeyClass(Text.class);+ job.setMapOutputValueClass(Generator.SelectorEntry.class);job.setPartitionerClass(PartitionUrlByHost.class);job.setReducerClass(FG.class);String segName = Generator.generateSegmentName();