/** * 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; }
/** * 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; }
/** * 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; }
/** * With node latched, try to lock the current key. Method expects mKeyHash * to be valid. Returns null if lock is required but not immediately available. * * @param txn can be null */ private LockResult tryLockKey(LocalTransaction txn) { LockMode mode; if (txn == null || (mode = txn.lockMode()) == LockMode.READ_COMMITTED) { // If lock is available, no need to acquire full lock and // immediately release it because node is latched. return mTree.isLockAvailable(txn, mKey, mKeyHash) ? LockResult.UNOWNED : null; } try { if (mode.noReadLock) { return LockResult.UNOWNED; } LockResult result = txn.tryLock(mode.repeatable, mTree.mId, mKey, mKeyHash, 0L); return result.isHeld() ? result : null; } catch (DeadlockException e) { // Not expected with timeout of zero anyhow. return null; } }
/** * With node latched, try to lock the current key. Method expects mKeyHash * to be valid. Returns null if lock is required but not immediately available. * * @param txn can be null */ private LockResult tryLockKey(LocalTransaction txn) { LockMode mode; if (txn == null || (mode = txn.lockMode()) == LockMode.READ_COMMITTED) { // If lock is available, no need to acquire full lock and // immediately release it because node is latched. return mTree.isLockAvailable(txn, mKey, mKeyHash) ? LockResult.UNOWNED : null; } try { if (mode.noReadLock) { return LockResult.UNOWNED; } LockResult result = txn.tryLock(mode.repeatable, mTree.mId, mKey, mKeyHash, 0L); return result.isHeld() ? result : null; } catch (DeadlockException e) { // Not expected with timeout of zero anyhow. return null; } }
/** * With node latched, try to lock the current key. Method expects mKeyHash * to be valid. Returns null if lock is required but not immediately available. * * @param txn can be null */ private LockResult tryLockKey(LocalTransaction txn) { LockMode mode; if (txn == null || (mode = txn.lockMode()) == LockMode.READ_COMMITTED) { // If lock is available, no need to acquire full lock and // immediately release it because node is latched. return mTree.isLockAvailable(txn, mKey, mKeyHash) ? LockResult.UNOWNED : null; } try { if (mode.noReadLock) { return LockResult.UNOWNED; } LockResult result = txn.tryLock(mode.repeatable, mTree.mId, mKey, mKeyHash, 0L); return result.isHeld() ? result : null; } catch (DeadlockException e) { // Not expected with timeout of zero anyhow. return null; } }
/** * @param txn non-null */ final void doCommit(LocalTransaction txn, byte[] key, byte[] value) throws IOException { if (txn.lockMode() != LockMode.UNSAFE) { txn.lockExclusive(mTree.mId, key, keyHash()); if (txn.mDurabilityMode != DurabilityMode.NO_REDO) { txn.storeCommit(this, value); return; } } store(txn, leafExclusive(), value); txn.commit(); }
/** * @param requireUndo true if undo logging is required (when key has been locked) * @param txn non-null */ final void doCommit(boolean requireUndo, LocalTransaction txn, byte[] key, byte[] value) throws IOException { if (txn.lockMode() != LockMode.UNSAFE) { txn.lockExclusive(mTree.mId, key, keyHash()); if (txn.mDurabilityMode != DurabilityMode.NO_REDO) { txn.storeCommit(requireUndo, this, value); return; } } store(txn, leafExclusive(), value); txn.commit(); }
int mode = storeMode(); if (mode <= 1) storeRedo: { if (txn.lockMode() != LockMode.UNSAFE) { txn.lockExclusive(mTree.mId, key, keyHash()); if (txn.mDurabilityMode == DurabilityMode.NO_REDO) { break store; } else { if (txn.lockMode() != LockMode.UNSAFE) { txn.lockExclusive(mTree.mId, key, keyHash());
@Override public final void store(byte[] value) throws IOException { byte[] key = mKey; ViewUtils.positionCheck(key); try { LocalTransaction txn = mTxn; if (txn == null) { txn = mTree.mDatabase.newAlwaysRedoTransaction(); try { if (txn.lockMode() != LockMode.UNSAFE) { txn.lockExclusive(mTree.mId, key, keyHash()); } store(txn, leafExclusive(), value); txn.commit(); } catch (Throwable e) { txn.reset(); throw e; } } else { if (txn.lockMode() != LockMode.UNSAFE) { txn.lockExclusive(mTree.mId, key, keyHash()); } store(txn, leafExclusive(), value); } } catch (Throwable e) { throw handleException(e, false); } }
@Override public final void store(byte[] value) throws IOException { final LocalTransaction txn = mTxn; if (txn == null) { storeAutoCommit(value); } else { byte[] key = mKey; ViewUtils.positionCheck(key); try { if (txn.lockMode() != LockMode.UNSAFE) { txn.lockExclusive(mTree.mId, key, keyHash()); } if (storeMode() <= 1) { storeAndRedo(txn, value); } else { storeNoRedo(txn, value); } } catch (Throwable e) { throw handleException(e, false); } } }
@Override public final void store(byte[] value) throws IOException { byte[] key = mKey; ViewUtils.positionCheck(key); try { LocalTransaction txn = mTxn; if (txn == null) { txn = mTree.mDatabase.newAlwaysRedoTransaction(); try { doCommit(true, txn, key, value); } catch (Throwable e) { txn.reset(); throw e; } } else { if (txn.lockMode() != LockMode.UNSAFE) { txn.lockExclusive(mTree.mId, key, keyHash()); } store(txn, leafExclusive(), value); } } catch (Throwable e) { throw handleException(e, false); } }
if (txn.lockMode() == LockMode.UNSAFE) { mKeyHash = 0; } else {
@Override public LockResult touch(Transaction txn, byte[] key) throws LockFailureException { LocalTransaction local = check(txn); LockMode mode; if (local == null || (mode = local.lockMode()) == LockMode.READ_COMMITTED) { int hash = LockManager.hash(mId, key); if (!isLockAvailable(local, key, hash)) { // Acquire and release. if (local == null) { lockSharedLocal(key, hash).unlock(); } else { LockResult result = local.lock(0, mId, key, hash, local.mLockTimeoutNanos); if (result == LockResult.ACQUIRED) { local.unlock(); } } } } else if (!mode.noReadLock) { int hash = LockManager.hash(mId, key); return local.lock(mode.repeatable, mId, key, hash, local.mLockTimeoutNanos); } return LockResult.UNOWNED; }
@Override public void store(byte[] value) throws IOException { byte[] key = mKey; ViewUtils.positionCheck(key); try { final LocalTransaction txn = mTxn; if (txn == null) { final Locker locker = mTree.lockExclusiveLocal(key, keyHash()); try { store(txn, leafExclusive(), value); } finally { locker.unlock(); } } else { if (txn.lockMode() != LockMode.UNSAFE) { txn.lockExclusive(mTree.mId, key, keyHash()); } store(txn, leafExclusive(), value); } } catch (Throwable e) { throw handleException(e, false); } }
@Override public void store(byte[] value) throws IOException { byte[] key = mKey; ViewUtils.positionCheck(key); try { final LocalTransaction txn = mTxn; if (txn == null) { final Locker locker = mTree.lockExclusiveLocal(key, keyHash()); try { store(txn, leafExclusive(), value); } finally { locker.unlock(); } } else { if (txn.lockMode() != LockMode.UNSAFE) { txn.lockExclusive(mTree.mId, key, keyHash()); } store(txn, leafExclusive(), value); } } catch (Throwable e) { throw handleException(e, false); } }
@Override public final void store(byte[] value) throws IOException { byte[] key = mKey; ViewUtils.positionCheck(key); try { final LocalTransaction txn = mTxn; if (txn == null) { store(LocalTransaction.BOGUS, leafExclusive(), value); } else { if (txn.lockMode() != LockMode.UNSAFE) { txn.lockExclusive(mTree.mId, key, keyHash()); } CursorFrame leaf = leafExclusive(); final DurabilityMode dmode = txn.durabilityMode(); if (dmode == DurabilityMode.NO_REDO) { store(txn, leaf, value); } else { txn.durabilityMode(DurabilityMode.NO_REDO); try { store(txn, leaf, value); } finally { txn.durabilityMode(dmode); } } } } catch (Throwable e) { throw handleException(e, false); } }
@Override public final void store(byte[] value) throws IOException { byte[] key = mKey; ViewUtils.positionCheck(key); try { final LocalTransaction txn = mTxn; if (txn == null) { store(LocalTransaction.BOGUS, leafExclusive(), value); } else { if (txn.lockMode() != LockMode.UNSAFE) { txn.lockExclusive(mTree.mId, key, keyHash()); } CursorFrame leaf = leafExclusive(); final DurabilityMode dmode = txn.durabilityMode(); if (dmode == DurabilityMode.NO_REDO) { store(txn, leaf, value); } else { txn.durabilityMode(DurabilityMode.NO_REDO); try { store(txn, leaf, value); } finally { txn.durabilityMode(dmode); } } } } catch (Throwable e) { throw handleException(e, false); } }
store(LocalTransaction.BOGUS, leafExclusive(), value); } else { if (txn.lockMode() != LockMode.UNSAFE) { txn.lockExclusive(mTree.mId, key, keyHash());
store(LocalTransaction.BOGUS, leafExclusive(), value); } else { if (txn.lockMode() != LockMode.UNSAFE) { txn.lockExclusive(mTree.mId, key, keyHash());