@Nullable @Override TreeMetaInfo getTreeMetaInfo(@NotNull final String name) { checkIsFinished(); final TreeMetaInfo result = createdStores.get(name); return result == null ? super.getTreeMetaInfo(name) : result; }
@NotNull @Override public ITree getTree(@NotNull final StoreImpl store) { checkIsFinished(); final ITreeMutable result = mutableTrees.get(store.getStructureId()); if (result == null) { return super.getTree(store); } return result; }
@Override public boolean commit() { checkIsFinished(); return getEnvironment().commitTransaction(this, false); }
public boolean forceFlush() { checkIsFinished(); return getEnvironment().flushTransaction(this, true); }
@NotNull ITreeMutable getMutableTree(@NotNull final StoreImpl store) { checkIsFinished(); if (getEnvironment().getEnvironmentConfig().getEnvTxnSingleThreadWrites()) { final Thread creatingThread = getCreatingThread(); if (!creatingThread.equals(Thread.currentThread())) { throw new ExodusException("Can't create mutable tree in a thread different from the one which transaction was created in"); } } final int structureId = store.getStructureId(); ITreeMutable result = mutableTrees.get(structureId); if (result == null) { result = getTree(store).getMutableCopy(); mutableTrees.put(structureId, result); } return result; }
@Override public void abort() { checkIsFinished(); clearImmutableTrees(); doRevert(); getEnvironment().finishTransaction(this); }
@NotNull public StoreImpl openStoreByStructureId(final int structureId) { checkIsFinished(); final EnvironmentImpl env = getEnvironment(); final String storeName = getMetaTree().getStoreNameByStructureId(structureId, env); return storeName == null ? new TemporaryEmptyStore(env) : env.openStoreImpl(storeName, StoreConfig.USE_EXISTING, this, getTreeMetaInfo(storeName)); }
void storeRemoved(@NotNull final StoreImpl store) { checkIsFinished(); super.storeRemoved(store); final int structureId = store.getStructureId(); final ITree tree = store.openImmutableTree(getMetaTree()); removedStores.put(structureId, new Pair<>(store.getName(), tree)); mutableTrees.remove(structureId); }
@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()); }