You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/02/05 11:30:57 UTC

[GitHub] [ozone] rakeshadr opened a new pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

rakeshadr opened a new pull request #1897:
URL: https://github.com/apache/ozone/pull/1897


   
   ## What changes were proposed in this pull request?
   
   Implemented create and commit upload part file request.
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-4781
   
   ## How was this patch tested?
   
   Added UT cases.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] linyiqun commented on a change in pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

Posted by GitBox <gi...@apache.org>.
linyiqun commented on a change in pull request #1897:
URL: https://github.com/apache/ozone/pull/1897#discussion_r571589976



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/multipart/S3MultipartUploadCommitPartRequestV1.java
##########
@@ -0,0 +1,247 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.request.s3.multipart;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
+import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.s3.multipart.S3MultipartUploadCommitPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handle Multipart upload commit upload part file.
+ */
+public class S3MultipartUploadCommitPartRequestV1
+        extends S3MultipartUploadCommitPartRequest {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(S3MultipartUploadCommitPartRequestV1.class);
+
+  public S3MultipartUploadCommitPartRequestV1(OMRequest omRequest) {
+    super(omRequest);
+  }
+
+  @Override
+  @SuppressWarnings("methodlength")
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+    MultipartCommitUploadPartRequest multipartCommitUploadPartRequest =
+        getOmRequest().getCommitMultiPartUploadRequest();
+
+    KeyArgs keyArgs = multipartCommitUploadPartRequest.getKeyArgs();
+    Map<String, String> auditMap = buildKeyArgsAuditMap(keyArgs);
+
+    String volumeName = keyArgs.getVolumeName();
+    String bucketName = keyArgs.getBucketName();
+    String keyName = keyArgs.getKeyName();
+
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+    ozoneManager.getMetrics().incNumCommitMultipartUploadParts();
+
+    boolean acquiredLock = false;
+
+    IOException exception = null;
+    String partName = null;
+    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(
+        getOmRequest());
+    OMClientResponse omClientResponse = null;
+    OzoneManagerProtocolProtos.PartKeyInfo oldPartKeyInfo = null;
+    String openKey = null;
+    OmKeyInfo omKeyInfo = null;
+    String multipartKey = null;
+    OmMultipartKeyInfo multipartKeyInfo = null;
+    Result result = null;
+    OmBucketInfo omBucketInfo = null;
+    OmBucketInfo copyBucketInfo = null;
+    try {
+      keyArgs = resolveBucketLink(ozoneManager, keyArgs, auditMap);
+      volumeName = keyArgs.getVolumeName();
+      bucketName = keyArgs.getBucketName();
+
+      // TODO to support S3 ACL later.
+      acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+          volumeName, bucketName);
+
+      validateBucketAndVolume(omMetadataManager, volumeName, bucketName);
+
+      String fileName = OzoneFSUtils.getFileName(keyName);
+      Iterator<Path> pathComponents = Paths.get(keyName).iterator();
+      String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
+      omBucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
+      long bucketId = omBucketInfo.getObjectID();
+      long parentID = OMFileRequest.getParentID(bucketId, pathComponents,
+              keyName, omMetadataManager);
+
+      String uploadID = keyArgs.getMultipartUploadID();
+      multipartKey = omMetadataManager.getMultipartKey(parentID,
+          fileName, uploadID);
+
+      multipartKeyInfo = omMetadataManager.getMultipartInfoTable()
+          .get(multipartKey);
+
+      long clientID = multipartCommitUploadPartRequest.getClientID();
+
+      openKey = omMetadataManager.getOpenFileName(parentID, fileName, clientID);
+
+      omKeyInfo = OMFileRequest.getOmKeyInfoFromFileTable(true,
+              omMetadataManager, openKey, keyName);
+
+      if (omKeyInfo == null) {
+        throw new OMException("Failed to commit Multipart Upload key, as " +
+            openKey + "entry is not found in the openKey table",
+            KEY_NOT_FOUND);
+      }
+
+      // set the data size and location info list
+      omKeyInfo.setDataSize(keyArgs.getDataSize());
+      omKeyInfo.updateLocationInfoList(keyArgs.getKeyLocationsList().stream()
+          .map(OmKeyLocationInfo::getFromProtobuf)
+          .collect(Collectors.toList()));
+      // Set Modification time
+      omKeyInfo.setModificationTime(keyArgs.getModificationTime());
+      // Set the UpdateID to current transactionLogIndex
+      omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
+
+      String ozoneKey = omMetadataManager.getOzonePathKey(parentID, fileName);
+      partName = ozoneKey + clientID;
+
+      if (multipartKeyInfo == null) {
+        // This can occur when user started uploading part by the time commit
+        // of that part happens, in between the user might have requested
+        // abort multipart upload. If we just throw exception, then the data
+        // will not be garbage collected, so move this part to delete table
+        // and throw error
+        // Move this part to delete table.
+        throw new OMException("No such Multipart upload is with specified " +
+            "uploadId " + uploadID,
+            OMException.ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
+      }
+
+      int partNumber = keyArgs.getMultipartNumber();
+      oldPartKeyInfo = multipartKeyInfo.getPartKeyInfo(partNumber);
+
+      // Build this multipart upload part info.
+      OzoneManagerProtocolProtos.PartKeyInfo.Builder partKeyInfo =
+          OzoneManagerProtocolProtos.PartKeyInfo.newBuilder();
+      partKeyInfo.setPartName(partName);
+      partKeyInfo.setPartNumber(partNumber);
+      partKeyInfo.setPartKeyInfo(omKeyInfo.getProtobuf(
+          getOmRequest().getVersion()));
+
+      // Add this part information in to multipartKeyInfo.
+      multipartKeyInfo.addPartKeyInfo(partNumber, partKeyInfo.build());
+
+      // Set the UpdateID to current transactionLogIndex
+      multipartKeyInfo.setUpdateID(trxnLogIndex,
+          ozoneManager.isRatisEnabled());
+
+      // OldPartKeyInfo will be deleted. Its updateID will be set in
+      // S3MultipartUplodaCommitPartResponse before being added to
+      // DeletedKeyTable.
+
+      // Add to cache.
+
+      // Delete from open key table and add it to multipart info table.
+      // No need to add cache entries to delete table, as no
+      // read/write requests that info for validation.
+      omMetadataManager.getMultipartInfoTable().addCacheEntry(
+          new CacheKey<>(multipartKey),
+          new CacheValue<>(Optional.of(multipartKeyInfo),
+              trxnLogIndex));
+
+      omMetadataManager.getOpenKeyTable().addCacheEntry(
+          new CacheKey<>(openKey),

Review comment:
       I noticed that in S3InitiateMultipartUploadRequest, we also use multipartKey as the open key inserted into openKey table. Why here we have a new open key defined for this? Not so fully get this. 

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/multipart/S3MultipartUploadCommitPartRequestV1.java
##########
@@ -0,0 +1,247 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.request.s3.multipart;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
+import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.s3.multipart.S3MultipartUploadCommitPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handle Multipart upload commit upload part file.
+ */
+public class S3MultipartUploadCommitPartRequestV1
+        extends S3MultipartUploadCommitPartRequest {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(S3MultipartUploadCommitPartRequestV1.class);
+
+  public S3MultipartUploadCommitPartRequestV1(OMRequest omRequest) {
+    super(omRequest);
+  }
+
+  @Override
+  @SuppressWarnings("methodlength")
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+    MultipartCommitUploadPartRequest multipartCommitUploadPartRequest =
+        getOmRequest().getCommitMultiPartUploadRequest();
+
+    KeyArgs keyArgs = multipartCommitUploadPartRequest.getKeyArgs();
+    Map<String, String> auditMap = buildKeyArgsAuditMap(keyArgs);
+
+    String volumeName = keyArgs.getVolumeName();
+    String bucketName = keyArgs.getBucketName();
+    String keyName = keyArgs.getKeyName();
+
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+    ozoneManager.getMetrics().incNumCommitMultipartUploadParts();
+
+    boolean acquiredLock = false;
+
+    IOException exception = null;
+    String partName = null;
+    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(
+        getOmRequest());
+    OMClientResponse omClientResponse = null;
+    OzoneManagerProtocolProtos.PartKeyInfo oldPartKeyInfo = null;
+    String openKey = null;
+    OmKeyInfo omKeyInfo = null;
+    String multipartKey = null;
+    OmMultipartKeyInfo multipartKeyInfo = null;
+    Result result = null;
+    OmBucketInfo omBucketInfo = null;
+    OmBucketInfo copyBucketInfo = null;
+    try {
+      keyArgs = resolveBucketLink(ozoneManager, keyArgs, auditMap);
+      volumeName = keyArgs.getVolumeName();
+      bucketName = keyArgs.getBucketName();
+
+      // TODO to support S3 ACL later.
+      acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+          volumeName, bucketName);
+
+      validateBucketAndVolume(omMetadataManager, volumeName, bucketName);
+
+      String fileName = OzoneFSUtils.getFileName(keyName);
+      Iterator<Path> pathComponents = Paths.get(keyName).iterator();
+      String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
+      omBucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
+      long bucketId = omBucketInfo.getObjectID();
+      long parentID = OMFileRequest.getParentID(bucketId, pathComponents,
+              keyName, omMetadataManager);
+
+      String uploadID = keyArgs.getMultipartUploadID();
+      multipartKey = omMetadataManager.getMultipartKey(parentID,
+          fileName, uploadID);
+
+      multipartKeyInfo = omMetadataManager.getMultipartInfoTable()
+          .get(multipartKey);
+
+      long clientID = multipartCommitUploadPartRequest.getClientID();
+
+      openKey = omMetadataManager.getOpenFileName(parentID, fileName, clientID);
+
+      omKeyInfo = OMFileRequest.getOmKeyInfoFromFileTable(true,
+              omMetadataManager, openKey, keyName);
+
+      if (omKeyInfo == null) {
+        throw new OMException("Failed to commit Multipart Upload key, as " +
+            openKey + "entry is not found in the openKey table",
+            KEY_NOT_FOUND);
+      }
+
+      // set the data size and location info list
+      omKeyInfo.setDataSize(keyArgs.getDataSize());
+      omKeyInfo.updateLocationInfoList(keyArgs.getKeyLocationsList().stream()
+          .map(OmKeyLocationInfo::getFromProtobuf)
+          .collect(Collectors.toList()));
+      // Set Modification time
+      omKeyInfo.setModificationTime(keyArgs.getModificationTime());
+      // Set the UpdateID to current transactionLogIndex
+      omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
+
+      String ozoneKey = omMetadataManager.getOzonePathKey(parentID, fileName);
+      partName = ozoneKey + clientID;
+
+      if (multipartKeyInfo == null) {
+        // This can occur when user started uploading part by the time commit
+        // of that part happens, in between the user might have requested
+        // abort multipart upload. If we just throw exception, then the data
+        // will not be garbage collected, so move this part to delete table
+        // and throw error
+        // Move this part to delete table.
+        throw new OMException("No such Multipart upload is with specified " +
+            "uploadId " + uploadID,
+            OMException.ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
+      }
+
+      int partNumber = keyArgs.getMultipartNumber();
+      oldPartKeyInfo = multipartKeyInfo.getPartKeyInfo(partNumber);
+
+      // Build this multipart upload part info.
+      OzoneManagerProtocolProtos.PartKeyInfo.Builder partKeyInfo =
+          OzoneManagerProtocolProtos.PartKeyInfo.newBuilder();
+      partKeyInfo.setPartName(partName);
+      partKeyInfo.setPartNumber(partNumber);
+      partKeyInfo.setPartKeyInfo(omKeyInfo.getProtobuf(
+          getOmRequest().getVersion()));
+
+      // Add this part information in to multipartKeyInfo.
+      multipartKeyInfo.addPartKeyInfo(partNumber, partKeyInfo.build());
+
+      // Set the UpdateID to current transactionLogIndex
+      multipartKeyInfo.setUpdateID(trxnLogIndex,
+          ozoneManager.isRatisEnabled());
+
+      // OldPartKeyInfo will be deleted. Its updateID will be set in
+      // S3MultipartUplodaCommitPartResponse before being added to
+      // DeletedKeyTable.
+
+      // Add to cache.
+
+      // Delete from open key table and add it to multipart info table.
+      // No need to add cache entries to delete table, as no
+      // read/write requests that info for validation.
+      omMetadataManager.getMultipartInfoTable().addCacheEntry(
+          new CacheKey<>(multipartKey),
+          new CacheValue<>(Optional.of(multipartKeyInfo),
+              trxnLogIndex));
+
+      omMetadataManager.getOpenKeyTable().addCacheEntry(
+          new CacheKey<>(openKey),
+          new CacheValue<>(Optional.absent(), trxnLogIndex));
+
+      long scmBlockSize = ozoneManager.getScmBlockSize();
+      int factor = omKeyInfo.getFactor().getNumber();
+      omBucketInfo = getBucketInfo(omMetadataManager, volumeName, bucketName);
+      // Block was pre-requested and UsedBytes updated when createKey and
+      // AllocatedBlock. The space occupied by the Key shall be based on
+      // the actual Key size, and the total Block size applied before should
+      // be subtracted.
+      long correctedSpace = omKeyInfo.getDataSize() * factor -
+          keyArgs.getKeyLocationsList().size() * scmBlockSize * factor;
+      omBucketInfo.incrUsedBytes(correctedSpace);
+
+      omResponse.setCommitMultiPartUploadResponse(
+          MultipartCommitUploadPartResponse.newBuilder()
+              .setPartName(partName));
+      omClientResponse = new S3MultipartUploadCommitPartResponse(

Review comment:
       Suppose we still need to have S3MultipartUploadCommitPartResponseV1 class. The cleanup table of OPEN_KEY_TABLE in S3MultipartUploadCommitPartResponse should replaced by OPEN_FILE_TABLE.
   ```java
   @CleanupTableInfo(cleanupTables = {OPEN_KEY_TABLE, DELETED_TABLE,
       MULTIPARTINFO_TABLE})
   public class S3MultipartUploadCommitPartResponse extends OMClientResponse {
   ...
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] mukul1987 commented on a change in pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

Posted by GitBox <gi...@apache.org>.
mukul1987 commented on a change in pull request #1897:
URL: https://github.com/apache/ozone/pull/1897#discussion_r571655445



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMKeyRequest.java
##########
@@ -661,9 +661,17 @@ private OmKeyInfo prepareMultipartFileInfo(
     // error no such multipart upload.
     String uploadID = args.getMultipartUploadID();
     Preconditions.checkNotNull(uploadID);
-    String multipartKey = omMetadataManager
-            .getMultipartKey(args.getVolumeName(), args.getBucketName(),
-                    args.getKeyName(), uploadID);
+    String multipartKey = "";
+    if (omPathInfo != null) {
+      // FileTable metadata format
+      multipartKey =
+              omMetadataManager.getMultipartKey(omPathInfo.getLastKnownParentId(),
+                      omPathInfo.getLeafNodeName(), uploadID);
+    } else {
+      multipartKey = omMetadataManager

Review comment:
       This code should ideally never be called, as this function is specific to Prefix optimizations. Should be add a precondition here saying, Not reachable code ?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] rakeshadr commented on a change in pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

Posted by GitBox <gi...@apache.org>.
rakeshadr commented on a change in pull request #1897:
URL: https://github.com/apache/ozone/pull/1897#discussion_r572785595



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/multipart/S3MultipartUploadCommitPartRequestV1.java
##########
@@ -0,0 +1,247 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.request.s3.multipart;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
+import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.s3.multipart.S3MultipartUploadCommitPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handle Multipart upload commit upload part file.
+ */
+public class S3MultipartUploadCommitPartRequestV1
+        extends S3MultipartUploadCommitPartRequest {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(S3MultipartUploadCommitPartRequestV1.class);
+
+  public S3MultipartUploadCommitPartRequestV1(OMRequest omRequest) {
+    super(omRequest);
+  }
+
+  @Override
+  @SuppressWarnings("methodlength")
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+    MultipartCommitUploadPartRequest multipartCommitUploadPartRequest =
+        getOmRequest().getCommitMultiPartUploadRequest();
+
+    KeyArgs keyArgs = multipartCommitUploadPartRequest.getKeyArgs();
+    Map<String, String> auditMap = buildKeyArgsAuditMap(keyArgs);
+
+    String volumeName = keyArgs.getVolumeName();
+    String bucketName = keyArgs.getBucketName();
+    String keyName = keyArgs.getKeyName();
+
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+    ozoneManager.getMetrics().incNumCommitMultipartUploadParts();
+
+    boolean acquiredLock = false;
+
+    IOException exception = null;
+    String partName = null;
+    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(
+        getOmRequest());
+    OMClientResponse omClientResponse = null;
+    OzoneManagerProtocolProtos.PartKeyInfo oldPartKeyInfo = null;
+    String openKey = null;
+    OmKeyInfo omKeyInfo = null;
+    String multipartKey = null;
+    OmMultipartKeyInfo multipartKeyInfo = null;
+    Result result = null;
+    OmBucketInfo omBucketInfo = null;
+    OmBucketInfo copyBucketInfo = null;
+    try {
+      keyArgs = resolveBucketLink(ozoneManager, keyArgs, auditMap);
+      volumeName = keyArgs.getVolumeName();
+      bucketName = keyArgs.getBucketName();
+
+      // TODO to support S3 ACL later.
+      acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+          volumeName, bucketName);
+
+      validateBucketAndVolume(omMetadataManager, volumeName, bucketName);
+
+      String fileName = OzoneFSUtils.getFileName(keyName);
+      Iterator<Path> pathComponents = Paths.get(keyName).iterator();
+      String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
+      omBucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
+      long bucketId = omBucketInfo.getObjectID();
+      long parentID = OMFileRequest.getParentID(bucketId, pathComponents,
+              keyName, omMetadataManager);
+
+      String uploadID = keyArgs.getMultipartUploadID();
+      multipartKey = omMetadataManager.getMultipartKey(parentID,
+          fileName, uploadID);
+
+      multipartKeyInfo = omMetadataManager.getMultipartInfoTable()
+          .get(multipartKey);
+
+      long clientID = multipartCommitUploadPartRequest.getClientID();
+
+      openKey = omMetadataManager.getOpenFileName(parentID, fileName, clientID);
+
+      omKeyInfo = OMFileRequest.getOmKeyInfoFromFileTable(true,
+              omMetadataManager, openKey, keyName);
+
+      if (omKeyInfo == null) {
+        throw new OMException("Failed to commit Multipart Upload key, as " +
+            openKey + "entry is not found in the openKey table",
+            KEY_NOT_FOUND);
+      }
+
+      // set the data size and location info list
+      omKeyInfo.setDataSize(keyArgs.getDataSize());
+      omKeyInfo.updateLocationInfoList(keyArgs.getKeyLocationsList().stream()
+          .map(OmKeyLocationInfo::getFromProtobuf)
+          .collect(Collectors.toList()));
+      // Set Modification time
+      omKeyInfo.setModificationTime(keyArgs.getModificationTime());
+      // Set the UpdateID to current transactionLogIndex
+      omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
+
+      String ozoneKey = omMetadataManager.getOzonePathKey(parentID, fileName);
+      partName = ozoneKey + clientID;
+
+      if (multipartKeyInfo == null) {
+        // This can occur when user started uploading part by the time commit
+        // of that part happens, in between the user might have requested
+        // abort multipart upload. If we just throw exception, then the data
+        // will not be garbage collected, so move this part to delete table
+        // and throw error
+        // Move this part to delete table.
+        throw new OMException("No such Multipart upload is with specified " +
+            "uploadId " + uploadID,
+            OMException.ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
+      }
+
+      int partNumber = keyArgs.getMultipartNumber();
+      oldPartKeyInfo = multipartKeyInfo.getPartKeyInfo(partNumber);
+
+      // Build this multipart upload part info.
+      OzoneManagerProtocolProtos.PartKeyInfo.Builder partKeyInfo =
+          OzoneManagerProtocolProtos.PartKeyInfo.newBuilder();
+      partKeyInfo.setPartName(partName);
+      partKeyInfo.setPartNumber(partNumber);
+      partKeyInfo.setPartKeyInfo(omKeyInfo.getProtobuf(
+          getOmRequest().getVersion()));
+
+      // Add this part information in to multipartKeyInfo.
+      multipartKeyInfo.addPartKeyInfo(partNumber, partKeyInfo.build());
+
+      // Set the UpdateID to current transactionLogIndex
+      multipartKeyInfo.setUpdateID(trxnLogIndex,
+          ozoneManager.isRatisEnabled());
+
+      // OldPartKeyInfo will be deleted. Its updateID will be set in
+      // S3MultipartUplodaCommitPartResponse before being added to
+      // DeletedKeyTable.
+
+      // Add to cache.

Review comment:
       I copied this comments "Add to cache" from V0 S3MultipartUploadCommitPartRequest class. I think, its added to convey that the entry will be added to cache and later will do the commit operation. Its Request framework logic and anyway its not a important comment and I will remove it. Hope this is same thought you also have, right?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] rakeshadr commented on a change in pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

Posted by GitBox <gi...@apache.org>.
rakeshadr commented on a change in pull request #1897:
URL: https://github.com/apache/ozone/pull/1897#discussion_r572956963



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/multipart/S3MultipartUploadCommitPartRequestV1.java
##########
@@ -0,0 +1,247 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.request.s3.multipart;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
+import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.s3.multipart.S3MultipartUploadCommitPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handle Multipart upload commit upload part file.
+ */
+public class S3MultipartUploadCommitPartRequestV1
+        extends S3MultipartUploadCommitPartRequest {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(S3MultipartUploadCommitPartRequestV1.class);
+
+  public S3MultipartUploadCommitPartRequestV1(OMRequest omRequest) {
+    super(omRequest);
+  }
+
+  @Override
+  @SuppressWarnings("methodlength")
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+    MultipartCommitUploadPartRequest multipartCommitUploadPartRequest =
+        getOmRequest().getCommitMultiPartUploadRequest();
+
+    KeyArgs keyArgs = multipartCommitUploadPartRequest.getKeyArgs();
+    Map<String, String> auditMap = buildKeyArgsAuditMap(keyArgs);
+
+    String volumeName = keyArgs.getVolumeName();
+    String bucketName = keyArgs.getBucketName();
+    String keyName = keyArgs.getKeyName();
+
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+    ozoneManager.getMetrics().incNumCommitMultipartUploadParts();
+
+    boolean acquiredLock = false;
+
+    IOException exception = null;
+    String partName = null;
+    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(
+        getOmRequest());
+    OMClientResponse omClientResponse = null;
+    OzoneManagerProtocolProtos.PartKeyInfo oldPartKeyInfo = null;
+    String openKey = null;
+    OmKeyInfo omKeyInfo = null;
+    String multipartKey = null;
+    OmMultipartKeyInfo multipartKeyInfo = null;
+    Result result = null;
+    OmBucketInfo omBucketInfo = null;
+    OmBucketInfo copyBucketInfo = null;
+    try {
+      keyArgs = resolveBucketLink(ozoneManager, keyArgs, auditMap);
+      volumeName = keyArgs.getVolumeName();
+      bucketName = keyArgs.getBucketName();
+
+      // TODO to support S3 ACL later.
+      acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+          volumeName, bucketName);
+
+      validateBucketAndVolume(omMetadataManager, volumeName, bucketName);
+
+      String fileName = OzoneFSUtils.getFileName(keyName);
+      Iterator<Path> pathComponents = Paths.get(keyName).iterator();
+      String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
+      omBucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
+      long bucketId = omBucketInfo.getObjectID();
+      long parentID = OMFileRequest.getParentID(bucketId, pathComponents,
+              keyName, omMetadataManager);
+
+      String uploadID = keyArgs.getMultipartUploadID();
+      multipartKey = omMetadataManager.getMultipartKey(parentID,
+          fileName, uploadID);
+
+      multipartKeyInfo = omMetadataManager.getMultipartInfoTable()
+          .get(multipartKey);
+
+      long clientID = multipartCommitUploadPartRequest.getClientID();
+
+      openKey = omMetadataManager.getOpenFileName(parentID, fileName, clientID);
+
+      omKeyInfo = OMFileRequest.getOmKeyInfoFromFileTable(true,
+              omMetadataManager, openKey, keyName);
+
+      if (omKeyInfo == null) {
+        throw new OMException("Failed to commit Multipart Upload key, as " +
+            openKey + "entry is not found in the openKey table",
+            KEY_NOT_FOUND);
+      }
+
+      // set the data size and location info list
+      omKeyInfo.setDataSize(keyArgs.getDataSize());
+      omKeyInfo.updateLocationInfoList(keyArgs.getKeyLocationsList().stream()
+          .map(OmKeyLocationInfo::getFromProtobuf)
+          .collect(Collectors.toList()));
+      // Set Modification time
+      omKeyInfo.setModificationTime(keyArgs.getModificationTime());
+      // Set the UpdateID to current transactionLogIndex
+      omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
+
+      String ozoneKey = omMetadataManager.getOzonePathKey(parentID, fileName);
+      partName = ozoneKey + clientID;
+
+      if (multipartKeyInfo == null) {
+        // This can occur when user started uploading part by the time commit
+        // of that part happens, in between the user might have requested
+        // abort multipart upload. If we just throw exception, then the data
+        // will not be garbage collected, so move this part to delete table
+        // and throw error
+        // Move this part to delete table.
+        throw new OMException("No such Multipart upload is with specified " +
+            "uploadId " + uploadID,
+            OMException.ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
+      }
+
+      int partNumber = keyArgs.getMultipartNumber();
+      oldPartKeyInfo = multipartKeyInfo.getPartKeyInfo(partNumber);
+
+      // Build this multipart upload part info.
+      OzoneManagerProtocolProtos.PartKeyInfo.Builder partKeyInfo =
+          OzoneManagerProtocolProtos.PartKeyInfo.newBuilder();
+      partKeyInfo.setPartName(partName);
+      partKeyInfo.setPartNumber(partNumber);
+      partKeyInfo.setPartKeyInfo(omKeyInfo.getProtobuf(
+          getOmRequest().getVersion()));
+
+      // Add this part information in to multipartKeyInfo.
+      multipartKeyInfo.addPartKeyInfo(partNumber, partKeyInfo.build());
+
+      // Set the UpdateID to current transactionLogIndex
+      multipartKeyInfo.setUpdateID(trxnLogIndex,
+          ozoneManager.isRatisEnabled());
+
+      // OldPartKeyInfo will be deleted. Its updateID will be set in
+      // S3MultipartUplodaCommitPartResponse before being added to
+      // DeletedKeyTable.
+
+      // Add to cache.
+
+      // Delete from open key table and add it to multipart info table.
+      // No need to add cache entries to delete table, as no
+      // read/write requests that info for validation.
+      omMetadataManager.getMultipartInfoTable().addCacheEntry(
+          new CacheKey<>(multipartKey),
+          new CacheValue<>(Optional.of(multipartKeyInfo),
+              trxnLogIndex));
+
+      omMetadataManager.getOpenKeyTable().addCacheEntry(
+          new CacheKey<>(openKey),

Review comment:
       During the S3 lifecycle, OpenKeyTable is used to store a multipartKey(in step-1) and a part key for a multipart upload(in step2). I'm referring to the [above steps](https://github.com/apache/ozone/pull/1897#discussion_r572803982) that I mentioned in my previous comment.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] rakeshadr commented on a change in pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

Posted by GitBox <gi...@apache.org>.
rakeshadr commented on a change in pull request #1897:
URL: https://github.com/apache/ozone/pull/1897#discussion_r573496871



##########
File path: hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/s3/multipart/TestS3MultipartUploadCommitPartResponseV1.java
##########
@@ -0,0 +1,226 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.response.s3.multipart;
+
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo;
+import org.apache.hadoop.ozone.om.request.TestOMRequestUtils;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PartKeyInfo;
+import org.apache.hadoop.util.Time;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.UUID;
+
+/**
+ * Test multipart upload commit part response.
+ */
+public class TestS3MultipartUploadCommitPartResponseV1
+    extends TestS3MultipartResponse {
+
+  private String dirName = "a/b/c/";
+
+  private long parentID;
+
+  @Test
+  public void testAddDBToBatch() throws Exception {
+    String volumeName = UUID.randomUUID().toString();
+    String bucketName = UUID.randomUUID().toString();
+    String keyName = getKeyName();
+    String multipartUploadID = UUID.randomUUID().toString();
+
+    TestOMRequestUtils.addVolumeAndBucketToDB(volumeName, bucketName,
+            omMetadataManager);
+
+    createParentPath(volumeName, bucketName);
+    String fileName = OzoneFSUtils.getFileName(keyName);
+    String multipartKey = omMetadataManager.getMultipartKey(parentID, fileName,
+            multipartUploadID);
+    long clientId = Time.now();
+    String openKey = omMetadataManager.getOpenFileName(parentID, fileName,
+            clientId);
+
+    S3MultipartUploadCommitPartResponse s3MultipartUploadCommitPartResponse =
+        createS3CommitMPUResponseV1(volumeName, bucketName, parentID, keyName,
+            multipartUploadID, null, null,
+                OzoneManagerProtocolProtos.Status.OK, openKey);
+
+    s3MultipartUploadCommitPartResponse.addToDBBatch(omMetadataManager,
+        batchOperation);
+
+    omMetadataManager.getStore().commitBatchOperation(batchOperation);
+
+    Assert.assertNull(omMetadataManager.getOpenKeyTable().get(multipartKey));
+    Assert.assertNotNull(
+        omMetadataManager.getMultipartInfoTable().get(multipartKey));
+
+    // As no parts are created, so no entries should be there in delete table.
+    Assert.assertTrue(omMetadataManager.countRowsInTable(
+            omMetadataManager.getDeletedTable()) == 0);
+  }
+
+  @Test
+  public void testAddDBToBatchWithParts() throws Exception {
+
+    String volumeName = UUID.randomUUID().toString();
+    String bucketName = UUID.randomUUID().toString();
+    String keyName = getKeyName();
+
+    TestOMRequestUtils.addVolumeAndBucketToDB(volumeName, bucketName,
+            omMetadataManager);
+    createParentPath(volumeName, bucketName);
+
+    String multipartUploadID = UUID.randomUUID().toString();
+
+    String fileName = OzoneFSUtils.getFileName(keyName);
+    String multipartKey = omMetadataManager.getMultipartKey(parentID, fileName,
+            multipartUploadID);
+
+    S3InitiateMultipartUploadResponse s3InitiateMultipartUploadResponseV1 =
+            createS3InitiateMPUResponseV1(volumeName, bucketName, parentID,
+                    keyName, multipartUploadID, new ArrayList<>());
+
+    s3InitiateMultipartUploadResponseV1.addToDBBatch(omMetadataManager,
+            batchOperation);
+
+    // Add some dummy parts for testing.
+    // Not added any key locations, as this just test is to see entries are
+    // adding to delete table or not.
+    OmMultipartKeyInfo omMultipartKeyInfo =
+            s3InitiateMultipartUploadResponseV1.getOmMultipartKeyInfo();
+
+    PartKeyInfo part1 = createPartKeyInfoV1(volumeName, bucketName, parentID,
+        fileName, 1);
+
+    addPart(1, part1, omMultipartKeyInfo);
+
+    long clientId = Time.now();
+    String openKey = omMetadataManager.getOpenFileName(parentID, fileName,
+            clientId);
+
+    S3MultipartUploadCommitPartResponse s3MultipartUploadCommitPartResponse =
+            createS3CommitMPUResponseV1(volumeName, bucketName, parentID,
+                    keyName, multipartUploadID,
+                    omMultipartKeyInfo.getPartKeyInfo(1),
+                    omMultipartKeyInfo,
+                    OzoneManagerProtocolProtos.Status.OK,  openKey);
+
+    s3MultipartUploadCommitPartResponse.checkAndUpdateDB(omMetadataManager,
+            batchOperation);
+
+    Assert.assertNull(omMetadataManager.getOpenKeyTable().get(multipartKey));
+    Assert.assertNull(
+        omMetadataManager.getMultipartInfoTable().get(multipartKey));
+
+    omMetadataManager.getStore().commitBatchOperation(batchOperation);
+
+    // As 1 parts are created, so 1 entry should be there in delete table.
+    Assert.assertTrue(omMetadataManager.countRowsInTable(
+        omMetadataManager.getDeletedTable()) == 1);
+
+    String part1DeletedKeyName =
+        omMultipartKeyInfo.getPartKeyInfo(1).getPartName();
+
+    Assert.assertNotNull(omMetadataManager.getDeletedTable().get(
+        part1DeletedKeyName));
+
+    RepeatedOmKeyInfo ro =
+        omMetadataManager.getDeletedTable().get(part1DeletedKeyName);
+    Assert.assertEquals(OmKeyInfo.getFromProtobuf(part1.getPartKeyInfo()),
+        ro.getOmKeyInfoList().get(0));
+  }
+
+  @Test
+  public void testWithMultipartUploadError() throws Exception {
+
+    String volumeName = UUID.randomUUID().toString();
+    String bucketName = UUID.randomUUID().toString();
+    String keyName = getKeyName();
+
+    TestOMRequestUtils.addVolumeAndBucketToDB(volumeName, bucketName,
+            omMetadataManager);
+    createParentPath(volumeName, bucketName);
+
+    String multipartUploadID = UUID.randomUUID().toString();
+
+    String fileName = OzoneFSUtils.getFileName(keyName);
+    String multipartKey = omMetadataManager.getMultipartKey(parentID, fileName,
+            multipartUploadID);
+
+    S3InitiateMultipartUploadResponse s3InitiateMultipartUploadResponseV1 =
+            createS3InitiateMPUResponseV1(volumeName, bucketName, parentID,
+                    keyName, multipartUploadID, new ArrayList<>());
+
+    s3InitiateMultipartUploadResponseV1.addToDBBatch(omMetadataManager,
+            batchOperation);
+
+    // Add some dummy parts for testing.
+    // Not added any key locations, as this just test is to see entries are
+    // adding to delete table or not.
+    OmMultipartKeyInfo omMultipartKeyInfo =
+            s3InitiateMultipartUploadResponseV1.getOmMultipartKeyInfo();
+
+    PartKeyInfo part1 = createPartKeyInfoV1(volumeName, bucketName, parentID,
+            fileName, 1);
+
+    addPart(1, part1, omMultipartKeyInfo);
+
+    long clientId = Time.now();
+    String openKey = omMetadataManager.getOpenFileName(parentID, fileName,
+            clientId);
+
+    S3MultipartUploadCommitPartResponse s3MultipartUploadCommitPartResponse =
+            createS3CommitMPUResponseV1(volumeName, bucketName, parentID,
+                    keyName + "invalid", multipartUploadID,
+                    omMultipartKeyInfo.getPartKeyInfo(1),
+                    omMultipartKeyInfo, OzoneManagerProtocolProtos.Status
+                            .NO_SUCH_MULTIPART_UPLOAD_ERROR, openKey);
+
+    s3MultipartUploadCommitPartResponse.checkAndUpdateDB(omMetadataManager,
+            batchOperation);
+
+    Assert.assertNull(omMetadataManager.getOpenKeyTable().get(multipartKey));
+    Assert.assertNull(
+            omMetadataManager.getMultipartInfoTable().get(multipartKey));
+
+    omMetadataManager.getStore().commitBatchOperation(batchOperation);
+
+    // As 1 parts are created, so 1 entry should be there in delete table.
+    Assert.assertTrue(omMetadataManager.countRowsInTable(
+            omMetadataManager.getDeletedTable()) == 1);

Review comment:
       Fixed.

##########
File path: hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/s3/multipart/TestS3MultipartUploadCommitPartResponseV1.java
##########
@@ -0,0 +1,226 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.response.s3.multipart;
+
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo;
+import org.apache.hadoop.ozone.om.request.TestOMRequestUtils;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PartKeyInfo;
+import org.apache.hadoop.util.Time;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.UUID;
+
+/**
+ * Test multipart upload commit part response.
+ */
+public class TestS3MultipartUploadCommitPartResponseV1
+    extends TestS3MultipartResponse {
+
+  private String dirName = "a/b/c/";
+
+  private long parentID;
+
+  @Test
+  public void testAddDBToBatch() throws Exception {
+    String volumeName = UUID.randomUUID().toString();
+    String bucketName = UUID.randomUUID().toString();
+    String keyName = getKeyName();
+    String multipartUploadID = UUID.randomUUID().toString();
+
+    TestOMRequestUtils.addVolumeAndBucketToDB(volumeName, bucketName,
+            omMetadataManager);
+
+    createParentPath(volumeName, bucketName);
+    String fileName = OzoneFSUtils.getFileName(keyName);
+    String multipartKey = omMetadataManager.getMultipartKey(parentID, fileName,
+            multipartUploadID);
+    long clientId = Time.now();
+    String openKey = omMetadataManager.getOpenFileName(parentID, fileName,
+            clientId);
+
+    S3MultipartUploadCommitPartResponse s3MultipartUploadCommitPartResponse =
+        createS3CommitMPUResponseV1(volumeName, bucketName, parentID, keyName,
+            multipartUploadID, null, null,
+                OzoneManagerProtocolProtos.Status.OK, openKey);
+
+    s3MultipartUploadCommitPartResponse.addToDBBatch(omMetadataManager,
+        batchOperation);
+
+    omMetadataManager.getStore().commitBatchOperation(batchOperation);
+
+    Assert.assertNull(omMetadataManager.getOpenKeyTable().get(multipartKey));
+    Assert.assertNotNull(
+        omMetadataManager.getMultipartInfoTable().get(multipartKey));
+
+    // As no parts are created, so no entries should be there in delete table.
+    Assert.assertTrue(omMetadataManager.countRowsInTable(
+            omMetadataManager.getDeletedTable()) == 0);

Review comment:
       Fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] linyiqun commented on a change in pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

Posted by GitBox <gi...@apache.org>.
linyiqun commented on a change in pull request #1897:
URL: https://github.com/apache/ozone/pull/1897#discussion_r573493128



##########
File path: hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/s3/multipart/TestS3MultipartUploadCommitPartResponseV1.java
##########
@@ -0,0 +1,226 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.response.s3.multipart;
+
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo;
+import org.apache.hadoop.ozone.om.request.TestOMRequestUtils;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PartKeyInfo;
+import org.apache.hadoop.util.Time;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.UUID;
+
+/**
+ * Test multipart upload commit part response.
+ */
+public class TestS3MultipartUploadCommitPartResponseV1
+    extends TestS3MultipartResponse {
+
+  private String dirName = "a/b/c/";
+
+  private long parentID;
+
+  @Test
+  public void testAddDBToBatch() throws Exception {
+    String volumeName = UUID.randomUUID().toString();
+    String bucketName = UUID.randomUUID().toString();
+    String keyName = getKeyName();
+    String multipartUploadID = UUID.randomUUID().toString();
+
+    TestOMRequestUtils.addVolumeAndBucketToDB(volumeName, bucketName,
+            omMetadataManager);
+
+    createParentPath(volumeName, bucketName);
+    String fileName = OzoneFSUtils.getFileName(keyName);
+    String multipartKey = omMetadataManager.getMultipartKey(parentID, fileName,
+            multipartUploadID);
+    long clientId = Time.now();
+    String openKey = omMetadataManager.getOpenFileName(parentID, fileName,
+            clientId);
+
+    S3MultipartUploadCommitPartResponse s3MultipartUploadCommitPartResponse =
+        createS3CommitMPUResponseV1(volumeName, bucketName, parentID, keyName,
+            multipartUploadID, null, null,
+                OzoneManagerProtocolProtos.Status.OK, openKey);
+
+    s3MultipartUploadCommitPartResponse.addToDBBatch(omMetadataManager,
+        batchOperation);
+
+    omMetadataManager.getStore().commitBatchOperation(batchOperation);
+
+    Assert.assertNull(omMetadataManager.getOpenKeyTable().get(multipartKey));
+    Assert.assertNotNull(
+        omMetadataManager.getMultipartInfoTable().get(multipartKey));
+
+    // As no parts are created, so no entries should be there in delete table.
+    Assert.assertTrue(omMetadataManager.countRowsInTable(
+            omMetadataManager.getDeletedTable()) == 0);
+  }
+
+  @Test
+  public void testAddDBToBatchWithParts() throws Exception {
+
+    String volumeName = UUID.randomUUID().toString();
+    String bucketName = UUID.randomUUID().toString();
+    String keyName = getKeyName();
+
+    TestOMRequestUtils.addVolumeAndBucketToDB(volumeName, bucketName,
+            omMetadataManager);
+    createParentPath(volumeName, bucketName);
+
+    String multipartUploadID = UUID.randomUUID().toString();
+
+    String fileName = OzoneFSUtils.getFileName(keyName);
+    String multipartKey = omMetadataManager.getMultipartKey(parentID, fileName,
+            multipartUploadID);
+
+    S3InitiateMultipartUploadResponse s3InitiateMultipartUploadResponseV1 =
+            createS3InitiateMPUResponseV1(volumeName, bucketName, parentID,
+                    keyName, multipartUploadID, new ArrayList<>());
+
+    s3InitiateMultipartUploadResponseV1.addToDBBatch(omMetadataManager,
+            batchOperation);
+
+    // Add some dummy parts for testing.
+    // Not added any key locations, as this just test is to see entries are
+    // adding to delete table or not.
+    OmMultipartKeyInfo omMultipartKeyInfo =
+            s3InitiateMultipartUploadResponseV1.getOmMultipartKeyInfo();
+
+    PartKeyInfo part1 = createPartKeyInfoV1(volumeName, bucketName, parentID,
+        fileName, 1);
+
+    addPart(1, part1, omMultipartKeyInfo);
+
+    long clientId = Time.now();
+    String openKey = omMetadataManager.getOpenFileName(parentID, fileName,
+            clientId);
+
+    S3MultipartUploadCommitPartResponse s3MultipartUploadCommitPartResponse =
+            createS3CommitMPUResponseV1(volumeName, bucketName, parentID,
+                    keyName, multipartUploadID,
+                    omMultipartKeyInfo.getPartKeyInfo(1),
+                    omMultipartKeyInfo,
+                    OzoneManagerProtocolProtos.Status.OK,  openKey);
+
+    s3MultipartUploadCommitPartResponse.checkAndUpdateDB(omMetadataManager,
+            batchOperation);
+
+    Assert.assertNull(omMetadataManager.getOpenKeyTable().get(multipartKey));
+    Assert.assertNull(
+        omMetadataManager.getMultipartInfoTable().get(multipartKey));
+
+    omMetadataManager.getStore().commitBatchOperation(batchOperation);
+
+    // As 1 parts are created, so 1 entry should be there in delete table.
+    Assert.assertTrue(omMetadataManager.countRowsInTable(
+        omMetadataManager.getDeletedTable()) == 1);
+
+    String part1DeletedKeyName =
+        omMultipartKeyInfo.getPartKeyInfo(1).getPartName();
+
+    Assert.assertNotNull(omMetadataManager.getDeletedTable().get(
+        part1DeletedKeyName));
+
+    RepeatedOmKeyInfo ro =
+        omMetadataManager.getDeletedTable().get(part1DeletedKeyName);
+    Assert.assertEquals(OmKeyInfo.getFromProtobuf(part1.getPartKeyInfo()),
+        ro.getOmKeyInfoList().get(0));
+  }
+
+  @Test
+  public void testWithMultipartUploadError() throws Exception {
+
+    String volumeName = UUID.randomUUID().toString();
+    String bucketName = UUID.randomUUID().toString();
+    String keyName = getKeyName();
+
+    TestOMRequestUtils.addVolumeAndBucketToDB(volumeName, bucketName,
+            omMetadataManager);
+    createParentPath(volumeName, bucketName);
+
+    String multipartUploadID = UUID.randomUUID().toString();
+
+    String fileName = OzoneFSUtils.getFileName(keyName);
+    String multipartKey = omMetadataManager.getMultipartKey(parentID, fileName,
+            multipartUploadID);
+
+    S3InitiateMultipartUploadResponse s3InitiateMultipartUploadResponseV1 =
+            createS3InitiateMPUResponseV1(volumeName, bucketName, parentID,
+                    keyName, multipartUploadID, new ArrayList<>());
+
+    s3InitiateMultipartUploadResponseV1.addToDBBatch(omMetadataManager,
+            batchOperation);
+
+    // Add some dummy parts for testing.
+    // Not added any key locations, as this just test is to see entries are
+    // adding to delete table or not.
+    OmMultipartKeyInfo omMultipartKeyInfo =
+            s3InitiateMultipartUploadResponseV1.getOmMultipartKeyInfo();
+
+    PartKeyInfo part1 = createPartKeyInfoV1(volumeName, bucketName, parentID,
+            fileName, 1);
+
+    addPart(1, part1, omMultipartKeyInfo);
+
+    long clientId = Time.now();
+    String openKey = omMetadataManager.getOpenFileName(parentID, fileName,
+            clientId);
+
+    S3MultipartUploadCommitPartResponse s3MultipartUploadCommitPartResponse =
+            createS3CommitMPUResponseV1(volumeName, bucketName, parentID,
+                    keyName + "invalid", multipartUploadID,
+                    omMultipartKeyInfo.getPartKeyInfo(1),
+                    omMultipartKeyInfo, OzoneManagerProtocolProtos.Status
+                            .NO_SUCH_MULTIPART_UPLOAD_ERROR, openKey);
+
+    s3MultipartUploadCommitPartResponse.checkAndUpdateDB(omMetadataManager,
+            batchOperation);
+
+    Assert.assertNull(omMetadataManager.getOpenKeyTable().get(multipartKey));
+    Assert.assertNull(
+            omMetadataManager.getMultipartInfoTable().get(multipartKey));
+
+    omMetadataManager.getStore().commitBatchOperation(batchOperation);
+
+    // As 1 parts are created, so 1 entry should be there in delete table.
+    Assert.assertTrue(omMetadataManager.countRowsInTable(
+            omMetadataManager.getDeletedTable()) == 1);

Review comment:
       The comment here is not correct, actually the open key was stored in delete table in this case. 

##########
File path: hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/s3/multipart/TestS3MultipartUploadCommitPartResponseV1.java
##########
@@ -0,0 +1,226 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.response.s3.multipart;
+
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo;
+import org.apache.hadoop.ozone.om.request.TestOMRequestUtils;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PartKeyInfo;
+import org.apache.hadoop.util.Time;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.UUID;
+
+/**
+ * Test multipart upload commit part response.
+ */
+public class TestS3MultipartUploadCommitPartResponseV1
+    extends TestS3MultipartResponse {
+
+  private String dirName = "a/b/c/";
+
+  private long parentID;
+
+  @Test
+  public void testAddDBToBatch() throws Exception {
+    String volumeName = UUID.randomUUID().toString();
+    String bucketName = UUID.randomUUID().toString();
+    String keyName = getKeyName();
+    String multipartUploadID = UUID.randomUUID().toString();
+
+    TestOMRequestUtils.addVolumeAndBucketToDB(volumeName, bucketName,
+            omMetadataManager);
+
+    createParentPath(volumeName, bucketName);
+    String fileName = OzoneFSUtils.getFileName(keyName);
+    String multipartKey = omMetadataManager.getMultipartKey(parentID, fileName,
+            multipartUploadID);
+    long clientId = Time.now();
+    String openKey = omMetadataManager.getOpenFileName(parentID, fileName,
+            clientId);
+
+    S3MultipartUploadCommitPartResponse s3MultipartUploadCommitPartResponse =
+        createS3CommitMPUResponseV1(volumeName, bucketName, parentID, keyName,
+            multipartUploadID, null, null,
+                OzoneManagerProtocolProtos.Status.OK, openKey);
+
+    s3MultipartUploadCommitPartResponse.addToDBBatch(omMetadataManager,
+        batchOperation);
+
+    omMetadataManager.getStore().commitBatchOperation(batchOperation);
+
+    Assert.assertNull(omMetadataManager.getOpenKeyTable().get(multipartKey));
+    Assert.assertNotNull(
+        omMetadataManager.getMultipartInfoTable().get(multipartKey));
+
+    // As no parts are created, so no entries should be there in delete table.
+    Assert.assertTrue(omMetadataManager.countRowsInTable(
+            omMetadataManager.getDeletedTable()) == 0);

Review comment:
       Nit: Can we use Assert.assertEquals(long expected, long actual) instead of?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] rakeshadr merged pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

Posted by GitBox <gi...@apache.org>.
rakeshadr merged pull request #1897:
URL: https://github.com/apache/ozone/pull/1897


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] rakeshadr commented on a change in pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

Posted by GitBox <gi...@apache.org>.
rakeshadr commented on a change in pull request #1897:
URL: https://github.com/apache/ozone/pull/1897#discussion_r572803982



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/multipart/S3MultipartUploadCommitPartRequestV1.java
##########
@@ -0,0 +1,247 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.request.s3.multipart;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
+import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.s3.multipart.S3MultipartUploadCommitPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handle Multipart upload commit upload part file.
+ */
+public class S3MultipartUploadCommitPartRequestV1
+        extends S3MultipartUploadCommitPartRequest {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(S3MultipartUploadCommitPartRequestV1.class);
+
+  public S3MultipartUploadCommitPartRequestV1(OMRequest omRequest) {
+    super(omRequest);
+  }
+
+  @Override
+  @SuppressWarnings("methodlength")
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+    MultipartCommitUploadPartRequest multipartCommitUploadPartRequest =
+        getOmRequest().getCommitMultiPartUploadRequest();
+
+    KeyArgs keyArgs = multipartCommitUploadPartRequest.getKeyArgs();
+    Map<String, String> auditMap = buildKeyArgsAuditMap(keyArgs);
+
+    String volumeName = keyArgs.getVolumeName();
+    String bucketName = keyArgs.getBucketName();
+    String keyName = keyArgs.getKeyName();
+
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+    ozoneManager.getMetrics().incNumCommitMultipartUploadParts();
+
+    boolean acquiredLock = false;
+
+    IOException exception = null;
+    String partName = null;
+    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(
+        getOmRequest());
+    OMClientResponse omClientResponse = null;
+    OzoneManagerProtocolProtos.PartKeyInfo oldPartKeyInfo = null;
+    String openKey = null;
+    OmKeyInfo omKeyInfo = null;
+    String multipartKey = null;
+    OmMultipartKeyInfo multipartKeyInfo = null;
+    Result result = null;
+    OmBucketInfo omBucketInfo = null;
+    OmBucketInfo copyBucketInfo = null;
+    try {
+      keyArgs = resolveBucketLink(ozoneManager, keyArgs, auditMap);
+      volumeName = keyArgs.getVolumeName();
+      bucketName = keyArgs.getBucketName();
+
+      // TODO to support S3 ACL later.
+      acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+          volumeName, bucketName);
+
+      validateBucketAndVolume(omMetadataManager, volumeName, bucketName);
+
+      String fileName = OzoneFSUtils.getFileName(keyName);
+      Iterator<Path> pathComponents = Paths.get(keyName).iterator();
+      String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
+      omBucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
+      long bucketId = omBucketInfo.getObjectID();
+      long parentID = OMFileRequest.getParentID(bucketId, pathComponents,
+              keyName, omMetadataManager);
+
+      String uploadID = keyArgs.getMultipartUploadID();
+      multipartKey = omMetadataManager.getMultipartKey(parentID,
+          fileName, uploadID);
+
+      multipartKeyInfo = omMetadataManager.getMultipartInfoTable()
+          .get(multipartKey);
+
+      long clientID = multipartCommitUploadPartRequest.getClientID();
+
+      openKey = omMetadataManager.getOpenFileName(parentID, fileName, clientID);
+
+      omKeyInfo = OMFileRequest.getOmKeyInfoFromFileTable(true,
+              omMetadataManager, openKey, keyName);
+
+      if (omKeyInfo == null) {
+        throw new OMException("Failed to commit Multipart Upload key, as " +
+            openKey + "entry is not found in the openKey table",
+            KEY_NOT_FOUND);
+      }
+
+      // set the data size and location info list
+      omKeyInfo.setDataSize(keyArgs.getDataSize());
+      omKeyInfo.updateLocationInfoList(keyArgs.getKeyLocationsList().stream()
+          .map(OmKeyLocationInfo::getFromProtobuf)
+          .collect(Collectors.toList()));
+      // Set Modification time
+      omKeyInfo.setModificationTime(keyArgs.getModificationTime());
+      // Set the UpdateID to current transactionLogIndex
+      omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
+
+      String ozoneKey = omMetadataManager.getOzonePathKey(parentID, fileName);
+      partName = ozoneKey + clientID;
+
+      if (multipartKeyInfo == null) {
+        // This can occur when user started uploading part by the time commit
+        // of that part happens, in between the user might have requested
+        // abort multipart upload. If we just throw exception, then the data
+        // will not be garbage collected, so move this part to delete table
+        // and throw error
+        // Move this part to delete table.
+        throw new OMException("No such Multipart upload is with specified " +
+            "uploadId " + uploadID,
+            OMException.ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
+      }
+
+      int partNumber = keyArgs.getMultipartNumber();
+      oldPartKeyInfo = multipartKeyInfo.getPartKeyInfo(partNumber);
+
+      // Build this multipart upload part info.
+      OzoneManagerProtocolProtos.PartKeyInfo.Builder partKeyInfo =
+          OzoneManagerProtocolProtos.PartKeyInfo.newBuilder();
+      partKeyInfo.setPartName(partName);
+      partKeyInfo.setPartNumber(partNumber);
+      partKeyInfo.setPartKeyInfo(omKeyInfo.getProtobuf(
+          getOmRequest().getVersion()));
+
+      // Add this part information in to multipartKeyInfo.
+      multipartKeyInfo.addPartKeyInfo(partNumber, partKeyInfo.build());
+
+      // Set the UpdateID to current transactionLogIndex
+      multipartKeyInfo.setUpdateID(trxnLogIndex,
+          ozoneManager.isRatisEnabled());
+
+      // OldPartKeyInfo will be deleted. Its updateID will be set in
+      // S3MultipartUplodaCommitPartResponse before being added to
+      // DeletedKeyTable.
+
+      // Add to cache.
+
+      // Delete from open key table and add it to multipart info table.
+      // No need to add cache entries to delete table, as no
+      // read/write requests that info for validation.
+      omMetadataManager.getMultipartInfoTable().addCacheEntry(
+          new CacheKey<>(multipartKey),
+          new CacheValue<>(Optional.of(multipartKeyInfo),
+              trxnLogIndex));
+
+      omMetadataManager.getOpenKeyTable().addCacheEntry(
+          new CacheKey<>(openKey),

Review comment:
       I've followed the same functionality from V0 `S3MultipartUploadCommitPartRequest.java` code base. 
   
   `openKey = omMetadataManager.getOpenFileName(parentID, fileName, clientID);` Below is the S3 logic:
   
   Following are the steps involved in S3 multi-part upload(MPU):
   step-1) Initiate MPU : multipart key will be stored into FileTable and MultipartInfoFileTable.
   step-2) create multipart key and upload part:  open key will be added into KeyTable. Here, internally it calls existing OMKeyCreateRequestV1 and OMAllocateBlockRequest code flow.
   step-3) commit multipart key : While committing it is removing the openKey by putting `Optional.absent()`.
   
   ```
    omMetadataManager.getOpenKeyTable().addCacheEntry(
             new CacheKey<>(openKey),
             new CacheValue<>(Optional.absent(), trxnLogIndex));
   ```
   
   step-4) Finally Multipart upload completion.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] rakeshadr commented on a change in pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

Posted by GitBox <gi...@apache.org>.
rakeshadr commented on a change in pull request #1897:
URL: https://github.com/apache/ozone/pull/1897#discussion_r572952741



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/multipart/S3MultipartUploadCommitPartRequestV1.java
##########
@@ -0,0 +1,247 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.request.s3.multipart;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
+import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.s3.multipart.S3MultipartUploadCommitPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handle Multipart upload commit upload part file.
+ */
+public class S3MultipartUploadCommitPartRequestV1
+        extends S3MultipartUploadCommitPartRequest {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(S3MultipartUploadCommitPartRequestV1.class);
+
+  public S3MultipartUploadCommitPartRequestV1(OMRequest omRequest) {
+    super(omRequest);
+  }
+
+  @Override
+  @SuppressWarnings("methodlength")
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+    MultipartCommitUploadPartRequest multipartCommitUploadPartRequest =
+        getOmRequest().getCommitMultiPartUploadRequest();
+
+    KeyArgs keyArgs = multipartCommitUploadPartRequest.getKeyArgs();
+    Map<String, String> auditMap = buildKeyArgsAuditMap(keyArgs);
+
+    String volumeName = keyArgs.getVolumeName();
+    String bucketName = keyArgs.getBucketName();
+    String keyName = keyArgs.getKeyName();
+
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+    ozoneManager.getMetrics().incNumCommitMultipartUploadParts();
+
+    boolean acquiredLock = false;
+
+    IOException exception = null;
+    String partName = null;
+    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(
+        getOmRequest());
+    OMClientResponse omClientResponse = null;
+    OzoneManagerProtocolProtos.PartKeyInfo oldPartKeyInfo = null;
+    String openKey = null;
+    OmKeyInfo omKeyInfo = null;
+    String multipartKey = null;
+    OmMultipartKeyInfo multipartKeyInfo = null;
+    Result result = null;
+    OmBucketInfo omBucketInfo = null;
+    OmBucketInfo copyBucketInfo = null;
+    try {
+      keyArgs = resolveBucketLink(ozoneManager, keyArgs, auditMap);
+      volumeName = keyArgs.getVolumeName();
+      bucketName = keyArgs.getBucketName();
+
+      // TODO to support S3 ACL later.
+      acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+          volumeName, bucketName);
+
+      validateBucketAndVolume(omMetadataManager, volumeName, bucketName);
+
+      String fileName = OzoneFSUtils.getFileName(keyName);
+      Iterator<Path> pathComponents = Paths.get(keyName).iterator();
+      String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
+      omBucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
+      long bucketId = omBucketInfo.getObjectID();
+      long parentID = OMFileRequest.getParentID(bucketId, pathComponents,
+              keyName, omMetadataManager);
+
+      String uploadID = keyArgs.getMultipartUploadID();
+      multipartKey = omMetadataManager.getMultipartKey(parentID,
+          fileName, uploadID);
+
+      multipartKeyInfo = omMetadataManager.getMultipartInfoTable()
+          .get(multipartKey);
+
+      long clientID = multipartCommitUploadPartRequest.getClientID();
+
+      openKey = omMetadataManager.getOpenFileName(parentID, fileName, clientID);
+
+      omKeyInfo = OMFileRequest.getOmKeyInfoFromFileTable(true,
+              omMetadataManager, openKey, keyName);
+
+      if (omKeyInfo == null) {
+        throw new OMException("Failed to commit Multipart Upload key, as " +
+            openKey + "entry is not found in the openKey table",
+            KEY_NOT_FOUND);
+      }
+
+      // set the data size and location info list
+      omKeyInfo.setDataSize(keyArgs.getDataSize());
+      omKeyInfo.updateLocationInfoList(keyArgs.getKeyLocationsList().stream()
+          .map(OmKeyLocationInfo::getFromProtobuf)
+          .collect(Collectors.toList()));
+      // Set Modification time
+      omKeyInfo.setModificationTime(keyArgs.getModificationTime());
+      // Set the UpdateID to current transactionLogIndex
+      omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
+
+      String ozoneKey = omMetadataManager.getOzonePathKey(parentID, fileName);
+      partName = ozoneKey + clientID;
+
+      if (multipartKeyInfo == null) {
+        // This can occur when user started uploading part by the time commit
+        // of that part happens, in between the user might have requested
+        // abort multipart upload. If we just throw exception, then the data
+        // will not be garbage collected, so move this part to delete table
+        // and throw error
+        // Move this part to delete table.
+        throw new OMException("No such Multipart upload is with specified " +
+            "uploadId " + uploadID,
+            OMException.ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
+      }
+
+      int partNumber = keyArgs.getMultipartNumber();
+      oldPartKeyInfo = multipartKeyInfo.getPartKeyInfo(partNumber);
+
+      // Build this multipart upload part info.
+      OzoneManagerProtocolProtos.PartKeyInfo.Builder partKeyInfo =
+          OzoneManagerProtocolProtos.PartKeyInfo.newBuilder();
+      partKeyInfo.setPartName(partName);
+      partKeyInfo.setPartNumber(partNumber);
+      partKeyInfo.setPartKeyInfo(omKeyInfo.getProtobuf(
+          getOmRequest().getVersion()));
+
+      // Add this part information in to multipartKeyInfo.
+      multipartKeyInfo.addPartKeyInfo(partNumber, partKeyInfo.build());
+
+      // Set the UpdateID to current transactionLogIndex
+      multipartKeyInfo.setUpdateID(trxnLogIndex,
+          ozoneManager.isRatisEnabled());
+
+      // OldPartKeyInfo will be deleted. Its updateID will be set in
+      // S3MultipartUplodaCommitPartResponse before being added to
+      // DeletedKeyTable.
+
+      // Add to cache.
+
+      // Delete from open key table and add it to multipart info table.
+      // No need to add cache entries to delete table, as no
+      // read/write requests that info for validation.
+      omMetadataManager.getMultipartInfoTable().addCacheEntry(
+          new CacheKey<>(multipartKey),
+          new CacheValue<>(Optional.of(multipartKeyInfo),
+              trxnLogIndex));
+
+      omMetadataManager.getOpenKeyTable().addCacheEntry(
+          new CacheKey<>(openKey),

Review comment:
       OK, its a very good point. It helped me to explore S3MultipartUploadCompleteRequest code and I saw that  [/S3MultipartUploadCompleteRequest.java#L374](https://github.com/apache/ozone/blob/master/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/multipart/S3MultipartUploadCompleteRequest.java#L374) is removing 'multipart key' from `OpenFileTable` during completion. I think, we need to consider this point while implementing S3MultipartUploadCompleteRequest task. I've raised HDDS-4813 jira and will take up once this PR is merged. Hope it make sense to you.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] linyiqun commented on a change in pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

Posted by GitBox <gi...@apache.org>.
linyiqun commented on a change in pull request #1897:
URL: https://github.com/apache/ozone/pull/1897#discussion_r572964904



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/multipart/S3MultipartUploadCommitPartRequestV1.java
##########
@@ -0,0 +1,247 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.request.s3.multipart;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
+import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.s3.multipart.S3MultipartUploadCommitPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handle Multipart upload commit upload part file.
+ */
+public class S3MultipartUploadCommitPartRequestV1
+        extends S3MultipartUploadCommitPartRequest {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(S3MultipartUploadCommitPartRequestV1.class);
+
+  public S3MultipartUploadCommitPartRequestV1(OMRequest omRequest) {
+    super(omRequest);
+  }
+
+  @Override
+  @SuppressWarnings("methodlength")
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+    MultipartCommitUploadPartRequest multipartCommitUploadPartRequest =
+        getOmRequest().getCommitMultiPartUploadRequest();
+
+    KeyArgs keyArgs = multipartCommitUploadPartRequest.getKeyArgs();
+    Map<String, String> auditMap = buildKeyArgsAuditMap(keyArgs);
+
+    String volumeName = keyArgs.getVolumeName();
+    String bucketName = keyArgs.getBucketName();
+    String keyName = keyArgs.getKeyName();
+
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+    ozoneManager.getMetrics().incNumCommitMultipartUploadParts();
+
+    boolean acquiredLock = false;
+
+    IOException exception = null;
+    String partName = null;
+    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(
+        getOmRequest());
+    OMClientResponse omClientResponse = null;
+    OzoneManagerProtocolProtos.PartKeyInfo oldPartKeyInfo = null;
+    String openKey = null;
+    OmKeyInfo omKeyInfo = null;
+    String multipartKey = null;
+    OmMultipartKeyInfo multipartKeyInfo = null;
+    Result result = null;
+    OmBucketInfo omBucketInfo = null;
+    OmBucketInfo copyBucketInfo = null;
+    try {
+      keyArgs = resolveBucketLink(ozoneManager, keyArgs, auditMap);
+      volumeName = keyArgs.getVolumeName();
+      bucketName = keyArgs.getBucketName();
+
+      // TODO to support S3 ACL later.
+      acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+          volumeName, bucketName);
+
+      validateBucketAndVolume(omMetadataManager, volumeName, bucketName);
+
+      String fileName = OzoneFSUtils.getFileName(keyName);
+      Iterator<Path> pathComponents = Paths.get(keyName).iterator();
+      String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
+      omBucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
+      long bucketId = omBucketInfo.getObjectID();
+      long parentID = OMFileRequest.getParentID(bucketId, pathComponents,
+              keyName, omMetadataManager);
+
+      String uploadID = keyArgs.getMultipartUploadID();
+      multipartKey = omMetadataManager.getMultipartKey(parentID,
+          fileName, uploadID);
+
+      multipartKeyInfo = omMetadataManager.getMultipartInfoTable()
+          .get(multipartKey);
+
+      long clientID = multipartCommitUploadPartRequest.getClientID();
+
+      openKey = omMetadataManager.getOpenFileName(parentID, fileName, clientID);
+
+      omKeyInfo = OMFileRequest.getOmKeyInfoFromFileTable(true,
+              omMetadataManager, openKey, keyName);
+
+      if (omKeyInfo == null) {
+        throw new OMException("Failed to commit Multipart Upload key, as " +
+            openKey + "entry is not found in the openKey table",
+            KEY_NOT_FOUND);
+      }
+
+      // set the data size and location info list
+      omKeyInfo.setDataSize(keyArgs.getDataSize());
+      omKeyInfo.updateLocationInfoList(keyArgs.getKeyLocationsList().stream()
+          .map(OmKeyLocationInfo::getFromProtobuf)
+          .collect(Collectors.toList()));
+      // Set Modification time
+      omKeyInfo.setModificationTime(keyArgs.getModificationTime());
+      // Set the UpdateID to current transactionLogIndex
+      omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
+
+      String ozoneKey = omMetadataManager.getOzonePathKey(parentID, fileName);
+      partName = ozoneKey + clientID;
+
+      if (multipartKeyInfo == null) {
+        // This can occur when user started uploading part by the time commit
+        // of that part happens, in between the user might have requested
+        // abort multipart upload. If we just throw exception, then the data
+        // will not be garbage collected, so move this part to delete table
+        // and throw error
+        // Move this part to delete table.
+        throw new OMException("No such Multipart upload is with specified " +
+            "uploadId " + uploadID,
+            OMException.ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
+      }
+
+      int partNumber = keyArgs.getMultipartNumber();
+      oldPartKeyInfo = multipartKeyInfo.getPartKeyInfo(partNumber);
+
+      // Build this multipart upload part info.
+      OzoneManagerProtocolProtos.PartKeyInfo.Builder partKeyInfo =
+          OzoneManagerProtocolProtos.PartKeyInfo.newBuilder();
+      partKeyInfo.setPartName(partName);
+      partKeyInfo.setPartNumber(partNumber);
+      partKeyInfo.setPartKeyInfo(omKeyInfo.getProtobuf(
+          getOmRequest().getVersion()));
+
+      // Add this part information in to multipartKeyInfo.
+      multipartKeyInfo.addPartKeyInfo(partNumber, partKeyInfo.build());
+
+      // Set the UpdateID to current transactionLogIndex
+      multipartKeyInfo.setUpdateID(trxnLogIndex,
+          ozoneManager.isRatisEnabled());
+
+      // OldPartKeyInfo will be deleted. Its updateID will be set in
+      // S3MultipartUplodaCommitPartResponse before being added to
+      // DeletedKeyTable.
+
+      // Add to cache.
+
+      // Delete from open key table and add it to multipart info table.
+      // No need to add cache entries to delete table, as no
+      // read/write requests that info for validation.
+      omMetadataManager.getMultipartInfoTable().addCacheEntry(
+          new CacheKey<>(multipartKey),
+          new CacheValue<>(Optional.of(multipartKeyInfo),
+              trxnLogIndex));
+
+      omMetadataManager.getOpenKeyTable().addCacheEntry(
+          new CacheKey<>(openKey),

Review comment:
       Make sense to me,  👍  .




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] mukul1987 commented on a change in pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

Posted by GitBox <gi...@apache.org>.
mukul1987 commented on a change in pull request #1897:
URL: https://github.com/apache/ozone/pull/1897#discussion_r571655775



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/multipart/S3MultipartUploadCommitPartRequestV1.java
##########
@@ -0,0 +1,247 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.request.s3.multipart;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
+import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.s3.multipart.S3MultipartUploadCommitPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handle Multipart upload commit upload part file.
+ */
+public class S3MultipartUploadCommitPartRequestV1
+        extends S3MultipartUploadCommitPartRequest {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(S3MultipartUploadCommitPartRequestV1.class);
+
+  public S3MultipartUploadCommitPartRequestV1(OMRequest omRequest) {
+    super(omRequest);
+  }
+
+  @Override
+  @SuppressWarnings("methodlength")
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+    MultipartCommitUploadPartRequest multipartCommitUploadPartRequest =
+        getOmRequest().getCommitMultiPartUploadRequest();
+
+    KeyArgs keyArgs = multipartCommitUploadPartRequest.getKeyArgs();
+    Map<String, String> auditMap = buildKeyArgsAuditMap(keyArgs);
+
+    String volumeName = keyArgs.getVolumeName();
+    String bucketName = keyArgs.getBucketName();
+    String keyName = keyArgs.getKeyName();
+
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+    ozoneManager.getMetrics().incNumCommitMultipartUploadParts();
+
+    boolean acquiredLock = false;
+
+    IOException exception = null;
+    String partName = null;
+    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(
+        getOmRequest());
+    OMClientResponse omClientResponse = null;
+    OzoneManagerProtocolProtos.PartKeyInfo oldPartKeyInfo = null;
+    String openKey = null;
+    OmKeyInfo omKeyInfo = null;
+    String multipartKey = null;
+    OmMultipartKeyInfo multipartKeyInfo = null;
+    Result result = null;
+    OmBucketInfo omBucketInfo = null;
+    OmBucketInfo copyBucketInfo = null;
+    try {
+      keyArgs = resolveBucketLink(ozoneManager, keyArgs, auditMap);
+      volumeName = keyArgs.getVolumeName();
+      bucketName = keyArgs.getBucketName();
+
+      // TODO to support S3 ACL later.
+      acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+          volumeName, bucketName);
+
+      validateBucketAndVolume(omMetadataManager, volumeName, bucketName);
+
+      String fileName = OzoneFSUtils.getFileName(keyName);
+      Iterator<Path> pathComponents = Paths.get(keyName).iterator();
+      String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
+      omBucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
+      long bucketId = omBucketInfo.getObjectID();
+      long parentID = OMFileRequest.getParentID(bucketId, pathComponents,
+              keyName, omMetadataManager);
+
+      String uploadID = keyArgs.getMultipartUploadID();
+      multipartKey = omMetadataManager.getMultipartKey(parentID,
+          fileName, uploadID);
+
+      multipartKeyInfo = omMetadataManager.getMultipartInfoTable()
+          .get(multipartKey);
+
+      long clientID = multipartCommitUploadPartRequest.getClientID();
+
+      openKey = omMetadataManager.getOpenFileName(parentID, fileName, clientID);
+
+      omKeyInfo = OMFileRequest.getOmKeyInfoFromFileTable(true,
+              omMetadataManager, openKey, keyName);
+
+      if (omKeyInfo == null) {
+        throw new OMException("Failed to commit Multipart Upload key, as " +
+            openKey + "entry is not found in the openKey table",
+            KEY_NOT_FOUND);
+      }
+
+      // set the data size and location info list
+      omKeyInfo.setDataSize(keyArgs.getDataSize());
+      omKeyInfo.updateLocationInfoList(keyArgs.getKeyLocationsList().stream()
+          .map(OmKeyLocationInfo::getFromProtobuf)
+          .collect(Collectors.toList()));
+      // Set Modification time
+      omKeyInfo.setModificationTime(keyArgs.getModificationTime());
+      // Set the UpdateID to current transactionLogIndex
+      omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
+
+      String ozoneKey = omMetadataManager.getOzonePathKey(parentID, fileName);
+      partName = ozoneKey + clientID;
+
+      if (multipartKeyInfo == null) {
+        // This can occur when user started uploading part by the time commit
+        // of that part happens, in between the user might have requested
+        // abort multipart upload. If we just throw exception, then the data
+        // will not be garbage collected, so move this part to delete table
+        // and throw error
+        // Move this part to delete table.
+        throw new OMException("No such Multipart upload is with specified " +
+            "uploadId " + uploadID,
+            OMException.ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
+      }
+
+      int partNumber = keyArgs.getMultipartNumber();
+      oldPartKeyInfo = multipartKeyInfo.getPartKeyInfo(partNumber);
+
+      // Build this multipart upload part info.
+      OzoneManagerProtocolProtos.PartKeyInfo.Builder partKeyInfo =
+          OzoneManagerProtocolProtos.PartKeyInfo.newBuilder();
+      partKeyInfo.setPartName(partName);
+      partKeyInfo.setPartNumber(partNumber);
+      partKeyInfo.setPartKeyInfo(omKeyInfo.getProtobuf(
+          getOmRequest().getVersion()));
+
+      // Add this part information in to multipartKeyInfo.
+      multipartKeyInfo.addPartKeyInfo(partNumber, partKeyInfo.build());
+
+      // Set the UpdateID to current transactionLogIndex
+      multipartKeyInfo.setUpdateID(trxnLogIndex,
+          ozoneManager.isRatisEnabled());
+
+      // OldPartKeyInfo will be deleted. Its updateID will be set in
+      // S3MultipartUplodaCommitPartResponse before being added to
+      // DeletedKeyTable.
+
+      // Add to cache.

Review comment:
       Shoudl this line be removed ? The add to cache happens later, move the comments maybe? 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] linyiqun commented on a change in pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

Posted by GitBox <gi...@apache.org>.
linyiqun commented on a change in pull request #1897:
URL: https://github.com/apache/ozone/pull/1897#discussion_r572934960



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/multipart/S3MultipartUploadCommitPartRequestV1.java
##########
@@ -0,0 +1,247 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.request.s3.multipart;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
+import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.s3.multipart.S3MultipartUploadCommitPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handle Multipart upload commit upload part file.
+ */
+public class S3MultipartUploadCommitPartRequestV1
+        extends S3MultipartUploadCommitPartRequest {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(S3MultipartUploadCommitPartRequestV1.class);
+
+  public S3MultipartUploadCommitPartRequestV1(OMRequest omRequest) {
+    super(omRequest);
+  }
+
+  @Override
+  @SuppressWarnings("methodlength")
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+    MultipartCommitUploadPartRequest multipartCommitUploadPartRequest =
+        getOmRequest().getCommitMultiPartUploadRequest();
+
+    KeyArgs keyArgs = multipartCommitUploadPartRequest.getKeyArgs();
+    Map<String, String> auditMap = buildKeyArgsAuditMap(keyArgs);
+
+    String volumeName = keyArgs.getVolumeName();
+    String bucketName = keyArgs.getBucketName();
+    String keyName = keyArgs.getKeyName();
+
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+    ozoneManager.getMetrics().incNumCommitMultipartUploadParts();
+
+    boolean acquiredLock = false;
+
+    IOException exception = null;
+    String partName = null;
+    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(
+        getOmRequest());
+    OMClientResponse omClientResponse = null;
+    OzoneManagerProtocolProtos.PartKeyInfo oldPartKeyInfo = null;
+    String openKey = null;
+    OmKeyInfo omKeyInfo = null;
+    String multipartKey = null;
+    OmMultipartKeyInfo multipartKeyInfo = null;
+    Result result = null;
+    OmBucketInfo omBucketInfo = null;
+    OmBucketInfo copyBucketInfo = null;
+    try {
+      keyArgs = resolveBucketLink(ozoneManager, keyArgs, auditMap);
+      volumeName = keyArgs.getVolumeName();
+      bucketName = keyArgs.getBucketName();
+
+      // TODO to support S3 ACL later.
+      acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+          volumeName, bucketName);
+
+      validateBucketAndVolume(omMetadataManager, volumeName, bucketName);
+
+      String fileName = OzoneFSUtils.getFileName(keyName);
+      Iterator<Path> pathComponents = Paths.get(keyName).iterator();
+      String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
+      omBucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
+      long bucketId = omBucketInfo.getObjectID();
+      long parentID = OMFileRequest.getParentID(bucketId, pathComponents,
+              keyName, omMetadataManager);
+
+      String uploadID = keyArgs.getMultipartUploadID();
+      multipartKey = omMetadataManager.getMultipartKey(parentID,
+          fileName, uploadID);
+
+      multipartKeyInfo = omMetadataManager.getMultipartInfoTable()
+          .get(multipartKey);
+
+      long clientID = multipartCommitUploadPartRequest.getClientID();
+
+      openKey = omMetadataManager.getOpenFileName(parentID, fileName, clientID);
+
+      omKeyInfo = OMFileRequest.getOmKeyInfoFromFileTable(true,
+              omMetadataManager, openKey, keyName);
+
+      if (omKeyInfo == null) {
+        throw new OMException("Failed to commit Multipart Upload key, as " +
+            openKey + "entry is not found in the openKey table",
+            KEY_NOT_FOUND);
+      }
+
+      // set the data size and location info list
+      omKeyInfo.setDataSize(keyArgs.getDataSize());
+      omKeyInfo.updateLocationInfoList(keyArgs.getKeyLocationsList().stream()
+          .map(OmKeyLocationInfo::getFromProtobuf)
+          .collect(Collectors.toList()));
+      // Set Modification time
+      omKeyInfo.setModificationTime(keyArgs.getModificationTime());
+      // Set the UpdateID to current transactionLogIndex
+      omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
+
+      String ozoneKey = omMetadataManager.getOzonePathKey(parentID, fileName);
+      partName = ozoneKey + clientID;
+
+      if (multipartKeyInfo == null) {
+        // This can occur when user started uploading part by the time commit
+        // of that part happens, in between the user might have requested
+        // abort multipart upload. If we just throw exception, then the data
+        // will not be garbage collected, so move this part to delete table
+        // and throw error
+        // Move this part to delete table.
+        throw new OMException("No such Multipart upload is with specified " +
+            "uploadId " + uploadID,
+            OMException.ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
+      }
+
+      int partNumber = keyArgs.getMultipartNumber();
+      oldPartKeyInfo = multipartKeyInfo.getPartKeyInfo(partNumber);
+
+      // Build this multipart upload part info.
+      OzoneManagerProtocolProtos.PartKeyInfo.Builder partKeyInfo =
+          OzoneManagerProtocolProtos.PartKeyInfo.newBuilder();
+      partKeyInfo.setPartName(partName);
+      partKeyInfo.setPartNumber(partNumber);
+      partKeyInfo.setPartKeyInfo(omKeyInfo.getProtobuf(
+          getOmRequest().getVersion()));
+
+      // Add this part information in to multipartKeyInfo.
+      multipartKeyInfo.addPartKeyInfo(partNumber, partKeyInfo.build());
+
+      // Set the UpdateID to current transactionLogIndex
+      multipartKeyInfo.setUpdateID(trxnLogIndex,
+          ozoneManager.isRatisEnabled());
+
+      // OldPartKeyInfo will be deleted. Its updateID will be set in
+      // S3MultipartUplodaCommitPartResponse before being added to
+      // DeletedKeyTable.
+
+      // Add to cache.
+
+      // Delete from open key table and add it to multipart info table.
+      // No need to add cache entries to delete table, as no
+      // read/write requests that info for validation.
+      omMetadataManager.getMultipartInfoTable().addCacheEntry(
+          new CacheKey<>(multipartKey),
+          new CacheValue<>(Optional.of(multipartKeyInfo),
+              trxnLogIndex));
+
+      omMetadataManager.getOpenKeyTable().addCacheEntry(
+          new CacheKey<>(openKey),

Review comment:
       @rakeshadr , sorry for that my previous comment is not very clear. My point is that we have a different open key defined in S3InitiateMultipartUploadRequestV1 and S3MultipartUploadCommitPartRequestV1.
   
   In S3InitiateMultipartUploadRequestV1, the key inserted is set as 
   
   ```java
         String multipartKey = omMetadataManager.getMultipartKey(
                 pathInfoV1.getLastKnownParentId(), pathInfoV1.getLeafNodeName(),
                 keyArgs.getMultipartUploadID());
   
         ...
         OMFileRequest.addOpenFileTableCacheEntry(omMetadataManager,
                 multipartKey, omKeyInfo, pathInfoV1.getLeafNodeName(),
                 transactionLogIndex);
   ```
   
   But in the S3MultipartUploadCommitPartRequestV1 request,  the key changed to 
   
   ```java
   openKey = omMetadataManager.getOpenFileName(parentID, fileName, clientID);
   omMetadataManager.getOpenKeyTable().addCacheEntry(
             new CacheKey<>(openKey),
             new CacheValue<>(Optional.absent(), trxnLogIndex));
   ```
   Above multipartKey is equals to openKey here? 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] rakeshadr commented on pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

Posted by GitBox <gi...@apache.org>.
rakeshadr commented on pull request #1897:
URL: https://github.com/apache/ozone/pull/1897#issuecomment-776572529


   Thanks a lot @linyiqun and @mukul1987 for the reviews. I've merged it to the branch.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] rakeshadr commented on a change in pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

Posted by GitBox <gi...@apache.org>.
rakeshadr commented on a change in pull request #1897:
URL: https://github.com/apache/ozone/pull/1897#discussion_r572773928



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMKeyRequest.java
##########
@@ -661,9 +661,17 @@ private OmKeyInfo prepareMultipartFileInfo(
     // error no such multipart upload.
     String uploadID = args.getMultipartUploadID();
     Preconditions.checkNotNull(uploadID);
-    String multipartKey = omMetadataManager
-            .getMultipartKey(args.getVolumeName(), args.getBucketName(),
-                    args.getKeyName(), uploadID);
+    String multipartKey = "";
+    if (omPathInfo != null) {
+      // FileTable metadata format
+      multipartKey =
+              omMetadataManager.getMultipartKey(omPathInfo.getLastKnownParentId(),
+                      omPathInfo.getLeafNodeName(), uploadID);
+    } else {
+      multipartKey = omMetadataManager

Review comment:
       Thanks @mukul1987 for the review comments.
   
   `OMKeyRequest#prepareMultipartFileInfo()` is a common function, used by both V0 and V1 code. I've used `omPathInfo != null` as a differentiator between V0 and V1.
   
   V0 code flow:-
   `OMKeyRequest#prepareKeyInfo --> OMKeyRequest#prepareFileInfo --> OMKeyRequest#prepareMultipartFileInfo()`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] rakeshadr commented on a change in pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

Posted by GitBox <gi...@apache.org>.
rakeshadr commented on a change in pull request #1897:
URL: https://github.com/apache/ozone/pull/1897#discussion_r572803982



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/multipart/S3MultipartUploadCommitPartRequestV1.java
##########
@@ -0,0 +1,247 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.request.s3.multipart;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
+import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.s3.multipart.S3MultipartUploadCommitPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handle Multipart upload commit upload part file.
+ */
+public class S3MultipartUploadCommitPartRequestV1
+        extends S3MultipartUploadCommitPartRequest {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(S3MultipartUploadCommitPartRequestV1.class);
+
+  public S3MultipartUploadCommitPartRequestV1(OMRequest omRequest) {
+    super(omRequest);
+  }
+
+  @Override
+  @SuppressWarnings("methodlength")
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+    MultipartCommitUploadPartRequest multipartCommitUploadPartRequest =
+        getOmRequest().getCommitMultiPartUploadRequest();
+
+    KeyArgs keyArgs = multipartCommitUploadPartRequest.getKeyArgs();
+    Map<String, String> auditMap = buildKeyArgsAuditMap(keyArgs);
+
+    String volumeName = keyArgs.getVolumeName();
+    String bucketName = keyArgs.getBucketName();
+    String keyName = keyArgs.getKeyName();
+
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+    ozoneManager.getMetrics().incNumCommitMultipartUploadParts();
+
+    boolean acquiredLock = false;
+
+    IOException exception = null;
+    String partName = null;
+    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(
+        getOmRequest());
+    OMClientResponse omClientResponse = null;
+    OzoneManagerProtocolProtos.PartKeyInfo oldPartKeyInfo = null;
+    String openKey = null;
+    OmKeyInfo omKeyInfo = null;
+    String multipartKey = null;
+    OmMultipartKeyInfo multipartKeyInfo = null;
+    Result result = null;
+    OmBucketInfo omBucketInfo = null;
+    OmBucketInfo copyBucketInfo = null;
+    try {
+      keyArgs = resolveBucketLink(ozoneManager, keyArgs, auditMap);
+      volumeName = keyArgs.getVolumeName();
+      bucketName = keyArgs.getBucketName();
+
+      // TODO to support S3 ACL later.
+      acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+          volumeName, bucketName);
+
+      validateBucketAndVolume(omMetadataManager, volumeName, bucketName);
+
+      String fileName = OzoneFSUtils.getFileName(keyName);
+      Iterator<Path> pathComponents = Paths.get(keyName).iterator();
+      String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
+      omBucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
+      long bucketId = omBucketInfo.getObjectID();
+      long parentID = OMFileRequest.getParentID(bucketId, pathComponents,
+              keyName, omMetadataManager);
+
+      String uploadID = keyArgs.getMultipartUploadID();
+      multipartKey = omMetadataManager.getMultipartKey(parentID,
+          fileName, uploadID);
+
+      multipartKeyInfo = omMetadataManager.getMultipartInfoTable()
+          .get(multipartKey);
+
+      long clientID = multipartCommitUploadPartRequest.getClientID();
+
+      openKey = omMetadataManager.getOpenFileName(parentID, fileName, clientID);
+
+      omKeyInfo = OMFileRequest.getOmKeyInfoFromFileTable(true,
+              omMetadataManager, openKey, keyName);
+
+      if (omKeyInfo == null) {
+        throw new OMException("Failed to commit Multipart Upload key, as " +
+            openKey + "entry is not found in the openKey table",
+            KEY_NOT_FOUND);
+      }
+
+      // set the data size and location info list
+      omKeyInfo.setDataSize(keyArgs.getDataSize());
+      omKeyInfo.updateLocationInfoList(keyArgs.getKeyLocationsList().stream()
+          .map(OmKeyLocationInfo::getFromProtobuf)
+          .collect(Collectors.toList()));
+      // Set Modification time
+      omKeyInfo.setModificationTime(keyArgs.getModificationTime());
+      // Set the UpdateID to current transactionLogIndex
+      omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
+
+      String ozoneKey = omMetadataManager.getOzonePathKey(parentID, fileName);
+      partName = ozoneKey + clientID;
+
+      if (multipartKeyInfo == null) {
+        // This can occur when user started uploading part by the time commit
+        // of that part happens, in between the user might have requested
+        // abort multipart upload. If we just throw exception, then the data
+        // will not be garbage collected, so move this part to delete table
+        // and throw error
+        // Move this part to delete table.
+        throw new OMException("No such Multipart upload is with specified " +
+            "uploadId " + uploadID,
+            OMException.ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
+      }
+
+      int partNumber = keyArgs.getMultipartNumber();
+      oldPartKeyInfo = multipartKeyInfo.getPartKeyInfo(partNumber);
+
+      // Build this multipart upload part info.
+      OzoneManagerProtocolProtos.PartKeyInfo.Builder partKeyInfo =
+          OzoneManagerProtocolProtos.PartKeyInfo.newBuilder();
+      partKeyInfo.setPartName(partName);
+      partKeyInfo.setPartNumber(partNumber);
+      partKeyInfo.setPartKeyInfo(omKeyInfo.getProtobuf(
+          getOmRequest().getVersion()));
+
+      // Add this part information in to multipartKeyInfo.
+      multipartKeyInfo.addPartKeyInfo(partNumber, partKeyInfo.build());
+
+      // Set the UpdateID to current transactionLogIndex
+      multipartKeyInfo.setUpdateID(trxnLogIndex,
+          ozoneManager.isRatisEnabled());
+
+      // OldPartKeyInfo will be deleted. Its updateID will be set in
+      // S3MultipartUplodaCommitPartResponse before being added to
+      // DeletedKeyTable.
+
+      // Add to cache.
+
+      // Delete from open key table and add it to multipart info table.
+      // No need to add cache entries to delete table, as no
+      // read/write requests that info for validation.
+      omMetadataManager.getMultipartInfoTable().addCacheEntry(
+          new CacheKey<>(multipartKey),
+          new CacheValue<>(Optional.of(multipartKeyInfo),
+              trxnLogIndex));
+
+      omMetadataManager.getOpenKeyTable().addCacheEntry(
+          new CacheKey<>(openKey),

Review comment:
       I've followed the same functionality from V0 `S3MultipartUploadCommitPartRequest.java` code base. 
   
   `openKey = omMetadataManager.getOpenFileName(parentID, fileName, clientID);` Below is the S3 logic:
   
   Following are the steps involved in S3 multi-part upload(MPU):
   step-1) Initiate MPU : multipart key will be stored into FileTable and MultipartInfoFileTable.
   step-2) create multipart key and upload part:  open key will be added into KeyTable. Here, internally it calls existing OMKeyCreateRequestV1 and OMAllocateBlockRequest code flow.
   step-3) commit multipart key : While committing it is removing the openKey by putting `Optional.absent()`.
   
   ```
    omMetadataManager.getOpenKeyTable().addCacheEntry(
             new CacheKey<>(openKey),
             new CacheValue<>(Optional.absent(), trxnLogIndex));
   ```
   
   step-4) Finally Multipart upload completion.
   
   Please let me know, if any more details. Thanks @linyiqun for the comment.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] rakeshadr commented on a change in pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

Posted by GitBox <gi...@apache.org>.
rakeshadr commented on a change in pull request #1897:
URL: https://github.com/apache/ozone/pull/1897#discussion_r572786129



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/multipart/S3MultipartUploadCommitPartRequestV1.java
##########
@@ -0,0 +1,247 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.request.s3.multipart;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
+import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.s3.multipart.S3MultipartUploadCommitPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handle Multipart upload commit upload part file.
+ */
+public class S3MultipartUploadCommitPartRequestV1
+        extends S3MultipartUploadCommitPartRequest {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(S3MultipartUploadCommitPartRequestV1.class);
+
+  public S3MultipartUploadCommitPartRequestV1(OMRequest omRequest) {
+    super(omRequest);
+  }
+
+  @Override
+  @SuppressWarnings("methodlength")
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+    MultipartCommitUploadPartRequest multipartCommitUploadPartRequest =
+        getOmRequest().getCommitMultiPartUploadRequest();
+
+    KeyArgs keyArgs = multipartCommitUploadPartRequest.getKeyArgs();
+    Map<String, String> auditMap = buildKeyArgsAuditMap(keyArgs);
+
+    String volumeName = keyArgs.getVolumeName();
+    String bucketName = keyArgs.getBucketName();
+    String keyName = keyArgs.getKeyName();
+
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+    ozoneManager.getMetrics().incNumCommitMultipartUploadParts();
+
+    boolean acquiredLock = false;
+
+    IOException exception = null;
+    String partName = null;
+    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(
+        getOmRequest());
+    OMClientResponse omClientResponse = null;
+    OzoneManagerProtocolProtos.PartKeyInfo oldPartKeyInfo = null;
+    String openKey = null;
+    OmKeyInfo omKeyInfo = null;
+    String multipartKey = null;
+    OmMultipartKeyInfo multipartKeyInfo = null;
+    Result result = null;
+    OmBucketInfo omBucketInfo = null;
+    OmBucketInfo copyBucketInfo = null;
+    try {
+      keyArgs = resolveBucketLink(ozoneManager, keyArgs, auditMap);
+      volumeName = keyArgs.getVolumeName();
+      bucketName = keyArgs.getBucketName();
+
+      // TODO to support S3 ACL later.
+      acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+          volumeName, bucketName);
+
+      validateBucketAndVolume(omMetadataManager, volumeName, bucketName);
+
+      String fileName = OzoneFSUtils.getFileName(keyName);
+      Iterator<Path> pathComponents = Paths.get(keyName).iterator();
+      String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
+      omBucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
+      long bucketId = omBucketInfo.getObjectID();
+      long parentID = OMFileRequest.getParentID(bucketId, pathComponents,
+              keyName, omMetadataManager);
+
+      String uploadID = keyArgs.getMultipartUploadID();
+      multipartKey = omMetadataManager.getMultipartKey(parentID,
+          fileName, uploadID);
+
+      multipartKeyInfo = omMetadataManager.getMultipartInfoTable()
+          .get(multipartKey);
+
+      long clientID = multipartCommitUploadPartRequest.getClientID();
+
+      openKey = omMetadataManager.getOpenFileName(parentID, fileName, clientID);
+
+      omKeyInfo = OMFileRequest.getOmKeyInfoFromFileTable(true,
+              omMetadataManager, openKey, keyName);
+
+      if (omKeyInfo == null) {
+        throw new OMException("Failed to commit Multipart Upload key, as " +
+            openKey + "entry is not found in the openKey table",
+            KEY_NOT_FOUND);
+      }
+
+      // set the data size and location info list
+      omKeyInfo.setDataSize(keyArgs.getDataSize());
+      omKeyInfo.updateLocationInfoList(keyArgs.getKeyLocationsList().stream()
+          .map(OmKeyLocationInfo::getFromProtobuf)
+          .collect(Collectors.toList()));
+      // Set Modification time
+      omKeyInfo.setModificationTime(keyArgs.getModificationTime());
+      // Set the UpdateID to current transactionLogIndex
+      omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
+
+      String ozoneKey = omMetadataManager.getOzonePathKey(parentID, fileName);
+      partName = ozoneKey + clientID;
+
+      if (multipartKeyInfo == null) {
+        // This can occur when user started uploading part by the time commit
+        // of that part happens, in between the user might have requested
+        // abort multipart upload. If we just throw exception, then the data
+        // will not be garbage collected, so move this part to delete table
+        // and throw error
+        // Move this part to delete table.
+        throw new OMException("No such Multipart upload is with specified " +
+            "uploadId " + uploadID,
+            OMException.ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
+      }
+
+      int partNumber = keyArgs.getMultipartNumber();
+      oldPartKeyInfo = multipartKeyInfo.getPartKeyInfo(partNumber);
+
+      // Build this multipart upload part info.
+      OzoneManagerProtocolProtos.PartKeyInfo.Builder partKeyInfo =
+          OzoneManagerProtocolProtos.PartKeyInfo.newBuilder();
+      partKeyInfo.setPartName(partName);
+      partKeyInfo.setPartNumber(partNumber);
+      partKeyInfo.setPartKeyInfo(omKeyInfo.getProtobuf(
+          getOmRequest().getVersion()));
+
+      // Add this part information in to multipartKeyInfo.
+      multipartKeyInfo.addPartKeyInfo(partNumber, partKeyInfo.build());
+
+      // Set the UpdateID to current transactionLogIndex
+      multipartKeyInfo.setUpdateID(trxnLogIndex,
+          ozoneManager.isRatisEnabled());
+
+      // OldPartKeyInfo will be deleted. Its updateID will be set in
+      // S3MultipartUplodaCommitPartResponse before being added to
+      // DeletedKeyTable.
+
+      // Add to cache.
+
+      // Delete from open key table and add it to multipart info table.
+      // No need to add cache entries to delete table, as no
+      // read/write requests that info for validation.
+      omMetadataManager.getMultipartInfoTable().addCacheEntry(
+          new CacheKey<>(multipartKey),
+          new CacheValue<>(Optional.of(multipartKeyInfo),
+              trxnLogIndex));
+
+      omMetadataManager.getOpenKeyTable().addCacheEntry(
+          new CacheKey<>(openKey),
+          new CacheValue<>(Optional.absent(), trxnLogIndex));
+
+      long scmBlockSize = ozoneManager.getScmBlockSize();
+      int factor = omKeyInfo.getFactor().getNumber();
+      omBucketInfo = getBucketInfo(omMetadataManager, volumeName, bucketName);
+      // Block was pre-requested and UsedBytes updated when createKey and
+      // AllocatedBlock. The space occupied by the Key shall be based on
+      // the actual Key size, and the total Block size applied before should
+      // be subtracted.
+      long correctedSpace = omKeyInfo.getDataSize() * factor -
+          keyArgs.getKeyLocationsList().size() * scmBlockSize * factor;
+      omBucketInfo.incrUsedBytes(correctedSpace);
+
+      omResponse.setCommitMultiPartUploadResponse(
+          MultipartCommitUploadPartResponse.newBuilder()
+              .setPartName(partName));
+      omClientResponse = new S3MultipartUploadCommitPartResponse(

Review comment:
       Good catch @linyiqun. Thanks for the review comments. I will add S3MultipartUploadCommitPartResponseV1 class.
   Thanks @mukul1987 for the ack:-)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


[GitHub] [ozone] linyiqun commented on a change in pull request #1897: HDDS-4781. [FSO]S3MultiPart: Implement create and commit upload part file

Posted by GitBox <gi...@apache.org>.
linyiqun commented on a change in pull request #1897:
URL: https://github.com/apache/ozone/pull/1897#discussion_r572934960



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/multipart/S3MultipartUploadCommitPartRequestV1.java
##########
@@ -0,0 +1,247 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om.request.s3.multipart;
+
+import com.google.common.base.Optional;
+import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
+import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.audit.OMAction;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OzoneManager;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
+import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper;
+import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
+import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
+import org.apache.hadoop.ozone.om.response.OMClientResponse;
+import org.apache.hadoop.ozone.om.response.s3.multipart.S3MultipartUploadCommitPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartCommitUploadPartResponse;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest;
+import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
+import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK;
+
+/**
+ * Handle Multipart upload commit upload part file.
+ */
+public class S3MultipartUploadCommitPartRequestV1
+        extends S3MultipartUploadCommitPartRequest {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(S3MultipartUploadCommitPartRequestV1.class);
+
+  public S3MultipartUploadCommitPartRequestV1(OMRequest omRequest) {
+    super(omRequest);
+  }
+
+  @Override
+  @SuppressWarnings("methodlength")
+  public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
+      long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
+    MultipartCommitUploadPartRequest multipartCommitUploadPartRequest =
+        getOmRequest().getCommitMultiPartUploadRequest();
+
+    KeyArgs keyArgs = multipartCommitUploadPartRequest.getKeyArgs();
+    Map<String, String> auditMap = buildKeyArgsAuditMap(keyArgs);
+
+    String volumeName = keyArgs.getVolumeName();
+    String bucketName = keyArgs.getBucketName();
+    String keyName = keyArgs.getKeyName();
+
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+    ozoneManager.getMetrics().incNumCommitMultipartUploadParts();
+
+    boolean acquiredLock = false;
+
+    IOException exception = null;
+    String partName = null;
+    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(
+        getOmRequest());
+    OMClientResponse omClientResponse = null;
+    OzoneManagerProtocolProtos.PartKeyInfo oldPartKeyInfo = null;
+    String openKey = null;
+    OmKeyInfo omKeyInfo = null;
+    String multipartKey = null;
+    OmMultipartKeyInfo multipartKeyInfo = null;
+    Result result = null;
+    OmBucketInfo omBucketInfo = null;
+    OmBucketInfo copyBucketInfo = null;
+    try {
+      keyArgs = resolveBucketLink(ozoneManager, keyArgs, auditMap);
+      volumeName = keyArgs.getVolumeName();
+      bucketName = keyArgs.getBucketName();
+
+      // TODO to support S3 ACL later.
+      acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+          volumeName, bucketName);
+
+      validateBucketAndVolume(omMetadataManager, volumeName, bucketName);
+
+      String fileName = OzoneFSUtils.getFileName(keyName);
+      Iterator<Path> pathComponents = Paths.get(keyName).iterator();
+      String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
+      omBucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
+      long bucketId = omBucketInfo.getObjectID();
+      long parentID = OMFileRequest.getParentID(bucketId, pathComponents,
+              keyName, omMetadataManager);
+
+      String uploadID = keyArgs.getMultipartUploadID();
+      multipartKey = omMetadataManager.getMultipartKey(parentID,
+          fileName, uploadID);
+
+      multipartKeyInfo = omMetadataManager.getMultipartInfoTable()
+          .get(multipartKey);
+
+      long clientID = multipartCommitUploadPartRequest.getClientID();
+
+      openKey = omMetadataManager.getOpenFileName(parentID, fileName, clientID);
+
+      omKeyInfo = OMFileRequest.getOmKeyInfoFromFileTable(true,
+              omMetadataManager, openKey, keyName);
+
+      if (omKeyInfo == null) {
+        throw new OMException("Failed to commit Multipart Upload key, as " +
+            openKey + "entry is not found in the openKey table",
+            KEY_NOT_FOUND);
+      }
+
+      // set the data size and location info list
+      omKeyInfo.setDataSize(keyArgs.getDataSize());
+      omKeyInfo.updateLocationInfoList(keyArgs.getKeyLocationsList().stream()
+          .map(OmKeyLocationInfo::getFromProtobuf)
+          .collect(Collectors.toList()));
+      // Set Modification time
+      omKeyInfo.setModificationTime(keyArgs.getModificationTime());
+      // Set the UpdateID to current transactionLogIndex
+      omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
+
+      String ozoneKey = omMetadataManager.getOzonePathKey(parentID, fileName);
+      partName = ozoneKey + clientID;
+
+      if (multipartKeyInfo == null) {
+        // This can occur when user started uploading part by the time commit
+        // of that part happens, in between the user might have requested
+        // abort multipart upload. If we just throw exception, then the data
+        // will not be garbage collected, so move this part to delete table
+        // and throw error
+        // Move this part to delete table.
+        throw new OMException("No such Multipart upload is with specified " +
+            "uploadId " + uploadID,
+            OMException.ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
+      }
+
+      int partNumber = keyArgs.getMultipartNumber();
+      oldPartKeyInfo = multipartKeyInfo.getPartKeyInfo(partNumber);
+
+      // Build this multipart upload part info.
+      OzoneManagerProtocolProtos.PartKeyInfo.Builder partKeyInfo =
+          OzoneManagerProtocolProtos.PartKeyInfo.newBuilder();
+      partKeyInfo.setPartName(partName);
+      partKeyInfo.setPartNumber(partNumber);
+      partKeyInfo.setPartKeyInfo(omKeyInfo.getProtobuf(
+          getOmRequest().getVersion()));
+
+      // Add this part information in to multipartKeyInfo.
+      multipartKeyInfo.addPartKeyInfo(partNumber, partKeyInfo.build());
+
+      // Set the UpdateID to current transactionLogIndex
+      multipartKeyInfo.setUpdateID(trxnLogIndex,
+          ozoneManager.isRatisEnabled());
+
+      // OldPartKeyInfo will be deleted. Its updateID will be set in
+      // S3MultipartUplodaCommitPartResponse before being added to
+      // DeletedKeyTable.
+
+      // Add to cache.
+
+      // Delete from open key table and add it to multipart info table.
+      // No need to add cache entries to delete table, as no
+      // read/write requests that info for validation.
+      omMetadataManager.getMultipartInfoTable().addCacheEntry(
+          new CacheKey<>(multipartKey),
+          new CacheValue<>(Optional.of(multipartKeyInfo),
+              trxnLogIndex));
+
+      omMetadataManager.getOpenKeyTable().addCacheEntry(
+          new CacheKey<>(openKey),

Review comment:
       @rakeshadr , sorry for that my previous comment is not very clear. My point is that we have a different open key defined in S3InitiateMultipartUploadRequestV1 and S3MultipartUploadCommitPartRequestV1.
   
   In S3InitiateMultipartUploadRequestV1, the key inserted is set as 
   
   ```java
         String multipartKey = omMetadataManager.getMultipartKey(
                 pathInfoV1.getLastKnownParentId(), pathInfoV1.getLeafNodeName(),
                 keyArgs.getMultipartUploadID());
   
         ...
         OMFileRequest.addOpenFileTableCacheEntry(omMetadataManager,
                 multipartKey, omKeyInfo, pathInfoV1.getLeafNodeName(),
                 transactionLogIndex);
   ```
   
   But in the S3MultipartUploadCommitPartRequestV1 request,  the key changed to 
   
   ```java
   openKey = omMetadataManager.getOpenFileName(parentID, fileName, clientID);
   omMetadataManager.getOpenKeyTable().addCacheEntry(
             new CacheKey<>(openKey),
             new CacheValue<>(Optional.absent(), trxnLogIndex));
   ```
   Above multipartKey (parentID, fileName, uploadID)is equals to openKey (parentID, fileName, clientID)here? 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org