You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "kirktrue (via GitHub)" <gi...@apache.org> on 2023/05/12 15:49:46 UTC

[GitHub] [kafka] kirktrue commented on a diff in pull request #13709: Added a validation to check if the record timestamp is in the future compared to the broker's timestamp

kirktrue commented on code in PR #13709:
URL: https://github.com/apache/kafka/pull/13709#discussion_r1192539289


##########
storage/src/main/java/org/apache/kafka/storage/internals/log/LogValidator.java:
##########
@@ -590,18 +593,25 @@ private static Optional<ApiRecordError> validateTimestamp(RecordBatch batch,
                                                               TimestampType timestampType,
                                                               long timestampDiffMaxMs) {
         if (timestampType == TimestampType.CREATE_TIME
-                && record.timestamp() != RecordBatch.NO_TIMESTAMP
-                && Math.abs(record.timestamp() - now) > timestampDiffMaxMs)
-            return Optional.of(new ApiRecordError(Errors.INVALID_TIMESTAMP, new RecordError(batchIndex,
-                "Timestamp " + record.timestamp() + " of message with offset " + record.offset()
-                + " is out of range. The timestamp should be within [" + (now - timestampDiffMaxMs)
-                + ", " + (now + timestampDiffMaxMs) + "]")));
+                && record.timestamp() != RecordBatch.NO_TIMESTAMP){
+            final long timestampDiff = record.timestamp() - now;
+            if(timestampDiff > TIME_DRIFT_TOLERANCE){
+                return Optional.of(new ApiRecordError(Errors.INVALID_TIMESTAMP, new RecordError(batchIndex,
+                        "Timestamp " + record.timestamp() + " of message with offset " + record.offset()
+                                + " is ahead of the server's time. " + now)));

Review Comment:
   nit: Can we change this:
   
   ```scala
   + " is ahead of the server's time. " + now)));
   ```
   
   to
   
   ```scala
   + " is ahead of the server's time (" + now + ").")));
   ```



-- 
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-unsubscribe@kafka.apache.org

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