Search in sources :

Example 1 with FileStore

use of java.nio.file.FileStore in project vert.x by eclipse.

the class FileSystemImpl method fsPropsInternal.

private BlockingAction<FileSystemProps> fsPropsInternal(String path, Handler<AsyncResult<FileSystemProps>> handler) {
    Objects.requireNonNull(path);
    return new BlockingAction<FileSystemProps>(handler) {

        public FileSystemProps perform() {
            try {
                Path target = vertx.resolveFile(path).toPath();
                FileStore fs = Files.getFileStore(target);
                return new FileSystemPropsImpl(fs.getTotalSpace(), fs.getUnallocatedSpace(), fs.getUsableSpace());
            } catch (IOException e) {
                throw new FileSystemException(e);
            }
        }
    };
}
Also used : Path(java.nio.file.Path) FileStore(java.nio.file.FileStore) FileSystemException(io.vertx.core.file.FileSystemException) IOException(java.io.IOException)

Example 2 with FileStore

use of java.nio.file.FileStore in project elasticsearch by elastic.

the class ESFileStoreTests method testNegativeSpace.

public void testNegativeSpace() throws Exception {
    FileStore mocked = mock(FileStore.class);
    when(mocked.getUsableSpace()).thenReturn(-1L);
    when(mocked.getTotalSpace()).thenReturn(-1L);
    when(mocked.getUnallocatedSpace()).thenReturn(-1L);
    assertEquals(-1, mocked.getUsableSpace());
    FileStore store = new ESFileStore(mocked);
    assertEquals(Long.MAX_VALUE, store.getUsableSpace());
    assertEquals(Long.MAX_VALUE, store.getTotalSpace());
    assertEquals(Long.MAX_VALUE, store.getUnallocatedSpace());
}
Also used : FileStore(java.nio.file.FileStore)

Example 3 with FileStore

use of java.nio.file.FileStore in project lucene-solr by apache.

the class IOUtils method spinsLinux.

// following methods are package-private for testing ONLY
// note: requires a real or fake linux filesystem!
static boolean spinsLinux(Path path) throws IOException {
    FileStore store = getFileStore(path);
    // this won't have a corresponding block device
    if ("tmpfs".equals(store.type())) {
        return false;
    }
    // get block device name
    String devName = store.name();
    // not a device (e.g. NFS server)
    if (!devName.startsWith("/")) {
        return true;
    }
    // resolve any symlinks to real block device (e.g. LVM)
    // /dev/sda0 -> sda0
    // /devices/XXX -> sda0
    devName = path.getRoot().resolve(devName).toRealPath().getFileName().toString();
    // now try to find the longest matching device folder in /sys/block
    // (that starts with our dev name):
    Path sysinfo = path.getRoot().resolve("sys").resolve("block");
    Path devsysinfo = null;
    int matchlen = 0;
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(sysinfo)) {
        for (Path device : stream) {
            String name = device.getFileName().toString();
            if (name.length() > matchlen && devName.startsWith(name)) {
                devsysinfo = device;
                matchlen = name.length();
            }
        }
    }
    if (devsysinfo == null) {
        // give up
        return true;
    }
    // read first byte from rotational, it's a 1 if it spins.
    Path rotational = devsysinfo.resolve("queue").resolve("rotational");
    try (InputStream stream = Files.newInputStream(rotational)) {
        return stream.read() == '1';
    }
}
Also used : Path(java.nio.file.Path) FileStore(java.nio.file.FileStore) InputStream(java.io.InputStream)

Example 4 with FileStore

use of java.nio.file.FileStore in project lucene-solr by apache.

the class TestIOUtils method testSSD.

