Skip to content

Partition Implementation

jbmusso edited this page Jul 12, 2016 · 8 revisions

Attention: this Wiki hosts an outdated version of the TinkerPop framework and Gremlin language 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:

  1. Partition Key: The property key that denotes a String value representing a partition.
  2. Write Partition: A String denoting what partition all future written elements will be in.
  3. 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.