GitHub user sasakitoa opened a pull request:

    https://github.com/apache/spark/pull/17462

    [SPARK-20050][DStream] Kafka 0.10 DirectStream doesn't commit last 
processed batch's offset when graceful shutdown

    ## What changes were proposed in this pull request?
    
    When we use KafkaDirectStream(Kafka0.10) with `enable.auto.commit` is 
`false`, 
    some record's offsets do not commit to Kafka at graceful shutdown, such 
below.
    
    Sample code
    
    ```
    val kafkaParams = Map[String, Object]("enable.auto.commit" -> "false")
    val kafkaStream = KafkaUtils.createDirectStream[String, String](ssc, ... , 
kafkaParams.asScala)
    
    kafkaStream.map { input =>
      "key: " + input.key.toString + " value: " + input.value.toString + " 
offset: " + input.offset.toString
      }.foreachRDD { rdd =>
        rdd.foreach { input =>
        println(input)
      }
    }
    
    kafkaStream.foreachRDD { rdd =>
      val offsetRanges = rdd.asInstanceOf[HasOffsetRanges].offsetRanges
      kafkaStream.asInstanceOf[CanCommitOffsets].commitAsync(offsetRanges)
    }
    ```
    
    output at first time
    
    ```
    key: null value: 1 offset: 101452472
    key: null value: 2 offset: 101452473
    key: null value: 3 offset: 101452474
    key: null value: 4 offset: 101452475
    key: null value: 5 offset: 101452476
    key: null value: 6 offset: 101452477
    key: null value: 7 offset: 101452478
    key: null value: 8 offset: 101452479
    key: null value: 9 offset: 101452480  // this is a last record before 
shutdown Spark Streaming gracefully
    ```
    
    output at second time
    
    ```
    key: null value: 7 offset: 101452478   // duplicate
    key: null value: 8 offset: 101452479   // duplicate
    key: null value: 9 offset: 101452480   // duplicate
    key: null value: 10 offset: 101452481
    ```
    
    This is because offset will commit at the beginning of each batches, and 
will not commit after all batches processed.
    
    
    
    ## How was this patch tested?
    
    Added tests `offset commit when graceful shtudown` in 
`DirectKafkaStreamSuite.scala`

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/sasakitoa/spark Kafka010commitAsync2

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/17462.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #17462
    
----
commit e7b218b877b15075a370b16909fb32e1b9865bb0
Author: Sasaki Toru <[email protected]>
Date:   2017-03-28T22:14:04Z

    Invoke DirectkafkaInputDStream#commitAll when graceful shutdown

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to