Skip to content

Commit d0a9ea6

Browse files
Implementation of TransportIndicesResolvingAction removed from TransportMultiGetAction, TransportMultiSearchAction, TransportMultiTermVectorsAction.
1 parent d2b9c19 commit d0a9ea6

File tree

6 files changed

+6
-152
lines changed

6 files changed

+6
-152
lines changed

server/src/main/java/org/opensearch/action/OriginalIndices.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939

4040
import java.io.IOException;
4141
import java.util.Arrays;
42-
import java.util.LinkedHashSet;
43-
import java.util.Set;
4442

4543
/**
4644
* Used to keep track of original indices within internal (e.g. shard level) requests
@@ -94,20 +92,4 @@ public static void writeOriginalIndices(OriginalIndices originalIndices, StreamO
9492
public String toString() {
9593
return "OriginalIndices{" + "indices=" + Arrays.toString(indices) + ", indicesOptions=" + indicesOptions + '}';
9694
}
97-
98-
public OriginalIndices mergeWith(OriginalIndices value) {
99-
if(value == null) {
100-
return this;
101-
}
102-
Set<String> set = new LinkedHashSet<>();
103-
if (this.indices != null) {
104-
java.util.Collections.addAll(set, this.indices);
105-
}
106-
if (value.indices != null) {
107-
java.util.Collections.addAll(set, value.indices);
108-
}
109-
String[] newIndices = set.toArray(new String[0]);
110-
IndicesOptions newOptions = this.indicesOptions.mergeWith(value.indicesOptions);
111-
return new OriginalIndices(newIndices, newOptions);
112-
}
11395
}

server/src/main/java/org/opensearch/action/get/TransportMultiGetAction.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@
3535
import org.opensearch.action.RoutingMissingException;
3636
import org.opensearch.action.support.ActionFilters;
3737
import org.opensearch.action.support.HandledTransportAction;
38-
import org.opensearch.action.support.TransportIndicesResolvingAction;
3938
import org.opensearch.cluster.ClusterState;
4039
import org.opensearch.cluster.block.ClusterBlockLevel;
4140
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
4241
import org.opensearch.cluster.metadata.Metadata;
43-
import org.opensearch.cluster.metadata.ResolvedIndices;
4442
import org.opensearch.cluster.routing.Preference;
4543
import org.opensearch.cluster.service.ClusterService;
4644
import org.opensearch.common.inject.Inject;
@@ -50,9 +48,7 @@
5048
import org.opensearch.tasks.Task;
5149
import org.opensearch.transport.TransportService;
5250

53-
import java.util.ArrayList;
5451
import java.util.HashMap;
55-
import java.util.List;
5652
import java.util.Map;
5753
import java.util.concurrent.atomic.AtomicInteger;
5854

@@ -61,7 +57,7 @@
6157
*
6258
* @opensearch.internal
6359
*/
64-
public class TransportMultiGetAction extends HandledTransportAction<MultiGetRequest, MultiGetResponse> implements TransportIndicesResolvingAction<MultiGetRequest> {
60+
public class TransportMultiGetAction extends HandledTransportAction<MultiGetRequest, MultiGetResponse> {
6561

6662
private final ClusterService clusterService;
6763
private final TransportShardMultiGetAction shardAction;
@@ -178,24 +174,4 @@ private void finishHim() {
178174
private static MultiGetItemResponse newItemFailure(String index, String id, Exception exception) {
179175
return new MultiGetItemResponse(null, new MultiGetResponse.Failure(index, id, exception));
180176
}
181-
182-
@Override
183-
public ResolvedIndices resolveIndices(MultiGetRequest request) {
184-
// TODO do we need these preconditions?
185-
ClusterState clusterState = clusterService.state();
186-
clusterState.blocks().globalBlockedRaiseException(ClusterBlockLevel.READ);
187-
188-
List<String> indices = new ArrayList<>();
189-
190-
for (MultiGetRequest.Item item : request.items) {
191-
try {
192-
String concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, item).getName();
193-
indices.add(concreteSingleIndex);
194-
} catch (Exception e) {
195-
// Multi get should not fail if one request is invalid
196-
}
197-
198-
}
199-
return ResolvedIndices.of(indices);
200-
}
201177
}

server/src/main/java/org/opensearch/action/search/TransportMultiSearchAction.java

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@
3434

3535
import org.opensearch.action.support.ActionFilters;
3636
import org.opensearch.action.support.HandledTransportAction;
37-
import org.opensearch.action.support.TransportIndicesResolvingAction;
3837
import org.opensearch.cluster.ClusterState;
3938
import org.opensearch.cluster.block.ClusterBlockLevel;
40-
import org.opensearch.cluster.metadata.ResolvedIndices;
4139
import org.opensearch.cluster.service.ClusterService;
4240
import org.opensearch.common.inject.Inject;
4341
import org.opensearch.common.settings.Settings;
@@ -53,9 +51,6 @@
5351
import org.opensearch.transport.TransportService;
5452
import org.opensearch.transport.client.node.NodeClient;
5553

56-
import java.util.ArrayList;
57-
import java.util.Collections;
58-
import java.util.List;
5954
import java.util.Queue;
6055
import java.util.concurrent.ConcurrentLinkedQueue;
6156
import java.util.concurrent.TimeUnit;
@@ -67,15 +62,13 @@
6762
*
6863
* @opensearch.internal
6964
*/
70-
public class TransportMultiSearchAction extends HandledTransportAction<MultiSearchRequest, MultiSearchResponse> implements
71-
TransportIndicesResolvingAction<MultiSearchRequest> {
65+
public class TransportMultiSearchAction extends HandledTransportAction<MultiSearchRequest, MultiSearchResponse> {
7266

7367
private final int allocatedProcessors;
7468
private final ThreadPool threadPool;
7569
private final ClusterService clusterService;
7670
private final LongSupplier relativeTimeProvider;
7771
private final NodeClient client;
78-
private final TransportSearchAction transportSearchAction;
7972

8073
@Inject
8174
public TransportMultiSearchAction(
@@ -84,16 +77,14 @@ public TransportMultiSearchAction(
8477
TransportService transportService,
8578
ClusterService clusterService,
8679
ActionFilters actionFilters,
87-
NodeClient client,
88-
TransportSearchAction transportSearchAction
80+
NodeClient client
8981
) {
9082
super(MultiSearchAction.NAME, transportService, actionFilters, (Writeable.Reader<MultiSearchRequest>) MultiSearchRequest::new);
9183
this.threadPool = threadPool;
9284
this.clusterService = clusterService;
9385
this.allocatedProcessors = OpenSearchExecutors.allocatedProcessors(settings);
9486
this.relativeTimeProvider = System::nanoTime;
9587
this.client = client;
96-
this.transportSearchAction = transportSearchAction;
9788
}
9889

9990
TransportMultiSearchAction(
@@ -103,16 +94,14 @@ public TransportMultiSearchAction(
10394
ClusterService clusterService,
10495
int allocatedProcessors,
10596
LongSupplier relativeTimeProvider,
106-
NodeClient client,
107-
TransportSearchAction transportSearchAction
97+
NodeClient client
10898
) {
10999
super(MultiSearchAction.NAME, transportService, actionFilters, (Writeable.Reader<MultiSearchRequest>) MultiSearchRequest::new);
110100
this.threadPool = threadPool;
111101
this.clusterService = clusterService;
112102
this.allocatedProcessors = allocatedProcessors;
113103
this.relativeTimeProvider = relativeTimeProvider;
114104
this.client = client;
115-
this.transportSearchAction = transportSearchAction;
116105
}
117106

118107
@Override
@@ -255,17 +244,6 @@ private boolean isCancelled(TaskId taskId) {
255244
return false;
256245
}
257246

258-
@Override
259-
public ResolvedIndices resolveIndices(MultiSearchRequest request) {
260-
List<SearchRequest> requests = request.requests();
261-
List<ResolvedIndices> resolvedIndicesList = new ArrayList<>();
262-
for(SearchRequest searchRequest : requests) {
263-
ResolvedIndices resolvedIndices = transportSearchAction.resolveIndices(searchRequest);
264-
resolvedIndicesList.add(resolvedIndices);
265-
}
266-
return resolvedIndicesList.stream().reduce(ResolvedIndices.of(Collections.emptySet()), ResolvedIndices::add);
267-
}
268-
269247
/**
270248
* Slots a search request
271249
*

server/src/main/java/org/opensearch/action/support/IndicesOptions.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -654,14 +654,6 @@ public static IndicesOptions lenientExpandHidden() {
654654
return LENIENT_EXPAND_OPEN_CLOSED_HIDDEN;
655655
}
656656

657-
public IndicesOptions mergeWith(IndicesOptions indicesOptions) {
658-
EnumSet<Option> newOptions = EnumSet.copyOf(this.options);
659-
EnumSet<WildcardStates> newExpandWildcards = EnumSet.copyOf(this.expandWildcards);
660-
newOptions.addAll(indicesOptions.options);
661-
newExpandWildcards.addAll(indicesOptions.expandWildcards);
662-
return new IndicesOptions(newOptions, newExpandWildcards);
663-
}
664-
665657
@Override
666658
public boolean equals(Object obj) {
667659
if (obj == null) {

server/src/main/java/org/opensearch/action/termvectors/TransportMultiTermVectorsAction.java

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@
3535
import org.opensearch.action.RoutingMissingException;
3636
import org.opensearch.action.support.ActionFilters;
3737
import org.opensearch.action.support.HandledTransportAction;
38-
import org.opensearch.action.support.TransportIndicesResolvingAction;
3938
import org.opensearch.cluster.ClusterState;
4039
import org.opensearch.cluster.block.ClusterBlockLevel;
4140
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
42-
import org.opensearch.cluster.metadata.ResolvedIndices;
4341
import org.opensearch.cluster.service.ClusterService;
4442
import org.opensearch.common.inject.Inject;
4543
import org.opensearch.common.util.concurrent.AtomicArray;
@@ -49,9 +47,7 @@
4947
import org.opensearch.tasks.Task;
5048
import org.opensearch.transport.TransportService;
5149

52-
import java.util.ArrayList;
5350
import java.util.HashMap;
54-
import java.util.List;
5551
import java.util.Map;
5652
import java.util.concurrent.atomic.AtomicInteger;
5753

@@ -60,8 +56,7 @@
6056
*
6157
* @opensearch.internal
6258
*/
63-
public class TransportMultiTermVectorsAction extends HandledTransportAction<MultiTermVectorsRequest, MultiTermVectorsResponse> implements
64-
TransportIndicesResolvingAction<MultiTermVectorsRequest> {
59+
public class TransportMultiTermVectorsAction extends HandledTransportAction<MultiTermVectorsRequest, MultiTermVectorsResponse> {
6560

6661
private final ClusterService clusterService;
6762
private final TransportShardMultiTermsVectorAction shardAction;
@@ -191,27 +186,4 @@ private void finishHim() {
191186
});
192187
}
193188
}
194-
195-
@Override
196-
public ResolvedIndices resolveIndices(MultiTermVectorsRequest request) {
197-
ClusterState clusterState = clusterService.state();
198-
clusterState.blocks().globalBlockedRaiseException(ClusterBlockLevel.READ);
199-
List<String> indices = new ArrayList<>();
200-
201-
202-
Map<ShardId, MultiTermVectorsShardRequest> shardRequests = new HashMap<>();
203-
for (int i = 0; i < request.requests.size(); i++) {
204-
TermVectorsRequest termVectorsRequest = request.requests.get(i);
205-
String routing = clusterState.metadata().resolveIndexRouting(termVectorsRequest.routing(), termVectorsRequest.index());
206-
if (!clusterState.metadata().hasConcreteIndex(termVectorsRequest.index())) {
207-
continue;
208-
}
209-
String concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, termVectorsRequest).getName();
210-
if (routing == null && clusterState.getMetadata().routingRequired(concreteSingleIndex)) {
211-
continue;
212-
}
213-
indices.add(concreteSingleIndex);
214-
}
215-
return ResolvedIndices.of(indices);
216-
}
217189
}

server/src/main/java/org/opensearch/cluster/metadata/ResolvedIndices.java

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ public static ResolvedIndices ofNonNull(String... indices) {
7171
return new ResolvedIndices(new Local(Collections.unmodifiableSet(indexSet), null, false), Collections.emptyMap());
7272
}
7373

74-
private static final Local LOCAL_ALL = new Local(Set.of(Metadata.ALL), null, true);
75-
private static final ResolvedIndices ALL = new ResolvedIndices(LOCAL_ALL, Collections.emptyMap());
76-
74+
private static final ResolvedIndices ALL = new ResolvedIndices(new Local(Set.of(Metadata.ALL), null, true), Collections.emptyMap());
7775

7876
private final Local local;
7977
private final Map<String, OriginalIndices> remote;
@@ -83,37 +81,6 @@ private ResolvedIndices(Local local, Map<String, OriginalIndices> remote) {
8381
this.remote = remote;
8482
}
8583

86-
private ResolvedIndices addLocal(Local local) {
87-
if(local == null || local().isEmpty()) {
88-
return this;
89-
}
90-
return new ResolvedIndices(this.local.addLocal(local), this.remote);
91-
}
92-
93-
private ResolvedIndices addRemote(Map<String, OriginalIndices> remote) {
94-
if(remote == null || remote.isEmpty()) {
95-
return this;
96-
}
97-
Map<String, OriginalIndices> newRemote = new HashMap<>(this.remote);
98-
for(Map.Entry<String, OriginalIndices> entry : remote.entrySet()) {
99-
if (newRemote.containsKey(entry.getKey())) {
100-
OriginalIndices originalIndices = newRemote.get(entry.getKey());
101-
OriginalIndices newOriginalIndices = originalIndices.mergeWith(entry.getValue());
102-
newRemote.put(entry.getKey(), newOriginalIndices);
103-
} else {
104-
newRemote.put(entry.getKey(), entry.getValue());
105-
}
106-
}
107-
return new ResolvedIndices(this.local, Collections.unmodifiableMap(newRemote));
108-
}
109-
110-
public ResolvedIndices add(ResolvedIndices other) {
111-
if (other == null || other.isEmpty()) {
112-
return this;
113-
}
114-
return this.addLocal(other.local).addRemote(other.remote);
115-
}
116-
11784
public Local local() {
11885
return this.local;
11986
}
@@ -182,19 +149,6 @@ public boolean contains(String index) {
182149
return this.names.contains(index);
183150
}
184151
}
185-
186-
public Local addLocal(Local local) {
187-
if(this.isAll) {
188-
return this;
189-
}
190-
if(local.isAll) {
191-
return local;
192-
}
193-
Set<String> namesSum = new HashSet<>(this.names);
194-
namesSum.addAll(local.names);
195-
OriginalIndices newOriginalIndices = this.originalIndices == null ? local.originalIndices : this.originalIndices.mergeWith(local.originalIndices);
196-
return new Local(Collections.unmodifiableSet(namesSum), newOriginalIndices, isAll);
197-
}
198152
}
199153

200154
}

0 commit comments

Comments
 (0)