use of alluxio.underfs.UfsFileStatus 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();
}
}
}
Aggregations