diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java index 4c475229ae5..62255df369b 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java @@ -83,7 +83,7 @@ public class ClusterStatsNodes implements ToXContent { continue; } if (nodeResponse.nodeStats().getFs() != null) { - this.fs.add(nodeResponse.nodeStats().getFs().total()); + this.fs.add(nodeResponse.nodeStats().getFs().getTotal()); } } this.counts = new Counts(nodeInfos); diff --git a/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java b/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java index 641dc3a5bb3..eec162afe49 100644 --- a/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java +++ b/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java @@ -410,16 +410,16 @@ public class FsInfo implements Iterable, Writeable, ToXContent { } - final long timestamp; - final Path[] paths; - final IoStats ioStats; - Path total; + private final long timestamp; + private final Path[] paths; + private final IoStats ioStats; + private final Path total; public FsInfo(long timestamp, IoStats ioStats, Path[] paths) { this.timestamp = timestamp; this.ioStats = ioStats; this.paths = paths; - this.total = null; + this.total = total(); } /** @@ -432,6 +432,7 @@ public class FsInfo implements Iterable, Writeable, ToXContent { for (int i = 0; i < paths.length; i++) { paths[i] = new Path(in); } + this.total = total(); } @Override @@ -445,13 +446,10 @@ public class FsInfo implements Iterable, Writeable, ToXContent { } public Path getTotal() { - return total(); + return total; } - public Path total() { - if (total != null) { - return total; - } + private Path total() { Path res = new Path(); Set seenDevices = new HashSet<>(paths.length); for (Path subPath : paths) { @@ -462,7 +460,6 @@ public class FsInfo implements Iterable, Writeable, ToXContent { } res.add(subPath); } - total = res; return res; } @@ -506,5 +503,4 @@ public class FsInfo implements Iterable, Writeable, ToXContent { static final String TOTAL = "total"; static final String IO_STATS = "io_stats"; } - } diff --git a/core/src/test/java/org/elasticsearch/monitor/fs/FsProbeTests.java b/core/src/test/java/org/elasticsearch/monitor/fs/FsProbeTests.java index 8eba98ae0b7..14f7151e40d 100644 --- a/core/src/test/java/org/elasticsearch/monitor/fs/FsProbeTests.java +++ b/core/src/test/java/org/elasticsearch/monitor/fs/FsProbeTests.java @@ -141,7 +141,7 @@ public class FsProbeTests extends ESTestCase { " 253 1 dm-1 112 0 4624 13 0 0 0 0 0 5 13", " 253 2 dm-2 48045 0 714866 49369 1372291 0 64128568 33730766 0 1058347 33782056")); - final FsInfo previous = new FsInfo(System.currentTimeMillis(), first, null); + final FsInfo previous = new FsInfo(System.currentTimeMillis(), first, new FsInfo.Path[0]); final FsInfo.IoStats second = probe.ioStats(devicesNumbers, previous); assertNotNull(second); assertThat(second.devicesStats[0].majorDeviceNumber, equalTo(253));