-
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
Changes from all commits
3575d98
cbfa154
d40f98b
cf6788d
47f08b9
2b6774b
876871e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
@@ -37,6 +38,7 @@ | |
import java.util.StringJoiner; | ||
import java.util.regex.Pattern; | ||
|
||
import com.carrotsearch.hppc.cursors.ObjectObjectCursor; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.collect.Sets; | ||
import org.apache.logging.log4j.LogManager; | ||
|
@@ -78,7 +80,6 @@ | |
import org.opensearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.opensearch.cluster.service.ClusterService; | ||
import org.opensearch.common.Strings; | ||
import org.opensearch.common.collect.ImmutableOpenMap; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.transport.TransportAddress; | ||
import org.opensearch.common.util.concurrent.ThreadContext; | ||
|
@@ -378,8 +379,6 @@ public PrivilegesEvaluatorResponse evaluate(final User user, String action0, fin | |
presponse.allowed = true; | ||
return presponse; | ||
} | ||
|
||
|
||
} | ||
} | ||
|
||
|
@@ -632,6 +631,7 @@ public static boolean isClusterPerm(String action0) { | |
) ; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private boolean checkFilteredAliases(Resolved requestedResolved, String action, boolean isDebugEnabled) { | ||
final String faMode = dcm.getFilteredAliasMode();// getConfigSettings().dynamic.filtered_alias_mode; | ||
|
||
|
@@ -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 clusterService.state().getMetadata().getIndices().values().iterator(); | ||
} | ||
}; | ||
} else { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. @scrawfor99 Why did you make this change? Doesn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @andrross, I made this swap because we could not use There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 If you just need an iterator over the keys then use There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
for (ObjectObjectCursor<String, AliasMetadata> cursor : indexMetaData.getAliases()) { | ||
aliases.put(cursor.key, cursor.value); | ||
} | ||
|
||
if(aliases != null && aliases.size() > 0) { | ||
if (isDebugEnabled) { | ||
log.debug("Aliases for {}: {}", indexMetaData.getIndex().getName(), aliases); | ||
} | ||
|
||
final Iterator<String> it = aliases.keysIt(); | ||
final Iterator<String> it = aliases.keySet().iterator(); | ||
while(it.hasNext()) { | ||
final String alias = it.next(); | ||
final AliasMetadata aliasMetadata = aliases.get(alias); | ||
|
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:
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.