All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
AbstractLogStorage, GraphBinaryStorage

public interface TinkerStorage extends AutoCloseable
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:

  1. open(TinkerStorageGraph, Configuration) — resolve the backing location and ready the store.
  2. replay(TinkerStorageGraph) — rebuild in-memory state from what was previously persisted.
  3. persist(long, Collection, Collection) then flush() — 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.
  4. compact(TinkerStorageGraph) — optionally fold accumulated changes into a compact snapshot.
  5. close() — release resources.
A new engine can be selected by name (see 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 Type
    Method
    Description
    void
    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.
    void
    void
    Fold accumulated changes into a compact representation of the current committed state, reclaiming space.
    void
    Stop accepting writes, as after a storage failure, until the graph is reopened.
    void
    Force any buffered writes to durable storage.
    default boolean
    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 boolean
    Whether this engine accepts no writes at all, such as when a damaged store was opened for recovery.
    default void
    Compact if the engine's accumulated data has grown past its own threshold, otherwise do nothing.
    void
    open(TinkerStorageGraph graph, org.apache.commons.configuration2.Configuration config)
    Prepare the storage engine for use, resolving its backing location from the supplied configuration.
    void
    Durably record the changeset of a committing transaction.
    void
    Rebuild the in-memory state of the graph from previously persisted data.
  • Method Details

    • open

      void open(TinkerStorageGraph graph, org.apache.commons.configuration2.Configuration config)
      Prepare the storage engine for use, resolving its backing location from the supplied configuration. Called once during graph construction before replay(TinkerStorageGraph).
      Parameters:
      graph - the graph that owns this engine
      config - the graph configuration, including gremlin.tinkergraph.storage.directory
    • replay

      void replay(TinkerStorageGraph graph)
      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 its loading guard 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 (see TinkerStorageMutation).
      Parameters:
      txVersion - the version number of the committing transaction
      changedVertices - the vertex mutations in this transaction
      changedEdges - the edge mutations in this transaction
    • flush

      void flush()
      Force any buffered writes to durable storage. Called after persist(long, Collection, Collection) as the commit's durability point.
    • compact

      void compact(TinkerStorageGraph graph)
      Fold accumulated changes into a compact representation of the current committed state, reclaiming space. Safe to call at any time; typically invoked on close() or on a size/commit-count threshold.
      Parameters:
      graph - the graph whose current committed state should be snapshotted
    • maybeCompact

      default void maybeCompact(TinkerStorageGraph graph)
      Compact if the engine's accumulated data has grown past its own threshold, otherwise do nothing. Called on the commit path after flush() (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 of compact(TinkerStorageGraph) and close().
      Parameters:
      graph - the graph whose current committed state would be snapshotted
    • clear

      void clear(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. Called by TinkerGraph.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 through failStop(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

      void failStop(Throwable cause)
      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 when clear(org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerStorageGraph) fails after the graph was emptied in memory. isFailed() reports true afterwards.
      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:
      close in interface AutoCloseable