Search in sources :

Example 31 with UfsStatus

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();
}
Also used : MkdirsOptions(alluxio.underfs.options.MkdirsOptions) UfsStatus(alluxio.underfs.UfsStatus) LockMode(alluxio.concurrent.LockMode) Mode(alluxio.security.authorization.Mode) IOException(java.io.IOException) UnderFileSystem(alluxio.underfs.UnderFileSystem) InvalidPathException(alluxio.exception.InvalidPathException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) UnavailableException(alluxio.exception.status.UnavailableException) BlockInfoException(alluxio.exception.BlockInfoException) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 32 with UfsStatus

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;
}
Also used : UfsFileStatus(alluxio.underfs.UfsFileStatus) UfsStatus(alluxio.underfs.UfsStatus) CephStat(com.ceph.fs.CephStat) UfsDirectoryStatus(alluxio.underfs.UfsDirectoryStatus) Nullable(javax.annotation.Nullable)

Example 33 with UfsStatus

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);
}
Also used : UfsStatus(alluxio.underfs.UfsStatus) Collections(java.util.Collections) AlluxioURI(alluxio.AlluxioURI) URI(java.net.URI) UfsJournal(alluxio.master.journal.ufs.UfsJournal) NoopMaster(alluxio.master.NoopMaster) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 34 with UfsStatus

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();
        }
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) UfsFileStatus(alluxio.underfs.UfsFileStatus) Inode(alluxio.master.file.meta.Inode) UfsStatus(alluxio.underfs.UfsStatus) FileNotFoundException(java.io.FileNotFoundException) MountTable(alluxio.master.file.meta.MountTable) UnderFileSystem(alluxio.underfs.UnderFileSystem)

Example 35 with UfsStatus

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);
}
Also used : LoadMetadataContext(alluxio.master.file.contexts.LoadMetadataContext) UfsStatus(alluxio.underfs.UfsStatus) DescendantType(alluxio.file.options.DescendantType)

Aggregations

UfsStatus (alluxio.underfs.UfsStatus)40 UnderFileSystem (alluxio.underfs.UnderFileSystem)12 IOException (java.io.IOException)12 Test (org.junit.Test)11 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)10 Path (org.apache.hadoop.fs.Path)9 AlluxioURI (alluxio.AlluxioURI)8 Inode (alluxio.master.file.meta.Inode)7 MountTable (alluxio.master.file.meta.MountTable)7 UfsFileStatus (alluxio.underfs.UfsFileStatus)6 UfsDirectoryStatus (alluxio.underfs.UfsDirectoryStatus)5 ArrayList (java.util.ArrayList)5 FileStatus (org.apache.hadoop.fs.FileStatus)5 BlockInfoException (alluxio.exception.BlockInfoException)4 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)4 FileNotFoundException (java.io.FileNotFoundException)4 Fingerprint (alluxio.underfs.Fingerprint)3 URI (java.net.URI)3 InvalidPathException (alluxio.exception.InvalidPathException)2 LoadMetadataContext (alluxio.master.file.contexts.LoadMetadataContext)2