Skip to content

Conversation

@echonesis
Copy link
Contributor

@echonesis echonesis commented Dec 4, 2025

What changes were proposed in this pull request?

This PR makes OmPrefixInfo immutable.

Essential modifications:

  • Add @Immutable to OmPrefixInfo
  • Remove setAcls, addAcl and removeAcl.

What is the link to the Apache JIRA

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

How was this patch tested?

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

@echonesis echonesis marked this pull request as ready for review December 4, 2025 08:13
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.


public boolean setAcls(List<OzoneAcl> newAcls) {
return OzoneAclUtil.setAcl(acls, newAcls);
return ImmutableList.copyOf(acls);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: since acls is already ImmutableList, we don't need to copy it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are correct; it is already an ImmutableList.

However, SpotBugs (FindBugs) appears to be mistakenly reporting an issue when detected via:

grep -c 'OmPrefixInfo' target/findbugs/summary.txt

Given this, should we proceed to return acls directly?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that can be fixed by:

  private final ImmutableList<OzoneAcl> acls;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!
This will be included in the next commit.


assertEquals(omPrefixInfo, clonePrefixInfo);

OmPrefixInfo modifiedPrefixInfo = new OmPrefixInfo.Builder(omPrefixInfo)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
OmPrefixInfo modifiedPrefixInfo = new OmPrefixInfo.Builder(omPrefixInfo)
OmPrefixInfo modifiedPrefixInfo = omPrefixInfo.toBuilder()

Comment on lines +105 to +108
assertThrows(UnsupportedOperationException.class,
() -> omPrefixInfo.getAcls().add(OzoneAcl.of(
IAccessAuthorizer.ACLIdentityType.USER, username,
ACCESS, IAccessAuthorizer.ACLType.READ)));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this belongs to a separate test case, since it verifies immutability

}

boolean removed = prefixInfo.removeAcl(ozoneAcl);
List<OzoneAcl> updatedAcls = new ArrayList<>(prefixInfo.getAcls());
Copy link
Contributor

Choose a reason for hiding this comment

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

This copies the list of ACLs, then Builder.setAcls copies them to its own list. I'd like to avoid this double copying. Please see #9430 for proposed improvement, used in OmVolumeArgs as POC. If it's accepted, can be applied to OmPrefixInfo and other classes, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!
I will follow #9430 design.

Comment on lines 265 to 266
metadataManager.getPrefixTable().put(ozoneObj.getPath(),
updatedPrefixInfo);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: no need to wrap (also in removeAcl and setAcl)

Suggested change
metadataManager.getPrefixTable().put(ozoneObj.getPath(),
updatedPrefixInfo);
metadataManager.getPrefixTable().put(ozoneObj.getPath(), updatedPrefixInfo);

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