-
Notifications
You must be signed in to change notification settings - Fork 282
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
Resolve ImmutableOpenMap issue from core refactor #2715
Resolve ImmutableOpenMap issue from core refactor #2715
Conversation
Signed-off-by: Stephen Crawford <[email protected]>
Will have to wait until the next build: https://build.ci.opensearch.org/job/distribution-build-opensearch/7748/ before we can actually confirm this is fixed. Most recent build gets pulled as part of build but that does not include the Core changes. |
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.
Hi @scrawfor99 , thanks for this fix. Sorry I had to dismissed my previous approve, because I was trying this fix on my local machine, and I think we need to fix some of the functions. I left a comment down below.
@@ -41,8 +41,8 @@ public AliasExistsMatcher(String aliasName) { | |||
protected boolean matchesSafely(Client client, Description mismatchDescription) { | |||
try { | |||
GetAliasesResponse response = client.admin().indices().getAliases(new GetAliasesRequest(aliasName)).get(); | |||
ImmutableOpenMap<String, List<AliasMetadata>> aliases = response.getAliases(); | |||
Set<String> actualAliasNames = StreamSupport.stream(spliteratorUnknownSize(aliases.valuesIt(), IMMUTABLE), false) | |||
Map<String, List<AliasMetadata>> aliases = response.getAliases(); |
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 for this getAliases()
, we also need to fix it, because it is also depending on the stale library of ImmutableOpenMap
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.
Oh okay, I will take a look.
Signed-off-by: Stephen Crawford <[email protected]>
93ef49d
to
cbfa154
Compare
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
@@ -649,7 +649,7 @@ private boolean checkFilteredAliases(Resolved requestedResolved, String action, | |||
indexMetaDataCollection = new Iterable<IndexMetadata>() { | |||
@Override | |||
public Iterator<IndexMetadata> iterator() { | |||
return clusterService.state().getMetadata().getIndices().valuesIt(); | |||
return (Iterator<IndexMetadata>) clusterService.state().getMetadata().getIndices().values(); |
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.
2023-04-24T19:23:06.3310228Z 1> java.lang.ClassCastException: class java.util.Collections$UnmodifiableCollection cannot be cast to class java.util.Iterator (java.util.Collections$UnmodifiableCollection and java.util.Iterator are in module java.base of loader 'bootstrap')
2023-04-24T19:23:06.3310965Z 1> at org.opensearch.security.privileges.PrivilegesEvaluator$1.iterator(PrivilegesEvaluator.java:652) ~[main/:?]
Think you might be missing a .iterator()
call before attempting to return, can you do this without the unchecked suppression?
You can repro the test failure with org.opensearch.security.IndexIntegrationTests.testIndexResolveMinus
for a quick turnaround
Signed-off-by: Stephen Crawford <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #2715 +/- ##
============================================
+ Coverage 61.45% 61.48% +0.03%
- Complexity 3385 3398 +13
============================================
Files 270 272 +2
Lines 18694 18743 +49
Branches 3279 3285 +6
============================================
+ Hits 11488 11524 +36
- Misses 5611 5620 +9
- Partials 1595 1599 +4
... and 2 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
final Map<String, Settings> indexToSettings = new HashMap<>(); | ||
for (ObjectObjectCursor<String, Settings> cursor : response.getIndexToSettings()) { | ||
indexToSettings.put(cursor.key, cursor.value); | ||
} |
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.
Can this be simplified to:
final Map<String, Settings> indexToSettings = new HashMap<>(); | |
for (ObjectObjectCursor<String, Settings> cursor : response.getIndexToSettings()) { | |
indexToSettings.put(cursor.key, cursor.value); | |
} | |
final Set<String> indexKeys = new HashSet<>(); | |
for (ObjectObjectCursor<String, Settings> cursor : response.getIndexToSettings()) { | |
indexKeys.add(cursor.key); | |
} |
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.
Looks like either would work, but since we are not using the values in the map and only getting a keySet it would take less memory.
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.
Sorry Craig, I didn't see this before the PR got merged. I had left it as a map because that is what the original implementation was. I agree that a Set should work fine here as well. If you wanted to swap it you could open up a quick PR to change it in main.
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.
Thank you @scrawfor99, the changes look good to me. I left one suggestion so let me know what you think. It wouldn't block this PR from being approved and merged. If the suggestion doesn't work then let me know and I will approve this PR.
@@ -674,14 +674,17 @@ public Iterator<IndexMetadata> iterator() { | |||
|
|||
final List<AliasMetadata> filteredAliases = new ArrayList<AliasMetadata>(); | |||
|
|||
final ImmutableOpenMap<String, AliasMetadata> aliases = indexMetaData.getAliases(); | |||
final Map<String, AliasMetadata> aliases = new HashMap<>(); |
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.
@scrawfor99 Why did you make this change? Doesn't indexMetaData.getAliases()
still return an ImmutableOpenMap? Seems like you should avoid making a copy of the map in any case.
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.
Hi @andrross, I made this swap because we could not use keysIt
anymore. We needed aliases
to be a normal map to then grab and iterate over the keyset. Is there an issue with this implementation?
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.
@nknize What's happening here? Pretty sure making a copy of the the map is the exact opposite of your intention with this change.
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 was the issue that arose when the change was made to core: #2714. I just made changes to get things Green. Sorry if this was not the intended implementation...
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.
Sorry @scrawfor99! Definitely not trying to blame you here! I don't understand why keysIt
doesn't work anymore, and I don't think the intent with @nknize's change is to force downstream dependencies to copy data structures when doing a simple iteration.
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.
Hi @andrross, no need to apologize :). I just want to make sure I did the correct thing. I did not look that closely into the overall reasoning for the change in core. I just checked to find the overall cause of the issue we were facing and then took the fastest route to unblocking. If you or Nick, have an alternative solution that is the preferred method now just let me know and I can make a swap. In the linked issue, I showed an example of the errors we were getting which was basically Java complaining about not being able to find the ImmutableOpenMap method definitions.
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.
No copies unless you need to make changes to the map (even then the core should return an unmodifiableMap
so you would only be able to change a clone).
If you just need an iterator over the keys then use .keySet().iterator()
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.
@scrawfor99 The code in question changed to be a plain map. I think you should be able to simplify this and get rid of the copy.
…#2715) Signed-off-by: Maciej Mierzwa <[email protected]>
…#2715) Signed-off-by: Maciej Mierzwa <[email protected]>
…#2715) Signed-off-by: Maciej Mierzwa <[email protected]>
…#2715) Signed-off-by: Sam <[email protected]>
* Resolve ImmutableOpenMap issue from core refactor (#2715) * Switch from ImmutableOpenMap to Map in AliasExistsMatcher (#2725) * Remove references to ObjectObjectCursor Signed-off-by: Craig Perkins <[email protected]> * Switch from ImmutableOpenMap to Map in AliasExistsMatcher (#2725) * Remove references to ObjectObjectCursor Signed-off-by: Craig Perkins <[email protected]> * Removes a missed reference for ImmutableOpenMap (#2726) Signed-off-by: Darshit Chanpura <[email protected]> * Update ClusterInfoHolder Signed-off-by: Craig Perkins <[email protected]> * Run spotlessApply Signed-off-by: Craig Perkins <[email protected]> --------- Signed-off-by: Craig Perkins <[email protected]> Signed-off-by: Darshit Chanpura <[email protected]> Co-authored-by: Stephen Crawford <[email protected]> Co-authored-by: Darshit Chanpura <[email protected]>
Description
Removes use of the ImmutableOpenMap from Security code to resolve issue #2714.
Check List
New functionality includes testingNew functionality has been documentedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.