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 573f78c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public FollowerCheckRequest(final StreamInput in) throws IOException {
public void writeTo(final StreamOutput out) throws IOException {
super.writeTo(out);
out.writeLong(term);
sender.writeTo(out);
sender.writeToWithoutAttribute(out);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ static class LeaderCheckRequest extends TransportRequest {
@Override
public void writeTo(final StreamOutput out) throws IOException {
super.writeTo(out);
sender.writeTo(out);
sender.writeToWithoutAttribute(out);
}

public DiscoveryNode getSender() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,17 +358,36 @@ public DiscoveryNode(StreamInput in) throws IOException {

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

public void writeToWithoutAttribute(StreamOutput out) throws IOException {
if (out.getVersion().onOrAfter(Version.V_2_16_0)) {
writeToUtil(out, false);
} else {
writeToUtil(out, true);
}

}

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());
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);
}

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

0 comments on commit 573f78c

Please sign in to comment.