Skip to content

HDDS-13937. Make WithObjectID immutable#9327

Merged
adoroszlai merged 5 commits intoapache:masterfrom
echonesis:HDDS-13937
Nov 21, 2025
Merged

HDDS-13937. Make WithObjectID immutable#9327
adoroszlai merged 5 commits intoapache:masterfrom
echonesis:HDDS-13937

Conversation

@echonesis
Copy link
Contributor

@echonesis echonesis commented Nov 19, 2025

What changes were proposed in this pull request?

This PR makes WithObjectID immutable.

Essential modifications:

  • Add @Immutable to WithObjectID
  • Remove setObjectID and setUpdateID. Instead, add Builder.withObjectID and Builder.withUpdateID to support the same logic

What is the link to the Apache JIRA

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

How was this patch tested?

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

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.

Comment on lines +171 to +172
/** Hook method, customized in subclasses. */
public String getObjectInfo() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getObjectInfo is overridden in value subclasses, but not in builders. What's more, value classes override toString(), but builders do not.

Probably worth a separate sub-task to keep patches from growing huge.

Copy link
Contributor Author

@echonesis echonesis Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @adoroszlai
I agree with you.
Could I create a subtask under HDDS-10519 since HDDS-13937 has already been a sub-task?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, subtask of HDDS-10519.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created one sub-task, HDDS-13964, to handle this.

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 updating the patch.

Comment on lines +306 to +309
Map<String, String> metadataMap = omKeyInfo.toBuilder().getMetadata();
metadataMap.putAll(KeyValueUtil.getFromProtobuf(
commitKeyArgs.getMetadataList()));
omKeyInfo = omKeyInfo.toBuilder()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid duplicate toBuilder():

Suggested change
Map<String, String> metadataMap = omKeyInfo.toBuilder().getMetadata();
metadataMap.putAll(KeyValueUtil.getFromProtobuf(
commitKeyArgs.getMetadataList()));
omKeyInfo = omKeyInfo.toBuilder()
OmKeyInfo.Builder builder = omKeyInfo.toBuilder();
Map<String, String> metadataMap = builder.getMetadata();
metadataMap.putAll(KeyValueUtil.getFromProtobuf(
commitKeyArgs.getMetadataList()));
omKeyInfo = builder

Comment on lines +159 to +161
newOmBucketInfo.setUpdateID(transactionLogIndex);
newOmBucketInfo = newOmBucketInfo.toBuilder()
.withUpdateID(transactionLogIndex)
.build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move .withUpdateID into existing builder chain:

OmBucketInfo newOmBucketInfo = omBucketInfo.toBuilder()
.setOwner(newOwner)
.setModificationTime(setBucketPropertyRequest.getModificationTime())
.build();

Comment on lines +109 to +111
omKeyInfo = omKeyInfo.toBuilder()
.withUpdateID(trxnLogIndex)
.build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This updated omKeyInfo is not stored anywhere, so the updateID will be lost. We need to replace the item in the list.

Comment on lines +144 to +146
omKeyInfo = omKeyInfo.toBuilder()
.withUpdateID(trxnLogIndex)
.build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, need to update dirList.

Comment on lines 980 to 985
dbKeyInfo = dbKeyInfo.toBuilder()
.withUpdateID(transactionLogIndex)
.build();
dbKeyInfo.setReplicationConfig(replicationConfig);

// Construct a new metadata map from KeyArgs by rebuilding via toBuilder.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please combine these two builders.

Comment on lines +227 to +236
Map<String, String> metaDataMap = omKeyInfo.toBuilder().getMetadata();
metaDataMap.putAll(KeyValueUtil.getFromProtobuf(
commitKeyArgs.getMetadataList()));
omKeyInfo.setDataSize(commitKeyArgs.getDataSize());

List<OmKeyLocationInfo> uncommitted =
omKeyInfo.updateLocationInfoList(locationInfoList, false);

// Set the UpdateID to current transactionLogIndex
omKeyInfo.setUpdateID(trxnLogIndex);
omKeyInfo = omKeyInfo.toBuilder()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid duplicate toBuilder().

@echonesis echonesis requested a review from adoroszlai November 21, 2025 08:10
@adoroszlai
Copy link
Contributor

Thanks @echonesis for updating the patch, 6506a7d looks good.

a10e72a was unnecessary. This PR is already large, it does not need to move all mutations into the builder chains.

@echonesis
Copy link
Contributor Author

Thanks @echonesis for updating the patch, 6506a7d looks good.

a10e72a was unnecessary. This PR is already large, it does not need to move all mutations into the builder chains.

OK, got it. I will revert to 6506a7d

@adoroszlai adoroszlai merged commit 56e7988 into apache:master Nov 21, 2025
87 checks passed
@adoroszlai
Copy link
Contributor

Thanks @echonesis for the patch.

@echonesis
Copy link
Contributor Author

Thanks @adoroszlai for the review and merge.

@echonesis echonesis deleted the HDDS-13937 branch November 21, 2025 13:30
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