ivandika3 commented on code in PR #7558:
URL: https://github.com/apache/ozone/pull/7558#discussion_r1908087313


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/KeyManagerImpl.java:
##########
@@ -509,6 +509,33 @@ private OmKeyInfo readKeyInfo(OmKeyArgs args, BucketLayout 
bucketLayout)
     if (args.getLatestVersionLocation()) {
       slimLocationVersion(value);
     }
+    int partNumberParam = args.getMultipartUploadPartNumber();
+    if (partNumberParam > 0) {
+      OmKeyLocationInfoGroup latestLocationVersion = 
value.getLatestVersionLocations();
+      if (latestLocationVersion != null && 
latestLocationVersion.isMultipartKey()) {
+        List<OmKeyLocationInfo> currentLocations =
+            
value.getKeyLocationVersions().get(value.getKeyLocationVersions().size() - 1)
+                .getLocationList()
+                .stream()
+                .filter(it -> it.getPartNumber() == partNumberParam)
+                .collect(Collectors.toList());
+
+        value.setKeyLocationVersions(
+            Collections.singletonList(
+                new OmKeyLocationInfoGroup(
+                    latestLocationVersion.getVersion(),
+                    currentLocations,
+                    true
+                )
+            )
+        );
+
+        long dataLength = currentLocations.stream()
+            .mapToLong(BlockLocationInfo::getLength)
+            .sum();
+        value.setDataSize(dataLength);

Review Comment:
   How about this? This should be similar to `RpcClient#getS3KeyDetails`.
   ```java
       int partNumberParam = args.getMultipartUploadPartNumber();
       if (partNumberParam > 0) {
         // Similar to RpcClient#getS3KeyDetails
         OmKeyLocationInfoGroup latestLocationVersion = 
value.getLatestVersionLocations();
         if (latestLocationVersion != null && 
latestLocationVersion.isMultipartKey()) {
           List<OmKeyLocationInfo> filteredKeyLocationInfo =
               latestLocationVersion.getBlocksLatestVersionOnly()
                   .stream()
                   .filter(it -> it.getPartNumber() == partNumberParam)
                   .collect(Collectors.toList());
           value.updateLocationInfoList(filteredKeyLocationInfo, true);
           value.setDataSize(filteredKeyLocationInfo.stream()
               .mapToLong(OmKeyLocationInfo::getLength)
               .sum());
         }
       }
   ```
   
   You can further extract it to another function, but I'm fine if you don't 
choose to.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to