You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/05/05 18:28:40 UTC
[1/4] incubator-tinkerpop git commit: Construct error message using
static member variable.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/master 80bfd8d82 -> 2cb33819f
Construct error message using static member variable.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/09b0c184
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/09b0c184
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/09b0c184
Branch: refs/heads/master
Commit: 09b0c18492cd1a2b292621b6bc924ab741d6a1a5
Parents: 24a1e9d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 5 07:58:56 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 5 07:58:56 2015 -0400
----------------------------------------------------------------------
.../org/apache/tinkerpop/gremlin/structure/util/GraphFactory.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/09b0c184/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/GraphFactory.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/GraphFactory.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/GraphFactory.java
index 29be657..97f56b1 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/GraphFactory.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/GraphFactory.java
@@ -52,7 +52,7 @@ public class GraphFactory {
final String clazz = configuration.getString(Graph.GRAPH, null);
if (null == clazz)
- throw new RuntimeException("Configuration must contain a valid 'gremlin.graph' setting");
+ throw new RuntimeException(String.format("Configuration must contain a valid '%s' setting", Graph.GRAPH));
final Class graphClass;
try {
[2/4] incubator-tinkerpop git commit: Added some javadoc to Graph.
Posted by sp...@apache.org.
Added some javadoc to Graph.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/9dff2d99
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/9dff2d99
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/9dff2d99
Branch: refs/heads/master
Commit: 9dff2d99bdc17dc09d13eb5150bb25283e961566
Parents: 09b0c18
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 5 08:11:17 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 5 08:11:17 2015 -0400
----------------------------------------------------------------------
.../main/java/org/apache/tinkerpop/gremlin/structure/Graph.java | 4 ++++
1 file changed, 4 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9dff2d99/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
index 62ae93f..1add3f9 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
@@ -27,6 +27,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.engine.StandardTraversalEn
import org.apache.tinkerpop.gremlin.structure.io.Io;
import org.apache.tinkerpop.gremlin.structure.io.IoRegistry;
import org.apache.tinkerpop.gremlin.structure.util.FeatureDescriptor;
+import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
import org.apache.tinkerpop.gremlin.structure.util.Host;
import org.javatuples.Pair;
@@ -55,6 +56,9 @@ import java.util.stream.Collectors;
*/
public interface Graph extends AutoCloseable, Host {
+ /**
+ * Configuration key used by {@link GraphFactory}} to determine which graph to instantiate.
+ */
public static final String GRAPH = "gremlin.graph";
/**
[4/4] incubator-tinkerpop git commit: GryoPool now takes a
Configuration object.
Posted by sp...@apache.org.
GryoPool now takes a Configuration object.
Allows setting of the pool initial size and the IoRegistry implementation to use. Added tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/2cb33819
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/2cb33819
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/2cb33819
Branch: refs/heads/master
Commit: 2cb33819f85fce0812697f70c2e5944e32e0251f
Parents: 7315e27
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 5 12:27:37 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 5 12:27:37 2015 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
.../gremlin/structure/io/gryo/GryoPool.java | 58 +++++++-
.../gremlin/structure/io/gryo/GryoPoolTest.java | 147 +++++++++++++++++++
3 files changed, 200 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2cb33819/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 3922e9e..930d513 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,6 +25,7 @@ image::http://www.tinkerpop.com/docs/current/images/gremlin-hindu.png[width=225]
TinkerPop 3.0.0.M9 (NOT OFFICIALLY RELEASED YET)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+* `GryoPool` now takes a `Configuration` object which allows setting the size of the pool and the `IoRegistry` instance.
* Added `PersistResultGraphAware` interface which is used by `OutputFormats` to specify persistence possibilities for a Hadoop `GraphComputer`.
* `ElementIdStrategy` now allows the identifier property to be set directly (and not only by specifying `T.id`).
* Added sample configuration files for registering a `TraversalStrategy` in Gremlin Server.
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2cb33819/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
index 044541f..20e084a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
@@ -18,48 +18,83 @@
*/
package org.apache.tinkerpop.gremlin.structure.io.gryo;
+import org.apache.commons.configuration.Configuration;
+import org.apache.tinkerpop.gremlin.structure.io.IoRegistry;
+import org.apache.tinkerpop.gremlin.structure.io.Mapper;
+
+import java.util.Optional;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.function.Consumer;
import java.util.function.Function;
/**
+ * Gryo objects are somewhat expensive to construct (given the dependency on Kryo), therefore this pool helps re-use
+ * those objects.
+ *
* @author Marko A. Rodriguez (http://markorodriguez.com)
+ * @author Stephen Mallette (http://stephen.genoprime.com)
*/
public class GryoPool {
+ public static final String CONFIG_IO_REGISTRY = "gremlin.io.registry";
+ public static final String CONFIG_IO_GRYO_POOL_SIZE = "gremlin.io.gryo.poolSize";
public enum Type {READER, WRITER, READER_WRITER}
private Queue<GryoReader> gryoReaders;
private Queue<GryoWriter> gryoWriters;
+ private final GryoMapper mapper;
+ public GryoPool(final Configuration conf) {
+ this(conf.getInt(CONFIG_IO_GRYO_POOL_SIZE, 256), Type.READER_WRITER, tryCreateIoRegistry(conf.getString(CONFIG_IO_REGISTRY, "")));
+ }
+
+ /**
+ * Create a pool of readers and writers of specified size and use the default {@link GryoMapper} (which means
+ * that custom serializers from vendors will not be applied.
+ *
+ * @param poolSize size of the pool.
+ */
public GryoPool(final int poolSize) {
- this(poolSize, Type.READER_WRITER);
+ this(poolSize, Type.READER_WRITER, Optional.empty());
}
- public GryoPool(final int poolSize, final Type type) {
+ /**
+ * Create a pool of a readers, writers or both of the specified size with an optional {@link IoRegistry} object
+ * which would allow custom serializers to be registered to the pool.
+ *
+ * @param poolSize size of the pool.
+ * @param type the type of pool.
+ * @param ioRegistry the registry to assign to each {@link GryoReader} and {@link GryoWriter} instances.
+ */
+ public GryoPool(final int poolSize, final Type type, final Optional<IoRegistry> ioRegistry) {
+ final GryoMapper.Builder mapperBuilder = GryoMapper.build();
+ ioRegistry.ifPresent(mapperBuilder::addRegistry);
+
+ // should be able to re-use the GryoMapper - it creates fresh kryo instances from its createMapper method
+ mapper = mapperBuilder.create();
if (type.equals(Type.READER) || type.equals(Type.READER_WRITER)) {
this.gryoReaders = new LinkedBlockingQueue<>(poolSize);
for (int i = 0; i < poolSize; i++) {
- this.gryoReaders.add(GryoReader.build().create());
+ this.gryoReaders.add(GryoReader.build().mapper(mapper).create());
}
}
if (type.equals(Type.WRITER) || type.equals(Type.READER_WRITER)) {
this.gryoWriters = new LinkedBlockingQueue<>(poolSize);
for (int i = 0; i < poolSize; i++) {
- this.gryoWriters.add(GryoWriter.build().create());
+ this.gryoWriters.add(GryoWriter.build().mapper(mapper).create());
}
}
}
public GryoReader takeReader() {
final GryoReader reader = this.gryoReaders.poll();
- return null == reader ? GryoReader.build().create() : reader;
+ return null == reader ? GryoReader.build().mapper(mapper).create() : reader;
}
public GryoWriter takeWriter() {
final GryoWriter writer = this.gryoWriters.poll();
- return null == writer ? GryoWriter.build().create() : writer;
+ return null == writer ? GryoWriter.build().mapper(mapper).create() : writer;
}
public void offerReader(final GryoReader gryoReader) {
@@ -82,4 +117,15 @@ public class GryoPool {
writerFunction.accept(gryoWriter);
this.offerWriter(gryoWriter);
}
+
+ private static Optional<IoRegistry> tryCreateIoRegistry(final String className) {
+ if (className.isEmpty()) return Optional.empty();
+
+ try {
+ final Class clazz = Class.forName(className);
+ return Optional.of((IoRegistry) clazz.newInstance());
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2cb33819/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java
new file mode 100644
index 0000000..ddc1aeb
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.structure.io.gryo;
+
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.apache.tinkerpop.gremlin.structure.io.AbstractIoRegistry;
+import org.apache.tinkerpop.gremlin.util.function.FunctionUtils;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class GryoPoolTest {
+
+ @Test
+ public void shouldDoWithReaderWriterMethods() throws Exception {
+ final Configuration conf = new BaseConfiguration();
+ final GryoPool pool = new GryoPool(conf);
+ try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
+ pool.doWithWriter(writer -> writer.writeObject(os, 1));
+ os.flush();
+ try (final ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray())) {
+ assertEquals(1, pool.<Integer>doWithReader(FunctionUtils.wrapFunction(reader -> reader.readObject(is, Integer.class))).intValue());
+ }
+ }
+ assertReaderWriter(pool.takeWriter(), pool.takeReader(), 1, Integer.class);
+ }
+
+ @Test
+ public void shouldConfigPoolOnConstructionWithDefaults() throws Exception {
+ final Configuration conf = new BaseConfiguration();
+ final GryoPool pool = new GryoPool(conf);
+ assertReaderWriter(pool.takeWriter(), pool.takeReader(), 1, Integer.class);
+ }
+
+ @Test
+ public void shouldConfigPoolOnConstructionWithPoolSizeOneAndNoIoRegistry() throws Exception {
+ final Configuration conf = new BaseConfiguration();
+ conf.setProperty(GryoPool.CONFIG_IO_GRYO_POOL_SIZE, 1);
+ final GryoPool pool = new GryoPool(conf);
+ final GryoReader reader = pool.takeReader();
+ final GryoWriter writer = pool.takeWriter();
+
+ pool.offerReader(reader);
+ pool.offerWriter(writer);
+
+ for (int ix = 0; ix < 100; ix++) {
+ final GryoReader r = pool.takeReader();
+ final GryoWriter w = pool.takeWriter();
+ assertReaderWriter(w, r, 1, Integer.class);
+
+ // should always return the same original instance
+ assertEquals(reader, r);
+ assertEquals(writer, w);
+
+ pool.offerReader(r);
+ pool.offerWriter(w);
+ }
+ }
+
+ @Test
+ public void shouldConfigPoolOnConstructionWithCustomIoRegistry() throws Exception {
+ final Configuration conf = new BaseConfiguration();
+ conf.setProperty(GryoPool.CONFIG_IO_REGISTRY, CustomIoRegistry.class.getName());
+ final GryoPool pool = new GryoPool(conf);
+ assertReaderWriter(pool.takeWriter(), pool.takeReader(), new Junk("test"), Junk.class);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void shouldConfigPoolOnConstructionWithoutCustomIoRegistryAndFail() throws Exception {
+ final Configuration conf = new BaseConfiguration();
+ final GryoPool pool = new GryoPool(conf);
+ assertReaderWriter(pool.takeWriter(), pool.takeReader(), new Junk("test"), Junk.class);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void shouldConfigPoolOnConstructionWithoutBadIoRegistryAndFail() throws Exception {
+ final Configuration conf = new BaseConfiguration();
+ conf.setProperty(GryoPool.CONFIG_IO_REGISTRY, "some.class.that.does.not.exist");
+ new GryoPool(conf);
+ }
+
+ private static <T> void assertReaderWriter(final GryoWriter writer, final GryoReader reader, final T o,
+ final Class<T> clazz) throws Exception{
+ try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
+ writer.writeObject(os, o);
+ os.flush();
+ try (final ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray())) {
+ assertEquals(o, reader.readObject(is, clazz));
+ }
+ }
+ }
+
+ public static class Junk {
+ private String x;
+
+ private Junk() {}
+
+ public Junk(final String x) {
+ this.x = x;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ final Junk junk = (Junk) o;
+
+ return x.equals(junk.x);
+
+ }
+
+ @Override
+ public int hashCode() {
+ return x.hashCode();
+ }
+ }
+
+ public static class CustomIoRegistry extends AbstractIoRegistry {
+ public CustomIoRegistry() {
+ register(GryoIo.class, Junk.class, null);
+ }
+ }
+}
[3/4] incubator-tinkerpop git commit: Merge remote-tracking branch
'origin/master'
Posted by sp...@apache.org.
Merge remote-tracking branch 'origin/master'
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/7315e279
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/7315e279
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/7315e279
Branch: refs/heads/master
Commit: 7315e2791473ce0e7bd710c8adff47140b54eee1
Parents: 9dff2d9 80bfd8d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue May 5 12:12:46 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue May 5 12:12:46 2015 -0400
----------------------------------------------------------------------
.../process/traversal/TraversalEngine.java | 54 ++++++++-
.../process/traversal/TraversalStrategies.java | 62 +++++-----
.../process/traversal/TraversalStrategy.java | 105 +++++++++++++++--
.../dsl/graph/GraphTraversalSource.java | 26 ++---
.../engine/ComputerTraversalEngine.java | 44 +++++--
.../engine/StandardTraversalEngine.java | 5 -
.../traversal/lambda/HasNextTraversal.java | 9 +-
.../traversal/step/branch/BranchStep.java | 2 +-
.../traversal/step/map/OrderGlobalStep.java | 25 +++-
.../step/util/TraversalComparator.java | 4 +
.../strategy/AbstractTraversalStrategy.java | 2 +-
.../decoration/ConjunctionStrategy.java | 83 +++++++++++++
.../strategy/decoration/ElementIdStrategy.java | 12 +-
.../strategy/decoration/EventStrategy.java | 3 +-
.../decoration/LabeledEndStepStrategy.java | 51 ++++++++
.../strategy/decoration/PartitionStrategy.java | 3 +-
.../strategy/decoration/SubgraphStrategy.java | 3 +-
.../finalization/EngineDependentStrategy.java | 46 ++++++++
.../strategy/finalization/ProfileStrategy.java | 91 +++++++++++++++
.../ComparatorHolderRemovalStrategy.java | 55 +++++++++
.../optimization/ConjunctionStrategy.java | 83 -------------
.../optimization/DedupBijectionStrategy.java | 76 ++++++++++++
.../optimization/DedupOptimizerStrategy.java | 75 ------------
.../optimization/IdentityRemovalStrategy.java | 3 +-
.../optimization/MatchWhereStrategy.java | 6 +-
.../strategy/optimization/ProfileStrategy.java | 115 -------------------
.../optimization/RangeByIsCountStrategy.java | 4 +-
.../ComparatorHolderRemovalStrategy.java | 54 ---------
.../ComputerVerificationStrategy.java | 75 ++++++++++++
.../verification/EngineDependentStrategy.java | 46 --------
.../verification/LabeledEndStepStrategy.java | 50 --------
.../verification/LambdaRestrictionStrategy.java | 3 +-
.../strategy/verification/ReadOnlyStrategy.java | 3 +-
.../TraversalVerificationStrategy.java | 72 ------------
.../traversal/util/DefaultTraversal.java | 6 +-
.../util/DefaultTraversalStrategies.java | 12 +-
.../util/EmptyTraversalStrategies.java | 4 +-
.../process/TraversalStrategiesTest.java | 111 +++++++++++++++---
.../optimization/TinkerGraphStepStrategy.java | 20 +++-
39 files changed, 880 insertions(+), 623 deletions(-)
----------------------------------------------------------------------