kerneltime commented on code in PR #6385:
URL: https://github.com/apache/ozone/pull/6385#discussion_r1571124162
##########
hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneBucket.java:
##########
@@ -469,6 +469,30 @@ public OzoneOutputStream createKey(String key, long size,
.createKey(volumeName, name, key, size, replicationConfig,
keyMetadata);
}
+ /**
+ * Overwrite an existing key using optimistic locking. The existingKey must
exist in Ozone to allow
+ * the new key to be created with the same name. Additionally, the existing
Key must not have been
+ * modified since the time it's details were read. This is controlled by the
updateID
+ * field in the existing Key. If the key is replaced or updated the updateID
will change. If the
+ * updateID has changed since the existing Key was read, either the initial
key create will fail,
+ * or the key will fail to commit after the data has been written as the
checks are carried out
+ * both a key open and commit time.
+ *
+ * For now this feature only works on Object Store Buckets. FSO support will
be added a later.
+ *
+ * @param existingKey Name of the key to be created.
+ * @param replicationConfig Replication configuration.
+ * @return OzoneOutputStream to which the data has to be written.
+ * @throws IOException
+ */
+ public OzoneOutputStream overwriteKey(OzoneKeyDetails existingKey,
ReplicationConfig replicationConfig)
Review Comment:
```suggestion
public OzoneOutputStream atomicUpdateKey(OzoneKeyDetails existingKey,
ReplicationConfig replicationConfig)
```
##########
hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneBucket.java:
##########
@@ -469,6 +469,30 @@ public OzoneOutputStream createKey(String key, long size,
.createKey(volumeName, name, key, size, replicationConfig,
keyMetadata);
}
+ /**
+ * Overwrite an existing key using optimistic locking. The existingKey must
exist in Ozone to allow
+ * the new key to be created with the same name. Additionally, the existing
Key must not have been
+ * modified since the time it's details were read. This is controlled by the
updateID
+ * field in the existing Key. If the key is replaced or updated the updateID
will change. If the
+ * updateID has changed since the existing Key was read, either the initial
key create will fail,
+ * or the key will fail to commit after the data has been written as the
checks are carried out
+ * both a key open and commit time.
+ *
+ * For now this feature only works on Object Store Buckets. FSO support will
be added a later.
+ *
+ * @param existingKey Name of the key to be created.
+ * @param replicationConfig Replication configuration.
+ * @return OzoneOutputStream to which the data has to be written.
+ * @throws IOException
+ */
+ public OzoneOutputStream overwriteKey(OzoneKeyDetails existingKey,
ReplicationConfig replicationConfig)
+ throws IOException {
+ if (this.bucketLayout != BucketLayout.OBJECT_STORE) {
+ throw new IllegalArgumentException("Optimistic locking is only supported
on Object Store Buckets");
Review Comment:
This validation should move into OM to allow older clients to be able to
update keys when OM supports it.
##########
hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneBucket.java:
##########
@@ -469,6 +469,30 @@ public OzoneOutputStream createKey(String key, long size,
.createKey(volumeName, name, key, size, replicationConfig,
keyMetadata);
}
+ /**
+ * Overwrite an existing key using optimistic locking. The existingKey must
exist in Ozone to allow
+ * the new key to be created with the same name. Additionally, the existing
Key must not have been
+ * modified since the time it's details were read. This is controlled by the
updateID
+ * field in the existing Key. If the key is replaced or updated the updateID
will change. If the
+ * updateID has changed since the existing Key was read, either the initial
key create will fail,
+ * or the key will fail to commit after the data has been written as the
checks are carried out
+ * both a key open and commit time.
+ *
+ * For now this feature only works on Object Store Buckets. FSO support will
be added a later.
Review Comment:
```suggestion
* This API allows to atomically update an existing key. The key read
before invoking this API
* should remain unchanged for this key to be written. This is controlled
by the updateID
* field in the existing Key param. If the key is replaced or updated the
updateID will change. If the
* updateID has changed since the existing Key was read, either the
initial key create will fail,
* or the key will fail to commit after the data has been written as the
checks are carried out
* both a key open and commit time.
*
* For now this feature only works on Object Store Buckets. FSO support
will be added a later.
```
##########
hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneKey.java:
##########
@@ -70,11 +70,19 @@ public class OzoneKey {
* Constructs OzoneKey from OmKeyInfo.
*
*/
+
+ /**
+ * The update ID of an existing key. This will be null if this OzoneKey
+ * object has not been created from an existing key read from OM, as OM
allocates
+ * the update ID on commit of the key.
+ */
+ private final Long updateID;
Review Comment:
We are leaking internal names into public APIs. For public facing API, I
would model it how google APIs have documented theirs :
https://cloud.google.com/storage/docs/metadata#generation-number
(We do not have the split between metadata only updates vs. whole object.)
For now, I would change this to `generation` and document the guarantees
that an application has around the use of generation. This should apply to the
entire PR, where we use `updateID` which is a more nebulous name.
--
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]