use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class AbstractFileSystem method getFileStatus.
/**
* {@inheritDoc}
*
* If the file does not exist in Alluxio, query it from HDFS.
*/
@Override
public FileStatus getFileStatus(Path path) throws IOException {
LOG.debug("getFileStatus({})", path);
if (mStatistics != null) {
mStatistics.incrementReadOps(1);
}
AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path));
URIStatus fileStatus;
try {
fileStatus = mFileSystem.getStatus(uri);
} catch (FileDoesNotExistException e) {
throw new FileNotFoundException(e.getMessage());
} catch (AlluxioException e) {
throw new IOException(e);
}
return new FileStatus(fileStatus.getLength(), fileStatus.isFolder(), BLOCK_REPLICATION_CONSTANT, fileStatus.getBlockSizeBytes(), fileStatus.getLastModificationTimeMs(), fileStatus.getCreationTimeMs(), new FsPermission((short) fileStatus.getMode()), fileStatus.getOwner(), fileStatus.getGroup(), new Path(mAlluxioHeader + uri));
}
use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class AbstractFileSystem method mkdirs.
/**
* Attempts to create a folder with the specified path. Parent directories will be created.
*
* @param path path to create
* @param permission permissions to grant the created folder
* @return true if the indicated folder is created successfully or already exists
* @throws IOException if the folder cannot be created
*/
@Override
public boolean mkdirs(Path path, FsPermission permission) throws IOException {
LOG.debug("mkdirs({}, {})", path, permission);
if (mStatistics != null) {
mStatistics.incrementWriteOps(1);
}
AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path));
CreateDirectoryOptions options = CreateDirectoryOptions.defaults().setRecursive(true).setAllowExists(true).setMode(new Mode(permission.toShort()));
try {
mFileSystem.createDirectory(uri, options);
return true;
} catch (AlluxioException e) {
throw new IOException(e);
}
}
use of alluxio.exception.AlluxioException 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;
}
use of alluxio.exception.AlluxioException 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;
}
use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class BaseKeyValueStoreWriter method close.
@Override
public void close() throws IOException {
if (mClosed) {
return;
}
try {
if (mCanceled) {
mWriter.cancel();
// TODO(binfan): cancel all other written partitions
} else {
completePartition();
mMasterClient.completeStore(mStoreUri);
}
} catch (AlluxioException e) {
throw new IOException(e);
} finally {
mMasterClient.close();
}
mClosed = true;
}
Aggregations