Skip to content

Commit

Permalink
Skipping serialization of node attributes in Leader and follower checks
Browse files Browse the repository at this point in the history
Signed-off-by: RS146BIJAY <[email protected]>
  • Loading branch information
RS146BIJAY committed Aug 22, 2024
1 parent b830d68 commit 56d65c4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,14 @@ public DiscoveryNode(StreamInput in) throws IOException {
this.address = new TransportAddress(in);
int size = in.readVInt();
this.attributes = new HashMap<>(size);
for (int i = 0; i < size; i++) {
this.attributes.put(in.readString(), in.readString());
if (in.getVersion().onOrAfter(Version.V_3_0_0) && !in.readBoolean()) {

} else {
for (int i = 0; i < size; i++) {
this.attributes.put(in.readString(), in.readString());
}
}

int rolesSize = in.readVInt();
final Set<DiscoveryNodeRole> roles = new HashSet<>(rolesSize);
for (int i = 0; i < rolesSize; i++) {
Expand Down Expand Up @@ -358,17 +363,38 @@ public DiscoveryNode(StreamInput in) throws IOException {

@Override
public void writeTo(StreamOutput out) throws IOException {
writeToUtil(out, true);
}

public void writeToWithoutAttribute(StreamOutput out) throws IOException {
writeToUtil(out, false);
}

private void writeToUtil(StreamOutput out, boolean includeAttributes) throws IOException {
out.writeString(nodeName);
out.writeString(nodeId);
out.writeString(ephemeralId);
out.writeString(hostName);
out.writeString(hostAddress);
address.writeTo(out);
out.writeVInt(attributes.size());
for (Map.Entry<String, String> entry : attributes.entrySet()) {
out.writeString(entry.getKey());
out.writeString(entry.getValue());
if (includeAttributes) {
out.writeVInt(attributes.size());
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
out.writeBoolean(true);
}

for (Map.Entry<String, String> entry : attributes.entrySet()) {
out.writeString(entry.getKey());
out.writeString(entry.getValue());
}
} else {
// Set the size of attribute as 0 so that no attribute is read from stream on receiver node.
out.writeVInt(0);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
out.writeBoolean(false);
}
}

out.writeVInt(roles.size());
for (final DiscoveryNodeRole role : roles) {
final DiscoveryNodeRole compatibleRole = role.getCompatibilityRole(out.getVersion());
Expand Down

0 comments on commit 56d65c4

Please sign in to comment.