Search in sources :

Example 1 with FreePOptions

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

the class BaseFileSystem method free.

@Override
public void free(AlluxioURI path, final FreePOptions options) throws FileDoesNotExistException, IOException, AlluxioException {
    checkUri(path);
    rpc(client -> {
        FreePOptions mergedOptions = FileSystemOptions.freeDefaults(mFsContext.getPathConf(path)).toBuilder().mergeFrom(options).build();
        client.free(path, mergedOptions);
        LOG.debug("Freed {}, options: {}", path.getPath(), mergedOptions);
        return null;
    });
}
Also used : FreePOptions(alluxio.grpc.FreePOptions)

Example 2 with FreePOptions

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

the class FreeContext method mergeFrom.

/**
 * Merges and embeds the given {@link FreePOptions} with the corresponding master options.
 *
 * @param optionsBuilder Builder for proto {@link FreePOptions} to merge with defaults
 * @return the instance of {@link FreeContext} with default values for master
 */
public static FreeContext mergeFrom(FreePOptions.Builder optionsBuilder) {
    FreePOptions masterOptions = FileSystemOptions.freeDefaults(ServerConfiguration.global());
    FreePOptions.Builder mergedOptionsBuilder = masterOptions.toBuilder().mergeFrom(optionsBuilder.build());
    return create(mergedOptionsBuilder);
}
Also used : FreePOptions(alluxio.grpc.FreePOptions)

Example 3 with FreePOptions

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

the class BaseFileSystemTest method free.

/**
 * Tests for the {@link BaseFileSystem#free(AlluxioURI, FreePOptions)} method.
 */
@Test
public void free() throws Exception {
    AlluxioURI file = new AlluxioURI("/file");
    FreePOptions freeOptions = FreePOptions.newBuilder().setRecursive(true).build();
    mFileSystem.free(file, freeOptions);
    verify(mFileSystemMasterClient).free(file, FileSystemOptions.freeDefaults(mConf).toBuilder().mergeFrom(freeOptions).build());
    verifyFilesystemContextAcquiredAndReleased();
}
Also used : FreePOptions(alluxio.grpc.FreePOptions) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with FreePOptions

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

the class FreeCommand method runPlainPath.

@Override
protected void runPlainPath(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
    int interval = Math.toIntExact(mFsContext.getPathConf(path).getMs(PropertyKey.WORKER_BLOCK_HEARTBEAT_INTERVAL_MS));
    FreePOptions options = FreePOptions.newBuilder().setRecursive(true).setForced(cl.hasOption("f")).build();
    mFileSystem.free(path, options);
    try {
        CommonUtils.waitFor("file to be freed. Another user may be loading it.", () -> {
            try {
                URIStatus fileStatus = mFileSystem.getStatus(path);
                if (fileStatus.getLength() == 0 && !fileStatus.isFolder()) {
                    // but 'free' on an empty file should be a no-op
                    return true;
                }
                if (fileStatus.getInAlluxioPercentage() > 0) {
                    mFileSystem.free(path, options);
                    return fileStatus.getInAlluxioPercentage() == 0;
                } else {
                    return true;
                }
            } catch (Exception e) {
                Throwables.propagateIfPossible(e);
                throw new RuntimeException(e);
            }
        }, WaitForOptions.defaults().setTimeoutMs(10 * Math.toIntExact(interval)).setInterval(interval));
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new RuntimeException(e);
    } catch (TimeoutException e) {
        throw new RuntimeException(e);
    }
    System.out.println(path + " was successfully freed from Alluxio space.");
}
Also used : FreePOptions(alluxio.grpc.FreePOptions) URIStatus(alluxio.client.file.URIStatus) TimeoutException(java.util.concurrent.TimeoutException) AlluxioException(alluxio.exception.AlluxioException) IOException(java.io.IOException) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with FreePOptions

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

the class BaseFileSystemTest method freeException.

/**
 * Ensures that an exception is propagated correctly when freeing a file.
 */
@Test
public void freeException() throws Exception {
    AlluxioURI file = new AlluxioURI("/file");
    FreePOptions freeOptions = FreePOptions.newBuilder().setRecursive(true).build();
    doThrow(EXCEPTION).when(mFileSystemMasterClient).free(file, FileSystemOptions.freeDefaults(mConf).toBuilder().mergeFrom(freeOptions).build());
    try {
        mFileSystem.free(file, freeOptions);
        fail(SHOULD_HAVE_PROPAGATED_MESSAGE);
    } catch (Exception e) {
        assertSame(EXCEPTION, e);
    }
    verifyFilesystemContextAcquiredAndReleased();
}
Also used : FreePOptions(alluxio.grpc.FreePOptions) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

FreePOptions (alluxio.grpc.FreePOptions)5 AlluxioURI (alluxio.AlluxioURI)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 URIStatus (alluxio.client.file.URIStatus)1 AlluxioException (alluxio.exception.AlluxioException)1 InvalidArgumentException (alluxio.exception.status.InvalidArgumentException)1 IOException (java.io.IOException)1 TimeoutException (java.util.concurrent.TimeoutException)1