Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] OsStats must be lenient with bad data from older nodes #73610

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 23 additions & 8 deletions server/src/main/java/org/elasticsearch/monitor/os/OsStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
Expand Down Expand Up @@ -184,10 +185,17 @@ public Swap(long total, long free) {
}

public Swap(StreamInput in) throws IOException {
this.total = in.readLong();
assert total >= 0 : "expected total swap to be positive, got: " + total;
this.free = in.readLong();
assert free >= 0 : "expected free swap to be positive, got: " + total;
if (in.getVersion().onOrAfter(Version.V_7_8_0)) {
this.total = in.readLong();
assert this.total >= 0 : "expected total swap to be positive, got: " + total;
this.free = in.readLong();
assert this.free >= 0 : "expected free swap to be positive, got: " + total;
} else {
// If we have a node in the cluster without the bug fix for
// negative memory values, we need to coerce negative values to 0 here.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have a link here to the relevant PR that added coercion, so a reader can verify the 7.8 boundary.

this.total = Math.max(0, in.readLong());
this.free = Math.max(0, in.readLong());
}
}

@Override
Expand Down Expand Up @@ -247,10 +255,17 @@ public Mem(long total, long free) {
}

public Mem(StreamInput in) throws IOException {
this.total = in.readLong();
assert total >= 0 : "expected total memory to be positive, got: " + total;
this.free = in.readLong();
assert free >= 0 : "expected free memory to be positive, got: " + total;
if (in.getVersion().onOrAfter(Version.V_7_2_0)) {
this.total = in.readLong();
assert total >= 0 : "expected total memory to be positive, got: " + total;
this.free = in.readLong();
assert free >= 0 : "expected free memory to be positive, got: " + total;
} else {
// If we have a node in the cluster without the bug fix for
// negative memory values, we need to coerce negative values to 0 here.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have a link here to the relevant PR that added coercion, so a reader can verify the 7.2 boundary.

this.total = Math.max(0, in.readLong());
this.free = Math.max(0, in.readLong());
}
}

@Override
Expand Down