Search in sources :

Example 11 with FileAlreadyExistsException

use of alluxio.exception.FileAlreadyExistsException in project alluxio by Alluxio.

the class FileSystemMaster method processJournalEntry.

@Override
public void processJournalEntry(JournalEntry entry) throws IOException {
    if (entry.hasInodeFile()) {
        mInodeTree.addInodeFileFromJournal(entry.getInodeFile());
        // Add the file to TTL buckets, the insert automatically rejects files w/ Constants.NO_TTL
        InodeFileEntry inodeFileEntry = entry.getInodeFile();
        if (inodeFileEntry.hasTtl()) {
            mTtlBuckets.insert(InodeFile.fromJournalEntry(inodeFileEntry));
        }
    } else if (entry.hasInodeDirectory()) {
        try {
            // Add the directory to TTL buckets, the insert automatically rejects directory
            // w/ Constants.NO_TTL
            InodeDirectoryEntry inodeDirectoryEntry = entry.getInodeDirectory();
            if (inodeDirectoryEntry.hasTtl()) {
                mTtlBuckets.insert(InodeDirectory.fromJournalEntry(inodeDirectoryEntry));
            }
            mInodeTree.addInodeDirectoryFromJournal(entry.getInodeDirectory());
        } catch (AccessControlException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasInodeLastModificationTime()) {
        InodeLastModificationTimeEntry modTimeEntry = entry.getInodeLastModificationTime();
        try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(modTimeEntry.getId(), InodeTree.LockMode.WRITE)) {
            inodePath.getInode().setLastModificationTimeMs(modTimeEntry.getLastModificationTimeMs(), true);
        } catch (FileDoesNotExistException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasPersistDirectory()) {
        PersistDirectoryEntry typedEntry = entry.getPersistDirectory();
        try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(typedEntry.getId(), InodeTree.LockMode.WRITE)) {
            inodePath.getInode().setPersistenceState(PersistenceState.PERSISTED);
        } catch (FileDoesNotExistException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasCompleteFile()) {
        try {
            completeFileFromEntry(entry.getCompleteFile());
        } catch (InvalidPathException | InvalidFileSizeException | FileAlreadyCompletedException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasSetAttribute()) {
        try {
            setAttributeFromEntry(entry.getSetAttribute());
        } catch (AccessControlException | FileDoesNotExistException | InvalidPathException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasDeleteFile()) {
        deleteFromEntry(entry.getDeleteFile());
    } else if (entry.hasRename()) {
        renameFromEntry(entry.getRename());
    } else if (entry.hasInodeDirectoryIdGenerator()) {
        mDirectoryIdGenerator.initFromJournalEntry(entry.getInodeDirectoryIdGenerator());
    } else if (entry.hasReinitializeFile()) {
        resetBlockFileFromEntry(entry.getReinitializeFile());
    } else if (entry.hasAddMountPoint()) {
        try {
            mountFromEntry(entry.getAddMountPoint());
        } catch (FileAlreadyExistsException | InvalidPathException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasDeleteMountPoint()) {
        try {
            unmountFromEntry(entry.getDeleteMountPoint());
        } catch (InvalidPathException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasAsyncPersistRequest()) {
        try {
            long fileId = (entry.getAsyncPersistRequest()).getFileId();
            try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(fileId, InodeTree.LockMode.WRITE)) {
                scheduleAsyncPersistenceInternal(inodePath);
            }
            // NOTE: persistence is asynchronous so there is no guarantee the path will still exist
            mAsyncPersistHandler.scheduleAsyncPersistence(getPath(fileId));
        } catch (AlluxioException e) {
            // It's possible that rescheduling the async persist calls fails, because the blocks may no
            // longer be in the memory
            LOG.error(e.getMessage());
        }
    } else {
        throw new IOException(ExceptionMessage.UNEXPECTED_JOURNAL_ENTRY.getMessage(entry));
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) InodeFileEntry(alluxio.proto.journal.File.InodeFileEntry) AccessControlException(alluxio.exception.AccessControlException) IOException(java.io.IOException) InodeLastModificationTimeEntry(alluxio.proto.journal.File.InodeLastModificationTimeEntry) PersistDirectoryEntry(alluxio.proto.journal.File.PersistDirectoryEntry) InvalidPathException(alluxio.exception.InvalidPathException) LockedInodePath(alluxio.master.file.meta.LockedInodePath) InodeDirectoryEntry(alluxio.proto.journal.File.InodeDirectoryEntry) InvalidFileSizeException(alluxio.exception.InvalidFileSizeException) FileAlreadyCompletedException(alluxio.exception.FileAlreadyCompletedException) AlluxioException(alluxio.exception.AlluxioException) UnexpectedAlluxioException(alluxio.exception.UnexpectedAlluxioException)

Example 12 with FileAlreadyExistsException

use of alluxio.exception.FileAlreadyExistsException in project alluxio by Alluxio.

the class FileSystemMaster method loadFileMetadataAndJournal.

/**
   * Loads metadata for the file identified by the given path from UFS into Alluxio.
   *
   * @param inodePath the path for which metadata should be loaded
   * @param resolution the UFS resolution of path
   * @param options the load metadata options
   * @param journalContext the journal context
   * @throws BlockInfoException if an invalid block size is encountered
   * @throws FileDoesNotExistException if there is no UFS path
   * @throws InvalidPathException if invalid path is encountered
   * @throws AccessControlException if permission checking fails or permission setting fails
   * @throws FileAlreadyCompletedException if the file is already completed
   * @throws InvalidFileSizeException if invalid file size is encountered
   * @throws IOException if an I/O error occurs
   */
private void loadFileMetadataAndJournal(LockedInodePath inodePath, MountTable.Resolution resolution, LoadMetadataOptions options, JournalContext journalContext) throws BlockInfoException, FileDoesNotExistException, InvalidPathException, AccessControlException, FileAlreadyCompletedException, InvalidFileSizeException, IOException {
    if (inodePath.fullPathExists()) {
        return;
    }
    AlluxioURI ufsUri = resolution.getUri();
    UnderFileSystem ufs = resolution.getUfs();
    long ufsBlockSizeByte = ufs.getBlockSizeByte(ufsUri.toString());
    long ufsLength = ufs.getFileSize(ufsUri.toString());
    // Metadata loaded from UFS has no TTL set.
    CreateFileOptions createFileOptions = CreateFileOptions.defaults().setBlockSizeBytes(ufsBlockSizeByte).setRecursive(options.isCreateAncestors()).setMetadataLoad(true).setPersisted(true);
    String ufsOwner = ufs.getOwner(ufsUri.toString());
    String ufsGroup = ufs.getGroup(ufsUri.toString());
    short ufsMode = ufs.getMode(ufsUri.toString());
    Mode mode = new Mode(ufsMode);
    if (resolution.getShared()) {
        mode.setOtherBits(mode.getOtherBits().or(mode.getOwnerBits()));
    }
    createFileOptions = createFileOptions.setOwner(ufsOwner).setGroup(ufsGroup).setMode(mode);
    try {
        createFileAndJournal(inodePath, createFileOptions, journalContext);
        CompleteFileOptions completeOptions = CompleteFileOptions.defaults().setUfsLength(ufsLength);
        completeFileAndJournal(inodePath, completeOptions, journalContext);
    } catch (FileAlreadyExistsException e) {
        LOG.error("FileAlreadyExistsException seen unexpectedly.", e);
        throw new RuntimeException(e);
    }
}
Also used : CreateFileOptions(alluxio.master.file.options.CreateFileOptions) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) Mode(alluxio.security.authorization.Mode) CompleteFileOptions(alluxio.master.file.options.CompleteFileOptions) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI)

Example 13 with FileAlreadyExistsException

use of alluxio.exception.FileAlreadyExistsException in project alluxio by Alluxio.

the class FileSystemMaster method start.

@Override
public void start(boolean isLeader) throws IOException {
    if (isLeader) {
        // Only initialize root when isLeader because when initializing root, BlockMaster needs to
        // write journal entry, if it is not leader, BlockMaster won't have a writable journal.
        // If it is standby, it should be able to load the inode tree from leader's checkpoint.
        mInodeTree.initializeRoot(SecurityUtils.getOwnerFromLoginModule(), SecurityUtils.getGroupFromLoginModule(), Mode.createFullAccess().applyDirectoryUMask());
        String defaultUFS = Configuration.get(PropertyKey.UNDERFS_ADDRESS);
        try {
            mMountTable.add(new AlluxioURI(MountTable.ROOT), new AlluxioURI(defaultUFS), MountOptions.defaults().setShared(UnderFileSystemUtils.isObjectStorage(defaultUFS) && Configuration.getBoolean(PropertyKey.UNDERFS_OBJECT_STORE_MOUNT_SHARED_PUBLICLY)));
        } catch (FileAlreadyExistsException | InvalidPathException e) {
            throw new IOException("Failed to mount the default UFS " + defaultUFS);
        }
    }
    // Call super.start after mInodeTree is initialized because mInodeTree is needed to write
    // a journal entry during super.start. Call super.start before calling
    // getExecutorService() because the super.start initializes the executor service.
    super.start(isLeader);
    if (isLeader) {
        mTtlCheckerService = getExecutorService().submit(new HeartbeatThread(HeartbeatContext.MASTER_TTL_CHECK, new MasterInodeTtlCheckExecutor(), Configuration.getInt(PropertyKey.MASTER_TTL_CHECKER_INTERVAL_MS)));
        mLostFilesDetectionService = getExecutorService().submit(new HeartbeatThread(HeartbeatContext.MASTER_LOST_FILES_DETECTION, new LostFilesDetectionHeartbeatExecutor(), Configuration.getInt(PropertyKey.MASTER_HEARTBEAT_INTERVAL_MS)));
        if (Configuration.getBoolean(PropertyKey.MASTER_STARTUP_CONSISTENCY_CHECK_ENABLED)) {
            mStartupConsistencyCheck = getExecutorService().submit(new Callable<List<AlluxioURI>>() {

                @Override
                public List<AlluxioURI> call() throws Exception {
                    return startupCheckConsistency(ExecutorServiceFactories.fixedThreadPoolExecutorServiceFactory("startup-consistency-check", 32).create());
                }
            });
        }
    }
}
Also used : FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) HeartbeatThread(alluxio.heartbeat.HeartbeatThread) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) Callable(java.util.concurrent.Callable) AlluxioURI(alluxio.AlluxioURI)

Example 14 with FileAlreadyExistsException

use of alluxio.exception.FileAlreadyExistsException in project alluxio by Alluxio.

the class FileSystemMaster method loadDirectoryMetadataAndJournal.

/**
   * 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 and is persisted.
   *
   * @param inodePath the path for which metadata should be loaded
   * @param options the load metadata options
   * @param journalContext the journal context
   * @throws InvalidPathException if invalid path is encountered
   * @throws IOException if an I/O error occurs
   * @throws AccessControlException if permission checking fails
   * @throws FileDoesNotExistException if the path does not exist
   */
private void loadDirectoryMetadataAndJournal(LockedInodePath inodePath, LoadMetadataOptions options, JournalContext journalContext) throws FileDoesNotExistException, InvalidPathException, AccessControlException, IOException {
    if (inodePath.fullPathExists()) {
        if (inodePath.getInode().isPersisted()) {
            return;
        }
    }
    CreateDirectoryOptions createDirectoryOptions = CreateDirectoryOptions.defaults().setMountPoint(mMountTable.isMountPoint(inodePath.getUri())).setPersisted(true).setRecursive(options.isCreateAncestors()).setMetadataLoad(true).setAllowExists(true);
    MountTable.Resolution resolution = mMountTable.resolve(inodePath.getUri());
    AlluxioURI ufsUri = resolution.getUri();
    UnderFileSystem ufs = resolution.getUfs();
    String ufsOwner = ufs.getOwner(ufsUri.toString());
    String ufsGroup = ufs.getGroup(ufsUri.toString());
    short ufsMode = ufs.getMode(ufsUri.toString());
    Mode mode = new Mode(ufsMode);
    if (resolution.getShared()) {
        mode.setOtherBits(mode.getOtherBits().or(mode.getOwnerBits()));
    }
    createDirectoryOptions = createDirectoryOptions.setOwner(ufsOwner).setGroup(ufsGroup).setMode(mode);
    try {
        createDirectoryAndJournal(inodePath, createDirectoryOptions, journalContext);
    } catch (FileAlreadyExistsException e) {
        // This should not happen.
        throw new RuntimeException(e);
    }
}
Also used : FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) CreateDirectoryOptions(alluxio.master.file.options.CreateDirectoryOptions) Mode(alluxio.security.authorization.Mode) MountTable(alluxio.master.file.meta.MountTable) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI)

