sreejasahithi commented on code in PR #10045:
URL: https://github.com/apache/ozone/pull/10045#discussion_r3039669232


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java:
##########
@@ -177,11 +164,140 @@ public Response get(
       throw ex;
     }
 
-    // The valid encodingType Values is "url"
+    // Return empty response if no keys found
+    // This path is reached when FILE_NOT_FOUND exception is caught and handled
+    ListObjectResponse emptyResponse = new ListObjectResponse();
+    emptyResponse.setName(bucketName);
+    emptyResponse.setKeyCount(0);
+    
+    // Log audit entry for empty response to align with previous behavior
+    long opLatencyNs = getMetrics().updateGetBucketSuccessStats(startNanos);
+    perf.appendCount(0);
+    perf.appendOpLatencyNanos(opLatencyNs);
+    auditReadSuccess(s3GAction, perf);
+    
+    return Response.ok(emptyResponse).build();
+  }
+
+  private int validateMaxKeys(int maxKeys) throws OS3Exception {
+    if (maxKeys < 0) {
+      throw newError(S3ErrorTable.INVALID_ARGUMENT, "maxKeys must be >= 0");
+    }
+
+    return Math.min(maxKeys, maxKeysLimit);
+  }
+
+  /**
+   * Context class to hold bucket listing parameters and state.
+   */
+  static class BucketListingContext {
+    private final String bucketName;
+    private final String delimiter;
+    private final String encodingType;
+    private final String marker;
+    private final int maxKeys;
+    private final String prefix;
+    private final String continueToken;
+    private final String startAfter;
+    private final String prevKey;
+    private final boolean shallow;
+    private final OzoneBucket bucket;
+    private final Iterator<? extends OzoneKey> ozoneKeyIterator;
+    private final ContinueToken decodedToken;
+
+    @SuppressWarnings("parameternumber")
+    BucketListingContext(String bucketName, String delimiter, String 
encodingType,
+                               String marker, int maxKeys, String prefix, 
String continueToken,
+                               String startAfter, String prevKey, boolean 
shallow,
+                               OzoneBucket bucket, Iterator<? extends 
OzoneKey> ozoneKeyIterator,
+                               ContinueToken decodedToken) {
+      this.bucketName = bucketName;
+      this.delimiter = delimiter;
+      this.encodingType = encodingType;
+      this.marker = marker;
+      this.maxKeys = maxKeys;
+      this.prefix = prefix;
+      this.continueToken = continueToken;
+      this.startAfter = startAfter;
+      this.prevKey = prevKey;
+      this.shallow = shallow;
+      this.bucket = bucket;
+      this.ozoneKeyIterator = ozoneKeyIterator;
+      this.decodedToken = decodedToken;
+    }
+
+    // Getters
+    public String getBucketName() {
+      return bucketName;
+    }
+
+    public String getDelimiter() {
+      return delimiter;
+    }
+
+    public String getEncodingType() {
+      return encodingType;
+    }
+
+    public String getMarker() {
+      return marker;
+    }
+
+    public int getMaxKeys() {
+      return maxKeys;
+    }
+
+    public String getPrefix() {
+      return prefix;
+    }
+
+    public String getContinueToken() {
+      return continueToken;
+    }
+
+    public String getStartAfter() {
+      return startAfter;
+    }
+
+    public String getPrevKey() {
+      return prevKey;
+    }
+
+    public boolean isShallow() {
+      return shallow;
+    }
+
+    public OzoneBucket getBucket() {
+      return bucket;
+    }
+
+    public Iterator<? extends OzoneKey> getOzoneKeyIterator() {
+      return ozoneKeyIterator;
+    }
+
+    public ContinueToken getDecodedToken() {
+      return decodedToken;
+    }
+  }
+
+  /**
+   * Validate and prepare parameters for bucket listing.
+   */
+  @SuppressWarnings({"parameternumber", "checkstyle:ParameterNumber"})
+  BucketListingContext validateAndPrepareParameters(
+      String bucketName, String delimiter, String encodingType, String marker,
+      int maxKeys, String prefix, String continueToken, String startAfter)
+      throws OS3Exception, IOException {
+    
+    // If you specify the encoding-type request parameter, should return 
encoded key name values 
+    // in the following response elements: Delimiter, Prefix, Key, and 
StartAfter.
+    // For detail refer: 
+    // 
https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html#AmazonS3-ListObjectsV2-response-EncodingType

Review Comment:
   nit : this comment is repeated.



##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java:
##########
@@ -134,31 +130,22 @@ public Response get(
         return listMultipartUploads(bucketName, prefix, keyMarker, 
uploadIdMarker, maxUploads);
       }
 
-      maxKeys = validateMaxKeys(maxKeys);
-
-      if (prefix == null) {
-        prefix = "";
-      }
-
-      // Assign marker to startAfter. for the compatibility of aws api v1
-      if (startAfter == null && marker != null) {
-        startAfter = marker;
-      }
+      // Actual bucket processing starts here
+      // Validate and prepare parameters
+      BucketListingContext listingContext = validateAndPrepareParameters(
+          bucketName, delimiter, encodingType, marker, maxKeys, prefix, 
+          continueToken, startAfter);
 
-      // If continuation token and start after both are provided, then we
-      // ignore start After
-      String prevKey = continueToken != null ? decodedToken.getLastKey()
-          : startAfter;
+      // Initialize response object
+      ListObjectResponse response = initializeListObjectResponse(
+          bucketName, delimiter, encodingType, marker, maxKeys, prefix, 
+          continueToken, startAfter);

Review Comment:
   Here maxKeys is initialized from the query parameters (e.g., a user requests 
5000), validateAndPrepareParameters is called. Inside this method, maxKeys is 
capped via validateMaxKeys(maxKeys) (e.g., capped to 1000). This capped value 
is stored inside the BucketListingContext, the maxKeys variable back in the 
get() method is not updated. It remains 5000. initializeListObjectResponse is 
called using the original maxKeys (5000).The response object now explicitly 
states <MaxKeys>5000</MaxKeys>.
   
   Could you confirm whether that’s intentional or something we should align?
   



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