在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消耗。