-
Notifications
You must be signed in to change notification settings - Fork 274
Partition Implementation
Attention: this Wiki hosts an outdated version of the TinkerPop framework and Gremlin language documentation.
Please visit the Apache TinkerPop website and latest documentation.
<dependency>
<groupId>com.tinkerpop.blueprints</groupId>
<artifactId>blueprints-core</artifactId>
<version>??</version>
</dependency>
PartitionGraph
is a graph wrapper that partitions the elements (vertices/edges) of a graph into String
named partitions (i.e. buckets, subgraphs, etc.). The idea behind PartitionGraph
is presented in the image above where each element is in a single partition (represented by its color). Partitions can be read from, written to, and linked/joined by edges that span one or two partitions (e.g. a tail vertex in one partition and a head vertex in another).
PartitionGraph
is simple to use. There are three primary variables in PartitionGraph
:
-
Partition Key: The property key that denotes a
String
value representing a partition. -
Write Partition: A
String
denoting what partition all future written elements will be in. -
Read Partitions: A
Set<String>
of partitions that can be read from.
The best way to understand PartitionGraph
is via an example.
PartitionGraph graph = new PartitionGraph(rawGraph, "_partition", "a"); // reading and writing is to partition "a"
Vertex v1 = graph.addVertex(null); // v1 has a property of {_partition:"a"}
graph.setWritePartition("b");
Vertex v2 = graph.addVertex(null); // v2 has a property of {_partition:"b"}
graph.getVertices(); // only v1 is in the iterator
graph.addReadPartition("b");
graph.getVertices() // both v1 and v2 are in the iterator
graph.removeReadPartition("a");
graph.removeReadPartition("b");
graph.getVertices(); // no vertices are in the iterator
graph.setWritePartition("c");
Edge e1 = graph.addEdge(null, v1, v2, "knows"); // e1 has a property of {_partition:"c"}
graph.getEdges(); // e1 is in the iterator
By writing elements to particular partitions and then restricting read partitions, the developer is able to create multiple graphs within a single address space. Moreover, by supporting references between partitions, it is possible to merge those multiple graphs (i.e. join partitions). Finally, there also exists PartitionIndexableGraph
with read partition respective index get()
and count()
methods.