Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Fixes for NUTCH-1480: Changes: - Logs for IndexerOutputFormat class to show the description of writers on the terminal. - IndexWriters instance, describe() method call and commit() call, moved from IndexingJob to IndexerOutputFormat. - The key of CACHE on ObjectCache.java:32 is now the UUID.

r0ann3l7e9d1df08817
diff --git a/conf/log4j.properties b/conf/log4j.properties
index e9e5e7f9f..e8bf5fad0 100644
--- a/conf/log4j.properties
+++ b/conf/log4j.properties
@@ -44,6 +44,7 @@ log4j.logger.org.apache.nutch.hostdb.UpdateHostDb=INFO,cmdstdout
log4j.logger.org.apache.nutch.hostdb.ReadHostDb=INFO,cmdstdout
log4j.logger.org.apache.nutch.indexer.IndexingFiltersChecker=INFO,cmdstdout
log4j.logger.org.apache.nutch.indexer.IndexingJob=INFO,cmdstdout
+log4j.logger.org.apache.nutch.indexer.IndexerOutputFormat=INFO,cmdstdout
log4j.logger.org.apache.nutch.indexwriter.solr.SolrIndexWriter=INFO,cmdstdout
log4j.logger.org.apache.nutch.indexwriter.solr.SolrUtils=INFO,cmdstdout
log4j.logger.org.apache.nutch.parse.ParserChecker=INFO,cmdstdout
diff --git a/src/java/org/apache/nutch/indexer/IndexerMapReduce.java b/src/java/org/apache/nutch/indexer/IndexerMapReduce.java
index cb6e1215e..8cdd78bb4 100644
--- a/src/java/org/apache/nutch/indexer/IndexerMapReduce.java
+++ b/src/java/org/apache/nutch/indexer/IndexerMapReduce.java
@@ -63,6 +63,7 @@ public class IndexerMapReduce extends Configured implements
public static final String INDEXER_PARAMS = "indexer.additional.params";
public static final String INDEXER_DELETE = "indexer.delete";
+ public static final String INDEXER_NO_COMMIT = "indexer.nocommit";
public static final String INDEXER_DELETE_ROBOTS_NOINDEX = "indexer.delete.robots.noindex";
public static final String INDEXER_DELETE_SKIPPED = "indexer.delete.skipped.by.indexingfilter";
public static final String INDEXER_SKIP_NOTMODIFIED = "indexer.skip.notmodified";
diff --git a/src/java/org/apache/nutch/indexer/IndexerOutputFormat.java b/src/java/org/apache/nutch/indexer/IndexerOutputFormat.java
index baa9ce619..892c1073e 100644
--- a/src/java/org/apache/nutch/indexer/IndexerOutputFormat.java
+++ b/src/java/org/apache/nutch/indexer/IndexerOutputFormat.java
@@ -17,6 +17,7 @@
package org.apache.nutch.indexer;
import java.io.IOException;
+import java.lang.invoke.MethodHandles;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.io.Text;
@@ -25,22 +26,32 @@ import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.RecordWriter;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.util.Progressable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class IndexerOutputFormat extends
FileOutputFormat<Text, NutchIndexAction> {
+ private static final Logger LOG = LoggerFactory
+ .getLogger(MethodHandles.lookup().lookupClass());
+
@Override
public RecordWriter<Text, NutchIndexAction> getRecordWriter(
FileSystem ignored, JobConf job, String name, Progressable progress)
throws IOException {
final IndexWriters writers = new IndexWriters(job);
+ LOG.info(writers.describe());
writers.open(job, name);
return new RecordWriter<Text, NutchIndexAction>() {
public void close(Reporter reporter) throws IOException {
+ boolean noCommit = job.getBoolean(IndexerMapReduce.INDEXER_NO_COMMIT, false);
+ if (!noCommit) {
+ writers.commit();
+ }
writers.close();
}
diff --git a/src/java/org/apache/nutch/indexer/IndexingJob.java b/src/java/org/apache/nutch/indexer/IndexingJob.java
index 2c861abed..2757c4b17 100644
--- a/src/java/org/apache/nutch/indexer/IndexingJob.java
+++ b/src/java/org/apache/nutch/indexer/IndexingJob.java
@@ -102,7 +102,6 @@ public class IndexingJob extends NutchTool implements Tool {
boolean filter, boolean normalize, boolean addBinaryContent,
boolean base64) throws IOException {
-
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long start = System.currentTimeMillis();
LOG.info("Indexer: starting at {}", sdf.format(start));
@@ -119,9 +118,7 @@ public class IndexingJob extends NutchTool implements Tool {
} else {
LOG.info("Indexer: adding binary content");
}
- }
- IndexWriters writers = new IndexWriters(getConf());
- LOG.info(writers.describe());
+ }
IndexerMapReduce.initMRJob(crawlDb, linkDb, segments, job, addBinaryContent);
@@ -132,6 +129,7 @@ public class IndexingJob extends NutchTool implements Tool {
job.setBoolean(IndexerMapReduce.URL_FILTERING, filter);
job.setBoolean(IndexerMapReduce.URL_NORMALIZING, normalize);
job.setBoolean(IndexerMapReduce.INDEXER_BINARY_AS_BASE64, base64);
+ job.setBoolean(IndexerMapReduce.INDEXER_NO_COMMIT, noCommit);
if (params != null) {
job.set(IndexerMapReduce.INDEXER_PARAMS, params);
@@ -145,11 +143,6 @@ public class IndexingJob extends NutchTool implements Tool {
FileOutputFormat.setOutputPath(job, tmp);
try {
RunningJob indexJob = JobClient.runJob(job);
- // do the commits once and for all the reducers in one go
- if (!noCommit) {
- writers.open(job, "commit");
- writers.commit();
- }
LOG.info("Indexer: number of documents indexed, deleted, or skipped:");
for (Counter counter : indexJob.getCounters().getGroup("IndexerStatus")) {
LOG.info("Indexer: {} {}",
diff --git a/src/java/org/apache/nutch/util/ObjectCache.java b/src/java/org/apache/nutch/util/ObjectCache.java
index 4ed3fd0b9..4e93d9d5f 100644
--- a/src/java/org/apache/nutch/util/ObjectCache.java
+++ b/src/java/org/apache/nutch/util/ObjectCache.java
@@ -29,7 +29,7 @@ public class ObjectCache {
private static final Logger LOG = LoggerFactory
.getLogger(MethodHandles.lookup().lookupClass());
- private static final WeakHashMap<Configuration, ObjectCache> CACHE = new WeakHashMap<>();
+ private static final WeakHashMap<String, ObjectCache> CACHE = new WeakHashMap<>();
private final HashMap<String, Object> objectMap;
@@ -38,12 +38,12 @@ public class ObjectCache {
}
public synchronized static ObjectCache get(Configuration conf) {
- ObjectCache objectCache = CACHE.get(conf);
+ ObjectCache objectCache = CACHE.get(NutchConfiguration.getUUID(conf));
if (objectCache == null) {
LOG.debug("No object cache found for conf=" + conf
+ ", instantiating a new object cache");
objectCache = new ObjectCache();
- CACHE.put(conf, objectCache);
+ CACHE.put(NutchConfiguration.getUUID(conf), objectCache);
}
return objectCache;
}