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 synchronized CloseableKVStore mutableSnapshot() { if (this.closed) throw new StaleTransactionException(this, "transaction closed"); final XodusKVStore snapshot = this.buildKV().readOnlySnapshot(); return new CloseableForwardingKVStore(new MutableView(snapshot, null, new Writes()), snapshot); }
this.mods = new MutableView(this.kvstore, null, new Writes());
@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; }
this.mods = new MutableView(this.mods, null, new Writes()); this.modsWritesSnapshot = null; previousModsFileLength = this.modsFileLength; this.modsFileSyncPoint = newModsFileSyncPoint; this.kvstore = new ArrayKVStore(this.indx, this.keys, this.vals); this.mods = new MutableView(this.kvstore, null, this.mods.getWrites()); this.modsWritesSnapshot = null; if (additionalModsLength == 0) this.mods = new MutableView(this.kvstore, null, writesToCompact); this.modsWritesSnapshot = null; writesDuringCompaction.applyTo(this.mods);
snapshot = new MutableView(snapshot, null, compactingWrites); if (outstandingWrites != null) snapshot = new MutableView(snapshot, null, outstandingWrites);
MostRecentView(final RaftKVDatabase raft, final long maxIndex) { // Sanity check assert raft != null; assert Thread.holdsLock(raft); assert maxIndex >= 0; // Grab a snapshot of the key/value store this.snapshot = raft.kv.snapshot(); // Create a view of just the state machine keys and values and successively layer unapplied log entries up to maxIndex KVStore kview = PrefixKVStore.create(snapshot, raft.getStateMachinePrefix()); this.config = new HashMap<>(raft.log.getLastAppliedConfig()); long viewIndex = raft.log.getLastAppliedIndex(); long viewTerm = raft.log.getLastAppliedTerm(); for (LogEntry logEntry : raft.log.getUnapplied()) { if (logEntry.getIndex() > maxIndex) break; final Writes writes = logEntry.getWrites(); if (!writes.isEmpty()) kview = new MutableView(kview, null, writes); logEntry.applyConfigChange(this.config); viewIndex = logEntry.getIndex(); viewTerm = logEntry.getTerm(); } // Finalize this.view = new MutableView(kview); this.term = viewTerm; this.index = viewIndex; }
private synchronized XodusKVStore buildKV() { if (this.closed) throw new StaleTransactionException(this, "transaction closed"); if (this.kv == null) { assert this.delegate == null; this.kv = new XodusKVStore(this.kvdb.getEnvironment(), this.kvdb.getStoreName(), this.transactionType); this.delegate = this.transactionType.isReadOnly() ? new MutableView(this.kv, null, new Writes()) : this.kv; } return this.kv; } }
/** * {@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()); } }