@Override public void beforeBackup() { environment.suspendGC(); environment.flushAndSync(); }
@NotNull public static Environment newInstance(@NotNull final Log log, @NotNull final EnvironmentConfig ec) { return prepare(new EnvironmentImpl(log, ec)); }
@Override public void executeInReadonlyTransaction(@NotNull TransactionalExecutable executable) { final Transaction txn = beginReadonlyTransaction(); try { executable.execute(txn); } finally { abortIfNotFinished(txn); } }
@Override public void executeInExclusiveTransaction(@NotNull final TransactionalExecutable executable) { executeInTransaction(executable, beginExclusiveTransaction()); }
@Override public <T> T computeInExclusiveTransaction(@NotNull TransactionalComputable<T> computable) { return computeInTransaction(computable, beginExclusiveTransaction()); }
@NotNull final TransactionBase txn, @Nullable TreeMetaInfo metaInfo) { checkIfTransactionCreatedAgainstThis(txn); if (config.useExisting) { // this parameter requires to recalculate if (metaInfo == null) { if (metaInfo == null) { if (txn.isReadonly() && ec.getEnvReadonlyEmptyStores()) { return createTemporaryEmptyStore(name); final int structureId = allocateStructureId(); metaInfo = TreeMetaInfo.load(this, config.duplicates, config.prefixing, structureId); result = createStore(name, metaInfo); final ReadWriteTransaction tx = throwIfReadonly(txn, "Can't create a store in read-only transaction"); tx.getMutableTree(result); tx.storeCreated(result); result = createStore(name, metaInfo);
this.log = log; this.ec = ec; applyEnvironmentSettings(log.getLocation(), ec); txns = new TransactionSet(); txnSafeTasks = new LinkedList<>(); invalidateStoreGetCache(); envSettingsListener = new EnvironmentSettingsListener(); ec.addChangedSettingsListener(envSettingsListener); throwableOnClose = null; stuckTxnMonitor = (transactionTimeout() > 0 || transactionExpirationTimeout() > 0) ? new StuckTransactionMonitor(this) : null; cipherBasicIV = logConfig.getCipherBasicIV(); loggerInfo("Exodus environment created: " + log.getLocation());
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 void truncateStore(@NotNull final String storeName, @NotNull final Transaction txn) { final ReadWriteTransaction t = throwIfReadonly(txn, "Can't truncate a store in read-only transaction"); StoreImpl store = openStore(storeName, StoreConfig.USE_EXISTING, t, false); if (store == null) { throw new ExodusException("Attempt to truncate unknown store '" + storeName + '\''); } t.storeRemoved(store); final TreeMetaInfo metaInfoCloned = store.getMetaInfo().clone(allocateStructureId()); store = new StoreImpl(this, storeName, metaInfoCloned); t.storeCreated(store); }
/** * Constructor for creating new snapshot transaction. */ ReadonlyTransaction(@NotNull final TransactionBase origin) { super(origin.getEnvironment(), false); beginHook = null; setMetaTree(origin.getMetaTree()); final EnvironmentImpl env = getEnvironment(); env.acquireTransaction(this); env.registerTransaction(this); env.getStatistics().getStatisticsItem(READONLY_TRANSACTIONS).incTotal(); }
private synchronized void close() { if (nonNull(this.entityStore)) { try { EnvironmentImpl environment = (EnvironmentImpl) this.entityStore.getEnvironment(); environment.flushAndSync(); this.entityStore.close(); } catch (ExodusException e) { // wait transaction try { Thread.sleep(1000 * 3); } catch (InterruptedException e1) { log.catching(e1); } this.entityStore.close(); } this.entityStore = null; } if (nonNull(this.environment)) { this.environment.close(); this.environment = null; } }
@NotNull @Override public Transaction beginReadonlyTransaction() { return beginReadonlyTransaction(null); }
private static void executeInTransaction(@NotNull final TransactionalExecutable executable, @NotNull final Transaction txn) { try { while (true) { executable.execute(txn); if (txn.isReadonly() || // txn can be read-only if Environment is in read-only mode txn.isFinished() || // txn can be finished if, e.g., it was aborted within executable txn.flush()) { break; } txn.revert(); } } finally { abortIfNotFinished(txn); } }
@NotNull @Override public ReadWriteTransaction beginGCTransaction() { final ReadWriteTransaction result = super.beginGCTransaction(); setCurrentTransaction(result); return result; }
@Nullable @Override protected Long getAutoUpdatedTotal() { final EnvironmentStatistics statistics = (EnvironmentStatistics) getStatistics(); return statistics == null ? null : (long) (statistics.env.activeTransactions()); } }
MetaTreeImpl holdNewestSnapshotBy(@NotNull final TransactionBase txn, final boolean acquireTxn) { if (acquireTxn) { acquireTransaction(txn); } final Runnable beginHook = txn.getBeginHook(); metaReadLock.lock(); try { if (beginHook != null) { beginHook.run(); } return metaTree; } finally { metaReadLock.unlock(); } }
public static void reset() { if (projectDatabase != null) { if (nonNull(projectDatabase.entityStore)) { try { EnvironmentImpl environment = (EnvironmentImpl) projectDatabase.entityStore.getEnvironment(); environment.flushAndSync(); projectDatabase.entityStore.close(); } catch (ExodusException e) { // wait transaction try { Thread.sleep(1000 * 3); } catch (InterruptedException e1) { log.catching(e1); } projectDatabase.entityStore.close(); } projectDatabase.entityStore = null; } if (nonNull(projectDatabase.environment)) { projectDatabase.environment.close(); projectDatabase.environment = null; } projectDatabase.open(); } }
@NotNull @Override public TransactionBase beginReadonlyTransaction(final Runnable beginHook) { final TransactionBase result = super.beginReadonlyTransaction(beginHook); setCurrentTransaction(result); return result; }
private static <T> T computeInTransaction(@NotNull final TransactionalComputable<T> computable, @NotNull final Transaction txn) { try { while (true) { final T result = computable.compute(txn); if (txn.isReadonly() || // txn can be read-only if Environment is in read-only mode txn.isFinished() || // txn can be finished if, e.g., it was aborted within computable txn.flush()) { return result; } txn.revert(); } } finally { abortIfNotFinished(txn); } }
@Override public <T> T computeInReadonlyTransaction(@NotNull TransactionalComputable<T> computable) { final Transaction txn = beginReadonlyTransaction(); try { return computable.compute(txn); } finally { abortIfNotFinished(txn); } }