void registerTransaction(@NotNull final TransactionBase txn) { checkIfTransactionCreatedAgainstThis(txn); // N.B! due to TransactionImpl.revert(), there can appear a txn which is already in the transaction set // any implementation of transaction set should process this well txns.add(txn); }
boolean isRegistered(@NotNull final ReadWriteTransaction txn) { checkIfTransactionCreatedAgainstThis(txn); return txns.contains(txn); }
void forEachActiveTransaction(@NotNull final TransactionalExecutable executable) { txns.forEach(executable); }
void forEach(@NotNull final TransactionalExecutable executable) { for (final Snapshot snapshot : getCurrent()) { executable.execute(snapshot.txn); } }
int activeTransactions() { return txns.size(); }
@Override public void executeTransactionSafeTask(@NotNull final Runnable task) { final long newestTxnRoot = txns.getNewestTxnRootAddress(); if (newestTxnRoot == Long.MIN_VALUE) { task.run(); } else { synchronized (txnSafeTasks) { txnSafeTasks.addLast(new RunnableWithTxnRoot(task, newestTxnRoot)); } } }
void runTransactionSafeTasks() { if (throwableOnCommit == null) { List<Runnable> tasksToRun = null; final long oldestTxnRoot = txns.getOldestTxnRootAddress(); synchronized (txnSafeTasks) { while (true) { if (!txnSafeTasks.isEmpty()) { final RunnableWithTxnRoot r = txnSafeTasks.getFirst(); if (r.txnRoot < oldestTxnRoot) { txnSafeTasks.removeFirst(); if (tasksToRun == null) { tasksToRun = new ArrayList<>(4); } tasksToRun.add(r.runnable); continue; } } break; } } if (tasksToRun != null) { for (final Runnable task : tasksToRun) { task.run(); } } } }
protected void finishTransaction(@NotNull final TransactionBase txn) { releaseTransaction(txn); txns.remove(txn); txn.setIsFinished(); runTransactionSafeTasks(); }
txns = new TransactionSet(); txnSafeTasks = new LinkedList<>(); invalidateStoreGetCache();
boolean isEmpty() { return getCurrent().isEmpty(); }
private void checkInactive(boolean exceptionSafe) { final int txnCount = txns.size(); if (txnCount > 0) { final String errorString = "Environment[" + getLocation() + "] is active: " + txnCount + " transaction(s) not finished"; if (!exceptionSafe) { loggerError(errorString); } else { loggerInfo(errorString); } if (!exceptionSafe) { reportAliveTransactions(false); } else if (logger.isDebugEnabled()) { reportAliveTransactions(true); } } if (!exceptionSafe) { if (txnCount > 0) { throw new ExodusException("Finish all transactions before closing database environment"); } } }
int size() { return getCurrent().size(); }
boolean contains(@NotNull final TransactionBase txn) { return getCurrent().contains(new Snapshot(txn, 0)); }