Support for Gremlin sessions - Amazon Neptune

Support for Gremlin sessions

You can use Gremlin sessions with implicit transactions in Amazon Neptune. For information about Gremlin sessions, see Considering Sessions in the Apache TinkerPop documentation.

Important

Currently, the longest time Neptune can keep a session open is 10 minutes. If you don't close a session before that, the session times out and everything in it is rolled back.

Gremlin sessions on the Gremlin console

If you create a remote connection on the Gremlin Console without the session parameter, the remote connection is created in sessionless mode. In this mode, each request that is submitted to the server is treated as a complete transaction in itself, and no state is saved between requests. If a request fails, only that request is rolled back.

If you create a remote connection that does use the session parameter, you create a session that lasts until you close the remote connection. Every session is identified by a unique UUID that the console generates and returns to you.

The following is an example of one console call that creates a session. After queries are submitted, another call closes the session and commits the queries.

gremlin> :remote connect tinkerpop.server conf/neptune-remote.yaml session . . . . . . gremlin> :remote close

For more information and examples, see Sessions in the TinkerPop documentation.

All the queries that you run during a session form a single transaction that isn't committed until all the queries succeed and you close the remote connection. If a query fails, or if you don't close the connection within the maximum session lifetime that Neptune supports, the session transaction is not committed, and all the queries in it are rolled back.

Gremlin sessions in the Gremlin Language Variant

In the Gremlin language variant (GLV), you need to create a SessionedClient object to issue multiple queries in a single transaction, as in the following example.

Cluster cluster = Cluster.open(); // line 1 Client client = cluster.connect("sessionName"); // line 2 . . . . . . client.close( );

Line 2 in the preceding example creates the SessionedClient object according to the configuration options set for the cluster in question. The sessionName string that you pass to the connect method becomes the unique name of the session. To avoid collisions, use a UUID for the name.

The client starts a session transaction when it is initialized. All the queries that you run during the session form are committed only when you call client.close( ). Again, if a single query fails, or if you don't close the connection within the maximum session lifetime that Neptune supports, the session transaction fails, and all the queries in it are rolled back.