void rebase(long baseTerm, long baseIndex, KVStore kvstore, CloseableKVStore snapshot) { assert Thread.holdsLock(this.view); assert Thread.holdsLock(this.raft); assert this.state.equals(TxState.EXECUTING); assert this.snapshotRefs != null; this.rebase(baseTerm, baseIndex); this.view.setKVStore(kvstore); this.snapshotRefs.unref(); this.snapshotRefs = new SnapshotRefs(snapshot); }
/** * {@inheritDoc} * * <p> * Mutable snapshots are supported by {@link RaftKVTransaction}. * * @return {@inheritDoc} * @throws UnsupportedOperationException {@inheritDoc} * @throws StaleTransactionException {@inheritDoc} * @throws io.permazen.kv.RetryTransactionException {@inheritDoc} */ @Override public CloseableKVStore mutableSnapshot() { final Writes writes; synchronized (this.view) { writes = this.view.getWrites().clone(); } synchronized (this.raft) { this.verifyExecuting(); assert this.snapshotRefs != null; this.snapshotRefs.ref(); final MutableView snapshotView = new MutableView(this.snapshotRefs.getKVStore(), null, writes); return new CloseableForwardingKVStore(snapshotView, this.snapshotRefs.getUnrefCloseable()); } }
/** * Constructor. * * @param raft associated database * @param consistency consistency guarantee * @param baseTerm term of the Raft log entry on which this transaction is based * @param baseIndex index of the Raft log entry on which this transaction is based * @param snapshot underlying state machine snapshot; will be closed with this instance * @param view this transaction's view of the (prefixed) key/value store */ RaftKVTransaction(RaftKVDatabase raft, Consistency consistency, long baseTerm, long baseIndex, CloseableKVStore snapshot, MutableView view) { this.raft = raft; this.consistency = consistency; this.baseTerm = baseTerm; this.baseIndex = baseIndex; this.snapshotRefs = new SnapshotRefs(snapshot); this.view = view; this.rebasable = consistency.isGuaranteesUpToDateReads(); // i.e., LINEARIZABLE if (!this.rebasable) this.view.disableReadTracking(); }
void setState(final TxState state) { assert state != null; synchronized (this.raft) { assert state.compareTo(this.state) >= 0; if (this.state.equals(TxState.EXECUTING) && !this.state.equals(state)) { this.view.setReadOnly(); this.snapshotRefs.unref(); this.snapshotRefs = null; } this.state = state; this.lastStateChangeTime = new Timestamp(); this.executing = state.equals(TxState.EXECUTING); } }