Skip to content

Commit fbfc707

Browse files
authored
Support serialization of aggregate metric double literal (#126352)
To backport the newly introduced AggregateMetricDoubleLiteral to 8.x, we need to override the supportsVersion method instead of getMinimalSupportedVersion.
1 parent a6aaccd commit fbfc707

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import java.util.function.IntFunction;
5151

5252
import static java.util.Map.entry;
53-
import static org.elasticsearch.TransportVersions.V_8_11_X;
5453

5554
/**
5655
* A stream from another node to this node. Technically, it can also be streamed from a byte array but that is mostly for testing.
@@ -813,13 +812,10 @@ public final void writeOptionalInstant(@Nullable Instant instant) throws IOExcep
813812
entry(GenericNamedWriteable.class, (o, v) -> {
814813
// Note that we do not rely on the checks in VersionCheckingStreamOutput because that only applies to CCS
815814
final var genericNamedWriteable = (GenericNamedWriteable) v;
816-
TransportVersion minSupportedVersion = genericNamedWriteable.getMinimalSupportedVersion();
817-
assert minSupportedVersion.onOrAfter(V_8_11_X) : "[GenericNamedWriteable] requires [" + V_8_11_X + "]";
818-
if (o.getTransportVersion().before(minSupportedVersion)) {
815+
if (genericNamedWriteable.supportsVersion(o.getTransportVersion()) == false) {
819816
final var message = Strings.format(
820-
"[%s] requires minimal transport version [%s] and cannot be sent using transport version [%s]",
817+
"[%s] doesn't support serialization with transport version [%s]",
821818
genericNamedWriteable.getWriteableName(),
822-
minSupportedVersion,
823819
o.getTransportVersion()
824820
);
825821
assert false : message;

server/src/test/java/org/elasticsearch/search/geo/GeoBoundsGenericWriteableTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void testSerializationFailsWithOlderVersion() {
8585
output.setTransportVersion(older);
8686
assertThat(
8787
expectThrows(Throwable.class, () -> output.writeGenericValue(testInstance)).getMessage(),
88-
containsString("[GeoBoundingBox] requires minimal transport version")
88+
containsString("[GeoBoundingBox] doesn't support serialization with transport version")
8989
);
9090
}
9191
}

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/AggregateMetricDoubleBlockBuilder.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,14 @@ public void writeTo(StreamOutput out) throws IOException {
200200
}
201201

202202
@Override
203-
public TransportVersion getMinimalSupportedVersion() {
204-
return TransportVersions.ESQL_AGGREGATE_METRIC_DOUBLE_LITERAL;
203+
public boolean supportsVersion(TransportVersion version) {
204+
return version.onOrAfter(TransportVersions.ESQL_AGGREGATE_METRIC_DOUBLE_LITERAL);
205205
}
206206

207+
@Override
208+
public TransportVersion getMinimalSupportedVersion() {
209+
assert false : "must not be called when overriding supportsVersion";
210+
throw new UnsupportedOperationException("must not be called when overriding supportsVersion");
211+
}
207212
}
208213
}

x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/fielddata/ShapeValuesGenericWriteableTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void testSerializationFailsWithOlderVersion() {
7373
output.setTransportVersion(older);
7474
assertThat(
7575
expectThrows(Throwable.class, () -> output.writeGenericValue(testInstance)).getMessage(),
76-
containsString("[" + shapeValueName() + "] requires minimal transport version")
76+
containsString("[" + shapeValueName() + "] doesn't support serialization with transport version")
7777
);
7878
}
7979
}

0 commit comments

Comments
 (0)