Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public final class OzoneConsts {
public static final String USER_PREFIX = "userPrefix";
public static final String REWRITE_GENERATION = "rewriteGeneration";
/** Sentinel generation used to request atomic create-if-not-exists(put if absent) semantics. */
public static final long EXPECTED_GEN_CREATE_IF_NOT_EXISTS = -1L;
public static final long EXPECTED_GEN_CREATE_IF_ABSENT = 0L;
public static final String FROM_SNAPSHOT = "fromSnapshot";
public static final String TO_SNAPSHOT = "toSnapshot";
public static final String TOKEN = "token";
Expand Down
2 changes: 1 addition & 1 deletion hadoop-hdds/docs/content/design/s3-conditional-requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ sequenceDiagram

User->>GW: PUT object with If-None-Match:* or If-Match:etag
alt If-None-Match: *
GW->>OM: createKey(expectedDataGeneration = -1)
GW->>OM: createKey(expectedDataGeneration = 0)
OM->>OM: Reject if key already exists
OM-->>GW: Open key or KEY_ALREADY_EXISTS
opt Open key created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ public OzoneOutputStream createKeyIfNotExists(String volumeName,
OmKeyArgs.Builder builder = createWriteKeyArgsBuilder(volumeName,
bucketName, keyName, size, replicationConfig, metadata, tags);
builder.setExpectedDataGeneration(
OzoneConsts.EXPECTED_GEN_CREATE_IF_NOT_EXISTS);
OzoneConsts.EXPECTED_GEN_CREATE_IF_ABSENT);
return openOutputStream(builder.build(), size);
}

Expand Down Expand Up @@ -1550,7 +1550,7 @@ public OzoneDataStreamOutput createStreamKeyIfNotExists(String volumeName,
volumeName, bucketName, keyName, size, replicationConfig, metadata,
tags);
builder.setExpectedDataGeneration(
OzoneConsts.EXPECTED_GEN_CREATE_IF_NOT_EXISTS);
OzoneConsts.EXPECTED_GEN_CREATE_IF_ABSENT);
return openDataStreamOutput(builder.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SNAPSHOT_DELETING_SERVICE_INTERVAL;
import static org.apache.hadoop.ozone.OzoneConsts.DEFAULT_OM_UPDATE_ID;
import static org.apache.hadoop.ozone.OzoneConsts.ETAG;
import static org.apache.hadoop.ozone.OzoneConsts.EXPECTED_GEN_CREATE_IF_NOT_EXISTS;
import static org.apache.hadoop.ozone.OzoneConsts.EXPECTED_GEN_CREATE_IF_ABSENT;
import static org.apache.hadoop.ozone.OzoneConsts.GB;
import static org.apache.hadoop.ozone.OzoneConsts.MD5_HASH;
import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER;
Expand Down Expand Up @@ -1450,7 +1450,7 @@ void rewriteRejectsNonPositiveGeneration(BucketLayout layout)
() -> {
bucket.rewriteKey("key2",
1024,
EXPECTED_GEN_CREATE_IF_NOT_EXISTS,
EXPECTED_GEN_CREATE_IF_ABSENT,
RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.ONE),
singletonMap("key", "value"));
});
Expand Down Expand Up @@ -3957,7 +3957,7 @@ public void testConditionalCompleteMultipartUploadIfNoneMatch() throws Exception
// Complete with If-None-Match semantics (key doesn't exist, should succeed)
OmMultipartUploadCompleteInfo result = bucket.completeMultipartUpload(
keyName, uploadID, partsMap,
EXPECTED_GEN_CREATE_IF_NOT_EXISTS, null);
EXPECTED_GEN_CREATE_IF_ABSENT, null);

