use of alluxio.master.file.contexts.CreateDirectoryContext in project alluxio by Alluxio.
the class InodeSyncStream method loadDirectoryMetadata.
/**
* Loads metadata for the directory identified by the given path from UFS into Alluxio. This does
* not actually require looking at the UFS path.
* It is a no-op if the directory exists.
*
* 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 if necessary.
*
* @param rpcContext the rpc context
* @param inodePath the path for which metadata should be loaded
* @param context the load metadata context
*/
static void loadDirectoryMetadata(RpcContext rpcContext, LockedInodePath inodePath, LoadMetadataContext context, MountTable mountTable, DefaultFileSystemMaster fsMaster) throws FileDoesNotExistException, InvalidPathException, AccessControlException, IOException {
if (inodePath.fullPathExists()) {
return;
}
CreateDirectoryContext createDirectoryContext = CreateDirectoryContext.defaults();
createDirectoryContext.getOptions().setRecursive(context.getOptions().getCreateAncestors()).setAllowExists(false).setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(context.getOptions().getCommonOptions().getTtl()).setTtlAction(context.getOptions().getCommonOptions().getTtlAction()));
createDirectoryContext.setMountPoint(mountTable.isMountPoint(inodePath.getUri()));
createDirectoryContext.setMetadataLoad(true);
createDirectoryContext.setWriteType(WriteType.THROUGH);
MountTable.Resolution resolution = mountTable.resolve(inodePath.getUri());
AlluxioURI ufsUri = resolution.getUri();
AccessControlList acl = null;
DefaultAccessControlList defaultAcl = null;
try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
UnderFileSystem ufs = ufsResource.get();
if (context.getUfsStatus() == null) {
context.setUfsStatus(ufs.getExistingDirectoryStatus(ufsUri.toString()));
}
Pair<AccessControlList, DefaultAccessControlList> aclPair = ufs.getAclPair(ufsUri.toString());
if (aclPair != null) {
acl = aclPair.getFirst();
defaultAcl = aclPair.getSecond();
}
}
String ufsOwner = context.getUfsStatus().getOwner();
String ufsGroup = context.getUfsStatus().getGroup();
short ufsMode = context.getUfsStatus().getMode();
Long lastModifiedTime = context.getUfsStatus().getLastModifiedTime();
Mode mode = new Mode(ufsMode);
if (resolution.getShared()) {
mode.setOtherBits(mode.getOtherBits().or(mode.getOwnerBits()));
}
createDirectoryContext.getOptions().setMode(mode.toProto());
createDirectoryContext.setOwner(ufsOwner).setGroup(ufsGroup).setUfsStatus(context.getUfsStatus());
createDirectoryContext.setXAttr(context.getUfsStatus().getXAttr());
if (acl != null) {
createDirectoryContext.setAcl(acl.getEntries());
}
if (defaultAcl != null) {
createDirectoryContext.setDefaultAcl(defaultAcl.getEntries());
}
if (lastModifiedTime != null) {
createDirectoryContext.setOperationTimeMs(lastModifiedTime);
}
try (LockedInodePath writeLockedPath = inodePath.lockFinalEdgeWrite()) {
fsMaster.createDirectoryInternal(rpcContext, writeLockedPath, createDirectoryContext);
} catch (FileAlreadyExistsException e) {
// This may occur if a thread created or loaded the directory before we got the write lock.
// The directory already exists, so nothing needs to be loaded.
}
// Re-traverse the path to pick up any newly created inodes.
inodePath.traverse();
}
use of alluxio.master.file.contexts.CreateDirectoryContext in project alluxio by Alluxio.
the class FileSystemMasterIntegrationTest method renameToDeeper.
@Test
public void renameToDeeper() throws Exception {
CreateFileContext createFileOptions = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setRecursive(true));
CreateDirectoryContext createDirectoryContext = CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true));
mThrown.expect(InvalidPathException.class);
mFsMaster.createDirectory(new AlluxioURI("/testDir1/testDir2"), createDirectoryContext);
mFsMaster.createFile(new AlluxioURI("/testDir1/testDir2/testDir3/testFile3"), createFileOptions);
mFsMaster.rename(new AlluxioURI("/testDir1/testDir2"), new AlluxioURI("/testDir1/testDir2/testDir3/testDir4"), RenameContext.defaults());
}
use of alluxio.master.file.contexts.CreateDirectoryContext in project alluxio by Alluxio.
the class InodeStoreBench method writeInode.
private static void writeInode() {
int id = NEXT_INODE_ID.getAndIncrement();
CreateDirectoryContext createContext = CreateDirectoryContext.defaults();
MutableInodeDirectory dir = MutableInodeDirectory.create(id, 0, CommonUtils.randomAlphaNumString(30), createContext);
sStore.writeInode(dir);
}
use of alluxio.master.file.contexts.CreateDirectoryContext in project alluxio by Alluxio.
the class FileSystemMasterTest method setTtlForDirectoryWithNoTtl.
/**
* Tests that an exception is thrown when trying to get information about a Directory after
* it has been deleted because of a TTL of 0.
*/
@Test
public void setTtlForDirectoryWithNoTtl() throws Exception {
CreateDirectoryContext directoryContext = CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true));
mFileSystemMaster.createDirectory(NESTED_URI, directoryContext);
mFileSystemMaster.createDirectory(NESTED_DIR_URI, directoryContext);
CreateFileContext createFileContext = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB).setRecursive(true));
long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, createFileContext).getFileId();
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
// Since no TTL is set, the file should not be deleted.
assertEquals(fileId, mFileSystemMaster.getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT).getFileId());
// Set ttl.
mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(0))));
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
// TTL is set to 0, the file and directory should have been deleted during last TTL check.
mThrown.expect(FileDoesNotExistException.class);
mFileSystemMaster.getFileInfo(NESTED_URI, GET_STATUS_CONTEXT);
mFileSystemMaster.getFileInfo(NESTED_DIR_URI, GET_STATUS_CONTEXT);
mFileSystemMaster.getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT);
}
use of alluxio.master.file.contexts.CreateDirectoryContext in project alluxio by Alluxio.
the class FileSystemMasterTest method ttlDirectoryFreeReplay.
/**
* Tests that TTL free of a directory is not forgotten across restarts.
*/
@Test
public void ttlDirectoryFreeReplay() throws Exception {
CreateDirectoryContext directoryContext = CreateDirectoryContext.mergeFrom(CreateDirectoryPOptions.newBuilder().setRecursive(true));
mFileSystemMaster.createDirectory(NESTED_URI, directoryContext);
long blockId = createFileWithSingleBlock(NESTED_FILE_URI);
assertEquals(1, mBlockMaster.getBlockInfo(blockId).getLocations().size());
// Set ttl & operation.
mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeContext.mergeFrom(SetAttributePOptions.newBuilder().setCommonOptions(FileSystemOptions.commonDefaults(ServerConfiguration.global()).toBuilder().setTtl(0).setTtlAction(alluxio.grpc.TtlAction.FREE))));
// Simulate restart.
stopServices();
startServices();
Command heartbeat = mBlockMaster.workerHeartbeat(mWorkerId1, null, ImmutableMap.of(Constants.MEDIUM_MEM, (long) Constants.KB), ImmutableList.of(blockId), ImmutableMap.of(), ImmutableMap.of(), mMetrics);
// Verify the muted Free command on worker1.
assertEquals(Command.newBuilder().setCommandType(CommandType.Nothing).build(), heartbeat);
assertEquals(0, mBlockMaster.getBlockInfo(blockId).getLocations().size());
}
Aggregations