Example 15 with FileAlreadyExistsException

use of alluxio.exception.FileAlreadyExistsException in project alluxio by Alluxio.

the class MountTable method add.

/**
   * Mounts the given UFS path at the given Alluxio path. The Alluxio path should not be nested
   * under an existing mount point.
   *
   * @param alluxioUri an Alluxio path URI
   * @param ufsUri a UFS path URI
   * @param options the mount options
   * @throws FileAlreadyExistsException if the mount point already exists
   * @throws InvalidPathException if an invalid path is encountered
   */
public void add(AlluxioURI alluxioUri, AlluxioURI ufsUri, MountOptions options) throws FileAlreadyExistsException, InvalidPathException {
    String alluxioPath = alluxioUri.getPath();
    LOG.info("Mounting {} at {}", ufsUri, alluxioPath);
    try (LockResource r = new LockResource(mWriteLock)) {
        if (mMountTable.containsKey(alluxioPath)) {
            throw new FileAlreadyExistsException(ExceptionMessage.MOUNT_POINT_ALREADY_EXISTS.getMessage(alluxioPath));
        }
        // or suffix of any existing mount path.
        for (Map.Entry<String, MountInfo> entry : mMountTable.entrySet()) {
            String mountedAlluxioPath = entry.getKey();
            AlluxioURI mountedUfsUri = entry.getValue().getUfsUri();
            if (!mountedAlluxioPath.equals(ROOT) && PathUtils.hasPrefix(alluxioPath, mountedAlluxioPath)) {
                throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER.getMessage(mountedAlluxioPath, alluxioPath));
            }
            if ((ufsUri.getScheme() == null || ufsUri.getScheme().equals(mountedUfsUri.getScheme())) && (ufsUri.getAuthority() == null || ufsUri.getAuthority().equals(mountedUfsUri.getAuthority()))) {
                String ufsPath = ufsUri.getPath();
                String mountedUfsPath = mountedUfsUri.getPath();
                if (PathUtils.hasPrefix(ufsPath, mountedUfsPath)) {
                    throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER.getMessage(mountedUfsUri.toString(), ufsUri.toString()));
                }
                if (PathUtils.hasPrefix(mountedUfsPath, ufsPath)) {
                    throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER.getMessage(ufsUri.toString(), mountedUfsUri.toString()));
                }
            }
        }
        mMountTable.put(alluxioPath, new MountInfo(ufsUri, options));
    }
}
Also used : FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) LockResource(alluxio.resource.LockResource) MountInfo(alluxio.master.file.meta.options.MountInfo) HashMap(java.util.HashMap) Map(java.util.Map) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Aggregations

FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)18 AlluxioURI (alluxio.AlluxioURI)14 InvalidPathException (alluxio.exception.InvalidPathException)9 Test (org.junit.Test)8 AlluxioException (alluxio.exception.AlluxioException)4 IOException (java.io.IOException)4 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)3 CreateDirectoryOptions (alluxio.master.file.options.CreateDirectoryOptions)3 CreateFileOptions (alluxio.master.file.options.CreateFileOptions)3 Mode (alluxio.security.authorization.Mode)3 UnderFileSystem (alluxio.underfs.UnderFileSystem)3 FileSystem (alluxio.client.file.FileSystem)1 CreateDirectoryOptions (alluxio.client.file.options.CreateDirectoryOptions)1 AccessControlException (alluxio.exception.AccessControlException)1 BlockInfoException (alluxio.exception.BlockInfoException)1 FileAlreadyCompletedException (alluxio.exception.FileAlreadyCompletedException)1 InvalidFileSizeException (alluxio.exception.InvalidFileSizeException)1 UnexpectedAlluxioException (alluxio.exception.UnexpectedAlluxioException)1 HeartbeatThread (alluxio.heartbeat.HeartbeatThread)1 Inode (alluxio.master.file.meta.Inode)1