From db059c6a3c2cfefce0c453d1012e5739454101c1 Mon Sep 17 00:00:00 2001 From: Kohei Sugihara Date: Fri, 24 Jan 2025 14:59:03 +0900 Subject: [PATCH] HDDS-12131. NPE in OM when overwriting empty file using multipart upload (#7739) --- .../src/main/smoketest/s3/MultipartUpload.robot | 6 ++++++ .../S3MultipartUploadCompleteResponse.java | 2 ++ .../S3MultipartUploadCompleteResponseWithFSO.java | 13 ++++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/hadoop-ozone/dist/src/main/smoketest/s3/MultipartUpload.robot b/hadoop-ozone/dist/src/main/smoketest/s3/MultipartUpload.robot index e630fe6cdae..c12f8e33581 100644 --- a/hadoop-ozone/dist/src/main/smoketest/s3/MultipartUpload.robot +++ b/hadoop-ozone/dist/src/main/smoketest/s3/MultipartUpload.robot @@ -61,6 +61,12 @@ Test Multipart Upload With Adjusted Length Perform Multipart Upload ${BUCKET} multipart/adjusted_length_${PREFIX} /tmp/part1 /tmp/part2 Verify Multipart Upload ${BUCKET} multipart/adjusted_length_${PREFIX} /tmp/part1 /tmp/part2 +Overwrite Empty File + Execute touch ${TEMP_DIR}/empty + Execute AWSS3Cli cp ${TEMP_DIR}/empty s3://${BUCKET}/empty_file_${PREFIX} + Perform Multipart Upload ${BUCKET} empty_file_${PREFIX} /tmp/part1 /tmp/part2 + Verify Multipart Upload ${BUCKET} empty_file_${PREFIX} /tmp/part1 /tmp/part2 + Test Multipart Upload ${uploadID} = Initiate MPU ${BUCKET} ${PREFIX}/multipartKey ${nextUploadID} = Initiate MPU ${BUCKET} ${PREFIX}/multipartKey diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/s3/multipart/S3MultipartUploadCompleteResponse.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/s3/multipart/S3MultipartUploadCompleteResponse.java index a1f7b796cd8..72fcd79608f 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/s3/multipart/S3MultipartUploadCompleteResponse.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/s3/multipart/S3MultipartUploadCompleteResponse.java @@ -33,6 +33,7 @@ import org.apache.hadoop.hdds.utils.db.BatchOperation; import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.BUCKET_TABLE; import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.DELETED_TABLE; @@ -130,6 +131,7 @@ protected OmKeyInfo getOmKeyInfo() { return omKeyInfo; } + @Nullable protected OmBucketInfo getOmBucketInfo() { return omBucketInfo; } diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/s3/multipart/S3MultipartUploadCompleteResponseWithFSO.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/s3/multipart/S3MultipartUploadCompleteResponseWithFSO.java index 4d1a6ce09bc..d2d95928ea1 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/s3/multipart/S3MultipartUploadCompleteResponseWithFSO.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/s3/multipart/S3MultipartUploadCompleteResponseWithFSO.java @@ -102,11 +102,14 @@ public void addToDBBatch(OMMetadataManager omMetadataManager, } // namespace quota changes for parent directory - String bucketKey = omMetadataManager.getBucketKey( - getOmBucketInfo().getVolumeName(), - getOmBucketInfo().getBucketName()); - omMetadataManager.getBucketTable().putWithBatch(batchOperation, - bucketKey, getOmBucketInfo()); + OmBucketInfo omBucketInfo = getOmBucketInfo(); + if (omBucketInfo != null) { + String bucketKey = omMetadataManager.getBucketKey( + omBucketInfo.getVolumeName(), + omBucketInfo.getBucketName()); + omMetadataManager.getBucketTable().putWithBatch(batchOperation, + bucketKey, omBucketInfo); + } if (OMFileRequest.getOmKeyInfoFromFileTable(true, omMetadataManager, getMultiPartKey(), getOmKeyInfo().getKeyName())