Search in sources :

Example 26 with LockResource

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

the class InodeTreePersistentState method updateTimestampsAndChildCount.

/**
 * Updates the last modification time and last access time for the indicated inode directory,
 * and updates its child count.
 *
 * If the inode's timestamps are already greater than the specified time, the inode's timestamps
 * will not be changed.
 *
 * @param id the inode to update
 * @param opTimeMs the time of the operation that modified the inode
 * @param deltaChildCount the change in inode directory child count
 */
private void updateTimestampsAndChildCount(long id, long opTimeMs, long deltaChildCount) {
    try (LockResource lr = mInodeLockManager.lockUpdate(id)) {
        MutableInodeDirectory inode = mInodeStore.getMutable(id).get().asDirectory();
        boolean madeUpdate = false;
        if (inode.getLastModificationTimeMs() < opTimeMs) {
            inode.setLastModificationTimeMs(opTimeMs);
            madeUpdate = true;
        }
        if (inode.getLastAccessTimeMs() < opTimeMs) {
            inode.setLastAccessTimeMs(opTimeMs);
            madeUpdate = true;
        }
        if (deltaChildCount != 0) {
            inode.setChildCount(inode.getChildCount() + deltaChildCount);
            madeUpdate = true;
        }
        if (madeUpdate) {
            mInodeStore.writeInode(inode);
        }
    }
}
Also used : LockResource(alluxio.resource.LockResource)

Example 27 with LockResource

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

the class HeartbeatScheduler method addTimer.

/**
 * @param timer a timer to add to the scheduler
 */
public static void addTimer(ScheduledTimer timer) {
    Preconditions.checkNotNull(timer, "timer");
    try (LockResource r = new LockResource(sLock)) {
        Preconditions.checkState(!sTimers.containsKey(timer.getThreadName()), "The timer for thread %s is already waiting to be scheduled", timer.getThreadName());
        sTimers.put(timer.getThreadName(), timer);
        sCondition.signalAll();
    }
}
Also used : LockResource(alluxio.resource.LockResource)

Example 28 with LockResource

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

the class HeartbeatScheduler method removeTimer.

/**
 * Removes a timer from the scheduler.
 *
 * This method will fail if the timer is not in the scheduler.
 *
 * @param timer the timer to remove
 */
public static void removeTimer(ScheduledTimer timer) {
    Preconditions.checkNotNull(timer, "timer");
    try (LockResource r = new LockResource(sLock)) {
        ScheduledTimer removedTimer = sTimers.remove(timer.getThreadName());
        Preconditions.checkNotNull(removedTimer, "sTimers should contain %s", timer.getThreadName());
        Preconditions.checkState(removedTimer == timer, "sTimers should contain the timer being removed");
    }
}
Also used : LockResource(alluxio.resource.LockResource)

Example 29 with LockResource

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

the class ScheduledTimer method schedule.

/**
 * Schedules execution of the heartbeat.
 */
protected void schedule() {
    try (LockResource r = new LockResource(mLock)) {
        Preconditions.checkState(!mScheduled, "Called schedule twice without waiting for any ticks");
        mScheduled = true;
        mTickCondition.signal();
        HeartbeatScheduler.removeTimer(this);
    }
}
Also used : LockResource(alluxio.resource.LockResource)

Example 30 with LockResource

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

the class StateLockManagerTest method testGraceMode_Forced.

@Test
public void testGraceMode_Forced() throws Throwable {
    // Enable interrupt-cycle with 100ms interval.
    configureInterruptCycle(true, 100);
    // The state-lock instance.
    StateLockManager stateLockManager = new StateLockManager();
    // Start a thread that owns the state-lock in shared mode.
    StateLockingThread sharedHolderThread = new StateLockingThread(stateLockManager, false);
    sharedHolderThread.start();
    sharedHolderThread.waitUntilStateLockAcquired();
    // Take the state-lock exclusively with GUARANTEED grace mode.
    try (LockResource lr = stateLockManager.lockExclusive(new StateLockOptions(StateLockOptions.GraceMode.FORCED, 10, 0, 100))) {
        // Holder should have been interrupted.
        Assert.assertTrue(sharedHolderThread.lockInterrupted());
        sharedHolderThread.join();
        // Spawn a new thread that waits on the lock.
        StateLockingThread sharedWaiterThread = new StateLockingThread(stateLockManager, false);
        sharedWaiterThread.start();
        // Wait until it's interrupted by the cycle too.
        CommonUtils.waitFor("waiter interrupted", () -> sharedWaiterThread.lockInterrupted());
        sharedWaiterThread.join();
    }
}
Also used : LockResource(alluxio.resource.LockResource) Test(org.junit.Test)

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