Github user tzulitai commented on a diff in the pull request:

    https://github.com/apache/flink/pull/3358#discussion_r102656903
  
    --- Diff: 
flink-connectors/flink-connector-elasticsearch-base/src/main/java/org/apache/flink/streaming/connectors/elasticsearch/ElasticsearchSinkBase.java
 ---
    @@ -211,6 +283,23 @@ public void invoke(T value) throws Exception {
        }
     
        @Override
    +   public void initializeState(FunctionInitializationContext context) 
throws Exception {
    +           // no initialization needed
    +   }
    +
    +   @Override
    +   public void snapshotState(FunctionSnapshotContext context) throws 
Exception {
    +           checkErrorAndRethrow();
    +
    +           if (flushOnCheckpoint) {
    +                   do {
    +                           bulkProcessor.flush();
    --- End diff --
    
    On a second look, I think my previous statement is incorrect.
    
    To elaborate, this is the way the `BulkProcessor`'s `flush` is implemented:
    ```
    if(this.bulkRequest.numberOfActions() > 0) {
        this.execute();
    }
    ```
    
    `execute()` doesn't return until `afterBulk` is called on the listener. 
Since we can re-add requests to the bulk processor within `afterBulk`, the 
`bulkRequest.numberOfActions() > 0` will be true again and enters the loop.
    
    Therefore, the `bulkProcessor.flush()` can actually just be called once, 
and will work with our failure-handler re-adding strategy so that the flush 
also waits for re-added requests before returning. We can just check once on 
`numPendingRequests` after the flush to make sure the flush works as expected.


---
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.
---

Reply via email to