Search in sources :

Example 6 with DeletePOptions

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

the class StressJobServiceBench method deletePath.

private void deletePath(FileSystem fs, String dirPath) throws IOException, AlluxioException {
    AlluxioURI path = new AlluxioURI(dirPath);
    if (fs.exists(path)) {
        DeletePOptions options = DeletePOptions.newBuilder().setRecursive(true).build();
        fs.delete(path, options);
    }
}
Also used : DeletePOptions(alluxio.grpc.DeletePOptions) AlluxioURI(alluxio.AlluxioURI)

Example 7 with DeletePOptions

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

the class UfsSyncIntegrationTest method deleteFileSync.

@Test
public void deleteFileSync() throws Exception {
    DeletePOptions options = DeletePOptions.newBuilder().setCommonOptions(PSYNC_ALWAYS).build();
    mFileSystem.delete(new AlluxioURI(alluxioPath(EXISTING_FILE)), options);
}
Also used : DeletePOptions(alluxio.grpc.DeletePOptions) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 8 with DeletePOptions

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

the class UfsJournalIntegrationTest method delete.

/**
 * Tests file and directory creation and deletion.
 */
@Test
public void delete() throws Exception {
    CreateDirectoryPOptions recMkdir = CreateDirectoryPOptions.newBuilder().setRecursive(true).build();
    DeletePOptions recDelete = DeletePOptions.newBuilder().setRecursive(true).build();
    for (int i = 0; i < 10; i++) {
        String dirPath = "/i" + i;
        mFileSystem.createDirectory(new AlluxioURI(dirPath), recMkdir);
        for (int j = 0; j < 10; j++) {
            CreateFilePOptions option = CreateFilePOptions.newBuilder().setBlockSizeBytes((i + j + 1) * 64).build();
            String filePath = dirPath + "/j" + j;
            mFileSystem.createFile(new AlluxioURI(filePath), option).close();
            if (j >= 5) {
                mFileSystem.delete(new AlluxioURI(filePath), recDelete);
            }
        }
        if (i >= 5) {
            mFileSystem.delete(new AlluxioURI(dirPath), recDelete);
        }
    }
    mLocalAlluxioCluster.stopFS();
    deleteTestUtil();
    deleteFsMasterJournalLogs();
    deleteTestUtil();
}
Also used : DeletePOptions(alluxio.grpc.DeletePOptions) CreateDirectoryPOptions(alluxio.grpc.CreateDirectoryPOptions) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 9 with DeletePOptions

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

the class CheckConsistencyCommand method runConsistencyCheck.

/**
 * Checks the inconsistent files and directories which exist in Alluxio but don't exist in the
 * under storage, repairs the inconsistent paths by deleting them if repairConsistency is true.
 *
 * @param path the specified path to be checked
 * @param repairConsistency whether to repair the consistency or not
 * @throws AlluxioException
 * @throws IOException
 */
private void runConsistencyCheck(AlluxioURI path, boolean repairConsistency, int repairThreads) throws AlluxioException, IOException {
    List<AlluxioURI> inconsistentUris = checkConsistency(path, FileSystemOptions.checkConsistencyDefaults(mFsContext.getPathConf(path)));
    if (inconsistentUris.isEmpty()) {
        System.out.println(path + " is consistent with the under storage system.");
        return;
    }
    if (!repairConsistency) {
        Collections.sort(inconsistentUris);
        System.out.println("The following files are inconsistent:");
        for (AlluxioURI uri : inconsistentUris) {
            System.out.println(uri);
        }
    } else {
        Collections.sort(inconsistentUris);
        System.out.println(String.format("%s has: %d inconsistent files. Repairing with %d threads.", path, inconsistentUris.size(), repairThreads));
        ConcurrentHashSet<AlluxioURI> inconsistentDirs = new ConcurrentHashSet<>();
        ExecutorService svc = Executors.newFixedThreadPool(repairThreads);
        CompletionService<Boolean> completionService = new ExecutorCompletionService<>(svc);
        ConcurrentHashSet<Exception> exceptions = new ConcurrentHashSet<>();
        int totalUris = inconsistentUris.size();
        for (AlluxioURI inconsistentUri : inconsistentUris) {
            completionService.submit(() -> {
                try {
                    URIStatus status = mFileSystem.getStatus(inconsistentUri);
                    if (status.isFolder()) {
                        inconsistentDirs.add(inconsistentUri);
                        return;
                    }
                    System.out.println("repairing path: " + inconsistentUri);
                    DeletePOptions deleteOptions = DeletePOptions.newBuilder().setAlluxioOnly(true).build();
                    mFileSystem.delete(inconsistentUri, deleteOptions);
                    mFileSystem.exists(inconsistentUri);
                    System.out.println(inconsistentUri + " repaired");
                    System.out.println();
                } catch (AlluxioException | IOException e) {
                    exceptions.add(e);
                }
            }, true);
        }
        waitForTasks(completionService, totalUris, exceptions);
        int totalDirs = inconsistentDirs.size();
        for (AlluxioURI uri : inconsistentDirs) {
            completionService.submit(() -> {
                try {
                    DeletePOptions deleteOptions = DeletePOptions.newBuilder().setAlluxioOnly(true).setRecursive(true).build();
                    System.out.println("repairing path: " + uri);
                    mFileSystem.delete(uri, deleteOptions);
                    mFileSystem.exists(uri);
                    System.out.println(uri + "repaired");
                    System.out.println();
                } catch (AlluxioException | IOException e) {
                    exceptions.add(e);
                }
            }, true);
        }
        waitForTasks(completionService, totalDirs, exceptions);
        svc.shutdown();
    }
}
Also used : ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) AggregateException(alluxio.exception.AggregateException) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) AlluxioException(alluxio.exception.AlluxioException) IOException(java.io.IOException) DeletePOptions(alluxio.grpc.DeletePOptions) ConcurrentHashSet(alluxio.collections.ConcurrentHashSet) ExecutorService(java.util.concurrent.ExecutorService) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 10 with DeletePOptions

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

