Search in sources :

Example 26 with FileDoesNotExistException

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

the class AlluxioFuseFileSystem method open.

/**
   * Opens an existing file for reading.
   *
   * Note that the open mode <i>must</i> be
   * O_RDONLY, otherwise the open will fail. This is due to
   * the Alluxio "write-once/read-many-times" file model.
   *
   * @param path the FS path of the file to open
   * @param fi FileInfo data structure kept by FUSE
   * @return 0 on success, a negative value on error
   */
@Override
public int open(String path, FuseFileInfo fi) {
    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("open({}, 0x{}) [Alluxio: {}]", path, Integer.toHexString(flags), turi);
    if ((flags & 3) != O_RDONLY.intValue()) {
        LOG.error("Files can only be opened in O_RDONLY mode ({})", path);
        return -ErrorCodes.EACCES();
    }
    try {
        if (!mFileSystem.exists(turi)) {
            LOG.error("File {} does not exist", turi);
            return -ErrorCodes.ENOENT();
        }
        final URIStatus status = mFileSystem.getStatus(turi);
        if (status.isFolder()) {
            LOG.error("File {} is a directory", turi);
            return -ErrorCodes.EISDIR();
        }
        synchronized (mOpenFiles) {
            if (mOpenFiles.size() == MAX_OPEN_FILES) {
                LOG.error("Cannot open {}: too many open files", turi);
                return ErrorCodes.EMFILE();
            }
            final OpenFileEntry ofe = new OpenFileEntry(mFileSystem.openFile(turi), null);
            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;
        }
    } catch (FileDoesNotExistException e) {
        LOG.debug("File does not exist {}", path, e);
        return -ErrorCodes.ENOENT();
    } 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 : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 27 with FileDoesNotExistException

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

the class KeyValueMaster method createStore.

/**
   * Creates a new key-value store.
   *
   * @param path URI of the key-value store
   * @throws FileAlreadyExistsException if a key-value store URI exists
   * @throws InvalidPathException if the given path is invalid
   * @throws AccessControlException if permission checking fails
   */
public synchronized void createStore(AlluxioURI path) throws FileAlreadyExistsException, InvalidPathException, AccessControlException {
    try {
        // Create this dir
        mFileSystemMaster.createDirectory(path, CreateDirectoryOptions.defaults().setRecursive(true));
    } catch (IOException e) {
        // TODO(binfan): Investigate why {@link mFileSystemMaster.createDirectory} throws IOException
        throw new InvalidPathException(String.format("Failed to createStore: can not create path %s", path), e);
    } catch (FileDoesNotExistException e) {
        // This should be impossible since we pass the recursive option into mkdir
        throw Throwables.propagate(e);
    }
    long fileId = mFileSystemMaster.getFileId(path);
    Preconditions.checkState(fileId != IdUtils.INVALID_FILE_ID);
    createStoreInternal(fileId);
    writeJournalEntry(newCreateStoreEntry(fileId));
    flushJournal();
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException)

Example 28 with FileDoesNotExistException

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

the class FreeAndDeleteIntegrationTest method freeAndDeleteIntegration.

@Test
public void freeAndDeleteIntegration() throws Exception {
    HeartbeatScheduler.await(HeartbeatContext.WORKER_BLOCK_SYNC, 5, TimeUnit.SECONDS);
    HeartbeatScheduler.await(HeartbeatContext.MASTER_LOST_FILES_DETECTION, 5, TimeUnit.SECONDS);
    AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath());
    FileOutStream os = mFileSystem.createFile(filePath, mWriteBoth);
    os.write((byte) 0);
    os.write((byte) 1);
    os.close();
    URIStatus status = mFileSystem.getStatus(filePath);
    Assert.assertEquals(PersistenceState.PERSISTED.toString(), status.getPersistenceState());
    final Long blockId = status.getBlockIds().get(0);
    BlockMaster bm = mLocalAlluxioClusterResource.get().getMaster().getInternalMaster().getBlockMaster();
    BlockInfo blockInfo = bm.getBlockInfo(blockId);
    Assert.assertEquals(2, blockInfo.getLength());
    Assert.assertFalse(blockInfo.getLocations().isEmpty());
    final BlockWorker bw = mLocalAlluxioClusterResource.get().getWorker().getBlockWorker();
    Assert.assertTrue(bw.hasBlockMeta(blockId));
    Assert.assertTrue(bm.getLostBlocks().isEmpty());
    mFileSystem.free(filePath);
    IntegrationTestUtils.waitForBlocksToBeFreed(bw, blockId);
    status = mFileSystem.getStatus(filePath);
    // Verify block metadata in master is still present after block freed.
    Assert.assertEquals(1, status.getBlockIds().size());
    blockInfo = bm.getBlockInfo(status.getBlockIds().get(0));
    Assert.assertEquals(2, blockInfo.getLength());
    // Verify the block has been removed from all workers.
    Assert.assertTrue(blockInfo.getLocations().isEmpty());
    Assert.assertFalse(bw.hasBlockMeta(blockId));
    // Verify the removed block is added to LostBlocks list.
    Assert.assertTrue(bm.getLostBlocks().contains(blockInfo.getBlockId()));
    mFileSystem.delete(filePath);
    try {
        // File is immediately gone after delete.
        mFileSystem.getStatus(filePath);
        Assert.fail(String.format("Expected file %s being deleted but it was not.", filePath));
    } catch (FileDoesNotExistException e) {
    // expected
    }
    // Execute the lost files detection.
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_LOST_FILES_DETECTION);
    // Verify the blocks are not in mLostBlocks.
    Assert.assertTrue(bm.getLostBlocks().isEmpty());
}
Also used : BlockMaster(alluxio.master.block.BlockMaster) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) BlockInfo(alluxio.wire.BlockInfo) FileOutStream(alluxio.client.file.FileOutStream) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) BlockWorker(alluxio.worker.block.BlockWorker) Test(org.junit.Test)

