final _Locker lockExclusiveLocal(long indexId, byte[] key, int hash) throws LockFailureException { _Locker locker = localLocker(); LockResult result = getLockHT(hash) .tryLock(TYPE_EXCLUSIVE, locker, indexId, key, hash, mDefaultTimeoutNanos); if (result.isHeld()) { return locker; } throw locker.failed(TYPE_EXCLUSIVE, result, mDefaultTimeoutNanos); }
final _Locker lockSharedLocal(long indexId, byte[] key, int hash) throws LockFailureException { _Locker locker = localLocker(); LockResult result = getLockHT(hash) .tryLock(TYPE_SHARED, locker, indexId, key, hash, mDefaultTimeoutNanos); if (result.isHeld()) { return locker; } throw locker.failed(TYPE_SHARED, result, mDefaultTimeoutNanos, hash); }
final _Locker lockSharedLocal(long indexId, byte[] key, int hash) throws LockFailureException { _Locker locker = localLocker(); LockResult result = getLockHT(hash) .tryLock(TYPE_SHARED, locker, indexId, key, hash, mDefaultTimeoutNanos); if (result.isHeld()) { return locker; } throw locker.failed(TYPE_SHARED, result, mDefaultTimeoutNanos); }
final _Locker lockExclusiveLocal(long indexId, byte[] key, int hash) throws LockFailureException { _Locker locker = localLocker(); LockResult result = getLockHT(hash) .tryLock(TYPE_EXCLUSIVE, locker, indexId, key, hash, mDefaultTimeoutNanos); if (result.isHeld()) { return locker; } throw locker.failed(TYPE_EXCLUSIVE, result, mDefaultTimeoutNanos); }
final _Locker lockExclusiveLocal(long indexId, byte[] key, int hash) throws LockFailureException { _Locker locker = localLocker(); LockResult result = getLockHT(hash) .tryLock(TYPE_EXCLUSIVE, locker, indexId, key, hash, mDefaultTimeoutNanos); if (result.isHeld()) { return locker; } throw locker.failed(TYPE_EXCLUSIVE, result, mDefaultTimeoutNanos, hash); }
final _Locker lockSharedLocal(long indexId, byte[] key, int hash) throws LockFailureException { _Locker locker = localLocker(); LockResult result = getLockHT(hash) .tryLock(TYPE_SHARED, locker, indexId, key, hash, mDefaultTimeoutNanos); if (result.isHeld()) { return locker; } throw locker.failed(TYPE_SHARED, result, mDefaultTimeoutNanos); }
@Override public boolean store(long indexId, byte[] key, byte[] value) throws IOException { Index ix = getIndex(indexId); // Allow side-effect free operations to be performed before acquiring latch. mOpLatch.acquireShared(); // Locks must be acquired in their original order to avoid // deadlock, so don't allow another task thread to run yet. _Locker locker = mDatabase.mLockManager.localLocker(); locker.lockExclusive(indexId, key, INFINITE_TIMEOUT); // Allow another task thread to run while operation completes. nextTask(); try { while (ix != null) { try { ix.store(Transaction.BOGUS, key, value); break; } catch (ClosedIndexException e) { // User closed the shared index reference, so re-open it. ix = openIndex(indexId, null); } } } finally { locker.scopeUnlockAll(); } // Only release if no exception. mOpLatch.releaseShared(); notifyStore(ix, key, value); // Return false to prevent RedoDecoder from looping back. return false; }