palandlom
palandlom

Reputation: 547

How to get graph with transaction support from remote gremlin server?

I have next configuration: remote Gremlin server (TinkerPop 3.2.6) with Janus GraphDB

I have gremlin-console (with janus plugin) + conf in remote.yaml: hosts: [10.1.3.2] # IP og gremlin-server host port: 8182 serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }}

So I want to make connection through gremlin-server (not to JanusGraph directly by graph = JanusGraphFactory.build().set("storage.backend", "cassandra").set("storage.hostname", "127.0.0.1").open();) and get graph which supports transactions?

Is it possible? Because as I see all TinkerFactory graphs do not support transactions

Upvotes: 1

Views: 1878

Answers (3)

Nischal Kumar
Nischal Kumar

Reputation: 522

Tinkerpop provides Cluster object to keep the config of connection. Using Cluster object graphTraversalSource object can be spawned.

this.cluster = Cluster.build()
                .addContactPoints("192.168.0.2","192.168.0.1")
                .port(8082)
                .credentials(username, password)
                .serializer(new GryoMessageSerializerV1d0(GryoMapper.build().addRegistry(JanusGraphIoRegistry.getInstance())))
                .maxConnectionPoolSize(8)
                .maxContentLength(10000000)
                .create();
        this.gts = AnonymousTraversalSource
                .traversal()
                .withRemote(DriverRemoteConnection.using(cluster));

gts object is thread safe. With remote each query will be executed in separate transaction. Ideally gts should be a singleton object.

Make sure to call gts.close() and cluster.close() upon shutdown of application else it may lead to connection leak.

Upvotes: 1

Kyle Zimmer
Kyle Zimmer

Reputation: 310

I believe that connecting a java application to a running gremlin server using withRemote() will not support transactions. I have had trouble finding information on this as well but as far as I can tell, if you want to do anything but read the graph, you need to use "embedded janusgraph" and have your remotely hosted persistent data stored in a "storage backend" that you connect to from your application as you describe in the second half of your question. https://groups.google.com/forum/#!topic/janusgraph-users/t7gNBeWC844 Some discussion I found around it here ^^ makes a mention of it auto-committing single transactions in remote mode, but it doesn't seem to do that when I try.

Upvotes: -1

palandlom
palandlom

Reputation: 547

As I understood to use the Janus graph through the gremlin server you should:

Define ip&port in the config file of the gremlin-console:

conf/remote.yaml

Connect by Gremlin-console to the gremlin server:

: remote connect tinkerpop.server conf/remote.yaml
==> Configured localhost/10.1.23.113: 8182

...and work in remote mode (using :> or :remote console), i.e. send ALL commands (or @script) to the gremlin-server.

:> graph.addVertex(...)

or

:remote console
==>All scripts will now be sent to Gremlin Server - [10.1.2.222/10.1.2.222:818]
graph.addVertex(...)

You don't need to define variables for the graph and the trawersal, but rather used

graph. - for the graph
g. - for the traversal

In this case, you can uses all graph features that are provided by the JanusGraphDB.

Upvotes: 1

Related Questions