Skip to content

Commit

Permalink
Use min version when storing async search response (#74642)
Browse files Browse the repository at this point in the history
If a new node in a mixed cluster creates an async search response and
leaves the cluster; then an older node can't decode that search
response. We should use the version of the oldest node in the cluster
instead when storing an async response.
  • Loading branch information
dnhatn committed Jun 28, 2021
1 parent 3a5e0f2 commit 022fd00
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ static XContentBuilder mappings() throws IOException {
private final NamedWriteableRegistry registry;
private final Writeable.Reader<R> reader;


public AsyncTaskIndexService(String index,
ClusterService clusterService,
ThreadContext threadContext,
Expand Down Expand Up @@ -472,7 +471,9 @@ boolean ensureAuthenticatedUserIsSame(Map<String, String> originHeaders, Authent
* Encode the provided response in a binary form using base64 encoding.
*/
String encodeResponse(R response) throws IOException {
final Version minNodeVersion = clusterService.state().nodes().getMinNodeVersion();
try (BytesStreamOutput out = new BytesStreamOutput()) {
out.setVersion(minNodeVersion);
Version.writeVersion(Version.CURRENT, out);
response.writeTo(out);
return Base64.getEncoder().encodeToString(BytesReference.toBytes(out.bytes()));
Expand All @@ -485,7 +486,9 @@ String encodeResponse(R response) throws IOException {
R decodeResponse(String value) throws IOException {
try (ByteBufferStreamInput buf = new ByteBufferStreamInput(ByteBuffer.wrap(Base64.getDecoder().decode(value)))) {
try (StreamInput in = new NamedWriteableAwareStreamInput(buf, registry)) {
in.setVersion(Version.readVersion(in));
final Version version = Version.readVersion(in);
assert version.onOrBefore(Version.CURRENT) : version + " >= " + Version.CURRENT;
in.setVersion(version);
return reader.read(in);
}
}
Expand Down

0 comments on commit 022fd00

Please sign in to comment.