Class TinkerStorageGraph
java.lang.Object
org.apache.tinkerpop.gremlin.tinkergraph.structure.AbstractTinkerGraph
org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerStorageGraph
- All Implemented Interfaces:
AutoCloseable,Graph,Host,TinkerGraph
The transactional implementation of the
TinkerGraph interface. It provides read committed
transaction isolation with optimistic locking and, when a storage engine is configured, durable persistence to
disk. With no storage engine configured it is an in-memory transactional graph that retains nothing across
restarts.
Persistence is pluggable through the TinkerStorage
SPI and enabled with the gremlin.tinkergraph.storage and gremlin.tinkergraph.storage.directory
configuration keys. Each committed transaction is written through to the storage engine before the in-memory commit
is applied, and reopening the same location replays the persisted commits to rebuild the graph. A storage location
is single-writer: it is guarded by an exclusive DirectoryLock
so a second open of the same directory fails rather than corrupting the data.- Author:
- Valentyn Kahamlyk
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassclassNested classes/interfaces inherited from class org.apache.tinkerpop.gremlin.tinkergraph.structure.AbstractTinkerGraph
AbstractTinkerGraph.TinkerGraphEdgeFeatures, AbstractTinkerGraph.TinkerGraphVertexFeatures, AbstractTinkerGraph.TinkerGraphVertexPropertyFeaturesNested classes/interfaces inherited from interface org.apache.tinkerpop.gremlin.structure.Graph
Graph.Exceptions, Graph.Features, Graph.Hidden, Graph.Index, Graph.OptIn, Graph.OptIns, Graph.OptOut, Graph.OptOuts, Graph.VariablesNested classes/interfaces inherited from interface org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
TinkerGraph.DefaultIdManager, TinkerGraph.IdManager<T> -
Field Summary
Fields inherited from class org.apache.tinkerpop.gremlin.tinkergraph.structure.AbstractTinkerGraph
allowNullPropertyValues, configuration, currentId, defaultEdgeLabel, defaultVertexLabel, defaultVertexPropertyCardinality, edgeIdManager, edgeIndex, edgeLabelCardinality, graphComputerView, serviceRegistry, variables, vertexIdManager, vertexIndex, vertexLabelCardinality, vertexProperties, vertexPropertyIdManagerFields inherited from interface org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
GREMLIN_TINKERGRAPH_ALLOW_NULL_PROPERTY_VALUES, GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, GREMLIN_TINKERGRAPH_EDGE_ID_MANAGER, GREMLIN_TINKERGRAPH_SERVICE, GREMLIN_TINKERGRAPH_STORAGE, GREMLIN_TINKERGRAPH_STORAGE_COMPACT_THRESHOLD, GREMLIN_TINKERGRAPH_STORAGE_DIRECTORY, GREMLIN_TINKERGRAPH_STORAGE_PRESERVE_VP_IDS, GREMLIN_TINKERGRAPH_STORAGE_RECOVER, GREMLIN_TINKERGRAPH_STORAGE_SYNC, GREMLIN_TINKERGRAPH_VERTEX_ID_MANAGER, GREMLIN_TINKERGRAPH_VERTEX_LABEL_CARDINALITY, GREMLIN_TINKERGRAPH_VERTEX_PROPERTY_ID_MANAGER -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEdgeToAdjacency(TinkerEdge edge, String label) Add an edge to the per-vertex adjacency maps under the given label.protected voidaddInEdge(TinkerVertex vertex, String label, Edge edge) protected voidaddOutEdge(TinkerVertex vertex, String label, Edge edge) voidclose()Closes the graph.The committed edges of the graph, for a storage engine to snapshot during compaction.The committed vertices of the graph, for a storage engine to snapshot during compaction.voidcompact()Fold the durable storage log into a compact snapshot of the current committed state, reclaiming space.protected EdgedoAddEdge(TinkerVertex outVertex, TinkerVertex inVertex, String label, Object... keyValues) Implementation ofAbstractTinkerGraph.addEdge(org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex, org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex, java.lang.String, java.lang.Object...), called once the graph is known to be open.protected VertexdoAddVertex(Object... keyValues) Implementation ofAbstractTinkerGraph.addVertex(java.lang.Object...), called once the graph is known to be open.protected voiddoClear()Implementation ofAbstractTinkerGraph.clear().protected longdoCountEdgesByLabel(String label) Implementation ofAbstractTinkerGraph.countEdgesByLabel(java.lang.String).protected longdoCountVerticesByLabel(String label) Implementation ofAbstractTinkerGraph.countVerticesByLabel(java.lang.String).protected <E extends Element>
voiddoCreateIndex(String key, Class<E> elementClass) protected <E extends Element>
voiddoDropIndex(String key, Class<E> elementClass) protected EdgeImplementation ofAbstractTinkerGraph.edge(java.lang.Object), called once the graph is known to be open.Implementation ofAbstractTinkerGraph.edges(java.lang.Object...), called once the graph is known to be open.protected intImplementation ofAbstractTinkerGraph.getEdgesCount(), called once the graph is known to be open.protected intImplementation ofAbstractTinkerGraph.getVerticesCount(), called once the graph is known to be open.protected booleanImplementation ofAbstractTinkerGraph.hasEdge(java.lang.Object), called once the graph is known to be open.protected booleandoHasVertex(Object id) Implementation ofAbstractTinkerGraph.hasVertex(java.lang.Object), called once the graph is known to be open.protected voiddoRemoveEdge(Object edgeId) Implementation ofAbstractTinkerGraph.removeEdge(java.lang.Object), called once the graph is known to be open.protected voiddoRemoveVertex(Object vertexId) Implementation ofAbstractTinkerGraph.removeVertex(java.lang.Object), called once the graph is known to be open.protected voiddoTouch(TinkerEdge edge) Implementation ofAbstractTinkerGraph.touch(TinkerEdge).protected voiddoTouch(TinkerVertex vertex) Implementation ofAbstractTinkerGraph.touch(TinkerVertex).protected TransactiondoTx()Implementation ofAbstractTinkerGraph.tx(), called once the graph is known to be open.protected VertexImplementation ofAbstractTinkerGraph.vertex(java.lang.Object), called once the graph is known to be open.doVertices(Object... vertexIds) Implementation ofAbstractTinkerGraph.vertices(java.lang.Object...), called once the graph is known to be open.features()Return TinkerGraph feature set.Gets the registry of service factories forcall()steps.booleanisTxMode()Determines if this graph stores elements in transactional containers, meaning elements are held by id reference and cloned on read rather than referenced directly.static TinkerStorageGraphopen()Open a newTinkerStorageGraphinstance.static TinkerStorageGraphopen(org.apache.commons.configuration2.Configuration configuration) Open a newTinkerStorageGraphinstance.voidremoveEdgeFromAdjacency(TinkerEdge edge, String label) Remove an edge from the per-vertex adjacency maps for the given label.Methods inherited from class org.apache.tinkerpop.gremlin.tinkergraph.structure.AbstractTinkerGraph
addEdge, addVertex, addVertexLabels, checkOpen, clear, compute, compute, configuration, countEdgesByLabel, countVerticesByLabel, createIndex, createTinkerEdge, createTinkerEdge, createTinkerVertex, createTinkerVertex, createTinkerVertex, dropIndex, edge, edges, getEdgesCount, getIndexedKeys, getVerticesCount, hasEdge, hasVertex, hasVertexProperty, index, instantiate, io, removeEdge, removeVertex, removeVertexLabels, selectIdManager, toString, touch, touch, tx, variables, vertex, vertices
-
Method Details
-
open
Open a newTinkerStorageGraphinstance. Reference Implementation Help: If aGraphimplementation does not require aConfiguration(or perhaps has a default configuration) it can choose to implement a zero argumentopen()method. This is an optional constructor method for TinkerGraph. It is not enforced by the Gremlin Test Suite. -
open
public static TinkerStorageGraph open(org.apache.commons.configuration2.Configuration configuration) Open a newTinkerStorageGraphinstance. Reference Implementation Help: This method is the one use by theGraphFactoryto instantiateGraphinstances. This method must be overridden for the Structure Test Suite to pass. Implementers have latitude in terms of how exceptions are handled within this method. Such exceptions will be considered implementation specific by the test suite as all test generate graph instances by way ofGraphFactory. As such, the exceptions get generalized behind that facade and sinceGraphFactoryis the preferred method to opening graphs it will be consistent at that level.- Parameters:
configuration- the configuration for the instance- Returns:
- a newly opened
Graph
-
doAddVertex
Description copied from class:AbstractTinkerGraphImplementation ofAbstractTinkerGraph.addVertex(java.lang.Object...), called once the graph is known to be open.- Specified by:
doAddVertexin classAbstractTinkerGraph
-
doRemoveVertex
Description copied from class:AbstractTinkerGraphImplementation ofAbstractTinkerGraph.removeVertex(java.lang.Object), called once the graph is known to be open.- Specified by:
doRemoveVertexin classAbstractTinkerGraph
-
doTouch
Description copied from class:AbstractTinkerGraphImplementation ofAbstractTinkerGraph.touch(TinkerVertex). If the graph does not support transactions, then does nothing.- Overrides:
doTouchin classAbstractTinkerGraph
-
doTouch
Description copied from class:AbstractTinkerGraphImplementation ofAbstractTinkerGraph.touch(TinkerEdge). If the graph does not support transactions, then does nothing.- Overrides:
doTouchin classAbstractTinkerGraph
-
doAddEdge
protected Edge doAddEdge(TinkerVertex outVertex, TinkerVertex inVertex, String label, Object... keyValues) Description copied from class:AbstractTinkerGraphImplementation ofAbstractTinkerGraph.addEdge(org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex, org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex, java.lang.String, java.lang.Object...), called once the graph is known to be open.- Specified by:
doAddEdgein classAbstractTinkerGraph
-
doRemoveEdge
Description copied from class:AbstractTinkerGraphImplementation ofAbstractTinkerGraph.removeEdge(java.lang.Object), called once the graph is known to be open.- Specified by:
doRemoveEdgein classAbstractTinkerGraph
-
doClear
protected void doClear()Implementation ofAbstractTinkerGraph.clear(). Subclasses that hold more data extend it and call this one. Like the in-memory graph, this clears the whole graph at once, outside any transaction: it needs no commit and cannot be rolled back. The calling thread's uncommitted changes are discarded with the rest of the graph, and a transaction still open on another thread fails to commit any element it changed. With storage configured the store is emptied in the same call, so a reopen finds the graph asclear()left it. A graph opened withgremlin.tinkergraph.storage.recoveris cleared in memory only and its store is left unchanged, like any other change made to it.- Overrides:
doClearin classAbstractTinkerGraph- Throws:
IllegalStateException- if the graph's storage is closed, or stopped accepting writes after a storage failure, in which case the graph is not clearedUncheckedIOException- if the graph was cleared in memory but its store could not be emptied, in which case the storage accepts no further commits until the graph is reopened, and the cleared data may return then
-
close
public void close()Closes the graph. When a storage engine is configured, it is flushed, compacted and closed, and the exclusive lock on its directory is released. A failure to flush or compact is logged rather than thrown, since the next open replays the log, and the engine and its directory lock are released regardless.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceGraph- Specified by:
closein interfaceTinkerGraph- Overrides:
closein classAbstractTinkerGraph
-
compact
public void compact()Fold the durable storage log into a compact snapshot of the current committed state, reclaiming space. Has no effect when no storage engine is configured, or when nothing was committed since the last compaction.- Throws:
IllegalStateException- if the graph is closed, was opened read-only to recover a damaged store, or its storage stopped accepting writes after a storage failure
-
doTx
Description copied from class:AbstractTinkerGraphImplementation ofAbstractTinkerGraph.tx(), called once the graph is known to be open. Element reads and iterators already being consumed also call it after the graph is closed, so they can keep reading the in-memory state as it stood at close.- Specified by:
doTxin classAbstractTinkerGraph
-
isTxMode
public boolean isTxMode()Description copied from class:AbstractTinkerGraphDetermines if this graph stores elements in transactional containers, meaning elements are held by id reference and cloned on read rather than referenced directly. Returnsfalseunless overridden by an implementation that supports transactions.- Overrides:
isTxModein classAbstractTinkerGraph
-
doGetVerticesCount
protected int doGetVerticesCount()Description copied from class:AbstractTinkerGraphImplementation ofAbstractTinkerGraph.getVerticesCount(), called once the graph is known to be open.- Specified by:
doGetVerticesCountin classAbstractTinkerGraph
-
doHasVertex
Description copied from class:AbstractTinkerGraphImplementation ofAbstractTinkerGraph.hasVertex(java.lang.Object), called once the graph is known to be open.- Specified by:
doHasVertexin classAbstractTinkerGraph
-
committedVertices
The committed vertices of the graph, for a storage engine to snapshot during compaction. Unlikevertices, this view excludes any uncommitted transaction-local state, so compaction never persists changes that a caller has not committed. Reads the committed value of each container (TinkerElementContainer.getUnmodified()), so a compaction snapshot reflects only committed state regardless of the calling thread's open transaction. A container whose committed value isnull(added but not yet committed, or committed and then deleted) is skipped. -
doGetEdgesCount
protected int doGetEdgesCount()Description copied from class:AbstractTinkerGraphImplementation ofAbstractTinkerGraph.getEdgesCount(), called once the graph is known to be open.- Specified by:
doGetEdgesCountin classAbstractTinkerGraph
-
doCountVerticesByLabel
Description copied from class:AbstractTinkerGraphImplementation ofAbstractTinkerGraph.countVerticesByLabel(java.lang.String). The default implementation does a full vertex scan; subclasses that maintain a label index should override this for O(1) performance.- Overrides:
doCountVerticesByLabelin classAbstractTinkerGraph
-
doCountEdgesByLabel
Description copied from class:AbstractTinkerGraphImplementation ofAbstractTinkerGraph.countEdgesByLabel(java.lang.String). The default implementation does a full edge scan; subclasses that maintain a label index should override this for O(1) performance.- Overrides:
doCountEdgesByLabelin classAbstractTinkerGraph
-
doHasEdge
Description copied from class:AbstractTinkerGraphImplementation ofAbstractTinkerGraph.hasEdge(java.lang.Object), called once the graph is known to be open.- Specified by:
doHasEdgein classAbstractTinkerGraph
-
committedEdges
The committed edges of the graph, for a storage engine to snapshot during compaction. The edge counterpart ofcommittedVertices(): reads only committed container state and skips containers whose committed value isnull. -
getServiceRegistry
Description copied from interface:TinkerGraphGets the registry of service factories forcall()steps.- Returns:
- The registry of callable services
-
doVertex
Description copied from class:AbstractTinkerGraphImplementation ofAbstractTinkerGraph.vertex(java.lang.Object), called once the graph is known to be open. Element reads and iterators already being consumed also call it after the graph is closed, so they can keep reading the in-memory state as it stood at close.- Specified by:
doVertexin classAbstractTinkerGraph
-
doVertices
Description copied from class:AbstractTinkerGraphImplementation ofAbstractTinkerGraph.vertices(java.lang.Object...), called once the graph is known to be open. Element reads and iterators already being consumed also call it after the graph is closed, so they can keep reading the in-memory state as it stood at close.- Specified by:
doVerticesin classAbstractTinkerGraph
-
doEdge
Description copied from class:AbstractTinkerGraphImplementation ofAbstractTinkerGraph.edge(java.lang.Object), called once the graph is known to be open. Element reads and iterators already being consumed also call it after the graph is closed, so they can keep reading the in-memory state as it stood at close.- Specified by:
doEdgein classAbstractTinkerGraph
-
doEdges
Description copied from class:AbstractTinkerGraphImplementation ofAbstractTinkerGraph.edges(java.lang.Object...), called once the graph is known to be open. Element reads and iterators already being consumed also call it after the graph is closed, so they can keep reading the in-memory state as it stood at close.- Specified by:
doEdgesin classAbstractTinkerGraph
-
addOutEdge
- Specified by:
addOutEdgein classAbstractTinkerGraph
-
addInEdge
- Specified by:
addInEdgein classAbstractTinkerGraph
-
addEdgeToAdjacency
Description copied from class:AbstractTinkerGraphAdd an edge to the per-vertex adjacency maps under the given label. Used when labels are added to an existing edge.- Specified by:
addEdgeToAdjacencyin classAbstractTinkerGraph- Parameters:
edge- the edge to registerlabel- the label under which to register the edge
-
removeEdgeFromAdjacency
Description copied from class:AbstractTinkerGraphRemove an edge from the per-vertex adjacency maps for the given label. Used when labels are removed from an existing edge.- Specified by:
removeEdgeFromAdjacencyin classAbstractTinkerGraph- Parameters:
edge- the edge to unregisterlabel- the label from which to unregister the edge
-
features
Return TinkerGraph feature set. Reference Implementation Help: Implementers only need to implement features for which there are negative or instance configured features. By default, allGraph.Featuresreturn true. -
doCreateIndex
Create an index for said element class (VertexorEdge) and said property key. Whenever an element has the specified key mutated, the index is updated. When the index is created, all existing elements are indexed to ensure that they are captured by the index.- Specified by:
doCreateIndexin classAbstractTinkerGraph- Type Parameters:
E- The type of the element class- Parameters:
key- the property key to indexelementClass- the element class to index
-
doDropIndex
- Specified by:
doDropIndexin classAbstractTinkerGraph- Type Parameters:
E- The type of the element class- Parameters:
key- the property key to stop indexingelementClass- the element class of the index to drop
-