use of alluxio.master.journal.MergeJournalContext in project alluxio by Alluxio.
the class InodeSyncStream method loadFileMetadataInternal.
/**
* Loads metadata for the file identified by the given path from UFS into Alluxio.
*
* This method doesn't require any specific type of locking on inodePath. If the path needs to be
* loaded, we will acquire a write-edge lock.
*
* @param rpcContext the rpc context
* @param inodePath the path for which metadata should be loaded
* @param resolution the UFS resolution of path
* @param context the load metadata context
*/
static void loadFileMetadataInternal(RpcContext rpcContext, LockedInodePath inodePath, MountTable.Resolution resolution, LoadMetadataContext context, DefaultFileSystemMaster fsMaster) throws BlockInfoException, FileDoesNotExistException, InvalidPathException, FileAlreadyCompletedException, InvalidFileSizeException, IOException {
if (inodePath.fullPathExists()) {
return;
}
AlluxioURI ufsUri = resolution.getUri();
long ufsBlockSizeByte;
long ufsLength;
AccessControlList acl = null;
try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
UnderFileSystem ufs = ufsResource.get();
if (context.getUfsStatus() == null) {
context.setUfsStatus(ufs.getExistingFileStatus(ufsUri.toString()));
}
ufsLength = ((UfsFileStatus) context.getUfsStatus()).getContentLength();
long blockSize = ((UfsFileStatus) context.getUfsStatus()).getBlockSize();
ufsBlockSizeByte = blockSize != UfsFileStatus.UNKNOWN_BLOCK_SIZE ? blockSize : ufs.getBlockSizeByte(ufsUri.toString());
if (fsMaster.isAclEnabled()) {
Pair<AccessControlList, DefaultAccessControlList> aclPair = ufs.getAclPair(ufsUri.toString());
if (aclPair != null) {
acl = aclPair.getFirst();
// DefaultACL should be null, because it is a file
if (aclPair.getSecond() != null) {
LOG.warn("File {} has default ACL in the UFS", inodePath.getUri());
}
}
}
}
// Metadata loaded from UFS has no TTL set.
CreateFileContext createFileContext = CreateFileContext.defaults();
createFileContext.getOptions().setBlockSizeBytes(ufsBlockSizeByte);
createFileContext.getOptions().setRecursive(context.getOptions().getCreateAncestors());
createFileContext.getOptions().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(context.getOptions().getCommonOptions().getTtl()).setTtlAction(context.getOptions().getCommonOptions().getTtlAction()));
// set as through since already in UFS
createFileContext.setWriteType(WriteType.THROUGH);
createFileContext.setMetadataLoad(true);
createFileContext.setOwner(context.getUfsStatus().getOwner());
createFileContext.setGroup(context.getUfsStatus().getGroup());
createFileContext.setXAttr(context.getUfsStatus().getXAttr());
short ufsMode = context.getUfsStatus().getMode();
Mode mode = new Mode(ufsMode);
Long ufsLastModified = context.getUfsStatus().getLastModifiedTime();
if (resolution.getShared()) {
mode.setOtherBits(mode.getOtherBits().or(mode.getOwnerBits()));
}
createFileContext.getOptions().setMode(mode.toProto());
if (acl != null) {
createFileContext.setAcl(acl.getEntries());
}
if (ufsLastModified != null) {
createFileContext.setOperationTimeMs(ufsLastModified);
}
try (LockedInodePath writeLockedPath = inodePath.lockFinalEdgeWrite();
MergeJournalContext merger = new MergeJournalContext(rpcContext.getJournalContext(), writeLockedPath.getUri(), InodeSyncStream::mergeCreateComplete)) {
// We do not want to close this wrapRpcContext because it uses elements from another context
RpcContext wrapRpcContext = new RpcContext(rpcContext.getBlockDeletionContext(), merger, rpcContext.getOperationContext());
fsMaster.createFileInternal(wrapRpcContext, writeLockedPath, createFileContext);
CompleteFileContext completeContext = CompleteFileContext.mergeFrom(CompleteFilePOptions.newBuilder().setUfsLength(ufsLength)).setUfsStatus(context.getUfsStatus());
if (ufsLastModified != null) {
completeContext.setOperationTimeMs(ufsLastModified);
}
fsMaster.completeFileInternal(wrapRpcContext, writeLockedPath, completeContext);
} catch (FileAlreadyExistsException e) {
// This may occur if a thread created or loaded the file before we got the write lock.
// The file already exists, so nothing needs to be loaded.
LOG.debug("Failed to load file metadata: {}", e.toString());
}
// Re-traverse the path to pick up any newly created inodes.
inodePath.traverse();
}
Aggregations