/** * Prepares the destination file path of the given file id. Also creates the parent folder if it * does not exist. * * @param fileInfo the file info * @param ufs the {@link UnderFileSystem} instance * @return the path for persistence */ private String prepareUfsFilePath(FileInfo fileInfo, UnderFileSystem ufs) throws AlluxioException, IOException { AlluxioURI alluxioPath = new AlluxioURI(fileInfo.getPath()); FileSystem fs = mFileSystemFactory.get(); URIStatus status = fs.getStatus(alluxioPath); String ufsPath = status.getUfsPath(); UnderFileSystemUtils.prepareFilePath(alluxioPath, ufsPath, fs, ufs); return ufsPath; }
/** * @param blockId id of the block * @return a {@link Protocol.OpenUfsBlockOptions} based on the block id and options */ public Protocol.OpenUfsBlockOptions getOpenUfsBlockOptions(long blockId) { Preconditions.checkArgument(mStatus.getBlockIds().contains(blockId), "blockId"); boolean readFromUfs = mStatus.isPersisted(); // In case it is possible to fallback to read UFS blocks, also fill in the options. boolean storedAsUfsBlock = mStatus.getPersistenceState().equals("TO_BE_PERSISTED"); readFromUfs = readFromUfs || storedAsUfsBlock; if (!readFromUfs) { return Protocol.OpenUfsBlockOptions.getDefaultInstance(); } long blockStart = BlockId.getSequenceNumber(blockId) * mStatus.getBlockSizeBytes(); BlockInfo info = getBlockInfo(blockId); Protocol.OpenUfsBlockOptions openUfsBlockOptions = Protocol.OpenUfsBlockOptions.newBuilder() .setUfsPath(mStatus.getUfsPath()).setOffsetInFile(blockStart).setBlockSize(info.getLength()) .setMaxUfsReadConcurrency(mProtoOptions.getMaxUfsReadConcurrency()) .setNoCache(!ReadType.fromProto(mProtoOptions.getReadType()).isCache()) .setMountId(mStatus.getMountId()).build(); if (storedAsUfsBlock) { // On client-side, we do not have enough mount information to fill in the UFS file path. // Instead, we unset the ufsPath field and fill in a flag ufsBlock to indicate the UFS file // path can be derived from mount id and the block ID. Also because the entire file is only // one block, we set the offset in file to be zero. openUfsBlockOptions = openUfsBlockOptions.toBuilder().clearUfsPath().setBlockInUfsTier(true) .setOffsetInFile(0).build(); } return openUfsBlockOptions; }
outStreamOptions.setUfsPath(status.getUfsPath()); outStreamOptions.setMountId(status.getMountId()); outStreamOptions.setAcl(status.getAcl());
Assert.assertEquals(uriStatus.getTtl(), fileInfo.getTtl()); Assert.assertEquals(uriStatus.getTtlAction(), fileInfo.getTtlAction()); Assert.assertEquals(uriStatus.getUfsPath(), fileInfo.getUfsPath()); Assert.assertEquals(uriStatus.getOwner(), fileInfo.getOwner()); Assert.assertEquals(uriStatus.isCacheable(), fileInfo.isCacheable());
private void updateUfsPath() throws IOException { FileSystemMasterClient client = mContext.acquireMasterClient(); try { URIStatus status = client.getStatus(mUri); mUfsPath = status.getUfsPath(); } catch (AlluxioException e) { throw new IOException(e); } finally { mContext.releaseMasterClient(client); } }
try { mFileInfo = fs.getStatus(uri); mHdfsPath = new Path(mFileInfo.getUfsPath()); mAlluxioFileInputStream = fs.openFile(uri, OpenFileOptions.defaults().setReadType(ReadType.CACHE));
new UnderStoreBlockInStream(blockStart, mBlockSize, mStatus.getUfsPath()); mShouldCacheCurrentBlock = mAlluxioStorageType.isStore();
OpenFileOptions options = OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE); FileInStream in = closer.register(fs.openFile(uri, options)); AlluxioURI dstPath = new AlluxioURI(status.getUfsPath()); UnderFileSystem ufs = UnderFileSystem.get(dstPath.toString(), conf); String parentPath = dstPath.getParent().toString();