chungen0126 commented on code in PR #11898:
URL: https://github.com/apache/ozone/pull/11898#discussion_r4466341567


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/S3ConditionalRequest.java:
##########
@@ -217,59 +204,47 @@ private static boolean eTagMatches(String headerValue, 
String currentETag) {
   }
 
   private static boolean matchesIfModifiedSince(OzoneKey key,
-      String headerValue) {
-    Instant since = parseConditionalInstant(headerValue);
+      String headerValue, PreconditionContext context) {
+    Instant since = parseConditionalInstant(headerValue, context);
     if (since == null) {
       return true;
     }
+    if (context == PreconditionContext.UPLOAD_PART_COPY_SOURCE) {
+      return !key.getModificationTime().isBefore(since);
+    }

Review Comment:
   I don't see why UPLOAD_PART_COPY_SOURCE needs a special case here.



##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/S3ConditionalRequest.java:
##########
@@ -65,6 +64,15 @@ enum PreconditionContext {
      * when any condition is not met (no 304 responses).
      */
     COPY_SOURCE(
+        S3Consts.COPY_SOURCE_IF_MATCH,
+        S3Consts.COPY_SOURCE_IF_NONE_MATCH,
+        S3Consts.COPY_SOURCE_IF_MODIFIED_SINCE,
+        S3Consts.COPY_SOURCE_IF_UNMODIFIED_SINCE),
+
+    /**
+     * For UploadPartCopy source validation, preserving the existing timestamp 
comparisons and ignoring future dates.
+     */
+    UPLOAD_PART_COPY_SOURCE(
         S3Consts.COPY_SOURCE_IF_MATCH,
         S3Consts.COPY_SOURCE_IF_NONE_MATCH,
         S3Consts.COPY_SOURCE_IF_MODIFIED_SINCE,

Review Comment:
   Could we simply use PreconditionContext.COPY_SOURCE here instead of adding 
UPLOAD_PART_COPY_SOURCE? 



##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/S3ConditionalRequest.java:
##########
@@ -217,59 +204,47 @@ private static boolean eTagMatches(String headerValue, 
String currentETag) {
   }
 
   private static boolean matchesIfModifiedSince(OzoneKey key,
-      String headerValue) {
-    Instant since = parseConditionalInstant(headerValue);
+      String headerValue, PreconditionContext context) {
+    Instant since = parseConditionalInstant(headerValue, context);
     if (since == null) {
       return true;
     }
+    if (context == PreconditionContext.UPLOAD_PART_COPY_SOURCE) {
+      return !key.getModificationTime().isBefore(since);
+    }
     Instant lastModified = key.getModificationTime()
         .truncatedTo(ChronoUnit.SECONDS);
     return lastModified.isAfter(since);
   }
 
   private static boolean matchesIfUnmodifiedSince(OzoneKey key,
-      String headerValue) {
-    Instant since = parseConditionalInstant(headerValue);
+      String headerValue, PreconditionContext context) {
+    Instant since = parseConditionalInstant(headerValue, context);
     if (since == null) {
       return true;
     }
-    Instant lastModified = key.getModificationTime()
-        .truncatedTo(ChronoUnit.SECONDS);
+    Instant lastModified = key.getModificationTime();
+    if (context != PreconditionContext.UPLOAD_PART_COPY_SOURCE) {
+      lastModified = lastModified.truncatedTo(ChronoUnit.SECONDS);
+    }
     return !lastModified.isAfter(since);
   }
 
-  private static Instant parseConditionalInstant(String headerValue) {
+  private static Instant parseConditionalInstant(String headerValue, 
PreconditionContext context) {
     if (headerValue == null) {
       return null;
     }
     try {
-      return Instant.ofEpochMilli(OzoneUtils.formatDate(headerValue))
-          .truncatedTo(ChronoUnit.SECONDS);
+      Instant since = Instant.ofEpochMilli(OzoneUtils.formatDate(headerValue));
+      if (context == PreconditionContext.UPLOAD_PART_COPY_SOURCE && 
since.isAfter(Instant.now())) {
+        return null;
+      }
+      return since.truncatedTo(ChronoUnit.SECONDS);

Review Comment:
   Nice change, correctly ignoring future dates. However, this should apply 
generally to all contexts rather than being restricted to 
UPLOAD_PART_COPY_SOURCE.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to