Interface TinkerStorage
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
AbstractLogStorage,GraphBinaryStorage
A pluggable durable storage engine for a transactional
TinkerStorageGraph. Implementations persist the
changeset of each committed transaction to disk and rebuild the in-memory graph on open. The graph remains the
authoritative in-memory copy (write-through); the engine is a durable mirror.
The lifecycle is:
open(TinkerStorageGraph, Configuration)— resolve the backing location and ready the store.replay(TinkerStorageGraph)— rebuild in-memory state from what was previously persisted.persist(long, Collection, Collection)thenflush()— called on each transaction commit, before the indexes and in-memory state are committed, so a failure aborts the commit and leaves the graph as it was. Whether a commit that failed in the engine reached disk is up to the engine; one that cannot say should refuse further commits until the graph is reopened.compact(TinkerStorageGraph)— optionally fold accumulated changes into a compact snapshot.close()— release resources.
DefaultStorage) or by fully-qualified class name via the
gremlin.tinkergraph.storage configuration key. Implementations must provide a public no-argument constructor.-
Method Summary
Modifier and TypeMethodDescriptionvoidclear(TinkerStorageGraph graph) Replace everything the engine holds with the graph's current committed state, which the caller has just emptied, so that the store holds nothing and a reopen finds an empty graph.voidclose()voidcompact(TinkerStorageGraph graph) Fold accumulated changes into a compact representation of the current committed state, reclaiming space.voidStop accepting writes, as after a storage failure, until the graph is reopened.voidflush()Force any buffered writes to durable storage.default booleanisFailed()Whether this engine has stopped accepting writes after a storage failure, such as a failed log write or the store being removed while the graph was open.default booleanWhether this engine accepts no writes at all, such as when a damaged store was opened for recovery.default voidmaybeCompact(TinkerStorageGraph graph) Compact if the engine's accumulated data has grown past its own threshold, otherwise do nothing.voidopen(TinkerStorageGraph graph, org.apache.commons.configuration2.Configuration config) Prepare the storage engine for use, resolving its backing location from the supplied configuration.voidpersist(long txVersion, Collection<TinkerStorageMutation<TinkerVertex>> changedVertices, Collection<TinkerStorageMutation<TinkerEdge>> changedEdges) Durably record the changeset of a committing transaction.voidreplay(TinkerStorageGraph graph) Rebuild the in-memory state of the graph from previously persisted data.
-
Method Details
-
open
Prepare the storage engine for use, resolving its backing location from the supplied configuration. Called once during graph construction beforereplay(TinkerStorageGraph).- Parameters:
graph- the graph that owns this engineconfig- the graph configuration, includinggremlin.tinkergraph.storage.directory
-
replay
Rebuild the in-memory state of the graph from previously persisted data. Called once during graph construction. Implementations should re-apply persisted elements through the graph's own mutation API; the graph sets itsloadingguard for the duration so this does not re-persist.- Parameters:
graph- the graph to populate
-
persist
void persist(long txVersion, Collection<TinkerStorageMutation<TinkerVertex>> changedVertices, Collection<TinkerStorageMutation<TinkerEdge>> changedEdges) Durably record the changeset of a committing transaction. Called from within the transaction commit, while the changed elements are locked, before the in-memory commit is applied. Each mutation is either a put (added or modified element) or a delete (seeTinkerStorageMutation).- Parameters:
txVersion- the version number of the committing transactionchangedVertices- the vertex mutations in this transactionchangedEdges- the edge mutations in this transaction
-
flush
void flush()Force any buffered writes to durable storage. Called afterpersist(long, Collection, Collection)as the commit's durability point. -
compact
Fold accumulated changes into a compact representation of the current committed state, reclaiming space. Safe to call at any time; typically invoked onclose()or on a size/commit-count threshold.- Parameters:
graph- the graph whose current committed state should be snapshotted
-
maybeCompact
Compact if the engine's accumulated data has grown past its own threshold, otherwise do nothing. Called on the commit path afterflush()(while the graph's commit lock is held) so a long-running graph that is never explicitly closed does not grow its backing storage without bound. The default is a no-op, leaving compaction entirely under the control ofcompact(TinkerStorageGraph)andclose().- Parameters:
graph- the graph whose current committed state would be snapshotted
-
clear
Replace everything the engine holds with the graph's current committed state, which the caller has just emptied, so that the store holds nothing and a reopen finds an empty graph. Called byTinkerGraph.clear()under the graph's commit lock, and never on a read-only engine. If the store cannot be emptied, the engine must refuse further commits until the graph is reopened: appending them to the old data would bring the cleared elements back on reopen, mixed with the new ones. The graph fail-stops the engine throughfailStop(Throwable)when this throws. Rewriting the store from the emptied graph, as a compaction does, is one way to empty it, but it must then run even when nothing was written since the last compaction, since the store still holds the data the graph no longer has.- Parameters:
graph- the graph, already emptied, whose committed state the store should now hold
-
isReadOnly
default boolean isReadOnly()Whether this engine accepts no writes at all, such as when a damaged store was opened for recovery. The graph then also leaves its other files in the storage directory, such as index definitions, unchanged. -
isFailed
default boolean isFailed()Whether this engine has stopped accepting writes after a storage failure, such as a failed log write or the store being removed while the graph was open. It stays so until the graph is reopened. The graph's committed data remains readable in memory for export, so operations that would discard or rewrite it are refused. -
failStop
Stop accepting writes, as after a storage failure, until the graph is reopened. The graph calls this when its memory no longer matches the store, so that nothing written from that memory, by a commit or a compaction, may reach the store: when a transaction's changes were persisted and flushed but could not then be applied in memory, so the transaction is durable and returns on the next open, and whenclear(org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerStorageGraph)fails after the graph was emptied in memory.isFailed()reportstrueafterwards.- Parameters:
cause- why the graph's memory no longer matches the store
-
close
void close()Flush and release resources. Does not delete persisted data.- Specified by:
closein interfaceAutoCloseable
-