-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
QueryFetchSearchResult as a proto message and node-to-node communication with protobuf #11910
Changes from all commits
82db23c
fe1fd90
931e1d9
7bbf23a
044b07f
b198451
4f569c0
891a085
e00c1a8
6274355
540846e
e7024db
3d49a4b
a2cf25a
0cf2fcb
f7a9d47
58a8af8
1ae993b
bd83a3f
fb24d35
67a3262
40df9ac
d6431ed
69831a8
0cb9018
4b801ea
5ae83ab
243f039
64b79dc
ff965e6
de88e46
b7ee789
117572c
46eeaf6
ed00f89
324c58f
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.core.common.io.stream; | ||
|
||
import org.opensearch.common.annotation.ExperimentalApi; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
/** | ||
* Implementers can be written to a {@linkplain OutputStream} and read from a byte array. This allows them to be "thrown | ||
* across the wire" using OpenSearch's internal protocol with protobuf bytes. | ||
* | ||
* @opensearch.api | ||
*/ | ||
@ExperimentalApi | ||
public interface BytesWriteable { | ||
|
||
/** | ||
* Write this into the {@linkplain OutputStream}. | ||
*/ | ||
void writeTo(OutputStream out) throws IOException; | ||
|
||
/** | ||
* Reference to a method that can write some object to a {@link OutputStream}. | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
@FunctionalInterface | ||
@ExperimentalApi | ||
interface Writer<V> { | ||
|
||
/** | ||
* Write {@code V}-type {@code value} to the {@code out}put stream. | ||
* | ||
* @param out Output to write the {@code value} too | ||
* @param value The value to add | ||
*/ | ||
void write(final OutputStream out, V value) throws IOException; | ||
} | ||
|
||
/** | ||
* Reference to a method that can read some object from a byte array. | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
@FunctionalInterface | ||
@ExperimentalApi | ||
interface Reader<V> { | ||
|
||
/** | ||
* Read {@code V}-type value from a byte array. | ||
* | ||
* @param in byte array to read the value from | ||
*/ | ||
V read(final InputStream in) throws IOException; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action; | ||
|
||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.core.common.io.stream.BytesWriteable; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.transport.TransportResponse; | ||
import org.opensearch.threadpool.ThreadPool; | ||
import org.opensearch.transport.TransportException; | ||
import org.opensearch.transport.TransportResponseHandler; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Objects; | ||
|
||
/** | ||
* A simple base class for action response listeners, defaulting to using the SAME executor (as its | ||
* very common on response handlers). | ||
* | ||
* @opensearch.api | ||
*/ | ||
public class ProtobufActionListenerResponseHandler<Response extends TransportResponse> implements TransportResponseHandler<Response> { | ||
VachaShah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private final ActionListener<? super Response> listener; | ||
private final BytesWriteable.Reader<Response> reader; | ||
private final String executor; | ||
|
||
public ProtobufActionListenerResponseHandler( | ||
ActionListener<? super Response> listener, | ||
BytesWriteable.Reader<Response> reader, | ||
String executor | ||
) { | ||
this.listener = Objects.requireNonNull(listener); | ||
this.reader = Objects.requireNonNull(reader); | ||
this.executor = Objects.requireNonNull(executor); | ||
} | ||
Check warning on line 43 in server/src/main/java/org/opensearch/action/ProtobufActionListenerResponseHandler.java Codecov / codecov/patchserver/src/main/java/org/opensearch/action/ProtobufActionListenerResponseHandler.java#L39-L43
|
||
|
||
public ProtobufActionListenerResponseHandler(ActionListener<? super Response> listener, BytesWriteable.Reader<Response> reader) { | ||
this(listener, reader, ThreadPool.Names.SAME); | ||
} | ||
Check warning on line 47 in server/src/main/java/org/opensearch/action/ProtobufActionListenerResponseHandler.java Codecov / codecov/patchserver/src/main/java/org/opensearch/action/ProtobufActionListenerResponseHandler.java#L46-L47
|
||
|
||
@Override | ||
public void handleResponse(Response response) { | ||
listener.onResponse(response); | ||
} | ||
Check warning on line 52 in server/src/main/java/org/opensearch/action/ProtobufActionListenerResponseHandler.java Codecov / codecov/patchserver/src/main/java/org/opensearch/action/ProtobufActionListenerResponseHandler.java#L51-L52
|
||
|
||
@Override | ||
public void handleException(TransportException e) { | ||
listener.onFailure(e); | ||
} | ||
Check warning on line 57 in server/src/main/java/org/opensearch/action/ProtobufActionListenerResponseHandler.java Codecov / codecov/patchserver/src/main/java/org/opensearch/action/ProtobufActionListenerResponseHandler.java#L56-L57
|
||
|
||
@Override | ||
public String executor() { | ||
return executor; | ||
Check warning on line 61 in server/src/main/java/org/opensearch/action/ProtobufActionListenerResponseHandler.java Codecov / codecov/patchserver/src/main/java/org/opensearch/action/ProtobufActionListenerResponseHandler.java#L61
|
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return super.toString() + "/" + listener; | ||
Check warning on line 66 in server/src/main/java/org/opensearch/action/ProtobufActionListenerResponseHandler.java Codecov / codecov/patchserver/src/main/java/org/opensearch/action/ProtobufActionListenerResponseHandler.java#L66
|
||
} | ||
|
||
@Override | ||
public Response read(StreamInput in) throws IOException { | ||
throw new UnsupportedOperationException("Unimplemented method 'read'"); | ||
Check warning on line 71 in server/src/main/java/org/opensearch/action/ProtobufActionListenerResponseHandler.java Codecov / codecov/patchserver/src/main/java/org/opensearch/action/ProtobufActionListenerResponseHandler.java#L71
|
||
} | ||
|
||
@Override | ||
public Response read(InputStream in) throws IOException { | ||
return reader.read(in); | ||
Check warning on line 76 in server/src/main/java/org/opensearch/action/ProtobufActionListenerResponseHandler.java Codecov / codecov/patchserver/src/main/java/org/opensearch/action/ProtobufActionListenerResponseHandler.java#L76
|
||
} | ||
} |
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.
Could we generalize of the source (stream) here instead of introducing a parallel hierarchy?
In this case we could make the current
Writeable
and new one the part of the same hierarchy?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.
I had tried generalizing the hierarchy, the problem with that is:
TransportMessage
cannot implement bothWriteable
andBytesWriteable
as it complains that it is implementing the same thing twice from the same hierarchy. We want the message to implement both since for now both ways exist side by side. I tried multiple ways to do it but ended up with the same fix of keeping it separate for now.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.
Hm ... we should be able to implement both: the classes have functions with different input arguments, in any case - we don't have to implement both on the same class, the intermediary layers could do that.
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.
Ah I think I tried a little differently than mentioned here, let me add this change to a newer commit as well.