Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 51 additions & 11 deletions src/java/org/apache/nutch/indexer/IndexerOutputFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.nutch.indexer;

import java.io.IOException;
import java.lang.invoke.MethodHandles;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.JobContext;
import org.apache.hadoop.mapreduce.OutputCommitter;
import org.apache.hadoop.mapreduce.OutputFormat;
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class IndexerOutputFormat
extends FileOutputFormat<Text, NutchIndexAction> {
public class IndexerOutputFormat extends OutputFormat<Text, NutchIndexAction> {

private static final Logger LOG = LoggerFactory
.getLogger(MethodHandles.lookup().lookupClass());
private static final Logger LOG =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

@Override
public RecordWriter<Text, NutchIndexAction> getRecordWriter(
Expand All @@ -40,32 +43,69 @@ public RecordWriter<Text, NutchIndexAction> getRecordWriter(
Configuration conf = context.getConfiguration();
final IndexWriters writers = IndexWriters.get(conf);

String name = getUniqueFile(context, "part", "");
writers.open(conf, name);
// open writers (no temporary file output anymore)
String indexName = "index-" + context.getTaskAttemptID().toString();
writers.open(conf, indexName);
LOG.info(writers.describe());

return new RecordWriter<Text, NutchIndexAction>() {

@Override
public void close(TaskAttemptContext context) throws IOException {

// do the commits once and for all the reducers in one go
boolean noCommit = conf
.getBoolean(IndexerMapReduce.INDEXER_NO_COMMIT, false);
boolean noCommit =
conf.getBoolean(IndexerMapReduce.INDEXER_NO_COMMIT, false);

if (!noCommit) {
writers.commit();
}

writers.close();
}

@Override
public void write(Text key, NutchIndexAction indexAction)
throws IOException {

if (indexAction.action == NutchIndexAction.ADD) {
writers.write(indexAction.doc);

} else if (indexAction.action == NutchIndexAction.DELETE) {
writers.delete(key.toString());
}
}
};
}
}

@Override
public void checkOutputSpecs(JobContext context)
throws IOException, InterruptedException {
// No output specs required since we don't write files
}

@Override
public OutputCommitter getOutputCommitter(TaskAttemptContext context)
throws IOException, InterruptedException {

return new OutputCommitter() {

@Override
public void setupJob(JobContext jobContext) {}

@Override
public void setupTask(TaskAttemptContext taskContext) {}

@Override
public boolean needsTaskCommit(TaskAttemptContext taskContext) {
return false;
}

@Override
public void commitTask(TaskAttemptContext taskContext) {}

@Override
public void abortTask(TaskAttemptContext taskContext) {}
};
Comment on lines +87 to +109
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The anonymous no-op OutputCommitter here largely duplicates Hadoop's built-in null output commit semantics (see NullOutputFormat usage elsewhere, e.g. CleaningJob). To reduce maintenance risk across Hadoop upgrades (API surface changes) and keep behavior consistent, consider extending org.apache.hadoop.mapreduce.lib.output.NullOutputFormat and only overriding getRecordWriter, or otherwise reuse a shared no-op committer implementation instead of defining a new anonymous one.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shishir-kuet can you address this issue? Thank you.

}
}