ReadWriteTransaction(@NotNull final EnvironmentImpl env, @Nullable final Runnable beginHook, final boolean isExclusive, final boolean cloneMeta) { super(env, isExclusive); mutableTrees = new TreeMap<>(); removedStores = new LongHashMap<>(); createdStores = new HashMapDecorator<>(); this.beginHook = new Runnable() { @Override public void run() { final MetaTreeImpl currentMetaTree = env.getMetaTreeInternal(); setMetaTree(cloneMeta ? currentMetaTree.getClone() : currentMetaTree); env.registerTransaction(ReadWriteTransaction.this); if (beginHook != null) { beginHook.run(); } } }; replayCount = 0; setExclusive(isExclusive() | env.shouldTransactionBeExclusive(this)); env.holdNewestSnapshotBy(this); env.getStatistics().getStatisticsItem(TRANSACTIONS).incTotal(); }
ReadWriteTransaction(@NotNull final TransactionBase origin, @Nullable final Runnable beginHook) { super(origin.getEnvironment(), false); mutableTrees = new TreeMap<>(); removedStores = new LongHashMap<>(); createdStores = new HashMapDecorator<>(); final EnvironmentImpl env = getEnvironment(); this.beginHook = getWrappedBeginHook(beginHook); replayCount = 0; setMetaTree(origin.getMetaTree()); setExclusive(env.shouldTransactionBeExclusive(this)); env.acquireTransaction(this); env.registerTransaction(this); env.getStatistics().getStatisticsItem(TRANSACTIONS).incTotal(); }
@Override public boolean flush() { checkIsFinished(); final EnvironmentImpl env = getEnvironment(); final boolean result = env.flushTransaction(this, false); if (result) { // if the transaction was upgraded to exclusive during re-playing // then it should be downgraded back after successful flush(). if (!wasCreatedExclusive() && isExclusive() && env.getEnvironmentConfig().getEnvTxnDowngradeAfterFlush()) { env.downgradeTransaction(this); setExclusive(false); } setStarted(System.currentTimeMillis()); } else { incReplayCount(); } return result; }
@Override public void revert() { checkIsFinished(); if (isReadonly()) { throw new ExodusException("Attempt ot revert read-only transaction"); } final long oldRoot = getMetaTree().root; final boolean wasExclusive = isExclusive(); final EnvironmentImpl env = getEnvironment(); if (isIdempotent()) { env.holdNewestSnapshotBy(this, false); } else { doRevert(); if (wasExclusive || !env.shouldTransactionBeExclusive(this)) { env.holdNewestSnapshotBy(this, false); } else { env.releaseTransaction(this); setExclusive(true); env.holdNewestSnapshotBy(this); } } if (!env.isRegistered(this)) { throw new ExodusException("Transaction should remain registered after revert"); } if (!checkVersion(oldRoot)) { clearImmutableTrees(); env.runTransactionSafeTasks(); } setStarted(System.currentTimeMillis()); }