Search in sources :

Example 1 with UfsAbsentPathCache

use of alluxio.master.file.meta.UfsAbsentPathCache in project alluxio by Alluxio.

the class LoadMetadataIntegrationTest method checkFunctionCall.

private Object checkFunctionCall(final String path, CheckedBiFunction<String, Message, Object> function, Message options, boolean expectExistsAlluxio, boolean expectExistsUfs, int expectedAccesses) throws Exception {
    long startMs = CommonUtils.getCurrentMs();
    Object result = null;
    try {
        result = function.apply(path, options);
        UfsAbsentPathCache cache = getUfsAbsentPathCache();
        if (!expectExistsAlluxio) {
            Assert.fail("Path is not expected to exist: " + path);
        }
    } catch (FileDoesNotExistException e) {
        if (expectExistsAlluxio) {
            throw e;
        }
    }
    long durationMs = CommonUtils.getCurrentMs() - startMs;
    assertTrue("Expected to be take between " + expectedAccesses * SLEEP_MS + " and " + (expectedAccesses + 0.5) * SLEEP_MS + ". actual duration (ms): " + durationMs, durationMs >= expectedAccesses * SLEEP_MS && durationMs < (expectedAccesses + 0.5) * SLEEP_MS);
    if (!expectExistsUfs) {
        // The metadata is loaded from Ufs, but the path does not exist, so it will be added to the
        // absent cache. Wait until the path shows up in the absent cache.
        UfsAbsentPathCache cache = getUfsAbsentPathCache();
        try {
            CommonUtils.waitFor("path (" + path + ") to be added to absent cache", () -> cache.isAbsentSince(new AlluxioURI(path), UfsAbsentPathCache.ALWAYS), WaitForOptions.defaults().setTimeoutMs(60000));
        } catch (TimeoutException e) {
            fail("Absent Path Cache addition timed out");
        }
    }
    if (expectExistsUfs) {
        // The metadata is loaded from Ufs, and the path exists, so it will be removed from the
        // absent cache. Wait until the path is removed.
        UfsAbsentPathCache cache = getUfsAbsentPathCache();
        try {
            CommonUtils.waitFor("path (" + path + ") to be removed from absent cache", () -> {
                if (cache.isAbsentSince(new AlluxioURI(path), UfsAbsentPathCache.ALWAYS)) {
                    return false;
                }
                return true;
            }, WaitForOptions.defaults().setTimeoutMs(60000));
        } catch (TimeoutException e) {
            fail("Absent Path Cache removal timed out");
        }
    }
    return result;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) UfsAbsentPathCache(alluxio.master.file.meta.UfsAbsentPathCache) AlluxioURI(alluxio.AlluxioURI) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

AlluxioURI (alluxio.AlluxioURI)1 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)1 UfsAbsentPathCache (alluxio.master.file.meta.UfsAbsentPathCache)1 TimeoutException (java.util.concurrent.TimeoutException)1