public void testSSD() throws Exception {
    assumeFalse("windows is not supported", Constants.WINDOWS);
    Path dir = createTempDir();
    dir = FilterPath.unwrap(dir).toRealPath();
    // fake ssd
    FileStore root = new MockFileStore(dir.toString() + " (/dev/zzz1)", "btrfs", "/dev/zzz1");
    // make a fake /dev/zzz1 for it
    Path devdir = dir.resolve("dev");
    Files.createDirectories(devdir);
    Files.createFile(devdir.resolve("zzz1"));
    // make a fake /sys/block/zzz/queue/rotational file for it
    Path sysdir = dir.resolve("sys").resolve("block").resolve("zzz").resolve("queue");
    Files.createDirectories(sysdir);
    try (OutputStream o = Files.newOutputStream(sysdir.resolve("rotational"))) {
        o.write("0\n".getBytes(StandardCharsets.US_ASCII));
    }
    Map<String, FileStore> mappings = Collections.singletonMap(dir.toString(), root);
    FileSystem mockLinux = new MockLinuxFileSystemProvider(dir.getFileSystem(), mappings, dir).getFileSystem(null);
    Path mockPath = mockLinux.getPath(dir.toString());
    assertFalse(IOUtils.spinsLinux(mockPath));
}
Also used : FilterPath(org.apache.lucene.mockfile.FilterPath) Path(java.nio.file.Path) FileStore(java.nio.file.FileStore) OutputStream(java.io.OutputStream) FileSystem(java.nio.file.FileSystem) FilterFileSystem(org.apache.lucene.mockfile.FilterFileSystem)

Example 5 with FileStore

use of java.nio.file.FileStore in project lucene-solr by apache.

the class TestIOUtils method testNVME.

public void testNVME() throws Exception {
    assumeFalse("windows is not supported", Constants.WINDOWS);
    Path dir = createTempDir();
    dir = FilterPath.unwrap(dir).toRealPath();
    // fake ssd
    FileStore root = new MockFileStore(dir.toString() + " (/dev/nvme0n1p1)", "btrfs", "/dev/nvme0n1p1");
    // make a fake /dev/nvme0n1p1 for it
    Path devdir = dir.resolve("dev");
    Files.createDirectories(devdir);
    Files.createFile(devdir.resolve("nvme0n1p1"));
    // make a fake /sys/block/nvme0n1/queue/rotational file for it
    Path sysdir = dir.resolve("sys").resolve("block").resolve("nvme0n1").resolve("queue");
    Files.createDirectories(sysdir);
    try (OutputStream o = Files.newOutputStream(sysdir.resolve("rotational"))) {
        o.write("0\n".getBytes(StandardCharsets.US_ASCII));
    }
    // As test for the longest path match, add some other devices (that have no queue/rotational), too:
    Files.createFile(dir.resolve("sys").resolve("block").resolve("nvme0"));
    Files.createFile(dir.resolve("sys").resolve("block").resolve("dummy"));
    Files.createFile(dir.resolve("sys").resolve("block").resolve("nvm"));
    Map<String, FileStore> mappings = Collections.singletonMap(dir.toString(), root);
    FileSystem mockLinux = new MockLinuxFileSystemProvider(dir.getFileSystem(), mappings, dir).getFileSystem(null);
    Path mockPath = mockLinux.getPath(dir.toString());
    assertFalse(IOUtils.spinsLinux(mockPath));
}
Also used : FilterPath(org.apache.lucene.mockfile.FilterPath) Path(java.nio.file.Path) FileStore(java.nio.file.FileStore) OutputStream(java.io.OutputStream) FileSystem(java.nio.file.FileSystem) FilterFileSystem(org.apache.lucene.mockfile.FilterFileSystem)

Aggregations

FileStore (java.nio.file.FileStore)17 Path (java.nio.file.Path)11 FileSystem (java.nio.file.FileSystem)8 FilterFileSystem (org.apache.lucene.mockfile.FilterFileSystem)8 FilterPath (org.apache.lucene.mockfile.FilterPath)8 OutputStream (java.io.OutputStream)5 IOException (java.io.IOException)4 FileSystemException (java.nio.file.FileSystemException)2 SuppressForbidden (org.elasticsearch.common.SuppressForbidden)2 NSDictionary (com.dd.plist.NSDictionary)1 NSNumber (com.dd.plist.NSNumber)1 NSObject (com.dd.plist.NSObject)1 FileSystemException (io.vertx.core.file.FileSystemException)1 File (java.io.File)1 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 UUID (java.util.UUID)1 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)1