Search in sources :

Example 1 with BlockMasterInfo

use of alluxio.wire.BlockMasterInfo in project alluxio by Alluxio.

the class AlluxioFuseFileSystem method statfsInternal.

private int statfsInternal(String path, Statvfs stbuf) {
    ClientContext ctx = ClientContext.create(sConf);
    try (BlockMasterClient blockClient = BlockMasterClient.Factory.create(MasterClientContext.newBuilder(ctx).build())) {
        Set<BlockMasterInfo.BlockMasterInfoField> blockMasterInfoFilter = new HashSet<>(Arrays.asList(BlockMasterInfo.BlockMasterInfoField.CAPACITY_BYTES, BlockMasterInfo.BlockMasterInfoField.FREE_BYTES, BlockMasterInfo.BlockMasterInfoField.USED_BYTES));
        BlockMasterInfo blockMasterInfo = blockClient.getBlockMasterInfo(blockMasterInfoFilter);
        // although user may set different block size for different files,
        // small block size can result more accurate compute.
        long blockSize = 4L * Constants.KB;
        // fs block size
        // The size in bytes of the minimum unit of allocation on this file system
        stbuf.f_bsize.set(blockSize);
        // The preferred length of I/O requests for files on this file system.
        stbuf.f_frsize.set(blockSize);
        // total data blocks in fs
        stbuf.f_blocks.set(blockMasterInfo.getCapacityBytes() / blockSize);
        // free blocks in fs
        long freeBlocks = blockMasterInfo.getFreeBytes() / blockSize;
        stbuf.f_bfree.set(freeBlocks);
        stbuf.f_bavail.set(freeBlocks);
        // inode info in fs
        // TODO(liuhongtong): support inode info
        stbuf.f_files.set(UNKNOWN_INODES);
        stbuf.f_ffree.set(UNKNOWN_INODES);
        stbuf.f_favail.set(UNKNOWN_INODES);
        // max file name length
        stbuf.f_namemax.set(MAX_NAME_LENGTH);
    } catch (IOException e) {
        LOG.error("statfs({}) failed:", path, e);
        return -ErrorCodes.EIO();
    }
    return 0;
}
Also used : BlockMasterInfo(alluxio.wire.BlockMasterInfo) BlockMasterClient(alluxio.client.block.BlockMasterClient) ClientContext(alluxio.ClientContext) MasterClientContext(alluxio.master.MasterClientContext) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 2 with BlockMasterInfo

use of alluxio.wire.BlockMasterInfo in project alluxio by Alluxio.

the class AlluxioJniFuseFileSystem method statfsInternal.

private int statfsInternal(String path, Statvfs stbuf) {
    ClientContext ctx = ClientContext.create(mConf);
    try (BlockMasterClient blockClient = BlockMasterClient.Factory.create(MasterClientContext.newBuilder(ctx).build())) {
        Set<BlockMasterInfo.BlockMasterInfoField> blockMasterInfoFilter = new HashSet<>(Arrays.asList(BlockMasterInfo.BlockMasterInfoField.CAPACITY_BYTES, BlockMasterInfo.BlockMasterInfoField.FREE_BYTES, BlockMasterInfo.BlockMasterInfoField.USED_BYTES));
        BlockMasterInfo blockMasterInfo = blockClient.getBlockMasterInfo(blockMasterInfoFilter);
        // although user may set different block size for different files,
        // small block size can result more accurate compute.
        long blockSize = 4L * Constants.KB;
        // fs block size
        // The size in bytes of the minimum unit of allocation on this file system
        stbuf.f_bsize.set(blockSize);
        // The preferred length of I/O requests for files on this file system.
        stbuf.f_frsize.set(blockSize);
        // total data blocks in fs
        stbuf.f_blocks.set(blockMasterInfo.getCapacityBytes() / blockSize);
        // free blocks in fs
        long freeBlocks = blockMasterInfo.getFreeBytes() / blockSize;
        stbuf.f_bfree.set(freeBlocks);
        stbuf.f_bavail.set(freeBlocks);
        // inode info in fs
        stbuf.f_files.set(UNKNOWN_INODES);
        stbuf.f_ffree.set(UNKNOWN_INODES);
        stbuf.f_favail.set(UNKNOWN_INODES);
        // max file name length
        stbuf.f_namemax.set(MAX_NAME_LENGTH);
    } catch (IOException e) {
        LOG.error("statfs({}) failed:", path, e);
        return -ErrorCodes.EIO();
    }
    return 0;
}
Also used : BlockMasterInfo(alluxio.wire.BlockMasterInfo) BlockMasterClient(alluxio.client.block.BlockMasterClient) ClientContext(alluxio.ClientContext) MasterClientContext(alluxio.master.MasterClientContext) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 3 with BlockMasterInfo

