protected final int keyHash() { int hash = mKeyHash; if (hash == 0) { mKeyHash = hash = LockManager.hash(mTree.mId, mKey); } return hash; }
private int keyHash() { int hash = mKeyHash; if (hash == 0) { mKeyHash = hash = LockManager.hash(mTree.mId, mKey); } return hash; }
protected final int keyHash() { int hash = mKeyHash; if (hash == 0) { mKeyHash = hash = LockManager.hash(mTree.mId, mKey); } return hash; }
Lock addLock(long indexId, byte[] key) { Lock lock = new Lock(); lock.mIndexId = indexId; lock.mKey = key; lock.mHashCode = LockManager.hash(indexId, key); lock.mLockManagerNext = mTopLock; mTopLock = lock; return lock; }
Lock addLock(long indexId, byte[] key) { Lock lock = new Lock(); lock.mIndexId = indexId; lock.mKey = key; lock.mHashCode = LockManager.hash(indexId, key); lock.mLockManagerNext = mTopLock; mTopLock = lock; return lock; }
Lock addLock(long indexId, byte[] key) { Lock lock = new Lock(); lock.mIndexId = indexId; lock.mKey = key; lock.mHashCode = LockManager.hash(indexId, key); lock.mLockManagerNext = mTopLock; mTopLock = lock; return lock; }
/** * Mark a lock as referencing a ghosted entry. Caller must ensure that lock * is already exclusively held. * * @param frame must be bound to the ghost position */ final void ghosted(long indexId, byte[] key, GhostFrame frame) { ghosted(indexId, key, hash(indexId, key), frame); }
/** * Attempts to acquire an exclusive lock for the given key, denying any * additional locks. If return value is {@link LockResult#alreadyOwned owned}, * transaction already owns exclusive lock, and no extra unlock should be * performed. * * <p><i>Note: This method is intended for advanced use cases.</i> * * @param key non-null key to lock; instance is not cloned * @param nanosTimeout maximum time to wait for lock; negative timeout is infinite * @return {@link LockResult#ACQUIRED ACQUIRED}, {@link LockResult#UPGRADED * UPGRADED}, or {@link LockResult#OWNED_EXCLUSIVE OWNED_EXCLUSIVE} * @throws LockFailureException if interrupted, timed out, or illegal upgrade * @throws DeadlockException if deadlock was detected after waiting full timeout */ public final LockResult lockExclusive(long indexId, byte[] key, long nanosTimeout) throws LockFailureException { return lock(TYPE_EXCLUSIVE, indexId, key, hash(indexId, key), nanosTimeout); }
/** * Attempts to acquire an exclusive lock for the given key, denying any * additional locks. If return value is {@link LockResult#alreadyOwned * owned}, transaction already owns exclusive lock, and no extra unlock * should be performed. If {@link LockResult#ILLEGAL ILLEGAL} is returned, * transaction holds a shared lock, which cannot be upgraded. * * <p><i>Note: This method is intended for advanced use cases.</i> * * @param key non-null key to lock; instance is not cloned * @param nanosTimeout maximum time to wait for lock; negative timeout is infinite * @return {@link LockResult#ILLEGAL ILLEGAL}, {@link * LockResult#INTERRUPTED INTERRUPTED}, {@link LockResult#TIMED_OUT_LOCK * TIMED_OUT_LOCK}, {@link LockResult#ACQUIRED ACQUIRED}, {@link * LockResult#UPGRADED UPGRADED}, or {@link LockResult#OWNED_EXCLUSIVE * OWNED_EXCLUSIVE} * @throws DeadlockException if deadlock was detected after waiting full timeout */ public final LockResult tryLockExclusive(long indexId, byte[] key, long nanosTimeout) throws DeadlockException { return tryLock(TYPE_EXCLUSIVE, indexId, key, hash(indexId, key), nanosTimeout); }
/** * Attempts to acquire a shared lock for the given key, denying exclusive * locks. If return value is {@link LockResult#alreadyOwned owned}, transaction * already owns a strong enough lock, and no extra unlock should be * performed. * * <p><i>Note: This method is intended for advanced use cases.</i> * * @param key non-null key to lock; instance is not cloned * @param nanosTimeout maximum time to wait for lock; negative timeout is infinite * @return {@link LockResult#INTERRUPTED INTERRUPTED}, {@link * LockResult#TIMED_OUT_LOCK TIMED_OUT_LOCK}, {@link LockResult#ACQUIRED * ACQUIRED}, {@link LockResult#OWNED_SHARED OWNED_SHARED}, {@link * LockResult#OWNED_UPGRADABLE OWNED_UPGRADABLE}, or {@link * LockResult#OWNED_EXCLUSIVE OWNED_EXCLUSIVE} * @throws IllegalStateException if too many shared locks * @throws DeadlockException if deadlock was detected after waiting full timeout */ public final LockResult tryLockShared(long indexId, byte[] key, long nanosTimeout) throws DeadlockException { return tryLock(TYPE_SHARED, indexId, key, hash(indexId, key), nanosTimeout); }
/** * Attempts to acquire a shared lock for the given key, denying exclusive * locks. If return value is {@link LockResult#alreadyOwned owned}, transaction * already owns a strong enough lock, and no extra unlock should be * performed. * * <p><i>Note: This method is intended for advanced use cases.</i> * * @param key non-null key to lock; instance is not cloned * @param nanosTimeout maximum time to wait for lock; negative timeout is infinite * @return {@link LockResult#ACQUIRED ACQUIRED}, {@link * LockResult#OWNED_SHARED OWNED_SHARED}, {@link * LockResult#OWNED_UPGRADABLE OWNED_UPGRADABLE}, or {@link * LockResult#OWNED_EXCLUSIVE OWNED_EXCLUSIVE} * @throws IllegalStateException if too many shared locks * @throws LockFailureException if interrupted or timed out * @throws DeadlockException if deadlock was detected after waiting full timeout */ public final LockResult lockShared(long indexId, byte[] key, long nanosTimeout) throws LockFailureException { return lock(TYPE_SHARED, indexId, key, hash(indexId, key), nanosTimeout); }
/** * Attempts to acquire an exclusive lock for the given key, denying any * additional locks. If return value is {@link LockResult#alreadyOwned owned}, * transaction already owns exclusive lock, and no extra unlock should be * performed. * * <p><i>Note: This method is intended for advanced use cases.</i> * * @param key non-null key to lock; instance is not cloned * @param nanosTimeout maximum time to wait for lock; negative timeout is infinite * @return {@link LockResult#ACQUIRED ACQUIRED}, {@link LockResult#UPGRADED * UPGRADED}, or {@link LockResult#OWNED_EXCLUSIVE OWNED_EXCLUSIVE} * @throws LockFailureException if interrupted, timed out, or illegal upgrade * @throws DeadlockException if deadlock was detected after waiting full timeout */ public final LockResult lockExclusive(long indexId, byte[] key, long nanosTimeout) throws LockFailureException { return lock(TYPE_EXCLUSIVE, indexId, key, hash(indexId, key), nanosTimeout); }
/** * Attempts to acquire an upgradable lock for the given key, denying * exclusive and additional upgradable locks. If return value is {@link * LockResult#alreadyOwned owned}, transaction already owns a strong enough * lock, and no extra unlock should be performed. If {@link * LockResult#ILLEGAL ILLEGAL} is returned, transaction holds a shared * lock, which cannot be upgraded. * * <p><i>Note: This method is intended for advanced use cases.</i> * * @param key non-null key to lock; instance is not cloned * @param nanosTimeout maximum time to wait for lock; negative timeout is infinite * @return {@link LockResult#ILLEGAL ILLEGAL}, {@link * LockResult#INTERRUPTED INTERRUPTED}, {@link LockResult#TIMED_OUT_LOCK * TIMED_OUT_LOCK}, {@link LockResult#ACQUIRED ACQUIRED}, {@link * LockResult#OWNED_UPGRADABLE OWNED_UPGRADABLE}, or {@link * LockResult#OWNED_EXCLUSIVE OWNED_EXCLUSIVE} * @throws DeadlockException if deadlock was detected after waiting full timeout */ public final LockResult tryLockUpgradable(long indexId, byte[] key, long nanosTimeout) throws DeadlockException { return tryLock(TYPE_UPGRADABLE, indexId, key, hash(indexId, key), nanosTimeout); }
/** * Attempts to acquire an exclusive lock for the given key, denying any * additional locks. If return value is {@link LockResult#alreadyOwned owned}, * transaction already owns exclusive lock, and no extra unlock should be * performed. * * <p><i>Note: This method is intended for advanced use cases.</i> * * @param key non-null key to lock; instance is not cloned * @param nanosTimeout maximum time to wait for lock; negative timeout is infinite * @return {@link LockResult#ACQUIRED ACQUIRED}, {@link LockResult#UPGRADED * UPGRADED}, or {@link LockResult#OWNED_EXCLUSIVE OWNED_EXCLUSIVE} * @throws LockFailureException if interrupted, timed out, or illegal upgrade * @throws DeadlockException if deadlock was detected after waiting full timeout */ public final LockResult lockExclusive(long indexId, byte[] key, long nanosTimeout) throws LockFailureException { return lock(TYPE_EXCLUSIVE, indexId, key, hash(indexId, key), nanosTimeout); }
/** * Checks the lock ownership for the given key. * * <p><i>Note: This method is intended for advanced use cases.</i> * * @return {@link LockResult#UNOWNED UNOWNED}, {@link * LockResult#OWNED_SHARED OWNED_SHARED}, {@link * LockResult#OWNED_UPGRADABLE OWNED_UPGRADABLE}, or {@link * LockResult#OWNED_EXCLUSIVE OWNED_EXCLUSIVE} */ public final LockResult lockCheck(long indexId, byte[] key) { return manager().check(this, indexId, key, hash(indexId, key)); }
/** * Checks the lock ownership for the given key. * * <p><i>Note: This method is intended for advanced use cases.</i> * * @return {@link LockResult#UNOWNED UNOWNED}, {@link * LockResult#OWNED_SHARED OWNED_SHARED}, {@link * LockResult#OWNED_UPGRADABLE OWNED_UPGRADABLE}, or {@link * LockResult#OWNED_EXCLUSIVE OWNED_EXCLUSIVE} */ public final LockResult lockCheck(long indexId, byte[] key) { return manager().check(this, indexId, key, hash(indexId, key)); }
/** * Checks the lock ownership for the given key. * * <p><i>Note: This method is intended for advanced use cases.</i> * * @return {@link LockResult#UNOWNED UNOWNED}, {@link * LockResult#OWNED_SHARED OWNED_SHARED}, {@link * LockResult#OWNED_UPGRADABLE OWNED_UPGRADABLE}, or {@link * LockResult#OWNED_EXCLUSIVE OWNED_EXCLUSIVE} */ public final LockResult lockCheck(long indexId, byte[] key) { return manager().check(this, indexId, key, hash(indexId, key)); }
/** * Checks validity of key, assigns key and hash code to cursor, and returns the linked * transaction. */ private LocalTransaction prepareFind(byte[] key) { keyCheck(key); LocalTransaction txn = mTxn; int hash; selectHash: { if (txn != null) { LockMode mode = txn.lockMode(); if (mode == LockMode.READ_UNCOMMITTED || mode == LockMode.UNSAFE) { hash = 0; break selectHash; } } hash = LockManager.hash(mTree.mId, key); } mKey = key; mKeyHash = hash; return txn; }
/** * Acquire a shared lock, with infinite timeout, but don't push the lock into the owned * lock stack. Returns the lock which was acquired, or null if already owned. */ final Lock lockSharedNoPush(long indexId, byte[] key) throws LockFailureException { int hash = hash(indexId, key); LockManager.LockHT ht = mManager.getLockHT(hash); Lock lock; LockResult result; ht.acquireExclusive(); try { lock = ht.lockAccess(indexId, key, hash); result = lock.tryLockShared(ht, this, -1); } finally { ht.releaseExclusive(); } if (!result.isHeld()) { throw failed(TYPE_SHARED, result, -1); } return result == LockResult.ACQUIRED ? lock : null; }
/** * Acquire an upgradable lock, with infinite timeout, but don't push the lock into the * owned lock stack. Returns the lock which was acquired, or null if already owned. */ final Lock lockUpgradableNoPush(long indexId, byte[] key) throws LockFailureException { int hash = hash(indexId, key); LockManager.LockHT ht = mManager.getLockHT(hash); Lock lock; LockResult result; ht.acquireExclusive(); try { lock = ht.lockAccess(indexId, key, hash); result = lock.tryLockUpgradable(ht, this, -1); } finally { ht.releaseExclusive(); } if (!result.isHeld()) { throw failed(TYPE_UPGRADABLE, result, -1); } return result == LockResult.ACQUIRED ? lock : null; }