jsancio commented on code in PR #15671:
URL: https://github.com/apache/kafka/pull/15671#discussion_r1586526016


##########
raft/src/main/java/org/apache/kafka/raft/ReplicatedLog.java:
##########
@@ -261,7 +260,7 @@ default long truncateToEndOffset(OffsetAndEpoch endOffset) {
      * @param snapshotId the end offset and epoch that identifies the snapshot
      * @return a writable snapshot if it doesn't already exist
      */
-    Optional<RawSnapshotWriter> storeSnapshot(OffsetAndEpoch snapshotId);
+    Optional<RawSnapshotWriter> createNewSnapshotUnchecked(OffsetAndEpoch 
snapshotId);

Review Comment:
   So the use cases are very different hence the reason why I separated the 
methods.
   
   `createNewSnapshot` is indirectly called by the KRaft state machine. In this 
case the `ReplicatedLog` makes sure that the provided snapshot id (offset and 
epoch) is consistent with the log.
   
   `createNewSnapshotUnchecked` is used by the local replica to override the 
entire log with the leader's snapshot. For example, right after downloading the 
snapshot we fully truncate the log: 
https://github.com/apache/kafka/blob/trunk/raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java#L1459-L1473
   
   This part of the code calls `truncateToLatestSnapshot` which deletes all of 
the old snapshots and replaces the log with an empty log that start at the just 
downloaded snapshot (the latest snapshot). In other words 
`truncateToLatestSnapshot` makes the `ReplicadLog` consistent after the direct 
use of `createNewSnapshotUnchecked`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to