Search in sources :

Example 16 with FileAlreadyExistsException

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

the class KeyValueMaster method renameStore.

/**
   * Renames one completed key-value store.
   *
   * @param oldUri the old {@link AlluxioURI} to the store
   * @param newUri the {@link AlluxioURI} to the store
   * @throws IOException if non-Alluxio error occurs
   * @throws AlluxioException if other Alluxio error occurs
   */
public synchronized void renameStore(AlluxioURI oldUri, AlluxioURI newUri) throws IOException, AlluxioException {
    long oldFileId = getFileId(oldUri);
    checkIsCompletePartition(oldFileId, oldUri);
    try {
        mFileSystemMaster.rename(oldUri, newUri, RenameOptions.defaults());
    } catch (FileAlreadyExistsException e) {
        throw new FileAlreadyExistsException(String.format("failed to rename store:the path %s has been used", newUri), e);
    }
    final long newFileId = mFileSystemMaster.getFileId(newUri);
    Preconditions.checkState(newFileId != IdUtils.INVALID_FILE_ID);
    renameStoreInternal(oldFileId, newFileId);
    writeJournalEntry(newRenameStoreEntry(oldFileId, newFileId));
    flushJournal();
}
Also used : FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException)

Example 17 with FileAlreadyExistsException

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

the class AlluxioFuseFileSystem method create.

/**
   * Creates and opens a new file.
   *
   * @param path The FS path of the file to open
   * @param mode mode flags
   * @param fi FileInfo data struct kept by FUSE
   * @return 0 on success. A negative value on error
   */
@Override
public int create(String path, @mode_t long mode, FuseFileInfo fi) {
    // mode is ignored in alluxio-fuse
    final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
    // (see {@code man 2 open} for the structure of the flags bitfield)
    // File creation flags are the last two bits of flags
    final int flags = fi.flags.get();
    LOG.trace("create({}, {}) [Alluxio: {}]", path, Integer.toHexString(flags), turi);
    final int openFlag = flags & 3;
    if (openFlag != O_WRONLY.intValue()) {
        OpenFlags flag = OpenFlags.valueOf(openFlag);
        LOG.error("Passed a {} flag to create(). Files can only be created in O_WRONLY mode ({})", flag.toString(), path);
        return -ErrorCodes.EACCES();
    }
    try {
        synchronized (mOpenFiles) {
            if (mOpenFiles.size() >= MAX_OPEN_FILES) {
                LOG.error("Cannot open {}: too many open files (MAX_OPEN_FILES: {})", turi, MAX_OPEN_FILES);
                return -ErrorCodes.EMFILE();
            }
            final OpenFileEntry ofe = new OpenFileEntry(null, mFileSystem.createFile(turi));
            LOG.debug("Alluxio OutStream created for {}", path);
            mOpenFiles.put(mNextOpenFileId, ofe);
            fi.fh.set(mNextOpenFileId);
            // Assuming I will never wrap around (2^64 open files are quite a lot anyway)
            mNextOpenFileId += 1;
        }
        LOG.debug("{} created and opened in O_WRONLY mode", path);
    } catch (FileAlreadyExistsException e) {
        LOG.debug("File {} already exists", turi, e);
        return -ErrorCodes.EEXIST();
    } catch (IOException e) {
        LOG.error("IOException on {}", path, e);
        return -ErrorCodes.EIO();
    } catch (AlluxioException e) {
        LOG.error("AlluxioException on {}", path, e);
        return -ErrorCodes.EFAULT();
    } catch (Throwable e) {
        LOG.error("Unexpected exception on {}", path, e);
        return -ErrorCodes.EFAULT();
    }
    return 0;
}
Also used : FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) OpenFlags(jnr.constants.platform.OpenFlags) IOException(java.io.IOException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 18 with FileAlreadyExistsException

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

the class AlluxioFuseFileSystem method mkdir.

/**
   * Creates a new dir.
   *
   * @param path the path on the FS of the new dir
   * @param mode Dir creation flags (IGNORED)
   * @return 0 on success, a negative value on error
   */
@Override
public int mkdir(String path, @mode_t long mode) {
    final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
    LOG.trace("mkdir({}) [Alluxio: {}]", path, turi);
    try {
        mFileSystem.createDirectory(turi);
    } catch (FileAlreadyExistsException e) {
        LOG.debug("Cannot make dir. {} already exists", path, e);
        return -ErrorCodes.EEXIST();
    } catch (InvalidPathException e) {
        LOG.debug("Cannot make dir. Invalid path: {}", path, e);
        return -ErrorCodes.ENOENT();
    } catch (IOException e) {
        LOG.error("Cannot make dir. IOException: {}", path, e);
        return -ErrorCodes.EIO();
    } catch (AlluxioException e) {
        LOG.error("Cannot make dir. {}", path, e);
        return -ErrorCodes.EFAULT();
    } catch (Throwable e) {
        LOG.error("Unexpected exception on {}", path, e);
        return -ErrorCodes.EFAULT();
    }
    return 0;
}
Also used : FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

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