当前位置: 首页> 游戏> 网游 > spark shuffle写操作——BypassMergeSortShuffleWriter

spark shuffle写操作——BypassMergeSortShuffleWriter

时间:2025/7/10 18:08:42来源:https://blog.csdn.net/weixin_43839095/article/details/140210844 浏览次数:0次

创建分区文件writer

每一个分区都生成一个临时文件,创建DiskBlockObjectWriter对象,放入partitionWriters
image.png

分区writer写入消息

遍历所有消息,每一条消息都使用分区器选择对应分区的writer然后写入
image.png

生成分区文件

将分区writer的数据flush,每个分区生成一个FlieSegment,保存在partitionWriterSegments
image.png

分区writer的commit

可以看到生成的fileSegment中file还是上面的分区临时文件
image.png

合并分区临时文件

遍历分区临时文件,获取对应的合并writer,将临时文件的数据写入到合并writer中
image.png
image.png

获取合并的writer

生成一个临时文件,多个reducer使用同一个临时文件。
每个分区都会生成一个LocalDiskShufflePartitionWriter
image.png
LocalDiskShufflePartitionWriter类核心方法有两个openStream、openChannelWrapper。
两个方法分别调用对应的init方法,返回PartitionWriterStream的stream对象和PartitionWriterChannel的channel对象。
PartitionWriterStream的write方法中使用outputBufferedFileStream,在initStream中可以看到outputBufferedFileStream使用的上面生成的临时文件outputTempFile。
PartitionWriterChannel的channel方法返回的是outputFileChannel,outputFileChannel在initChannel中使用的也是上面生成的临时文件outputTempFile。
这表明无论使用stream还是channel,最后都是写入临时文件outputTempFile中。
image.png
image.png
image.png
image.png

临时文件数据写入合并writer

writePartitionedDataWithChannel是使用channel的方式,调用copyFileStreamNIO
writePartitionedDataWithStream是使用stream的方式,调用copyStream
image.png
copyFileStreamNIO
可以看到使用了transferTo方法(零拷贝)
image.png
copyStream
先判断是否能使用transferTo,能的话就调copyFileStreamNIO用零拷贝的方式,不行的话就走普通的流复制
image.png

最终的分区文件提交

将最终的分区临时文件提交,生成对应的data文件和index文件。
可以看到是调用的IndexShuffleBlockResolver类的writeIndexFileAndCommit方法。
image.png
image.png

关键字:spark shuffle写操作——BypassMergeSortShuffleWriter

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: