jsancio commented on a change in pull request #10593:
URL: https://github.com/apache/kafka/pull/10593#discussion_r620232416



##########
File path: raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java
##########
@@ -2268,6 +2269,20 @@ private Long append(int epoch, List<T> records, boolean 
isAtomic) {
         );
     }
 
+    private void validateSnapshotId(OffsetAndEpoch snapshotId) {
+        Optional<LogOffsetMetadata> highWatermarkOpt = 
quorum().highWatermark();
+        if (!highWatermarkOpt.isPresent() || highWatermarkOpt.get().offset <= 
snapshotId.offset) {
+            throw new KafkaException("Trying to creating snapshot with 
snapshotId: " + snapshotId + " whose offset is larger than the high-watermark: 
" +
+                    highWatermarkOpt + ". This may necessarily mean a bug in 
the caller, since the there should be a minimum " +
+                    "size of records between the latest snapshot and the 
high-watermark when creating snapshot");
+        }
+        int leaderEpoch = quorum().epoch();
+        if (snapshotId.epoch > leaderEpoch) {
+            throw new KafkaException("Trying to creating snapshot with 
snapshotId: " + snapshotId + " whose epoch is" +
+                    " larger than the current leader epoch: " + leaderEpoch);
+        }

Review comment:
       Yeah, This is not strictly required for correctness. Oh, I see, the 
check in 2280 is checking that the `epoch > current epoch`.
   
   I mistakenly read it as `epoch != current epoch`. If we perform this check 
we are basically saying that the caller of `createSnapshot` needs to catch up 
to the current quorum epoch before it can generate a snapshot. Yes, I think 
epoch <= quorum epoch` is fine. Let me think about it and I'll update the Jira.




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

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


Reply via email to