Skip to content

Commit 4bf96e9

Browse files
authored
Remove FieldStats version checks (#71574)
We recently added script stats to the existing field type stats. That change is now backported hence master does not need to support the scenario where such info is not available, only the 7.x branch does to account for mixed cluster scenarios. Relates to #71219
1 parent a478b5f commit 4bf96e9

File tree

2 files changed

+12
-36
lines changed

2 files changed

+12
-36
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/stats/FieldStats.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
package org.elasticsearch.action.admin.cluster.stats;
1010

11-
import org.elasticsearch.Version;
1211
import org.elasticsearch.common.io.stream.StreamInput;
1312
import org.elasticsearch.common.io.stream.StreamOutput;
1413
import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -34,24 +33,17 @@ public final class FieldStats extends IndexFeatureStats {
3433

3534
FieldStats(StreamInput in) throws IOException {
3635
super(in);
37-
if (in.getVersion().onOrAfter(Version.V_8_0_0)) {
38-
scriptCount = in.readVInt();
39-
scriptLangs = in.readSet(StreamInput::readString);
40-
fieldScriptStats = new FieldScriptStats(in);
41-
} else {
42-
scriptLangs = new HashSet<>();
43-
fieldScriptStats = new FieldScriptStats();
44-
}
36+
scriptCount = in.readVInt();
37+
scriptLangs = in.readSet(StreamInput::readString);
38+
fieldScriptStats = new FieldScriptStats(in);
4539
}
4640

4741
@Override
4842
public void writeTo(StreamOutput out) throws IOException {
4943
super.writeTo(out);
50-
if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
51-
out.writeVInt(scriptCount);
52-
out.writeCollection(scriptLangs, StreamOutput::writeString);
53-
fieldScriptStats.writeTo(out);
54-
}
44+
out.writeVInt(scriptCount);
45+
out.writeCollection(scriptLangs, StreamOutput::writeString);
46+
fieldScriptStats.writeTo(out);
5547
}
5648

5749
@Override

server/src/test/java/org/elasticsearch/action/admin/cluster/stats/MappingStatsTests.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import java.io.IOException;
2525
import java.util.ArrayList;
26-
import java.util.Base64;
2726
import java.util.Collection;
2827
import java.util.Collections;
2928
import java.util.List;
@@ -310,31 +309,16 @@ public void testChecksForCancellation() {
310309
}));
311310
}
312311

313-
public void testWriteToPre8_0() throws IOException {
314-
FieldStats fieldStats = randomFieldStats("test");
315-
MappingStats mappingStats = new MappingStats(Collections.singleton(fieldStats), Collections.emptyList());
316-
Version version = VersionUtils.randomPreviousCompatibleVersion(random(), Version.V_8_0_0);
312+
public void testWriteTo() throws IOException {
313+
MappingStats instance = createTestInstance();
317314
BytesStreamOutput out = new BytesStreamOutput();
315+
Version version = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT);
318316
out.setVersion(version);
319-
mappingStats.writeTo(out);
317+
instance.writeTo(out);
320318
StreamInput in = StreamInput.wrap(out.bytes().toBytesRef().bytes);
321319
in.setVersion(version);
322320
MappingStats deserialized = new MappingStats(in);
323-
assertEquals("{\"mappings\":{\"field_types\":[" +
324-
"{\"name\":\"test\",\"count\":" + fieldStats.count+ ",\"index_count\":" + fieldStats.indexCount +
325-
",\"script_count\":0}],\"runtime_field_types\":[]}}",
326-
Strings.toString(deserialized));
327-
}
328-
329-
public void testReadFromPre8_0() throws IOException {
330-
String base64EncodedFromPre8_0 = "AQR0ZXN0qebzzQGSg/HlBgAAAAAAAAAA";
331-
byte[] bytes = Base64.getDecoder().decode(base64EncodedFromPre8_0);
332-
Version version = VersionUtils.randomPreviousCompatibleVersion(random(), Version.V_8_0_0);
333-
StreamInput in = StreamInput.wrap(bytes);
334-
in.setVersion(version);
335-
MappingStats deserialized = new MappingStats(in);
336-
assertEquals("{\"mappings\":{\"field_types\":" +
337-
"[{\"name\":\"test\",\"count\":431813417,\"index_count\":1824276882,\"script_count\":0}],\"runtime_field_types\":[]}}",
338-
Strings.toString(deserialized));
321+
assertEquals(instance.getFieldTypeStats(), deserialized.getFieldTypeStats());
322+
assertEquals(instance.getRuntimeFieldStats(), deserialized.getRuntimeFieldStats());
339323
}
340324
}

0 commit comments

Comments
 (0)