Skip to content

Commit 80ea64c

Browse files
[8.x] OsStats must be lenient with bad data from older nodes (#73610)
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 3d80e77 commit 80ea64c

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
@@ -10,6 +10,7 @@
1010

1111
import org.apache.logging.log4j.LogManager;
1212
import org.apache.logging.log4j.Logger;
13+
import org.elasticsearch.Version;
1314
import org.elasticsearch.common.io.stream.StreamInput;
1415
import org.elasticsearch.common.io.stream.StreamOutput;
1516
import org.elasticsearch.common.io.stream.Writeable;
@@ -184,10 +185,18 @@ public Swap(long total, long free) {
184185
}
185186

186187
public Swap(StreamInput in) throws IOException {
187-
this.total = in.readLong();
188-
assert total >= 0 : "expected total swap to be positive, got: " + total;
189-
this.free = in.readLong();
190-
assert free >= 0 : "expected free swap to be positive, got: " + total;
188+
if (in.getVersion().onOrAfter(Version.V_7_8_0)) {
189+
this.total = in.readLong();
190+
assert this.total >= 0 : "expected total swap to be positive, got: " + total;
191+
this.free = in.readLong();
192+
assert this.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+
this.total = Math.max(0, in.readLong());
198+
this.free = Math.max(0, in.readLong());
199+
}
191200
}
192201

193202
@Override
@@ -247,10 +256,18 @@ public Mem(long total, long free) {
247256
}
248257

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

256273
@Override

0 commit comments

Comments
 (0)