ArafatKhan2198 commented on code in PR #12216:
URL: https://github.com/apache/ozone/pull/12216#discussion_r4765628343
##########
hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/ObjectStore.java:
##########
@@ -148,14 +146,23 @@ public void createS3Bucket(String bucketName) throws
IOException {
"pre-finalized for bucket layouts. Retrying creation with a " +
"{} bucket.",
s3BucketLayout, fallbackLayout);
- volume.createBucket(bucketName, BucketArgs.newBuilder()
- .setBucketLayout(fallbackLayout).build());
+ createS3Bucket(bucketName, fallbackLayout);
Review Comment:
Earlier we were fetching the S3 volume only once and reusing it during the
fallback. With this change, won't we end up making another RPC call to OM
through getS3Volume()? Can we reuse the volume object here and avoid the
additional RPC?
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketCrudHandler.java:
##########
@@ -66,7 +79,11 @@ Response handlePutRequest(S3RequestContext context, String
bucketName, InputStre
context.setAction(S3GAction.CREATE_BUCKET);
try {
- getClient().getObjectStore().createS3Bucket(bucketName);
+ if (isDirectoryBucketRequest(bucketName, body)) {
+ getClient().getObjectStore().createS3Bucket(bucketName,
BucketLayout.FILE_SYSTEM_OPTIMIZED);
Review Comment:
What happens if someone tries to create a directory bucket while OM is still
pre-finalized? From the current error mapping, it looks like we would return a
500 InternalError. This could also cause the SDK to retry the request
unnecessarily. Can we handle this explicitly and add a test for this scenario?
##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketPut.java:
##########
@@ -95,6 +117,37 @@ public void testCreateBucketSuccess() throws Exception {
assertNotNull(response.getLocation());
}
+ @Test
+ public void testCreateDirectoryBucket() throws Exception {
+ Response response = bucketEndpoint.put(bucketName,
toInputStream(DIRECTORY_BUCKET_CONFIGURATION));
+
+ assertEquals(HTTP_OK, response.getStatus());
+ assertEquals(BucketLayout.FILE_SYSTEM_OPTIMIZED,
+ clientStub.getObjectStore().getS3Bucket(bucketName).getBucketLayout());
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"", GENERAL_PURPOSE_BUCKET_CONFIGURATION})
+ public void testCreateBucketWithoutBucketType(String body) throws Exception {
+ Response response = bucketEndpoint.put(bucketName, toInputStream(body));
+
+ assertEquals(HTTP_OK, response.getStatus());
+ assertNotEquals(BucketLayout.FILE_SYSTEM_OPTIMIZED,
Review Comment:
Shouldn't we check the exact configured layout here instead of just checking
that it is not FSO?
Even if we accidentally create a LEGACY bucket instead of OBS, this test
would still pass. Can we also cover the case where the configured default
itself is FSO?
##########
hadoop-ozone/integration-test-s3/src/test/java/org/apache/hadoop/ozone/s3/awssdk/v2/AbstractS3SDKV2Tests.java:
##########
@@ -5855,5 +5858,28 @@ public void testListBucketsIncludesFSOBuckets() throws
Exception {
deleteFsoBucket(fsoBucketName);
}
}
+
+ /**
+ * Verifies that CreateBucket with bucket type Directory creates an FSO
bucket.
+ */
+ @Test
+ public void testCreateDirectoryBucket() {
+ final String bucketName = uniqueObjectName();
+
+ s3Client.createBucket(b -> b.bucket(bucketName)
+ .createBucketConfiguration(c -> c
+ .location(l ->
l.type(LocationType.AVAILABILITY_ZONE).name("usw2-az1"))
+ .bucket(i ->
i.type(BucketType.DIRECTORY).dataRedundancy(DataRedundancy.SINGLE_AVAILABILITY_ZONE))));
+ try {
+ ListDirectoryBucketsResponse response = s3Client.listDirectoryBuckets(
+ ListDirectoryBucketsRequest.builder()
+ .maxDirectoryBuckets(1000)
+ .build());
+
+
assertThat(response.buckets()).extracting(Bucket::name).contains(bucketName);
Review Comment:
Can we explicitly configure OBS as the default layout for this test? If the
default layout is already FSO this test could pass even without the changes
introduced in this PR. It would also be good to verify the actual bucket layout
from OM instead of only checking ListDirectoryBuckets.
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketCrudHandler.java:
##########
@@ -77,6 +94,37 @@ Response handlePutRequest(S3RequestContext context, String
bucketName, InputStre
}
}
+ /**
+ * Check whether the CreateBucketConfiguration in the request body, if any,
asks for a directory bucket.
+ */
+ private static boolean isDirectoryBucketRequest(String bucketName,
InputStream body)
+ throws IOException, OS3Exception {
+ if (body == null) {
+ return false;
+ }
+ // Read one byte to detect an empty body: InputStream#available() may
return 0 before the body is buffered.
+ PushbackInputStream configuration = new PushbackInputStream(body);
+ int firstByte = configuration.read();
+ if (firstByte == -1) {
+ return false;
+ }
+ configuration.unread(firstByte);
+
+ String bucketType;
+ try {
+ bucketType = UNMARSHALLER.get().readFrom(configuration).getBucketType();
Review Comment:
Do we have any limit on the size of the request body here? Earlier we were
ignoring the body but now we are parsing the entire XML just to get the bucket
type.
If multiple clients send large XML payloads concurrently, this could
unnecessarily consume S3G CPU and memory Can we check if an existing limit
covers this or introduce a reasonable one?
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/CreateBucketConfiguration.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.s3.endpoint;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import org.apache.hadoop.ozone.s3.util.S3Consts;
+
+/**
+ * Request body of CreateBucket. Only the bucket type is read, other elements
are ignored.
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "CreateBucketConfiguration", namespace =
S3Consts.S3_XML_NAMESPACE)
+public class CreateBucketConfiguration {
+
+ @XmlElement(name = "Bucket")
+ private BucketInfo bucket;
+
+ /**
+ * Returns the requested bucket type, or null if the request does not
specify one.
+ */
+ public String getBucketType() {
+ return bucket == null ? null : bucket.type;
+ }
+
+ /**
+ * JAXB entity for the Bucket element.
+ */
+ @XmlAccessorType(XmlAccessType.FIELD)
+ @XmlRootElement(name = "Bucket")
+ public static class BucketInfo {
+
+ @XmlElement(name = "Type")
+ private String type;
Review Comment:
What happens if the request contains multiple Type elements, where one says
Unknown and another says Directory? Would the unmarshaller sikently pick the
last value? Since this value decides the actual bucket layout shouldn't we
reject such requests? Can we add a test for this?
##########
hadoop-ozone/integration-test-s3/src/test/java/org/apache/hadoop/ozone/s3/awssdk/v2/AbstractS3SDKV2Tests.java:
##########
@@ -5855,5 +5858,28 @@ public void testListBucketsIncludesFSOBuckets() throws
Exception {
deleteFsoBucket(fsoBucketName);
}
}
+
+ /**
+ * Verifies that CreateBucket with bucket type Directory creates an FSO
bucket.
+ */
+ @Test
+ public void testCreateDirectoryBucket() {
Review Comment:
Can we also perform a few object operations on the newly created directory
bucket preferably with nested paths? Currently we are only checking whether the
bucket gets created and listed
It would be good to verifu that put, get, list, and delete operations work
as expected through the same SDK client.
--
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]