Skip to content

Partition Implementation

okram edited this page Feb 1, 2012 · 8 revisions

PartitionGraph is a graph wrapper that partitions a the elements (vertices/edges) of a graph into String named partions. The interface is simple with useful ramifications. 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 to partition all future written elements will be in.
  3. Read Partitions: A Set<String> of named 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 setting restricted read partions, allows the developer to create multiple graphs within a single address space. Moreover, by supporting references between partitions, it is possible to have merges of those partitions from yet another read partition perspective.