Description
When multiple options like with("x",1).with("y",1) are used to build a traversal, the Bytecode building logic when constructing the traversal on the server keeps appending the Bytecode incrementally instead of replacing the previous Bytecode instruction.
For a query like below:
g .with('evaluationTimeout',300000L) .with('a', 1) .with('b', 2) .with('c', 3) .V()
The Bytecode attached to traversal looks as:
g .withStrategies(new org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.OptionsStrategy(evaluationTimeout: 300000L)) .withStrategies(new org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.OptionsStrategy(evaluationTimeout: 300000L, a: (int) 1)) .withStrategies(new org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.OptionsStrategy(evaluationTimeout: 300000L, a: (int) 1, b: (int) 2)) .withStrategies(new org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.OptionsStrategy(evaluationTimeout: 300000L, a: (int) 1, b: (int) 2, c: (int) 3)) .V()
Instead it should be just single instruction for OptionsStrategy as:
g .withStrategies(new org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.OptionsStrategy(evaluationTimeout: 300000L, a: (int) 1, b: (int) 2, c: (int) 3)) .V()
We always build a new OptionsStrategy here and carry over the previous options https://github.com/apache/tinkerpop/blob/master/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java#L116-L122
as OptionsStrategy itself is immutable and we cannot add new options after creating it.
We build the traversal strategies set and bytecode here:
The traversal strategies set itself is built correctly and we remove duplicates https://github.com/apache/tinkerpop/blob/master/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversalStrategies.java#L42-L50
But Bytecode just appends the new strategy as instruction https://github.com/apache/tinkerpop/blob/master/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java#L82-L83