Copilot commented on code in PR #12034:
URL: https://github.com/apache/ozone/pull/12034#discussion_r4551463668


##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/s3/multipart/TestS3MultipartUploadCompleteRequestWithFSO.java:
##########
@@ -158,6 +160,10 @@ public void 
testValidateAndUpdateCacheFileExistsInParentPath() throws Exception
     String uploadId = 
getS3InitiateMultipartUploadReq(initiateRequest).validateAndUpdateCache(ozoneManager,
 1L)
         
.getOMResponse().getInitiateMultiPartUploadResponse().getMultipartUploadID();
     String dirKey = omMetadataManager.getOzonePathKey(volumeId, bucketId, 
bucketId, "a");
+    long dirId = 
omMetadataManager.getDirectoryTable().get(dirKey).getObjectID();
+    String openKey = omMetadataManager.getMultipartKey(volumeId, bucketId, 
dirId, "b", uploadId);
+    OmKeyInfo openKeyInfo = 
omMetadataManager.getOpenKeyTable(getBucketLayout()).get(openKey);
+    assertNotNull(openKeyInfo);
     omMetadataManager.getDirectoryTable().addCacheEntry(new 
CacheKey<>(dirKey), CacheValue.get(2L));

Review Comment:
   This inserts a `Long` into the directory table cache, but elsewhere in this 
test you treat directory-table values as `OmDirectoryInfo` (eg, calling 
`.getObjectID()`). If the directory table is typed to `OmDirectoryInfo`, 
caching a `Long` risks runtime `ClassCastException` or inconsistent behavior. 
Use an `OmDirectoryInfo` (or the correct value type for the table) when 
inserting the cache entry.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/multipart/S3InitiateMultipartUploadRequestWithFSO.java:
##########
@@ -113,7 +110,7 @@ public OMClientResponse validateAndUpdateCache(OzoneManager 
ozoneManager, Execut
               keyName, Paths.get(keyName));
 
       // check if the directory already existed in OM
-      checkDirectoryResult(keyName, pathInfoFSO.getDirectoryResult());
+      OMFileRequest.checkDirectoryResult(keyName, true, 
pathInfoFSO.getDirectoryResult());

Review Comment:
   Passing the literal `true` for `isOverWrite` here effectively means \"ignore 
`FILE_EXISTS`\" (preserving prior behavior), but it reads as \"overwrite is 
enabled\" which is easy to misinterpret at the call site. Consider using a 
named local constant (eg, `boolean ignoreFileExistsAtKey = true`) or adding a 
short comment explaining why overwrite is forced to `true` for this path check.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/file/OMFileRequest.java:
##########
@@ -155,6 +155,32 @@ public static OMPathInfo verifyFilesInPath(
     return new OMPathInfo(missing, OMDirectoryResult.NONE, acls);
   }
 
+  /**
+   * Verify om directory result.
+   *
+   * @param keyName           key name
+   * @param isOverWrite       flag represents whether file can be overwritten
+   * @param omDirectoryResult directory result
+   * @throws OMException if file or directory or file exists in the given path
+   */
+  public static void checkDirectoryResult(String keyName, boolean isOverWrite,
+      OMDirectoryResult omDirectoryResult) throws OMException {
+    if (omDirectoryResult == OMDirectoryResult.FILE_EXISTS) {
+      if (!isOverWrite) {
+        throw new OMException("File " + keyName + " already exists",
+            OMException.ResultCodes.FILE_ALREADY_EXISTS);
+      }
+    } else if (omDirectoryResult == OMDirectoryResult.DIRECTORY_EXISTS) {
+      throw new OMException("Can not write to directory: " + keyName,
+          OMException.ResultCodes.NOT_A_FILE);
+    } else if (omDirectoryResult == 
OMDirectoryResult.FILE_EXISTS_IN_GIVENPATH) {
+      throw new OMException(
+          "Can not create file: " + keyName + " as there " +
+              "is already file in the given path",
+          OMException.ResultCodes.NOT_A_FILE);
+    }
+  }

Review Comment:
   The Javadoc says this throws when a file/directory exists in the given path, 
but the implementation only throws for `FILE_EXISTS_IN_GIVENPATH` (and does not 
throw for `DIRECTORY_EXISTS_IN_GIVENPATH`). Please update the `@throws` 
description (and/or document which `OMDirectoryResult` values are intentionally 
non-errors) so API behavior and documentation match.



##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/s3/multipart/TestS3MultipartUploadCompleteRequestWithFSO.java:
##########
@@ -167,8 +173,44 @@ public void 
testValidateAndUpdateCacheFileExistsInParentPath() throws Exception
     OMClientResponse response = 
getS3MultipartUploadCompleteReq(request).validateAndUpdateCache(ozoneManager, 
3L);
 
     assertEquals(OzoneManagerProtocolProtos.Status.NOT_A_FILE, 
response.getOMResponse().getStatus());
+    assertEquals(openKeyInfo, 
omMetadataManager.getOpenKeyTable(getBucketLayout()).get(openKey));
+  }
+
+  @Test
+  public void testValidateAndUpdateCacheDirectoryExistsAtKey() throws 
Exception {
+    String volumeName = UUID.randomUUID().toString();
+    String bucketName = UUID.randomUUID().toString();
+    addVolumeAndBucket(volumeName, bucketName);
+    long volumeId = omMetadataManager.getVolumeId(volumeName);
+    long bucketId = omMetadataManager.getBucketId(volumeName, bucketName);
+    OMClientResponse initiateResponse = getS3InitiateMultipartUploadReq(
+        doPreExecuteInitiateMPU(volumeName, bucketName, 
"x/a")).validateAndUpdateCache(ozoneManager, 1L);
+    assertEquals(OzoneManagerProtocolProtos.Status.OK, 
initiateResponse.getOMResponse().getStatus());
+    String uploadId = 
initiateResponse.getOMResponse().getInitiateMultiPartUploadResponse().getMultipartUploadID();
+    long oldParentId = omMetadataManager.getDirectoryTable()
+        .get(omMetadataManager.getOzonePathKey(volumeId, bucketId, bucketId, 
"x")).getObjectID();
+    String openKey = omMetadataManager.getMultipartKey(volumeId, bucketId, 
oldParentId, "a", uploadId);
+    String multipartKey = omMetadataManager.getMultipartKey(volumeName, 
bucketName, "x/a", uploadId);
+    OmKeyInfo openKeyInfo = 
omMetadataManager.getOpenKeyTable(getBucketLayout()).get(openKey);
+    OmMultipartKeyInfo multipartKeyInfo = 
omMetadataManager.getMultipartInfoTable().get(multipartKey);
+    assertNotNull(openKeyInfo);
+    assertNotNull(multipartKeyInfo);
+    // Replace "x" with a new directory that has a directory "a" in it.
+    OMRequestTestUtils.addParentsToDirTable(volumeName, bucketName, "x/a", 
omMetadataManager);
+    long newParentId = omMetadataManager.getDirectoryTable()
+        .get(omMetadataManager.getOzonePathKey(volumeId, bucketId, bucketId, 
"x")).getObjectID();

Review Comment:
   This test assumes `addParentsToDirTable(..., \"x/a\", ...)` replaces the 
existing directory entry for `x` and changes its objectID, but if the helper 
only creates missing parents (typical behavior), `newParentId` will equal 
`oldParentId` and the test will fail/flap. To make the test deterministic, 
explicitly remove/overwrite the existing `x` directory entry before re-adding, 
or adjust the scenario so the ID change is guaranteed (eg, create a different 
parent path that forces a different parentId rather than expecting `x` to be 
replaced in-place).



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