Example 29 with FileDoesNotExistException

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

the class CpCommand method copy.

/**
   * Copies a file or a directory in the Alluxio filesystem.
   *
   * @param srcPath the source {@link AlluxioURI} (could be a file or a directory)
   * @param dstPath the {@link AlluxioURI} of the destination path in the Alluxio filesystem
   * @param recursive indicates whether directories should be copied recursively
   * @throws AlluxioException when Alluxio exception occurs
   * @throws IOException when non-Alluxio exception occurs
   */
private void copy(AlluxioURI srcPath, AlluxioURI dstPath, boolean recursive) throws AlluxioException, IOException {
    URIStatus srcStatus = mFileSystem.getStatus(srcPath);
    URIStatus dstStatus = null;
    try {
        dstStatus = mFileSystem.getStatus(dstPath);
    } catch (FileDoesNotExistException e) {
    // if the destination does not exist, it will be created
    }
    if (!srcStatus.isFolder()) {
        if (dstStatus != null && dstStatus.isFolder()) {
            dstPath = new AlluxioURI(PathUtils.concatPath(dstPath.getPath(), srcPath.getName()));
        }
        copyFile(srcPath, dstPath);
    } else {
        if (!recursive) {
            throw new IOException(srcPath.getPath() + " is a directory, to copy it please use \"cp -R <src> <dst>\"");
        }
        List<URIStatus> statuses;
        statuses = mFileSystem.listStatus(srcPath);
        if (dstStatus != null) {
            if (!dstStatus.isFolder()) {
                throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
            }
            // subdirectory of the destination
            if (srcStatus.isFolder()) {
                dstPath = new AlluxioURI(PathUtils.concatPath(dstPath.getPath(), srcPath.getName()));
                mFileSystem.createDirectory(dstPath);
                System.out.println("Created directory: " + dstPath);
            }
        }
        if (dstStatus == null) {
            mFileSystem.createDirectory(dstPath);
            System.out.println("Created directory: " + dstPath);
        }
        List<String> errorMessages = new ArrayList<>();
        for (URIStatus status : statuses) {
            try {
                copy(new AlluxioURI(srcPath.getScheme(), srcPath.getAuthority(), status.getPath()), new AlluxioURI(dstPath.getScheme(), dstPath.getAuthority(), PathUtils.concatPath(dstPath.getPath(), status.getName())), recursive);
            } catch (IOException e) {
                errorMessages.add(e.getMessage());
            }
        }
        if (errorMessages.size() != 0) {
            throw new IOException(Joiner.on('\n').join(errorMessages));
        }
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 30 with FileDoesNotExistException

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

the class CpCommand method run.

@Override
public void run(CommandLine cl) throws AlluxioException, IOException {
    String[] args = cl.getArgs();
    AlluxioURI srcPath = new AlluxioURI(args[0]);
    AlluxioURI dstPath = new AlluxioURI(args[1]);
    if ((dstPath.getScheme() == null || isAlluxio(dstPath.getScheme())) && isFile(srcPath.getScheme())) {
        List<File> srcFiles = AlluxioShellUtils.getFiles(srcPath.getPath());
        if (srcFiles.size() == 0) {
            throw new IOException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(srcPath));
        }
        if (srcPath.containsWildcard()) {
            List<AlluxioURI> srcPaths = new ArrayList<>();
            for (File srcFile : srcFiles) {
                srcPaths.add(new AlluxioURI(srcPath.getScheme(), srcPath.getAuthority(), srcFile.getPath()));
            }
            copyFromLocalWildcard(srcPaths, dstPath);
        } else {
            copyFromLocal(srcPath, dstPath);
        }
    } else if ((srcPath.getScheme() == null || isAlluxio(srcPath.getScheme())) && isFile(dstPath.getScheme())) {
        List<AlluxioURI> srcPaths = AlluxioShellUtils.getAlluxioURIs(mFileSystem, srcPath);
        if (srcPaths.size() == 0) {
            throw new IOException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(srcPath));
        }
        if (srcPath.containsWildcard()) {
            copyWildcardToLocal(srcPaths, dstPath);
        } else {
            copyToLocal(srcPath, dstPath);
        }
    } else if ((srcPath.getScheme() == null || isAlluxio(srcPath.getScheme())) && (dstPath.getScheme() == null || isAlluxio(dstPath.getScheme()))) {
        List<AlluxioURI> srcPaths = AlluxioShellUtils.getAlluxioURIs(mFileSystem, srcPath);
        if (srcPaths.size() == 0) {
            throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(srcPath.getPath()));
        }
        if (srcPath.containsWildcard()) {
            copyWildcard(srcPaths, dstPath, cl.hasOption("R"));
        } else {
            copy(srcPath, dstPath, cl.hasOption("R"));
        }
    } else {
        throw new InvalidPathException("Schemes must be either file or alluxio, and at most one file scheme is allowed.");
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) File(java.io.File) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Aggregations

FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)51 AlluxioURI (alluxio.AlluxioURI)36 InvalidPathException (alluxio.exception.InvalidPathException)20 IOException (java.io.IOException)19 AlluxioException (alluxio.exception.AlluxioException)16 Test (org.junit.Test)14 URIStatus (alluxio.client.file.URIStatus)13 ArrayList (java.util.ArrayList)10 AccessControlException (alluxio.exception.AccessControlException)7 FileInfo (alluxio.wire.FileInfo)7 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)5 BlockInfoException (alluxio.exception.BlockInfoException)4 RestApiTest (alluxio.rest.RestApiTest)4 TestCase (alluxio.rest.TestCase)4 HashMap (java.util.HashMap)4 FileAlreadyCompletedException (alluxio.exception.FileAlreadyCompletedException)3 InvalidFileSizeException (alluxio.exception.InvalidFileSizeException)3 UnexpectedAlluxioException (alluxio.exception.UnexpectedAlluxioException)3 Inode (alluxio.master.file.meta.Inode)3 LockedInodePath (alluxio.master.file.meta.LockedInodePath)3