配置 Alluxio Master 主机地址:
Configuration.set(PropertyKey.MASTER_HOSTNAME, "alluxio_master");
配置用户:
Configuration.set(PropertyKey.SECURITY_LOGIN_USERNAME, "alluxio");
默认会使用当前用户,如果当前用户没有权限,则会抛出异常 alluxio.exception.status.PermissionDeniedException: Permission denied
FileSystem fs = FileSystem.Factory.get();
try (FileOutStream out = fs.createFile(new AlluxioURI("/tmp/test"))) {
out.write("it works!".getBytes("utf-8"));
} catch (AlluxioException | IOException e) {
// do something
}
在创建文件时,可以对写操作进行配置:
CreateFileOptions createFileOptions = CreateFileOptions.defaults()
.setWriteType(WriteType.MUST_CACHE);
try (FileOutStream out = fs.createFile(new AlluxioURI("/tmp/test"), createFileOptions)) {
} catch (AlluxioException | IOException e) {
// do something
}
WriteType 选项:
try (FileInStream in = fs.openFile(new AlluxioURI("/tmp/test"))) {
String content = IOUtils.toString(in, "utf-8");
System.out.println(content);
} catch (AlluxioException | IOException e) {
// do something
}
在打开文件时,可以对读操作进行配置:
OpenFileOptions openFileOptions = OpenFileOptions.defaults().setReadType(ReadType.CACHE);
try (FileInStream in = fs.openFile(new AlluxioURI("/tmp/test"), openFileOptions)) {
} catch (AlluxioException | IOException e) {
// do something
}
ReadType 选项:
alluxio.user.file.cache.partially.read.block
设置为 true,没有完全读取的数据块也会被 全部
存到 Alluxio 内。 相反,一个数据块只有完全被读取时,才能被缓存。 alluxio.user.file.cache.partially.read.block
设置为 true,没有完全读取的数据块也会被 全部
存到 Alluxio 内。 相反,一个数据块只有完全被读取时,才能被缓存。