use of alluxio.resource.LockResource in project alluxio by Alluxio.
the class MetricsStore method clear.
/**
* Clears all the metrics.
*
* This method should only be called when starting the {@link DefaultMetricsMaster}
* and before starting the metrics updater to avoid conflicts with
* other methods in this class which updates or accesses
* the metrics inside metrics sets.
*/
public void clear() {
long start = System.currentTimeMillis();
try (LockResource r = new LockResource(mLock.writeLock())) {
for (Counter counter : mClusterCounters.values()) {
counter.dec(counter.getCount());
}
mLastClearTime = mClock.millis();
MetricsSystem.resetAllMetrics();
}
LOG.info("Cleared the metrics store and metrics system in {} ms", System.currentTimeMillis() - start);
}
use of alluxio.resource.LockResource in project alluxio by Alluxio.
the class SignalBlockMaster method lockBlock.
@Override
LockResource lockBlock(long blockId) {
LockResource res = super.lockBlock(blockId);
// The latch can receive more signals than the countdown number
// But the CountdownLatch guarantees nothing happens if the countdown is already 0
mLatch.countDown();
return res;
}
use of alluxio.resource.LockResource in project alluxio by Alluxio.
the class InodeLockManagerTest method inodeLockTest.
private void inodeLockTest(LockMode take, LockMode tryToTake, boolean expectBlocking) throws Exception {
InodeLockManager lockManager = new InodeLockManager();
AtomicBoolean threadFinished = new AtomicBoolean(false);
MutableInodeFile inode = MutableInodeFile.create(0, 0, "name", 0, CreateFileContext.defaults());
LockResource lock = lockManager.lockInode(inode, take, false);
Thread t = new Thread(() -> {
// Copy the inode to make sure we aren't comparing inodes by reference.
MutableInodeFile inodeCopy = MutableInodeFile.fromJournalEntry(inode.toJournalEntry().getInodeFile());
try (LockResource lr = lockManager.lockInode(inodeCopy, tryToTake, false)) {
threadFinished.set(true);
}
});
t.start();
if (expectBlocking) {
CommonUtils.sleepMs(20);
assertFalse(threadFinished.get());
lock.close();
}
CommonUtils.waitFor("lock to be acquired by the second thread", threadFinished::get);
}
use of alluxio.resource.LockResource in project alluxio by Alluxio.
the class BlockLockManager method cleanupSession.
/**
* Cleans up the locks currently hold by a specific session.
*
* @param sessionId the id of the session to cleanup
*/
public void cleanupSession(long sessionId) {
try (LockResource r = new LockResource(mSharedMapsLock.writeLock())) {
Set<Long> sessionLockIds = mSessionIdToLockIdsMap.get(sessionId);
if (sessionLockIds == null) {
return;
}
for (long lockId : sessionLockIds) {
LockRecord record = mLockIdToRecordMap.get(lockId);
if (record == null) {
LOG.error(ExceptionMessage.LOCK_RECORD_NOT_FOUND_FOR_LOCK_ID.getMessage(lockId));
continue;
}
Lock lock = record.getLock();
unlock(lock, record.getBlockId());
mLockIdToRecordMap.remove(lockId);
}
mSessionIdToLockIdsMap.remove(sessionId);
}
}
use of alluxio.resource.LockResource in project alluxio by Alluxio.
the class TieredBlockStore method getBlockReader.
@Override
public BlockReader getBlockReader(long sessionId, long blockId, long lockId) throws BlockDoesNotExistException, InvalidWorkerStateException, IOException {
LOG.debug("getBlockReader: sessionId={}, blockId={}, lockId={}", sessionId, blockId, lockId);
mLockManager.validateLock(sessionId, blockId, lockId);
try (LockResource r = new LockResource(mMetadataReadLock)) {
BlockMeta blockMeta = mMetaManager.getBlockMeta(blockId);
return new StoreBlockReader(sessionId, blockMeta);
}
}
Aggregations