Skip to content

Commit 30e2019

Browse files
[7.x] OsStats must be lenient with bad data from older nodes (#73614)
We've had a series of bug fixes for cases where an OsProbe gives negative values, most often just -1, to the OsStats class. We added assertions to catch cases where we were initializing OsStats with bad values. Unfortunately, these fixes turned to not be backwards-compatible. In this commit, we simply coerce bad values to 0 when data is coming from nodes that don't have the relevant bug fixes. Relevant PRs: * #42725 * #56435 * #57317 Fixes #73459
1 parent df1294e commit 30e2019

File tree

1 file changed

+25
-8
lines changed
  • server/src/main/java/org/elasticsearch/monitor/os

1 file changed

+25
-8
lines changed

server/src/main/java/org/elasticsearch/monitor/os/OsStats.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,19 @@ public Swap(long total, long free) {
185185
}
186186

187187
public Swap(StreamInput in) throws IOException {
188-
this.total = in.readLong();
189-
assert total >= 0 : "expected total swap to be positive, got: " + total;
190-
this.free = in.readLong();
191-
assert free >= 0 : "expected free swap to be positive, got: " + total;
188+
if (in.getVersion().onOrAfter(Version.V_6_8_14) || in.getVersion().onOrAfter(Version.V_7_8_0)) {
189+
this.total = in.readLong();
190+
assert total >= 0 : "expected total swap to be positive, got: " + total;
191+
this.free = in.readLong();
192+
assert free >= 0 : "expected free swap to be positive, got: " + total;
193+
} else {
194+
// If we have a node in the cluster without the bug fix for
195+
// negative memory values, we need to coerce negative values to 0 here.
196+
// The relevant bug fix was added for 7.8.0 in https://github.com/elastic/elasticsearch/pull/57317
197+
// and for 6.8.14 in https://github.com/elastic/elasticsearch/pull/68554
198+
this.total = Math.max(0, in.readLong());
199+
this.free = Math.max(0, in.readLong());
200+
}
192201
}
193202

194203
@Override
@@ -248,10 +257,18 @@ public Mem(long total, long free) {
248257
}
249258

250259
public Mem(StreamInput in) throws IOException {
251-
this.total = in.readLong();
252-
assert total >= 0 : "expected total memory to be positive, got: " + total;
253-
this.free = in.readLong();
254-
assert free >= 0 : "expected free memory to be positive, got: " + total;
260+
if (in.getVersion().onOrAfter(Version.V_6_8_2) || in.getVersion().onOrAfter(Version.V_7_2_0)) {
261+
this.total = in.readLong();
262+
assert total >= 0 : "expected total memory to be positive, got: " + total;
263+
this.free = in.readLong();
264+
assert free >= 0 : "expected free memory to be positive, got: " + total;
265+
} else {
266+
// If we have a node in the cluster without the bug fix for
267+
// negative memory values, we need to coerce negative values to 0 here.
268+
// The relevant bug fix was added for 7.2.0 and 6.8.2 in https://github.com/elastic/elasticsearch/pull/42725
269+
this.total = Math.max(0, in.readLong());
270+
this.free = Math.max(0, in.readLong());
271+
}
255272
}
256273

257274
@Override

0 commit comments

Comments
 (0)