diff --git a/server/src/main/java/org/opensearch/cluster/coordination/FollowersChecker.java b/server/src/main/java/org/opensearch/cluster/coordination/FollowersChecker.java index 2ec0dabd91786..2cee9b1c2ee33 100644 --- a/server/src/main/java/org/opensearch/cluster/coordination/FollowersChecker.java +++ b/server/src/main/java/org/opensearch/cluster/coordination/FollowersChecker.java @@ -35,6 +35,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; +import org.opensearch.Version; import org.opensearch.cluster.ClusterManagerMetrics; import org.opensearch.cluster.coordination.Coordinator.Mode; import org.opensearch.cluster.node.DiscoveryNode; @@ -503,7 +504,11 @@ public FollowerCheckRequest(final StreamInput in) throws IOException { public void writeTo(final StreamOutput out) throws IOException { super.writeTo(out); out.writeLong(term); - sender.writeTo(out); + if (out.getVersion().onOrAfter(Version.V_3_0_0)) { + sender.writeToWithoutAttribute(out); + } else { + sender.writeTo(out); + } } @Override diff --git a/server/src/main/java/org/opensearch/cluster/node/DiscoveryNode.java b/server/src/main/java/org/opensearch/cluster/node/DiscoveryNode.java index 653f81830ed17..63a003e15ce92 100644 --- a/server/src/main/java/org/opensearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/opensearch/cluster/node/DiscoveryNode.java @@ -70,7 +70,7 @@ * * @opensearch.api */ -@PublicApi(since = "1.0.0") +@PublicApi(since = "2.17.0") public class DiscoveryNode implements Writeable, ToXContentFragment { static final String COORDINATING_ONLY = "coordinating_only"; @@ -369,6 +369,26 @@ public void writeTo(StreamOutput out) throws IOException { out.writeString(entry.getKey()); out.writeString(entry.getValue()); } + + 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.writeBoolean(compatibleRole.canContainData()); + } + + out.writeVersion(version); + } + + public void writeToWithoutAttribute(StreamOutput out) throws IOException { + out.writeString(nodeName); + out.writeString(nodeId); + out.writeString(ephemeralId); + out.writeString(hostName); + out.writeString(hostAddress); + address.writeTo(out); + out.writeVInt(0); out.writeVInt(roles.size()); for (final DiscoveryNodeRole role : roles) { final DiscoveryNodeRole compatibleRole = role.getCompatibilityRole(out.getVersion()); @@ -376,6 +396,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeString(compatibleRole.roleNameAbbreviation()); out.writeBoolean(compatibleRole.canContainData()); } + out.writeVersion(version); } @@ -572,7 +593,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.field(entry.getKey(), entry.getValue()); } builder.endObject(); - builder.endObject(); return builder; }