Skip to content

HDDS-13919. S3 Conditional Writes (PutObject)#9815

Draft
peterxcli wants to merge 7 commits intoapache:masterfrom
peterxcli:HDDS-13919-conditional-writes
Draft

HDDS-13919. S3 Conditional Writes (PutObject)#9815
peterxcli wants to merge 7 commits intoapache:masterfrom
peterxcli:HDDS-13919-conditional-writes

Conversation

@peterxcli
Copy link
Member

@peterxcli peterxcli commented Feb 24, 2026

What changes were proposed in this pull request?

## Specification
### AWS S3 Conditional Write Specification
#### If-None-Match Header
```
If-None-Match: "*"
```
- Succeeds only if object does NOT exist
- Returns `412 Precondition Failed` if object exists
- Primary use case: Create-only semantics
#### If-Match Header
```
If-Match: "<etag>"
```
- Succeeds only if object EXISTS and ETag matches
- Returns `412 Precondition Failed` if object doesn't exist or ETag mismatches
- Primary use case: Atomic updates (compare-and-swap)

Should be merged after #9332

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-13919

How was this patch tested?

…ion handling

- Implemented tests for `createKey` and `rewriteKey` methods to validate behavior when using the `EXPECTED_GEN_CREATE_IF_NOT_EXISTS` constant.
- Added scenarios for key creation when the key is absent and when it already exists.
- Enhanced the `rewriteFailsWhenKeyExists` test to cover cases for both committed and uncommitted keys.
- Updated error handling to ensure correct responses for key existence checks.
@peterxcli peterxcli changed the title Hdds 13919 conditional writes HDDS-13919. S3 Conditional Writes (PutObject) Feb 24, 2026
Copy link
Contributor

@jojochuang jojochuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from a quick glance it looks mostly reasonable.

.addAllMetadataGdpr(metadata)
.addAllTags(tags)
.setLatestVersionLocation(getLatestVersionLocation)
.setExpectedETag(expectedETag);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it set setExpectedDataGeneration here?

Comment on lines 211 to +270
@@ -267,13 +267,17 @@ public enum ResultCodes {
UNAUTHORIZED,

S3_SECRET_ALREADY_EXISTS,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not commit changes that unrelated.

@@ -187,8 +188,18 @@ public Response put(
throw newError(S3ErrorTable.NO_SUCH_BUCKET, bucketName, ex);
} else if (ex.getResult() == ResultCodes.FILE_ALREADY_EXISTS) {
throw newError(S3ErrorTable.NO_OVERWRITE, keyPath, ex);
} else if (ex.getResult() == ResultCodes.KEY_ALREADY_EXISTS) {
throw newError(PRECOND_FAILED, keyPath, ex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you like to consider having different error messages for different cases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants