amazon-kinesis-client icon indicating copy to clipboard operation
amazon-kinesis-client copied to clipboard

KCL v2 - Checkpointing in regular intervals

Open markvdlaan93 opened this issue 5 years ago • 4 comments

I'm currently experiencing issues with the Kinesis Consumer Library and DynamoDB. I'm using DynamoDB for managing the checkpoints for the Kinesis consumer (like the documentation). The problem is that the checkpoints are only updated when the application is gracefully closed. I expect that the checkpoints should also be automatically updated in a regular interval (i.e. every 30 seconds or minute). Is it necessary to manually checkpoint or should the KCL take care of this?

If manually checkpointing is necessary, the documentation should be updated accordingly (https://docs.aws.amazon.com/streams/latest/dev/building-enhanced-consumers-kcl-java.html).

At the moment, I added a fix (from this example with v1: https://github.com/aws-samples/amazon-kinesis-learning/blob/learning-module-1/src/com/amazonaws/services/kinesis/samples/stocktrades/processor/StockTradeRecordProcessor.java) to make sure that the checkpointing happens periodically (in processRecords method after processing the batch):

private static final long CHECKPOINT_INTERVAL_MILLIS = 60000L;
private long nextCheckpointTimeInMillis;
public void processRecords(ProcessRecordsInput processRecordsInput) {
     // code for processing records like documentation
     ...........
     // Checkpoint if minute has passed
     if (System.currentTimeMillis() > nextCheckpointTimeInMillis) {
            try{
                processRecordsInput.checkpointer().checkpoint();
            } catch (InvalidStateException e){
                LOG.error("InvalidStateException thrown during checkpointing");
            } catch (ShutdownException e){
                LOG.error("ShutdownException thrown during checkpointing");
            }
            nextCheckpointTimeInMillis = System.currentTimeMillis() + CHECKPOINT_INTERVAL_MILLIS;
      }
}

markvdlaan93 avatar Sep 11 '19 14:09 markvdlaan93

I believe the docs in https://docs.aws.amazon.com/streams/latest/dev/building-enhanced-consumers-kcl-java.html show this manual / periodic checkpointing now?

synhershko avatar Mar 11 '20 12:03 synhershko

At time of writing, I didn't but now it does indeed. I will close this issue.

markvdlaan93 avatar Mar 13 '20 23:03 markvdlaan93

@markvdlaan93 , I see that you have closed this issue but the docs in https://docs.aws.amazon.com/streams/latest/dev/building-enhanced-consumers-kcl-java.html still don't show manual checkpointing.

rahulj51 avatar Mar 22 '20 11:03 rahulj51

As of July 2021 the docs still don't include periodic checkpointing. This issue should be reopened.

code4dc avatar Jul 16 '21 13:07 code4dc