the class LoadMetadataCommandIntegrationTest method loadMetadataFileWithWildcard.

@Test
public void loadMetadataFileWithWildcard() throws IOException, AlluxioException {
    String dirPath = "/testRoot/layer1/layer2/layer3/";
    String filePathA = PathUtils.concatPath(dirPath, "testFileA");
    String filePathB = PathUtils.concatPath(dirPath, "testFileB");
    FileSystemTestUtils.createByteFile(sFileSystem, filePathA, WritePType.CACHE_THROUGH, 10);
    FileSystemTestUtils.createByteFile(sFileSystem, filePathB, WritePType.THROUGH, 30);
    AlluxioURI uriA = new AlluxioURI(filePathA);
    AlluxioURI uriB = new AlluxioURI(filePathB);
    URIStatus statusBeforeA = sFileSystem.getStatus(uriA);
    URIStatus statusBeforeB = sFileSystem.getStatus(uriB);
    // Delete testFileA's metadata and testFileB's metadata.
    DeletePOptions deletePOptions = DeletePOptions.newBuilder().setAlluxioOnly(true).setRecursive(true).build();
    sFileSystem.delete(uriA, deletePOptions);
    sFileSystem.delete(uriB, deletePOptions);
    // Load metadata from ufs.
    sFsShell.run("loadMetadata", "/*/*/*/*/testFile*");
    // Use LoadMetadataPType.NEVER to avoid loading metadata during get file status.
    GetStatusPOptions getStatusPOptions = GetStatusPOptions.newBuilder().setLoadMetadataType(LoadMetadataPType.NEVER).build();
    // Check testFileA's metadata.
    URIStatus statusAfterA = sFileSystem.getStatus(uriA, getStatusPOptions);
    assertEquals(statusBeforeA.getFileInfo().getName(), statusAfterA.getFileInfo().getName());
    assertEquals(statusBeforeA.getFileInfo().getLength(), statusAfterA.getFileInfo().getLength());
    // Check testFileB's metadata.
    URIStatus statusAfterB = sFileSystem.getStatus(uriB, getStatusPOptions);
    assertEquals(statusBeforeB.getFileInfo().getName(), statusAfterB.getFileInfo().getName());
    assertEquals(statusBeforeB.getFileInfo().getLength(), statusAfterB.getFileInfo().getLength());
}
Also used : DeletePOptions(alluxio.grpc.DeletePOptions) URIStatus(alluxio.client.file.URIStatus) GetStatusPOptions(alluxio.grpc.GetStatusPOptions) AlluxioURI(alluxio.AlluxioURI) AbstractFileSystemShellTest(alluxio.client.cli.fs.AbstractFileSystemShellTest) Test(org.junit.Test)

Aggregations

DeletePOptions (alluxio.grpc.DeletePOptions)19 AlluxioURI (alluxio.AlluxioURI)15 Test (org.junit.Test)10 URIStatus (alluxio.client.file.URIStatus)6 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)6 IOException (java.io.IOException)6 AlluxioException (alluxio.exception.AlluxioException)5 AbstractFileSystemShellTest (alluxio.client.cli.fs.AbstractFileSystemShellTest)4 GetStatusPOptions (alluxio.grpc.GetStatusPOptions)4 DirectoryNotEmptyException (alluxio.exception.DirectoryNotEmptyException)3 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)3 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)3 FileSystem (alluxio.client.file.FileSystem)2 CreateDirectoryPOptions (alluxio.grpc.CreateDirectoryPOptions)2 CreateFilePOptions (alluxio.grpc.CreateFilePOptions)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Constants (alluxio.Constants)1 FileInStream (alluxio.client.file.FileInStream)1 FileOutStream (alluxio.client.file.FileOutStream)1 ConcurrentHashSet (alluxio.collections.ConcurrentHashSet)1