Search in sources :

Example 1 with UnixMountInfo

use of alluxio.util.UnixMountInfo in project alluxio by Alluxio.

the class DefaultStorageTier method checkEnoughMemSpace.

/**
 * Checks that a tmpfs/ramfs backing the storage directory has enough capacity. If the storage
 * directory is not backed by tmpfs/ramfs or the size of the tmpfs/ramfs cannot be determined, a
 * warning is logged but no exception is thrown.
 *
 * @param storageDir the storage dir to check
 * @throws IllegalStateException if the tmpfs/ramfs is smaller than the configured memory size
 */
private void checkEnoughMemSpace(StorageDir storageDir) {
    if (!OSUtils.isLinux()) {
        return;
    }
    List<UnixMountInfo> info;
    try {
        info = ShellUtils.getUnixMountInfo();
    } catch (IOException e) {
        LOG.warn("Failed to get mount information for verifying memory capacity: {}", e.toString());
        return;
    }
    boolean foundMountInfo = false;
    for (UnixMountInfo mountInfo : info) {
        Optional<String> mountPointOption = mountInfo.getMountPoint();
        Optional<String> fsTypeOption = mountInfo.getFsType();
        Optional<Long> sizeOption = mountInfo.getOptions().getSize();
        if (!mountPointOption.isPresent() || !fsTypeOption.isPresent() || !sizeOption.isPresent()) {
            continue;
        }
        String mountPoint = mountPointOption.get();
        String fsType = fsTypeOption.get();
        long size = sizeOption.get();
        try {
            // getDirPath gives something like "/mnt/tmpfs/alluxioworker".
            String rootStoragePath = PathUtils.getParent(storageDir.getDirPath());
            if (!PathUtils.cleanPath(mountPoint).equals(rootStoragePath)) {
                continue;
            }
        } catch (InvalidPathException e) {
            continue;
        }
        foundMountInfo = true;
        if (fsType.equalsIgnoreCase("tmpfs") && size < storageDir.getCapacityBytes()) {
            throw new IllegalStateException(String.format("%s is smaller than the configured size: %s size: %s, configured size: %s", fsType, fsType, size, storageDir.getCapacityBytes()));
        }
        break;
    }
    if (!foundMountInfo) {
        LOG.warn("Failed to verify memory capacity");
    }
}
Also used : UnixMountInfo(alluxio.util.UnixMountInfo) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException)

Aggregations

InvalidPathException (alluxio.exception.InvalidPathException)1 UnixMountInfo (alluxio.util.UnixMountInfo)1 IOException (java.io.IOException)1