assertNotNull(result);
assertEquals(keyName, result.getKey());
Expand Down Expand Up @@ -3993,7 +3993,7 @@ public void testConditionalCompleteMultipartUploadIfNoneMatchFail() throws Excep
// Complete with If-None-Match semantics (key exists, should fail)
OMException omEx = assertThrows(OMException.class,
() -> bucket.completeMultipartUpload(keyName, uploadID, partsMap,
EXPECTED_GEN_CREATE_IF_NOT_EXISTS, null));
EXPECTED_GEN_CREATE_IF_ABSENT, null));

assertEquals(KEY_ALREADY_EXISTS, omEx.getResult());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {

if (keyArgs.hasExpectedDataGeneration()) {
if (keyArgs.getExpectedDataGeneration()
== OzoneConsts.EXPECTED_GEN_CREATE_IF_NOT_EXISTS) {
== OzoneConsts.EXPECTED_GEN_CREATE_IF_ABSENT) {
ozoneManager.checkFeatureEnabled(
OzoneManagerVersion.ATOMIC_CREATE_IF_NOT_EXISTS);
} else {
Expand Down Expand Up @@ -625,7 +625,7 @@ protected void validateAtomicRewrite(OmKeyInfo existing, OmKeyInfo toCommit, Map
Long expectedGen = toCommit.getExpectedDataGeneration();
auditMap.put(OzoneConsts.REWRITE_GENERATION, String.valueOf(expectedGen));

if (expectedGen == OzoneConsts.EXPECTED_GEN_CREATE_IF_NOT_EXISTS) {
if (expectedGen == OzoneConsts.EXPECTED_GEN_CREATE_IF_ABSENT) {
if (existing != null) {
throw new OMException("Atomic create-if-not-exists conflicted with an existing key",
OMException.ResultCodes.ATOMIC_WRITE_CONFLICT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {

if (keyArgs.hasExpectedDataGeneration()) {
if (keyArgs.getExpectedDataGeneration()
== OzoneConsts.EXPECTED_GEN_CREATE_IF_NOT_EXISTS) {
== OzoneConsts.EXPECTED_GEN_CREATE_IF_ABSENT) {
ozoneManager.checkFeatureEnabled(
OzoneManagerVersion.ATOMIC_CREATE_IF_NOT_EXISTS);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ protected void validateAtomicRewrite(OmKeyInfo dbKeyInfo, KeyArgs keyArgs)
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 (expectedGen == OzoneConsts.EXPECTED_GEN_CREATE_IF_ABSENT) {
if (dbKeyInfo != null) {
throw new OMException("Key already exists",
OMException.ResultCodes.KEY_ALREADY_EXISTS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public void testAtomicCreateIfNotExistsCommitKeyAbsent() throws Exception {
OmKeyInfo.Builder omKeyInfoBuilder = OMRequestTestUtils.createOmKeyInfo(
volumeName, bucketName, keyName, replicationConfig,
new OmKeyLocationInfoGroup(version, new ArrayList<>()));
omKeyInfoBuilder.setExpectedDataGeneration(OzoneConsts.EXPECTED_GEN_CREATE_IF_NOT_EXISTS);
omKeyInfoBuilder.setExpectedDataGeneration(OzoneConsts.EXPECTED_GEN_CREATE_IF_ABSENT);

String openKey = addKeyToOpenKeyTable(allocatedLocationList, omKeyInfoBuilder);
assertNotNull(openKeyTable.get(openKey));
Expand Down Expand Up @@ -335,7 +335,7 @@ public void testAtomicCreateIfNotExistsCommitKeyAlreadyExists() throws Exception
OmKeyInfo.Builder omKeyInfoBuilder = OMRequestTestUtils.createOmKeyInfo(
volumeName, bucketName, keyName, replicationConfig,
new OmKeyLocationInfoGroup(version, new ArrayList<>()));
omKeyInfoBuilder.setExpectedDataGeneration(OzoneConsts.EXPECTED_GEN_CREATE_IF_NOT_EXISTS);
omKeyInfoBuilder.setExpectedDataGeneration(OzoneConsts.EXPECTED_GEN_CREATE_IF_ABSENT);

String openKey = addKeyToOpenKeyTable(allocatedLocationList, omKeyInfoBuilder);
assertNotNull(openKeyTable.get(openKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void testCreateKeyExpectedGenCreateIfNotExistsKeyMissing(

OMRequest modifiedOmRequest = doPreExecute(createKeyRequest(
false, 0, 100L, replicationConfig,
OzoneConsts.EXPECTED_GEN_CREATE_IF_NOT_EXISTS));
OzoneConsts.EXPECTED_GEN_CREATE_IF_ABSENT));
OMKeyCreateRequest omKeyCreateRequest = getOMKeyCreateRequest(modifiedOmRequest);

addVolumeAndBucketToDB(volumeName, bucketName, omMetadataManager, getBucketLayout());
Expand All @@ -170,7 +170,7 @@ public void testCreateKeyExpectedGenCreateIfNotExistsKeyMissing(
OmKeyInfo openKeyInfo = omMetadataManager.getOpenKeyTable(getBucketLayout())
.get(getOpenKey(id));
assertNotNull(openKeyInfo);
assertEquals(OzoneConsts.EXPECTED_GEN_CREATE_IF_NOT_EXISTS,
assertEquals(OzoneConsts.EXPECTED_GEN_CREATE_IF_ABSENT,
openKeyInfo.getExpectedDataGeneration());
}

Expand All @@ -183,7 +183,7 @@ public void testCreateKeyExpectedGenCreateIfNotExistsKeyAlreadyExists(

OMRequest modifiedOmRequest = doPreExecute(createKeyRequest(
false, 0, 100L, replicationConfig,
OzoneConsts.EXPECTED_GEN_CREATE_IF_NOT_EXISTS));
OzoneConsts.EXPECTED_GEN_CREATE_IF_ABSENT));
OMKeyCreateRequest omKeyCreateRequest = getOMKeyCreateRequest(modifiedOmRequest);

addVolumeAndBucketToDB(volumeName, bucketName, omMetadataManager, getBucketLayout());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ public Response completeMultipartUpload(
Long expectedDataGeneration = null;
String expectedETag = null;
if (writeConditions.hasIfNoneMatch()) {
expectedDataGeneration = OzoneConsts.EXPECTED_GEN_CREATE_IF_NOT_EXISTS;
expectedDataGeneration = OzoneConsts.EXPECTED_GEN_CREATE_IF_ABSENT;
} else if (writeConditions.hasIfMatch()) {
expectedETag = writeConditions.getExpectedETag();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.hadoop.ozone.client;

import static org.apache.hadoop.ozone.OzoneConsts.ETAG;
import static org.apache.hadoop.ozone.OzoneConsts.EXPECTED_GEN_CREATE_IF_NOT_EXISTS;
import static org.apache.hadoop.ozone.OzoneConsts.EXPECTED_GEN_CREATE_IF_ABSENT;
import static org.apache.hadoop.ozone.OzoneConsts.MD5_HASH;
import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER;

Expand Down Expand Up @@ -587,9 +587,9 @@ public OmMultipartUploadCompleteInfo completeMultipartUpload(String key,
public OmMultipartUploadCompleteInfo completeMultipartUpload(String key,
String uploadID, Map<Integer, String> partsMap,
Long expectedDataGeneration, String expectedETag) throws IOException {
// Handle If-None-Match: * (expectedDataGeneration == -1 means create-if-absent)
// Handle If-None-Match: * (expectedDataGeneration == 0 means create-if-absent)
if (expectedDataGeneration != null &&
expectedDataGeneration == EXPECTED_GEN_CREATE_IF_NOT_EXISTS) {
expectedDataGeneration == EXPECTED_GEN_CREATE_IF_ABSENT) {
if (keyContents.containsKey(key)) {
throw new OMException("Key already exists", ResultCodes.KEY_ALREADY_EXISTS);
}
Expand Down