use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method getattr.
/**
* Retrieves file attributes.
*
* @param path The path on the FS of the file
* @param stat FUSE data structure to fill with file attrs
* @return 0 on success, negative value on error
*/
@Override
public int getattr(String path, FileStat stat) {
final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
LOG.trace("getattr({}) [Alluxio: {}]", path, turi);
try {
if (!mFileSystem.exists(turi)) {
return -ErrorCodes.ENOENT();
}
final URIStatus status = mFileSystem.getStatus(turi);
stat.st_size.set(status.getLength());
final long ctime_sec = status.getLastModificationTimeMs() / 1000;
//keeps only the "residual" nanoseconds not caputred in
// citme_sec
final long ctime_nsec = (status.getLastModificationTimeMs() % 1000) * 1000;
stat.st_ctim.tv_sec.set(ctime_sec);
stat.st_ctim.tv_nsec.set(ctime_nsec);
stat.st_mtim.tv_sec.set(ctime_sec);
stat.st_mtim.tv_nsec.set(ctime_nsec);
// TODO(andreareale): understand how to map FileInfo#getOwner()
// and FileInfo#getGroup() to UIDs and GIDs of the node
// where alluxio-fuse is mounted.
// While this is not done, just use uid and gid of the user
// running alluxio-fuse.
stat.st_uid.set(UID_AND_GID[0]);
stat.st_gid.set(UID_AND_GID[1]);
final int mode;
if (status.isFolder()) {
mode = FileStat.S_IFDIR;
} else {
mode = FileStat.S_IFREG;
}
stat.st_mode.set(mode);
} catch (InvalidPathException e) {
LOG.debug("Invalid path {}", path, e);
return -ErrorCodes.ENOENT();
} 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;
}
use of alluxio.exception.AlluxioException in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method rmInternal.
/**
* Convenience internal method to remove files or directories.
*
* @param path The path to remove
* @param mustBeFile When true, returns an error when trying to
* remove a directory
* @return 0 on success, a negative value on error
*/
private int rmInternal(String path, boolean mustBeFile) {
final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
try {
if (!mFileSystem.exists(turi)) {
LOG.error("File {} does not exist", turi);
return -ErrorCodes.ENOENT();
}
final URIStatus status = mFileSystem.getStatus(turi);
if (mustBeFile && status.isFolder()) {
LOG.error("File {} is a directory", turi);
return -ErrorCodes.EISDIR();
}
mFileSystem.delete(turi);
} 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;
}
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;
}
Aggregations