3535import java .util .List ;
3636import java .util .ListIterator ;
3737import java .util .Map ;
38+ import java .util .Objects ;
3839import java .util .Set ;
3940import java .util .regex .PatternSyntaxException ;
4041import java .util .stream .Collectors ;
4142
4243import com .google .common .collect .ImmutableSet ;
43- import org .apache .commons .collections .keyvalue .MultiKey ;
4444import org .apache .logging .log4j .LogManager ;
4545import org .apache .logging .log4j .Logger ;
4646import org .greenrobot .eventbus .Subscribe ;
@@ -112,7 +112,7 @@ public IndexResolverReplacer(IndexNameExpressionResolver resolver, ClusterServic
112112 this .clusterInfoHolder = clusterInfoHolder ;
113113 }
114114
115- private static final boolean isAllWithNoRemote (final String ... requestedPatterns ) {
115+ private static boolean isAllWithNoRemote (final String ... requestedPatterns ) {
116116
117117 final List <String > patterns = requestedPatterns == null ? null : Arrays .asList (requestedPatterns );
118118
@@ -131,11 +131,11 @@ private static final boolean isAllWithNoRemote(final String... requestedPatterns
131131 return false ;
132132 }
133133
134- private static final boolean isLocalAll (String ... requestedPatterns ) {
134+ private static boolean isLocalAll (String ... requestedPatterns ) {
135135 return isLocalAll (requestedPatterns == null ? null : Arrays .asList (requestedPatterns ));
136136 }
137137
138- private static final boolean isLocalAll (Collection <String > patterns ) {
138+ private static boolean isLocalAll (Collection <String > patterns ) {
139139 if (IndexNameExpressionResolver .isAllIndices (patterns )) {
140140 return true ;
141141 }
@@ -158,9 +158,49 @@ private class ResolvedIndicesProvider implements IndicesProvider {
158158 private final ImmutableSet .Builder <String > remoteIndices ;
159159 // set of previously resolved index requests to avoid resolving
160160 // the same index more than once while processing bulk requests
161- private final Set <MultiKey > alreadyResolved ;
161+ private final Set <AlreadyResolvedKey > alreadyResolved ;
162162 private final String name ;
163163
164+ private final class AlreadyResolvedKey {
165+
166+ private final IndicesOptions indicesOptions ;
167+
168+ private final boolean enableCrossClusterResolution ;
169+
170+ private final String [] original ;
171+
172+ private AlreadyResolvedKey (final IndicesOptions indicesOptions , final boolean enableCrossClusterResolution ) {
173+ this (indicesOptions , enableCrossClusterResolution , null );
174+ }
175+
176+ private AlreadyResolvedKey (
177+ final IndicesOptions indicesOptions ,
178+ final boolean enableCrossClusterResolution ,
179+ final String [] original
180+ ) {
181+ this .indicesOptions = indicesOptions ;
182+ this .enableCrossClusterResolution = enableCrossClusterResolution ;
183+ this .original = original ;
184+ }
185+
186+ @ Override
187+ public boolean equals (Object o ) {
188+ if (this == o ) return true ;
189+ if (o == null || getClass () != o .getClass ()) return false ;
190+ AlreadyResolvedKey that = (AlreadyResolvedKey ) o ;
191+ return enableCrossClusterResolution == that .enableCrossClusterResolution
192+ && Objects .equals (indicesOptions , that .indicesOptions )
193+ && Arrays .equals (original , that .original );
194+ }
195+
196+ @ Override
197+ public int hashCode () {
198+ int result = Objects .hash (indicesOptions , enableCrossClusterResolution );
199+ result = 31 * result + Arrays .hashCode (original );
200+ return result ;
201+ }
202+ }
203+
164204 ResolvedIndicesProvider (Object request ) {
165205 aliases = ImmutableSet .builder ();
166206 allIndices = ImmutableSet .builder ();
@@ -336,9 +376,13 @@ public String[] provide(String[] original, Object localRequest, boolean supports
336376 || localRequest instanceof SearchRequest
337377 || localRequest instanceof ResolveIndexAction .Request ;
338378 // skip the whole thing if we have seen this exact resolveIndexPatterns request
339- if (alreadyResolved .add (
340- new MultiKey (indicesOptions , enableCrossClusterResolution , (original != null ) ? new MultiKey (original , false ) : null )
341- )) {
379+ final AlreadyResolvedKey alreadyResolvedKey ;
380+ if (original != null ) {
381+ alreadyResolvedKey = new AlreadyResolvedKey (indicesOptions , enableCrossClusterResolution , original );
382+ } else {
383+ alreadyResolvedKey = new AlreadyResolvedKey (indicesOptions , enableCrossClusterResolution );
384+ }
385+ if (alreadyResolved .add (alreadyResolvedKey )) {
342386 resolveIndexPatterns (localRequest .getClass ().getSimpleName (), indicesOptions , enableCrossClusterResolution , original );
343387 }
344388 return IndicesProvider .NOOP ;
0 commit comments