从gremlin服务器获取正确数据的问题

时间:2019-09-24 17:35:42

标签: gremlin tinkerpop tinkerpop3 gremlin-server graphson

我遇到了一系列荒谬的问题,这些问题令我发疯。我想完成几件事:

  1. 我正在尝试设置我的gremlin服务器以“加载” json格式的某个graphson文件,并在那里遇到一些非常奇怪的问题,我将详细介绍

  2. 我正在尝试运行一个简单的ajax调用来查询该数据,但是-我不仅无法获取所需的数据(由于gremlin拒绝加载它可能很有意义),我似乎得到一些我不知道的数据。

  3. 我正在尝试找出如何在终端上测试gremlin服务器的方法,但是我无法运行查询,因为./gremlin-server.sh status返回了Server not running,即使它已100%运行并且我的ajax呼叫可以看到。

克里姆林宫未加载文件

要启动,我正在运行Gremlin v.3.4.3,可以在here中找到它。我用来运行gremlin的命令是

bin/gremlin-server.sh data/gremlin-server-rest-modern.yaml

Gremlin Server下载随附了te yaml文件,其内容为:

#...license stuff...

host: localhost
port: 8182
scriptEvaluationTimeout: 30000
channelizer: org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer
graphs: {
  graph: conf/tinkergraph-empty.properties}
scriptEngines: {
  gremlin-groovy: {
    plugins: { org.apache.tinkerpop.gremlin.server.jsr223.GremlinServerGremlinPlugin: {},
               org.apache.tinkerpop.gremlin.tinkergraph.jsr223.TinkerGraphGremlinPlugin: {},
               org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: {classImports: [java.lang.Math], methodImports: [java.lang.Math#*]},
               org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: {files: [scripts/generate-modern.groovy]}}}}
serializers:
  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV3d0] }}         # application/json
metrics: {
  slf4jReporter: {enabled: true, interval: 180000}}
strictTransactionManagement: false
maxInitialLineLength: 4096
maxHeaderSize: 8192
maxChunkSize: 8192
maxContentLength: 65536
maxAccumulationBufferComponents: 1024
resultIterationBatchSize: 64

现在,据我所知,需要注意的重要事项是导致graph文件的组件properties。我正在加载的属性文件是tinkergraph-empty.properties,其内容为:

gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
gremlin.tinkergraph.vertexIdManager=LONG

文件名tinkergraph-empty暗示了一些重要的内容:gremlin服务器将不会加载图形。很酷-当我启动gremlin服务器时,它会正常加载并产生预期的结果:

