AKG
AKG

Reputation: 618

How to traverse graph created using ConfiguredPlanFactory in JanusGraph?

I have set up a Janusgraph Cluster with Cassandra + ES. The cluster has been set up to support ConfiguredGraphFactory. Also, I am connecting the gremlin cluster remotely. I have set up a client and am able to create a graph using :

client.submit(String.format("ConfiguredGraphFactory.create(\"%s\")", graphName));

However, I am not able to get the traversalSource of the graph created using the gremlin driver. Do I have to create raw gremlin queries and traverse the graph using client.submit or is there a way to get it through the gremlin driver using Emptygraph.Instance().

Upvotes: 0

Views: 731

Answers (1)

David
David

Reputation: 506

To get the remote traversal reference, you need to pass in a variable name that is bound to your graph traversal. This binding is usually done as part of the "globals" in your startup script when you start the remote server (the start up script is configured to run as part of the gremlin-server.yaml).

There is currently no inherent way to dynamically bind a variable to a graph or traversal reference, but I plan on fixing this at some point.

A short term fix is to bind your graph and traversal references to a method that will be variably defined, and then create some mechanism to change the variable dynamically.

To further explain a potential solution:

  1. Update your server's startup script to bind g to something variable:

    globals << [g : DynamicBindingTool.getBoundGraphTraversal()]
    
  2. Create DynamicBindingTool, which has to do two things:

    A. Provide a way to setBoundGraph() which may look something like:

    setBoundGraph(graphName) {
        this.boundGraph = ConfiguredGraphFactory.open(graphName);
    }
    

    B. Provide a way to getBoundGraphTraversal() which may look something like:

    getBoundGraphTraversal() {
        this.boundGraph.traversal();
    }
    

You can include these sorts of functions in your start-up script or perhaps even create a separate jar that you attach to your Gremlin Server.

Finally, I would like to note that the proposed example solution does not take into account a multi-node JanusGraph cluster, i.e. your notion of the current bound graph would not be shared across the JG nodes. To make this a multi-node solution, you can update the functions to define the bound graph on an external database or even piggybacked on a JanusGraph graph.

For example, something like this would be a multi-node safe implementation:

setBoundGraph(graphName) {
    def managementGraph = ConfiguredGraphFactory.open("managementGraph");
    managementGraph.traversal().V().has("boundGraph", true).remove();
    def v = managementGraph.addVertex();
    v.property("boundGraph", true);
    v.property("graph.graphname", graphName);
}

and:

getBoundGraphTraversal() {
    def managementGraph = ConfiguredGraphFactory.open("managementGraph");
    def graphName = managementGraph.traversal().V().has("boundGraph", true).values("graph.graphname");
    return ConfiguredGraphFactory.open(graphName).traversal();
}

EDIT:

Unfortunately, the above "short-term trick" will not work as the global bindings are evaluated once and stored in a Map for the duration of the sever life cycle. Please see here for more information and updates on fixes: https://issues.apache.org/jira/browse/TINKERPOP-1839.

Upvotes: 3

Related Questions