You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2015/04/21 23:42:45 UTC

incubator-tinkerpop git commit: VertexWritable now serializes and deserializes the StarGraph directly -- no more intermediate DetachedXXX representation. Less object creation and less strain on the GC.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master 9378af66c -> 24ffbddfe


VertexWritable now serializes and deserializes the StarGraph directly -- no more intermediate DetachedXXX representation. Less object creation and less strain on the GC.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/24ffbddf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/24ffbddf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/24ffbddf

Branch: refs/heads/master
Commit: 24ffbddfe0d8b9f9b02505fbc84ce462019cb8c8
Parents: 9378af6
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Apr 21 15:42:41 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Apr 21 15:42:41 2015 -0600

----------------------------------------------------------------------
 CHANGELOG.asciidoc                                |  1 +
 .../gremlin/structure/io/gryo/GryoMapper.java     | 18 +++++++++++-------
 .../gremlin/structure/util/star/StarGraph.java    |  5 +++--
 .../hadoop/structure/io/VertexWritable.java       |  9 ++-------
 4 files changed, 17 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/24ffbddf/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 6391c2a..80e05e9 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)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* `VertexWritable` serializes and deserializes the `StarGraph` object -- no more intermediate `DetachedXXX` objects.
 * Moved `T` tokens to the `structure/` package as its more general than `process/`.
 * `Attachable.attach()` now takes a `Method` to determine whether to attach via `GET`, `CREATE`, or `GET_OR_CREATE`.
 * Decreased size of Gremlin Server `RequestMessage` and `ResponseMessage` serialization payloads and reduced object creation.

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/24ffbddf/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
index 191b2fe..07417b2 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
@@ -21,7 +21,6 @@ package org.apache.tinkerpop.gremlin.structure.io.gryo;
 import org.apache.tinkerpop.gremlin.process.computer.MapReduce;
 import org.apache.tinkerpop.gremlin.process.computer.util.MapMemory;
 import org.apache.tinkerpop.gremlin.process.traversal.Path;
-import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.B_O_PA_S_SE_SL_Traverser;
@@ -36,6 +35,7 @@ import org.apache.tinkerpop.gremlin.structure.Contains;
 import org.apache.tinkerpop.gremlin.structure.Direction;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.apache.tinkerpop.gremlin.structure.io.IoRegistry;
@@ -50,6 +50,7 @@ import org.apache.tinkerpop.gremlin.structure.util.reference.ReferencePath;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceProperty;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertex;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
 import org.apache.tinkerpop.shaded.kryo.Kryo;
 import org.apache.tinkerpop.shaded.kryo.KryoSerializable;
 import org.apache.tinkerpop.shaded.kryo.Serializer;
@@ -194,7 +195,9 @@ public final class GryoMapper implements Mapper<Kryo> {
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(ReferenceVertexProperty.class, null, 82));
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(ReferenceProperty.class, null, 83));
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(ReferenceVertex.class, null, 84));
-            add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(ReferencePath.class, null, 85));  // ***LAST ID**
+            add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(ReferencePath.class, null, 85));
+
+            add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(StarGraph.class, null, 86)); // ***LAST ID**
 
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(Edge.class, kryo -> new GraphSerializer.EdgeSerializer(), 65));
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(Vertex.class, kryo -> new GraphSerializer.VertexSerializer(), 66));
@@ -226,9 +229,10 @@ public final class GryoMapper implements Mapper<Kryo> {
          * Starts numbering classes for Gryo serialization at 65536 to leave room for future usage by TinkerPop.
          */
         private final AtomicInteger currentSerializationId = new AtomicInteger(65536);
-        
-        private Builder() {}
-        
+
+        private Builder() {
+        }
+
         @Override
         public Builder addRegistry(final IoRegistry registry) {
             this.registry = registry;
@@ -237,7 +241,7 @@ public final class GryoMapper implements Mapper<Kryo> {
 
         /**
          * Register custom classes to serializes with gryo using default serialization.
-         */        
+         */
         public Builder addCustom(final Class... custom) {
             if (custom != null && custom.length > 0)
                 serializationList.addAll(Arrays.asList(custom).stream()
@@ -256,7 +260,7 @@ public final class GryoMapper implements Mapper<Kryo> {
 
         /**
          * Register a custom class to serialize with a custom serializer as returned from a {@link Function}.
-         */        
+         */
         public Builder addCustom(final Class clazz, final Function<Kryo, Serializer> serializer) {
             serializationList.add(Triplet.with(clazz, serializer, currentSerializationId.getAndIncrement()));
             return this;

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/24ffbddf/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
index ddce092..1e47e6d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
@@ -24,12 +24,12 @@ package org.apache.tinkerpop.gremlin.structure.util.star;
 import org.apache.commons.configuration.BaseConfiguration;
 import org.apache.commons.configuration.Configuration;
 import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
-import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Direction;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Element;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Transaction;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
@@ -38,6 +38,7 @@ import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
 import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -50,7 +51,7 @@ import java.util.stream.Stream;
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
  */
-public final class StarGraph implements Graph {
+public final class StarGraph implements Graph, Serializable {
 
     private static final Configuration STAR_GRAPH_CONFIGURATION = new BaseConfiguration();
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/24ffbddf/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java
index 40057aa..aa66d1a 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/VertexWritable.java
@@ -20,9 +20,7 @@ package org.apache.tinkerpop.gremlin.hadoop.structure.io;
 
 import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.io.WritableUtils;
-import org.apache.tinkerpop.gremlin.structure.Direction;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.util.Attachable;
 import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
 import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
 
@@ -65,10 +63,7 @@ public final class VertexWritable implements Writable, Serializable {
             this.vertex = HadoopPools.GRYO_POOL.doWithReader(gryoReader -> {
                 try {
                     final ByteArrayInputStream inputStream = new ByteArrayInputStream(WritableUtils.readCompressedByteArray(input));
-                    final StarGraph starGraph = StarGraph.open();
-                    return gryoReader.readVertex(inputStream, Direction.BOTH,
-                            detachedVertex -> detachedVertex.attach(starGraph, Attachable.Method.CREATE),
-                            detachedEdge -> detachedEdge.attach(starGraph, Attachable.Method.CREATE));
+                    return ((StarGraph) gryoReader.readObject(inputStream)).getStarVertex(); // read the star graph
                 } catch (final IOException e) {
                     throw new IllegalStateException(e.getMessage(), e);
                 }
@@ -87,7 +82,7 @@ public final class VertexWritable implements Writable, Serializable {
             HadoopPools.GRYO_POOL.doWithWriter(gryoWriter -> {
                 try {
                     final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-                    gryoWriter.writeVertex(outputStream, this.vertex, Direction.BOTH);
+                    gryoWriter.writeObject(outputStream, this.vertex.graph()); // write the star graph
                     WritableUtils.writeCompressedByteArray(output, outputStream.toByteArray());
                 } catch (final IOException e) {
                     throw new IllegalStateException(e.getMessage(), e);