Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,21 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, Execut
.get(multipartOpenKey);
omBucketInfo = getBucketInfo(omMetadataManager, volumeName, bucketName);

// If there is no entry in openKeyTable, then there is no multipart
// upload initiated for this key.
if (omKeyInfo == null) {
throw new OMException("Abort Multipart Upload Failed: volume: " +
requestedVolume + "bucket: " + requestedBucket + "key: " + keyName,
OMException.ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
// In old env, OpenKeycleanupservice may have deleted key from openKeyTable leaving behind
// orphan parts in multipartInfoTable.
LOG.warn("Entry doesn't exist in openKeyTable, bucket: {}, key: {}", bucketName, keyName);
}

multipartKeyInfo = omMetadataManager.getMultipartInfoTable()
.get(multipartKey);

if (multipartKeyInfo == null) {
throw new OMException("Abort Multipart Upload Failed: volume: " +
requestedVolume + " bucket: " + requestedBucket + " key: " + keyName,
OMException.ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
}

multipartKeyInfo = multipartKeyInfo.toBuilder()
.setUpdateID(trxnLogIndex)
.build();
Expand All @@ -170,7 +175,7 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, Execut
for (PartKeyInfo iterPartKeyInfo : multipartKeyInfo.getPartKeyInfoMap()) {
quotaReleased += QuotaUtil.getReplicatedSize(
iterPartKeyInfo.getPartKeyInfo().getDataSize(),
omKeyInfo.getReplicationConfig());
multipartKeyInfo.getReplicationConfig());
}
omBucketInfo.incrUsedBytes(-quotaReleased);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
package org.apache.hadoop.ozone.om.request.s3.multipart;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.io.IOException;
import java.util.UUID;
import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
import org.apache.hadoop.ozone.om.request.OMRequestTestUtils;
import org.apache.hadoop.ozone.om.response.OMClientResponse;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
Expand Down Expand Up @@ -120,6 +123,80 @@ public void testValidateAndUpdateCacheMultipartNotFound() throws Exception {

}

/**
* Test abort MPU when omKeyInfo is null in openKeyTable.
* This simulates the case where OpenKeyCleanupService has deleted the key
* from openKeyTable leaving behind orphan parts in multipartInfoTable.
*/
@Test
public void testValidateAndUpdateCacheWithOrphanMultipartInfo() throws Exception {
String volumeName = UUID.randomUUID().toString();
String bucketName = UUID.randomUUID().toString();
String keyName = getKeyName();

OMRequestTestUtils.addVolumeAndBucketToDB(volumeName, bucketName,
omMetadataManager, getBucketLayout());

createParentPath(volumeName, bucketName);

// Step 1: Initiate multipart upload
OMRequest initiateMPURequest = doPreExecuteInitiateMPU(volumeName,
bucketName, keyName);

S3InitiateMultipartUploadRequest s3InitiateMultipartUploadRequest =
getS3InitiateMultipartUploadReq(initiateMPURequest);

OMClientResponse omClientResponse =
s3InitiateMultipartUploadRequest.validateAndUpdateCache(ozoneManager, 1L);

String multipartUploadID = omClientResponse.getOMResponse()
.getInitiateMultiPartUploadResponse().getMultipartUploadID();

String multipartKey = omMetadataManager.getMultipartKey(volumeName,
bucketName, keyName, multipartUploadID);
String multipartOpenKey = getMultipartOpenKey(volumeName, bucketName,
keyName, multipartUploadID);

// Step 2: Verify initial state - both tables have entries
assertNotNull(omMetadataManager.getMultipartInfoTable().get(multipartKey));
assertNotNull(omMetadataManager.getOpenKeyTable(getBucketLayout()).get(multipartOpenKey));

// Step 3: Simulate OpenKeyCleanupService deleting the entry from openKeyTable
// while keeping the multipartInfoTable entry (orphan scenario)
// Mark the entry as deleted in the cache
omMetadataManager.getOpenKeyTable(getBucketLayout())
.addCacheEntry(new CacheKey<>(multipartOpenKey),
CacheValue.get(100L));

// Verify orphan state: multipartInfoTable has entry, openKeyTable doesn't
assertNotNull(omMetadataManager.getMultipartInfoTable().get(multipartKey));
assertNull(omMetadataManager.getOpenKeyTable(getBucketLayout()).get(multipartOpenKey));

// Step 4: Now abort the multipart upload with orphaned metadata
OMRequest abortMPURequest =
doPreExecuteAbortMPU(volumeName, bucketName, keyName,
multipartUploadID);

S3MultipartUploadAbortRequest s3MultipartUploadAbortRequest =
getS3MultipartUploadAbortReq(abortMPURequest);

// This should succeed despite omKeyInfo being null (orphan cleanup case)
omClientResponse =
s3MultipartUploadAbortRequest.validateAndUpdateCache(ozoneManager, 2L);

// Check response - abort should succeed
assertEquals(OzoneManagerProtocolProtos.Status.OK,
omClientResponse.getOMResponse().getStatus());

// Verify cleanup: multipartInfoTable entry should be removed
assertNull(omMetadataManager.getMultipartInfoTable().get(multipartKey));

// Verify openKeyTable entry remains null
assertNull(omMetadataManager
.getOpenKeyTable(s3MultipartUploadAbortRequest.getBucketLayout())
.get(multipartOpenKey));
}

@Test
public void testValidateAndUpdateCacheVolumeNotFound() throws Exception {
String volumeName = UUID.randomUUID().toString();
Expand Down