use of alluxio.master.file.meta.InodeView in project alluxio by Alluxio.
the class AbstractJournalDumper method readRocksCheckpoint.
private void readRocksCheckpoint(CheckpointInputStream checkpoint, Path path) throws IOException {
// An empty dir for storing the db.
Path dbPath = Paths.get(path.toFile().getPath() + "-rocks-db");
// Create RocksInodeStore over checkpoint stream for extracting the inodes.
try (PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(path.toFile())));
RocksInodeStore inodeStore = new RocksInodeStore(dbPath.toAbsolutePath().toString())) {
// Create and restore RocksInodeStore from the checkpoint.
inodeStore.restoreFromCheckpoint(checkpoint);
// Dump entries.
final String ENTRY_SEPARATOR = Strings.repeat("-", 80);
try (CloseableIterator<InodeView> iterator = inodeStore.getCloseableIterator()) {
for (; iterator.hasNext(); ) {
InodeView inode = iterator.next();
out.println(ENTRY_SEPARATOR);
out.println(inode.toProto());
}
}
} finally {
// Remove the temp db directory.
FileUtils.deletePathRecursively(dbPath.toFile().getPath());
}
}
use of alluxio.master.file.meta.InodeView in project alluxio by Alluxio.
the class BackupManagerTest method rocksInodeStoreIteratorNotUsed.
@Test
public void rocksInodeStoreIteratorNotUsed() throws Exception {
// Prepare some data for the iterator
List<InodeView> inodes = new ArrayList<>();
inodes.add(createRootDir(99L));
inodes.add(createNewFile(100L));
inodes.add(createNewFile(101L));
inodes.add(createNewFile(102L));
// When RocksInodeStore.iterator(), return mock iterator
RocksInodeStore mockInodeStore = mock(RocksInodeStore.class);
// Make sure the iterator is not used in the backup operation
when(mockInodeStore.getCloseableIterator()).thenThrow(new UnsupportedOperationException());
// When the root inode is asked for, return the directory
InodeView dir = inodes.get(0);
when(mockInodeStore.get(eq(0L))).thenReturn(Optional.of(new InodeDirectory((InodeDirectoryView) dir)));
CoreMasterContext masterContext = MasterTestUtils.testMasterContext(new NoopJournalSystem(), null, () -> new HeapBlockStore(), x -> mockInodeStore);
mMetricsMaster = new MetricsMasterFactory().create(mRegistry, masterContext);
mBlockMaster = new DefaultBlockMaster(mMetricsMaster, masterContext, mClock, ExecutorServiceFactories.constantExecutorServiceFactory(mExecutorService));
mRegistry.add(BlockMaster.class, mBlockMaster);
// Prepare the FileSystemMaster for the backup operation
FileSystemMaster fsMaster = new DefaultFileSystemMaster(mBlockMaster, masterContext, ExecutorServiceFactories.constantExecutorServiceFactory(mExecutorService));
mRegistry.add(FileSystemMaster.class, fsMaster);
mRegistry.start(true);
// Finish backup operation
BackupManager manager = new BackupManager(mRegistry);
File backupDir = AlluxioTestDirectory.createTemporaryDirectory("backup-dir");
File backupFile = new File(backupDir, "1.backup");
AtomicLong counter = new AtomicLong(0L);
// No exception means the RocksInodeStore iterator is not used
manager.backup(new FileOutputStream(backupFile), counter);
}
use of alluxio.master.file.meta.InodeView in project alluxio by Alluxio.
the class DefaultPermissionChecker method checkInodeList.
/**
* This method provides basic permission checking logic on a list of inodes. The input includes
* user and its group, requested action and inode list (by traversing the path). Then user,
* group, and the requested action will be evaluated on each of the inodes. It will return if
* check passed, and throw exception if check failed.
*
* @param user who requests access permission
* @param groups in which user belongs to
* @param bits bits that capture the action {@link Mode.Bits} by user
* @param path the path to check permission on
* @param inodeList file info list of all the inodes retrieved by traversing the path
* @param checkIsOwner indicates whether to check the user is the owner of the path
* @throws AccessControlException if permission checking fails
*/
protected void checkInodeList(String user, List<String> groups, Mode.Bits bits, String path, List<InodeView> inodeList, boolean checkIsOwner) throws AccessControlException {
int size = inodeList.size();
Preconditions.checkArgument(size > 0, PreconditionMessage.EMPTY_FILE_INFO_LIST_FOR_PERMISSION_CHECK);
// bypass checking permission for super user or super group of Alluxio file system.
if (isPrivilegedUser(user, groups)) {
return;
}
// traverses from root to the parent dir to all inodes included by this path are executable
for (int i = 0; i < size - 1; i++) {
checkInode(user, groups, inodeList.get(i), Mode.Bits.EXECUTE, path);
}
InodeView inode = inodeList.get(inodeList.size() - 1);
if (checkIsOwner) {
if (inode == null || user.equals(inode.getOwner())) {
return;
}
throw new AccessControlException(ExceptionMessage.PERMISSION_DENIED.getMessage("user=" + user + " is not the owner of path=" + path));
}
checkInode(user, groups, inode, bits, path);
}
use of alluxio.master.file.meta.InodeView in project alluxio by Alluxio.
the class DefaultPermissionChecker method getPermissionInternal.
/**
* Gets the permission to access an inode path given a user and its groups.
*
* @param user the user
* @param groups the groups this user belongs to
* @param path the inode path
* @param inodeList the list of inodes in the path
* @return the permission
*/
private Mode.Bits getPermissionInternal(String user, List<String> groups, String path, List<InodeView> inodeList) {
int size = inodeList.size();
Preconditions.checkArgument(size > 0, PreconditionMessage.EMPTY_FILE_INFO_LIST_FOR_PERMISSION_CHECK);
// bypass checking permission for super user or super group of Alluxio file system.
if (isPrivilegedUser(user, groups)) {
return Mode.Bits.ALL;
}
// traverses from root to the parent dir to all inodes included by this path are executable
for (int i = 0; i < size - 1; i++) {
try {
checkInode(user, groups, inodeList.get(i), Mode.Bits.EXECUTE, path);
} catch (AccessControlException e) {
return Mode.Bits.NONE;
}
}
InodeView inode = inodeList.get(inodeList.size() - 1);
if (inode == null) {
return Mode.Bits.NONE;
}
return inode.getPermission(user, groups).toModeBits();
}
Aggregations