@Test public void cleanupSession() throws Exception { long sessionId1 = TEST_SESSION_ID; long sessionId2 = TEST_SESSION_ID + 1; long lockId1 = mLockManager.lockBlock(sessionId1, TEST_BLOCK_ID, BlockLockType.READ); long lockId2 = mLockManager.lockBlock(sessionId2, TEST_BLOCK_ID, BlockLockType.READ); mThrown.expect(BlockDoesNotExistException.class); mThrown.expectMessage(ExceptionMessage.LOCK_RECORD_NOT_FOUND_FOR_LOCK_ID.getMessage(lockId2)); mLockManager.cleanupSession(sessionId2); mLockManager.validateLock(sessionId1, TEST_BLOCK_ID, lockId1); mLockManager.validateLock(sessionId2, TEST_BLOCK_ID, lockId2); }
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); } }
BlockLockManager { 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); } } }
BlockLockManager { 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); } } BlockLockManager(); }
BlockLockManager { 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); } } BlockLockManager(); long lockBlock(long sessionId, long blockId, BlockLockType blockLockType); boolean unlockBlockNoException(long lockId); void unlockBlock(long lockId); boolean unlockBlock(long sessionId, long blockId); void validateLock(long sessionId, long blockId, long lockId); void cleanupSession(long sessionId); Set<Long> getLockedBlocks(); void validate(); }
BlockLockManager { 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); } } BlockLockManager(); long lockBlock(long sessionId, long blockId, BlockLockType blockLockType); boolean unlockBlockNoException(long lockId); void unlockBlock(long lockId); boolean unlockBlock(long sessionId, long blockId); void validateLock(long sessionId, long blockId, long lockId); void cleanupSession(long sessionId); Set<Long> getLockedBlocks(); void validate(); static final long INVALID_LOCK_ID; }