Search in sources :

Example 96 with LockResource

use of alluxio.resource.LockResource in project alluxio by Alluxio.

the class LockPoolTest method getKeys.

private Thread getKeys(int low, int high) {
    Thread t = new Thread(() -> {
        for (int i = low; i < high; i++) {
            try (LockResource resource = mPool.get(i, LockMode.READ)) {
            // Empty.
            }
        }
    });
    t.start();
    return t;
}
Also used : LockResource(alluxio.resource.LockResource)

Example 97 with LockResource

use of alluxio.resource.LockResource in project alluxio by Alluxio.

the class LockPoolTest method insertValueTest.

@Test(timeout = 10000)
public void insertValueTest() throws Exception {
    // Fills cache until high watermark.
    for (int key = 0; key < HIGH_WATERMARK; key++) {
        assertEquals(key, mPool.size());
        try (LockResource resource = mPool.get(key, LockMode.READ)) {
            assertTrue(mPool.containsKey(key));
            assertEquals(key + 1, mPool.size());
        }
    }
    // Exceeds high watermark, will be evicted until low watermark.
    try (LockResource r = mPool.get(HIGH_WATERMARK, LockMode.READ)) {
        assertTrue(mPool.containsKey(HIGH_WATERMARK));
        CommonUtils.waitFor("Pool size to go below low watermark", () -> mPool.size() <= LOW_WATERMARK);
        assertEquals(LOW_WATERMARK, mPool.size());
    }
    // Fills cache until high watermark again.
    for (int newLock = 1; newLock <= HIGH_WATERMARK - LOW_WATERMARK; newLock++) {
        int key = HIGH_WATERMARK + newLock;
        try (LockResource resource = mPool.get(key, LockMode.READ)) {
            assertTrue(mPool.containsKey(key));
            assertEquals(LOW_WATERMARK + newLock, mPool.size());
        }
    }
    // Exceeds high watermark, will be evicted until low watermark.
    try (LockResource r = mPool.get(2 * HIGH_WATERMARK, LockMode.READ)) {
        assertTrue(mPool.containsKey(2 * HIGH_WATERMARK));
        CommonUtils.waitFor("Pool size to go below low watermark", () -> mPool.size() <= LOW_WATERMARK);
        assertEquals(LOW_WATERMARK, mPool.size());
    }
}
Also used : LockResource(alluxio.resource.LockResource) Test(org.junit.Test)

Example 98 with LockResource

use of alluxio.resource.LockResource in project alluxio by Alluxio.

the class MountTable method resolve.

/**
 * Resolves the given Alluxio path. If the given Alluxio path is nested under a mount point, the
 * resolution maps the Alluxio path to the corresponding UFS path. Otherwise, the resolution is a
 * no-op.
 *
 * @param uri an Alluxio path URI
 * @return the {@link Resolution} representing the UFS path
 * @throws InvalidPathException if an invalid path is encountered
 */
public Resolution resolve(AlluxioURI uri) throws InvalidPathException {
    try (LockResource r = new LockResource(mReadLock)) {
        String path = uri.getPath();
        LOG.debug("Resolving {}", path);
        PathUtils.validatePath(uri.getPath());
        // This will re-acquire the read lock, but that is allowed.
        String mountPoint = getMountPoint(uri);
        if (mountPoint != null) {
            MountInfo info = mState.getMountTable().get(mountPoint);
            AlluxioURI ufsUri = info.getUfsUri();
            UfsManager.UfsClient ufsClient;
            AlluxioURI resolvedUri;
            try {
                ufsClient = mUfsManager.get(info.getMountId());
                try (CloseableResource<UnderFileSystem> ufsResource = ufsClient.acquireUfsResource()) {
                    UnderFileSystem ufs = ufsResource.get();
                    resolvedUri = ufs.resolveUri(ufsUri, path.substring(mountPoint.length()));
                }
            } catch (NotFoundException | UnavailableException e) {
                throw new RuntimeException(String.format("No UFS information for %s for mount Id %d, we should never reach here", uri, info.getMountId()), e);
            }
            return new Resolution(resolvedUri, ufsClient, info.getOptions().getShared(), info.getMountId());
        }
        // TODO(binfan): throw exception as we should never reach here
        return new Resolution(uri, null, false, IdUtils.INVALID_MOUNT_ID);
    }
}
Also used : UfsManager(alluxio.underfs.UfsManager) UnavailableException(alluxio.exception.status.UnavailableException) NotFoundException(alluxio.exception.status.NotFoundException) MountInfo(alluxio.master.file.meta.options.MountInfo) LockResource(alluxio.resource.LockResource) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI)

Example 99 with LockResource

use of alluxio.resource.LockResource in project alluxio by Alluxio.

the class HeartbeatScheduler method schedule.

/**
 * Schedules execution of a heartbeat for the given thread.
 *
 * @param threadName a name of the thread for which heartbeat is to be executed
 */
public static void schedule(String threadName) {
    try (LockResource r = new LockResource(sLock)) {
        ScheduledTimer timer = sTimers.get(threadName);
        if (timer == null) {
            throw new RuntimeException("Timer for thread " + threadName + " not found.");
        }
        timer.schedule();
    }
}
Also used : LockResource(alluxio.resource.LockResource)

Example 100 with LockResource

use of alluxio.resource.LockResource in project alluxio by Alluxio.

the class ScheduledTimer method tick.

/**
 * Waits until the heartbeat is scheduled for execution.
 *
 * @throws InterruptedException if the thread is interrupted while waiting
 */
public void tick() throws InterruptedException {
    try (LockResource r = new LockResource(mLock)) {
        HeartbeatScheduler.addTimer(this);
        // Wait in a loop to handle spurious wakeups
        while (!mScheduled) {
            mTickCondition.await();
        }
        mScheduled = false;
    }
}
Also used : LockResource(alluxio.resource.LockResource)

Aggregations

LockResource (alluxio.resource.LockResource)116 IOException (java.io.IOException)14 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)13 HashMap (java.util.HashMap)12 BlockAlreadyExistsException (alluxio.exception.BlockAlreadyExistsException)11 BlockDoesNotExistException (alluxio.exception.BlockDoesNotExistException)11 Map (java.util.Map)11 AlluxioURI (alluxio.AlluxioURI)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)10 WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)9 ArrayList (java.util.ArrayList)9 MasterWorkerInfo (alluxio.master.block.meta.MasterWorkerInfo)8 InvalidPathException (alluxio.exception.InvalidPathException)7 NotFoundException (alluxio.exception.status.NotFoundException)7 List (java.util.List)7 Lock (java.util.concurrent.locks.Lock)7 ConcurrentHashSet (alluxio.collections.ConcurrentHashSet)6 InvalidWorkerStateException (alluxio.exception.InvalidWorkerStateException)6 UnavailableException (alluxio.exception.status.UnavailableException)6