From c31a21c3d892fa3aa4c7c6e78a7d70a8c083df4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Mon, 13 Jan 2020 10:10:15 +0100 Subject: [PATCH] Fix time zone issue in Rounding serialization (#50845) When deserializing time zones in the Rounding classes we used to include a tiny normalization step via `DateUtils.of(in.readString())` that was lost in #50609. Its at least necessary for some tests, e.g. the cause of #50827 is that when sending the default time zone ZoneOffset.UTC on a stream pre 7.0 we convert it to a "UTC" string id via `DateUtils.zoneIdToDateTimeZone`. This gets then read back as a UTC ZoneRegion, which should behave the same but fails the equality tests in our serialization tests. Reverting to the previous behaviour with an additional normalization step on 7.x. Co-authored-by: Nik Everett Closes #50827 --- server/src/main/java/org/elasticsearch/common/Rounding.java | 6 ++++-- .../search/aggregations/InternalAggregationsTests.java | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/common/Rounding.java b/server/src/main/java/org/elasticsearch/common/Rounding.java index 451517481b75c..1ae53a8919ad4 100644 --- a/server/src/main/java/org/elasticsearch/common/Rounding.java +++ b/server/src/main/java/org/elasticsearch/common/Rounding.java @@ -252,7 +252,8 @@ static class TimeUnitRounding extends Rounding { } TimeUnitRounding(StreamInput in) throws IOException { - this(DateTimeUnit.resolve(in.readByte()), in.readZoneId()); + this(DateTimeUnit.resolve(in.readByte()), + in.getVersion().onOrAfter(Version.V_7_0_0) ? in.readZoneId() : DateUtils.of(in.readString())); } @Override @@ -467,7 +468,8 @@ static class TimeIntervalRounding extends Rounding { } TimeIntervalRounding(StreamInput in) throws IOException { - this(in.readVLong(), in.readZoneId()); + this(in.readVLong(), + in.getVersion().onOrAfter(Version.V_7_0_0) ? in.readZoneId() : DateUtils.of(in.readString())); } @Override diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationsTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationsTests.java index 9dc214f3d1993..c19727041ddd9 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationsTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationsTests.java @@ -120,7 +120,6 @@ public static InternalAggregations createTestInstance() throws Exception { return new InternalAggregations(aggsList, topLevelPipelineAggs); } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/50827") public void testSerialization() throws Exception { InternalAggregations aggregations = createTestInstance(); writeToAndReadFrom(aggregations, 0);