Using adjacent queries for Partitioned Vertices does not work correctly
While using Graph Partitioning (Vertex Cut) to alleviate large partition sizes in a backed like cassandra, I noticed a specific issue where if you try to query for adjacency, the query returns incorrect results. Assuming 'left' and 'right' are two partitioned vertices connected by an edge, a query like
left.query().adjacent(right).direction(Direction.OUT).labels("leftToRight").edges()
will return incorrect results. In case of a vertex cut, where the cluster.maxPartition is 32, both left and right will be cut in 32 segments, and can be represented as left[32] and right[32]. The VertexCentricQueryBuilder and the BasicVertexCentricQueryBuilder attempts to query the canonical long id of 'right' against the all representatives of left aka left[32] and may or may not find the correct right[i] in this query resulting into incorrect results.
Looking at the code further, when partitioning is in play, the VertexIdAssigner uses a consistent way of assigning/connecting relations to a vertex.
- Properties are always assigned to the canonical representative 2) Edges are assigned to the partition block of the non-partitioned vertex 2a) unless the edge is unique in the direction away from the partitioned vertex in which case its assigned to the canonical representative 2b) if both end vertices are partitioned, it is assigned to the partition to which the edge id hashes
VertexIdAssigner.java This information could be further used in optimizing the number of backend queries while performing a Vertex Centric Query as well. The current information uses a brute-force find in all representatives.
Having looked at the code for a sufficiently long time, I would be happy to contribute the changes if there is consensus on this issue. My proposal would be:
-
To fix the incorrect results issue - the primary problem here: BasicVertexCentricBuilder should be enhanced to understand that the adjacentVertex could also be partitioned and will need a seperate handling.
-
Performance Optimization of Vertex Centric Queries The vertex centric queries emanating from BasicVerexCentricQueryBuilder and VertexCentricQueryBuilder should follow the logic used by VertexIdAssigner to reduce the number of required queries to the backend. For eg:- if searching for a property/loading all properties for a partitioned vertex, its sufficient to only query the canonical representative instead of querying against all 32 representatives.
@nathsachindra thank you for finding these issues! I didn't work with optimizers much but your proposals sounds good to me. Maybe @smcquillan or @FlorianHockmann have something to add?
Also, there is a requirement that each contributor must sign a CLA. It isn't automate right now but JanusGraph members are working on it. I would suggest that you sign and send CLA now because sometimes it takes a while.
To contribute you should:
- Sign a CLA. Instructions are here: https://github.com/JanusGraph/legal/blob/master/README.md
- Follow this instructions: https://github.com/JanusGraph/janusgraph/blob/master/CONTRIBUTING.md
Please feel free to ask any questions if you have some.
Thank you. I believe I have a CCLA signed sometime back. Will wait for more opinions/corner cases if other developers are aware of.
@nathsachindra Can't say I’m familiar with using the Janus Graph Partitioning with Vertex Cut but looking at the code it does look like you’re onto something when you say:
For eg:- if searching for a property/loading all properties for a partitioned vertex, its sufficient to only query the canonical representative instead of querying against all 32 representatives.
And from my recent testing with the multi-query optimisations I can say that the overhead from the network latency of many small queries really does add up. So your suggested optimisation would be nice to have.