Spark Checkpoint读操作代码分析
来源:互联网 发布:怎么安装spss13软件 编辑:程序博客网 时间:2024/05/18 02:59
《Spark RDD缓存代码分析》
《Spark Task序列化代码分析》
《Spark分区器HashPartitioner和RangePartitioner代码详解》
《Spark Checkpoint读操作代码分析》
《Spark Checkpoint写操作代码分析》
《Spark Task序列化代码分析》
《Spark分区器HashPartitioner和RangePartitioner代码详解》
《Spark Checkpoint读操作代码分析》
《Spark Checkpoint写操作代码分析》
上次介绍了RDD的Checkpint写过程(《Spark Checkpoint写操作代码分析》),本文将介绍RDD如何读取已经Checkpint的数据。在RDD Checkpint完之后,Checkpint的信息(比如数据存放的目录)都由RDDCheckpointData去管理,所以当下次计算依赖了这个RDD的时候,首先是根据依赖关系判断出当前这个RDD是否被Checkpint了,主要是通过RDD的dependencies决定:
final
def
dependencies
:
Seq[Dependency[
_
]]
=
{
checkpointRDD.map(r
=
> List(
new
OneToOneDependency(r))).getOrElse {
if
(dependencies
_
==
null
) {
dependencies
_
=
getDependencies
}
dependencies
_
}
}
如果RDD被Checkpint了,那么checkpointRDD为Some(CheckpointRDD[T])了,所以依赖的RDD变成了CheckpointRDD。在计算数据的过程中会调用RDD的iterator方法:
final
def
iterator(split
:
Partition, context
:
TaskContext)
:
Iterator[T]
=
{
if
(storageLevel !
=
StorageLevel.NONE) {
<
span
class
=
"wp_keywordlink_affiliate"
><
a href
=
"http://www.iteblog.com/archives/tag/spark"
title
=
""
target
=
"_blank"
data-original-title
=
"View all posts in Spark"
>
Spark
<
/a
><
/span
>
Env.get.cacheManager.getOrCompute(
this
, split, context, storageLevel)
}
else
{
computeOrReadCheckpoint(split, context)
}
}
private
[spark]
def
computeOrReadCheckpoint(split
:
Partition, context
:
TaskContext)
:
Iterator[T]
=
{
if
(isCheckpointed) firstParent[T].iterator(split, context)
else
compute(split, context)
}
计算的过程中首先会判断RDD是否被Checkpint了,而RDD Checkpint写之后这个条件肯定是true的。而firstParent已经变成了CheckpointRDD,所以会调用CheckpointRDD的iterator方法, 该方法最终会调用ReliableCheckpointRDD的compute方法:
override
def
compute(split
:
Partition, context
:
TaskContext)
:
Iterator[T]
=
{
val
file
=
new
Path(checkpointPath, ReliableCheckpointRDD.checkpointFileName(split.index))
ReliableCheckpointRDD.readCheckpointFile(file, broadcastedConf, context)
}
在compute方法中会通过ReliableCheckpointRDD的readCheckpointFile方法来从file路径里面读出已经Checkpint的数据,readCheckpointFile的实现如下:
def
readCheckpointFile[T](
path
:
Path,
broadcastedConf
:
Broadcast[SerializableConfiguration],
context
:
TaskContext)
:
Iterator[T]
=
{
val
env
=
<
span
class
=
"wp_keywordlink_affiliate"
><
a href
=
"http://www.iteblog.com/archives/tag/spark"
title
=
""
target
=
"_blank"
data-original-title
=
"View all posts in Spark"
>
Spark
<
/a
><
/span
>
Env.get
val
fs
=
path.getFileSystem(broadcastedConf.value.value)
val
bufferSize
=
env.conf.getInt(
"spark.buffer.size"
,
65536
)
val
fileInputStream
=
fs.open(path, bufferSize)
val
serializer
=
env.serializer.newInstance()
val
deserializeStream
=
serializer.deserializeStream(fileInputStream)
// Register an on-task-completion callback to close the input stream.
context.addTaskCompletionListener(context
=
> deserializeStream.close())
deserializeStream.asIterator.asInstanceOf[Iterator[T]]
}
最后数据就回被全部读取出来,整个Checkpint读过程完成了。
转载自过往记忆(http://www.iteblog.com/)
0 0
- Spark Checkpoint读操作代码分析
- Spark Checkpoint读操作代码分析
- Spark Checkpoint读操作代码分析
- Spark Checkpoint写操作代码分析
- Spark Checkpoint写操作代码分析
- Spark Checkpoint写操作代码分析
- Spark中CheckPoint操作
- spark streaming源码分析5 checkpoint
- Spark源码分析之Checkpoint机制
- spark checkpoint
- spark core源码分析11 RDD缓存及checkpoint
- spark源码学习(十二)--- checkpoint机制分析
- spark cache和checkpoint
- Spark函数讲解:checkpoint
- spark的checkpoint
- spark的checkpoint
- Spark cache和checkpoint
- [spark] Checkpoint 源码解析
- Spark读取数据库(Mysql)的四种方式讲解
- 8086汇编语言 R命令查看各个寄存器的存储值
- JAVA 面向对象 类和对象
- 初始JavaScript
- 《linux学习》之新建用户无法登陆问题
- Spark Checkpoint读操作代码分析
- Base64编码及其作用
- Codeforces Round #271 (Div. 2) F Ant colony
- StarUML软件设计建模工具破解
- 8086汇编语言 R命令更改寄存器的内容
- poj-1222 高斯消元
- python学习——分布式进程
- 355-Design Twitter
- 一个简单代码的不简单实现