use of alluxio.wire.BlockMasterInfo in project alluxio by Alluxio.

the class AlluxioFuseFileSystemTest method statfs.

@Test
public void statfs() throws Exception {
    Runtime runtime = Runtime.getSystemRuntime();
    Pointer pointer = runtime.getMemoryManager().allocateTemporary(4 * Constants.KB, true);
    Statvfs stbuf = Statvfs.of(pointer);
    int blockSize = 4 * Constants.KB;
    int totalBlocks = 4;
    int freeBlocks = 3;
    BlockMasterClient blockMasterClient = PowerMockito.mock(BlockMasterClient.class);
    PowerMockito.mockStatic(BlockMasterClient.Factory.class);
    when(BlockMasterClient.Factory.create(any())).thenReturn(blockMasterClient);
    BlockMasterInfo blockMasterInfo = new BlockMasterInfo();
    blockMasterInfo.setCapacityBytes(totalBlocks * blockSize);
    blockMasterInfo.setFreeBytes(freeBlocks * blockSize);
    when(blockMasterClient.getBlockMasterInfo(any())).thenReturn(blockMasterInfo);
    assertEquals(0, mFuseFs.statfs("/", stbuf));
    assertEquals(blockSize, stbuf.f_bsize.intValue());
    assertEquals(blockSize, stbuf.f_frsize.intValue());
    assertEquals(totalBlocks, stbuf.f_blocks.longValue());
    assertEquals(freeBlocks, stbuf.f_bfree.longValue());
    assertEquals(freeBlocks, stbuf.f_bavail.longValue());
    assertEquals(AlluxioFuseFileSystem.UNKNOWN_INODES, stbuf.f_files.intValue());
    assertEquals(AlluxioFuseFileSystem.UNKNOWN_INODES, stbuf.f_ffree.intValue());
    assertEquals(AlluxioFuseFileSystem.UNKNOWN_INODES, stbuf.f_favail.intValue());
    assertEquals(AlluxioFuseFileSystem.MAX_NAME_LENGTH, stbuf.f_namemax.intValue());
}
Also used : BlockMasterInfo(alluxio.wire.BlockMasterInfo) Runtime(jnr.ffi.Runtime) BlockMasterClient(alluxio.client.block.BlockMasterClient) Pointer(jnr.ffi.Pointer) Statvfs(ru.serce.jnrfuse.struct.Statvfs) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with BlockMasterInfo

use of alluxio.wire.BlockMasterInfo in project alluxio by Alluxio.

the class AlluxioJniFuseFileSystemTest method statfs.

@Test
public void statfs() throws Exception {
    ByteBuffer buffer = ByteBuffer.allocateDirect(4 * Constants.KB);
    buffer.clear();
    Statvfs stbuf = Statvfs.of(buffer);
    int blockSize = 4 * Constants.KB;
    int totalBlocks = 4;
    int freeBlocks = 3;
    BlockMasterClient blockMasterClient = PowerMockito.mock(BlockMasterClient.class);
    PowerMockito.mockStatic(BlockMasterClient.Factory.class);
    when(BlockMasterClient.Factory.create(any())).thenReturn(blockMasterClient);
    BlockMasterInfo blockMasterInfo = new BlockMasterInfo();
    blockMasterInfo.setCapacityBytes(totalBlocks * blockSize);
    blockMasterInfo.setFreeBytes(freeBlocks * blockSize);
    when(blockMasterClient.getBlockMasterInfo(any())).thenReturn(blockMasterInfo);
    assertEquals(0, mFuseFs.statfs("/", stbuf));
    assertEquals(blockSize, stbuf.f_bsize.intValue());
    assertEquals(blockSize, stbuf.f_frsize.intValue());
    assertEquals(totalBlocks, stbuf.f_blocks.longValue());
    assertEquals(freeBlocks, stbuf.f_bfree.longValue());
    assertEquals(freeBlocks, stbuf.f_bavail.longValue());
    assertEquals(AlluxioJniFuseFileSystem.UNKNOWN_INODES, stbuf.f_files.intValue());
    assertEquals(AlluxioJniFuseFileSystem.UNKNOWN_INODES, stbuf.f_ffree.intValue());
    assertEquals(AlluxioJniFuseFileSystem.UNKNOWN_INODES, stbuf.f_favail.intValue());
    assertEquals(AlluxioJniFuseFileSystem.MAX_NAME_LENGTH, stbuf.f_namemax.intValue());
}
Also used : BlockMasterInfo(alluxio.wire.BlockMasterInfo) BlockMasterClient(alluxio.client.block.BlockMasterClient) Statvfs(alluxio.jnifuse.struct.Statvfs) ByteBuffer(java.nio.ByteBuffer) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with BlockMasterInfo

