Skip to content

Commit

Permalink
Replace Streamable w/ Writable for MultiSearchRequest (#44057)
Browse files Browse the repository at this point in the history
This commit replaces usages of Streamable with Writeable for the
MultiSearchRequest class.

I ran into this when developing a custom action that reuses
MultiSearchRequest in the enrich branch.

Relates to #34389
  • Loading branch information
martijnvg committed Jul 10, 2019
1 parent cb62d4a commit 913b6a6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,13 @@
package org.elasticsearch.action.search;

import org.elasticsearch.action.ActionType;
import org.elasticsearch.common.io.stream.Writeable;

public class MultiSearchAction extends ActionType<MultiSearchResponse> {

public static final MultiSearchAction INSTANCE = new MultiSearchAction();
public static final String NAME = "indices:data/read/msearch";

private MultiSearchAction() {
super(NAME);
}

@Override
public Writeable.Reader<MultiSearchResponse> getResponseReader() {
return MultiSearchResponse::new;
super(NAME, MultiSearchResponse::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ public class MultiSearchRequest extends ActionRequest implements CompositeIndice
public static final int MAX_CONCURRENT_SEARCH_REQUESTS_DEFAULT = 0;

private int maxConcurrentSearchRequests = 0;
private List<SearchRequest> requests = new ArrayList<>();
private final List<SearchRequest> requests = new ArrayList<>();

private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpenAndForbidClosedIgnoreThrottled();

public MultiSearchRequest() {}

/**
* Add a search request to execute. Note, the order is important, the search response will be returned in the
* same order as the search requests.
Expand Down Expand Up @@ -130,9 +132,9 @@ public MultiSearchRequest indicesOptions(IndicesOptions indicesOptions) {
return this;
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);

public MultiSearchRequest(StreamInput in) throws IOException {
super(in);
maxConcurrentSearchRequests = in.readVInt();
int size = in.readVInt();
for (int i = 0; i < size; i++) {
Expand All @@ -141,6 +143,11 @@ public void readFrom(StreamInput in) throws IOException {
}
}

@Override
public void readFrom(StreamInput in) throws IOException {
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.AtomicArray;
import org.elasticsearch.common.util.concurrent.EsExecutors;
Expand All @@ -51,7 +52,7 @@ public class TransportMultiSearchAction extends HandledTransportAction<MultiSear
@Inject
public TransportMultiSearchAction(Settings settings, ThreadPool threadPool, TransportService transportService,
ClusterService clusterService, ActionFilters actionFilters, NodeClient client) {
super(MultiSearchAction.NAME, transportService, actionFilters, MultiSearchRequest::new);
super(MultiSearchAction.NAME, transportService, actionFilters, (Writeable.Reader<MultiSearchRequest>) MultiSearchRequest::new);
this.threadPool = threadPool;
this.clusterService = clusterService;
this.availableProcessors = EsExecutors.numberOfProcessors(settings);
Expand All @@ -62,7 +63,7 @@ public TransportMultiSearchAction(Settings settings, ThreadPool threadPool, Tran
TransportMultiSearchAction(ThreadPool threadPool, ActionFilters actionFilters, TransportService transportService,
ClusterService clusterService, int availableProcessors,
LongSupplier relativeTimeProvider, NodeClient client) {
super(MultiSearchAction.NAME, transportService, actionFilters, MultiSearchRequest::new);
super(MultiSearchAction.NAME, transportService, actionFilters, (Writeable.Reader<MultiSearchRequest>) MultiSearchRequest::new);
this.threadPool = threadPool;
this.clusterService = clusterService;
this.availableProcessors = availableProcessors;
Expand Down

0 comments on commit 913b6a6

Please sign in to comment.