Spark Streaming:>抛出异常写记录:BatchAllocationEvent

时间:2018-03-07 20:50:54

标签: apache-spark spark-streaming

我使用以下代码关闭Spark StreamingContext。

本质上一个线程监视一个布尔开关,然后调用StreamingContext.stop(true,true)

一切似乎都在处理,我的所有数据似乎都已收集完毕。但是,我在关机时遇到以下异常。

我可以忽略吗?看起来有可能导致数据丢失。

  

18/03/07 11:46:40 WARN ReceivedBlockTracker:抛出异常   写记录:BatchAllocationEvent(1520452000000   ms,AllocatedBlocks(Map(0 - > ArrayBuffer())))到WriteAheadLog。   java.lang.IllegalStateException:调用了close()   写入请求之前的BatchedWriteAheadLog,时间为1520452000001   可以实现。           at org.apache.spark.streaming.util.BatchedWriteAheadLog.write(BatchedWriteAheadLog.scala:86)           在org.apache.spark.streaming.scheduler.ReceivedBlockTracker.writeToLog(ReceivedBlockTracker.scala:234)           在org.apache.spark.streaming.scheduler.ReceivedBlockTracker.allocateBlocksToBatch(ReceivedBlockTracker.scala:118)           在org.apache.spark.streaming.scheduler.ReceiverTracker.allocateBlocksToBatch(ReceiverTracker.scala:213)           在org.apache.spark.streaming.scheduler.JobGenerator $$ anonfun $ 3.apply(JobGenerator.scala:248)

线程

var stopScc=false

private def stopSccThread(): Unit = {
val thread = new Thread {
  override def run {

    var continueRun=true
    while (continueRun) {
      logger.debug("Checking status")
      if (stopScc == true) {
        getSparkStreamingContext(fieldVariables).stop(true, true)
        logger.info("Called Stop on Streaming Context")
        continueRun=false


      }
      Thread.sleep(50)
    }
  }
}
thread.start

}

@throws(classOf[IKodaMLException])
def startStream(ip: String, port: Int): Unit = {

try {
  val ssc = getSparkStreamingContext(fieldVariables)
  ssc.checkpoint("./ikoda/cp")

  val lines = ssc.socketTextStream(ip, port, StorageLevel.MEMORY_AND_DISK_SER)
  lines.print


  val lmap = lines.map {
    l =>

      if (l.contains("IKODA_END_STREAM")) {
        stopScc = true
      }
      l
  }


  lmap.foreachRDD {
    r =>
      if (r.count() > 0) {
        logger.info(s"RECEIVED: ${r.toString()} first: ${r.first().toString}")
        r.saveAsTextFile("./ikoda/test/test")
      }
      else {
        logger.info("Empty RDD. No data received")
      }
  }
  ssc.start()

  ssc.awaitTermination()
}
catch {
  case e: Exception =>
    logger.error(e.getMessage, e)
    throw new IKodaMLException(e.getMessage, e)
}

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,并调用close()而不是停止修复它。