Do Session requests support Bytecode

268 views
Skip to first unread message

Dave Bloodworth

unread,
Apr 18, 2019, 12:11:50 PM4/18/19
to Gremlin-users
I am using TinkerGraph through GremlinServer V3.4.1 and I am trying to get familiar with using gremlin when connecting from a java app.

I have created a client session, such that I can make multiple graph inserts in a single transaction, much as I would with any other db.

The setup is summarized below:

Cluster cluster = Cluster.open(getGraphServerConfiguration());
String sessionId = UUID.randomUUID().toString();
Client sessionClient = cluster.connect(sessionId);
GraphTraversalSource g = AnonymousTraversalSource.traversal().withRemote(DriverRemoteConnection.using(sessionClient));

However, if I query the server using the traversal source, e.g.

g.V().next();

It always results in the response error "REQUEST_ERROR_MALFORMED_REQUEST" and "ResponseException: Message with op code [bytecode] is not recognized."

Stack trace:
Caused by: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: Message with op code [bytecode] is not recognized.
    at org.apache.tinkerpop.gremlin.driver.Handler$GremlinResponseHandler.channelRead0(Handler.java:259)
    at org.apache.tinkerpop.gremlin.driver.Handler$GremlinResponseHandler.channelRead0(Handler.java:198)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
...

I wondered what I am doing wrong? The error suggests that bytecode operations are not permitted when calling (though a SessionClient) into a session but, if that is the case, what is the purpose of being able to create a traversal source based on a such a client?

Thanks,

Dave

Stephen Mallette

unread,
Apr 18, 2019, 1:48:55 PM4/18/19
to gremli...@googlegroups.com
There is no session support for bytecode requests - it's only for scripts. Sessions will probably die with scripts at some point in the future (certainly by TP4).

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/92c49c9f-5790-4d03-83d7-a912d499b04f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave Bloodworth

unread,
Apr 18, 2019, 6:55:43 PM4/18/19
to gremli...@googlegroups.com
Thank you for confirming the relationship between sessions and scripts, I got that from the docs but didn't appreciate that bytecode was not supported for sessions at all. Also, for indicating that scripts will be deprecated at some point in the near future. That helps.

Thank you for the fast response. 

cmilowka

unread,
Dec 18, 2019, 7:39:40 PM12/18/19
to Gremlin-users
Hi Stephen,

You said, "/../ Sessions will probably die with scripts at some point in the future (certainly by TP4). /.../"

May you offer some just few more words, to explain how the above may effect existing behaviour to submit script, 

We doing it things through: "gremlinClient.client.submit( script );"  on Remote Server driver, where we expect
to have one session with one transaction, allowing script like:  "a = addVertex().next();  a.property("aa","bb")... "
to be entirely rollback in case of any failure on the road.... Any impact that may stop us from upgrading?
Regards, CM


 

Stephen Mallette

unread,
Dec 19, 2019, 7:07:17 AM12/19/19
to gremli...@googlegroups.com
I assume the following just pseudocode because it isn't exactly valid Gremlin:

a = addVertex().next();  
a.property("aa","bb");

but I suppose I get what you mean. If you submit that as a single script request you don't need a session and can expect it to commit/rollback as a whole on success/failure. Note that "as a whole" may have different meanings depending on the semantics of the graph database that you are using. The only reason you would need a session would be if you intended to control the transaction yourself or expected to utilize the value of "a" again on a future request. 

All that said, the recommended approach is to use Gremlin (not the Graph API method of Graph.addVertex() or Vertex.property()) and therefore rather than the above pseudocode, just do:

g.addV().property("aa","bb")

You should also prefer Gremlin bytecode requests over scripts (session-based or sessionless). Gremlin bytecode will provide the most portable code across providers, allow you to write Gremlin in your native programming language rather than embedded strings, and provide the easiest upgrade path for the long term.  

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages