Spark Streaming metadata checkpoint

來源:互聯網
上載者:User

標籤:

一個流應用程式必須全天候運行,所有必須能夠解決應用程式邏輯無關的故障(如系統錯誤,JVM崩潰等)。為了使這成為可能,Spark Streaming需要checkpoint足夠的資訊到容錯儲存系統中, 以使系統從故障中恢複。

  • Metadata checkpointing:儲存StreamCompute的定義資訊到容錯儲存系統如HDFS中。這用來恢複應用程式中運行worker的節點的故障。中繼資料套件括
    • Configuration :建立Spark Streaming應用程式的配置資訊
    • DStream operations :定義Streaming應用程式的操作集合
    • Incomplete batches:操作存在隊列中的未完成的批
  • Data checkpointing :儲存產生的RDD到可靠的儲存系統中,這在有狀態transformation(如結合跨多個批次的資料)中是必須的。在這樣一個transformation中,產生的RDD依賴於之前 批的RDD,隨著時間的推移,這個依賴鏈的長度會持續增長。在恢複的過程中,為了避免這種無限增長。有狀態的transformation的中間RDD將會定時地儲存到可靠儲存系統中,以截斷這個依賴鏈。

中繼資料checkpoint主要是為了從driver故障中恢複資料。如果transformation操作被用到了,資料checkpoint即使在簡單的操作中都是必須的。

 

Metadata checkpointing相關代碼: 
def createContext(checkpointDirectory: String): StreamingContext = {    // If you do not see this printed, that means the StreamingContext has been loaded    // from the new checkpoint    println("Creating new context")    val sparkConf = new SparkConf().setAppName("DynamicRange")    // Create the context with a 1 second batch size    val ssc = new StreamingContext(sparkConf, Seconds(8))    ssc.checkpoint(checkpointDirectory)    ...    //你的kafka streaming的相關代碼最好放在這裡,不然有可能拋異常:spark checkpoint KafkaInputDStream has not been initialize    //create kafka stream    val fullLines = KafkaUtils.createStream(ssc, SystemConfig.config.kafkaZkQuorum, SystemConfig.config.kafkaGroup, topicMap);    //parse data string    val valueLines = fullLines.map(_._2)    ..    ssc}def main(args: Array[String]) {    var ssc: StreamingContext = null    try {        ssc = StreamingContext.getOrCreate(".", () => {            println("get context fail, try to create a new one.")            createContext(".")        })    } catch{        case e:Exception =>{            println("get context exception, try to create a new one.")            ssc = createContext(".")        }    }    ssc.start()    ssc.awaitTermination()}
 注意:
  1. kafka streaming的相關代碼最好放在createContext裡面,不然有可能拋異常:spark checkpoint KafkaInputDStream has not been initialize。
  2. 不同版本之間的Spark Driver是不能從檔案中恢複的,所以這裡我用try catch如果有異常就建立一個context。

Spark Streaming metadata checkpoint

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.