Search in sources :

Example 6 with ListStatusPOptions

use of alluxio.grpc.ListStatusPOptions in project alluxio by Alluxio.

the class ConcurrentFileSystemMasterCreateIntegrationTest method runLoadMetadata.

/**
 * Runs load metadata tests.
 *
 * @param writeType the {@link WritePType} to create ancestors, if not null
 * @param useSinglePath if true, threads will only use a single path
 * @param createFiles if true, will create files at the bottom of the tree, directories otherwise
 * @param listParentDir if true, will list the parent dir to load the metadata
 */
private void runLoadMetadata(WritePType writeType, boolean useSinglePath, boolean createFiles, boolean listParentDir) throws Exception {
    int numThreads = CONCURRENCY_FACTOR;
    int bufferFactor = CONCURRENCY_FACTOR / 2;
    // 2 nested components to create.
    long limitMs = 2 * SLEEP_MS * bufferFactor;
    int uniquePaths = useSinglePath ? 1 : numThreads;
    if (writeType != WritePType.CACHE_THROUGH) {
        // all 3 components must be synced to UFS.
        limitMs = 3 * SLEEP_MS * bufferFactor;
    }
    if (listParentDir) {
        // Loading direct children needs to load each child, so reduce the branching factor.
        uniquePaths = 10;
        limitMs = 2 + uniquePaths * SLEEP_MS * bufferFactor;
    }
    // Create UFS files outside of Alluxio.
    new File(mLocalUfsPath + "/existing/path/").mkdirs();
    for (int i = 0; i < uniquePaths; i++) {
        if (createFiles) {
            FileWriter fileWriter = new FileWriter(mLocalUfsPath + "/existing/path/last_" + i);
            fileWriter.write("testtesttesttest");
            fileWriter.close();
        } else {
            new File(mLocalUfsPath + "/existing/path/last_" + i).mkdirs();
        }
    }
    if (writeType != null) {
        // create inodes in Alluxio
        mFileSystem.createDirectory(new AlluxioURI("/existing/path/"), CreateDirectoryPOptions.newBuilder().setRecursive(true).setWriteType(writeType).build());
    }
    // Generate path names for threads.
    AlluxioURI[] paths = new AlluxioURI[numThreads];
    int fileId = 0;
    for (int i = 0; i < numThreads; i++) {
        if (listParentDir) {
            paths[i] = new AlluxioURI("/existing/path/");
        } else {
            paths[i] = new AlluxioURI("/existing/path/last_" + ((fileId++) % uniquePaths));
        }
    }
    List<Throwable> errors;
    if (listParentDir) {
        errors = ConcurrentFileSystemMasterUtils.unaryOperation(mFileSystem, ConcurrentFileSystemMasterUtils.UnaryOperation.LIST_STATUS, paths, limitMs);
    } else {
        errors = ConcurrentFileSystemMasterUtils.unaryOperation(mFileSystem, ConcurrentFileSystemMasterUtils.UnaryOperation.GET_FILE_INFO, paths, limitMs);
    }
    if (!errors.isEmpty()) {
        Assert.fail("Encountered " + errors.size() + " errors, the first one is " + errors.get(0) + "\n" + Throwables.getStackTraceAsString(errors.get(0)));
    }
    ListStatusPOptions listOptions = ListStatusPOptions.newBuilder().setLoadMetadataType(LoadMetadataPType.NEVER).build();
    List<URIStatus> files = mFileSystem.listStatus(new AlluxioURI("/"), listOptions);
    Assert.assertEquals(1, files.size());
    Assert.assertEquals("existing", files.get(0).getName());
    Assert.assertEquals(PersistenceState.PERSISTED, PersistenceState.valueOf(files.get(0).getPersistenceState()));
    files = mFileSystem.listStatus(new AlluxioURI("/existing"), listOptions);
    Assert.assertEquals(1, files.size());
    Assert.assertEquals("path", files.get(0).getName());
    Assert.assertEquals(PersistenceState.PERSISTED, PersistenceState.valueOf(files.get(0).getPersistenceState()));
    files = mFileSystem.listStatus(new AlluxioURI("/existing/path/"), listOptions);
    Assert.assertEquals(uniquePaths, files.size());
    Collections.sort(files, new ConcurrentFileSystemMasterUtils.IntegerSuffixedPathComparator());
    for (int i = 0; i < uniquePaths; i++) {
        Assert.assertEquals("last_" + i, files.get(i).getName());
        Assert.assertEquals(PersistenceState.PERSISTED, PersistenceState.valueOf(files.get(i).getPersistenceState()));
    }
}
Also used : FileWriter(java.io.FileWriter) URIStatus(alluxio.client.file.URIStatus) ListStatusPOptions(alluxio.grpc.ListStatusPOptions) File(java.io.File) AlluxioURI(alluxio.AlluxioURI)

