Skip to content

Commit

Permalink
HDDS-8649. Remove duplicate helper methods getDBMultipartOpenKey()
Browse files Browse the repository at this point in the history
  • Loading branch information
ceekay committed Jan 22, 2024
1 parent 27c1f9c commit c463b7f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@

import org.apache.hadoop.ozone.om.helpers.QuotaUtil;
import org.apache.hadoop.ozone.om.request.OMRequestTestUtils;
import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -568,8 +567,7 @@ public void testAbortUploadSuccessWithParts() throws Exception {
bucket.abortMultipartUpload(keyName, uploadID);

String multipartOpenKey =
getMultipartOpenKey(uploadID, volumeName, bucketName, keyName,
metadataMgr);
metadataMgr.getMultipartKeyFSO(volumeName, bucketName, keyName, uploadID);
OmKeyInfo omKeyInfo =
metadataMgr.getOpenKeyTable(bucketLayout).get(multipartOpenKey);
OmMultipartKeyInfo omMultipartKeyInfo =
Expand Down Expand Up @@ -853,8 +851,7 @@ private String verifyUploadedPart(String uploadID, String partName,
ozoneManager.getMetadataManager().getBucketTable().get(buckKey);
BucketLayout bucketLayout = buckInfo.getBucketLayout();
String multipartOpenKey =
getMultipartOpenKey(uploadID, volumeName, bucketName, keyName,
metadataMgr);
metadataMgr.getMultipartKeyFSO(volumeName, bucketName, keyName, uploadID);

String multipartKey = metadataMgr.getMultipartKey(volumeName, bucketName,
keyName, uploadID);
Expand All @@ -881,32 +878,6 @@ private String verifyUploadedPart(String uploadID, String partName,
return multipartKey;
}

private String getMultipartOpenKey(String multipartUploadID,
String volName, String buckName, String kName,
OMMetadataManager omMetadataManager) throws IOException {

String fileName = OzoneFSUtils.getFileName(kName);
final long volumeId = omMetadataManager.getVolumeId(volName);
final long bucketId = omMetadataManager.getBucketId(volName,
buckName);
long parentID = getParentID(volName, buckName, kName,
omMetadataManager);

String multipartKey = omMetadataManager.getMultipartKey(volumeId, bucketId,
parentID, fileName, multipartUploadID);

return multipartKey;
}

private long getParentID(String volName, String buckName,
String kName, OMMetadataManager omMetadataManager) throws IOException {
final long volumeId = omMetadataManager.getVolumeId(volName);
final long bucketId = omMetadataManager.getBucketId(volName,
buckName);
return OMFileRequest.getParentID(volumeId, bucketId,
kName, omMetadataManager);
}

private String initiateMultipartUpload(OzoneBucket oBucket, String kName,
ReplicationType replicationType, ReplicationFactor replicationFactor)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,19 @@ List<ExpiredMultipartUploadsBucket> getExpiredMultipartUploads(
String getMultipartKey(String volume, String bucket, String key, String
uploadId);

/**
* Returns the DB key name of a multipart upload key in OM metadata store
* for FSO-enabled buckets.
*
* @param volume - volume name
* @param bucket - bucket name
* @param key - key name
* @param uploadId - the upload id for this key
* @return bytes of DB key.
*/
String getMultipartKeyFSO(String volume, String bucket, String key, String
uploadId) throws IOException;


/**
* Gets the multipart info table which holds the information about
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
import org.apache.hadoop.ozone.om.request.OMClientRequest;
import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
import org.apache.hadoop.ozone.om.request.util.OMMultipartUploadUtils;
import org.apache.hadoop.ozone.om.service.DirectoryDeletingService;
import org.apache.hadoop.ozone.om.service.KeyDeletingService;
import org.apache.hadoop.ozone.om.service.MultipartUploadCleanupService;
Expand Down Expand Up @@ -836,7 +835,7 @@ public OmMultipartUploadListParts listParts(String volumeName,
//if there are no parts, use the replicationType from the open key.
if (isBucketFSOptimized(volumeName, bucketName)) {
multipartKey =
getMultipartOpenKeyFSO(volumeName, bucketName, keyName,
metadataManager.getMultipartKeyFSO(volumeName, bucketName, keyName,
uploadID);
}
OmKeyInfo omKeyInfo =
Expand Down Expand Up @@ -907,13 +906,6 @@ private String getPartName(PartKeyInfo partKeyInfo, String volName,
return partName;
}

private String getMultipartOpenKeyFSO(String volumeName, String bucketName,
String keyName, String uploadID) throws IOException {
OMMetadataManager metaMgr = metadataManager;
return OMMultipartUploadUtils.getMultipartOpenKeyFSO(
volumeName, bucketName, keyName, uploadID, metaMgr);
}

/**
* Returns list of ACLs for given Ozone object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import org.apache.hadoop.ozone.om.lock.OzoneManagerLock;
import org.apache.hadoop.hdds.utils.TransactionInfo;
import org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolClientSideTranslatorPB;
import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
import org.apache.hadoop.ozone.om.request.util.OMMultipartUploadUtils;
import org.apache.hadoop.ozone.om.snapshot.ReferenceCounted;
import org.apache.hadoop.ozone.om.snapshot.SnapshotCache;
Expand Down Expand Up @@ -113,6 +114,7 @@
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.OzoneConsts.OM_SNAPSHOT_CHECKPOINT_DIR;
import static org.apache.hadoop.ozone.om.request.file.OMFileRequest.getParentId;
import static org.apache.hadoop.ozone.om.service.SnapshotDeletingService.isBlockLocationInfoSame;
import static org.apache.hadoop.ozone.om.snapshot.SnapshotUtils.checkSnapshotDirExist;

Expand Down Expand Up @@ -863,6 +865,20 @@ public String getMultipartKey(String volume, String bucket, String key,
return OmMultipartUpload.getDbKey(volume, bucket, key, uploadId);
}

@Override
public String getMultipartKeyFSO(String volume, String bucket, String key, String uploadId) throws IOException {
final long volumeId = getVolumeId(volume);
final long bucketId = getBucketId(volume,
bucket);
long parentId =
OMFileRequest.getParentID(volumeId, bucketId, key, this);

String fileName = OzoneFSUtils.getFileName(key);

return getMultipartKey(volumeId, bucketId, parentId,
fileName, uploadId);
}

/**
* Returns the OzoneManagerLock used on Metadata DB.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
import org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo;
import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
import org.apache.hadoop.ozone.om.request.file.OMDirectoryCreateRequestWithFSO;
Expand All @@ -54,7 +53,6 @@
import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
import static org.apache.hadoop.ozone.om.request.file.OMFileRequest.OMDirectoryResult.DIRECTORY_EXISTS;
import static org.apache.hadoop.ozone.om.request.file.OMFileRequest.OMDirectoryResult.FILE_EXISTS_IN_GIVENPATH;
import static org.apache.hadoop.ozone.om.request.file.OMFileRequest.getParentId;

/**
* Handles CreateKey request layout version1.
Expand Down Expand Up @@ -253,16 +251,6 @@ protected String getDBMultipartOpenKey(String volumeName, String bucketName,
String keyName, String uploadID,
OMMetadataManager omMetadataManager)
throws IOException {

final long volumeId = omMetadataManager.getVolumeId(volumeName);
final long bucketId = omMetadataManager.getBucketId(volumeName,
bucketName);
long parentId =
getParentId(omMetadataManager, volumeName, bucketName, keyName);

String fileName = OzoneFSUtils.getFileName(keyName);

return omMetadataManager.getMultipartKey(volumeId, bucketId, parentId,
fileName, uploadID);
return omMetadataManager.getMultipartKeyFSO(volumeName, bucketName, keyName, uploadID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,7 @@ protected String getDBOzoneKey(OMMetadataManager omMetadataManager,
protected String getDBMultipartOpenKey(String volumeName, String bucketName,
String keyName, String uploadID, OMMetadataManager omMetadataManager)
throws IOException {

long parentId =
getParentId(omMetadataManager, volumeName, bucketName, keyName);

String fileName = keyName;
Path filePath = Paths.get(keyName).getFileName();
if (filePath != null) {
fileName = filePath.toString();
}

final long volumeId = omMetadataManager.getVolumeId(volumeName);
final long bucketId = omMetadataManager.getBucketId(volumeName,
bucketName);

return omMetadataManager.getMultipartKey(volumeId, bucketId,
parentId, fileName, uploadID);
return omMetadataManager.getMultipartKeyFSO(volumeName, bucketName, keyName, uploadID);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.apache.hadoop.ozone.om.OMMetadataManager;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
import org.apache.hadoop.ozone.om.request.file.OMFileRequest;

import java.io.IOException;
import java.util.UUID;
Expand Down Expand Up @@ -93,8 +91,7 @@ public static String getMultipartOpenKey(String volumeName,
OMMetadataManager omMetadataManager, BucketLayout bucketLayout)
throws IOException {
if (bucketLayout == BucketLayout.FILE_SYSTEM_OPTIMIZED) {
return getMultipartOpenKeyFSO(volumeName, bucketName,
keyName, multipartUploadId, omMetadataManager);
return omMetadataManager.getMultipartKeyFSO(volumeName, bucketName, keyName, multipartUploadId);
} else {
return getMultipartOpenKey(volumeName, bucketName,
keyName, multipartUploadId, omMetadataManager);
Expand All @@ -108,23 +105,6 @@ public static String getMultipartOpenKey(String volumeName,
volumeName, bucketName, keyName, multipartUploadId);
}

public static String getMultipartOpenKeyFSO(String volumeName,
String bucketName, String keyName, String uploadID,
OMMetadataManager metaMgr) throws IOException {
String fileName = OzoneFSUtils.getFileName(keyName);

final long volumeId = metaMgr.getVolumeId(volumeName);
final long bucketId = metaMgr.getBucketId(volumeName, bucketName);
long parentID =
OMFileRequest.getParentID(volumeId, bucketId,
keyName, metaMgr);

String multipartKey = metaMgr.getMultipartKey(volumeId, bucketId,
parentID, fileName, uploadID);

return multipartKey;
}


/**
* Check whether key's isMultipartKey flag is set.
Expand Down

0 comments on commit c463b7f

Please sign in to comment.