Skip to content

HDDS-11784. Allow aborting FSO multipart uploads with missing parent directories #7700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 8, 2025
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 @@ -631,6 +631,42 @@ public void testListMultipartUploadParts() throws Exception {
assertFalse(ozoneMultipartUploadPartListParts.isTruncated());
}

@Test
public void testAbortMultipartUploadSuccessWithMissingParentDirectories() throws Exception {
String parentDir = "parentDirToDelete/";
keyName = parentDir + UUID.randomUUID();

OzoneManager ozoneManager = cluster.getOzoneManager();
String buckKey = ozoneManager.getMetadataManager()
.getBucketKey(volume.getName(), bucket.getName());
OmBucketInfo buckInfo =
ozoneManager.getMetadataManager().getBucketTable().get(buckKey);
BucketLayout bucketLayout = buckInfo.getBucketLayout();

String uploadID = initiateMultipartUpload(bucket, keyName, RATIS,
ONE);

OMMetadataManager metadataMgr =
cluster.getOzoneManager().getMetadataManager();
String multipartOpenKey =
metadataMgr.getMultipartKeyFSO(volumeName, bucketName, keyName, uploadID);
String multipartKey = metadataMgr.getMultipartKey(volumeName, bucketName,
keyName, uploadID);

// Delete parent directory
ozClient.getProxy().deleteKey(volumeName, bucketName, parentDir, false);

// Abort multipart upload with missing parent directory
bucket.abortMultipartUpload(keyName, uploadID);

OmKeyInfo omKeyInfo =
metadataMgr.getOpenKeyTable(bucketLayout).get(multipartOpenKey);
OmMultipartKeyInfo omMultipartKeyInfo =
metadataMgr.getMultipartInfoTable().get(multipartKey);
assertNull(omKeyInfo);
assertNull(omMultipartKeyInfo);
}

private void verifyPartNamesInDB(Map<Integer, String> partsMap,
OzoneMultipartUploadPartListParts ozoneMultipartUploadPartListParts,
String uploadID) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.BUCKET_NOT_FOUND;
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.FILE_NOT_FOUND;
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.VOLUME_NOT_FOUND;
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR;
import static org.apache.hadoop.ozone.OzoneConsts.OM_SNAPSHOT_CHECKPOINT_DIR;
import static org.apache.hadoop.ozone.om.service.SnapshotDeletingService.isBlockLocationInfoSame;
import static org.apache.hadoop.ozone.om.snapshot.SnapshotUtils.checkSnapshotDirExist;
Expand Down Expand Up @@ -892,11 +893,26 @@ public String getMultipartKeyFSO(String volume, String bucket, String key, Strin
final long volumeId = getVolumeId(volume);
final long bucketId = getBucketId(volume,
bucket);
long parentId =
OMFileRequest.getParentID(volumeId, bucketId, key, this);

String fileName = OzoneFSUtils.getFileName(key);
long parentId;
try {
parentId = OMFileRequest.getParentID(volumeId, bucketId, key, this);
} catch (final Exception e) {
// It is possible we miss directories and exception is thrown.
// see https://issues.apache.org/jira/browse/HDDS-11784
LOG.warn("Got exception when finding parent id for {}/{}/{}. Use another way to get it",
volumeId, bucketId, key, e);
final String multipartKey =
getMultipartKey(volume, bucket, key, uploadId);
final OmMultipartKeyInfo multipartKeyInfo =
getMultipartInfoTable().get(multipartKey);
if (multipartKeyInfo == null) {
LOG.error("Could not find multipartKeyInfo for {}", multipartKey);
throw new OMException(NO_SUCH_MULTIPART_UPLOAD_ERROR);
}
parentId = multipartKeyInfo.getParentID();
}

final String fileName = OzoneFSUtils.getFileName(key);
return getMultipartKey(volumeId, bucketId, parentId,
fileName, uploadId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.FILE_TABLE;
import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.MULTIPARTINFO_TABLE;
import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.OPEN_FILE_TABLE;
import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.DIRECTORY_TABLE;

/**
* Response for Multipart Upload Complete request.
Expand All @@ -47,7 +48,7 @@
* 3) Delete unused parts.
*/
@CleanupTableInfo(cleanupTables = {OPEN_FILE_TABLE, FILE_TABLE, DELETED_TABLE,
MULTIPARTINFO_TABLE})
MULTIPARTINFO_TABLE, DIRECTORY_TABLE})
public class S3MultipartUploadCompleteResponseWithFSO
extends S3MultipartUploadCompleteResponse {

Expand Down