use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class KeyValueInputFormat method getSplits.
/**
* Returns a list of {@link KeyValueInputSplit} where each split is one key-value partition.
*
* @param jobContext MapReduce job configuration
* @return list of {@link InputSplit}s, each split is a partition
* @throws IOException if information about the partition cannot be retrieved
*/
@Override
public List<InputSplit> getSplits(JobContext jobContext) throws IOException {
// The paths are MapReduce program's inputs specified in
// {@code mapreduce.input.fileinputformat.inputdir}, each path should be a key-value store.
Path[] paths = FileInputFormat.getInputPaths(jobContext);
List<InputSplit> splits = new ArrayList<>();
try {
for (Path path : paths) {
List<PartitionInfo> partitionInfos = mKeyValueMasterClient.getPartitionInfo(new AlluxioURI(path.toString()));
for (PartitionInfo partitionInfo : partitionInfos) {
splits.add(new KeyValueInputSplit(partitionInfo));
}
}
} catch (AlluxioException e) {
throw new IOException(e);
}
return splits;
}
use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class KeyValueRecordReader method nextKeyValue.
@Override
public synchronized boolean nextKeyValue() throws IOException {
if (!mKeyValuePairIterator.hasNext()) {
return false;
}
KeyValuePair pair;
try {
pair = mKeyValuePairIterator.next();
} catch (AlluxioException e) {
throw new IOException(e);
}
// TODO(cc): Implement a ByteBufferInputStream which is backed by a ByteBuffer so we could
// benefit from zero-copy.
mCurrentKey.set(new BytesWritable(BufferUtils.newByteArrayFromByteBuffer(pair.getKey())));
mCurrentValue.set(new BytesWritable(BufferUtils.newByteArrayFromByteBuffer(pair.getValue())));
mNumVisitedKeyValuePairs++;
return true;
}
use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method readdir.
/**
* Reads the contents of a directory.
*
* @param path The FS path of the directory
* @param buff The FUSE buffer to fill
* @param filter FUSE filter
* @param offset Ignored in alluxio-fuse
* @param fi FileInfo data structure kept by FUSE
* @return 0 on success, a negative value on error
*/
@Override
public int readdir(String path, Pointer buff, FuseFillDir filter, @off_t long offset, FuseFileInfo fi) {
final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
LOG.trace("readdir({}) [Alluxio: {}]", path, turi);
try {
if (!mFileSystem.exists(turi)) {
return -ErrorCodes.ENOENT();
}
final URIStatus status = mFileSystem.getStatus(turi);
if (!status.isFolder()) {
return -ErrorCodes.ENOTDIR();
}
final List<URIStatus> ls = mFileSystem.listStatus(turi);
// standard . and .. entries
filter.apply(buff, ".", null, 0);
filter.apply(buff, "..", null, 0);
for (final URIStatus file : ls) {
filter.apply(buff, file.getName(), null, 0);
}
} catch (FileDoesNotExistException e) {
LOG.debug("File does not exist {}", path, e);
return -ErrorCodes.ENOENT();
} catch (InvalidPathException e) {
LOG.debug("Invalid path {}", 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;
}
use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method rename.
/**
* Renames a path.
*
* @param oldPath the source path in the FS
* @param newPath the destination path in the FS
* @return 0 on success, a negative value on error
*/
@Override
public int rename(String oldPath, String newPath) {
final AlluxioURI oldUri = mPathResolverCache.getUnchecked(oldPath);
final AlluxioURI newUri = mPathResolverCache.getUnchecked(newPath);
LOG.trace("rename({}, {}) [Alluxio: {}, {}]", oldPath, newPath, oldUri, newUri);
try {
if (!mFileSystem.exists(oldUri)) {
LOG.error("File {} does not exist", oldPath);
return -ErrorCodes.ENOENT();
} else {
mFileSystem.rename(oldUri, newUri);
}
} catch (FileDoesNotExistException e) {
LOG.debug("File {} does not exist", oldPath);
return -ErrorCodes.ENOENT();
} catch (IOException e) {
LOG.error("IOException while moving {} to {}", oldPath, newPath, e);
return -ErrorCodes.EIO();
} catch (AlluxioException e) {
LOG.error("Exception while moving {} to {}", oldPath, newPath, e);
return -ErrorCodes.EFAULT();
} catch (Throwable e) {
LOG.error("Unexpected exception on mv {} {}", oldPath, newPath, e);
return -ErrorCodes.EFAULT();
}
return 0;
}
use of alluxio.exception.AlluxioException 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;
}
Aggregations