Skip to content

Commit ca5544d

Browse files
committed
Merge branch '3.7-dev' into 3.8-dev
2 parents c52dc72 + 98ffa44 commit ca5544d

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

CHANGELOG.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
8686
=== TinkerPop 3.7.4 (NOT OFFICIALLY RELEASED YET)
8787
8888
* Fixed bug in server `Settings` where it was referencing a property that was back in 3.3.0 and generating a warning log.
89+
* Improved performance of `Traversal.lock()` which was being called excessively.
8990
* Added log entry in `WsAndHttpChannelizerHandler` to catch general errors that escape the handlers.
9091
* Added a `MessageSizeEstimator` implementation to cover `Frame` allowing Gremlin Server to better estimate message sizes for the direct buffer.
9192
* Fixed bug in Gremlin Console for field accessor issue with JDK17.

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,10 @@ public void lock() {
335335
// lock the parent before the children
336336
this.locked = true;
337337

338-
// now lock all the children
339-
TraversalHelper.applyTraversalRecursively(Admin::lock, this, true);
338+
// now lock all the children. since it's being called recursively here, we don't need each child to then
339+
// also call this recursively TINKERPOP-3100
340+
if (isRoot() || parent instanceof VertexProgramStep)
341+
TraversalHelper.applyTraversalRecursively(Admin::lock, this, true);
340342
}
341343

342344
/**

gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversalTest.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@
2020
package org.apache.tinkerpop.gremlin.process.traversal.util;
2121

2222
import org.apache.tinkerpop.gremlin.process.traversal.Operator;
23+
import org.apache.tinkerpop.gremlin.process.traversal.P;
2324
import org.apache.tinkerpop.gremlin.process.traversal.Step;
2425
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
2526
import org.apache.tinkerpop.gremlin.process.traversal.TraversalSideEffects;
2627
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal;
28+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
2729
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
2830
import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
31+
import org.apache.tinkerpop.gremlin.structure.Graph;
32+
import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
2933
import org.apache.tinkerpop.gremlin.util.function.ConstantSupplier;
3034
import org.apache.tinkerpop.gremlin.util.function.HashSetSupplier;
3135
import org.hamcrest.CoreMatchers;
@@ -42,13 +46,15 @@
4246
import java.util.stream.Collectors;
4347
import java.util.stream.IntStream;
4448

49+
import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
4550
import static org.hamcrest.number.OrderingComparison.greaterThan;
4651
import static org.hamcrest.number.OrderingComparison.lessThan;
4752
import static org.junit.Assert.assertEquals;
4853
import static org.junit.Assert.assertFalse;
4954
import static org.junit.Assert.assertNotEquals;
5055
import static org.junit.Assert.assertNotSame;
5156
import static org.hamcrest.MatcherAssert.assertThat;
57+
import static org.hamcrest.core.Is.is;
5258
import static org.junit.Assert.assertTrue;
5359

5460
/**
@@ -127,6 +133,53 @@ public void shouldBeTheSameSideEffectsThroughoutAllChildTraversals() {
127133
recursiveTestTraversals(traversal, sideEffects, new HashSet<>(Arrays.asList("marko", "bob", "x")), 13);
128134
}
129135

136+
@Test
137+
public void shouldLock() {
138+
final Traversal t = getBigDeepTraversal();
139+
t.asAdmin().lock();
140+
recursiveTestLock(t.asAdmin());
141+
}
142+
143+
144+
@Test
145+
public void shouldLockAfterApplyingStrategies() {
146+
final Traversal t = getBigDeepTraversal();
147+
t.asAdmin().applyStrategies();
148+
recursiveTestLock(t.asAdmin());
149+
}
150+
151+
private static Traversal getBigDeepTraversal() {
152+
final Graph graph = EmptyGraph.instance();
153+
final GraphTraversalSource g = traversal().withEmbedded(graph);
154+
155+
final Traversal t = g.V().or(
156+
__.has("name", P.within(new HashSet<>(Arrays.asList("DARK STAR", "ST. STEPHEN", "CHINA CAT SUNFLOWER")))),
157+
__.has("songType", P.eq("cover"))).where(
158+
__.coalesce(
159+
__.where(
160+
__.union(
161+
__.as("a").inE("sungBy").choose(
162+
__.has("weight"), __.has("weight", P.gt(1)), __.identity()
163+
).outV().filter(__.has("weight", P.lt(1))),
164+
__.as("a").outE("followedBy").choose(
165+
__.has("weight"), __.has("weight", P.gt(1)), __.identity()
166+
).inV().where(__.identity())
167+
).dedup().select("a")
168+
)
169+
));
170+
return t;
171+
}
172+
173+
private void recursiveTestLock(final Traversal.Admin<?, ?> traversal) {
174+
assertThat(traversal.isLocked(), is(true));
175+
for (final Step<?, ?> step : traversal.getSteps()) {
176+
if (step instanceof TraversalParent) {
177+
((TraversalParent) step).getGlobalChildren().forEach(this::recursiveTestLock);
178+
((TraversalParent) step).getLocalChildren().forEach(this::recursiveTestLock);
179+
}
180+
}
181+
}
182+
130183
private void recursiveTestTraversals(final Traversal.Admin<?, ?> traversal, final TraversalSideEffects sideEffects, final Set aValue, final int bValue) {
131184
assertTrue(traversal.getSideEffects() == sideEffects);
132185
assertEquals(sideEffects.keys().size(), traversal.getSideEffects().keys().size());

0 commit comments

Comments
 (0)