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;
}
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;
}
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());
}
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());
}
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()));
}
Aggregations