From 351b4ec6c5500ecbbe9035c3a5945915d8022ed7 Mon Sep 17 00:00:00 2001 From: William Brafford Date: Tue, 1 Jun 2021 10:36:56 -0400 Subject: [PATCH 1/2] OsStats must be lenient with bad data from older nodes --- .../org/elasticsearch/monitor/os/OsStats.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/monitor/os/OsStats.java b/server/src/main/java/org/elasticsearch/monitor/os/OsStats.java index c5b5bb277f487..a066be420da67 100644 --- a/server/src/main/java/org/elasticsearch/monitor/os/OsStats.java +++ b/server/src/main/java/org/elasticsearch/monitor/os/OsStats.java @@ -185,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_6_8_14) || in.getVersion().onOrAfter(Version.V_7_8_0)) { + 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. + this.total = Math.max(0, in.readLong()); + this.free = Math.max(0, in.readLong()); + } } @Override @@ -248,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_6_8_2) || 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. + this.total = Math.max(0, in.readLong()); + this.free = Math.max(0, in.readLong()); + } } @Override From c14dea662daec11b588d20eb56eac48e48604352 Mon Sep 17 00:00:00 2001 From: William Brafford Date: Tue, 1 Jun 2021 14:20:04 -0400 Subject: [PATCH 2/2] Add links to original bug fixes --- server/src/main/java/org/elasticsearch/monitor/os/OsStats.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/monitor/os/OsStats.java b/server/src/main/java/org/elasticsearch/monitor/os/OsStats.java index a066be420da67..544f56e4ceea2 100644 --- a/server/src/main/java/org/elasticsearch/monitor/os/OsStats.java +++ b/server/src/main/java/org/elasticsearch/monitor/os/OsStats.java @@ -193,6 +193,8 @@ public Swap(StreamInput in) throws IOException { } 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()); } @@ -263,6 +265,7 @@ public Mem(StreamInput in) throws IOException { } 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()); }