Search in sources :

Example 36 with LockResource

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);
}
Also used : Counter(com.codahale.metrics.Counter) LockResource(alluxio.resource.LockResource)

Example 37 with LockResource

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;
}
Also used : LockResource(alluxio.resource.LockResource)

Example 38 with LockResource

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);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LockResource(alluxio.resource.LockResource)

Example 39 with LockResource

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);
    }
}
Also used : LockResource(alluxio.resource.LockResource) AtomicLong(java.util.concurrent.atomic.AtomicLong) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 40 with LockResource

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);
    }
}
Also used : LockResource(alluxio.resource.LockResource) StoreBlockReader(alluxio.worker.block.io.StoreBlockReader) BlockMeta(alluxio.worker.block.meta.BlockMeta) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta)

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