Hadoop----MR(Map与Job的联系源码)----(源码篇二)

MR–Map源码

要是看提交任务和map是怎么连通的 需要从提交任务这边找到最后提交任务那里
由此进入
在这里插入图片描述
走到这一步,点击submitJob进入
在这里插入图片描述
这个job 继承了thread new的时候 下面调用了一个start 开启线程 所以job里面的run方法 被调用 ,进入本地实现类中。
在这里插入图片描述
线程启动在这里,我们去寻找一下run
在这里插入图片描述
我们直接找对应的run方法,线程的真正开启,是线程的run方法
在这里插入图片描述

  1. TaskSplitMetaInfo[] taskSplitMetaInfos =
    SplitMetaInfoReader.readSplitMetaInfo(jobId, localFs, conf, systemJobDir);
    // 读取job.splitmetainfo
    在这里插入图片描述
  2. int numReduceTasks = job.getNumReduceTasks(); // 获取ReduceTask个数

在这里插入图片描述
3. List mapRunnables = getMapTaskRunnables(
taskSplitMetaInfos, jobId, mapOutputFiles);
// 根据切片的个数, 创建执行MapTask的 MapTaskRunnable
在这里插入图片描述
4. ExecutorService mapService = createMapExecutor(); // 创建线程池
在这里插入图片描述
5. runTasks(mapRunnables, mapService, “map”); //执行 MapTaskRunnable
在这里插入图片描述
6. 因为Runnable提交给线程池执行,接下来会执行MapTaskRunnable的run方法。
7. 执行 LocalJobRunner J o b Job MapTaskRunnable 的run()方法
7.1MapTask map = new MapTask(systemJobFile.toString(),mapId,taskId,info.getSplitIndex(), 1); //创建MapTask对象

在这里插入图片描述
7.2 map.run(localConf, Job.this); //执行MapTask中的run方法
点击run进入run方法,会发现另一片天地----MapTask类中。
在这里插入图片描述
7.2.1 .runNewMapper(job, splitMetaInfo, umbilical, reporter);
在这里插入图片描述
split = getSplitDetails(new Path(splitIndex.getSplitLocation()),splitIndex.getStartOffset()); // 重构切片对象
在这里插入图片描述
切片对象的信息 : file:/D:/input/inputWord/JaneEyre.txt:0+36306679

output = new NewOutputCollector(taskContext, job, umbilical, reporter); //构造缓冲区对象
在这里插入图片描述
collector = createSortingCollector(job, reporter); //获取缓冲区对象
MapTask$MapOutputBuffer
在这里插入图片描述
collector.init(context); //初始化缓冲区对象
在这里插入图片描述
.final float spillper =
job.getFloat(JobContext.MAP_SORT_SPILL_PERCENT, (float)0.8); // 溢写百分比 0.8
在这里插入图片描述
final int sortmb = job.getInt(MRJobConfig.IO_SORT_MB,MRJobConfig.DEFAULT_IO_SORT_MB); // 缓冲区大小 100M
在这里插入图片描述
sorter = ReflectionUtils.newInstance(job.getClass( MRJobConfig.MAP_SORT_CLASS,QuickSort.class,IndexedSorter.class), job);
// 排序对象
// 排序使用的是快排,并且基于索引排序。
在这里插入图片描述
开始kv序列化
在这里插入图片描述
然后走output counters// 计数器
走compression // 压缩
走// combiner // combiner
总结:
mapper.run(mapperContext); // 执行WordCountMapper中的run方法。 实际执行的是
WordCountMapper继承的Mapper中的run方法。

	      [1] . 在Mapper中的run方法中 
	             map(context.getCurrentKey(), context.getCurrentValue(), context);
		     执行到WordCountMapper中的map方法。
	      [2] . 在WordCountMapper中的map方法中将kv写出
	            context.write(outK,outV);

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_45284133/article/details/105614517
今日推荐