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();
}
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;
}
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;
}
Aggregations