Custom MutationListener on Transaction

Hello everyone, I'm a beginner regarding tinkerpop and i'm trying to fire my custom listener after a transaction is done. I have registered an EventStrategy on my JanusGraph
graph.traversal().withStrategies(EventStrategy.build().eventQueue(new CustomTransactionnalEventQueue(graph)).addListener(new CustomListener(graph.traversal())).create())
graph.traversal().withStrategies(EventStrategy.build().eventQueue(new CustomTransactionnalEventQueue(graph)).addListener(new CustomListener(graph.traversal())).create())
The Custom transactionnal Event Queue is just a copy of the one in the EventStrategy class with logs at every step to help me find where the problem is . Now the problem : I have noticed that my transaction are never mark as committed. i tried a simple g.addV() :
gremlin> g.addV("aeaeazezeezee")
==>v[368652472]
gremlin> g.addV("aeaeazezeezee")
==>v[368652472]
and tried using
g.tx().commit()
g.tx().commit()
I see in my logs that the event are catched and added to the eventQueue but my listeners is never used on them since the status of my transaction is never marked as commited. I hope I'm clear in my explanation. I can provide more information/code if needed Regards
13 Replies
spmallette
spmallette14mo ago
you dont have a single continuous Gremlin Console session there so it's a little hard to be sure what's happening. could you perhaps share a full console session that demonstrates the setup of g and the order in which your example works?
Napsetern
Napsetern14mo ago
Sure, so I have a JanusGraph where I define in the groovy script g with the EventStrategy and my Custom Listener
globals << [g : graph.traversal().withStrategies(EventStrategy.build().eventQueue(new CustomTransactionnalEventQueue(graph)).addListener(new CustomListener(graph.traversal())).create())]
globals << [g : graph.traversal().withStrategies(EventStrategy.build().eventQueue(new CustomTransactionnalEventQueue(graph)).addListener(new CustomListener(graph.traversal())).create())]
I then start it and see in my logs that both my transactionnal queue and listener are created Then I launch gremlin
./bin/gremlin.sh start
./bin/gremlin.sh start
gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Configured localhost/127.0.0.1:8182
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8182] - type ':remote console' to return to local mode
gremlin>
gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Configured localhost/127.0.0.1:8182
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8182] - type ':remote console' to return to local mode
gremlin>
I add a vertex
gremlin> g.addV("test")
==>v[245764288]
gremlin> g.addV("test")
==>v[245764288]
I see that my EventQueue size increased but my listener is not triggered. Since It's a transactionnal queue I try to use g.tx() :
gremlin> g.tx().open()
==>null
gremlin> g.addV("test2")
==>v[614404184]
gremlin> g.tx().commit()
==>null
gremlin> g.tx().close()
==>null
gremlin> g.tx().open()
==>null
gremlin> g.addV("test2")
==>v[614404184]
gremlin> g.tx().commit()
==>null
gremlin> g.tx().close()
==>null
but I see in my logs the same output as a lone g.addV(), my EventQueue gets populated with the event but my event queue is never fired. Basically in the TransactionnalEventQueue code below from EventStrategy class I have the feeling that I never go into the else part.
public TransactionalEventQueue(final Graph graph) {
if (!graph.features().graph().supportsTransactions()) {
throw new IllegalStateException(String.format("%s requires the graph to support transactions", EventStrategy.class.getName()));
} else {
graph.tx().addTransactionListener((status) -> {
if (status == Status.COMMIT) {
this.fireEventQueue();
} else {
if (status != Status.ROLLBACK) {
throw new RuntimeException(String.format("The %s is not aware of this status: %s", EventQueue.class.getName(), status));
}

this.resetEventQueue();
}

});
}
}
public TransactionalEventQueue(final Graph graph) {
if (!graph.features().graph().supportsTransactions()) {
throw new IllegalStateException(String.format("%s requires the graph to support transactions", EventStrategy.class.getName()));
} else {
graph.tx().addTransactionListener((status) -> {
if (status == Status.COMMIT) {
this.fireEventQueue();
} else {
if (status != Status.ROLLBACK) {
throw new RuntimeException(String.format("The %s is not aware of this status: %s", EventQueue.class.getName(), status));
}

this.resetEventQueue();
}

});
}
}
spmallette
spmallette14mo ago
Does this work if you take Gremlin Server out of the picture and just execute all the same directly in Gremlin Console or in a simple embedded application?
Napsetern
Napsetern14mo ago
I have tested it with a simple Java App , I tried commit, close and it's no different that just doing a simple addV(), event are catched and added to the event queue but listener is never fired on those event.
spmallette
spmallette14mo ago
do the EventStrategy tests run for @janusgraph ?
Napsetern
Napsetern14mo ago
I had no problem with a non TransactionnalEventQueue (I think it's called DefaultEventQueue) my event are caught and my listener is triggered
spmallette
spmallette14mo ago
that was a question for JanusGraph contributors. i'm wondering if the TinkerPop test suite that checks that functionality is running.
Dendriform
Dendriform14mo ago
There is a JanusGraph Discord server as well.
Bo
Bo14mo ago
EventStrategyProcessTest::shouldResetAfterRollback is disabled for JanusGraph. Others are enabled. @Napsetern Can you try this: after a transaction is completed, manually call
graph.tx().addTransactionListener(listener);
graph.tx().addTransactionListener(listener);
explicitly if you want to reuse this listener. See https://docs.janusgraph.org/changelog/#breaking-change-for-gremlin-eventstrategy-usage
spmallette
spmallette14mo ago
thanks - i didn't know that problem existed. EventStrategy is a nice idea but i'm not sure it's a good general purpose feature of TinkerPop. It also has the problem of being Java-only and it can't work remotely.
Napsetern
Napsetern14mo ago
Correct me if I'm wrong but you mean at the end in the status check in the transactionnalQueue ? If so no change noticed. So that means this default code will never trigger the listener a second time ?
graph.traversal().withStrategies(EventStrategy.build().eventQueue(new TransactionalEventQueue(graph)).addListener(new CustomListener()).create())
graph.traversal().withStrategies(EventStrategy.build().eventQueue(new TransactionalEventQueue(graph)).addListener(new CustomListener()).create())
since we never "re add" the transactionnal listener ?
Bo
Bo14mo ago
Unfortunately, yes So yeah... it's now very cumbersome to use EventStrategy with JanusGraph. I would just use https://docs.janusgraph.org/advanced-topics/transaction-log/ instead.
spmallette
spmallette14mo ago
yeah...i think this is a good point. i'm starting to feel like this sort of a use case is best left to individual graph systems to provide as a feature rather than it be a TinkerPop one.
Want results from more Discord servers?
Add your server
More Posts
Gremlin Query to give all related items in versioned graphI am working on a requirement where I need to store all version of a record in a Graph Database say Order group count result alphabeticallyHi! Given the following query and results in the enclosed image: how would I sort the labels alphabTransactions - tx.commit vs tx.closeI have a question related to transactions. I'm having issues with tx.commit() hanging locally when rExtracting the ProjectStep of a GraphTraversal instance during unit testing**Tl;dr** Given an instance of `GraphTraversal<?, Map<String, Object>>`, is it possible to extract tWhen can we get a non-RC release for Python 3.11 support in Production Envs?There was a bug where the version of aiohttp was too strict and blocked Python 3.11 support. ( httpsSubgraph query returns String instead of TinkerGraph Object in Fluent Java APIHi guys. I am running the following query in the console and it works fine: `g.V().has('user', 'id'Multiple Graphs in Gremlin Server?How do I manage multiple graphs? Is there an option where I can select which graph to use for query Has anyone else encountered "NoSuchElementException" when calling getLeafTrees() on a tree objectDid a little bit of debugging and it seems that the issue has to do with a cast to Tree before calliThe query gets slower as the number of vertices that already exist in JanusGraph gets bigger and bigWhen i start JanusGraph and perform any query like : - g.V().has(properties).limit(10).toList() - g.Is there a limitation on Neptune HTTP API endpoint compatibility when using a proxy and IAM Auth?Hi, Got a weird one today. I'm working on bringing full compatibility for the use of proxies fronti