فهرست منبع

Remove notion of compatibility role (#64384)

This notion was necessary so that old masters that do not understand the
data_* roles could still ascertain whether nor not a node could hold
data. We replaced this by serializing canContainData as part of the
serialized role representation. This means that now we can rely on the
role representation to determine whether or not a node can contain
data. Since this change was pushed to 7.10, and nodes based on 8.0 are
not expected to have compatibility with nodes < 7.10, we can remove
compatibility role from 8.0.
Jason Tedor 5 سال پیش
والد
کامیت
5cafcbfe8d

+ 3 - 4
server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java

@@ -291,11 +291,10 @@ public class DiscoveryNode implements Writeable, ToXContentFragment {
         out.writeMap(attributes, StreamOutput::writeString, StreamOutput::writeString);
         out.writeVInt(roles.size());
         for (final DiscoveryNodeRole role : roles) {
-            final DiscoveryNodeRole compatibleRole = role.getCompatibilityRole(out.getVersion());
-            out.writeString(compatibleRole.roleName());
-            out.writeString(compatibleRole.roleNameAbbreviation());
+            out.writeString(role.roleName());
+            out.writeString(role.roleNameAbbreviation());
             if (out.getVersion().onOrAfter(Version.V_7_10_0)) {
-                out.writeBoolean(compatibleRole.canContainData());
+                out.writeBoolean(role.canContainData());
             }
         }
         Version.writeVersion(version, out);

+ 0 - 11
server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java

@@ -19,7 +19,6 @@
 
 package org.elasticsearch.cluster.node;
 
-import org.elasticsearch.Version;
 import org.elasticsearch.common.settings.Setting;
 import org.elasticsearch.common.settings.Setting.Property;
 import org.elasticsearch.common.settings.Settings;
@@ -96,16 +95,6 @@ public abstract class DiscoveryNodeRole implements Comparable<DiscoveryNodeRole>
 
     public abstract Setting<Boolean> legacySetting();
 
-    /**
-     * When serializing a {@link DiscoveryNodeRole}, the role may not be available to nodes of
-     * previous versions, where the role had not yet been added. This method allows overriding
-     * the role that should be serialized when communicating to versions prior to the introduction
-     * of the discovery node role.
-     */
-    public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) {
-        return this;
-    }
-
     @Override
     public final boolean equals(Object o) {
         if (this == o) return true;

+ 15 - 15
server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java

@@ -31,7 +31,6 @@ import java.net.InetAddress;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
-import java.util.stream.Collectors;
 
 import static java.util.Collections.emptyMap;
 import static java.util.Collections.emptySet;
@@ -40,6 +39,7 @@ import static org.elasticsearch.test.NodeRoles.remoteClusterClientNode;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.greaterThanOrEqualTo;
 import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.not;
 
 public class DiscoveryNodeTests extends ESTestCase {
@@ -101,14 +101,6 @@ public class DiscoveryNodeTests extends ESTestCase {
                 return null;
             }
 
-            @Override
-            public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) {
-                if (nodeVersion.equals(Version.CURRENT)) {
-                    return this;
-                } else {
-                    return DiscoveryNodeRole.DATA_ROLE;
-                }
-            }
         };
 
         DiscoveryNode node = new DiscoveryNode("name1", "id1", transportAddress, emptyMap(),
@@ -122,20 +114,28 @@ public class DiscoveryNodeTests extends ESTestCase {
             StreamInput in = StreamInput.wrap(streamOutput.bytes().toBytesRef().bytes);
             in.setVersion(Version.CURRENT);
             DiscoveryNode serialized = new DiscoveryNode(in);
-            assertThat(serialized.getRoles().stream().map(DiscoveryNodeRole::roleName).collect(Collectors.joining()),
-                equalTo("custom_role"));
+            final Set<DiscoveryNodeRole> roles = serialized.getRoles();
+            assertThat(roles, hasSize(1));
+            @SuppressWarnings("OptionalGetWithoutIsPresent") final DiscoveryNodeRole role = roles.stream().findFirst().get();
+            assertThat(role.roleName(), equalTo("custom_role"));
+            assertThat(role.roleNameAbbreviation(), equalTo("z"));
+            assertTrue(role.canContainData());
         }
 
         {
             BytesStreamOutput streamOutput = new BytesStreamOutput();
-            streamOutput.setVersion(Version.V_7_10_0);
+            streamOutput.setVersion(Version.V_7_11_0);
             node.writeTo(streamOutput);
 
             StreamInput in = StreamInput.wrap(streamOutput.bytes().toBytesRef().bytes);
-            in.setVersion(Version.V_7_10_0);
+            in.setVersion(Version.V_7_11_0);
             DiscoveryNode serialized = new DiscoveryNode(in);
-            assertThat(serialized.getRoles().stream().map(DiscoveryNodeRole::roleName).collect(Collectors.joining()),
-                equalTo("data"));
+            final Set<DiscoveryNodeRole> roles = serialized.getRoles();
+            assertThat(roles, hasSize(1));
+            @SuppressWarnings("OptionalGetWithoutIsPresent") final DiscoveryNodeRole role = roles.stream().findFirst().get();
+            assertThat(role.roleName(), equalTo("custom_role"));
+            assertThat(role.roleNameAbbreviation(), equalTo("z"));
+            assertTrue(role.canContainData());
         }
 
     }

+ 0 - 17
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTier.java

@@ -8,7 +8,6 @@ package org.elasticsearch.xpack.core;
 
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
-import org.elasticsearch.Version;
 import org.elasticsearch.cluster.metadata.IndexMetadata;
 import org.elasticsearch.cluster.node.DiscoveryNode;
 import org.elasticsearch.cluster.node.DiscoveryNodeRole;
@@ -85,10 +84,6 @@ public class DataTier {
             );
         }
 
-        @Override
-        public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) {
-            return nodeVersion.before(Version.V_7_10_0) ? DiscoveryNodeRole.DATA_ROLE : this;
-        }
     };
 
     public static DiscoveryNodeRole DATA_HOT_NODE_ROLE = new DiscoveryNodeRole("data_hot", "h", true) {
@@ -110,10 +105,6 @@ public class DataTier {
             );
         }
 
-        @Override
-        public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) {
-            return nodeVersion.before(Version.V_7_10_0) ? DiscoveryNodeRole.DATA_ROLE : this;
-        }
     };
 
     public static DiscoveryNodeRole DATA_WARM_NODE_ROLE = new DiscoveryNodeRole("data_warm", "w", true) {
@@ -135,10 +126,6 @@ public class DataTier {
             );
         }
 
-        @Override
-        public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) {
-            return nodeVersion.before(Version.V_7_10_0) ? DiscoveryNodeRole.DATA_ROLE : this;
-        }
     };
 
     public static DiscoveryNodeRole DATA_COLD_NODE_ROLE = new DiscoveryNodeRole("data_cold", "c", true) {
@@ -160,10 +147,6 @@ public class DataTier {
             );
         }
 
-        @Override
-        public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) {
-            return nodeVersion.before(Version.V_7_10_0) ? DiscoveryNodeRole.DATA_ROLE : this;
-        }
     };
 
     public static boolean isContentNode(DiscoveryNode discoveryNode) {