Example 7 with ListStatusPOptions

use of alluxio.grpc.ListStatusPOptions in project alluxio by Alluxio.

the class LoadMetadataIntegrationTest method loadRecursive.

@Test
public void loadRecursive() throws Exception {
    ServerConfiguration.set(PropertyKey.USER_FILE_METADATA_LOAD_TYPE, LoadMetadataType.ONCE.toString());
    ListStatusPOptions options = ListStatusPOptions.newBuilder().setRecursive(true).build();
    int createdInodes = createUfsFiles(5);
    List<URIStatus> list = mFileSystem.listStatus(new AlluxioURI("/mnt"), options);
    // 25 files, 25 level 2 dirs, 5 level 1 dirs, 1 file and 1 dir created in before
    // 4 directories/files in must cache
    assertEquals(createdInodes + EXTRA_DIR_FILES, list.size());
}
Also used : URIStatus(alluxio.client.file.URIStatus) ListStatusPOptions(alluxio.grpc.ListStatusPOptions) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 8 with ListStatusPOptions

use of alluxio.grpc.ListStatusPOptions in project alluxio by Alluxio.

the class LoadMetadataIntegrationTest method symLink.

@Test
public void symLink() throws Exception {
    Path target = Paths.get(mLocalUfsPath + "/dir1/dirA/file");
    Path link = Paths.get(mLocalUfsPath + "/symlink");
    Files.createSymbolicLink(link, target);
    Path target2 = Paths.get(mLocalUfsPath + "/dir1/dirA/");
    Path link2 = Paths.get(mLocalUfsPath + "/symlinkDir");
    Files.createSymbolicLink(link2, target2);
    ListStatusPOptions options = ListStatusPOptions.newBuilder().setLoadMetadataType(LoadMetadataPType.ONCE).setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setSyncIntervalMs(-1)).build();
    List<URIStatus> statusList = checkListStatus("/mnt/", options, true, true, 3);
    assertEquals(4, statusList.size());
    assertTrue(statusList.stream().anyMatch(x -> x.getName().equals("symlink")));
    assertTrue(statusList.stream().anyMatch(x -> x.getName().equals("symlinkDir")));
    if (Files.exists(link)) {
        Files.delete(link);
    }
    if (Files.exists(link2)) {
        Files.delete(link2);
    }
}
Also used : Path(java.nio.file.Path) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) Whitebox(org.powermock.reflect.Whitebox) GetStatusPOptions(alluxio.grpc.GetStatusPOptions) SleepingUnderFileSystemOptions(alluxio.testutils.underfs.sleeping.SleepingUnderFileSystemOptions) TimeoutException(java.util.concurrent.TimeoutException) FileOutStream(alluxio.client.file.FileOutStream) PropertyKey(alluxio.conf.PropertyKey) FileSystemMaster(alluxio.master.file.FileSystemMaster) WaitForOptions(alluxio.util.WaitForOptions) LoadMetadataType(alluxio.wire.LoadMetadataType) SleepingUnderFileSystemFactory(alluxio.testutils.underfs.sleeping.SleepingUnderFileSystemFactory) PathUtils(alluxio.util.io.PathUtils) FileSystem(alluxio.client.file.FileSystem) Constants(alluxio.Constants) AlluxioURI(alluxio.AlluxioURI) After(org.junit.After) FileSystemMasterCommonPOptions(alluxio.grpc.FileSystemMasterCommonPOptions) Assert.fail(org.junit.Assert.fail) ClassRule(org.junit.ClassRule) ListStatusPOptions(alluxio.grpc.ListStatusPOptions) Path(java.nio.file.Path) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Before(org.junit.Before) TtlAction(alluxio.grpc.TtlAction) WritePType(alluxio.grpc.WritePType) ServerConfiguration(alluxio.conf.ServerConfiguration) Files(java.nio.file.Files) LocalAlluxioClusterResource(alluxio.testutils.LocalAlluxioClusterResource) FileWriter(java.io.FileWriter) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) UfsAbsentPathCache(alluxio.master.file.meta.UfsAbsentPathCache) UnderFileSystemFactoryRegistryRule(alluxio.UnderFileSystemFactoryRegistryRule) URIStatus(alluxio.client.file.URIStatus) List(java.util.List) Rule(org.junit.Rule) Paths(java.nio.file.Paths) Assert.assertFalse(org.junit.Assert.assertFalse) Message(com.google.protobuf.Message) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) LoadMetadataPType(alluxio.grpc.LoadMetadataPType) Assert(org.junit.Assert) AuthenticatedUserRule(alluxio.AuthenticatedUserRule) Assert.assertEquals(org.junit.Assert.assertEquals) CommonUtils(alluxio.util.CommonUtils) TemporaryFolder(org.junit.rules.TemporaryFolder) URIStatus(alluxio.client.file.URIStatus) ListStatusPOptions(alluxio.grpc.ListStatusPOptions) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 9 with ListStatusPOptions

