Adjust available and free bytes to be non-negative on huge FSes

In #23093 we made a change so that total bytes for a filesystem would not be a
negative value when the total bytes were > Long.MAX_VALUE.

This fixes #24453 which had a related issue where `available` and `free` bytes
could also be so large that they were negative. These will now return
`Long.MAX_VALUE` for the bytes if the JDK returns a negative value.
This commit is contained in:
Lee Hinman 2017-05-26 12:21:40 -06:00
parent e072cc7770
commit 23fb36cc87
2 changed files with 6 additions and 4 deletions

View File

@ -155,8 +155,8 @@ public class FsProbe extends AbstractComponent {
// since recomputing these once per second (default) could be costly,
// and they should not change:
fsPath.total = adjustForHugeFilesystems(nodePath.fileStore.getTotalSpace());
fsPath.free = nodePath.fileStore.getUnallocatedSpace();
fsPath.available = nodePath.fileStore.getUsableSpace();
fsPath.free = adjustForHugeFilesystems(nodePath.fileStore.getUnallocatedSpace());
fsPath.available = adjustForHugeFilesystems(nodePath.fileStore.getUsableSpace());
fsPath.type = nodePath.fileStore.type();
fsPath.mount = nodePath.fileStore.toString();
return fsPath;

View File

@ -246,6 +246,8 @@ public class FsProbeTests extends ESTestCase {
public void testAdjustForHugeFilesystems() throws Exception {
NodePath np = new FakeNodePath(createTempDir());
assertThat(FsProbe.getFSInfo(np).total, greaterThanOrEqualTo(0L));
assertThat(FsProbe.getFSInfo(np).free, greaterThanOrEqualTo(0L));
assertThat(FsProbe.getFSInfo(np).available, greaterThanOrEqualTo(0L));
}
static class FakeNodePath extends NodeEnvironment.NodePath {
@ -284,12 +286,12 @@ public class FsProbeTests extends ESTestCase {
@Override
public long getUsableSpace() throws IOException {
return 10;
return randomIntBetween(-1000, 1000);
}
@Override
public long getUnallocatedSpace() throws IOException {
return 10;
return randomIntBetween(-1000, 1000);
}
@Override