-
Notifications
You must be signed in to change notification settings - Fork 581
HDDS-10522. Make OmPrefixInfo immutable #9427
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
base: master
Are you sure you want to change the base?
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.
|
|
||
| public boolean setAcls(List<OzoneAcl> newAcls) { | ||
| return OzoneAclUtil.setAcl(acls, newAcls); | ||
| return ImmutableList.copyOf(acls); |
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.
nit: since acls is already ImmutableList, we don't need to copy it.
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.
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?
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.
I think that can be fixed by:
private final ImmutableList<OzoneAcl> acls;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!
This will be included in the next commit.
|
|
||
| assertEquals(omPrefixInfo, clonePrefixInfo); | ||
|
|
||
| OmPrefixInfo modifiedPrefixInfo = new OmPrefixInfo.Builder(omPrefixInfo) |
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.
nit:
| OmPrefixInfo modifiedPrefixInfo = new OmPrefixInfo.Builder(omPrefixInfo) | |
| OmPrefixInfo modifiedPrefixInfo = omPrefixInfo.toBuilder() |
| assertThrows(UnsupportedOperationException.class, | ||
| () -> omPrefixInfo.getAcls().add(OzoneAcl.of( | ||
| IAccessAuthorizer.ACLIdentityType.USER, username, | ||
| ACCESS, IAccessAuthorizer.ACLType.READ))); |
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.
nit: this belongs to a separate test case, since it verifies immutability
| } | ||
|
|
||
| boolean removed = prefixInfo.removeAcl(ozoneAcl); | ||
| List<OzoneAcl> updatedAcls = new ArrayList<>(prefixInfo.getAcls()); |
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.
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.
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!
I will follow #9430 design.
| metadataManager.getPrefixTable().put(ozoneObj.getPath(), | ||
| updatedPrefixInfo); |
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.
nit: no need to wrap (also in removeAcl and setAcl)
| metadataManager.getPrefixTable().put(ozoneObj.getPath(), | |
| updatedPrefixInfo); | |
| metadataManager.getPrefixTable().put(ozoneObj.getPath(), updatedPrefixInfo); |
What changes were proposed in this pull request?
This PR makes
OmPrefixInfoimmutable.Essential modifications:
@ImmutabletoOmPrefixInfosetAcls,addAclandremoveAcl.What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-10522
How was this patch tested?