Search in sources :

Example 1 with CheckConsistencyOptions

use of alluxio.client.file.options.CheckConsistencyOptions in project alluxio by Alluxio.

the class CheckConsistencyCommand method checkConsistency.

private void checkConsistency(AlluxioURI path, boolean repairConsistency) throws AlluxioException, IOException {
    CheckConsistencyOptions options = CheckConsistencyOptions.defaults();
    List<AlluxioURI> inconsistentUris = FileSystemUtils.checkConsistency(path, options);
    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(path + " has: " + inconsistentUris.size() + " inconsistent files.");
        List<AlluxioURI> inconsistentDirs = new ArrayList<AlluxioURI>();
        for (int i = 0; i < inconsistentUris.size(); i++) {
            AlluxioURI inconsistentUri = inconsistentUris.get(i);
            URIStatus status = mFileSystem.getStatus(inconsistentUri);
            if (status.isFolder()) {
                inconsistentDirs.add(inconsistentUri);
                continue;
            }
            System.out.println("repairing path: " + inconsistentUri);
            DeleteOptions deleteOptions = DeleteOptions.defaults().setAlluxioOnly(true);
            mFileSystem.delete(inconsistentUri, deleteOptions);
            mFileSystem.exists(inconsistentUri);
            System.out.println(inconsistentUri + " repaired");
            System.out.println();
        }
        for (AlluxioURI uri : inconsistentDirs) {
            DeleteOptions deleteOptions = DeleteOptions.defaults().setAlluxioOnly(true).setRecursive(true);
            System.out.println("repairing path: " + uri);
            mFileSystem.delete(uri, deleteOptions);
            mFileSystem.exists(uri);
            System.out.println(uri + "repaired");
            System.out.println();
        }
    }
}
Also used : DeleteOptions(alluxio.client.file.options.DeleteOptions) ArrayList(java.util.ArrayList) CheckConsistencyOptions(alluxio.client.file.options.CheckConsistencyOptions) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI)

Aggregations

AlluxioURI (alluxio.AlluxioURI)1 URIStatus (alluxio.client.file.URIStatus)1 CheckConsistencyOptions (alluxio.client.file.options.CheckConsistencyOptions)1 DeleteOptions (alluxio.client.file.options.DeleteOptions)1 ArrayList (java.util.ArrayList)1