[关闭]
@xtccc 2016-01-03T11:19:17.000000Z 字数 947 阅读 2348

Spark Streaming

SparkStreaming


Fault-Tolerant Processing


如果一个Spark Streaming app driver host崩溃了,那么它就丢失所有已经收到但是还未被处理的数据。为了应对这种情况,Spark可以将它收到的数据写入到HDFS中,这样可以在Spark app崩溃时恢复数据。这个特性称为 Spark Streaming Recovery ,在CDH 5.4开始可以用于生产环境。

开启该特性的步骤:

  1. 设置“spark.streaming.receiver.writeAheadLog.enable”
  1. sparkConf.set("spark.streaming.receiver.writeAheadLog.enable", "true")
  1. 使用上述的“SparkConf”创建一个“StreamingContext”实例,并指定一个checkpoint目录
  2. 调用“StreamingContext”的“getOrCreate”方法来创建一个新的“StreamingContext”实例,或者是基于checkpoint目录恢复原有的“StreamingContext”实例
  1. def createContext(): StreamingContext = {
  2. val conf = new SparkConf()
  3. conf.set("spark.streaming.receiver.writeAheadLog.enable", "true")
  4. val ssc = new StreamingContext(conf) // new cobtext
  5. val kafkaStream = KafkaStream.createStream(...)
  6. // Do some transformations on the stream ... and write it out etc
  7. ssc.checkpoint(checkPointDirectory) // set checkpoint dir
  8. ssc
  9. }
  10. // Get StreamingContext from checkpoing data or create a new one
  11. val ssc = StreamingContext.getOrCreate(checkPointDirectory, createContext _)
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注