@Override public void store(byte[] value) throws IOException { byte[] key = mKey; ViewUtils.positionCheck(key); Transaction txn = mTxn; if (txn == null) { txn = mView.newTransaction(null); try { store(txn, key, value); txn.commit(); } finally { txn.reset(); } } else if (txn.lockMode() != LockMode.UNSAFE) { txn.enter(); try { txn.lockMode(LockMode.UPGRADABLE_READ); store(txn, key, value); txn.commit(); } finally { txn.exit(); } } else { store(txn, key, value); } }
@Override public void commit() throws BackendException { log.trace("commit txn={}, id={}", txn, id); try { txn.commit(); txn.exit(); if(DurabilityMode.NO_REDO == txn.durabilityMode()) { //TODO should I always call checkpoint? database.checkpoint(); } } catch (IOException e) { throw new PermanentBackendException("unable to commit tx " + id, e); } }
@Override public boolean txnLockExclusive(long txnId, long indexId, byte[] key) throws IOException { Transaction txn = txn(txnId); if (txn != null) { txn.lockExclusive(indexId, key); } return true; }
try { txn.lockMode(LockMode.UNSAFE); byte[] key = new byte[8]; encodeLongBE(key, 0, index); txn.lockExclusive(mPageCopyIndex.getId(), key); txn.commit(); txn.reset();
txn.lockTimeout(-1, null); txn.commit(); txn.reset();
createTxn.lockTimeout(-1, null); try { if (createTxn != null) { createTxn.reset(); createTxn.commit(); } catch (Throwable e) { try { createTxn.reset(); mRegistry.delete(Transaction.BOGUS, treeIdBytes); } catch (Throwable e2) { txn.lockTimeout(-1, null); if (txn.lockCheck(mRegistry.getId(), treeIdBytes) != LockResult.UNOWNED) { throw new LockFailureException("Index open listener self deadlock"); txn.reset();
@Override public byte[] load(Transaction txn, byte[] key) throws IOException { if (mCombiner.combineLocks()) combine: { if (txn == null) { txn = newTransaction(null); txn.lockMode(LockMode.REPEATABLE_READ); } else if (txn.lockMode() == LockMode.READ_COMMITTED) { txn.enter(); } else { break combine; } try { return doLoad(txn, key); } finally { txn.exit(); } } return doLoad(txn, key); }
/** * Reset the transaction due to the given cause. This provides an opportunity to prevent * this transaction from being used any further. No exception is thrown when invoking this * method. * * @param cause pass a cause to reset and disable the transaction; pass null to simply * reset the transaction and ignore any exception when doing so */ default void reset(Throwable cause) { try { reset(); } catch (Throwable e) { // Ignore. } }
@Override public void exitTransaction(@Nonnull Transaction tx) throws IOException { tx.exit(); } }
private boolean txnInsert(Transaction txn, byte[] key, byte[] value) throws IOException { final DurabilityMode dmode = txn.durabilityMode(); if (dmode == DurabilityMode.NO_REDO) { return super.insert(txn, key, value); } else { txn.durabilityMode(DurabilityMode.NO_REDO); try { return super.insert(txn, key, value); } finally { txn.durabilityMode(dmode); } } }
@Override public void commitTransaction(@Nonnull Transaction tx) throws IOException { tx.commit(); }
private void resetTxnMode() { LockMode original = mOriginalMode; if (original != null) { mOriginalMode = null; mCursor.link().lockMode(original); } } }
static RuntimeException lockCleanup(Throwable e, Transaction txn, LockResult result) { if (result.isAcquired()) { try { txn.unlock(); } catch (Throwable e2) { Utils.suppress(e, e2); } } throw Utils.rethrow(e); }
static LockResult tryLock(Transaction txn, byte[] key, long nanosTimeout, LockAction action) throws DeadlockException, ViewConstraintException { final long originalTimeout = txn.lockTimeout(TimeUnit.NANOSECONDS); try { txn.lockTimeout(nanosTimeout, TimeUnit.NANOSECONDS); return action.lock(txn, key); } catch (DeadlockException e) { throw e; } catch (IllegalUpgradeException e) { return LockResult.ILLEGAL; } catch (LockInterruptedException e) { return LockResult.INTERRUPTED; } catch (LockFailureException e) { return LockResult.TIMED_OUT_LOCK; } finally { txn.lockTimeout(originalTimeout, TimeUnit.NANOSECONDS); } }
static Transaction enterScope(View view, Transaction txn) throws IOException { if (txn == null) { txn = view.newTransaction(null); } else if (txn != Transaction.BOGUS) { txn.enter(); } return txn; }
try { txn.lockMode(LockMode.UNSAFE); byte[] key = new byte[8]; encodeLongBE(key, 0, index); txn.lockExclusive(mPageCopyIndex.getId(), key); txn.commit(); txn.reset();
txn.lockTimeout(-1, null); txn.commit(); txn.reset();