ChenSammi commented on code in PR #10183:
URL: https://github.com/apache/ozone/pull/10183#discussion_r4236641145
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMKeyRequest.java:
##########
@@ -1369,46 +1369,96 @@ protected void validateEncryptionKeyInfo(OmBucketInfo
bucketInfo, KeyArgs keyArg
}
/**
- * Validates atomic rewrite conditions for conditional writes.
- * <p>
- * For If-None-Match: * (expectedDataGeneration =
EXPECTED_GEN_CREATE_IF_NOT_EXISTS),
- * the key must NOT exist.
- * <p>
- * For If-Match with a specific generation, the key must exist with matching
updateID.
+ * Resolves conditional write state at request admission time.
*
- * @param dbKeyInfo the existing key info from the database (null if key
doesn't exist)
- * @param keyArgs the key arguments containing expected generation
- * @throws OMException if validation fails
+ * This validates expected generations as admission-time preconditions and
+ * rewrites matching ETags into expected generations for commit-time checks.
*/
- protected void validateAtomicRewrite(OmKeyInfo dbKeyInfo, KeyArgs keyArgs)
- throws OMException {
+ protected KeyArgs resolveConditionalWriteAtAdmission(OmKeyInfo dbKeyInfo,
+ KeyArgs keyArgs, Map<String, String> auditMap) 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_ABSENT) {
- 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);
- }
+ validateAtomicRewriteAtAdmission(dbKeyInfo,
keyArgs.getExpectedDataGeneration(), auditMap);
+ return keyArgs;
+ }
+
+ return validateAndResolveIfMatchAsExpectedGeneration(keyArgs, dbKeyInfo,
auditMap);
+ }
+
+ /**
+ * Validates the condition at request admission time.
+ *
+ * This form is for callers that resolve the admitted generation from
+ * persisted open-key state rather than from request key arguments.
+ */
+ protected void validateAtomicRewriteAtAdmission(OmKeyInfo dbKeyInfo,
Review Comment:
Can we rename this function to validateExpectedGenAtAdmission, and next
function to validateExpectedGenAtCommit, since they are used not only in the
atomic rewrite case, but also create-if-not-exists case?
--
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]