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



##########
File path: raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java
##########
@@ -2268,6 +2269,25 @@ 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 invalid 
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 quorumEpoch = quorum().epoch();
+        if (snapshotId.epoch > quorumEpoch) {
+            throw new KafkaException("Trying to creating snapshot with invalid 
snapshotId: " + snapshotId + " whose epoch is" +
+                    " larger than the quorum epoch: " + quorumEpoch);
+        }
+        OffsetAndEpoch endOffsetAndEpoch = 
log.endOffsetForEpoch(snapshotId.epoch);
+        if (endOffsetAndEpoch.epoch != snapshotId.epoch || 
endOffsetAndEpoch.offset < snapshotId.offset) {
+            throw new KafkaException("Trying to creating snapshot with invalid 
snapshotId: " + snapshotId +

Review comment:
       Will fix, but I assume you want `IllegalArgumentException` instead of 
`InvalidArgumentException`? 




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