-
Notifications
You must be signed in to change notification settings - Fork 594
HDDS-10388. Make WithMetadata immutable #9293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
adoroszlai
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @echonesis for the patch, nicely done.
| .build(); | ||
| if (hsync) { | ||
| keyInfo.getMetadata().put(OzoneConsts.HSYNC_CLIENT_ID, "clientid"); | ||
| keyInfo = keyInfo.withMetadataMutations(metadata -> | ||
| metadata.put(OzoneConsts.HSYNC_CLIENT_ID, "clientid")); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metadata can be added before build() to avoid extra copy.
| OmKeyInfo keyInfo = createOmKeyInfo(volumeName, bucketName, keyName, | ||
| replicationConfig).build(); | ||
| keyInfo.setMetadata(initialMetadata); | ||
| replicationConfig).build().withMetadata(initialMetadata); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metadata can be added before build() to avoid extra copy.
| .build(); | ||
| omKeyInfo.appendNewBlocks(locationList, false); | ||
| if (hsyncFlag) { | ||
| omKeyInfo.getMetadata().put(OzoneConsts.HSYNC_CLIENT_ID, | ||
| String.valueOf(clientID)); | ||
| omKeyInfo = omKeyInfo.withMetadataMutations(metadata -> | ||
| metadata.put(OzoneConsts.HSYNC_CLIENT_ID, | ||
| String.valueOf(clientID))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metadata can be added before build() to avoid extra copy.
| } | ||
| openKeyInfo.getMetadata().put(OzoneConsts.LEASE_RECOVERY, "true"); | ||
| openKeyInfo = openKeyInfo.withMetadataMutations( | ||
| metadata -> metadata.put(OzoneConsts.LEASE_RECOVERY, "true")); | ||
| openKeyInfo.setUpdateID(transactionLogIndex); | ||
| openKeyInfo.setModificationTime(Time.now()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change to
openKeyInfo = openKeyInfo.toBuilder()
.addMetadata(...)
.build();to prepare for upcoming changes making WithObjectID / OmKeyInfo immutable (where we can simply move setUpdateID / setModificationTime into the builder chain).
| openKeyToDelete = openKeyToDelete.withMetadataMutations( | ||
| metadata -> metadata.put(OzoneConsts.OVERWRITTEN_HSYNC_KEY, "true")); | ||
| openKeyToDelete.setModificationTime(Time.now()); | ||
| openKeyToDelete.setUpdateID(trxnLogIndex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use toBuilder() directly here as well to prepare for future changes.
| // Prevent hsync metadata from getting committed to the final key | ||
| omKeyInfo.getMetadata().remove(OzoneConsts.HSYNC_CLIENT_ID); | ||
| omKeyInfo = omKeyInfo.withMetadataMutations( | ||
| metadata -> metadata.remove(OzoneConsts.HSYNC_CLIENT_ID)); | ||
| if (isRecovery) { | ||
| omKeyInfo.getMetadata().remove(OzoneConsts.LEASE_RECOVERY); | ||
| omKeyInfo = omKeyInfo.withMetadataMutations( | ||
| metadata -> metadata.remove(OzoneConsts.LEASE_RECOVERY)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's combine the two updates.
| omMetadataManager, dbOpenKeyToDeleteKey, keyName); | ||
| openKeyToDelete.getMetadata().put(OzoneConsts.OVERWRITTEN_HSYNC_KEY, "true"); | ||
| openKeyToDelete = openKeyToDelete.withMetadataMutations( | ||
| metadata -> metadata.put(OzoneConsts.OVERWRITTEN_HSYNC_KEY, "true")); | ||
| openKeyToDelete.setModificationTime(Time.now()); | ||
| openKeyToDelete.setUpdateID(trxnLogIndex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use toBuilder() directly here as well to prepare for future changes.
| dbKeyInfo = dbKeyInfo.withMetadataMutations(metadata -> { | ||
| metadata.clear(); | ||
| metadata.putAll(KeyValueUtil.getFromProtobuf( | ||
| keyArgs.getMetadataList())); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use toBuilder() directly here as well to prepare for future changes.
| omKeyInfo = omKeyInfo.withMetadataMutations(metadata -> | ||
| metadata.putAll(KeyValueUtil.getFromProtobuf( | ||
| keyArgs.getMetadataList()))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use toBuilder() directly here as well to prepare for future changes.
| if (dbOpenKeyInfo.getMetadata() != null) { | ||
| omKeyInfo.setMetadata(dbOpenKeyInfo.getMetadata()); | ||
| omKeyInfo = omKeyInfo.withMetadata(dbOpenKeyInfo.getMetadata()); | ||
| } | ||
| omKeyInfo.getMetadata().put(OzoneConsts.ETAG, | ||
| multipartUploadedKeyHash(partKeyInfoMap)); | ||
| final String multipartHash = multipartUploadedKeyHash(partKeyInfoMap); | ||
| omKeyInfo = omKeyInfo.withMetadataMutations( | ||
| metadata -> metadata.put(OzoneConsts.ETAG, multipartHash)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's combine the two updates.
|
Thanks @echonesis for the patch. |
|
Thanks @adoroszlai for the review and merging. |
What changes were proposed in this pull request?
This PR makes
WithMetadataimmutable. See #6193 for similar change and make them consistent.Essential modifications:
@ImmutabletoWithMetadataOmKeyInfow.r.t. usage underRpcClientWhat is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-10388
How was this patch tested?