Apache Nutch is an extensible and scalable web crawler
NUTCH-634 Upgrade Nutch to Hadoop 0.17.1 .
Andrzej Bialeckiff5c58276b5d
diff --git a/CHANGES.txt b/CHANGES.txtindex 524c1a1a0..a7a2b7f99 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -253,6 +253,9 @@ Unreleased changes (1.0-dev)92. NUTCH-618 - Tika error "Media type alias already exists" (mattmann,kubes)+93. NUTCH-634 - Upgrade Nutch to Hadoop 0.17.1 (Michael Gottesman, Lincoln+ Ritter, ab)+Release 0.9 - 2007-04-021. Changed log4j confiquration to log to stdout on commandlinediff --git a/conf/nutch-default.xml b/conf/nutch-default.xmlindex ecc10a41e..f4b0a7ca7 100644--- a/conf/nutch-default.xml+++ b/conf/nutch-default.xml@@ -1189,4 +1189,17 @@</description></property>+<!-- Temporary Hadoop 0.17.x workaround. -->++<property>+ <name>hadoop.job.history.user.location</name>+ <value>${hadoop.log.dir}/history/user</value>+ <description>Hadoop 0.17.x comes with a default setting to create+ user logs inside the output path of the job. This breaks some+ Hadoop classes, which expect the output to contain only+ part-XXXXX files. This setting changes the output to a+ subdirectory of the regular log directory.+ </description>+</property>+</configuration>diff --git a/lib/hadoop-0.16.0-core.jar b/lib/hadoop-0.16.0-core.jardeleted file mode 100644index 1ead30494..000000000Binary files a/lib/hadoop-0.16.0-core.jar and /dev/null differdiff --git a/lib/hadoop-0.17.1-core.jar b/lib/hadoop-0.17.1-core.jarnew file mode 100644index 000000000..ad7842352Binary files /dev/null and b/lib/hadoop-0.17.1-core.jar differdiff --git a/lib/native/Linux-amd64-64/libhadoop.a b/lib/native/Linux-amd64-64/libhadoop.aindex acaf946fc..45174ecf0 100644Binary files a/lib/native/Linux-amd64-64/libhadoop.a and b/lib/native/Linux-amd64-64/libhadoop.a differdiff --git a/lib/native/Linux-amd64-64/libhadoop.so b/lib/native/Linux-amd64-64/libhadoop.soindex ef73cab9c..5a3e95bc4 100644Binary files a/lib/native/Linux-amd64-64/libhadoop.so and b/lib/native/Linux-amd64-64/libhadoop.so differdiff --git a/lib/native/Linux-amd64-64/libhadoop.so.1 b/lib/native/Linux-amd64-64/libhadoop.so.1index ef73cab9c..5a3e95bc4 100644Binary files a/lib/native/Linux-amd64-64/libhadoop.so.1 and b/lib/native/Linux-amd64-64/libhadoop.so.1 differdiff --git a/lib/native/Linux-amd64-64/libhadoop.so.1.0.0 b/lib/native/Linux-amd64-64/libhadoop.so.1.0.0index ef73cab9c..5a3e95bc4 100644Binary files a/lib/native/Linux-amd64-64/libhadoop.so.1.0.0 and b/lib/native/Linux-amd64-64/libhadoop.so.1.0.0 differdiff --git a/lib/native/Linux-i386-32/libhadoop.a b/lib/native/Linux-i386-32/libhadoop.aindex b3ae2940a..430438951 100644Binary files a/lib/native/Linux-i386-32/libhadoop.a and b/lib/native/Linux-i386-32/libhadoop.a differdiff --git a/lib/native/Linux-i386-32/libhadoop.so b/lib/native/Linux-i386-32/libhadoop.soindex bf854a59e..5fbc3fe3d 100644Binary files a/lib/native/Linux-i386-32/libhadoop.so and b/lib/native/Linux-i386-32/libhadoop.so differdiff --git a/lib/native/Linux-i386-32/libhadoop.so.1 b/lib/native/Linux-i386-32/libhadoop.so.1index bf854a59e..5fbc3fe3d 100644Binary files a/lib/native/Linux-i386-32/libhadoop.so.1 and b/lib/native/Linux-i386-32/libhadoop.so.1 differdiff --git a/lib/native/Linux-i386-32/libhadoop.so.1.0.0 b/lib/native/Linux-i386-32/libhadoop.so.1.0.0index bf854a59e..5fbc3fe3d 100644Binary files a/lib/native/Linux-i386-32/libhadoop.so.1.0.0 and b/lib/native/Linux-i386-32/libhadoop.so.1.0.0 differdiff --git a/src/java/org/apache/nutch/crawl/Crawl.java b/src/java/org/apache/nutch/crawl/Crawl.javaindex 2958c90d9..782b7624e 100644--- a/src/java/org/apache/nutch/crawl/Crawl.java+++ b/src/java/org/apache/nutch/crawl/Crawl.java@@ -131,19 +131,21 @@ public class Crawl {// Delete old indexesif (fs.exists(indexes)) {LOG.info("Deleting old indexes: " + indexes);- fs.delete(indexes);+ fs.delete(indexes, true);}// Delete old indexif (fs.exists(index)) {LOG.info("Deleting old merged index: " + index);- fs.delete(index);+ fs.delete(index, true);}// index, dedup & merge- indexer.index(indexes, crawlDb, linkDb, fs.listPaths(segments, HadoopFSUtil.getPassAllFilter()));+ FileStatus[] fstats = fs.listStatus(segments, HadoopFSUtil.getPassDirectoriesFilter(fs));+ indexer.index(indexes, crawlDb, linkDb, HadoopFSUtil.getPaths(fstats));dedup.dedup(new Path[] { indexes });- merger.merge(fs.listPaths(indexes, HadoopFSUtil.getPassAllFilter()), index, tmpDir);+ fstats = fs.listStatus(indexes, HadoopFSUtil.getPassDirectoriesFilter(fs));+ merger.merge(HadoopFSUtil.getPaths(fstats), index, tmpDir);} else {LOG.warn("No URLs to fetch - check your seed list and URL filters.");}diff --git a/src/java/org/apache/nutch/crawl/CrawlDb.java b/src/java/org/apache/nutch/crawl/CrawlDb.javaindex 55bfa9aae..07cac53d2 100644--- a/src/java/org/apache/nutch/crawl/CrawlDb.java+++ b/src/java/org/apache/nutch/crawl/CrawlDb.java@@ -80,8 +80,8 @@ public class CrawlDb extends Configured implements Tool {Path fetch = new Path(segments[i], CrawlDatum.FETCH_DIR_NAME);Path parse = new Path(segments[i], CrawlDatum.PARSE_DIR_NAME);if (fs.exists(fetch) && fs.exists(parse)) {- job.addInputPath(fetch);- job.addInputPath(parse);+ FileInputFormat.addInputPath(job, fetch);+ FileInputFormat.addInputPath(job, parse);} else {LOG.info(" - skipping invalid segment " + segments[i]);}@@ -94,7 +94,8 @@ public class CrawlDb extends Configured implements Tool {JobClient.runJob(job);} catch (IOException e) {LockUtil.removeLockFile(fs, lock);- if (fs.exists(job.getOutputPath())) fs.delete(job.getOutputPath());+ Path outPath = FileOutputFormat.getOutputPath(job);+ if (fs.exists(outPath) ) fs.delete(outPath, true);throw e;}@@ -114,14 +115,14 @@ public class CrawlDb extends Configured implements Tool {Path current = new Path(crawlDb, CURRENT_NAME);if (FileSystem.get(job).exists(current)) {- job.addInputPath(current);+ FileInputFormat.addInputPath(job, current);}job.setInputFormat(SequenceFileInputFormat.class);job.setMapperClass(CrawlDbFilter.class);job.setReducerClass(CrawlDbReducer.class);- job.setOutputPath(newCrawlDb);+ FileOutputFormat.setOutputPath(job, newCrawlDb);job.setOutputFormat(MapFileOutputFormat.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(CrawlDatum.class);@@ -130,17 +131,17 @@ public class CrawlDb extends Configured implements Tool {}public static void install(JobConf job, Path crawlDb) throws IOException {- Path newCrawlDb = job.getOutputPath();+ Path newCrawlDb = FileOutputFormat.getOutputPath(job);FileSystem fs = new JobClient(job).getFs();Path old = new Path(crawlDb, "old");Path current = new Path(crawlDb, CURRENT_NAME);if (fs.exists(current)) {- if (fs.exists(old)) fs.delete(old);+ if (fs.exists(old)) fs.delete(old, true);fs.rename(current, old);}fs.mkdirs(crawlDb);fs.rename(newCrawlDb, current);- if (fs.exists(old)) fs.delete(old);+ if (fs.exists(old)) fs.delete(old, true);Path lock = new Path(crawlDb, LOCK_NAME);LockUtil.removeLockFile(fs, lock);}diff --git a/src/java/org/apache/nutch/crawl/CrawlDbFilter.java b/src/java/org/apache/nutch/crawl/CrawlDbFilter.javaindex 15c4ddcde..a1db9e8f5 100644--- a/src/java/org/apache/nutch/crawl/CrawlDbFilter.java+++ b/src/java/org/apache/nutch/crawl/CrawlDbFilter.java@@ -22,8 +22,6 @@ import java.io.IOException;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.hadoop.io.Text;-import org.apache.hadoop.io.Writable;-import org.apache.hadoop.io.WritableComparable;import org.apache.hadoop.mapred.JobConf;import org.apache.hadoop.mapred.Mapper;import org.apache.hadoop.mapred.OutputCollector;@@ -37,7 +35,7 @@ import org.apache.nutch.net.URLNormalizers;** @author Andrzej Bialecki*/-public class CrawlDbFilter implements Mapper {+public class CrawlDbFilter implements Mapper<Text, CrawlDatum, Text, CrawlDatum> {public static final String URL_FILTERING = "crawldb.url.filters";public static final String URL_NORMALIZING = "crawldb.url.normalizers";@@ -72,7 +70,9 @@ public class CrawlDbFilter implements Mapper {private Text newKey = new Text();- public void map(WritableComparable key, Writable value, OutputCollector output, Reporter reporter) throws IOException {+ public void map(Text key, CrawlDatum value,+ OutputCollector<Text, CrawlDatum> output,+ Reporter reporter) throws IOException {String url = key.toString();if (urlNormalizers) {diff --git a/src/java/org/apache/nutch/crawl/CrawlDbMerger.java b/src/java/org/apache/nutch/crawl/CrawlDbMerger.javaindex 731656dc8..e33ad8e31 100644--- a/src/java/org/apache/nutch/crawl/CrawlDbMerger.java+++ b/src/java/org/apache/nutch/crawl/CrawlDbMerger.java@@ -53,7 +53,8 @@ public class CrawlDbMerger extends Configured implements Tool {private static final Log LOG = LogFactory.getLog(CrawlDbMerger.class);public static class Merger extends MapReduceBase implements Reducer<Text, CrawlDatum, Text, CrawlDatum> {- MapWritable meta = new MapWritable();+ private MapWritable meta = new MapWritable();+ private CrawlDatum res = new CrawlDatum();private FetchSchedule schedule;public void close() throws IOException {}@@ -64,13 +65,14 @@ public class CrawlDbMerger extends Configured implements Tool {public void reduce(Text key, Iterator<CrawlDatum> values, OutputCollector<Text, CrawlDatum> output, Reporter reporter)throws IOException {- CrawlDatum res = null;long resTime = 0L;+ boolean resSet = false;meta.clear();while (values.hasNext()) {CrawlDatum val = values.next();- if (res == null) {- res = val;+ if (!resSet) {+ res.set(val);+ resSet = true;resTime = schedule.calculateLastFetchTime(res);meta.putAll(res.getMetaData());continue;@@ -80,7 +82,7 @@ public class CrawlDbMerger extends Configured implements Tool {if (valTime > resTime) {// collect all metadata, newer values override older valuesmeta.putAll(val.getMetaData());- res = val;+ res.set(val);resTime = valTime ;} else {// insert older metadata before newer@@ -104,12 +106,12 @@ public class CrawlDbMerger extends Configured implements Tool {public void merge(Path output, Path[] dbs, boolean normalize, boolean filter) throws Exception {JobConf job = createMergeJob(getConf(), output, normalize, filter);for (int i = 0; i < dbs.length; i++) {- job.addInputPath(new Path(dbs[i], CrawlDb.CURRENT_NAME));+ FileInputFormat.addInputPath(job, new Path(dbs[i], CrawlDb.CURRENT_NAME));}JobClient.runJob(job);FileSystem fs = FileSystem.get(getConf());fs.mkdirs(output);- fs.rename(job.getOutputPath(), new Path(output, CrawlDb.CURRENT_NAME));+ fs.rename(FileOutputFormat.getOutputPath(job), new Path(output, CrawlDb.CURRENT_NAME));}public static JobConf createMergeJob(Configuration conf, Path output, boolean normalize, boolean filter) {@@ -125,7 +127,7 @@ public class CrawlDbMerger extends Configured implements Tool {job.setBoolean(CrawlDbFilter.URL_NORMALIZING, normalize);job.setReducerClass(Merger.class);- job.setOutputPath(newCrawlDb);+ FileOutputFormat.setOutputPath(job, newCrawlDb);job.setOutputFormat(MapFileOutputFormat.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(CrawlDatum.class);diff --git a/src/java/org/apache/nutch/crawl/CrawlDbReader.java b/src/java/org/apache/nutch/crawl/CrawlDbReader.javaindex 6bd53b5af..0ba44afc8 100644--- a/src/java/org/apache/nutch/crawl/CrawlDbReader.java+++ b/src/java/org/apache/nutch/crawl/CrawlDbReader.java@@ -39,12 +39,13 @@ import org.apache.hadoop.io.LongWritable;import org.apache.hadoop.io.MapFile;import org.apache.hadoop.io.SequenceFile;import org.apache.hadoop.io.Text;+import org.apache.hadoop.mapred.FileInputFormat;+import org.apache.hadoop.mapred.FileOutputFormat;import org.apache.hadoop.mapred.JobClient;import org.apache.hadoop.mapred.JobConf;import org.apache.hadoop.mapred.MapFileOutputFormat;import org.apache.hadoop.mapred.Mapper;import org.apache.hadoop.mapred.OutputCollector;-import org.apache.hadoop.mapred.OutputFormatBase;import org.apache.hadoop.mapred.RecordWriter;import org.apache.hadoop.mapred.Reducer;import org.apache.hadoop.mapred.Reporter;@@ -77,7 +78,8 @@ public class CrawlDbReader implements Closeable {private void openReaders(String crawlDb, Configuration config) throws IOException {if (readers != null) return;FileSystem fs = FileSystem.get(config);- readers = MapFileOutputFormat.getReaders(fs, new Path(crawlDb, CrawlDb.CURRENT_NAME), config);+ readers = MapFileOutputFormat.getReaders(fs, new Path(crawlDb,+ CrawlDb.CURRENT_NAME), config);}private void closeReaders() {@@ -91,7 +93,7 @@ public class CrawlDbReader implements Closeable {}}- public static class CrawlDatumCsvOutputFormat extends OutputFormatBase<Text,CrawlDatum> {+ public static class CrawlDatumCsvOutputFormat extends FileOutputFormat<Text,CrawlDatum> {protected static class LineRecordWriter implements RecordWriter<Text,CrawlDatum> {private DataOutputStream out;@@ -138,7 +140,7 @@ public class CrawlDbReader implements Closeable {public RecordWriter<Text,CrawlDatum> getRecordWriter(FileSystem fs, JobConf job, String name,Progressable progress) throws IOException {- Path dir = job.getOutputPath();+ Path dir = FileOutputFormat.getOutputPath(job);DataOutputStream fileOut = fs.create(new Path(dir, name), progress);return new LineRecordWriter(fileOut);}@@ -299,14 +301,14 @@ public class CrawlDbReader implements Closeable {job.setJobName("stats " + crawlDb);job.setBoolean("db.reader.stats.sort", sort);- job.addInputPath(new Path(crawlDb, CrawlDb.CURRENT_NAME));+ FileInputFormat.addInputPath(job, new Path(crawlDb, CrawlDb.CURRENT_NAME));job.setInputFormat(SequenceFileInputFormat.class);job.setMapperClass(CrawlDbStatMapper.class);job.setCombinerClass(CrawlDbStatCombiner.class);job.setReducerClass(CrawlDbStatReducer.class);- job.setOutputPath(tmpFolder);+ FileOutputFormat.setOutputPath(job, tmpFolder);job.setOutputFormat(SequenceFileOutputFormat.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(LongWritable.class);@@ -366,7 +368,7 @@ public class CrawlDbReader implements Closeable {}}// removing the tmp folder- fileSystem.delete(tmpFolder);+ fileSystem.delete(tmpFolder, true);if (LOG.isInfoEnabled()) { LOG.info("CrawlDb statistics: done"); }}@@ -375,7 +377,8 @@ public class CrawlDbReader implements Closeable {Text key = new Text(url);CrawlDatum val = new CrawlDatum();openReaders(crawlDb, config);- CrawlDatum res = (CrawlDatum)MapFileOutputFormat.getEntry(readers, new HashPartitioner(), key, val);+ CrawlDatum res = (CrawlDatum)MapFileOutputFormat.getEntry(readers,+ new HashPartitioner<Text, CrawlDatum>(), key, val);return res;}@@ -401,10 +404,10 @@ public class CrawlDbReader implements Closeable {JobConf job = new NutchJob(config);job.setJobName("dump " + crawlDb);- job.addInputPath(new Path(crawlDb, CrawlDb.CURRENT_NAME));+ FileInputFormat.addInputPath(job, new Path(crawlDb, CrawlDb.CURRENT_NAME));job.setInputFormat(SequenceFileInputFormat.class);- job.setOutputPath(outFolder);+ FileOutputFormat.setOutputPath(job, outFolder);if(format == CSV_FORMAT) job.setOutputFormat(CrawlDatumCsvOutputFormat.class);else job.setOutputFormat(TextOutputFormat.class);job.setOutputKeyClass(Text.class);@@ -429,12 +432,12 @@ public class CrawlDbReader implements Closeable {JobConf job = new NutchJob(config);job.setJobName("topN prepare " + crawlDb);- job.addInputPath(new Path(crawlDb, CrawlDb.CURRENT_NAME));+ FileInputFormat.addInputPath(job, new Path(crawlDb, CrawlDb.CURRENT_NAME));job.setInputFormat(SequenceFileInputFormat.class);job.setMapperClass(CrawlDbTopNMapper.class);job.setReducerClass(IdentityReducer.class);- job.setOutputPath(tempDir);+ FileOutputFormat.setOutputPath(job, tempDir);job.setOutputFormat(SequenceFileOutputFormat.class);job.setOutputKeyClass(FloatWritable.class);job.setOutputValueClass(Text.class);@@ -450,22 +453,21 @@ public class CrawlDbReader implements Closeable {job.setJobName("topN collect " + crawlDb);job.setLong("db.reader.topn", topN);- job.addInputPath(tempDir);+ FileInputFormat.addInputPath(job, tempDir);job.setInputFormat(SequenceFileInputFormat.class);job.setMapperClass(IdentityMapper.class);job.setReducerClass(CrawlDbTopNReducer.class);- job.setOutputPath(outFolder);+ FileOutputFormat.setOutputPath(job, outFolder);job.setOutputFormat(TextOutputFormat.class);job.setOutputKeyClass(FloatWritable.class);job.setOutputValueClass(Text.class);- // XXX *sigh* this apparently doesn't work ... :-((job.setNumReduceTasks(1); // create a single file.JobClient.runJob(job);FileSystem fs = FileSystem.get(config);- fs.delete(tempDir);+ fs.delete(tempDir, true);if (LOG.isInfoEnabled()) { LOG.info("CrawlDb topN: done"); }}diff --git a/src/java/org/apache/nutch/crawl/CrawlDbReducer.java b/src/java/org/apache/nutch/crawl/CrawlDbReducer.javaindex d1842ed40..7ceed077e 100644--- a/src/java/org/apache/nutch/crawl/CrawlDbReducer.java+++ b/src/java/org/apache/nutch/crawl/CrawlDbReducer.java@@ -32,7 +32,7 @@ import org.apache.nutch.scoring.ScoringFilterException;import org.apache.nutch.scoring.ScoringFilters;/** Merge new page entries with existing entries. */-public class CrawlDbReducer implements Reducer {+public class CrawlDbReducer implements Reducer<Text, CrawlDatum, Text, CrawlDatum> {public static final Log LOG = LogFactory.getLog(CrawlDbReducer.class);private int retryMax;@@ -42,6 +42,8 @@ public class CrawlDbReducer implements Reducer {private boolean additionsAllowed;private int maxInterval;private FetchSchedule schedule;+ private CrawlDatum fetch = new CrawlDatum();+ private CrawlDatum old = new CrawlDatum();public void configure(JobConf job) {retryMax = job.getInt("db.fetch.retry.max", 3);@@ -55,40 +57,44 @@ public class CrawlDbReducer implements Reducer {public void close() {}- public void reduce(WritableComparable key, Iterator values,- OutputCollector output, Reporter reporter)+ public void reduce(Text key, Iterator<CrawlDatum> values,+ OutputCollector<Text, CrawlDatum> output, Reporter reporter)throws IOException {- CrawlDatum fetch = null;- CrawlDatum old = null;+ boolean fetchSet = false;+ boolean oldSet = false;byte[] signature = null;linked.clear();while (values.hasNext()) {CrawlDatum datum = (CrawlDatum)values.next();if (CrawlDatum.hasDbStatus(datum)) {- if (old == null) {- old = datum;+ if (!oldSet) {+ old.set(datum);+ oldSet = true;} else {// always take the latest version- if (old.getFetchTime() < datum.getFetchTime()) old = datum;+ if (old.getFetchTime() < datum.getFetchTime()) old.set(datum);}continue;}if (CrawlDatum.hasFetchStatus(datum)) {- if (fetch == null) {- fetch = datum;+ if (!fetchSet) {+ fetch.set(datum);+ fetchSet = true;} else {// always take the latest version- if (fetch.getFetchTime() < datum.getFetchTime()) fetch = datum;+ if (fetch.getFetchTime() < datum.getFetchTime()) fetch.set(datum);}continue;}switch (datum.getStatus()) { // collect other infocase CrawlDatum.STATUS_LINKED:- linked.add(datum);+ CrawlDatum link = new CrawlDatum();+ link.set(datum);+ linked.add(link);break;case CrawlDatum.STATUS_SIGNATURE:signature = datum.getSignature();@@ -99,16 +105,17 @@ public class CrawlDbReducer implements Reducer {}// if it doesn't already exist, skip it- if (old == null && !additionsAllowed) return;+ if (!oldSet && !additionsAllowed) return;// if there is no fetched datum, perhaps there is a link- if (fetch == null && linked.size() > 0) {+ if (!fetchSet && linked.size() > 0) {fetch = linked.get(0);+ fetchSet = true;}// still no new data - record only unchanged old data, if exists, and return- if (fetch == null) {- if (old != null) // at this point at least "old" should be present+ if (!fetchSet) {+ if (oldSet) // at this point at least "old" should be presentoutput.collect(key, old);elseLOG.warn("Missing fetch and old value, signature=" + signature);@@ -116,12 +123,12 @@ public class CrawlDbReducer implements Reducer {}if (signature == null) signature = fetch.getSignature();- long prevModifiedTime = old != null ? old.getModifiedTime() : 0L;- long prevFetchTime = old != null ? old.getFetchTime() : 0L;+ long prevModifiedTime = oldSet ? old.getModifiedTime() : 0L;+ long prevFetchTime = oldSet ? old.getFetchTime() : 0L;// initialize with the latest version, be it fetch or linkresult.set(fetch);- if (old != null) {+ if (oldSet) {// copy metadata from old, if existsif (old.getMetaData().size() > 0) {result.getMetaData().putAll(old.getMetaData());@@ -138,7 +145,7 @@ public class CrawlDbReducer implements Reducer {switch (fetch.getStatus()) { // determine new statuscase CrawlDatum.STATUS_LINKED: // it was link- if (old != null) { // if old exists+ if (oldSet) { // if old existsresult.set(old); // use it} else {result = schedule.initializeSchedule((Text)key, result);@@ -164,7 +171,7 @@ public class CrawlDbReducer implements Reducer {if (fetch.getStatus() == CrawlDatum.STATUS_FETCH_NOTMODIFIED) {modified = FetchSchedule.STATUS_NOTMODIFIED;} else {- if (old != null && old.getSignature() != null && signature != null) {+ if (oldSet && old.getSignature() != null && signature != null) {if (SignatureComparator._compare(old.getSignature(), signature) != 0) {modified = FetchSchedule.STATUS_MODIFIED;} else {@@ -178,7 +185,7 @@ public class CrawlDbReducer implements Reducer {// set the result status and signatureif (modified == FetchSchedule.STATUS_NOTMODIFIED) {result.setStatus(CrawlDatum.STATUS_DB_NOTMODIFIED);- if (old != null) result.setSignature(old.getSignature());+ if (oldSet) result.setSignature(old.getSignature());} else {switch (fetch.getStatus()) {case CrawlDatum.STATUS_FETCH_SUCCESS:@@ -192,7 +199,7 @@ public class CrawlDbReducer implements Reducer {break;default:LOG.warn("Unexpected status: " + fetch.getStatus() + " resetting to old status.");- if (old != null) result.setStatus(old.getStatus());+ if (oldSet) result.setStatus(old.getStatus());else result.setStatus(CrawlDatum.STATUS_DB_UNFETCHED);}result.setSignature(signature);@@ -210,7 +217,7 @@ public class CrawlDbReducer implements Reducer {}return;case CrawlDatum.STATUS_FETCH_RETRY: // temporary failure- if (old != null) {+ if (oldSet) {result.setSignature(old.getSignature()); // use old signature}result = schedule.setPageRetrySchedule((Text)key, result, prevFetchTime,@@ -223,7 +230,7 @@ public class CrawlDbReducer implements Reducer {break;case CrawlDatum.STATUS_FETCH_GONE: // permanent failure- if (old != null)+ if (oldSet)result.setSignature(old.getSignature()); // use old signatureresult.setStatus(CrawlDatum.STATUS_DB_GONE);result = schedule.setPageGoneSchedule((Text)key, result, prevFetchTime,@@ -235,7 +242,7 @@ public class CrawlDbReducer implements Reducer {}try {- scfilters.updateDbScore((Text)key, old, result, linked);+ scfilters.updateDbScore((Text)key, oldSet ? old : null, result, linked);} catch (Exception e) {if (LOG.isWarnEnabled()) {LOG.warn("Couldn't update score, key=" + key + ": " + e);diff --git a/src/java/org/apache/nutch/crawl/Generator.java b/src/java/org/apache/nutch/crawl/Generator.javaindex dd4617abb..baa25d57a 100644--- a/src/java/org/apache/nutch/crawl/Generator.java+++ b/src/java/org/apache/nutch/crawl/Generator.java@@ -339,24 +339,25 @@ public class Generator extends Configured implements Tool {output.collect((Text)key, (CrawlDatum)value);}}+ private CrawlDatum orig = new CrawlDatum();+ private LongWritable genTime = new LongWritable(0L);public void reduce(Text key, Iterator<CrawlDatum> values, OutputCollector<Text, CrawlDatum> output, Reporter reporter) throws IOException {- CrawlDatum orig = null;- LongWritable genTime = null;while (values.hasNext()) {CrawlDatum val = values.next();if (val.getMetaData().containsKey(Nutch.WRITABLE_GENERATE_TIME_KEY)) {- genTime = (LongWritable)val.getMetaData().get(Nutch.WRITABLE_GENERATE_TIME_KEY);+ LongWritable gt = (LongWritable)val.getMetaData().get(Nutch.WRITABLE_GENERATE_TIME_KEY);+ genTime.set(gt.get());if (genTime.get() != generateTime) {- orig = val;- genTime = null;+ orig.set(val);+ genTime.set(0L);continue;}} else {- orig = val;+ orig.set(val);}}- if (genTime != null) {+ if (genTime.get() != 0L) {orig.getMetaData().put(Nutch.WRITABLE_GENERATE_TIME_KEY, genTime);}output.collect(key, orig);@@ -440,14 +441,14 @@ public class Generator extends Configured implements Tool {job.setLong(CRAWL_TOP_N, topN);job.setBoolean(CRAWL_GENERATE_FILTER, filter);- job.setInputPath(new Path(dbDir, CrawlDb.CURRENT_NAME));+ FileInputFormat.addInputPath(job, new Path(dbDir, CrawlDb.CURRENT_NAME));job.setInputFormat(SequenceFileInputFormat.class);job.setMapperClass(Selector.class);job.setPartitionerClass(Selector.class);job.setReducerClass(Selector.class);- job.setOutputPath(tempDir);+ FileOutputFormat.setOutputPath(job, tempDir);job.setOutputFormat(SequenceFileOutputFormat.class);job.setOutputKeyClass(FloatWritable.class);job.setOutputKeyComparatorClass(DecreasingFloatComparator.class);@@ -476,7 +477,7 @@ public class Generator extends Configured implements Tool {if (empty) {LOG.warn("Generator: 0 records selected for fetching, exiting ...");LockUtil.removeLockFile(fs, lock);- fs.delete(tempDir);+ fs.delete(tempDir, true);return null;}@@ -489,7 +490,7 @@ public class Generator extends Configured implements Tool {job.setInt("partition.url.by.host.seed", new Random().nextInt());- job.setInputPath(tempDir);+ FileInputFormat.addInputPath(job, tempDir);job.setInputFormat(SequenceFileInputFormat.class);job.setMapperClass(SelectorInverseMapper.class);@@ -499,7 +500,7 @@ public class Generator extends Configured implements Tool {job.setReducerClass(PartitionReducer.class);job.setNumReduceTasks(numLists);- job.setOutputPath(output);+ FileOutputFormat.setOutputPath(job, output);job.setOutputFormat(SequenceFileOutputFormat.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(CrawlDatum.class);@@ -508,7 +509,7 @@ public class Generator extends Configured implements Tool {JobClient.runJob(job);} catch (IOException e) {LockUtil.removeLockFile(fs, lock);- fs.delete(tempDir);+ fs.delete(tempDir, true);throw e;}if (getConf().getBoolean(GENERATE_UPDATE_CRAWLDB, false)) {@@ -520,28 +521,28 @@ public class Generator extends Configured implements Tool {job = new NutchJob(getConf());job.setJobName("generate: updatedb " + dbDir);job.setLong(Nutch.GENERATE_TIME_KEY, generateTime);- job.addInputPath(tempDir);- job.addInputPath(new Path(dbDir, CrawlDb.CURRENT_NAME));+ FileInputFormat.addInputPath(job, tempDir);+ FileInputFormat.addInputPath(job, new Path(dbDir, CrawlDb.CURRENT_NAME));job.setInputFormat(SequenceFileInputFormat.class);job.setMapperClass(CrawlDbUpdater.class);job.setReducerClass(CrawlDbUpdater.class);job.setOutputFormat(MapFileOutputFormat.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(CrawlDatum.class);- job.setOutputPath(tempDir2);+ FileOutputFormat.setOutputPath(job, tempDir2);try {JobClient.runJob(job);CrawlDb.install(job, dbDir);} catch (IOException e) {LockUtil.removeLockFile(fs, lock);- fs.delete(tempDir);- fs.delete(tempDir2);+ fs.delete(tempDir, true);+ fs.delete(tempDir2, true);throw e;}- fs.delete(tempDir2);+ fs.delete(tempDir2, true);}LockUtil.removeLockFile(fs, lock);- fs.delete(tempDir);+ fs.delete(tempDir, true);if (LOG.isInfoEnabled()) { LOG.info("Generator: done."); }diff --git a/src/java/org/apache/nutch/crawl/Injector.java b/src/java/org/apache/nutch/crawl/Injector.javaindex 54bab395f..c2f0d91f6 100644--- a/src/java/org/apache/nutch/crawl/Injector.java+++ b/src/java/org/apache/nutch/crawl/Injector.java@@ -99,22 +99,25 @@ public class Injector extends Configured implements Tool {public void configure(JobConf job) {}public void close() {}+ private CrawlDatum old = new CrawlDatum();+ private CrawlDatum injected = new CrawlDatum();+public void reduce(Text key, Iterator<CrawlDatum> values,OutputCollector<Text, CrawlDatum> output, Reporter reporter)throws IOException {- CrawlDatum old = null;- CrawlDatum injected = null;+ boolean oldSet = false;while (values.hasNext()) {CrawlDatum val = values.next();if (val.getStatus() == CrawlDatum.STATUS_INJECTED) {- injected = val;+ injected.set(val);injected.setStatus(CrawlDatum.STATUS_DB_UNFETCHED);} else {- old = val;+ old.set(val);+ oldSet = true;}}CrawlDatum res = null;- if (old != null) res = old; // don't overwrite existing value+ if (oldSet) res = old; // don't overwrite existing valueelse res = injected;output.collect(key, res);@@ -146,10 +149,10 @@ public class Injector extends Configured implements Tool {}JobConf sortJob = new NutchJob(getConf());sortJob.setJobName("inject " + urlDir);- sortJob.setInputPath(urlDir);+ FileInputFormat.addInputPath(sortJob, urlDir);sortJob.setMapperClass(InjectMapper.class);- sortJob.setOutputPath(tempDir);+ FileOutputFormat.setOutputPath(sortJob, tempDir);sortJob.setOutputFormat(SequenceFileOutputFormat.class);sortJob.setOutputKeyClass(Text.class);sortJob.setOutputValueClass(CrawlDatum.class);@@ -161,14 +164,14 @@ public class Injector extends Configured implements Tool {LOG.info("Injector: Merging injected urls into crawl db.");}JobConf mergeJob = CrawlDb.createJob(getConf(), crawlDb);- mergeJob.addInputPath(tempDir);+ FileInputFormat.addInputPath(mergeJob, tempDir);mergeJob.setReducerClass(InjectReducer.class);JobClient.runJob(mergeJob);CrawlDb.install(mergeJob, crawlDb);// clean upFileSystem fs = FileSystem.get(getConf());- fs.delete(tempDir);+ fs.delete(tempDir, true);if (LOG.isInfoEnabled()) { LOG.info("Injector: done"); }}diff --git a/src/java/org/apache/nutch/crawl/LinkDb.java b/src/java/org/apache/nutch/crawl/LinkDb.javaindex 3dbc2fe70..7d6ea5046 100644--- a/src/java/org/apache/nutch/crawl/LinkDb.java+++ b/src/java/org/apache/nutch/crawl/LinkDb.java@@ -164,7 +164,7 @@ public class LinkDb extends Configured implements Tool, Mapper<Text, ParseData,if (LOG.isInfoEnabled()) {LOG.info("LinkDb: adding segment: " + segments[i]);}- job.addInputPath(new Path(segments[i], ParseData.DIR_NAME));+ FileInputFormat.addInputPath(job, new Path(segments[i], ParseData.DIR_NAME));}try {JobClient.runJob(job);@@ -177,18 +177,18 @@ public class LinkDb extends Configured implements Tool, Mapper<Text, ParseData,LOG.info("LinkDb: merging with existing linkdb: " + linkDb);}// try to merge- Path newLinkDb = job.getOutputPath();+ Path newLinkDb = FileOutputFormat.getOutputPath(job);job = LinkDbMerger.createMergeJob(getConf(), linkDb, normalize, filter);- job.addInputPath(currentLinkDb);- job.addInputPath(newLinkDb);+ FileInputFormat.addInputPath(job, currentLinkDb);+ FileInputFormat.addInputPath(job, newLinkDb);try {JobClient.runJob(job);} catch (IOException e) {LockUtil.removeLockFile(fs, lock);- fs.delete(newLinkDb);+ fs.delete(newLinkDb, true);throw e;}- fs.delete(newLinkDb);+ fs.delete(newLinkDb, true);}LinkDb.install(job, linkDb);if (LOG.isInfoEnabled()) { LOG.info("LinkDb: done"); }@@ -220,7 +220,7 @@ public class LinkDb extends Configured implements Tool, Mapper<Text, ParseData,}job.setReducerClass(LinkDbMerger.class);- job.setOutputPath(newLinkDb);+ FileOutputFormat.setOutputPath(job, newLinkDb);job.setOutputFormat(MapFileOutputFormat.class);job.setBoolean("mapred.output.compress", true);job.setOutputKeyClass(Text.class);@@ -230,17 +230,17 @@ public class LinkDb extends Configured implements Tool, Mapper<Text, ParseData,}public static void install(JobConf job, Path linkDb) throws IOException {- Path newLinkDb = job.getOutputPath();+ Path newLinkDb = FileOutputFormat.getOutputPath(job);FileSystem fs = new JobClient(job).getFs();Path old = new Path(linkDb, "old");Path current = new Path(linkDb, CURRENT_NAME);if (fs.exists(current)) {- if (fs.exists(old)) fs.delete(old);+ if (fs.exists(old)) fs.delete(old, true);fs.rename(current, old);}fs.mkdirs(linkDb);fs.rename(newLinkDb, current);- if (fs.exists(old)) fs.delete(old);+ if (fs.exists(old)) fs.delete(old, true);LockUtil.removeLockFile(fs, new Path(linkDb, LOCK_NAME));}diff --git a/src/java/org/apache/nutch/crawl/LinkDbFilter.java b/src/java/org/apache/nutch/crawl/LinkDbFilter.javaindex 4ae49cd83..645a3b376 100644--- a/src/java/org/apache/nutch/crawl/LinkDbFilter.java+++ b/src/java/org/apache/nutch/crawl/LinkDbFilter.java@@ -23,8 +23,6 @@ import java.util.Iterator;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.hadoop.io.Text;-import org.apache.hadoop.io.Writable;-import org.apache.hadoop.io.WritableComparable;import org.apache.hadoop.mapred.JobConf;import org.apache.hadoop.mapred.Mapper;import org.apache.hadoop.mapred.OutputCollector;@@ -38,7 +36,7 @@ import org.apache.nutch.net.URLNormalizers;** @author Andrzej Bialecki*/-public class LinkDbFilter implements Mapper {+public class LinkDbFilter implements Mapper<Text, Inlinks, Text, Inlinks> {public static final String URL_FILTERING = "linkdb.url.filters";public static final String URL_NORMALIZING = "linkdb.url.normalizer";@@ -73,7 +71,8 @@ public class LinkDbFilter implements Mapper {public void close() {}- public void map(WritableComparable key, Writable value, OutputCollector output, Reporter reporter) throws IOException {+ public void map(Text key, Inlinks value,+ OutputCollector<Text, Inlinks> output, Reporter reporter) throws IOException {String url = key.toString();Inlinks result = new Inlinks();if (normalize) {@@ -93,8 +92,7 @@ public class LinkDbFilter implements Mapper {}}if (url == null) return; // didn't pass the filters- Inlinks inlinks = (Inlinks)value;- Iterator<Inlink> it = inlinks.iterator();+ Iterator<Inlink> it = value.iterator();String fromUrl = null;while (it.hasNext()) {Inlink inlink = it.next();diff --git a/src/java/org/apache/nutch/crawl/LinkDbMerger.java b/src/java/org/apache/nutch/crawl/LinkDbMerger.javaindex a467df628..7e6a83730 100644--- a/src/java/org/apache/nutch/crawl/LinkDbMerger.java+++ b/src/java/org/apache/nutch/crawl/LinkDbMerger.java@@ -28,6 +28,8 @@ import org.apache.hadoop.conf.Configured;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.Text;+import org.apache.hadoop.mapred.FileInputFormat;+import org.apache.hadoop.mapred.FileOutputFormat;import org.apache.hadoop.mapred.JobClient;import org.apache.hadoop.mapred.JobConf;import org.apache.hadoop.mapred.MapFileOutputFormat;@@ -100,12 +102,12 @@ public class LinkDbMerger extends Configured implements Tool, Reducer<Text, Inlipublic void merge(Path output, Path[] dbs, boolean normalize, boolean filter) throws Exception {JobConf job = createMergeJob(getConf(), output, normalize, filter);for (int i = 0; i < dbs.length; i++) {- job.addInputPath(new Path(dbs[i], LinkDb.CURRENT_NAME));+ FileInputFormat.addInputPath(job, new Path(dbs[i], LinkDb.CURRENT_NAME));}JobClient.runJob(job);FileSystem fs = FileSystem.get(getConf());fs.mkdirs(output);- fs.rename(job.getOutputPath(), new Path(output, LinkDb.CURRENT_NAME));+ fs.rename(FileOutputFormat.getOutputPath(job), new Path(output, LinkDb.CURRENT_NAME));}public static JobConf createMergeJob(Configuration config, Path linkDb, boolean normalize, boolean filter) {@@ -123,7 +125,7 @@ public class LinkDbMerger extends Configured implements Tool, Reducer<Text, Inlijob.setBoolean(LinkDbFilter.URL_FILTERING, filter);job.setReducerClass(LinkDbMerger.class);- job.setOutputPath(newLinkDb);+ FileOutputFormat.setOutputPath(job, newLinkDb);job.setOutputFormat(MapFileOutputFormat.class);job.setBoolean("mapred.output.compress", true);job.setOutputKeyClass(Text.class);diff --git a/src/java/org/apache/nutch/crawl/LinkDbReader.java b/src/java/org/apache/nutch/crawl/LinkDbReader.javaindex eb5df45bf..0c23f8b3a 100644--- a/src/java/org/apache/nutch/crawl/LinkDbReader.java+++ b/src/java/org/apache/nutch/crawl/LinkDbReader.java@@ -99,10 +99,10 @@ public class LinkDbReader extends Configured implements Tool, Closeable {JobConf job = new NutchJob(getConf());job.setJobName("read " + linkdb);- job.addInputPath(new Path(linkdb, LinkDb.CURRENT_NAME));+ FileInputFormat.addInputPath(job, new Path(linkdb, LinkDb.CURRENT_NAME));job.setInputFormat(SequenceFileInputFormat.class);- job.setOutputPath(outFolder);+ FileOutputFormat.setOutputPath(job, outFolder);job.setOutputFormat(TextOutputFormat.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(Inlinks.class);diff --git a/src/java/org/apache/nutch/fetcher/Fetcher.java b/src/java/org/apache/nutch/fetcher/Fetcher.javaindex fbb6b179b..bb1b1deea 100644--- a/src/java/org/apache/nutch/fetcher/Fetcher.java+++ b/src/java/org/apache/nutch/fetcher/Fetcher.java@@ -62,7 +62,8 @@ public class Fetcher extends Configured implements Tool, MapRunnable<WritableComFileSystem fs = FileSystem.get(job);InputSplit[] splits = new InputSplit[files.length];for (int i = 0; i < files.length; i++) {- splits[i] = new FileSplit(files[i], 0, fs.getFileStatus(files[i]).getLen(), job);+ splits[i] = new FileSplit(files[i], 0,+ fs.getFileStatus(files[i]).getLen(), (String[])null);}return splits;}@@ -519,12 +520,12 @@ public class Fetcher extends Configured implements Tool, MapRunnable<WritableCom// for politeness, don't permit parallel execution of a single taskjob.setSpeculativeExecution(false);- job.setInputPath(new Path(segment, CrawlDatum.GENERATE_DIR_NAME));+ FileInputFormat.addInputPath(job, new Path(segment, CrawlDatum.GENERATE_DIR_NAME));job.setInputFormat(InputFormat.class);job.setMapRunnerClass(Fetcher.class);- job.setOutputPath(segment);+ FileOutputFormat.setOutputPath(job, segment);job.setOutputFormat(FetcherOutputFormat.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(NutchWritable.class);diff --git a/src/java/org/apache/nutch/fetcher/Fetcher2.java b/src/java/org/apache/nutch/fetcher/Fetcher2.javaindex abf5732bd..ea429f612 100644--- a/src/java/org/apache/nutch/fetcher/Fetcher2.java+++ b/src/java/org/apache/nutch/fetcher/Fetcher2.java@@ -83,11 +83,12 @@ import org.apache.nutch.util.*;** @author Andrzej Bialecki*/-public class Fetcher2 extends Configured implements MapRunnable {+public class Fetcher2 extends Configured implements+ MapRunnable<Text, CrawlDatum, Text, NutchWritable> {public static final Log LOG = LogFactory.getLog(Fetcher2.class);- public static class InputFormat extends SequenceFileInputFormat {+ public static class InputFormat extends SequenceFileInputFormat<Text, CrawlDatum> {/** Don't split inputs, to keep things polite. */public InputSplit[] getSplits(JobConf job, int nSplits)throws IOException {@@ -95,13 +96,14 @@ public class Fetcher2 extends Configured implements MapRunnable {FileSplit[] splits = new FileSplit[files.length];FileSystem fs = FileSystem.get(job);for (int i = 0; i < files.length; i++) {- splits[i] = new FileSplit(files[i], 0, fs.getFileStatus(files[i]).getLen(), job);+ splits[i] = new FileSplit(files[i], 0,+ fs.getFileStatus(files[i]).getLen(), (String[])null);}return splits;}}- private OutputCollector output;+ private OutputCollector<Text, NutchWritable> output;private Reporter reporter;private String segmentName;@@ -376,11 +378,12 @@ public class Fetcher2 extends Configured implements MapRunnable {* items are consumed by FetcherThread-s.*/private static class QueueFeeder extends Thread {- private RecordReader reader;+ private RecordReader<Text, CrawlDatum> reader;private FetchItemQueues queues;private int size;- public QueueFeeder(RecordReader reader, FetchItemQueues queues, int size) {+ public QueueFeeder(RecordReader<Text, CrawlDatum> reader,+ FetchItemQueues queues, int size) {this.reader = reader;this.queues = queues;this.size = size;@@ -681,7 +684,8 @@ public class Fetcher2 extends Configured implements MapRunnable {}return url;} else {- CrawlDatum newDatum = new CrawlDatum();+ CrawlDatum newDatum = new CrawlDatum(CrawlDatum.STATUS_LINKED,+ datum.getFetchInterval());if (reprUrl != null) {newDatum.getMetaData().put(Nutch.WRITABLE_REPR_URL_KEY,new Text(reprUrl));@@ -859,7 +863,8 @@ public class Fetcher2 extends Configured implements MapRunnable {return conf.getBoolean("fetcher.store.content", true);}- public void run(RecordReader input, OutputCollector output,+ public void run(RecordReader<Text, CrawlDatum> input,+ OutputCollector<Text, NutchWritable> output,Reporter reporter) throws IOException {this.output = output;@@ -927,12 +932,12 @@ public class Fetcher2 extends Configured implements MapRunnable {// for politeness, don't permit parallel execution of a single taskjob.setSpeculativeExecution(false);- job.setInputPath(new Path(segment, CrawlDatum.GENERATE_DIR_NAME));+ FileInputFormat.addInputPath(job, new Path(segment, CrawlDatum.GENERATE_DIR_NAME));job.setInputFormat(InputFormat.class);job.setMapRunnerClass(Fetcher2.class);- job.setOutputPath(segment);+ FileOutputFormat.setOutputPath(job, segment);job.setOutputFormat(FetcherOutputFormat.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(NutchWritable.class);diff --git a/src/java/org/apache/nutch/fetcher/FetcherOutputFormat.java b/src/java/org/apache/nutch/fetcher/FetcherOutputFormat.javaindex de6dbcc88..70e411ccc 100644--- a/src/java/org/apache/nutch/fetcher/FetcherOutputFormat.java+++ b/src/java/org/apache/nutch/fetcher/FetcherOutputFormat.java@@ -25,16 +25,16 @@ import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.MapFile;-import org.apache.hadoop.io.SequenceFile;-import org.apache.hadoop.io.WritableComparable;import org.apache.hadoop.io.Writable;import org.apache.hadoop.io.Text;import org.apache.hadoop.io.SequenceFile.CompressionType;+import org.apache.hadoop.mapred.FileOutputFormat;import org.apache.hadoop.mapred.OutputFormat;import org.apache.hadoop.mapred.RecordWriter;import org.apache.hadoop.mapred.JobConf;import org.apache.hadoop.mapred.Reporter;+import org.apache.hadoop.mapred.SequenceFileOutputFormat;import org.apache.hadoop.util.Progressable;import org.apache.nutch.parse.Parse;@@ -42,32 +42,34 @@ import org.apache.nutch.parse.ParseOutputFormat;import org.apache.nutch.protocol.Content;/** Splits FetcherOutput entries into multiple map files. */-public class FetcherOutputFormat implements OutputFormat {+public class FetcherOutputFormat implements OutputFormat<Text, NutchWritable> {public void checkOutputSpecs(FileSystem fs, JobConf job) throws IOException {- if (fs.exists(new Path(job.getOutputPath(), CrawlDatum.FETCH_DIR_NAME)))+ Path out = FileOutputFormat.getOutputPath(job);+ if (fs.exists(new Path(out, CrawlDatum.FETCH_DIR_NAME)))throw new IOException("Segment already fetched!");}- public RecordWriter getRecordWriter(final FileSystem fs,+ public RecordWriter<Text, NutchWritable> getRecordWriter(final FileSystem fs,final JobConf job,final String name,final Progressable progress) throws IOException {+ Path out = FileOutputFormat.getOutputPath(job);final Path fetch =- new Path(new Path(job.getOutputPath(), CrawlDatum.FETCH_DIR_NAME), name);+ new Path(new Path(out, CrawlDatum.FETCH_DIR_NAME), name);final Path content =- new Path(new Path(job.getOutputPath(), Content.DIR_NAME), name);+ new Path(new Path(out, Content.DIR_NAME), name);- final CompressionType compType = SequenceFile.getCompressionType(job);+ final CompressionType compType = SequenceFileOutputFormat.getOutputCompressionType(job);final MapFile.Writer fetchOut =new MapFile.Writer(job, fs, fetch.toString(), Text.class, CrawlDatum.class,compType, progress);- return new RecordWriter() {+ return new RecordWriter<Text, NutchWritable>() {private MapFile.Writer contentOut;- private RecordWriter parseOut;+ private RecordWriter<Text, Parse> parseOut;{if (Fetcher.isStoringContent(job)) {@@ -81,17 +83,17 @@ public class FetcherOutputFormat implements OutputFormat {}}- public void write(WritableComparable key, Writable value)+ public void write(Text key, NutchWritable value)throws IOException {- Writable w = ((NutchWritable)value).get();+ Writable w = value.get();if (w instanceof CrawlDatum)fetchOut.append(key, w);else if (w instanceof Content)contentOut.append(key, w);else if (w instanceof Parse)- parseOut.write(key, w);+ parseOut.write(key, (Parse)w);}public void close(Reporter reporter) throws IOException {diff --git a/src/java/org/apache/nutch/indexer/DeleteDuplicates.java b/src/java/org/apache/nutch/indexer/DeleteDuplicates.javaindex bbc7e044b..6bc2512ab 100644--- a/src/java/org/apache/nutch/indexer/DeleteDuplicates.java+++ b/src/java/org/apache/nutch/indexer/DeleteDuplicates.java@@ -148,7 +148,7 @@ public class DeleteDuplicates extends ConfiguredPath[] files = listPaths(job);InputSplit[] splits = new InputSplit[files.length];for (int i = 0; i < files.length; i++) {- splits[i] = new FileSplit(files[i], 0, INDEX_LENGTH, job);+ splits[i] = new FileSplit(files[i], 0, INDEX_LENGTH, (String[])null);}return splits;}@@ -263,21 +263,19 @@ public class DeleteDuplicates extends Configuredpublic void close() {}+ private IndexDoc latest = new IndexDoc();+public void reduce(Text key, Iterator<IndexDoc> values,OutputCollector<MD5Hash, IndexDoc> output, Reporter reporter) throws IOException {- IndexDoc latest = null;+ WritableUtils.cloneInto(latest, values.next());while (values.hasNext()) {IndexDoc value = values.next();- if (latest == null) {- latest = value;- continue;- }if (value.time > latest.time) {// discard current and use more recentlatest.keep = false;LOG.debug("-discard " + latest + ", keep " + value);output.collect(latest.hash, latest);- latest = value;+ WritableUtils.cloneInto(latest, value);} else {// discardvalue.keep = false;@@ -301,10 +299,13 @@ public class DeleteDuplicates extends Configured}public void close() {}++ private IndexDoc highest = new IndexDoc();+public void reduce(MD5Hash key, Iterator<IndexDoc> values,OutputCollector<Text, IndexDoc> output, Reporter reporter)throws IOException {- IndexDoc highest = null;+ boolean highestSet = false;while (values.hasNext()) {IndexDoc value = values.next();// skip already deleted@@ -313,8 +314,9 @@ public class DeleteDuplicates extends Configuredoutput.collect(value.url, value);continue;}- if (highest == null) {- highest = value;+ if (!highestSet) {+ WritableUtils.cloneInto(highest, value);+ highestSet = true;continue;}IndexDoc toDelete = null, toKeep = null;@@ -334,7 +336,7 @@ public class DeleteDuplicates extends ConfiguredtoDelete.keep = false;output.collect(toDelete.url, toDelete);- highest = toKeep;+ WritableUtils.cloneInto(highest, toKeep);}LOG.debug("-keep " + highest);// no need to add this - in phase 2 we only process docs to delete them@@ -427,7 +429,7 @@ public class DeleteDuplicates extends Configuredif (LOG.isInfoEnabled()) {LOG.info("Dedup: adding indexes in: " + indexDirs[i]);}- job.addInputPath(indexDirs[i]);+ FileInputFormat.addInputPath(job, indexDirs[i]);}job.setJobName("dedup 1: urls by time");@@ -436,7 +438,7 @@ public class DeleteDuplicates extends Configuredjob.setMapOutputValueClass(IndexDoc.class);job.setReducerClass(UrlsReducer.class);- job.setOutputPath(outDir1);+ FileOutputFormat.setOutputPath(job, outDir1);job.setOutputKeyClass(MD5Hash.class);job.setOutputValueClass(IndexDoc.class);@@ -450,7 +452,7 @@ public class DeleteDuplicates extends Configuredjob = new NutchJob(getConf());job.setJobName("dedup 2: content by hash");- job.addInputPath(outDir1);+ FileInputFormat.addInputPath(job, outDir1);job.setInputFormat(SequenceFileInputFormat.class);job.setMapOutputKeyClass(MD5Hash.class);job.setMapOutputValueClass(IndexDoc.class);@@ -458,7 +460,7 @@ public class DeleteDuplicates extends Configuredjob.setSpeculativeExecution(false);job.setReducerClass(HashReducer.class);- job.setOutputPath(outDir2);+ FileOutputFormat.setOutputPath(job, outDir2);job.setOutputKeyClass(Text.class);job.setOutputValueClass(IndexDoc.class);@@ -467,12 +469,12 @@ public class DeleteDuplicates extends ConfiguredJobClient.runJob(job);// remove outDir1 - no longer needed- fs.delete(outDir1);+ fs.delete(outDir1, true);job = new NutchJob(getConf());job.setJobName("dedup 3: delete from index(es)");- job.addInputPath(outDir2);+ FileInputFormat.addInputPath(job, outDir2);job.setInputFormat(SequenceFileInputFormat.class);//job.setInputKeyClass(Text.class);//job.setInputValueClass(IndexDoc.class);@@ -487,7 +489,7 @@ public class DeleteDuplicates extends ConfiguredJobClient.runJob(job);- fs.delete(outDir2);+ fs.delete(outDir2, true);if (LOG.isInfoEnabled()) { LOG.info("Dedup: done"); }}diff --git a/src/java/org/apache/nutch/indexer/FsDirectory.java b/src/java/org/apache/nutch/indexer/FsDirectory.javaindex b4b976840..78bab0b1a 100644--- a/src/java/org/apache/nutch/indexer/FsDirectory.java+++ b/src/java/org/apache/nutch/indexer/FsDirectory.java@@ -54,15 +54,17 @@ public class FsDirectory extends Directory {throw new IOException(directory + " not a directory");// clear old files- Path[] files = fs.listPaths(directory, HadoopFSUtil.getPassAllFilter());+ FileStatus[] fstats = fs.listStatus(directory, HadoopFSUtil.getPassAllFilter());+ Path[] files = HadoopFSUtil.getPaths(fstats);for (int i = 0; i < files.length; i++) {- if (!fs.delete(files[i]))+ if (!fs.delete(files[i], false))throw new IOException("Cannot delete " + files[i]);}}public String[] list() throws IOException {- Path[] files = fs.listPaths(directory, HadoopFSUtil.getPassAllFilter());+ FileStatus[] fstats = fs.listStatus(directory, HadoopFSUtil.getPassAllFilter());+ Path[] files = HadoopFSUtil.getPaths(fstats);if (files == null) return null;String[] result = new String[files.length];@@ -89,7 +91,7 @@ public class FsDirectory extends Directory {}public void deleteFile(String name) throws IOException {- if (!fs.delete(new Path(directory, name)))+ if (!fs.delete(new Path(directory, name), false))throw new IOException("Cannot delete " + name);}@@ -98,14 +100,14 @@ public class FsDirectory extends Directory {// so we explicitly delete the target first.Path target = new Path(directory, to);if (fs.exists(target)) {- fs.delete(target);+ fs.delete(target, false);}fs.rename(new Path(directory, from), target);}public IndexOutput createOutput(String name) throws IOException {Path file = new Path(directory, name);- if (fs.exists(file) && !fs.delete(file)) // delete existing, if any+ if (fs.exists(file) && !fs.delete(file, false)) // delete existing, if anythrow new IOException("Cannot overwrite: " + file);return new DfsIndexOutput(file, this.ioFileBufferSize);diff --git a/src/java/org/apache/nutch/indexer/IndexMerger.java b/src/java/org/apache/nutch/indexer/IndexMerger.javaindex e734506a0..7849998a3 100644--- a/src/java/org/apache/nutch/indexer/IndexMerger.java+++ b/src/java/org/apache/nutch/indexer/IndexMerger.java@@ -63,7 +63,7 @@ public class IndexMerger extends Configured implements Tool {FileSystem localFs = FileSystem.getLocal(getConf());if (localFs.exists(localWorkingDir)) {- localFs.delete(localWorkingDir);+ localFs.delete(localWorkingDir, true);}localFs.mkdirs(localWorkingDir);@@ -135,7 +135,8 @@ public class IndexMerger extends Configured implements Tool {Path outputIndex = new Path(args[i++]);for (; i < args.length; i++) {- indexDirs.addAll(Arrays.asList(fs.listPaths(new Path(args[i]), HadoopFSUtil.getPassAllFilter())));+ FileStatus[] fstats = fs.listStatus(new Path(args[i]), HadoopFSUtil.getPassDirectoriesFilter(fs));+ indexDirs.addAll(Arrays.asList(HadoopFSUtil.getPaths(fstats)));}//@@ -151,7 +152,7 @@ public class IndexMerger extends Configured implements Tool {LOG.fatal("IndexMerger: " + StringUtils.stringifyException(e));return -1;} finally {- FileSystem.getLocal(getConf()).delete(workDir);+ FileSystem.getLocal(getConf()).delete(workDir, true);}}}diff --git a/src/java/org/apache/nutch/indexer/Indexer.java b/src/java/org/apache/nutch/indexer/Indexer.javaindex 1fefee9f9..e89a279dd 100644--- a/src/java/org/apache/nutch/indexer/Indexer.java+++ b/src/java/org/apache/nutch/indexer/Indexer.java@@ -83,14 +83,14 @@ public class Indexer extends Configured implements Tool, Reducer<Text, NutchWrit/** Unwrap Lucene Documents created by reduce and add them to an index. */public static class OutputFormat- extends org.apache.hadoop.mapred.OutputFormatBase<WritableComparable, LuceneDocumentWrapper> {+ extends org.apache.hadoop.mapred.FileOutputFormat<WritableComparable, LuceneDocumentWrapper> {public RecordWriter<WritableComparable, LuceneDocumentWrapper> getRecordWriter(final FileSystem fs, JobConf job,String name, final Progressable progress) throws IOException {- final Path perm = new Path(job.getOutputPath(), name);+ final Path perm = new Path(FileOutputFormat.getOutputPath(job), name);final Path temp =job.getLocalPath("index/_"+Integer.toString(new Random().nextInt()));- fs.delete(perm); // delete old, if any+ fs.delete(perm, true); // delete old, if anyfinal AnalyzerFactory factory = new AnalyzerFactory(job);final IndexWriter writer = // build locally first@@ -290,20 +290,20 @@ public class Indexer extends Configured implements Tool, Reducer<Text, NutchWritif (LOG.isInfoEnabled()) {LOG.info("Indexer: adding segment: " + segments[i]);}- job.addInputPath(new Path(segments[i], CrawlDatum.FETCH_DIR_NAME));- job.addInputPath(new Path(segments[i], CrawlDatum.PARSE_DIR_NAME));- job.addInputPath(new Path(segments[i], ParseData.DIR_NAME));- job.addInputPath(new Path(segments[i], ParseText.DIR_NAME));+ FileInputFormat.addInputPath(job, new Path(segments[i], CrawlDatum.FETCH_DIR_NAME));+ FileInputFormat.addInputPath(job, new Path(segments[i], CrawlDatum.PARSE_DIR_NAME));+ FileInputFormat.addInputPath(job, new Path(segments[i], ParseData.DIR_NAME));+ FileInputFormat.addInputPath(job, new Path(segments[i], ParseText.DIR_NAME));}- job.addInputPath(new Path(crawlDb, CrawlDb.CURRENT_NAME));- job.addInputPath(new Path(linkDb, LinkDb.CURRENT_NAME));+ FileInputFormat.addInputPath(job, new Path(crawlDb, CrawlDb.CURRENT_NAME));+ FileInputFormat.addInputPath(job, new Path(linkDb, LinkDb.CURRENT_NAME));job.setInputFormat(SequenceFileInputFormat.class);job.setMapperClass(Indexer.class);job.setReducerClass(Indexer.class);- job.setOutputPath(indexDir);+ FileOutputFormat.setOutputPath(job, indexDir);job.setOutputFormat(OutputFormat.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(NutchWritable.class);diff --git a/src/java/org/apache/nutch/parse/Outlink.java b/src/java/org/apache/nutch/parse/Outlink.javaindex 462b8b2e9..744140c0a 100644--- a/src/java/org/apache/nutch/parse/Outlink.java+++ b/src/java/org/apache/nutch/parse/Outlink.java@@ -21,8 +21,6 @@ import java.io.*;import java.net.MalformedURLException;import org.apache.hadoop.io.*;-import org.apache.nutch.net.URLNormalizers;-import org.apache.hadoop.conf.Configuration;/* An outgoing link from a page. */public class Outlink implements Writable {diff --git a/src/java/org/apache/nutch/parse/ParseOutputFormat.java b/src/java/org/apache/nutch/parse/ParseOutputFormat.javaindex 8e440feab..7dd042246 100644--- a/src/java/org/apache/nutch/parse/ParseOutputFormat.java+++ b/src/java/org/apache/nutch/parse/ParseOutputFormat.java@@ -44,7 +44,7 @@ import java.util.Map.Entry;import org.apache.hadoop.util.Progressable;/* Parse content in a segment. */-public class ParseOutputFormat implements OutputFormat {+public class ParseOutputFormat implements OutputFormat<Text, Parse> {private static final Log LOG = LogFactory.getLog(ParseOutputFormat.class);private URLFilters filters;@@ -75,11 +75,12 @@ public class ParseOutputFormat implements OutputFormat {}public void checkOutputSpecs(FileSystem fs, JobConf job) throws IOException {- if (fs.exists(new Path(job.getOutputPath(), CrawlDatum.PARSE_DIR_NAME)))+ Path out = FileOutputFormat.getOutputPath(job);+ if (fs.exists(new Path(out, CrawlDatum.PARSE_DIR_NAME)))throw new IOException("Segment already parsed!");}- public RecordWriter getRecordWriter(FileSystem fs, JobConf job,+ public RecordWriter<Text, Parse> getRecordWriter(FileSystem fs, JobConf job,String name, Progressable progress) throws IOException {this.filters = new URLFilters(job);@@ -90,14 +91,12 @@ public class ParseOutputFormat implements OutputFormat {int maxOutlinksPerPage = job.getInt("db.max.outlinks.per.page", 100);final int maxOutlinks = (maxOutlinksPerPage < 0) ? Integer.MAX_VALUE: maxOutlinksPerPage;- final CompressionType compType = SequenceFile.getCompressionType(job);+ final CompressionType compType = SequenceFileOutputFormat.getOutputCompressionType(job);+ Path out = FileOutputFormat.getOutputPath(job);- Path text =- new Path(new Path(job.getOutputPath(), ParseText.DIR_NAME), name);- Path data =- new Path(new Path(job.getOutputPath(), ParseData.DIR_NAME), name);- Path crawl =- new Path(new Path(job.getOutputPath(), CrawlDatum.PARSE_DIR_NAME), name);+ Path text = new Path(new Path(out, ParseText.DIR_NAME), name);+ Path data = new Path(new Path(out, ParseData.DIR_NAME), name);+ Path crawl = new Path(new Path(out, CrawlDatum.PARSE_DIR_NAME), name);final MapFile.Writer textOut =new MapFile.Writer(job, fs, text.toString(), Text.class, ParseText.class,@@ -111,13 +110,12 @@ public class ParseOutputFormat implements OutputFormat {SequenceFile.createWriter(fs, job, crawl, Text.class, CrawlDatum.class,compType, progress);- return new RecordWriter() {+ return new RecordWriter<Text, Parse>() {- public void write(WritableComparable key, Writable value)+ public void write(Text key, Parse parse)throws IOException {- Parse parse = (Parse)value;String fromUrl = key.toString();String fromHost = null;String toHost = null;diff --git a/src/java/org/apache/nutch/parse/ParseSegment.java b/src/java/org/apache/nutch/parse/ParseSegment.javaindex de2b9eeb5..abdad07b5 100644--- a/src/java/org/apache/nutch/parse/ParseSegment.java+++ b/src/java/org/apache/nutch/parse/ParseSegment.java@@ -38,7 +38,9 @@ import java.util.*;import java.util.Map.Entry;/* Parse content in a segment. */-public class ParseSegment extends Configured implements Tool, Mapper<WritableComparable, Content, Text, ParseImpl>, Reducer<Text, Writable, Text, Writable> {+public class ParseSegment extends Configured implements Tool,+ Mapper<WritableComparable, Content, Text, ParseImpl>,+ Reducer<Text, Writable, Text, Writable> {public static final Log LOG = LogFactory.getLog(Parser.class);@@ -135,13 +137,13 @@ public class ParseSegment extends Configured implements Tool, Mapper<WritableComJobConf job = new NutchJob(getConf());job.setJobName("parse " + segment);- job.setInputPath(new Path(segment, Content.DIR_NAME));+ FileInputFormat.addInputPath(job, new Path(segment, Content.DIR_NAME));job.set(Nutch.SEGMENT_NAME_KEY, segment.getName());job.setInputFormat(SequenceFileInputFormat.class);job.setMapperClass(ParseSegment.class);job.setReducerClass(ParseSegment.class);- job.setOutputPath(segment);+ FileOutputFormat.setOutputPath(job, segment);job.setOutputFormat(ParseOutputFormat.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(ParseImpl.class);diff --git a/src/java/org/apache/nutch/parse/ParseStatus.java b/src/java/org/apache/nutch/parse/ParseStatus.javaindex 1c8c7b49d..d86d95846 100644--- a/src/java/org/apache/nutch/parse/ParseStatus.java+++ b/src/java/org/apache/nutch/parse/ParseStatus.java@@ -24,7 +24,6 @@ package org.apache.nutch.parse;import java.io.DataInput;import java.io.DataOutput;import java.io.IOException;-import java.util.Arrays;import org.apache.hadoop.io.VersionMismatchException;import org.apache.hadoop.io.Writable;diff --git a/src/java/org/apache/nutch/parse/ParserFactory.java b/src/java/org/apache/nutch/parse/ParserFactory.javaindex 3c820f580..ee8975e51 100644--- a/src/java/org/apache/nutch/parse/ParserFactory.java+++ b/src/java/org/apache/nutch/parse/ParserFactory.java@@ -104,7 +104,7 @@ public final class ParserFactory {throws ParserNotFound {List<Parser> parsers = null;- List parserExts = null;+ List<Extension> parserExts = null;ObjectCache objectCache = ObjectCache.get(conf);diff --git a/src/java/org/apache/nutch/searcher/FetchedSegments.java b/src/java/org/apache/nutch/searcher/FetchedSegments.javaindex 8ed1304c0..6c56797bf 100644--- a/src/java/org/apache/nutch/searcher/FetchedSegments.java+++ b/src/java/org/apache/nutch/searcher/FetchedSegments.java@@ -27,6 +27,7 @@ import org.apache.hadoop.io.*;import org.apache.hadoop.fs.*;import org.apache.nutch.protocol.*;import org.apache.nutch.parse.*;+import org.apache.nutch.util.HadoopFSUtil;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.mapred.*;import org.apache.hadoop.mapred.lib.*;@@ -116,7 +117,9 @@ public class FetchedSegments implements HitSummarizer, HitContent {/** Construct given a directory containing fetcher output. */public FetchedSegments(FileSystem fs, String segmentsDir, Configuration conf) throws IOException {- Path[] segmentDirs = fs.listPaths(new Path(segmentsDir));+ FileStatus[] fstats = fs.listStatus(new Path(segmentsDir),+ HadoopFSUtil.getPassDirectoriesFilter(fs));+ Path[] segmentDirs = HadoopFSUtil.getPaths(fstats);this.summarizer = new SummarizerFactory(conf).getSummarizer();if (segmentDirs != null) {diff --git a/src/java/org/apache/nutch/searcher/NutchBean.java b/src/java/org/apache/nutch/searcher/NutchBean.javaindex 68d0e5e56..c531a5309 100644--- a/src/java/org/apache/nutch/searcher/NutchBean.java+++ b/src/java/org/apache/nutch/searcher/NutchBean.java@@ -122,7 +122,9 @@ public class NutchBean}Vector vDirs=new Vector();- Path [] directories = fs.listPaths(indexesDir, HadoopFSUtil.getPassDirectoriesFilter(fs));+ FileStatus[] fstats = fs.listStatus(indexesDir,+ HadoopFSUtil.getPassDirectoriesFilter(fs));+ Path [] directories = HadoopFSUtil.getPaths(fstats);for(int i = 0; i < directories.length; i++) {Path indexdone = new Path(directories[i], Indexer.DONE_NAME);if(fs.isFile(indexdone)) {diff --git a/src/java/org/apache/nutch/segment/SegmentMerger.java b/src/java/org/apache/nutch/segment/SegmentMerger.javaindex 1c3a218b0..4d1683358 100644--- a/src/java/org/apache/nutch/segment/SegmentMerger.java+++ b/src/java/org/apache/nutch/segment/SegmentMerger.java@@ -27,6 +27,7 @@ import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.conf.Configured;+import org.apache.hadoop.fs.FileStatus;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.MapFile;@@ -36,6 +37,8 @@ import org.apache.hadoop.io.UTF8;import org.apache.hadoop.io.Writable;import org.apache.hadoop.io.WritableComparable;import org.apache.hadoop.io.SequenceFile.CompressionType;+import org.apache.hadoop.mapred.FileInputFormat;+import org.apache.hadoop.mapred.FileOutputFormat;import org.apache.hadoop.mapred.FileSplit;import org.apache.hadoop.mapred.InputSplit;import org.apache.hadoop.mapred.JobClient;@@ -48,6 +51,7 @@ import org.apache.hadoop.mapred.RecordWriter;import org.apache.hadoop.mapred.Reducer;import org.apache.hadoop.mapred.Reporter;import org.apache.hadoop.mapred.SequenceFileInputFormat;+import org.apache.hadoop.mapred.SequenceFileOutputFormat;import org.apache.hadoop.mapred.SequenceFileRecordReader;import org.apache.hadoop.util.Progressable;import org.apache.nutch.crawl.CrawlDatum;@@ -110,7 +114,9 @@ import org.apache.nutch.util.NutchJob;** @author Andrzej Bialecki*/-public class SegmentMerger extends Configured implements Mapper, Reducer {+public class SegmentMerger extends Configured implements+ Mapper<Text, MetaWrapper, Text, MetaWrapper>,+ Reducer<Text, MetaWrapper, Text, MetaWrapper> {private static final Log LOG = LogFactory.getLog(SegmentMerger.class);private static final String SEGMENT_PART_KEY = "part";@@ -125,10 +131,11 @@ public class SegmentMerger extends Configured implements Mapper, Reducer {* Wraps inputs in an {@link MetaWrapper}, to permit merging different* types in reduce and use additional metadata.*/- public static class ObjectInputFormat extends SequenceFileInputFormat {+ public static class ObjectInputFormat extends+ SequenceFileInputFormat<Text, MetaWrapper> {@Override- public RecordReader getRecordReader(InputSplit split,+ public RecordReader<Text, MetaWrapper> getRecordReader(InputSplit split,JobConf job, Reporter reporter) {reporter.setStatus(split.toString());@@ -174,12 +181,12 @@ public class SegmentMerger extends Configured implements Mapper, Reducer {}}- public static class SegmentOutputFormat extends OutputFormatBase {+ public static class SegmentOutputFormat extends FileOutputFormat<Text, MetaWrapper> {private static final String DEFAULT_SLICE = "default";@Override- public RecordWriter getRecordWriter(final FileSystem fs, final JobConf job, final String name, final Progressable progress) throws IOException {- return new RecordWriter() {+ public RecordWriter<Text, MetaWrapper> getRecordWriter(final FileSystem fs, final JobConf job, final String name, final Progressable progress) throws IOException {+ return new RecordWriter<Text, MetaWrapper>() {MapFile.Writer c_out = null;MapFile.Writer f_out = null;MapFile.Writer pd_out = null;@@ -189,9 +196,8 @@ public class SegmentMerger extends Configured implements Mapper, Reducer {HashMap sliceWriters = new HashMap();String segmentName = job.get("segment.merger.segmentName");- public void write(WritableComparable key, Writable value) throws IOException {+ public void write(Text key, MetaWrapper wrapper) throws IOException {// unwrap- MetaWrapper wrapper = (MetaWrapper)value;SegmentPart sp = SegmentPart.parse(wrapper.getMeta(SEGMENT_PART_KEY));Writable o = (Writable)wrapper.get();String slice = wrapper.getMeta(SEGMENT_SLICE_KEY);@@ -232,14 +238,15 @@ public class SegmentMerger extends Configured implements Mapper, Reducer {SequenceFile.Writer res = (SequenceFile.Writer)sliceWriters.get(slice + dirName);if (res != null) return res;Path wname;+ Path out = FileOutputFormat.getOutputPath(job);if (slice == DEFAULT_SLICE) {- wname = new Path(new Path(new Path(job.getOutputPath(), segmentName), dirName), name);+ wname = new Path(new Path(new Path(out, segmentName), dirName), name);} else {- wname = new Path(new Path(new Path(job.getOutputPath(), segmentName + "-" + slice), dirName), name);+ wname = new Path(new Path(new Path(out, segmentName + "-" + slice), dirName), name);}res = SequenceFile.createWriter(fs, job, wname, Text.class,- CrawlDatum.class,- SequenceFile.getCompressionType(job), progress);+ CrawlDatum.class,+ SequenceFileOutputFormat.getOutputCompressionType(job), progress);sliceWriters.put(slice + dirName, res);return res;}@@ -250,12 +257,14 @@ public class SegmentMerger extends Configured implements Mapper, Reducer {MapFile.Writer res = (MapFile.Writer)sliceWriters.get(slice + dirName);if (res != null) return res;Path wname;+ Path out = FileOutputFormat.getOutputPath(job);if (slice == DEFAULT_SLICE) {- wname = new Path(new Path(new Path(job.getOutputPath(), segmentName), dirName), name);+ wname = new Path(new Path(new Path(out, segmentName), dirName), name);} else {- wname = new Path(new Path(new Path(job.getOutputPath(), segmentName + "-" + slice), dirName), name);+ wname = new Path(new Path(new Path(out, segmentName + "-" + slice), dirName), name);}- CompressionType compType = SequenceFile.getCompressionType(job);+ CompressionType compType =+ SequenceFileOutputFormat.getOutputCompressionType(job);if (clazz.isAssignableFrom(ParseText.class)) {compType = CompressionType.RECORD;}@@ -312,7 +321,8 @@ public class SegmentMerger extends Configured implements Mapper, Reducer {private Text newKey = new Text();- public void map(WritableComparable key, Writable value, OutputCollector output, Reporter reporter) throws IOException {+ public void map(Text key, MetaWrapper value,+ OutputCollector<Text, MetaWrapper> output, Reporter reporter) throws IOException {String url = key.toString();if (normalizers != null) {try {@@ -342,7 +352,8 @@ public class SegmentMerger extends Configured implements Mapper, Reducer {* important that segments be named in an increasing lexicographic order as* their creation time increases.*/- public void reduce(WritableComparable key, Iterator values, OutputCollector output, Reporter reporter) throws IOException {+ public void reduce(Text key, Iterator<MetaWrapper> values,+ OutputCollector<Text, MetaWrapper> output, Reporter reporter) throws IOException {CrawlDatum lastG = null;CrawlDatum lastF = null;CrawlDatum lastSig = null;@@ -358,7 +369,7 @@ public class SegmentMerger extends Configured implements Mapper, Reducer {TreeMap<String, ArrayList<CrawlDatum>> linked =new TreeMap<String, ArrayList<CrawlDatum>>();while (values.hasNext()) {- MetaWrapper wrapper = (MetaWrapper)values.next();+ MetaWrapper wrapper = values.next();Object o = wrapper.get();String spString = wrapper.getMeta(SEGMENT_PART_KEY);if (spString == null) {@@ -568,33 +579,33 @@ public class SegmentMerger extends Configured implements Mapper, Reducer {if (segs[i] == null) continue;if (g) {Path gDir = new Path(segs[i], CrawlDatum.GENERATE_DIR_NAME);- job.addInputPath(gDir);+ FileInputFormat.addInputPath(job, gDir);}if (c) {Path cDir = new Path(segs[i], Content.DIR_NAME);- job.addInputPath(cDir);+ FileInputFormat.addInputPath(job, cDir);}if (f) {Path fDir = new Path(segs[i], CrawlDatum.FETCH_DIR_NAME);- job.addInputPath(fDir);+ FileInputFormat.addInputPath(job, fDir);}if (p) {Path pDir = new Path(segs[i], CrawlDatum.PARSE_DIR_NAME);- job.addInputPath(pDir);+ FileInputFormat.addInputPath(job, pDir);}if (pd) {Path pdDir = new Path(segs[i], ParseData.DIR_NAME);- job.addInputPath(pdDir);+ FileInputFormat.addInputPath(job, pdDir);}if (pt) {Path ptDir = new Path(segs[i], ParseText.DIR_NAME);- job.addInputPath(ptDir);+ FileInputFormat.addInputPath(job, ptDir);}}job.setInputFormat(ObjectInputFormat.class);job.setMapperClass(SegmentMerger.class);job.setReducerClass(SegmentMerger.class);- job.setOutputPath(out);+ FileOutputFormat.setOutputPath(job, out);job.setOutputKeyClass(Text.class);job.setOutputValueClass(MetaWrapper.class);job.setOutputFormat(SegmentOutputFormat.class);@@ -626,7 +637,9 @@ public class SegmentMerger extends Configured implements Mapper, Reducer {boolean normalize = false;for (int i = 1; i < args.length; i++) {if (args[i].equals("-dir")) {- Path[] files = fs.listPaths(new Path(args[++i]), HadoopFSUtil.getPassDirectoriesFilter(fs));+ FileStatus[] fstats = fs.listStatus(new Path(args[++i]),+ HadoopFSUtil.getPassDirectoriesFilter(fs));+ Path[] files = HadoopFSUtil.getPaths(fstats);for (int j = 0; j < files.length; j++)segs.add(files[j]);} else if (args[i].equals("-filter")) {diff --git a/src/java/org/apache/nutch/segment/SegmentReader.java b/src/java/org/apache/nutch/segment/SegmentReader.javaindex dc22bd0e6..4d93305da 100644--- a/src/java/org/apache/nutch/segment/SegmentReader.java+++ b/src/java/org/apache/nutch/segment/SegmentReader.java@@ -38,6 +38,7 @@ import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.conf.Configured;+import org.apache.hadoop.fs.FileStatus;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.MapFile;@@ -46,6 +47,7 @@ import org.apache.hadoop.io.Text;import org.apache.hadoop.io.UTF8;import org.apache.hadoop.io.Writable;import org.apache.hadoop.io.WritableComparable;+import org.apache.hadoop.mapred.FileOutputFormat;import org.apache.hadoop.mapred.JobClient;import org.apache.hadoop.mapred.JobConf;import org.apache.hadoop.mapred.MapFileOutputFormat;@@ -69,7 +71,8 @@ import org.apache.nutch.util.NutchConfiguration;import org.apache.nutch.util.NutchJob;/** Dump the content of a segment. */-public class SegmentReader extends Configured implements Reducer {+public class SegmentReader extends Configured implements+ Reducer<Text, NutchWritable, Text, Text> {public static final Log LOG = LogFactory.getLog(SegmentReader.class);@@ -78,31 +81,36 @@ public class SegmentReader extends Configured implements Reducer {private boolean co, fe, ge, pa, pd, pt;private FileSystem fs;- public static class InputCompatMapper extends MapReduceBase implements Mapper {+ public static class InputCompatMapper extends MapReduceBase implements+ Mapper<WritableComparable, Writable, Text, NutchWritable> {private Text newKey = new Text();- public void map(WritableComparable key, Writable value, OutputCollector collector, Reporter reporter) throws IOException {+ public void map(WritableComparable key, Writable value,+ OutputCollector<Text, NutchWritable> collector, Reporter reporter) throws IOException {// convert on the fly from old formats with UTF8 keysif (key instanceof UTF8) {newKey.set(key.toString());key = newKey;}- collector.collect(key, new NutchWritable(value));+ collector.collect((Text)key, new NutchWritable(value));}}/** Implements a text output format */- public static class TextOutputFormat extends org.apache.hadoop.mapred.OutputFormatBase {- public RecordWriter getRecordWriter(final FileSystem fs, JobConf job, String name, final Progressable progress) throws IOException {+ public static class TextOutputFormat extends+ FileOutputFormat<WritableComparable, Writable> {+ public RecordWriter<WritableComparable, Writable> getRecordWriter(+ final FileSystem fs, JobConf job,+ String name, final Progressable progress) throws IOException {- final Path segmentDumpFile = new Path(job.getOutputPath(), name);+ final Path segmentDumpFile = new Path(FileOutputFormat.getOutputPath(job), name);// Get the old copy out of the way- if (fs.exists(segmentDumpFile)) fs.delete(segmentDumpFile);+ if (fs.exists(segmentDumpFile)) fs.delete(segmentDumpFile, true);final PrintStream printStream = new PrintStream(fs.create(segmentDumpFile));- return new RecordWriter() {+ return new RecordWriter<WritableComparable, Writable>() {public synchronized void write(WritableComparable key, Writable value) throws IOException {printStream.println(value);}@@ -162,14 +170,15 @@ public class SegmentReader extends Configured implements Reducer {public void close() {}- public void reduce(WritableComparable key, Iterator values, OutputCollector output, Reporter reporter)+ public void reduce(Text key, Iterator<NutchWritable> values,+ OutputCollector<Text, Text> output, Reporter reporter)throws IOException {StringBuffer dump = new StringBuffer();dump.append("\nRecno:: ").append(recNo++).append("\n");dump.append("URL:: " + key.toString() + "\n");while (values.hasNext()) {- Writable value = ((NutchWritable) values.next()).get(); // unwrap+ Writable value = values.next().get(); // unwrapif (value instanceof CrawlDatum) {dump.append("\nCrawlDatum::\n").append(((CrawlDatum) value).toString());} else if (value instanceof Content) {@@ -219,8 +228,9 @@ public class SegmentReader extends Configured implements Reducer {Path dumpFile = new Path(output, job.get("segment.dump.dir", "dump"));// remove the old file- fs.delete(dumpFile);- Path[] files = fs.listPaths(tempDir, HadoopFSUtil.getPassAllFilter());+ fs.delete(dumpFile, true);+ FileStatus[] fstats = fs.listStatus(tempDir, HadoopFSUtil.getPassAllFilter());+ Path[] files = HadoopFSUtil.getPaths(fstats);PrintWriter writer = null;int currentRecordNumber = 0;@@ -559,7 +569,8 @@ public class SegmentReader extends Configured implements Reducer {if (args[i] == null) continue;if (args[i].equals("-dir")) {Path dir = new Path(args[++i]);- Path[] files = fs.listPaths(dir, HadoopFSUtil.getPassDirectoriesFilter(fs));+ FileStatus[] fstats = fs.listStatus(dir, HadoopFSUtil.getPassDirectoriesFilter(fs));+ Path[] files = HadoopFSUtil.getPaths(fstats);if (files != null && files.length > 0) {dirs.addAll(Arrays.asList(files));}diff --git a/src/java/org/apache/nutch/tools/FreeGenerator.java b/src/java/org/apache/nutch/tools/FreeGenerator.javaindex d0abba366..dfca7564d 100644--- a/src/java/org/apache/nutch/tools/FreeGenerator.java+++ b/src/java/org/apache/nutch/tools/FreeGenerator.java@@ -28,6 +28,8 @@ import org.apache.hadoop.fs.Path;import org.apache.hadoop.conf.Configured;import org.apache.hadoop.io.Text;import org.apache.hadoop.io.WritableComparable;+import org.apache.hadoop.mapred.FileInputFormat;+import org.apache.hadoop.mapred.FileOutputFormat;import org.apache.hadoop.mapred.JobClient;import org.apache.hadoop.mapred.JobConf;import org.apache.hadoop.mapred.MapReduceBase;@@ -158,7 +160,7 @@ public class FreeGenerator extends Configured implements Tool {JobConf job = new NutchJob(getConf());job.setBoolean(FILTER_KEY, filter);job.setBoolean(NORMALIZE_KEY, normalize);- job.addInputPath(new Path(args[0]));+ FileInputFormat.addInputPath(job, new Path(args[0]));job.setInputFormat(TextInputFormat.class);job.setMapperClass(FG.class);job.setMapOutputKeyClass(Text.class);@@ -171,7 +173,8 @@ public class FreeGenerator extends Configured implements Tool {job.setOutputKeyClass(Text.class);job.setOutputValueClass(CrawlDatum.class);job.setOutputKeyComparatorClass(Generator.HashComparator.class);- job.setOutputPath(new Path(args[1], new Path(segName, CrawlDatum.GENERATE_DIR_NAME)));+ FileOutputFormat.setOutputPath(job, new Path(args[1],+ new Path(segName, CrawlDatum.GENERATE_DIR_NAME)));try {JobClient.runJob(job);return 0;diff --git a/src/java/org/apache/nutch/tools/arc/ArcInputFormat.java b/src/java/org/apache/nutch/tools/arc/ArcInputFormat.javaindex a679443df..9e60c0611 100644--- a/src/java/org/apache/nutch/tools/arc/ArcInputFormat.java+++ b/src/java/org/apache/nutch/tools/arc/ArcInputFormat.java@@ -18,6 +18,8 @@ package org.apache.nutch.tools.arc;import java.io.IOException;+import org.apache.hadoop.io.BytesWritable;+import org.apache.hadoop.io.Text;import org.apache.hadoop.mapred.FileInputFormat;import org.apache.hadoop.mapred.FileSplit;import org.apache.hadoop.mapred.InputSplit;@@ -29,7 +31,7 @@ import org.apache.hadoop.mapred.Reporter;* A input format the reads arc files.*/public class ArcInputFormat- extends FileInputFormat {+ extends FileInputFormat<Text, BytesWritable> {/*** Returns the <code>RecordReader</code> for reading the arc file.@@ -38,8 +40,8 @@ public class ArcInputFormat* @param job The job configuration.* @param reporter The progress reporter.*/- public RecordReader getRecordReader(InputSplit split, JobConf job,- Reporter reporter)+ public RecordReader<Text, BytesWritable> getRecordReader(InputSplit split,+ JobConf job, Reporter reporter)throws IOException {reporter.setStatus(split.toString());return new ArcRecordReader(job, (FileSplit)split);diff --git a/src/java/org/apache/nutch/tools/arc/ArcRecordReader.java b/src/java/org/apache/nutch/tools/arc/ArcRecordReader.javaindex c3432103d..49d661c49 100644--- a/src/java/org/apache/nutch/tools/arc/ArcRecordReader.java+++ b/src/java/org/apache/nutch/tools/arc/ArcRecordReader.java@@ -28,8 +28,6 @@ import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.BytesWritable;import org.apache.hadoop.io.Text;-import org.apache.hadoop.io.Writable;-import org.apache.hadoop.io.WritableComparable;import org.apache.hadoop.mapred.FileSplit;import org.apache.hadoop.mapred.RecordReader;import org.apache.hadoop.util.ReflectionUtils;@@ -50,7 +48,7 @@ import org.apache.hadoop.util.StringUtils;* @see http://www.grub.org/*/public class ArcRecordReader- implements RecordReader {+ implements RecordReader<Text, BytesWritable> {public static final Log LOG = LogFactory.getLog(ArcRecordReader.class);@@ -123,15 +121,15 @@ public class ArcRecordReader/*** Creates a new instance of the <code>Text</code> object for the key.*/- public WritableComparable createKey() {- return (WritableComparable)ReflectionUtils.newInstance(Text.class, conf);+ public Text createKey() {+ return (Text)ReflectionUtils.newInstance(Text.class, conf);}/*** Creates a new instance of the <code>BytesWritable</code> object for the key*/- public Writable createValue() {- return (Writable)ReflectionUtils.newInstance(BytesWritable.class, conf);+ public BytesWritable createValue() {+ return (BytesWritable)ReflectionUtils.newInstance(BytesWritable.class, conf);}/**@@ -175,7 +173,7 @@ public class ArcRecordReader** @throws IOException If an error occurs while reading the record value.*/- public boolean next(WritableComparable key, Writable value)+ public boolean next(Text key, BytesWritable value)throws IOException {try {diff --git a/src/java/org/apache/nutch/tools/arc/ArcSegmentCreator.java b/src/java/org/apache/nutch/tools/arc/ArcSegmentCreator.javaindex e73cecc4d..7506b7472 100644--- a/src/java/org/apache/nutch/tools/arc/ArcSegmentCreator.java+++ b/src/java/org/apache/nutch/tools/arc/ArcSegmentCreator.java@@ -28,6 +28,8 @@ import org.apache.hadoop.conf.Configured;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.BytesWritable;import org.apache.hadoop.io.Text;+import org.apache.hadoop.mapred.FileInputFormat;+import org.apache.hadoop.mapred.FileOutputFormat;import org.apache.hadoop.mapred.JobClient;import org.apache.hadoop.mapred.JobConf;import org.apache.hadoop.mapred.Mapper;@@ -353,10 +355,10 @@ public class ArcSegmentCreatorjob.setJobName("ArcSegmentCreator " + arcFiles);String segName = generateSegmentName();job.set(Nutch.SEGMENT_NAME_KEY, segName);- job.setInputPath(arcFiles);+ FileInputFormat.addInputPath(job, arcFiles);job.setInputFormat(ArcInputFormat.class);job.setMapperClass(ArcSegmentCreator.class);- job.setOutputPath(new Path(segmentsOutDir, segName));+ FileOutputFormat.setOutputPath(job, new Path(segmentsOutDir, segName));job.setOutputFormat(FetcherOutputFormat.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(NutchWritable.class);diff --git a/src/java/org/apache/nutch/tools/compat/CrawlDbConverter.java b/src/java/org/apache/nutch/tools/compat/CrawlDbConverter.javaindex 8a14c168e..08fdc5df5 100644--- a/src/java/org/apache/nutch/tools/compat/CrawlDbConverter.java+++ b/src/java/org/apache/nutch/tools/compat/CrawlDbConverter.java@@ -23,12 +23,15 @@ import java.util.Random;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;+import org.apache.hadoop.conf.Configured;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.Text;import org.apache.hadoop.io.UTF8;import org.apache.hadoop.io.Writable;import org.apache.hadoop.io.WritableComparable;+import org.apache.hadoop.mapred.FileInputFormat;+import org.apache.hadoop.mapred.FileOutputFormat;import org.apache.hadoop.mapred.JobClient;import org.apache.hadoop.mapred.JobConf;import org.apache.hadoop.mapred.MapFileOutputFormat;@@ -37,7 +40,8 @@ import org.apache.hadoop.mapred.OutputCollector;import org.apache.hadoop.mapred.Reporter;import org.apache.hadoop.mapred.SequenceFileInputFormat;import org.apache.hadoop.util.StringUtils;-import org.apache.hadoop.util.ToolBase;+import org.apache.hadoop.util.Tool;+import org.apache.hadoop.util.ToolRunner;import org.apache.nutch.crawl.CrawlDatum;import org.apache.nutch.crawl.CrawlDb;import org.apache.nutch.crawl.MapWritable;@@ -52,7 +56,8 @@ import org.apache.nutch.util.NutchJob;** @author Andrzej Bialecki*/-public class CrawlDbConverter extends ToolBase implements Mapper {+public class CrawlDbConverter extends Configured implements Tool,+ Mapper<WritableComparable, CrawlDatum, Text, CrawlDatum> {private static final Log LOG = LogFactory.getLog(CrawlDbConverter.class);private static final String CONVERT_META_KEY = "db.converter.with.metadata";@@ -66,7 +71,8 @@ public class CrawlDbConverter extends ToolBase implements Mapper {newKey = new Text();}- public void map(WritableComparable key, Writable value, OutputCollector output,+ public void map(WritableComparable key, CrawlDatum value,+ OutputCollector<Text, CrawlDatum> output,Reporter reporter) throws IOException {newKey.set(key.toString());if (withMetadata) {@@ -97,7 +103,8 @@ public class CrawlDbConverter extends ToolBase implements Mapper {* @param args*/public static void main(String[] args) throws Exception {- int res = new CrawlDbConverter().doMain(NutchConfiguration.create(), args);+ int res = ToolRunner.run(NutchConfiguration.create(), new CrawlDbConverter(), args);+ System.exit(res);}public int run(String[] args) throws Exception {@@ -123,13 +130,13 @@ public class CrawlDbConverter extends ToolBase implements Mapper {withMetadata = true;job.setBoolean(CONVERT_META_KEY, withMetadata);- job.setInputPath(oldDb);+ FileInputFormat.addInputPath(job, oldDb);job.setInputFormat(SequenceFileInputFormat.class);job.setMapperClass(CrawlDbConverter.class);job.setOutputFormat(MapFileOutputFormat.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(CrawlDatum.class);- job.setOutputPath(newDb);+ FileOutputFormat.setOutputPath(job, newDb);try {JobClient.runJob(job);CrawlDb.install(job, new Path(args[1]));diff --git a/src/java/org/apache/nutch/util/LockUtil.java b/src/java/org/apache/nutch/util/LockUtil.javaindex 62aa1d850..47ed0191a 100644--- a/src/java/org/apache/nutch/util/LockUtil.java+++ b/src/java/org/apache/nutch/util/LockUtil.java@@ -65,6 +65,6 @@ public class LockUtil {if (!fs.exists(lockFile)) return false;if (fs.getFileStatus(lockFile).isDir())throw new IOException("lock file " + lockFile + " exists but is a directory!");- return fs.delete(lockFile);+ return fs.delete(lockFile, false);}}diff --git a/src/test/org/apache/nutch/crawl/TestGenerator.java b/src/test/org/apache/nutch/crawl/TestGenerator.javaindex 0f6b0d6cb..947421764 100644--- a/src/test/org/apache/nutch/crawl/TestGenerator.java+++ b/src/test/org/apache/nutch/crawl/TestGenerator.java@@ -53,7 +53,7 @@ public class TestGenerator extends TestCase {protected void setUp() throws Exception {conf = CrawlDBTestUtil.createConfiguration();fs = FileSystem.get(conf);- fs.delete(testdir);+ fs.delete(testdir, true);}protected void tearDown() {@@ -62,7 +62,7 @@ public class TestGenerator extends TestCase {private void delete(Path p) {try {- fs.delete(p);+ fs.delete(p, true);} catch (IOException e) {}}diff --git a/src/test/org/apache/nutch/crawl/TestInjector.java b/src/test/org/apache/nutch/crawl/TestInjector.javaindex 90a7ab67e..f1734221e 100644--- a/src/test/org/apache/nutch/crawl/TestInjector.java+++ b/src/test/org/apache/nutch/crawl/TestInjector.java@@ -52,12 +52,12 @@ public class TestInjector extends TestCase {urlPath=new Path(testdir,"urls");crawldbPath=new Path(testdir,"crawldb");fs=FileSystem.get(conf);- if (fs.exists(urlPath)) fs.delete(urlPath);- if (fs.exists(crawldbPath)) fs.delete(crawldbPath);+ if (fs.exists(urlPath)) fs.delete(urlPath, false);+ if (fs.exists(crawldbPath)) fs.delete(crawldbPath, true);}protected void tearDown() throws IOException{- fs.delete(testdir);+ fs.delete(testdir, true);}public void testInject() throws IOException {diff --git a/src/test/org/apache/nutch/crawl/TestLinkDbMerger.java b/src/test/org/apache/nutch/crawl/TestLinkDbMerger.javaindex 74f4e8422..a8e1b49d2 100644--- a/src/test/org/apache/nutch/crawl/TestLinkDbMerger.java+++ b/src/test/org/apache/nutch/crawl/TestLinkDbMerger.java@@ -95,7 +95,7 @@ public class TestLinkDbMerger extends TestCase {public void tearDown() {try {if (fs.exists(testDir))- fs.delete(testDir);+ fs.delete(testDir, true);} catch (Exception e) { }try {reader.close();@@ -136,7 +136,7 @@ public class TestLinkDbMerger extends TestCase {}}reader.close();- fs.delete(testDir);+ fs.delete(testDir, true);}private void createLinkDb(Configuration config, FileSystem fs, Path linkdb, TreeMap init) throws Exception {diff --git a/src/test/org/apache/nutch/crawl/TestMapWritable.java b/src/test/org/apache/nutch/crawl/TestMapWritable.javaindex 5c400796d..0af90ad22 100644--- a/src/test/org/apache/nutch/crawl/TestMapWritable.java+++ b/src/test/org/apache/nutch/crawl/TestMapWritable.java@@ -105,7 +105,7 @@ public class TestMapWritable extends TestCase {public void testPerformance() throws Exception {FileSystem fs = FileSystem.get(configuration);Path file = new Path(System.getProperty("java.io.tmpdir"), "mapTestFile");- fs.delete(file);+ fs.delete(file, false);org.apache.hadoop.io.SequenceFile.Writer writer = SequenceFile.createWriter(fs, configuration, file, IntWritable.class, MapWritable.class);// write map@@ -164,7 +164,7 @@ public class TestMapWritable extends TestCase {}needed = System.currentTimeMillis() - start;System.out.println("needed time for reading Text: " + needed);- fs.delete(file);+ fs.delete(file, false);}/** Utility method for testing writables, from hadoop code */diff --git a/src/test/org/apache/nutch/fetcher/TestFetcher.java b/src/test/org/apache/nutch/fetcher/TestFetcher.javaindex c9345f508..977a592aa 100644--- a/src/test/org/apache/nutch/fetcher/TestFetcher.java+++ b/src/test/org/apache/nutch/fetcher/TestFetcher.java@@ -59,7 +59,7 @@ public class TestFetcher extends TestCase {protected void setUp() throws Exception{conf=CrawlDBTestUtil.createConfiguration();fs=FileSystem.get(conf);- fs.delete(testdir);+ fs.delete(testdir, true);urlPath=new Path(testdir,"urls");crawldbPath=new Path(testdir,"crawldb");segmentsPath=new Path(testdir,"segments");@@ -69,7 +69,7 @@ public class TestFetcher extends TestCase {protected void tearDown() throws InterruptedException, IOException{server.stop();- fs.delete(testdir);+ fs.delete(testdir, true);}public void testFetch() throws IOException {diff --git a/src/test/org/apache/nutch/indexer/TestDeleteDuplicates.java b/src/test/org/apache/nutch/indexer/TestDeleteDuplicates.javaindex 22edf1e95..94e7485de 100644--- a/src/test/org/apache/nutch/indexer/TestDeleteDuplicates.java+++ b/src/test/org/apache/nutch/indexer/TestDeleteDuplicates.java@@ -110,7 +110,7 @@ public class TestDeleteDuplicates extends TestCase {}public void tearDown() throws Exception {- fs.delete(root);+ fs.delete(root, true);}private void hashDuplicatesHelper(Path index, String url) throws Exception {diff --git a/src/test/org/apache/nutch/searcher/TestDistributedSearch.java b/src/test/org/apache/nutch/searcher/TestDistributedSearch.javaindex 150bf8a75..b7cb93451 100644--- a/src/test/org/apache/nutch/searcher/TestDistributedSearch.java+++ b/src/test/org/apache/nutch/searcher/TestDistributedSearch.java@@ -139,6 +139,6 @@ public class TestDistributedSearchserver2.stop();}- fs.delete(testServersPath);+ fs.delete(testServersPath, true);}}