You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by Ted Wilmes <tw...@gmail.com> on 2015/10/16 17:08:26 UTC
repeat step interaction with optimization strategy
Hi guys,
I'm finally trying my hand at a Titan bug fix and I've come up with a
TinkerPop question related to how the repeat step works under the covers
and the implications for query optimization strategies. For reference, you
can find the issue here: http://bit.ly/1OImTBF
In summary, with Titan's batching turned on, a NPE is generated with
traversals that make use of repeat, a very simple example being:
g.V().has('id', 1).emit().repeat(out('knows'))
Same behavior can be seen when the 'emit' is placed post-repeat. Jumping
over to the TitanVertex step, the stack trace leads to the multi query
results not being populated during the execution of the batching
optimization in the processNextStart(). Relevant chunks of code can be
seen at http://bit.ly/1KdpKwb between lines 65 and 100 with the NPE being
thrown on 95.
So, big question is why bring this to the TinkerPop list? After tracing
through the execution, I believe this has to do with how the repeat step is
working and when certain pieces of info, namely the 'starts' are made
available to the nested out step that this TitanVertexStep is
representing. In the non repeat steps case, the processNextStart() of the
TitanVertexStep is called and if batch=true, the step is initialized, ie.
the multi query call is made using the steps 'starts' or inbound vertices
from the previous step (at least that's how I'm conceptualized this but
correct me if I'm wrong). Now, if a repeat is used in the query, I've
noticed that the initial check to see if there are any starts available
fails and throws the FastNoSuchElementException. The multi query results
are not initialized, and when the flatMap is finally called, this leads to
the NPE. My possibly naive assumption is that the starts are not available
because in a repeat situation, the TitanVertexStep is in fact nested within
the repeat step which in it of itself initially doesn't carry those starts
forward. While playing around with the ordering of things, I was able to
get the emit().repeat(out('knows') case to work if I did an additional
check within the flatMap to see if the data was initialized, and If not, I
called initialize again and at that point, the starts were in fact
available. This proved to not work though for the
repeat(out('knows')).emit() case.
So, long story short, my question is, given this optimization strategy
where all of the previous steps vertices must be available to execute the
batched retrieval, is there a different way to handle the case where the
step is nested within a repeat? After tracing through the execution, my
thoughts included possibly reaching back up into the traverser but that
felt prone to error and a violation of the boundaries between the
implementer customizations and core TinkerPop.
Thanks!
Ted
Re: repeat step interaction with optimization strategy
Posted by Ted Wilmes <tw...@gmail.com>.
Hey Marko,
Thanks for the pointers and yes, you nailed it, I was referring to the
multi-query optimization in particular. Your relation of this to a barrier
is helpful and how I was conceptualizing this sort of optimization. I'll
dig into what you've provided here and first thing first, get the full test
suite running with multi-query turned on to ferret out any other issues.
Thanks,
Ted
On Tue, Oct 20, 2015 at 11:50 AM, Marko Rodriguez <ok...@gmail.com>
wrote:
> Hey Ted,
>
> That is a bomb of a question. Let me see what I can do.
>
> First, I'm going to assume by "bulking" you mean Titan's "multi-query"
> functionality. I'll call it "multi-query" as bulking has a different
> meaning in TinkerPop.
>
> Second, Titan has to pass TinkerPop's test suite to be considered
> "TinkerPop-enabled." There are various repeat().emit()-style tests in
> RepeatTest.
>
> https://github.com/apache/incubator-tinkerpop/blob/master/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatTest.java#L51-L67
> If I were you, I would submit a PR to Titan that runs the
> StandardProcessTestSuite with TWO GraphProviders (e.g.
> TitanMultiQueryGraphProvider and TitanGraphProvider). One with multi-query
> turned on and one with multi-query turned off. Doing this will help shake
> out any bugs in their optimizers as it relates to multi-query.
>
> Third, the hard part… damn.
> 1. This line is scary:
> https://github.com/thinkaurelius/titan/blob/1349a5edd1149a00da6a37a4584aed25a8164a14/titan-core/src/main/java/com/thinkaurelius/titan/graphdb/tinkerpop/optimize/TitanVertexStep.java#L77
> - Why do you drain the starts and then just add the starts
> right back?
> 2. TitanVertexStep (w/ multi-query) is acting like a "barrier" and
> barriers in repeat() can cause problems (we don't allow
> ReducingBarrierSteps in repeat()). Perhaps the same problems are creeping
> up here.
>
> https://github.com/apache/incubator-tinkerpop/blob/master/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java#L39-L42
> - CollectingBarrrierSteps work which is what
> TitanVertexStep "seems" to me. However, perhaps it requires a "reset()" on
> each next() if its in multi-query mode.
> 3. I suspect the issue is here:
>
> https://github.com/apache/incubator-tinkerpop/blob/master/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java#L154-L156
>
> https://github.com/apache/incubator-tinkerpop/blob/master/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java#L240-L260
>
> See where that takes you…
>
> Thanks Ted,
> Marko.
>
> http://markorodriguez.com
>
> On Oct 16, 2015, at 9:08 AM, Ted Wilmes <tw...@gmail.com> wrote:
>
> > Hi guys,
> > I'm finally trying my hand at a Titan bug fix and I've come up with a
> > TinkerPop question related to how the repeat step works under the covers
> > and the implications for query optimization strategies. For reference,
> you
> > can find the issue here: http://bit.ly/1OImTBF
> >
> > In summary, with Titan's batching turned on, a NPE is generated with
> > traversals that make use of repeat, a very simple example being:
> >
> > g.V().has('id', 1).emit().repeat(out('knows'))
> >
> >
> > Same behavior can be seen when the 'emit' is placed post-repeat. Jumping
> > over to the TitanVertex step, the stack trace leads to the multi query
> > results not being populated during the execution of the batching
> > optimization in the processNextStart(). Relevant chunks of code can be
> > seen at http://bit.ly/1KdpKwb between lines 65 and 100 with the NPE
> being
> > thrown on 95.
> >
> > So, big question is why bring this to the TinkerPop list? After tracing
> > through the execution, I believe this has to do with how the repeat step
> is
> > working and when certain pieces of info, namely the 'starts' are made
> > available to the nested out step that this TitanVertexStep is
> > representing. In the non repeat steps case, the processNextStart() of
> the
> > TitanVertexStep is called and if batch=true, the step is initialized, ie.
> > the multi query call is made using the steps 'starts' or inbound vertices
> > from the previous step (at least that's how I'm conceptualized this but
> > correct me if I'm wrong). Now, if a repeat is used in the query, I've
> > noticed that the initial check to see if there are any starts available
> > fails and throws the FastNoSuchElementException. The multi query results
> > are not initialized, and when the flatMap is finally called, this leads
> to
> > the NPE. My possibly naive assumption is that the starts are not
> available
> > because in a repeat situation, the TitanVertexStep is in fact nested
> within
> > the repeat step which in it of itself initially doesn't carry those
> starts
> > forward. While playing around with the ordering of things, I was able to
> > get the emit().repeat(out('knows') case to work if I did an additional
> > check within the flatMap to see if the data was initialized, and If not,
> I
> > called initialize again and at that point, the starts were in fact
> > available. This proved to not work though for the
> > repeat(out('knows')).emit() case.
> >
> > So, long story short, my question is, given this optimization strategy
> > where all of the previous steps vertices must be available to execute the
> > batched retrieval, is there a different way to handle the case where the
> > step is nested within a repeat? After tracing through the execution, my
> > thoughts included possibly reaching back up into the traverser but that
> > felt prone to error and a violation of the boundaries between the
> > implementer customizations and core TinkerPop.
> >
> > Thanks!
> > Ted
>
>
Re: repeat step interaction with optimization strategy
Posted by Marko Rodriguez <ok...@gmail.com>.
Hey Ted,
That is a bomb of a question. Let me see what I can do.
First, I'm going to assume by "bulking" you mean Titan's "multi-query" functionality. I'll call it "multi-query" as bulking has a different meaning in TinkerPop.
Second, Titan has to pass TinkerPop's test suite to be considered "TinkerPop-enabled." There are various repeat().emit()-style tests in RepeatTest.
https://github.com/apache/incubator-tinkerpop/blob/master/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatTest.java#L51-L67
If I were you, I would submit a PR to Titan that runs the StandardProcessTestSuite with TWO GraphProviders (e.g. TitanMultiQueryGraphProvider and TitanGraphProvider). One with multi-query turned on and one with multi-query turned off. Doing this will help shake out any bugs in their optimizers as it relates to multi-query.
Third, the hard part… damn.
1. This line is scary: https://github.com/thinkaurelius/titan/blob/1349a5edd1149a00da6a37a4584aed25a8164a14/titan-core/src/main/java/com/thinkaurelius/titan/graphdb/tinkerpop/optimize/TitanVertexStep.java#L77
- Why do you drain the starts and then just add the starts right back?
2. TitanVertexStep (w/ multi-query) is acting like a "barrier" and barriers in repeat() can cause problems (we don't allow ReducingBarrierSteps in repeat()). Perhaps the same problems are creeping up here.
https://github.com/apache/incubator-tinkerpop/blob/master/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java#L39-L42
- CollectingBarrrierSteps work which is what TitanVertexStep "seems" to me. However, perhaps it requires a "reset()" on each next() if its in multi-query mode.
3. I suspect the issue is here:
https://github.com/apache/incubator-tinkerpop/blob/master/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java#L154-L156
https://github.com/apache/incubator-tinkerpop/blob/master/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java#L240-L260
See where that takes you…
Thanks Ted,
Marko.
http://markorodriguez.com
On Oct 16, 2015, at 9:08 AM, Ted Wilmes <tw...@gmail.com> wrote:
> Hi guys,
> I'm finally trying my hand at a Titan bug fix and I've come up with a
> TinkerPop question related to how the repeat step works under the covers
> and the implications for query optimization strategies. For reference, you
> can find the issue here: http://bit.ly/1OImTBF
>
> In summary, with Titan's batching turned on, a NPE is generated with
> traversals that make use of repeat, a very simple example being:
>
> g.V().has('id', 1).emit().repeat(out('knows'))
>
>
> Same behavior can be seen when the 'emit' is placed post-repeat. Jumping
> over to the TitanVertex step, the stack trace leads to the multi query
> results not being populated during the execution of the batching
> optimization in the processNextStart(). Relevant chunks of code can be
> seen at http://bit.ly/1KdpKwb between lines 65 and 100 with the NPE being
> thrown on 95.
>
> So, big question is why bring this to the TinkerPop list? After tracing
> through the execution, I believe this has to do with how the repeat step is
> working and when certain pieces of info, namely the 'starts' are made
> available to the nested out step that this TitanVertexStep is
> representing. In the non repeat steps case, the processNextStart() of the
> TitanVertexStep is called and if batch=true, the step is initialized, ie.
> the multi query call is made using the steps 'starts' or inbound vertices
> from the previous step (at least that's how I'm conceptualized this but
> correct me if I'm wrong). Now, if a repeat is used in the query, I've
> noticed that the initial check to see if there are any starts available
> fails and throws the FastNoSuchElementException. The multi query results
> are not initialized, and when the flatMap is finally called, this leads to
> the NPE. My possibly naive assumption is that the starts are not available
> because in a repeat situation, the TitanVertexStep is in fact nested within
> the repeat step which in it of itself initially doesn't carry those starts
> forward. While playing around with the ordering of things, I was able to
> get the emit().repeat(out('knows') case to work if I did an additional
> check within the flatMap to see if the data was initialized, and If not, I
> called initialize again and at that point, the starts were in fact
> available. This proved to not work though for the
> repeat(out('knows')).emit() case.
>
> So, long story short, my question is, given this optimization strategy
> where all of the previous steps vertices must be available to execute the
> batched retrieval, is there a different way to handle the case where the
> step is nested within a repeat? After tracing through the execution, my
> thoughts included possibly reaching back up into the traverser but that
> felt prone to error and a violation of the boundaries between the
> implementer customizations and core TinkerPop.
>
> Thanks!
> Ted