[INFO] GremlinServer - Configuring Gremlin Server from ./conf/gremlin-server-rest-modern.yaml
[INFO] MetricManager - Configured Metrics Slf4jReporter configured with interval=180000ms and loggerName=org.apache.tinkerpop.gremlin.server.Settings$Slf4jReporterMetrics
[INFO] DefaultGraphManager - Graph [graph] was successfully configured via [conf/tinkergraph-empty.properties].
[INFO] ServerGremlinExecutor - Initialized Gremlin thread pool.  Threads in pool named with pattern gremlin-*
[INFO] ServerGremlinExecutor - Initialized GremlinExecutor and preparing GremlinScriptEngines instances.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/Users/<user>/apache-tinkerpop-gremlin-server-3.4.3/lib/groovy-2.5.7-indy.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] ServerGremlinExecutor - Initialized gremlin-groovy GremlinScriptEngine and registered metrics
[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
[INFO] OpLoader - Adding the standard OpProcessor.
[INFO] OpLoader - Adding the session OpProcessor.
[INFO] OpLoader - Adding the traversal OpProcessor.
[INFO] TraversalOpProcessor - Initialized cache for TraversalOpProcessor with size 1000 and expiration time of 600000 ms
[INFO] GremlinServer - Executing start up LifeCycleHook
[INFO] Logger$info - Loading 'modern' graph data.
[INFO] AbstractChannelizer - Configured application/vnd.gremlin-v3.0+json with org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0
[INFO] AbstractChannelizer - Configured application/json with org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0
[INFO] GremlinServer$1 - Gremlin Server configured with worker thread pool of 1, gremlin pool of 8 and boss thread pool of 1.
[INFO] GremlinServer$1 - Channel started at port 8182.

这一行特别有希望:[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]

它“加载”的图(我假设它必须初始化图)具有零个顶点和边。

当我运行我的ajax调用时(如我所承诺的那样),我将在稍后进入,成功地将POST POST到服务器。它已经启动并正在运行。一切都很好。

但是...

当我更改tinkerpop-empty.properties文件夹以加载图形时,情况变得很奇怪。我将这样更改它:

gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
gremlin.tinkergraph.vertexIdManager=LONG
gremlin.tinkergraph.graphLocation=data/tinkerpop-crew.json
gremlin.tinkergraph.graphFormat=graphson

我现在加载了一个名为tinkerpop-crew.json的数据文件夹,并添加了一个graphFormat: graphson。这应该是正确的。可以找到here的json文件,并且属性文件遵循此file的格式。

现在,当我运行此命令时,我得到了截然不同的结果:

[INFO] GremlinServer - Configuring Gremlin Server from ./conf/gremlin-server-rest-modern.yaml
[INFO] MetricManager - Configured Metrics Slf4jReporter configured with interval=180000ms and loggerName=org.apache.tinkerpop.gremlin.server.Settings$Slf4jReporterMetrics
[INFO] DefaultGraphManager - Graph [graph] was successfully configured via [conf/tinkergraph-empty.properties].
[INFO] ServerGremlinExecutor - Initialized Gremlin thread pool.  Threads in pool named with pattern gremlin-*
[INFO] ServerGremlinExecutor - Initialized GremlinExecutor and preparing GremlinScriptEngines instances.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/Users/xbbn1xn/apache-tinkerpop-gremlin-server-3.4.3/lib/groovy-2.5.7-indy.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] ServerGremlinExecutor - Initialized gremlin-groovy GremlinScriptEngine and registered metrics
[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:6 edges:14], standard]
[INFO] OpLoader - Adding the standard OpProcessor.
[INFO] OpLoader - Adding the session OpProcessor.
[INFO] OpLoader - Adding the traversal OpProcessor.
[INFO] TraversalOpProcessor - Initialized cache for TraversalOpProcessor with size 1000 and expiration time of 600000 ms
[INFO] GremlinServer - Executing start up LifeCycleHook
[INFO] Logger$info - Loading 'modern' graph data.
[ERROR] GremlinServer - Gremlin Server Error
java.lang.IllegalArgumentException: Vertex with id already exists: 1
    at org.apache.tinkerpop.gremlin.structure.Graph$Exceptions.vertexWithIdAlreadyExists(Graph.java:1196)
    at org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph.addVertex(TinkerGraph.java:167)
    at org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory.generateModern(TinkerFactory.java:90)
    at org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory$generateModern.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:127)
    at Script1$_run_closure1.doCall(Script1.groovy:28)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:263)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041)
    at groovy.lang.Closure.call(Closure.java:405)
    at org.codehaus.groovy.runtime.ConvertedMap.invokeCustom(ConvertedMap.java:54)
    at org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:122)
    at com.sun.proxy.$Proxy15.onStartUp(Unknown Source)
    at org.apache.tinkerpop.gremlin.server.GremlinServer.lambda$start$1(GremlinServer.java:154)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
    at org.apache.tinkerpop.gremlin.server.GremlinServer.start(GremlinServer.java:151)
    at org.apache.tinkerpop.gremlin.server.GremlinServer.main(GremlinServer.java:346)
[ERROR] GremlinServer - Gremlin Server was unable to start and will now begin shutdown: Vertex with id already exists: 1
[INFO] GremlinServer - Shutting down OpProcessor[]
[INFO] GremlinServer - Shutting down OpProcessor[session]
[INFO] GremlinServer - Shutting down OpProcessor[traversal]
[INFO] GremlinServer - Shutting down thread pools.
[INFO] GremlinServer - Executing shutdown LifeCycleHook
[INFO] GremlinServer - Closed Graph instance [graph]
[INFO] GremlinServer - Gremlin Server - shutdown complete

嗯?顶点已经存在?这不可能。我什至从未运行这个文件,为什么它什至没有任何记忆呢?就gremlin而言,我什至从未加载过图表。也许它会启动图,却忘记将其从内存中删除,是吧?

好吧,让我们创建自己的文件,并仅初始化一个Vertex和一些奇怪的质数且没有边的初始化。我们称之为tinkerpop-crew2.json

{"id":{"@type":"g:Int64","@value":47284629},"label":"person"}

可能不是素数。随你。好的,太好了,那行得通!

[INFO] GremlinServer - Configuring Gremlin Server from ./conf/gremlin-server-rest-modern.yaml
[INFO] MetricManager - Configured Metrics Slf4jReporter configured with interval=180000ms and loggerName=org.apache.tinkerpop.gremlin.server.Settings$Slf4jReporterMetrics
[INFO] DefaultGraphManager - Graph [graph] was successfully configured via [conf/tinkergraph-empty.properties].
[INFO] ServerGremlinExecutor - Initialized Gremlin thread pool.  Threads in pool named with pattern gremlin-*
[INFO] ServerGremlinExecutor - Initialized GremlinExecutor and preparing GremlinScriptEngines instances.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/Users/xbbn1xn/apache-tinkerpop-gremlin-server-3.4.3/lib/groovy-2.5.7-indy.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] ServerGremlinExecutor - Initialized gremlin-groovy GremlinScriptEngine and registered metrics
[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:1 edges:0], standard]
[INFO] OpLoader - Adding the standard OpProcessor.
[INFO] OpLoader - Adding the session OpProcessor.
[INFO] OpLoader - Adding the traversal OpProcessor.
[INFO] TraversalOpProcessor - Initialized cache for TraversalOpProcessor with size 1000 and expiration time of 600000 ms
[INFO] GremlinServer - Executing start up LifeCycleHook
[INFO] Logger$info - Loading 'modern' graph data.
[INFO] AbstractChannelizer - Configured application/vnd.gremlin-v3.0+json with org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0
[INFO] AbstractChannelizer - Configured application/json with org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0
[INFO] GremlinServer$1 - Gremlin Server configured with worker thread pool of 1, gremlin pool of 8 and boss thread pool of 1.
[INFO] GremlinServer$1 - Channel started at port 8182.

在这里注意:[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:1 edges:0], standard]。一个顶点。

当服务器配置为再次使用此文件时会发生什么?

[INFO] GremlinServer - Configuring Gremlin Server from ./conf/gremlin-server-rest-modern.yaml
[INFO] MetricManager - Configured Metrics Slf4jReporter configured with interval=180000ms and loggerName=org.apache.tinkerpop.gremlin.server.Settings$Slf4jReporterMetrics
[INFO] DefaultGraphManager - Graph [graph] was successfully configured via [conf/tinkergraph-empty.properties].
[INFO] ServerGremlinExecutor - Initialized Gremlin thread pool.  Threads in pool named with pattern gremlin-*
[INFO] ServerGremlinExecutor - Initialized GremlinExecutor and preparing GremlinScriptEngines instances.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/Users/xbbn1xn/apache-tinkerpop-gremlin-server-3.4.3/lib/groovy-2.5.7-indy.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] ServerGremlinExecutor - Initialized gremlin-groovy GremlinScriptEngine and registered metrics
[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:7 edges:6], standard]
[INFO] OpLoader - Adding the standard OpProcessor.
[INFO] OpLoader - Adding the session OpProcessor.
[INFO] OpLoader - Adding the traversal OpProcessor.
[INFO] TraversalOpProcessor - Initialized cache for TraversalOpProcessor with size 1000 and expiration time of 600000 ms
[INFO] GremlinServer - Executing start up LifeCycleHook
[INFO] Logger$info - Loading 'modern' graph data.
[ERROR] GremlinServer - Gremlin Server Error
java.lang.IllegalArgumentException: Vertex with id already exists: 1
    at org.apache.tinkerpop.gremlin.structure.Graph$Exceptions.vertexWithIdAlreadyExists(Graph.java:1196)
    at org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph.addVertex(TinkerGraph.java:167)
    at org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory.generateModern(TinkerFactory.java:90)
    at org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory$generateModern.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:127)
    at Script1$_run_closure1.doCall(Script1.groovy:28)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:263)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041)
    at groovy.lang.Closure.call(Closure.java:405)
    at org.codehaus.groovy.runtime.ConvertedMap.invokeCustom(ConvertedMap.java:54)
    at org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:122)
    at com.sun.proxy.$Proxy15.onStartUp(Unknown Source)
    at org.apache.tinkerpop.gremlin.server.GremlinServer.lambda$start$1(GremlinServer.java:154)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
    at org.apache.tinkerpop.gremlin.server.GremlinServer.start(GremlinServer.java:151)
    at org.apache.tinkerpop.gremlin.server.GremlinServer.main(GremlinServer.java:346)
[ERROR] GremlinServer - Gremlin Server was unable to start and will now begin shutdown: Vertex with id already exists: 1
[INFO] GremlinServer - Shutting down OpProcessor[]
[INFO] GremlinServer - Shutting down OpProcessor[session]
[INFO] GremlinServer - Shutting down OpProcessor[traversal]
[INFO] GremlinServer - Shutting down thread pools.
[INFO] GremlinServer - Executing shutdown LifeCycleHook
[INFO] GremlinServer - Closed Graph instance [graph]
[INFO] GremlinServer - Gremlin Server - shutdown complete

与以前相同的错误。这到底是怎么回事?还有两件事引起我的注意:

  1. ERROR] GremlinServer - Gremlin Server Error java.lang.IllegalArgumentException: Vertex with id already exists: 1。是说仅存在一个顶点,还是存在ID为“ 1”的顶点?因为我的所有顶点的ID都不为1。也就是说,直到...

  2. 您会注意到这甚至没有加载我的文件! [INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:7 edges:6], standard]。我的文件没有7个顶点和6个边。它具有1个顶点和0个边。实际上,这看起来似乎令人怀疑,它正在加载原始的tinkerpop-crew.json文件或类似文件,即使当我们最初加载该文件时,INFO消息也显示为:[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:6 edges:14], standard]

好的,所以我不知道这是怎么回事。

运行我的ajax查询以查看发生了什么

我有一个非常非常简单的查询,可以使用AJAX调用来运行和发布:

$.ajax({
            type: "POST",
            accept: "application/json",
            url: url // http://localhost:8182,
            timeout: timeout // I have it set to 3500,
            data: JSON.stringify({"gremlin" : q}),
            success: function(data, textStatus, jqXHR){
                            var retrvData = data.result.data;
                            console.log(retrvData)
}

好,所以有几件重要的事情。 q变量是我发送到Gremlin服务器以返回一些数据的查询,它看起来像这样:

q = 'nodes = g.V().limit(15).toList();edges = g.V(nodes).aggregate('node').outE().as('edge').inV().where(within('node')).select('edge').toList();[nodes,edges]'

此查询实质上应返回节点和边的列表。现在,我想讲三种情况:

tinkerpop-empty.properties(实际上为空):

第一种情况是使用未更改的tinkerpop-empty.properties文件。记住,当我加载它时,我得到的输出是:

[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]

这意味着修补程序中应该没有任何信息。我应该收到一个空名单。但是,当我拨打电话时,我得到了:

value: Array(2)
0: Array(7)
0: {id: 1, label: "person", type: "vertex"}
1: {id: 2, label: "person", type: "vertex"}
2: {id: 3, label: "software", type: "vertex"}
3: {id: 47284629, label: "person", type: "vertex"}
4: {id: 4, label: "person", type: "vertex"}
5: {id: 5, label: "software", type: "vertex"}
6: {id: 6, label: "person", type: "vertex"}
length: 7
__proto__: Array(0)
1: Array(6)
0: {id: 9, label: "created", inVLabel: "software", outVLabel: "person", inV: 3, …}
1: {id: 7, label: "knows", inVLabel: "person", outVLabel: "person", inV: 2, …}
2: {id: 8, label: "knows", inVLabel: "person", outVLabel: "person", inV: 4, …}
3: {id: 10, label: "created", inVLabel: "software", outVLabel: "person", inV: 5, …}
4: {id: 11, label: "created", inVLabel: "software", outVLabel: "person", inV: 3, …}
5: {id: 12, label: "created", inVLabel: "software", outVLabel: "person", inV: 3, …}
length: 6

这是开发人员控制台中的输出(来自console.log(retrvData))。有各种各样的数据。而且,节点的长度为7,边缘为6。听起来很熟悉吗?为什么gremlin加载此数据?为什么将它发送到我的Ajax查询?

tinkergraph-empty.properties(已修改为使用tinkerpop-crew.json)

好的,随便。让我们运行下一个properties文件。记住,我们现在使用tinkerpop-crew.json并将graphFormat设置为graphson。

我遇到的错误与以前相同,当然是java.lang.IllegalArgumentException: Vertex with id already exists: 1。我的服务器也关闭了:

[ERROR] GremlinServer - Gremlin Server was unable to start and will now begin shutdown: Vertex with id already exists: 1
[INFO] GremlinServer - Shutting down OpProcessor[]
[INFO] GremlinServer - Shutting down OpProcessor[session]
[INFO] GremlinServer - Shutting down OpProcessor[traversal]
[INFO] GremlinServer - Shutting down thread pools.
[INFO] GremlinServer - Executing shutdown LifeCycleHook
[INFO] GremlinServer - Closed Graph instance [graph]
[INFO] GremlinServer - Gremlin Server - shutdown complete

我们去查询我的AJAX,看看会得到什么。

什么都没有。我的gremlin服务器崩溃了。由于INFO日志显示A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:6 edges:14], standard],因此似乎正在加载正确的文件。我还没有证实这是正确的……不是那么容易。

tinkerpop-empty.properties加载tinkerpop-crew2.json

我们第一次运行tinkerpop-crew2.json时,一切进展顺利。我们将ID更改为一些奇怪的数字,并且没有引发异常。此外,该图似乎加载了正确的内容。现在让我们再次运行它,并将ID更改为4724729456382

好吧,哇,我正在输入,请看一下我刚刚发现的内容:

{"id":{"@type":"g:Int64","@value":1},"label":"person","outE":{"created":[{"id":{"@type":"g:Int32","@value":9},"inV":{"@type":"g:Int64","@value":3},"properties":{"weight":{"@type":"g:Double","@value":0.4}}}],"knows":[{"id":{"@type":"g:Int32","@value":7},"inV":{"@type":"g:Int64","@value":2},"properties":{"weight":{"@type":"g:Double","@value":0.5}}},{"id":{"@type":"g:Int32","@value":8},"inV":{"@type":"g:Int64","@value":4},"properties":{"weight":{"@type":"g:Double","@value":1.0}}}]},"properties":{"name":[{"id":{"@type":"g:Int64","@value":0},"value":"marko"}],"age":[{"id":{"@type":"g:Int64","@value":2},"value":{"@type":"g:Int32","@value":29}}]}}
{"id":{"@type":"g:Int64","@value":2},"label":"person","inE":{"knows":[{"id":{"@type":"g:Int32","@value":7},"outV":{"@type":"g:Int64","@value":1},"properties":{"weight":{"@type":"g:Double","@value":0.5}}}]},"properties":{"name":[{"id":{"@type":"g:Int64","@value":3},"value":"vadas"}],"age":[{"id":{"@type":"g:Int64","@value":4},"value":{"@type":"g:Int32","@value":27}}]}}
{"id":{"@type":"g:Int64","@value":3},"label":"software","inE":{"created":[{"id":{"@type":"g:Int32","@value":9},"outV":{"@type":"g:Int64","@value":1},"properties":{"weight":{"@type":"g:Double","@value":0.4}}},{"id":{"@type":"g:Int32","@value":11},"outV":{"@type":"g:Int64","@value":4},"properties":{"weight":{"@type":"g:Double","@value":0.4}}},{"id":{"@type":"g:Int32","@value":12},"outV":{"@type":"g:Int64","@value":6},"properties":{"weight":{"@type":"g:Double","@value":0.2}}}]},"properties":{"name":[{"id":{"@type":"g:Int64","@value":5},"value":"lop"}],"lang":[{"id":{"@type":"g:Int64","@value":6},"value":"java"}]}}
{"id":{"@type":"g:Int64","@value":4},"label":"person","inE":{"knows":[{"id":{"@type":"g:Int32","@value":8},"outV":{"@type":"g:Int64","@value":1},"properties":{"weight":{"@type":"g:Double","@value":1.0}}}]},"outE":{"created":[{"id":{"@type":"g:Int32","@value":10},"inV":{"@type":"g:Int64","@value":5},"properties":{"weight":{"@type":"g:Double","@value":1.0}}},{"id":{"@type":"g:Int32","@value":11},"inV":{"@type":"g:Int64","@value":3},"properties":{"weight":{"@type":"g:Double","@value":0.4}}}]},"properties":{"name":[{"id":{"@type":"g:Int64","@value":7},"value":"josh"}],"age":[{"id":{"@type":"g:Int64","@value":8},"value":{"@type":"g:Int32","@value":32}}]}}
{"id":{"@type":"g:Int64","@value":5},"label":"software","inE":{"created":[{"id":{"@type":"g:Int32","@value":10},"outV":{"@type":"g:Int64","@value":4},"properties":{"weight":{"@type":"g:Double","@value":1.0}}}]},"properties":{"name":[{"id":{"@type":"g:Int64","@value":9},"value":"ripple"}],"lang":[{"id":{"@type":"g:Int64","@value":10},"value":"java"}]}}
{"id":{"@type":"g:Int64","@value":6},"label":"person","outE":{"created":[{"id":{"@type":"g:Int32","@value":12},"inV":{"@type":"g:Int64","@value":3},"properties":{"weight":{"@type":"g:Double","@value":0.2}}}]},"properties":{"name":[{"id":{"@type":"g:Int64","@value":11},"value":"peter"}],"age":[{"id":{"@type":"g:Int64","@value":12},"value":{"@type":"g:Int32","@value":35}}]}}
{"id":{"@type":"g:Int64","@value":47284629},"label":"person"}

现在这是我的tinkerpop-crew2.json的内容!这里发生了什么?为什么gremlin服务器将信息转储到该文件?如果您看到最后一行,它具有文件的原始内容:

{"id":{"@type":"g:Int64","@value":47284629},"label":"person"}

好吧,@ tinkerpop,到底是什么?

我想这现在为什么为什么当我第二次运行文件时,它再次引发该错误,并说ID为1的顶点已经存在!

我很高兴地离题!让我们删除该文件的原始部分,然后使用以下命令运行它:

{"id":{"@type":"g:Int64","@value":47284629},"label":"person"}

好的,我可以使用正确的INFO:[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:1 edges:0], standard]

现在,让我们运行该AJAX调用...

啊!同样的东西!

value: Array(2)
0: Array(7)
0: {id: 1, label: "person", type: "vertex"}
1: {id: 2, label: "person", type: "vertex"}
2: {id: 3, label: "software", type: "vertex"}
3: {id: 47284629, label: "person", type: "vertex"}
4: {id: 4, label: "person", type: "vertex"}
5: {id: 5, label: "software", type: "vertex"}
6: {id: 6, label: "person", type: "vertex"}
length: 7
__proto__: Array(0)
1: Array(6)
0: {id: 9, label: "created", inVLabel: "software", outVLabel: "person", inV: 3, …}
1: {id: 7, label: "knows", inVLabel: "person", outVLabel: "person", inV: 2, …}
2: {id: 8, label: "knows", inVLabel: "person", outVLabel: "person", inV: 4, …}
3: {id: 10, label: "created", inVLabel: "software", outVLabel: "person", inV: 5, …}
4: {id: 11, label: "created", inVLabel: "software", outVLabel: "person", inV: 3, …}
5: {id: 12, label: "created", inVLabel: "software", outVLabel: "person", inV: 3, …}
length: 6

请注意,节点列表的长度为7,边缘的长度为6!假设它正在加载某些内容,例如附加我的文件,则它应该是节点长度8和边长7!这是怎么回事?

接受的答案

解决方案是进入scripts/generate-modern.groovy并注释掉以下几行:

globals << [hook : [
  onStartUp: { ctx ->
    ctx.logger.info("Loading 'modern' graph data.")
      org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory.generateModern(graph)
  }
] as LifeCycleHook]

1 个答案:

答案 0 :(得分:2)

我认为这里的情况开始对您不利:

  

当我更改tinkerpop-empty.properties文件夹以加载图形时,情况变得很奇怪。我将这样更改它:

     

gremlin.graph = org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph   gremlin.tinkergraph.vertexIdManager =长   gremlin.tinkergraph.graphLocation = data / tinkerpop-crew.json   gremlin.tinkergraph.graphFormat = graphson

出现错误是因为您缺少Gremlin Server初始化脚本正在运行的事实-yaml中的以下行:

https://github.com/apache/tinkerpop/blob/3.4.3/gremlin-server/conf/gremlin-server-rest-modern.yaml

因此,这试图将“现代”图加载到您要指定为“乘员”图的图中(或者相反,我不记得先加载哪个图,但我想我已经没错)。解决方案是:

  1. 注释掉在scripts/generate-modern.groovy中加载“现代”图的行,并使属性文件保持原样或
  2. 更改scripts/generate-modern.groovy初始化脚本以仅加载“ crew”数据,并保持属性文件不变以具有空图。

您有一长串看起来很奇怪的其他赔率/赔率,但我想知道其中有多少是由于缺少init文件以及它对您“背后”的影响。这些知识是否有助于解决您的所有问题?如果不是这样,请告诉我还有什么不对劲,我可以设法帮助解决它。

相关问题