import org.apache.hadoop.ipc.Client; //導入方法依賴的package包/類
/**
* Runs the actual graph application through Hadoop Map-Reduce.
*
* @param verbose If true, provide verbose output, false otherwise
* @return True if success, false otherwise
* @throws ClassNotFoundException
* @throws InterruptedException
* @throws IOException
*/
public final boolean run(boolean verbose)
throws IOException, InterruptedException, ClassNotFoundException {
// Most users won't hit this hopefully and can set it higher if desired
setIntConfIfDefault("mapreduce.job.counters.limit", 5120);
// Capacity scheduler-specific settings. These should be enough for
// a reasonable Giraph job
setIntConfIfDefault("mapred.job.map.memory.mb", 1024);
setIntConfIfDefault("mapred.job.reduce.memory.mb", 0);
// Speculative execution doesn't make sense for Giraph
giraphConfiguration.setBoolean(
"mapred.map.tasks.speculative.execution", false);
// Set the ping interval to 5 minutes instead of one minute
// (DEFAULT_PING_INTERVAL)
Client.setPingInterval(giraphConfiguration, 60000 * 5);
// Should work in MAPREDUCE-1938 to let the user jars/classes
// get loaded first
giraphConfiguration.setBoolean("mapreduce.user.classpath.first", true);
giraphConfiguration.setBoolean("mapreduce.job.user.classpath.first", true);
// If the checkpoint frequency is 0 (no failure handling), set the max
// tasks attempts to be 0 to encourage faster failure of unrecoverable jobs
if (giraphConfiguration.getCheckpointFrequency() == 0) {
int oldMaxTaskAttempts = giraphConfiguration.getMaxTaskAttempts();
giraphConfiguration.setMaxTaskAttempts(0);
if (LOG.isInfoEnabled()) {
LOG.info("run: Since checkpointing is disabled (default), " +
"do not allow any task retries (setting " +
GiraphConstants.MAX_TASK_ATTEMPTS.getKey() + " = 0, " +
"old value = " + oldMaxTaskAttempts + ")");
}
}
// Set the job properties, check them, and submit the job
ImmutableClassesGiraphConfiguration conf =
new ImmutableClassesGiraphConfiguration(giraphConfiguration);
checkLocalJobRunnerConfiguration(conf);
//this part is just used for testing to delete the output dir.
File outputDir = new File(conf.get("mapred.work.output.dir")+"/partitions");
if(outputDir.exists()){
outputDir.delete();
}
Job submittedJob = new Job(conf, jobName);
if (submittedJob.getJar() == null) {
submittedJob.setJarByClass(getClass());
}
submittedJob.setNumReduceTasks(0);
submittedJob.setMapperClass(GraphMapper.class);
submittedJob.setInputFormatClass(BspInputFormat.class);
submittedJob.setOutputFormatClass(BspOutputFormat.class);
GiraphJobObserver jobObserver = conf.getJobObserver();
jobObserver.launchingJob(submittedJob);
boolean passed = submittedJob.waitForCompletion(verbose);
jobObserver.jobFinished(submittedJob, passed);
return passed;
}