use of alluxio.grpc.OpenFilePOptions in project alluxio by Alluxio.
the class JobUtils method loadThroughCacheRequest.
private static void loadThroughCacheRequest(URIStatus status, FileSystemContext context, long blockId, AlluxioConfiguration conf, WorkerNetAddress localNetAddress) throws IOException {
AlluxioBlockStore blockStore = AlluxioBlockStore.create(context);
OpenFilePOptions openOptions = OpenFilePOptions.newBuilder().setReadType(ReadPType.CACHE).build();
InStreamOptions inOptions = new InStreamOptions(status, openOptions, conf);
BlockLocationPolicy policy = BlockLocationPolicy.Factory.create(LocalFirstPolicy.class.getCanonicalName(), conf);
inOptions.setUfsReadLocationPolicy(policy);
Protocol.OpenUfsBlockOptions openUfsBlockOptions = inOptions.getOpenUfsBlockOptions(blockId);
BlockInfo info = Preconditions.checkNotNull(status.getBlockInfo(blockId));
long blockLength = info.getLength();
Pair<WorkerNetAddress, BlockInStream.BlockInStreamSource> dataSourceAndType = blockStore.getDataSourceAndType(status.getBlockInfo(blockId), status, policy, ImmutableMap.of());
WorkerNetAddress dataSource = dataSourceAndType.getFirst();
String host = dataSource.getHost();
// to establish the connection.
if (!dataSource.getContainerHost().equals("")) {
host = dataSource.getContainerHost();
}
CacheRequest request = CacheRequest.newBuilder().setBlockId(blockId).setLength(blockLength).setOpenUfsBlockOptions(openUfsBlockOptions).setSourceHost(host).setSourcePort(dataSource.getDataPort()).build();
try (CloseableResource<BlockWorkerClient> blockWorker = context.acquireBlockWorkerClient(localNetAddress)) {
blockWorker.get().cache(request);
} catch (Exception e) {
throw new IOException(e);
}
}
use of alluxio.grpc.OpenFilePOptions in project alluxio by Alluxio.
the class TieredStoreIntegrationTest method deleteWhileRead.
/**
* Tests that deletes go through despite failing initially due to concurrent read.
*/
@Test
public void deleteWhileRead() throws Exception {
// Small enough not to trigger async eviction
int fileSize = MEM_CAPACITY_BYTES / 2;
AlluxioURI file = new AlluxioURI("/test1");
FileSystemTestUtils.createByteFile(mFileSystem, file, WritePType.MUST_CACHE, fileSize);
CommonUtils.waitFor("file in memory", () -> {
try {
return 100 == mFileSystem.getStatus(file).getInAlluxioPercentage();
} catch (Exception e) {
return false;
}
}, WAIT_OPTIONS);
// Open the file
OpenFilePOptions options = OpenFilePOptions.newBuilder().setReadType(ReadPType.CACHE).build();
FileInStream in = mFileSystem.openFile(file, options);
Assert.assertEquals(0, in.read());
// Delete the file
mFileSystem.delete(file);
// After the delete, the master should no longer serve the file
Assert.assertFalse(mFileSystem.exists(file));
// However, the previous read should still be able to read it as the data still exists
byte[] res = new byte[fileSize];
Assert.assertEquals(fileSize - 1, in.read(res, 1, fileSize - 1));
res[0] = 0;
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(fileSize, res));
in.close();
CommonUtils.waitFor("file blocks are deleted", () -> 0 == mBlockMaster.getUsedBytes(), WAIT_OPTIONS);
// After the file is closed, the master's delete should go through and new files can be created
AlluxioURI newFile = new AlluxioURI("/test2");
FileSystemTestUtils.createByteFile(mFileSystem, newFile, WritePType.MUST_CACHE, MEM_CAPACITY_BYTES);
Assert.assertEquals(100, mFileSystem.getStatus(newFile).getInAlluxioPercentage());
}
Aggregations