diff --git a/server/src/main/java/org/opensearch/monitor/fs/FsInfo.java b/server/src/main/java/org/opensearch/monitor/fs/FsInfo.java index f6879109c337f..67a2f6c43fc84 100644 --- a/server/src/main/java/org/opensearch/monitor/fs/FsInfo.java +++ b/server/src/main/java/org/opensearch/monitor/fs/FsInfo.java @@ -81,8 +81,8 @@ public static class Path implements Writeable, ToXContentObject { public Path() {} /** - * Please notice that this constructor will use value of 0 - * for fileCacheReserved and fileCacheUtilized variables. + * Please notice that this constructor will set value of 0 + * to fileCacheReserved and fileCacheUtilized variables. * * See {@link #getFileCacheReserved()}, {@link #getFileCacheUtilized()} */ @@ -90,6 +90,11 @@ public Path(String path, @Nullable String mount, long total, long free, long ava new Path(path, mount, total, free, available, 0, 0); } + /** + * Do not assign negative values to variables total, free, available, + * fileCacheReserved and fileCacheUtilized. The only exception is value -1 + * which is interpreted as an uninitialized value. + */ @InternalApi public Path( String path, @@ -107,6 +112,12 @@ public Path( this.available = available; this.fileCacheReserved = fileCacheReserved; this.fileCacheUtilized = fileCacheUtilized; + + assert (this.total == -1 || this.total >= 0) : "Total value can not be negative"; + assert (this.free == -1 || this.free >= 0) : "Free value can not be negative"; + assert (this.available == -1 || this.available >= 0) : "Available value can not be negative"; + assert (this.fileCacheReserved == -1 || this.fileCacheReserved >= 0) : "File cache reserved value can not be negative"; + assert (this.fileCacheUtilized == -1 || this.fileCacheUtilized >= 0) : "File cache utilization value can not be negative"; } /**