This is an automated email from the ASF dual-hosted git repository.
smengcl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 257a71ab277 HDDS-17480. Use decoded length for streaming PutObject
directory detection (#11776)
257a71ab277 is described below
commit 257a71ab277a980afa1a29557b3940072bdbfa3a
Author: KUAN-HAO HUANG <[email protected]>
AuthorDate: Fri Oct 30 09:53:29 2026 +0800
HDDS-17480. Use decoded length for streaming PutObject directory detection
(#11776)
---
.../hadoop/ozone/s3/endpoint/ObjectEndpoint.java | 9 ++--
.../hadoop/ozone/s3/endpoint/TestObjectPut.java | 58 ++++++++++++++++++++--
2 files changed, 60 insertions(+), 7 deletions(-)
diff --git
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java
index 8cf13edd52a..77453286783 100644
---
a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java
+++
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java
@@ -110,6 +110,7 @@
import org.apache.hadoop.ozone.s3.util.RangeHeaderParserUtil;
import org.apache.hadoop.ozone.s3.util.S3Consts;
import org.apache.hadoop.ozone.s3.util.S3Consts.QueryParams;
+import org.apache.hadoop.ozone.s3.util.S3ContentSha256Type;
import org.apache.hadoop.ozone.s3.util.S3StorageType;
import org.apache.hadoop.ozone.s3.util.S3Utils;
import org.apache.hadoop.util.Time;
@@ -248,10 +249,12 @@ Response handlePutRequest(ObjectRequestContext context,
String keyPath, InputStr
String amzDecodedLength =
getHeaders().getHeaderString(S3Consts.DECODED_CONTENT_LENGTH_HEADER);
- boolean hasAmzDecodedLengthZero = amzDecodedLength != null &&
- Long.parseLong(amzDecodedLength) == 0;
+ String amzContentSha256 =
getHeaders().getHeaderString(S3Consts.X_AMZ_CONTENT_SHA256);
+ boolean useDecodedLength = amzDecodedLength != null && amzContentSha256
!= null &&
+ S3ContentSha256Type.fromHeaderValue(amzContentSha256).isStreaming();
+ boolean isEmptyPayload = useDecodedLength ?
Long.parseLong(amzDecodedLength) == 0 : length == 0;
if (canCreateDirectory &&
- (length == 0 || hasAmzDecodedLengthZero) &&
+ isEmptyPayload &&
StringUtils.endsWith(keyPath, "/")
) {
context.setAction(S3GAction.CREATE_DIRECTORY);
diff --git
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectPut.java
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectPut.java
index 84469e0e949..13a26adb3bb 100644
---
a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectPut.java
+++
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectPut.java
@@ -1159,15 +1159,65 @@ void testDirectoryCreation() throws Exception {
assertThat(key.isFile()).as("directory").isFalse();
}
- @Test
- void testDirectoryCreationWithUnsignedTrailer() throws Exception {
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void testDirectoryCreationWithUnsignedTrailer(boolean hasContentLength)
throws Exception {
configureUnsignedTrailer(0, false);
+ String body = "0\r\nx-amz-checksum-crc32:AAAAAA==\r\n\r\n";
+ when(objectEndpoint.getContext().getMethod()).thenReturn(HttpMethod.PUT);
+ when(headers.getHeaderString(HttpHeaders.CONTENT_LENGTH))
+ .thenReturn(hasContentLength ? String.valueOf(body.length()) : null);
- assertSucceeds(() -> put(objectEndpoint, FSO_BUCKET_NAME, "dir/",
- "0\r\nx-amz-checksum-crc32:AAAAAA==\r\n\r\n"));
+ try (InputStream input = new
ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))) {
+ assertSucceeds(() -> objectEndpoint.put(FSO_BUCKET_NAME, "dir/", input));
+ }
assertThat(fsoBucket.getKey("dir/").isFile()).isFalse();
}
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void testPutNonEmptyObjectWithTrailingSlashWithoutContentLength(boolean
signed) throws Exception {
+ String content = "hello";
+ String body;
+ if (signed) {
+ configureSignedChunksWithTrailer(content.length());
+ ((OzoneBucketStub) fsoBucket).setDerivedKey(signingKey());
+
when(headers.getHeaderString(X_AMZ_TRAILER)).thenReturn("x-amz-checksum-crc32");
+ body = signedChunkedBodyWithTrailer(content, "x-amz-checksum-crc32",
"NhCmhg==");
+ } else {
+ configureUnsignedTrailer(content.length(), false);
+ body = "5\r\nhello\r\n0\r\nx-amz-checksum-crc32:NhCmhg==\r\n\r\n";
+ }
+ when(objectEndpoint.getContext().getMethod()).thenReturn(HttpMethod.PUT);
+ when(headers.getHeaderString(HttpHeaders.CONTENT_LENGTH)).thenReturn(null);
+
+ try (InputStream input = new
ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8))) {
+ assertSucceeds(() -> objectEndpoint.put(FSO_BUCKET_NAME, "dir/", input));
+ }
+
+ OzoneKeyDetails key = fsoBucket.getKey("dir/");
+ assertThat(key.isFile()).isTrue();
+ assertThat(key.getDataSize()).isEqualTo(content.length());
+ assertKeyContent(fsoBucket, "dir/", content);
+ }
+
+ @ParameterizedTest
+ @CsvSource({"'',5", "hello,0"})
+ void testPutWithTrailingSlashUsesContentLengthForNonStreamingPayload(String
content, String decodedLength)
+ throws Exception {
+
when(headers.getHeaderString(X_AMZ_CONTENT_SHA256)).thenReturn(UNSIGNED_PAYLOAD);
+
when(headers.getHeaderString(DECODED_CONTENT_LENGTH_HEADER)).thenReturn(decodedLength);
+
+ assertSucceeds(() -> put(objectEndpoint, FSO_BUCKET_NAME, "dir/",
content));
+
+ OzoneKeyDetails key = fsoBucket.getKey("dir/");
+ assertThat(key.isFile()).isEqualTo(!content.isEmpty());
+ assertThat(key.getDataSize()).isEqualTo(content.length());
+ if (!content.isEmpty()) {
+ assertKeyContent(fsoBucket, "dir/", content);
+ }
+ }
+
@ParameterizedTest
@ValueSource(strings = {"", "0\r\n",
"0\r\nx-amz-checksum-crc32:AAAAAA==\r\n"})
void testDirectoryCreationRejectsIncompleteUnsignedTrailer(String body) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]