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 @@ -1432,7 +1432,7 @@ public OzoneOutputStream rewriteKey(String volumeName, String bucketName, String
.addAllMetadataGdpr(metadata)
.setLatestVersionLocation(getLatestVersionLocation)
.setOwnerName(ownerName)
.setRewriteGeneration(existingKeyGeneration);
.setExpectedDataGeneration(existingKeyGeneration);

OpenKeySession openKey = ozoneManagerClient.openKey(builder.build());
// For bucket with layout OBJECT_STORE, when create an empty file (size=0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public final class OmKeyArgs implements Auditable {
private final boolean recursive;
private final boolean headOp;
private final boolean forceUpdateContainerCacheFromSCM;
// RewriteGeneration, when used in key creation indicates that a
// expectedDataGeneration, when used in key creation indicates that a
// key with the same keyName should exist with the given generation.
// For a key commit to succeed, the original key should still be present with the
// generation unchanged.
// This allows a key to be created an committed atomically if the original has not
// been modified.
private Long rewriteGeneration = null;
private Long expectedDataGeneration = null;

private OmKeyArgs(Builder b) {
this.volumeName = b.volumeName;
Expand All @@ -79,7 +79,7 @@ private OmKeyArgs(Builder b) {
this.headOp = b.headOp;
this.forceUpdateContainerCacheFromSCM = b.forceUpdateContainerCacheFromSCM;
this.ownerName = b.ownerName;
this.rewriteGeneration = b.rewriteGeneration;
this.expectedDataGeneration = b.expectedDataGeneration;
}

public boolean getIsMultipartKey() {
Expand Down Expand Up @@ -158,8 +158,8 @@ public boolean isForceUpdateContainerCacheFromSCM() {
return forceUpdateContainerCacheFromSCM;
}

public Long getRewriteGeneration() {
return rewriteGeneration;
public Long getExpectedDataGeneration() {
return expectedDataGeneration;
}

@Override
Expand Down Expand Up @@ -203,8 +203,8 @@ public OmKeyArgs.Builder toBuilder() {
.setAcls(acls)
.setForceUpdateContainerCacheFromSCM(forceUpdateContainerCacheFromSCM);

if (rewriteGeneration != null) {
builder.setRewriteGeneration(rewriteGeneration);
if (expectedDataGeneration != null) {
builder.setExpectedDataGeneration(expectedDataGeneration);
}
return builder;
}
Expand All @@ -221,8 +221,8 @@ public KeyArgs toProtobuf() {
.setHeadOp(isHeadOp())
.setForceUpdateContainerCacheFromSCM(
isForceUpdateContainerCacheFromSCM());
if (rewriteGeneration != null) {
builder.setRewriteGeneration(rewriteGeneration);
if (expectedDataGeneration != null) {
builder.setExpectedDataGeneration(expectedDataGeneration);
}
return builder.build();
}
Expand All @@ -248,7 +248,7 @@ public static class Builder {
private boolean recursive;
private boolean headOp;
private boolean forceUpdateContainerCacheFromSCM;
private Long rewriteGeneration = null;
private Long expectedDataGeneration = null;

public Builder setVolumeName(String volume) {
this.volumeName = volume;
Expand Down Expand Up @@ -348,8 +348,8 @@ public Builder setForceUpdateContainerCacheFromSCM(boolean value) {
return this;
}

public Builder setRewriteGeneration(long generation) {
this.rewriteGeneration = generation;
public Builder setExpectedDataGeneration(long generation) {
this.expectedDataGeneration = generation;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ public static Codec<OmKeyInfo> getCodec(boolean ignorePipeline) {
*/
private final CopyOnWriteArrayList<OzoneAcl> acls;

// rewriteGeneration, when used in key creation indicates that a
// expectedDataGeneration, when used in key creation indicates that a
// key with the same keyName should exist with the given generation.
// For a key commit to succeed, the original key should still be present with the
// generation unchanged.
// This allows a key to be created an committed atomically if the original has not
// been modified.
private Long rewriteGeneration = null;
private Long expectedDataGeneration = null;

private OmKeyInfo(Builder b) {
super(b);
Expand All @@ -126,7 +126,7 @@ private OmKeyInfo(Builder b) {
this.fileName = b.fileName;
this.isFile = b.isFile;
this.ownerName = b.ownerName;
this.rewriteGeneration = b.rewriteGeneration;
this.expectedDataGeneration = b.expectedDataGeneration;
}

public String getVolumeName() {
Expand Down Expand Up @@ -169,12 +169,12 @@ public String getFileName() {
return fileName;
}

public void setRewriteGeneration(Long generation) {
this.rewriteGeneration = generation;
public void setExpectedDataGeneration(Long generation) {
this.expectedDataGeneration = generation;
}

public Long getRewriteGeneration() {
return rewriteGeneration;
public Long getExpectedDataGeneration() {
return expectedDataGeneration;
}

public String getOwnerName() {
Expand Down Expand Up @@ -460,7 +460,7 @@ public static class Builder extends WithParentObjectId.Builder {
private FileChecksum fileChecksum;

private boolean isFile;
private Long rewriteGeneration = null;
private Long expectedDataGeneration = null;

public Builder() {
}
Expand Down Expand Up @@ -589,8 +589,8 @@ public Builder setFile(boolean isAFile) {
return this;
}

public Builder setRewriteGeneration(Long existingGeneration) {
this.rewriteGeneration = existingGeneration;
public Builder setExpectedDataGeneration(Long existingGeneration) {
this.expectedDataGeneration = existingGeneration;
return this;
}

Expand Down Expand Up @@ -698,8 +698,8 @@ private KeyInfo getProtobuf(boolean ignorePipeline, String fullKeyName,
kb.setFileEncryptionInfo(OMPBHelper.convert(encInfo));
}
kb.setIsFile(isFile);
if (rewriteGeneration != null) {
kb.setRewriteGeneration(rewriteGeneration);
if (expectedDataGeneration != null) {
kb.setExpectedDataGeneration(expectedDataGeneration);
}
if (ownerName != null) {
kb.setOwnerName(ownerName);
Expand Down Expand Up @@ -750,8 +750,8 @@ public static OmKeyInfo getFromProtobuf(KeyInfo keyInfo) throws IOException {
if (keyInfo.hasIsFile()) {
builder.setFile(keyInfo.getIsFile());
}
if (keyInfo.hasRewriteGeneration()) {
builder.setRewriteGeneration(keyInfo.getRewriteGeneration());
if (keyInfo.hasExpectedDataGeneration()) {
builder.setExpectedDataGeneration(keyInfo.getExpectedDataGeneration());
}

if (keyInfo.hasOwnerName()) {
Expand Down Expand Up @@ -867,8 +867,8 @@ public OmKeyInfo copyObject() {
if (fileChecksum != null) {
builder.setFileChecksum(fileChecksum);
}
if (rewriteGeneration != null) {
builder.setRewriteGeneration(rewriteGeneration);
if (expectedDataGeneration != null) {
builder.setExpectedDataGeneration(expectedDataGeneration);
}

return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,8 @@ public OpenKeySession openKey(OmKeyArgs args) throws IOException {

keyArgs.setSortDatanodes(args.getSortDatanodes());

if (args.getRewriteGeneration() != null) {
keyArgs.setRewriteGeneration(args.getRewriteGeneration());
if (args.getExpectedDataGeneration() != null) {
keyArgs.setExpectedDataGeneration(args.getExpectedDataGeneration());
}

req.setKeyArgs(keyArgs.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void protobufConversion() throws IOException {
assertFalse(key.isHsync());
key.getMetadata().put(OzoneConsts.HSYNC_CLIENT_ID, "clientid");
assertTrue(key.isHsync());
assertEquals(5678L, key.getRewriteGeneration());
assertEquals(5678L, key.getExpectedDataGeneration());
}

@Test
Expand Down Expand Up @@ -124,7 +124,7 @@ private OmKeyInfo createOmKeyInfo(ReplicationConfig replicationConfig) {
.setReplicationConfig(replicationConfig)
.addMetadata("key1", "value1")
.addMetadata("key2", "value2")
.setRewriteGeneration(5678L)
.setExpectedDataGeneration(5678L)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1026,13 +1026,13 @@ message KeyArgs {
// Force OM to update container cache location from SCL
optional bool forceUpdateContainerCacheFromSCM = 20;
optional string ownerName = 21;
// rewriteGeneration, when used in key creation indicates that a
// expectedDataGeneration, when used in key creation indicates that a
// key with the same keyName should exist with the given generation.
// For a key commit to succeed, the original key should still be present with the
// generation unchanged.
// This allows a key to be created an committed atomically if the original has not
// been modified.
optional uint64 rewriteGeneration = 22;
optional uint64 expectedDataGeneration = 22;
}

message KeyLocation {
Expand Down Expand Up @@ -1116,13 +1116,13 @@ message KeyInfo {
optional FileChecksumProto fileChecksum = 18;
optional bool isFile = 19;
optional string ownerName = 20;
// rewriteGeneration, when used in key creation indicates that a
// expectedDataGeneration, when used in key creation indicates that a
// key with the same keyName should exist with the given generation.
// For a key commit to succeed, the original key should still be present with the
// generation unchanged.
// This allows a key to be created an committed atomically if the original has not
// been modified.
optional uint64 rewriteGeneration = 21;
optional uint64 expectedDataGeneration = 21;
}

message BasicKeyInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ default Map<String, String> buildKeyArgsAuditMap(KeyArgs keyArgs) {
auditMap.put(OzoneConsts.REPLICATION_CONFIG,
ECReplicationConfig.toString(keyArgs.getEcReplicationConfig()));
}
if (keyArgs.hasRewriteGeneration()) {
if (keyArgs.hasExpectedDataGeneration()) {
auditMap.put(OzoneConsts.REWRITE_GENERATION,
String.valueOf(keyArgs.getRewriteGeneration()));
String.valueOf(keyArgs.getExpectedDataGeneration()));
}
for (HddsProtos.KeyValue item : keyArgs.getMetadataList()) {
if (ETAG.equals(item.getKey())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn
validateAtomicRewrite(keyToDelete, omKeyInfo, auditMap);
// Optimistic locking validation has passed. Now set the rewrite fields to null so they are
// not persisted in the key table.
omKeyInfo.setRewriteGeneration(null);
omKeyInfo.setExpectedDataGeneration(null);

omKeyInfo.getMetadata().putAll(KeyValueUtil.getFromProtobuf(
commitKeyArgs.getMetadataList()));
Expand Down Expand Up @@ -506,16 +506,16 @@ public static OMRequest disallowHsync(

private void validateAtomicRewrite(OmKeyInfo existing, OmKeyInfo toCommit, Map<String, String> auditMap)
throws OMException {
if (toCommit.getRewriteGeneration() != null) {
if (toCommit.getExpectedDataGeneration() != null) {
// These values are not passed in the request keyArgs, so add them into the auditMap if they are present
// in the open key entry.
auditMap.put(OzoneConsts.REWRITE_GENERATION, String.valueOf(toCommit.getRewriteGeneration()));
auditMap.put(OzoneConsts.REWRITE_GENERATION, String.valueOf(toCommit.getExpectedDataGeneration()));
if (existing == null) {
throw new OMException("Atomic rewrite is not allowed for a new key", KEY_NOT_FOUND);
}
if (!toCommit.getRewriteGeneration().equals(existing.getUpdateID())) {
if (!toCommit.getExpectedDataGeneration().equals(existing.getUpdateID())) {
throw new OMException("Cannot commit as current generation (" + existing.getUpdateID() +
") does not match with the rewrite generation (" + toCommit.getRewriteGeneration() + ")",
") does not match with the rewrite generation (" + toCommit.getExpectedDataGeneration() + ")",
KEY_NOT_FOUND);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,12 @@ public static OMRequest blockCreateKeyWithBucketLayoutFromOldClient(

private void validateAtomicRewrite(OmKeyInfo dbKeyInfo, KeyArgs keyArgs)
throws OMException {
if (keyArgs.hasRewriteGeneration()) {
if (keyArgs.hasExpectedDataGeneration()) {
// 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() != keyArgs.getRewriteGeneration()) {
if (dbKeyInfo.getUpdateID() != keyArgs.getExpectedDataGeneration()) {
throw new OMException("Generation mismatch during expected rewrite", OMException.ResultCodes.KEY_NOT_FOUND);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,8 @@ protected OmKeyInfo prepareFileInfo(
dbKeyInfo.getMetadata().putAll(KeyValueUtil.getFromProtobuf(
keyArgs.getMetadataList()));

if (keyArgs.hasRewriteGeneration()) {
dbKeyInfo.setRewriteGeneration(keyArgs.getRewriteGeneration());
if (keyArgs.hasExpectedDataGeneration()) {
dbKeyInfo.setExpectedDataGeneration(keyArgs.getExpectedDataGeneration());
}
dbKeyInfo.setFileEncryptionInfo(encInfo);
return dbKeyInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void testAtomicRewrite() throws Exception {

OmKeyInfo.Builder omKeyInfoBuilder = OMRequestTestUtils.createOmKeyInfo(
volumeName, bucketName, keyName, replicationConfig, new OmKeyLocationInfoGroup(version, new ArrayList<>()));
omKeyInfoBuilder.setRewriteGeneration(1L);
omKeyInfoBuilder.setExpectedDataGeneration(1L);
OmKeyInfo omKeyInfo = omKeyInfoBuilder.build();
omKeyInfo.appendNewBlocks(allocatedLocationList, false);
List<OzoneAcl> acls = Collections.singletonList(OzoneAcl.parseAcl("user:foo:rw"));
Expand All @@ -268,7 +268,7 @@ public void testAtomicRewrite() throws Exception {
assertEquals(KEY_NOT_FOUND, omClientResponse.getOMResponse().getStatus());

// Now add the key to the key table, and try again, but with different generation
omKeyInfoBuilder.setRewriteGeneration(null);
omKeyInfoBuilder.setExpectedDataGeneration(null);
omKeyInfoBuilder.setUpdateID(0L);
OmKeyInfo invalidKeyInfo = omKeyInfoBuilder.build();
closedKeyTable.put(getOzonePathKey(), invalidKeyInfo);
Expand All @@ -287,7 +287,7 @@ public void testAtomicRewrite() throws Exception {
assertEquals(OK, omClientResponse.getOMResponse().getStatus());

OmKeyInfo committedKey = closedKeyTable.get(getOzonePathKey());
assertNull(committedKey.getRewriteGeneration());
assertNull(committedKey.getExpectedDataGeneration());
// Generation should be changed
assertNotEquals(closedKeyInfo.getGeneration(), committedKey.getGeneration());
assertEquals(acls, committedKey.getAcls());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,14 +706,14 @@ protected OMRequest createKeyRequest(boolean isMultipartKey, int partNumber,

private OMRequest createKeyRequest(
boolean isMultipartKey, int partNumber, long keyLength,
ReplicationConfig repConfig, Long rewriteGeneration) {
ReplicationConfig repConfig, Long expectedDataGeneration) {
return createKeyRequest(isMultipartKey, partNumber, keyLength, repConfig,
rewriteGeneration, null);
expectedDataGeneration, null);
}

private OMRequest createKeyRequest(
boolean isMultipartKey, int partNumber, long keyLength,
ReplicationConfig repConfig, Long rewriteGeneration, Map<String, String> metaData) {
ReplicationConfig repConfig, Long expectedDataGeneration, Map<String, String> metaData) {

KeyArgs.Builder keyArgs = KeyArgs.newBuilder()
.setVolumeName(volumeName).setBucketName(bucketName)
Expand All @@ -732,8 +732,8 @@ private OMRequest createKeyRequest(
if (isMultipartKey) {
keyArgs.setMultipartNumber(partNumber);
}
if (rewriteGeneration != null) {
keyArgs.setRewriteGeneration(rewriteGeneration);
if (expectedDataGeneration != null) {
keyArgs.setExpectedDataGeneration(expectedDataGeneration);
}
if (metaData != null) {
metaData.forEach((key, value) -> keyArgs.addMetadata(KeyValue.newBuilder()
Expand Down Expand Up @@ -981,12 +981,12 @@ public void testAtomicRewrite(
response = omKeyCreateRequest.validateAndUpdateCache(ozoneManager, 105L);
assertEquals(OK, response.getOMResponse().getStatus());

// Ensure the rewriteGeneration is persisted in the open key table
// Ensure the expectedDataGeneration is persisted in the open key table
String openKey = omMetadataManager.getOpenKey(volumeName, bucketName,
keyName, omRequest.getCreateKeyRequest().getClientID());
OmKeyInfo openKeyInfo = omMetadataManager.getOpenKeyTable(omKeyCreateRequest.getBucketLayout()).get(openKey);

assertEquals(existingKeyInfo.getGeneration(), openKeyInfo.getRewriteGeneration());
assertEquals(existingKeyInfo.getGeneration(), openKeyInfo.getExpectedDataGeneration());
// Creation time should remain the same on rewrite.
assertEquals(existingKeyInfo.getCreationTime(), openKeyInfo.getCreationTime());
// Update ID should change
Expand Down