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);
}
}
}
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();
}
}
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");
}
}
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);
}
}
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();
}
}
Aggregations