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 @@ -56,3 +56,11 @@ Compare Key With Local File with Different File
Compare Key With Local File if File Does Not Exist
${matches} = Compare Key With Local File o3://${OM_SERVICE_ID}/vol1/bucket/passwd /no-such-file
Should Be Equal ${matches} ${FALSE}

Rejects Put Key With Zero Expected Generation
${output} = Execute and checkrc ozone sh key put --expectedGeneration 0 o3://${OM_SERVICE_ID}/vol1/bucket/passwd /etc/passwd 255
Should Contain ${output} must be positive

Rejects Put Key With Negative Expected Generation
${output} = Execute and checkrc ozone sh key put --expectedGeneration -1 o3://${OM_SERVICE_ID}/vol1/bucket/passwd /etc/passwd 255
Should Contain ${output} must be positive
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class PutKeyHandler extends KeyHandler {

@Option(names = "--expectedGeneration",
description = "Store key only if it already exists and its generation matches the value provided")
private long expectedGeneration;
private Long expectedGeneration;

@Override
protected void execute(OzoneClient client, OzoneAddress address)
Expand Down Expand Up @@ -131,9 +131,14 @@ private void async(
private OzoneOutputStream createOrReplaceKey(OzoneBucket bucket, String keyName,
long size, Map<String, String> keyMetadata, ReplicationConfig replicationConfig
) throws IOException {
return expectedGeneration > 0
? bucket.rewriteKey(keyName, size, expectedGeneration, replicationConfig, keyMetadata)
: bucket.createKey(keyName, size, replicationConfig, keyMetadata);
if (expectedGeneration != null) {
final long existingGeneration = expectedGeneration;
Preconditions.checkArgument(existingGeneration > 0,
"expectedGeneration must be positive, but was %s", existingGeneration);
return bucket.rewriteKey(keyName, size, existingGeneration, replicationConfig, keyMetadata);
}

return bucket.createKey(keyName, size, replicationConfig, keyMetadata);
}

private void stream(
Expand Down