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

[6.8] OsStats must be lenient with bad data from older nodes #73616

Merged
merged 2 commits into from Jun 1, 2021
Merged
Changes from all 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
33 changes: 25 additions & 8 deletions server/src/main/java/org/elasticsearch/monitor/os/OsStats.java
Expand Up @@ -202,10 +202,19 @@ 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_6_8_14)) {
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;
} 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.
// The relevant bug fix was added for 7.8.0 in https://github.com/elastic/elasticsearch/pull/57317
// and for 6.8.14 in https://github.com/elastic/elasticsearch/pull/68554
this.total = Math.max(0, in.readLong());
this.free = Math.max(0, in.readLong());
}
}

@Override
Expand Down Expand Up @@ -263,10 +272,18 @@ 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_6_8_2)) {
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.
// The relevant bug fix was added for 7.2.0 and 6.8.2 in https://github.com/elastic/elasticsearch/pull/42725
this.total = Math.max(0, in.readLong());
this.free = Math.max(0, in.readLong());
}
}

@Override
Expand Down