use of alluxio.wire.FileBlockInfo in project alluxio by Alluxio.
the class AlluxioBlockStoreTest method getInStreamUfsLocalFirst.
@Test
public void getInStreamUfsLocalFirst() throws Exception {
WorkerNetAddress remote = new WorkerNetAddress().setHost("remote");
WorkerNetAddress local = new WorkerNetAddress().setHost(WORKER_HOSTNAME_LOCAL);
BlockInfo info = new BlockInfo().setBlockId(0);
URIStatus dummyStatus = new URIStatus(new FileInfo().setPersisted(true).setBlockIds(Collections.singletonList(0L)).setFileBlockInfos(Collections.singletonList(new FileBlockInfo().setBlockInfo(info))));
OpenFilePOptions readOptions = OpenFilePOptions.newBuilder().build();
InStreamOptions options = new InStreamOptions(dummyStatus, readOptions, sConf);
when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(new BlockInfo());
when(mContext.getCachedWorkers()).thenReturn(Lists.newArrayList(new BlockWorkerInfo(remote, 100, 0), new BlockWorkerInfo(local, 100, 0)));
BlockInStream stream = mBlockStore.getInStream(BLOCK_ID, options);
assertEquals(local, stream.getAddress());
assertEquals(GrpcDataReader.Factory.class.getName(), stream.getDataReaderFactory().getClass().getName());
}
use of alluxio.wire.FileBlockInfo in project alluxio by Alluxio.
the class AlluxioBlockStoreTest method getInStreamUfsProcessLocal.
@Test
public void getInStreamUfsProcessLocal() throws Exception {
WorkerNetAddress remote = new WorkerNetAddress().setHost("remote");
WorkerNetAddress local = new WorkerNetAddress().setHost(WORKER_HOSTNAME_LOCAL);
BlockInfo info = new BlockInfo().setBlockId(0);
URIStatus dummyStatus = new URIStatus(new FileInfo().setPersisted(true).setBlockIds(Collections.singletonList(0L)).setFileBlockInfos(Collections.singletonList(new FileBlockInfo().setBlockInfo(info))));
OpenFilePOptions readOptions = OpenFilePOptions.newBuilder().build();
InStreamOptions options = new InStreamOptions(dummyStatus, readOptions, sConf);
when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(new BlockInfo());
when(mContext.getCachedWorkers()).thenReturn(Lists.newArrayList(new BlockWorkerInfo(remote, 100, 0), new BlockWorkerInfo(local, 100, 0)));
when(mContext.getNodeLocalWorker()).thenReturn(local);
when(mContext.hasProcessLocalWorker()).thenReturn(true);
BlockWorker blockWorker = Mockito.mock(BlockWorker.class);
when(mContext.getProcessLocalWorker()).thenReturn(blockWorker);
BlockInStream stream = mBlockStore.getInStream(BLOCK_ID, options);
assertEquals(local, stream.getAddress());
assertEquals(BlockWorkerDataReader.Factory.class.getName(), stream.getDataReaderFactory().getClass().getName());
}
use of alluxio.wire.FileBlockInfo in project alluxio by Alluxio.
the class CacheRequestManagerTest method before.
/**
* Sets up all dependencies before a test runs.
*/
@Before
public void before() throws IOException {
BlockMasterClient blockMasterClient = mock(BlockMasterClient.class);
BlockMasterClientPool blockMasterClientPool = spy(new BlockMasterClientPool());
when(blockMasterClientPool.createNewResource()).thenReturn(blockMasterClient);
TieredBlockStore blockStore = new TieredBlockStore();
FileSystemMasterClient fileSystemMasterClient = mock(FileSystemMasterClient.class);
Sessions sessions = mock(Sessions.class);
// Connect to the real UFS for testing
UfsManager ufsManager = mock(UfsManager.class);
mRootUfs = ServerConfiguration.getString(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS);
UfsManager.UfsClient ufsClient = new UfsManager.UfsClient(() -> UnderFileSystem.Factory.create(mRootUfs, UnderFileSystemConfiguration.defaults(ServerConfiguration.global())), new AlluxioURI(mRootUfs));
when(ufsManager.get(anyLong())).thenReturn(ufsClient);
mBlockWorker = spy(new DefaultBlockWorker(blockMasterClientPool, fileSystemMasterClient, sessions, blockStore, ufsManager));
FileSystemContext context = mock(FileSystemContext.class);
mCacheRequestManager = spy(new CacheRequestManager(GrpcExecutors.CACHE_MANAGER_EXECUTOR, mBlockWorker, context));
// Write an actual file to UFS
String testFilePath = File.createTempFile("temp", null, new File(mRootUfs)).getAbsolutePath();
byte[] buffer = BufferUtils.getIncreasingByteArray(CHUNK_SIZE);
BufferUtils.writeBufferToFile(testFilePath, buffer);
// create options
BlockInfo info = new BlockInfo().setBlockId(BLOCK_ID).setLength(CHUNK_SIZE);
URIStatus dummyStatus = new URIStatus(new FileInfo().setPersisted(true).setUfsPath(testFilePath).setBlockIds(Collections.singletonList(BLOCK_ID)).setLength(CHUNK_SIZE).setBlockSizeBytes(CHUNK_SIZE).setFileBlockInfos(Collections.singletonList(new FileBlockInfo().setBlockInfo(info))));
OpenFilePOptions readOptions = FileSystemOptions.openFileDefaults(mConf);
InStreamOptions options = new InStreamOptions(dummyStatus, readOptions, mConf);
mOpenUfsBlockOptions = options.getOpenUfsBlockOptions(BLOCK_ID);
}
use of alluxio.wire.FileBlockInfo in project alluxio by Alluxio.
the class PersistDefinitionTest method selectExecutorsMissingLocationTest.
@Test
public void selectExecutorsMissingLocationTest() throws Exception {
AlluxioURI uri = new AlluxioURI("/test");
PersistConfig config = new PersistConfig(uri.getPath(), -1, true, "");
long blockId = 1;
BlockInfo blockInfo = new BlockInfo().setBlockId(blockId);
FileBlockInfo fileBlockInfo = new FileBlockInfo().setBlockInfo(blockInfo);
FileInfo testFileInfo = new FileInfo();
testFileInfo.setFileBlockInfos(Lists.newArrayList(fileBlockInfo));
Mockito.when(mMockFileSystem.getStatus(uri)).thenReturn(new URIStatus(testFileInfo));
try {
new PersistDefinition().selectExecutors(config, Lists.newArrayList(new WorkerInfo()), new SelectExecutorsContext(1, mJobServerContext));
} catch (Exception e) {
Assert.assertEquals("Block " + blockId + " does not exist", e.getMessage());
}
}
use of alluxio.wire.FileBlockInfo in project alluxio by Alluxio.
the class DefaultFileSystemMaster method generateFileBlockInfo.
/**
* Generates a {@link FileBlockInfo} object from internal metadata. This adds file information to
* the block, such as the file offset, and additional UFS locations for the block.
*
* @param inodePath the file the block is a part of
* @param blockInfo the {@link BlockInfo} to generate the {@link FileBlockInfo} from
* @return a new {@link FileBlockInfo} for the block
*/
private FileBlockInfo generateFileBlockInfo(LockedInodePath inodePath, BlockInfo blockInfo) throws FileDoesNotExistException {
InodeFile file = inodePath.getInodeFile();
FileBlockInfo fileBlockInfo = new FileBlockInfo();
fileBlockInfo.setBlockInfo(blockInfo);
fileBlockInfo.setUfsLocations(new ArrayList<>());
// The sequence number part of the block id is the block index.
long offset = file.getBlockSizeBytes() * BlockId.getSequenceNumber(blockInfo.getBlockId());
fileBlockInfo.setOffset(offset);
if (fileBlockInfo.getBlockInfo().getLocations().isEmpty() && file.isPersisted()) {
// No alluxio locations, but there is a checkpoint in the under storage system. Add the
// locations from the under storage system.
long blockId = fileBlockInfo.getBlockInfo().getBlockId();
List<String> locations = mUfsBlockLocationCache.get(blockId, inodePath.getUri(), fileBlockInfo.getOffset());
if (locations != null) {
fileBlockInfo.setUfsLocations(locations);
}
}
return fileBlockInfo;
}
Aggregations