use of alluxio.grpc.ListStatusPOptions in project alluxio by Alluxio.

the class LoadMetadataIntegrationTest method repeatedDirectorySync.

@Test
public void repeatedDirectorySync() throws Exception {
    ListStatusPOptions options = ListStatusPOptions.newBuilder().setRecursive(true).setLoadMetadataType(LoadMetadataPType.ONCE).setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setSyncIntervalMs(-1)).build();
    checkListStatus("/mnt/dir1/", options, true, true, 3);
    checkListStatus("/mnt/dir1/", options, true, true, 0);
}
Also used : ListStatusPOptions(alluxio.grpc.ListStatusPOptions) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 10 with ListStatusPOptions

use of alluxio.grpc.ListStatusPOptions in project alluxio by Alluxio.

the class LoadMetadataIntegrationTest method getStatusDoesNotLoadFile.

@Test
public void getStatusDoesNotLoadFile() throws Exception {
    GetStatusPOptions getStatusOptions = GetStatusPOptions.newBuilder().setLoadMetadataType(LoadMetadataPType.ONCE).build();
    ListStatusPOptions lsOptions = ListStatusPOptions.newBuilder().setLoadMetadataType(LoadMetadataPType.ALWAYS).setCommonOptions(PSYNC_ALWAYS).build();
    // load metadata for dirA with 'ALWAYS'
    checkGetStatus("/mnt/dir1/dirA", getStatusOptions, true, true, 2);
    // the file should NOT already be loaded
    checkGetStatus("/mnt/dir1/dirA/file", getStatusOptions, true, true, 1);
}
Also used : GetStatusPOptions(alluxio.grpc.GetStatusPOptions) ListStatusPOptions(alluxio.grpc.ListStatusPOptions) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

ListStatusPOptions (alluxio.grpc.ListStatusPOptions)34 Test (org.junit.Test)24 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)21 AlluxioURI (alluxio.AlluxioURI)17 URIStatus (alluxio.client.file.URIStatus)14 File (java.io.File)9 GetStatusPOptions (alluxio.grpc.GetStatusPOptions)7 HashMap (java.util.HashMap)3 FileSystem (alluxio.client.file.FileSystem)2 AlluxioException (alluxio.exception.AlluxioException)2 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)2 ListBucketResult (alluxio.proxy.s3.ListBucketResult)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 AuthenticatedUserRule (alluxio.AuthenticatedUserRule)1 Constants (alluxio.Constants)1 UnderFileSystemFactoryRegistryRule (alluxio.UnderFileSystemFactoryRegistryRule)1 FileOutStream (alluxio.client.file.FileOutStream)1 PropertyKey (alluxio.conf.PropertyKey)1