Eagerly compute FsInfo#total so that the member instance can become final
FsInfo#total is removed in favour of getTotal, which allows to retrieve the total value [TEST] fix FsProbeTests: null is not accepted as path constructor argument
This commit is contained in:
parent
f1b1d1cae0
commit
af633a293c
|
@ -83,7 +83,7 @@ public class ClusterStatsNodes implements ToXContent {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (nodeResponse.nodeStats().getFs() != null) {
|
if (nodeResponse.nodeStats().getFs() != null) {
|
||||||
this.fs.add(nodeResponse.nodeStats().getFs().total());
|
this.fs.add(nodeResponse.nodeStats().getFs().getTotal());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.counts = new Counts(nodeInfos);
|
this.counts = new Counts(nodeInfos);
|
||||||
|
|
|
@ -410,16 +410,16 @@ public class FsInfo implements Iterable<FsInfo.Path>, Writeable, ToXContent {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final long timestamp;
|
private final long timestamp;
|
||||||
final Path[] paths;
|
private final Path[] paths;
|
||||||
final IoStats ioStats;
|
private final IoStats ioStats;
|
||||||
Path total;
|
private final Path total;
|
||||||
|
|
||||||
public FsInfo(long timestamp, IoStats ioStats, Path[] paths) {
|
public FsInfo(long timestamp, IoStats ioStats, Path[] paths) {
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
this.ioStats = ioStats;
|
this.ioStats = ioStats;
|
||||||
this.paths = paths;
|
this.paths = paths;
|
||||||
this.total = null;
|
this.total = total();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -432,6 +432,7 @@ public class FsInfo implements Iterable<FsInfo.Path>, Writeable, ToXContent {
|
||||||
for (int i = 0; i < paths.length; i++) {
|
for (int i = 0; i < paths.length; i++) {
|
||||||
paths[i] = new Path(in);
|
paths[i] = new Path(in);
|
||||||
}
|
}
|
||||||
|
this.total = total();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -445,13 +446,10 @@ public class FsInfo implements Iterable<FsInfo.Path>, Writeable, ToXContent {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Path getTotal() {
|
public Path getTotal() {
|
||||||
return total();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Path total() {
|
|
||||||
if (total != null) {
|
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Path total() {
|
||||||
Path res = new Path();
|
Path res = new Path();
|
||||||
Set<String> seenDevices = new HashSet<>(paths.length);
|
Set<String> seenDevices = new HashSet<>(paths.length);
|
||||||
for (Path subPath : paths) {
|
for (Path subPath : paths) {
|
||||||
|
@ -462,7 +460,6 @@ public class FsInfo implements Iterable<FsInfo.Path>, Writeable, ToXContent {
|
||||||
}
|
}
|
||||||
res.add(subPath);
|
res.add(subPath);
|
||||||
}
|
}
|
||||||
total = res;
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,5 +503,4 @@ public class FsInfo implements Iterable<FsInfo.Path>, Writeable, ToXContent {
|
||||||
static final String TOTAL = "total";
|
static final String TOTAL = "total";
|
||||||
static final String IO_STATS = "io_stats";
|
static final String IO_STATS = "io_stats";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 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"));
|
" 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);
|
final FsInfo.IoStats second = probe.ioStats(devicesNumbers, previous);
|
||||||
assertNotNull(second);
|
assertNotNull(second);
|
||||||
assertThat(second.devicesStats[0].majorDeviceNumber, equalTo(253));
|
assertThat(second.devicesStats[0].majorDeviceNumber, equalTo(253));
|
||||||
|
|
Loading…
Reference in New Issue