为什么在完成加载存储的偏移后删除检查点文件?

时间:2017-08-23 07:35:32

标签: apache-kafka kafka-consumer-api

在kafka 0.10.2.0中,当完成初始化ProcessorStateManager时,为什么要删除检查点文件:

// load the checkpoint information
OffsetCheckpoint checkpoint = new OffsetCheckpoint(new File(this.baseDir, CHECKPOINT_FILE_NAME));
this.checkpointedOffsets = new HashMap<>(checkpoint.read());

// delete the checkpoint file after finish loading its stored offsets
checkpoint.delete();

如果然后我强行终止应用程序并重新启动它,它将不会加载检查点文件,因为它已被删除,因此在恢复分区的状态时:

if (checkpointedOffsets.containsKey(storePartition)) {
    restoreConsumer.seek(storePartition, checkpointedOffsets.get(storePartition));
} else {
    restoreConsumer.seekToBeginning(singleton(storePartition));
}

因为它将执行seekToBeginning,然后消费者将从偏移0消耗。

1 个答案:

答案 0 :(得分:0)

我找到答案:

KAFKA-4317

PATCH