-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
[8.x] OsStats must be lenient with bad data from older nodes #73610
Merged
williamrandolph
merged 4 commits into
elastic:master
from
williamrandolph:fix/master/os-stats-bwc
Jun 1, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.io.stream.Writeable; | ||
|
@@ -184,10 +185,18 @@ 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_7_8_0)) { | ||
this.total = in.readLong(); | ||
assert this.total >= 0 : "expected total swap to be positive, got: " + total; | ||
this.free = in.readLong(); | ||
assert this.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 | ||
this.total = Math.max(0, in.readLong()); | ||
this.free = Math.max(0, in.readLong()); | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -247,10 +256,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_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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to have a link here to the relevant PR that added coercion, so a reader can verify the 7.2 boundary. |
||
// The relevant bug fix was added for 7.2.0 in https://github.com/elastic/elasticsearch/pull/42725 | ||
this.total = Math.max(0, in.readLong()); | ||
this.free = Math.max(0, in.readLong()); | ||
} | ||
} | ||
|
||
@Override | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to have a link here to the relevant PR that added coercion, so a reader can verify the 7.8 boundary.