fix: Traversal.graph is empty in StepStrategy.apply() with count().is(0)#1699
fix: Traversal.graph is empty in StepStrategy.apply() with count().is(0)#1699javeme wants to merge 2 commits intoapache:3.5-devfrom
count().is(0)#1699Conversation
count().is(0)
|
The following is the stack trace when 2022-06-13 23:18:00 [gremlin-server-exec-2] [WARN] o.a.t.g.s.h.HttpHandlerUtil - Invalid request - responding with 500 Internal Server Error and Error encountered evaluating script: g.V(3).repeat(inE('child').outV().simplePath()).until(or(inE().count().is(0),loops().is(eq(2)))).path()
java.lang.NullPointerException: null
at com.baidu.hugegraph.traversal.optimize.HugeVertexStepStrategy.apply(HugeVertexStepStrategy.java:73) ~[classes/:?]
at com.baidu.hugegraph.auth.HugeGraphAuthProxy$TraversalStrategyProxy.apply(HugeGraphAuthProxy.java:1722) ~[classes/:?]
at org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper.applyTraversalRecursively(TraversalHelper.java:467) ~[gremlin-core-3.5.1.jar:3.5.1]
at org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper.applyTraversalRecursively(TraversalHelper.java:475) ~[gremlin-core-3.5.1.jar:3.5.1]
at org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper.applyTraversalRecursively(TraversalHelper.java:475) ~[gremlin-core-3.5.1.jar:3.5.1]
at org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper.applyTraversalRecursively(TraversalHelper.java:475) ~[gremlin-core-3.5.1.jar:3.5.1]
at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.applyStrategies(DefaultTraversal.java:151) ~[gremlin-core-3.5.1.jar:3.5.1]
at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.hasNext(DefaultTraversal.java:221) ~[gremlin-core-3.5.1.jar:3.5.1]
at org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils.fill(IteratorUtils.java:62) ~[gremlin-core-3.5.1.jar:3.5.1]
at org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils.list(IteratorUtils.java:85) ~[gremlin-core-3.5.1.jar:3.5.1]
at org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils.asList(IteratorUtils.java:382) ~[gremlin-core-3.5.1.jar:3.5.1]
at org.apache.tinkerpop.gremlin.server.handler.HttpGremlinEndpointHandler.lambda$channelRead$1(HttpGremlinEndpointHandler.java:221) ~[gremlin-server-3.5.1.jar:3.5.1]
at org.apache.tinkerpop.gremlin.util.function.FunctionUtils.lambda$wrapFunction$0(FunctionUtils.java:36) ~[gremlin-core-3.5.1.jar:3.5.1]
at org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.lambda$eval$0(GremlinExecutor.java:278) ~[gremlin-groovy-3.5.1.jar:3.5.1]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_111]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_111]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_111]
at com.baidu.hugegraph.auth.HugeGraphAuthProxy$ContextTask.run(HugeGraphAuthProxy.java:1838) [classes/:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_111]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_111]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111] |
|
sorry no one has had a chance to look at this until now. i think you've identified the problem well. A few things:
|
|
Thanks for your review.
|
Codecov Report
@@ Coverage Diff @@
## 3.5-dev #1699 +/- ##
========================================
Coverage 63.27% 63.27%
========================================
Files 23 23
Lines 3553 3553
========================================
Hits 2248 2248
Misses 1131 1131
Partials 174 174 Continue to review full report at Codecov.
|
|
i have this more generalized fix i'm considering: 8a7049f i don't like that it adds yet another round of recursion. i'm questioning if strategy application should even be responsible for this, but its always been this way. i don't think this adds any significant performance penalty as strategy application is already pretty fast. in any event, if you have a way to test this fix on your end, that would be helpful but i'm leaning toward this approach for at least the branches we can't take breaks in. |
…s(0)`
This PR fix: traversal.getGraph() is empty in StepStrategy.apply() method
`VertexStepStrategy.apply(Traversal.Admin<?, ?> traversal)`
for the following gremlin:
```
g.V(3).repeat(inE('child').outV().simplePath())
.until(or(inE().count().is(0),loops().is(eq(2))))
.path()
```
|
I think it's ok to assign graph instance after each strategy is applied, it ensures that the So do we need to merge this PR as a bug record, or abandon it? |
|
I have compiled and tested this fix on hugegraph backend, it works as expected. |
|
if that fix works then i think we would just close this PR and assume the problem satisfied by the change you tested. thanks for bringing this up. i'll close this after the other fix gets merged. |
|
merged the fix noted above as 1a548e8 |
|
@javeme this is a bit old now, but it seems we must revisit it. the fix mentioned here is being rolled back for 3.5.6/3.6.3. that extra recursion is proving too costly. please see the latest work on this here: #2026 if you find the |
|
Thank you for your notice. According to #2026 it seems that the |
|
yes - the |
This PR fixed:
traversal.getGraph()is empty inStepStrategy.apply()methodVertexStepStrategy.apply(Traversal.Admin traversal)for the following Gremlin:Initial data:
Cause analysis:
In the case of a non
count().is(0)statement, the graph context is passed here:tinkerpop/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
Line 138 in f8af061
So we can get the graph context when Strategy.apply() is called:
tinkerpop/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
Line 152 in f8af061
But when using the
count().is(0)statement, the graph context is missing because the original traversal is replaced with a new traversal by__.start():tinkerpop/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/CountStrategy.java
Line 154 in 7f7d3a4
The
__.start()method implementation:tinkerpop/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
Line 59 in 2c24493