Skip to content

Conversation

@echonesis
Copy link
Contributor

@echonesis echonesis commented Nov 14, 2025

What changes were proposed in this pull request?

This PR makes WithMetadata immutable. See #6193 for similar change and make them consistent.

Essential modifications:

  • Add @Immutable to WithMetadata
  • Modify OmKeyInfo w.r.t. usage under RpcClient

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-10388

How was this patch tested?

$ hadoop-ozone/dev-support/checks/findbugs.sh -Dspotbugs.version=4.8.3.0
$ grep -c 'WithMetadata' target/findbugs/summary.txt
0

@echonesis echonesis marked this pull request as draft November 14, 2025 09:57
@echonesis echonesis marked this pull request as ready for review November 15, 2025 04:02
Copy link
Contributor

@adoroszlai adoroszlai left a 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.

Comment on lines 69 to 73
.build();
if (hsync) {
keyInfo.getMetadata().put(OzoneConsts.HSYNC_CLIENT_ID, "clientid");
keyInfo = keyInfo.withMetadataMutations(metadata ->
metadata.put(OzoneConsts.HSYNC_CLIENT_ID, "clientid"));
}
Copy link
Contributor

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);
Copy link
Contributor

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.

Comment on lines 591 to 597
.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)));
Copy link
Contributor

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.

Comment on lines 230 to 234
}
openKeyInfo.getMetadata().put(OzoneConsts.LEASE_RECOVERY, "true");
openKeyInfo = openKeyInfo.withMetadataMutations(
metadata -> metadata.put(OzoneConsts.LEASE_RECOVERY, "true"));
openKeyInfo.setUpdateID(transactionLogIndex);
openKeyInfo.setModificationTime(Time.now());
Copy link
Contributor

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).

Comment on lines 277 to 280
openKeyToDelete = openKeyToDelete.withMetadataMutations(
metadata -> metadata.put(OzoneConsts.OVERWRITTEN_HSYNC_KEY, "true"));
openKeyToDelete.setModificationTime(Time.now());
openKeyToDelete.setUpdateID(trxnLogIndex);
Copy link
Contributor

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.

Comment on lines 387 to 393
// 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));
}
Copy link
Contributor

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.

Comment on lines 204 to 208
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);
Copy link
Contributor

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.

Comment on lines 984 to 988
dbKeyInfo = dbKeyInfo.withMetadataMutations(metadata -> {
metadata.clear();
metadata.putAll(KeyValueUtil.getFromProtobuf(
keyArgs.getMetadataList()));
});
Copy link
Contributor

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.

Comment on lines 164 to 166
omKeyInfo = omKeyInfo.withMetadataMutations(metadata ->
metadata.putAll(KeyValueUtil.getFromProtobuf(
keyArgs.getMetadataList())));
Copy link
Contributor

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.

Comment on lines 522 to 527
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));
Copy link
Contributor

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.

@adoroszlai adoroszlai merged commit f4660a2 into apache:master Nov 16, 2025
43 checks passed
@adoroszlai
Copy link
Contributor

Thanks @echonesis for the patch.

@echonesis
Copy link
Contributor Author

Thanks @adoroszlai for the review and merging.

@echonesis echonesis deleted the HDDS-10388 branch November 16, 2025 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants