tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [20/20] tinkerpop git commit: Merge branch 'tp32'
Date Wed, 15 Mar 2017 16:36:49 GMT
Merge branch 'tp32'

Conflicts:
	docs/src/reference/gremlin-applications.asciidoc
	gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEngines.java
	gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
	gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java


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

Branch: refs/heads/master
Commit: ef10d8f2b8488b6a8fbb66f4ea10cb5efabb5b97
Parents: b5bd36b d7c2a22
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Wed Mar 15 12:02:45 2017 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Wed Mar 15 12:02:45 2017 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |   7 +
 .../src/reference/gremlin-applications.asciidoc |   6 +
 .../upgrade/release-3.2.x-incubating.asciidoc   |  10 +
 gremlin-groovy/pom.xml                          |   5 +
 .../jsr223/CompilationOptionsCustomizer.java    |  39 ++++
 .../jsr223/GremlinGroovyScriptEngine.java       | 205 +++++++++++++++++--
 .../jsr223/GroovyCompilerGremlinPlugin.java     |  13 ++
 ...roovyScriptEngineCompilationOptionsTest.java |  56 +++++
 .../jsr223/GremlinGroovyScriptEngineTest.java   |  70 ++++++-
 .../jsr223/GroovyCompilerGremlinPluginTest.java |  25 ++-
 gremlin-server/pom.xml                          |   5 -
 .../gremlin/server/op/session/Session.java      |  18 ++
 .../gremlin/server/util/MetricManager.java      |  80 +++++++-
 .../server/util/ServerGremlinExecutor.java      |   7 +
 14 files changed, 509 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/CHANGELOG.asciidoc
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/docs/src/reference/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --cc docs/src/reference/gremlin-applications.asciidoc
index 6e1ea57,3a2c446..9932442
--- a/docs/src/reference/gremlin-applications.asciidoc
+++ b/docs/src/reference/gremlin-applications.asciidoc
@@@ -1453,17 -1335,14 +1453,18 @@@ The `GroovyCompilerGremlinPlugin` has 
  [width="100%",cols="3,10a",options="header"]
  |=========================================================
  |Customizer |Description
 -|`CompileStaticCustomizerProvider` |Applies `CompileStatic` annotations to incoming scripts
thus removing dynamic dispatch. More information about static compilation can be found in
the link:http://docs.groovy-lang.org/latest/html/documentation/#_static_compilation[Groovy
Documentation].  It is possible to configure this `CustomizerProvider` by specifying a comma
separated list of link:http://docs.groovy-lang.org/latest/html/documentation/#Typecheckingextensions-Workingwithextensions[type
checking extensions] that can have the effect of securing calls to various methods.
 -|`CompilationOptionsCustomizerProvider` |The amount of time a script is allowed to compile
before a warning message is sent to the logs.
 -|`ConfigurationCustomizerProvider` |Allows configuration of the Groovy `CompilerConfiguration`
object by taking a `Map` of key/value pairs where the "key" is a property to set on the `CompilerConfiguration`.
 -|`ThreadInterruptCustomizerProvider` |Injects checks for thread interruption, thus allowing
the thread to potentially respect calls to `Thread.interrupt()`
 -|`TimedInterruptCustomizerProvider` |Injects checks into loops to interrupt them if they
exceed the configured timeout in milliseconds.
 -|`TypeCheckedCustomizerProvider` |Similar to the above mentioned, `CompileStaticCustomizerProvider`,
the `TypeCheckedCustomizerProvider` injects `TypeChecked` annotations to incoming scripts.
 More information on the nature of this annotation can be found in the link:http://docs.groovy-lang.org/latest/html/documentation/#_the_code_typechecked_code_annotation[Groovy
Documentation].  It too takes a comma separated list of link:http://docs.groovy-lang.org/latest/html/documentation/#Typecheckingextensions-Workingwithextensions[type
checking extensions].
 +|`compilation` |Allows for three configurations: `COMPILE_STATIC`, `TYPE_CHECKED` or `NONE`
(default). When configured with `COMPILE_STATIC` or `TYPE_CHECKED` it applies `CompileStatic`
or `TypeChecked` annotations (respectively) to incoming scripts thus removing dynamic dispatch.
More information about static compilation can be found link:http://docs.groovy-lang.org/latest/html/documentation/#_static_compilation[here]
and additional information on `TypeChecked` usage can be found link:http://docs.groovy-lang.org/latest/html/documentation/#_the_code_typechecked_code_annotation[here].
 +|`compilerConfigurationOptions` |Allows configuration of the Groovy `CompilerConfiguration`
object by taking a `Map` of key/value pairs where the "key" is a property to set on the `CompilerConfiguration`.
 +|`enableThreadInterrupt` |Injects checks for thread interruption, thus allowing the thread
to potentially respect calls to `Thread.interrupt()`
++|`expectedCompilationTime` |The amount of time in milliseconds a script is allowed to compile
before a warning message is sent to the logs.
 +|`extensions` | This setting is for use when `compilation` is configured with `COMPILE_STATIC`
or `TYPE_CHECKED` and accepts a comma separated list of link:http://docs.groovy-lang.org/latest/html/documentation/#Typecheckingextensions-Workingwithextensions[type
checking extensions] that can have the effect of securing calls to various methods.
 +|`timedInterrupt` |Injects checks into loops to interrupt them if they exceed the configured
timeout in milliseconds.
  |=========================================================
  
 +NOTE: Consult the latest link:http://docs.groovy-lang.org/latest/html/documentation/#_typing[Groovy
Documentation]
 +for information on the differences. It is important to understand the impact that these
configuration will have on
 +submitted scripts before enabling this feature.
 +
  To provide some basic out-of-the-box protections against troublesome scripts, the following
configuration can be used:
  
  [source,yaml]
@@@ -1671,63 -1562,12 +1672,68 @@@ and standard deviation evaluation times
  * `op.traversal` - the number of `Traveral` executions, mean rate, 1, 5, and 15 minute rates,
minimum, maximum, median,
  mean, and standard deviation evaluation times, as well as the 75th, 95th, 98th, 99th and
99.9th percentile evaluation
  times.
+ * `engine-name.session.session-id.*` - metrics related to different `GremlinScriptEngine`
instances configured for
+ session-based requests where "engine-name" will be the actual name of the engine, such as
"gremlin-groovy" and
+ "session-id" will be the identifier for the session itself.
+ * `engine-name.sessionless.*` - metrics related to different `GremlinScriptEngine` instances
configured for sessionless
+ requests where "engine-name" will be the actual name of the engine, such as "gremlin-groovy".
  
 +As A Service
 +^^^^^^^^^^^^
 +
 +Gremlin server can be configured to run as a service.
 +
 +Init.d (SysV)
 ++++++++++++++
 +
 +Link `bin/gremlin-server.sh` to `init.d`
 +Be sure to set RUNAS to the service user in `bin/gremlin-server.conf`
 +
 +[source,bash]
 +----
 +# Install
 +ln -s /path/to/apache-tinkerpop-gremlin-server-x.y.z/bin/gremlin-server.sh /etc/init.d/gremlin-server
 +
 +# Systems with chkconfig/service. E.g. Fedora, Red Hat
 +chkconfig --add gremlin-server
 +
 +# Start
 +service gremlin-server start
 +
 +# Or call directly
 +/etc/init.d/gremlin-server restart
 +
 +----
 +
 +Systemd
 ++++++++
 +
 +To install, copy the service template below to /etc/systemd/system/gremlin.service
 +and update the paths `/path/to/apache-tinkerpop-gremlin-server` with the actual install
path of Gremlin Server.
 +
 +[source,bash]
 +----
 +[Unit]
 +Description=Apache TinkerPop Gremlin Server daemon
 +Documentation=http://tinkerpop.apache.org/
 +After=network.target
 +
 +[Service]
 +Type=forking
 +ExecStart=/path/to/apache-tinkerpop-gremlin-server/bin/gremlin-server.sh start
 +ExecStop=/path/to/apache-tinkerpop-gremlin-server/bin/gremlin-server.sh stop
 +PIDFile=/path/to/apache-tinkerpop-gremlin-server/run/gremlin.pid
 +
 +[Install]
 +WantedBy=multi-user.target
 +----
 +
 +
 +Enable the service with `systemctl enable gremlin-server`
 +
 +Start the service with `systemctl start gremlin-server`
 +
 +
  Best Practices
  ~~~~~~~~~~~~~~
  

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/docs/src/upgrade/release-3.2.x-incubating.asciidoc
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/gremlin-groovy/pom.xml
----------------------------------------------------------------------
diff --cc gremlin-groovy/pom.xml
index 75b21a5,474b458..fdf6caf
--- a/gremlin-groovy/pom.xml
+++ b/gremlin-groovy/pom.xml
@@@ -70,14 -70,13 +70,19 @@@ limitations under the License
              <artifactId>jbcrypt</artifactId>
              <version>0.4</version>
          </dependency>
+         <dependency>
+             <groupId>com.github.ben-manes.caffeine</groupId>
+             <artifactId>caffeine</artifactId>
+             <version>2.3.1</version>
+         </dependency>
          <!-- TEST -->
          <dependency>
 +            <groupId>org.apache.tinkerpop</groupId>
 +            <artifactId>tinkergraph-gremlin</artifactId>
 +            <version>${project.version}</version>
 +            <scope>test</scope>
 +        </dependency>
 +        <dependency>
              <groupId>org.slf4j</groupId>
              <artifactId>slf4j-log4j12</artifactId>
              <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
----------------------------------------------------------------------
diff --cc gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
index 0ac5582,4b27180..9d232d8
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
@@@ -18,6 -18,10 +18,9 @@@
   */
  package org.apache.tinkerpop.gremlin.groovy.jsr223;
  
+ import com.github.benmanes.caffeine.cache.CacheLoader;
+ import com.github.benmanes.caffeine.cache.Caffeine;
+ import com.github.benmanes.caffeine.cache.LoadingCache;
 -import groovy.grape.Grape;
  import groovy.lang.Binding;
  import groovy.lang.Closure;
  import groovy.lang.DelegatingMetaClass;
@@@ -80,8 -101,9 +89,9 @@@ import java.util.stream.Collectors
   * @see org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor
   */
  public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
 -        implements DependencyManager, AutoCloseable, GremlinScriptEngine {
 +        implements AutoCloseable, GremlinScriptEngine {
  
+     private static final Logger log = LoggerFactory.getLogger(GremlinGroovyScriptEngine.class);
      /**
       * An "internal" key for sandboxing the script engine - technically not for public use.
       */
@@@ -167,10 -233,15 +221,11 @@@
      private final ImportGroovyCustomizer importGroovyCustomizer;
      private final List<GroovyCustomizer> groovyCustomizers;
  
 -    private final Set<Artifact> artifactsToUse = new HashSet<>();
      private final boolean interpreterModeEnabled;
+     private final long expectedCompilationTime;
  
      /**
 -     * Creates a new instance using the {@link DefaultImportCustomizerProvider}.
 +     * Creates a new instance using no {@link Customizer}.
       */
      public GremlinGroovyScriptEngine() {
          this(new Customizer[0]);
@@@ -249,8 -483,11 +310,8 @@@
  
          // must clear the local cache here because the classloader has been reset.  therefore,
classes previously
          // referenced before that might not have evaluated might cleanly evaluate now.
-         classMap.clear();
+         classMap.invalidateAll();
          globalClosures.clear();
 -
 -        final Set<Artifact> toReuse = new HashSet<>(artifactsToUse);
 -        toReuse.forEach(this::use);
      }
  
      /**

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompilationOptionsTest.java
----------------------------------------------------------------------
diff --cc gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompilationOptionsTest.java
index 0000000,b87d0ac..b1ec3e5
mode 000000,100644..100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompilationOptionsTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompilationOptionsTest.java
@@@ -1,0 -1,80 +1,56 @@@
+ /*
+  * 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.groovy.jsr223;
+ 
 -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompilationOptionsCustomizerProvider;
+ import org.junit.Test;
+ 
+ import javax.script.Bindings;
+ import javax.script.SimpleBindings;
+ 
+ import static org.junit.Assert.assertEquals;
+ 
+ /**
+  * @author Stephen Mallette (http://stephen.genoprime.com)
+  */
+ public class GremlinGroovyScriptEngineCompilationOptionsTest {
 -    @Test
 -    public void shouldRegisterLongCompilationDeprecated() throws Exception {
 -        final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new CompilationOptionsCustomizerProvider(10));
 -
 -        final int numberOfParameters = 3000;
 -        final Bindings b = new SimpleBindings();
 -
 -        // generate a script that takes a long time to compile
 -        String script = "x = 0";
 -        for (int ix = 0; ix < numberOfParameters; ix++) {
 -            if (ix > 0 && ix % 100 == 0) {
 -                script = script + ";" + System.lineSeparator() + "x = x";
 -            }
 -            script = script + " + x" + ix;
 -            b.put("x" + ix, ix);
 -        }
 -
 -        assertEquals(0, engine.getClassCacheLongRunCompilationCount());
 -
 -        engine.eval(script, b);
 -
 -        assertEquals(1, engine.getClassCacheLongRunCompilationCount());
 -    }
+ 
+     @Test
+     public void shouldRegisterLongCompilation() throws Exception {
+         final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new CompilationOptionsCustomizer(10));
+ 
+         final int numberOfParameters = 3000;
+         final Bindings b = new SimpleBindings();
+ 
+         // generate a script that takes a long time to compile
+         String script = "x = 0";
+         for (int ix = 0; ix < numberOfParameters; ix++) {
+             if (ix > 0 && ix % 100 == 0) {
+                 script = script + ";" + System.lineSeparator() + "x = x";
+             }
+             script = script + " + x" + ix;
+             b.put("x" + ix, ix);
+         }
+ 
+         assertEquals(0, engine.getClassCacheLongRunCompilationCount());
+ 
+         engine.eval(script, b);
+ 
+         assertEquals(1, engine.getClassCacheLongRunCompilationCount());
+     }
+ }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/gremlin-server/pom.xml
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
----------------------------------------------------------------------
diff --cc gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
index 62a08cb,6961339..3a3c836
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
@@@ -18,7 -18,11 +18,10 @@@
   */
  package org.apache.tinkerpop.gremlin.server.op.session;
  
+ import com.codahale.metrics.Metric;
+ import com.codahale.metrics.MetricFilter;
  import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor;
 -import org.apache.tinkerpop.gremlin.groovy.engine.ScriptEngines;
+ import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
  import org.apache.tinkerpop.gremlin.server.Context;
  import org.apache.tinkerpop.gremlin.server.GraphManager;
  import org.apache.tinkerpop.gremlin.server.Settings;
@@@ -90,6 -98,15 +97,8 @@@ public class Session 
                  SessionOpProcessor.CONFIG_PER_GRAPH_CLOSE_TIMEOUT, SessionOpProcessor.DEFAULT_PER_GRAPH_CLOSE_TIMEOUT).toString());
  
          this.gremlinExecutor = initializeGremlinExecutor().create();
+ 
 -        settings.scriptEngines.keySet().forEach(engineName -> {
 -            try {
 -                gremlinExecutor.eval("1+1", engineName, Collections.emptyMap()).join();
 -                registerMetrics(engineName);
 -            } catch (Exception ex) {
 -                logger.warn(String.format("Could not initialize {} ScriptEngine as script
could not be evaluated - %s", engineName), ex);
 -            }
 -        });
++        settings.scriptEngines.keySet().forEach(this::registerMetrics);
      }
  
      public GremlinExecutor getGremlinExecutor() {
@@@ -235,4 -263,12 +248,9 @@@
  
          return gremlinExecutorBuilder;
      }
+ 
+     private void registerMetrics(final String engineName) {
 -        final ScriptEngines scriptEngines = gremlinExecutor.getScriptEngines();
 -        final GremlinScriptEngine engine = null == scriptEngines ?
 -                gremlinExecutor.getScriptEngineManager().getEngineByName(engineName) :
 -                scriptEngines.getEngineByName(engineName);
++        final GremlinScriptEngine engine = gremlinExecutor.getScriptEngineManager().getEngineByName(engineName);
+         MetricManager.INSTANCE.registerGremlinScriptEngineMetrics(engine, engineName, "session",
session, "class-cache");
+     }
  }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ef10d8f2/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
----------------------------------------------------------------------
diff --cc gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
index 116d627,e3c0cae..6bf8095
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
@@@ -18,7 -18,11 +18,8 @@@
   */
  package org.apache.tinkerpop.gremlin.server.util;
  
 -import com.codahale.metrics.Gauge;
  import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor;
 -import org.apache.tinkerpop.gremlin.groovy.engine.ScriptEngines;
 -import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
+ import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
  import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
  import org.apache.tinkerpop.gremlin.server.Channelizer;
  import org.apache.tinkerpop.gremlin.server.GraphManager;
@@@ -171,6 -186,14 +173,11 @@@ public class ServerGremlinExecutor<T ex
                  .collect(Collectors.toList());
      }
  
+     private void registerMetrics(final String engineName) {
 -        final ScriptEngines scriptEngines = gremlinExecutor.getScriptEngines();
 -        final GremlinScriptEngine engine = null == scriptEngines ?
 -                gremlinExecutor.getScriptEngineManager().getEngineByName(engineName) :
 -                scriptEngines.getEngineByName(engineName);
++        final GremlinScriptEngine engine = gremlinExecutor.getScriptEngineManager().getEngineByName(engineName);
+         MetricManager.INSTANCE.registerGremlinScriptEngineMetrics(engine, engineName, "sessionless",
"class-cache");
+     }
+ 
      public void addHostOption(final String key, final Object value) {
          hostOptions.put(key, value);
      }


Mime
View raw message