Search in sources :

Example 1 with InodeView

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());
    }
}
Also used : Path(java.nio.file.Path) PrintStream(java.io.PrintStream) RocksInodeStore(alluxio.master.metastore.rocks.RocksInodeStore) InodeView(alluxio.master.file.meta.InodeView) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with InodeView

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);
}
Also used : RocksInodeStore(alluxio.master.metastore.rocks.RocksInodeStore) InodeView(alluxio.master.file.meta.InodeView) DefaultBlockMaster(alluxio.master.block.DefaultBlockMaster) ArrayList(java.util.ArrayList) HeapBlockStore(alluxio.master.metastore.heap.HeapBlockStore) DefaultFileSystemMaster(alluxio.master.file.DefaultFileSystemMaster) FileSystemMaster(alluxio.master.file.FileSystemMaster) NoopJournalSystem(alluxio.master.journal.noop.NoopJournalSystem) MutableInodeDirectory(alluxio.master.file.meta.MutableInodeDirectory) InodeDirectory(alluxio.master.file.meta.InodeDirectory) AtomicLong(java.util.concurrent.atomic.AtomicLong) DefaultFileSystemMaster(alluxio.master.file.DefaultFileSystemMaster) FileOutputStream(java.io.FileOutputStream) File(java.io.File) MutableInodeFile(alluxio.master.file.meta.MutableInodeFile) MetricsMasterFactory(alluxio.master.metrics.MetricsMasterFactory) Test(org.junit.Test)

Example 3 with InodeView

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);
}
Also used : InodeView(alluxio.master.file.meta.InodeView) AccessControlException(alluxio.exception.AccessControlException)

Example 4 with InodeView

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();
}
Also used : InodeView(alluxio.master.file.meta.InodeView) AccessControlException(alluxio.exception.AccessControlException)

Aggregations

InodeView (alluxio.master.file.meta.InodeView)4 AccessControlException (alluxio.exception.AccessControlException)2 RocksInodeStore (alluxio.master.metastore.rocks.RocksInodeStore)2 FileOutputStream (java.io.FileOutputStream)2 DefaultBlockMaster (alluxio.master.block.DefaultBlockMaster)1 DefaultFileSystemMaster (alluxio.master.file.DefaultFileSystemMaster)1 FileSystemMaster (alluxio.master.file.FileSystemMaster)1 InodeDirectory (alluxio.master.file.meta.InodeDirectory)1 MutableInodeDirectory (alluxio.master.file.meta.MutableInodeDirectory)1 MutableInodeFile (alluxio.master.file.meta.MutableInodeFile)1 NoopJournalSystem (alluxio.master.journal.noop.NoopJournalSystem)1 HeapBlockStore (alluxio.master.metastore.heap.HeapBlockStore)1 MetricsMasterFactory (alluxio.master.metrics.MetricsMasterFactory)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 PrintStream (java.io.PrintStream)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Test (org.junit.Test)1