use of alluxio.wire.BlockMasterInfo in project alluxio by Alluxio.

the class SummaryCommand method printBlockMasterInfo.

/**
 * Prints Alluxio block master information.
 */
private void printBlockMasterInfo() throws IOException {
    Set<BlockMasterInfoField> blockMasterInfoFilter = new HashSet<>(Arrays.asList(BlockMasterInfoField.LIVE_WORKER_NUM, BlockMasterInfoField.LOST_WORKER_NUM, BlockMasterInfoField.CAPACITY_BYTES, BlockMasterInfoField.USED_BYTES, BlockMasterInfoField.FREE_BYTES, BlockMasterInfoField.CAPACITY_BYTES_ON_TIERS, BlockMasterInfoField.USED_BYTES_ON_TIERS));
    BlockMasterInfo blockMasterInfo = mBlockMasterClient.getBlockMasterInfo(blockMasterInfoFilter);
    print("Live Workers: " + blockMasterInfo.getLiveWorkerNum());
    print("Lost Workers: " + blockMasterInfo.getLostWorkerNum());
    print("Total Capacity: " + FormatUtils.getSizeFromBytes(blockMasterInfo.getCapacityBytes()));
    mIndentationLevel++;
    Map<String, Long> totalCapacityOnTiers = new TreeMap<>((a, b) -> (FileSystemAdminShellUtils.compareTierNames(a, b)));
    totalCapacityOnTiers.putAll(blockMasterInfo.getCapacityBytesOnTiers());
    for (Map.Entry<String, Long> capacityBytesTier : totalCapacityOnTiers.entrySet()) {
        print("Tier: " + capacityBytesTier.getKey() + "  Size: " + FormatUtils.getSizeFromBytes(capacityBytesTier.getValue()));
    }
    mIndentationLevel--;
    print("Used Capacity: " + FormatUtils.getSizeFromBytes(blockMasterInfo.getUsedBytes()));
    mIndentationLevel++;
    Map<String, Long> usedCapacityOnTiers = new TreeMap<>((a, b) -> (FileSystemAdminShellUtils.compareTierNames(a, b)));
    usedCapacityOnTiers.putAll(blockMasterInfo.getUsedBytesOnTiers());
    for (Map.Entry<String, Long> usedBytesTier : usedCapacityOnTiers.entrySet()) {
        print("Tier: " + usedBytesTier.getKey() + "  Size: " + FormatUtils.getSizeFromBytes(usedBytesTier.getValue()));
    }
    mIndentationLevel--;
    print("Free Capacity: " + FormatUtils.getSizeFromBytes(blockMasterInfo.getFreeBytes()));
}
Also used : BlockMasterInfo(alluxio.wire.BlockMasterInfo) BlockMasterInfoField(alluxio.wire.BlockMasterInfo.BlockMasterInfoField) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

BlockMasterInfo (alluxio.wire.BlockMasterInfo)6 BlockMasterClient (alluxio.client.block.BlockMasterClient)5 HashSet (java.util.HashSet)3 ClientContext (alluxio.ClientContext)2 MasterClientContext (alluxio.master.MasterClientContext)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 MetaMasterClient (alluxio.client.meta.MetaMasterClient)1 MasterInfo (alluxio.grpc.MasterInfo)1 Statvfs (alluxio.jnifuse.struct.Statvfs)1 BlockMasterInfoField (alluxio.wire.BlockMasterInfo.BlockMasterInfoField)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Pointer (jnr.ffi.Pointer)1 Runtime (jnr.ffi.Runtime)1