peterxcli commented on code in PR #10164:
URL: https://github.com/apache/ozone/pull/10164#discussion_r3172709382
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java:
##########
@@ -770,6 +782,15 @@ public Response completeMultipartUpload(
"considered as Unix Paths. A directory already exists with a " +
"given KeyName caused failure for MPU");
throw os3Exception;
+ } else if (ex.getResult() == ResultCodes.KEY_ALREADY_EXISTS
+ || ex.getResult() == ResultCodes.ETAG_MISMATCH
+ || ex.getResult() == ResultCodes.ETAG_NOT_AVAILABLE) {
+ // Conditional write precondition failed
Review Comment:
```suggestion
```
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/s3/multipart/S3MultipartUploadCompleteRequest.java:
##########
@@ -269,6 +269,16 @@ public OMClientResponse
validateAndUpdateCache(OzoneManager ozoneManager, Execut
OMException.ResultCodes.NO_SUCH_MULTIPART_UPLOAD_ERROR);
}
+ // Conditional write validation for If-None-Match / If-Match headers
+ // Load existing committed key to check preconditions
+ OmKeyInfo existingKeyInfo =
omMetadataManager.getKeyTable(getBucketLayout()).get(dbOzoneKey);
+
+ // Validate If-None-Match: * (create-if-absent) or generation match
+ validateAtomicRewrite(existingKeyInfo, keyArgs);
+
+ // Convert If-Match ETag to expectedDataGeneration for atomic validation
+ keyArgs = validateAndRewriteIfMatchAsExpectedGeneration(keyArgs,
existingKeyInfo);
Review Comment:
Curious why you choose to rewrite here?
```suggestion
```
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java:
##########
@@ -770,6 +782,15 @@ public Response completeMultipartUpload(
"considered as Unix Paths. A directory already exists with a " +
"given KeyName caused failure for MPU");
throw os3Exception;
+ } else if (ex.getResult() == ResultCodes.KEY_ALREADY_EXISTS
+ || ex.getResult() == ResultCodes.ETAG_MISMATCH
+ || ex.getResult() == ResultCodes.ETAG_NOT_AVAILABLE) {
+ // Conditional write precondition failed
+ throw newError(PRECOND_FAILED, key, ex);
+ } else if (ex.getResult() == ResultCodes.KEY_NOT_FOUND
+ && writeConditions.hasIfMatch()) {
+ // If-Match failed because the key doesn't exist
Review Comment:
```suggestion
```
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMKeyCreateRequest.java:
##########
@@ -476,56 +476,6 @@ public static OMRequest
blockCreateKeyWithBucketLayoutFromOldClient(
return req;
}
- protected void validateAtomicRewrite(OmKeyInfo dbKeyInfo, KeyArgs keyArgs)
- throws OMException {
- if (keyArgs.hasExpectedDataGeneration()) {
- long expectedGen = keyArgs.getExpectedDataGeneration();
- // If expectedGen is EXPECTED_GEN_CREATE_IF_NOT_EXISTS, it means the key
MUST NOT exist (If-None-Match)
- if (expectedGen == OzoneConsts.EXPECTED_GEN_CREATE_IF_NOT_EXISTS) {
- if (dbKeyInfo != null) {
- throw new OMException("Key already exists",
- OMException.ResultCodes.KEY_ALREADY_EXISTS);
- }
- } else {
- // If a key does not exist, or if it exists but the updateID do not
match, then fail this request.
- if (dbKeyInfo == null) {
- throw new OMException("Key not found during expected rewrite",
OMException.ResultCodes.KEY_NOT_FOUND);
- }
- if (dbKeyInfo.getUpdateID() != expectedGen) {
- throw new OMException("Generation mismatch during expected rewrite",
- OMException.ResultCodes.KEY_NOT_FOUND);
- }
- }
- }
-
- }
-
- protected KeyArgs validateAndRewriteIfMatchAsExpectedGeneration(
- KeyArgs keyArgs, OmKeyInfo dbKeyInfo) throws OMException {
- if (!keyArgs.hasExpectedETag()) {
- return keyArgs;
- }
-
- String expectedETag = keyArgs.getExpectedETag();
- if (dbKeyInfo == null) {
- throw new OMException("Key not found for If-Match",
- OMException.ResultCodes.KEY_NOT_FOUND);
- }
- if (!dbKeyInfo.hasEtag()) {
- throw new OMException("Key does not have an ETag",
- OMException.ResultCodes.ETAG_NOT_AVAILABLE);
- }
- if (!dbKeyInfo.isEtagEquals(expectedETag)) {
- throw new OMException("ETag mismatch",
- OMException.ResultCodes.ETAG_MISMATCH);
- }
- if (keyArgs.hasExpectedDataGeneration()) {
- return keyArgs;
- }
-
- return keyArgs.toBuilder()
- .setExpectedDataGeneration(dbKeyInfo.getUpdateID())
- .clearExpectedETag()
- .build();
- }
+ // validateAtomicRewrite() and
validateAndRewriteIfMatchAsExpectedGeneration()
+ // are inherited from OMKeyRequest base class
Review Comment:
```suggestion
```
--
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]