use of alluxio.underfs.UfsStatus in project alluxio by Alluxio.
the class InodeTree method syncPersistDirectory.
/**
* Persists the directory to the UFS, returning the UFS status if the directory is found to
* already exist in the UFS.
*
* @param dir the directory to persist
* @return optional ufs status if the directory already existed
*/
private Optional<UfsStatus> syncPersistDirectory(InodeDirectoryView dir) throws FileDoesNotExistException, IOException, InvalidPathException {
AlluxioURI uri = getPath(dir);
MountTable.Resolution resolution = mMountTable.resolve(uri);
String ufsUri = resolution.getUri().toString();
try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
UnderFileSystem ufs = ufsResource.get();
MkdirsOptions mkdirsOptions = MkdirsOptions.defaults(ServerConfiguration.global()).setCreateParent(false).setOwner(dir.getOwner()).setGroup(dir.getGroup()).setMode(new Mode(dir.getMode()));
if (!ufs.mkdirs(ufsUri, mkdirsOptions)) {
// Directory might already exist. Try loading the status from ufs.
UfsStatus status;
try {
status = ufs.getStatus(ufsUri);
} catch (Exception e) {
throw new IOException(String.format("Cannot create or load UFS directory %s: %s.", ufsUri, e.toString()), e);
}
if (status.isFile()) {
throw new InvalidPathException(String.format("Error persisting directory. A file exists at the UFS location %s.", ufsUri));
}
return Optional.of(status);
}
}
return Optional.empty();
}
use of alluxio.underfs.UfsStatus in project alluxio by Alluxio.
the class CephFSUnderFileSystem method listStatus.
/**
* Each string is a name rather than a complete path.
*
* @param path the path to list
* @return An array with the statuses of the files and directories in the directory
* denoted by this path. The array will be empty if the directory is empty. Returns
* null if this path does not denote a directory
*/
@Override
@Nullable
public UfsStatus[] listStatus(String path) throws IOException {
path = stripPath(path);
String[] lst = listDirectory(path);
if (lst != null) {
UfsStatus[] status = new UfsStatus[lst.length];
for (int i = 0; i < status.length; i++) {
CephStat stat = new CephStat();
lstat(PathUtils.concatPath(path, lst[i]), stat);
if (!stat.isDir()) {
String contentHash = UnderFileSystemUtils.approximateContentHash(stat.size, stat.m_time);
status[i] = new UfsFileStatus(lst[i], contentHash, stat.size, stat.m_time, "", "", (short) stat.mode);
} else {
status[i] = new UfsDirectoryStatus(lst[i], "", "", (short) stat.mode);
}
}
return status;
}
return null;
}
use of alluxio.underfs.UfsStatus in project alluxio by Alluxio.
the class UfsJournalIntegrationTest method multipleFlush.
/**
* Tests flushing the journal multiple times, without writing any data.
*/
@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.MASTER_JOURNAL_LOG_SIZE_BYTES_MAX, "0" })
public void multipleFlush() throws Exception {
String journalFolder = mLocalAlluxioCluster.getLocalAlluxioMaster().getJournalFolder();
mLocalAlluxioCluster.stop();
UfsJournal journal = new UfsJournal(new URI(PathUtils.concatPath(journalFolder, Constants.FILE_SYSTEM_MASTER_NAME)), new NoopMaster(), 0, Collections::emptySet);
journal.start();
journal.gainPrimacy();
UfsStatus[] paths = UnderFileSystem.Factory.create(journalFolder, ServerConfiguration.global()).listStatus(journal.getLogDir().toString());
int expectedSize = paths == null ? 0 : paths.length;
journal.flush();
journal.flush();
journal.flush();
journal.close();
paths = UnderFileSystem.Factory.create(journalFolder, ServerConfiguration.global()).listStatus(journal.getLogDir().toString());
int actualSize = paths == null ? 0 : paths.length;
// No new files are created.
Assert.assertEquals(expectedSize, actualSize);
}
use of alluxio.underfs.UfsStatus in project alluxio by Alluxio.
the class DefaultFileSystemMaster method checkConsistencyInternal.
/**
* Checks if a path is consistent between Alluxio and the underlying storage.
* <p>
* A path without a backing under storage is always consistent.
* <p>
* A not persisted path is considered consistent if:
* 1. It does not shadow an object in the underlying storage.
* <p>
* A persisted path is considered consistent if:
* 1. An equivalent object exists for its under storage path.
* 2. The metadata of the Alluxio and under storage object are equal.
*
* @param inodePath the path to check. This must exist and be read-locked
* @return true if the path is consistent, false otherwise
*/
private boolean checkConsistencyInternal(LockedInodePath inodePath) throws InvalidPathException, IOException {
Inode inode;
try {
inode = inodePath.getInode();
} catch (FileDoesNotExistException e) {
// already checked existence when creating the inodePath
throw new RuntimeException(e);
}
MountTable.Resolution resolution = mMountTable.resolve(inodePath.getUri());
try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
UnderFileSystem ufs = ufsResource.get();
String ufsPath = resolution.getUri().getPath();
if (ufs == null) {
return true;
}
if (!inode.isPersisted()) {
return !ufs.exists(ufsPath);
}
UfsStatus ufsStatus;
try {
ufsStatus = ufs.getStatus(ufsPath);
} catch (FileNotFoundException e) {
return !inode.isPersisted();
}
// TODO(calvin): Evaluate which other metadata fields should be validated.
if (inode.isDirectory()) {
return ufsStatus.isDirectory();
} else {
String ufsFingerprint = Fingerprint.create(ufs.getUnderFSType(), ufsStatus).serialize();
return ufsStatus.isFile() && (ufsFingerprint.equals(inode.asFile().getUfsFingerprint())) && ufsStatus instanceof UfsFileStatus && ((UfsFileStatus) ufsStatus).getContentLength() == inode.asFile().getLength();
}
}
}
use of alluxio.underfs.UfsStatus in project alluxio by Alluxio.
the class InodeSyncStream method loadMetadataForPath.
private void loadMetadataForPath(LockedInodePath inodePath) throws InvalidPathException, AccessControlException, IOException, FileDoesNotExistException, FileAlreadyCompletedException, InvalidFileSizeException, BlockInfoException {
UfsStatus status = mStatusCache.fetchStatusIfAbsent(inodePath.getUri(), mMountTable);
DescendantType descendantType = mDescendantType;
// do not load the subdirectory
if (descendantType.equals(DescendantType.ONE) && !inodePath.getUri().equals(mRootScheme.getPath())) {
descendantType = DescendantType.NONE;
}
LoadMetadataContext ctx = LoadMetadataContext.mergeFrom(LoadMetadataPOptions.newBuilder().setCommonOptions(NO_TTL_OPTION).setCreateAncestors(true).setLoadDescendantType(GrpcUtils.toProto(descendantType))).setUfsStatus(status);
loadMetadata(inodePath, ctx);
}
Aggregations