Selaa lähdekoodia

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
Luca Cavanna 4 vuotta sitten
vanhempi
commit
4bf96e9cfa

+ 6 - 14
server/src/main/java/org/elasticsearch/action/admin/cluster/stats/FieldStats.java

@@ -8,7 +8,6 @@
 
 package org.elasticsearch.action.admin.cluster.stats;
 
-import org.elasticsearch.Version;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -34,24 +33,17 @@ public final class FieldStats extends IndexFeatureStats {
 
     FieldStats(StreamInput in) throws IOException {
         super(in);
-        if (in.getVersion().onOrAfter(Version.V_8_0_0)) {
-            scriptCount = in.readVInt();
-            scriptLangs = in.readSet(StreamInput::readString);
-            fieldScriptStats = new FieldScriptStats(in);
-        } else {
-            scriptLangs = new HashSet<>();
-            fieldScriptStats = new FieldScriptStats();
-        }
+        scriptCount = in.readVInt();
+        scriptLangs = in.readSet(StreamInput::readString);
+        fieldScriptStats = new FieldScriptStats(in);
     }
 
     @Override
     public void writeTo(StreamOutput out) throws IOException {
         super.writeTo(out);
-        if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
-            out.writeVInt(scriptCount);
-            out.writeCollection(scriptLangs, StreamOutput::writeString);
-            fieldScriptStats.writeTo(out);
-        }
+        out.writeVInt(scriptCount);
+        out.writeCollection(scriptLangs, StreamOutput::writeString);
+        fieldScriptStats.writeTo(out);
     }
 
     @Override

+ 6 - 22
server/src/test/java/org/elasticsearch/action/admin/cluster/stats/MappingStatsTests.java

@@ -23,7 +23,6 @@ import org.elasticsearch.test.VersionUtils;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Base64;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -310,31 +309,16 @@ public class MappingStatsTests extends AbstractWireSerializingTestCase<MappingSt
         }));
     }
 
-    public void testWriteToPre8_0() throws IOException {
-        FieldStats fieldStats = randomFieldStats("test");
-        MappingStats mappingStats = new MappingStats(Collections.singleton(fieldStats), Collections.emptyList());
-        Version version = VersionUtils.randomPreviousCompatibleVersion(random(), Version.V_8_0_0);
+    public void testWriteTo() throws IOException {
+        MappingStats instance = createTestInstance();
         BytesStreamOutput out = new BytesStreamOutput();
+        Version version = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT);
         out.setVersion(version);
-        mappingStats.writeTo(out);
+        instance.writeTo(out);
         StreamInput in = StreamInput.wrap(out.bytes().toBytesRef().bytes);
         in.setVersion(version);
         MappingStats deserialized = new MappingStats(in);
-        assertEquals("{\"mappings\":{\"field_types\":[" +
-            "{\"name\":\"test\",\"count\":" + fieldStats.count+ ",\"index_count\":" + fieldStats.indexCount +
-                ",\"script_count\":0}],\"runtime_field_types\":[]}}",
-            Strings.toString(deserialized));
-    }
-
-    public void testReadFromPre8_0() throws IOException {
-        String base64EncodedFromPre8_0 = "AQR0ZXN0qebzzQGSg/HlBgAAAAAAAAAA";
-        byte[] bytes = Base64.getDecoder().decode(base64EncodedFromPre8_0);
-        Version version = VersionUtils.randomPreviousCompatibleVersion(random(), Version.V_8_0_0);
-        StreamInput in = StreamInput.wrap(bytes);
-        in.setVersion(version);
-        MappingStats deserialized = new MappingStats(in);
-        assertEquals("{\"mappings\":{\"field_types\":" +
-            "[{\"name\":\"test\",\"count\":431813417,\"index_count\":1824276882,\"script_count\":0}],\"runtime_field_types\":[]}}",
-            Strings.toString(deserialized));
+        assertEquals(instance.getFieldTypeStats(), deserialized.getFieldTypeStats());
+        assertEquals(instance.getRuntimeFieldStats(), deserialized.getRuntimeFieldStats());
     }
 }