Resolve ImmutableOpenMap issue from core refactor#2715
Resolve ImmutableOpenMap issue from core refactor#2715peternied merged 7 commits intoopensearch-project:mainfrom
Conversation
Signed-off-by: Stephen Crawford <steecraw@amazon.com>
|
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. |
RyanL1997
left a comment
There was a problem hiding this comment.
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.
| 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.
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.
Oh okay, I will take a look.
Signed-off-by: Stephen Crawford <steecraw@amazon.com>
93ef49d to
cbfa154
Compare
Signed-off-by: Stephen Crawford <steecraw@amazon.com>
Signed-off-by: Stephen Crawford <steecraw@amazon.com>
| @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.
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 <steecraw@amazon.com>
Signed-off-by: Stephen Crawford <steecraw@amazon.com>
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.
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.
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.
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.
| 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.
@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.
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.
@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.
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.
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.
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.
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.
@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 <dev.maciej.mierzwa@gmail.com>
…#2715) Signed-off-by: Maciej Mierzwa <dev.maciej.mierzwa@gmail.com>
…#2715) Signed-off-by: Maciej Mierzwa <dev.maciej.mierzwa@gmail.com>
…#2715) Signed-off-by: Sam <samuel.costa@eliatra.com>
* Resolve ImmutableOpenMap issue from core refactor (#2715) * Switch from ImmutableOpenMap to Map in AliasExistsMatcher (#2725) * Remove references to ObjectObjectCursor Signed-off-by: Craig Perkins <cwperx@amazon.com> * Switch from ImmutableOpenMap to Map in AliasExistsMatcher (#2725) * Remove references to ObjectObjectCursor Signed-off-by: Craig Perkins <cwperx@amazon.com> * Removes a missed reference for ImmutableOpenMap (#2726) Signed-off-by: Darshit Chanpura <dchanp@amazon.com> * Update ClusterInfoHolder Signed-off-by: Craig Perkins <cwperx@amazon.com> * Run spotlessApply Signed-off-by: Craig Perkins <cwperx@amazon.com> --------- Signed-off-by: Craig Perkins <cwperx@amazon.com> Signed-off-by: Darshit Chanpura <dchanp@amazon.com> Co-authored-by: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> Co-authored-by: Darshit Chanpura <35282393+DarshitChanpura@users.noreply.github.com>
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.