Skip to content

Commit 38cbf10

Browse files
[6.8] OsStats must be lenient with bad data from older nodes (#73616)
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 d366690 commit 38cbf10

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

+25-8
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,19 @@ public Swap(long total, long free) {
202202
}
203203

204204
public Swap(StreamInput in) throws IOException {
205-
this.total = in.readLong();
206-
assert total >= 0 : "expected total swap to be positive, got: " + total;
207-
this.free = in.readLong();
208-
assert free >= 0 : "expected free swap to be positive, got: " + total;
205+
if (in.getVersion().onOrAfter(Version.V_6_8_14)) {
206+
this.total = in.readLong();
207+
assert total >= 0 : "expected total swap to be positive, got: " + total;
208+
this.free = in.readLong();
209+
assert free >= 0 : "expected free swap to be positive, got: " + total;
210+
} else {
211+
// If we have a node in the cluster without the bug fix for
212+
// negative memory values, we need to coerce negative values to 0 here.
213+
// The relevant bug fix was added for 7.8.0 in https://github.com/elastic/elasticsearch/pull/57317
214+
// and for 6.8.14 in https://github.com/elastic/elasticsearch/pull/68554
215+
this.total = Math.max(0, in.readLong());
216+
this.free = Math.max(0, in.readLong());
217+
}
209218
}
210219

211220
@Override
@@ -263,10 +272,18 @@ public Mem(long total, long free) {
263272
}
264273

265274
public Mem(StreamInput in) throws IOException {
266-
this.total = in.readLong();
267-
assert total >= 0 : "expected total memory to be positive, got: " + total;
268-
this.free = in.readLong();
269-
assert free >= 0 : "expected free memory to be positive, got: " + total;
275+
if (in.getVersion().onOrAfter(Version.V_6_8_2)) {
276+
this.total = in.readLong();
277+
assert total >= 0 : "expected total memory to be positive, got: " + total;
278+
this.free = in.readLong();
279+
assert free >= 0 : "expected free memory to be positive, got: " + total;
280+
} else {
281+
// If we have a node in the cluster without the bug fix for
282+
// negative memory values, we need to coerce negative values to 0 here.
283+
// The relevant bug fix was added for 7.2.0 and 6.8.2 in https://github.com/elastic/elasticsearch/pull/42725
284+
this.total = Math.max(0, in.readLong());
285+
this.free = Math.max(0, in.readLong());
286+
}
270287
}
271288

272289
@Override

0 commit comments

Comments
 (0)