Spark CheckPoint

简述:

checkpoint就是存盘的意思,比如一个程序要运行10步,结果在第8步挂了,难道前面7步要重头再来?如果前面7步是非常耗时的话,那这样损失是非常大的。

步骤:

1、启动spark集群

cd /usr/local/spark-1.6.1-bin-hadoop2.6/sbin/
./start-all.sh 

注意:之所以没有配置在环境变量里,是因为hadoop也有个start-all,怕有冲突

2、启动hdfs

start-dfs.sh

3、启动spark shell

cd /usr/local/spark-1.6.1-bin-hadoop2.6/bin/
./spark-shell --master spark://node01:7077 --executor-memory 1024m --total-executor-cores 4

4、设置checkpoint dir

sc.setCheckpointDir("hdfs://node01:9000/ck0001")

5、运行word count

 val res=sc.textFile("hdfs://node01:9000/myinput/").flatMap(_.split(" ")).map((_,1)).reduceByKey(_+_)

6、将res放入缓存

 res.cache()

7、将res放入checkpoint中

res.checkpoint()

8、collect(必须要作Action类型的算子,否则不会往hdfs放)

res.collect()

8.1、命令执行完效果如下图

9、查看hdfs中的内容

 hdfs dfs -cat /ck0001/194cae8f-1124-4d3c-90ec-8107608b5119/rdd-9/part-00000

结果如下

9.1、或者用web hdfs查看(需要修改hdfs-site.xml使web-hdfs生效),如下图

 

转载于:https://my.oschina.net/windows20/blog/1818915

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值