void setNoLongerRebasable() { assert Thread.holdsLock(this.raft); assert this.rebasable == (this.view.getReads() != null); if (this.rebasable) { if (this.raft.logger.isTraceEnabled()) this.raft.trace("stopping rebasing for " + this); this.raft.setHighPriority(this, false); // if it's not longer rebasable, it can't be a victim of any conflicts this.view.disableReadTracking(); this.rebasable = false; } }
/** * 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(); }
CachingKVTransaction(CachingKVDatabase kvdb, KVTransaction inner, ExecutorService executor, long rttEstimate) { this.kvdb = kvdb; this.inner = inner; this.cachingKV = new CachingKVStore(inner, executor, rttEstimate); this.kvdb.copyCachingConfigTo(this.cachingKV); this.view = new MutableView(this.cachingKV); this.view.disableReadTracking(); }
@Override public CloseableKVStore mutableSnapshot() { // Build copy CloseableKVStore kvstore; if (this.kvdb.kv instanceof NavigableMapKVStore) { final NavigableMapKVStore kv; synchronized (this.kvdb) { kv = ((NavigableMapKVStore)this.kvdb.kv).clone(); } kvstore = new CloseableForwardingKVStore(kv.clone()); } else if (this.kvdb.kv instanceof AtomicKVStore) { final AtomicKVStore kv = (AtomicKVStore)this.kvdb.kv; final CloseableKVStore snapshot = kv.snapshot(); final MutableView view = new MutableView(snapshot); view.disableReadTracking(); kvstore = new CloseableForwardingKVStore(view, snapshot); } else { throw new UnsupportedOperationException("underlying KVStore " + this.kvdb.kv.getClass().getSimpleName() + " is not an AtomicKVStore"); } // Apply mutations synchronized (this.kvdb) { for (Mutation mutation : this.mutations) mutation.apply(kvstore); } // Done return kvstore; }