从 gremlin 服务器获取正确数据的问题
Issues getting correct data from gremlin server
我有一系列荒谬的问题让我抓狂。我正在努力完成几件事:
我正在尝试将我的 gremlin 服务器设置为 "load" 某个 json
格式的 json
文件,并在那里遇到非常奇怪的问题我再详细说。
我正在尝试 运行 一个简单的 ajax 调用来查询该数据,但是 - 我不仅无法获得我想要的数据(这可能会使因为 gremlin 拒绝加载它),我似乎得到了一些我不知道它来自哪里的数据。
我想知道如何在我的终端上测试 gremlin 服务器,但我无法 运行 查询,因为 ./gremlin-server.sh status
returns Server not running
即使它是 100% 运行ning 并且我的 ajax 调用可以看到。
Gremlin 未加载文件
要启动,我是 运行ning Gremlin v.3.4.3,可以找到 here。我用于 运行 gremlin 的命令是
bin/gremlin-server.sh data/gremlin-server-rest-modern.yaml
Te yaml 文件随 Gremlin 服务器下载一起提供,其内容为:
#...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
现在,据我了解,要注意的重要事项是导致 properties
文件的组件 graph
。我正在加载的属性文件是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 (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
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 - Gremlin Server configured with worker thread pool of 1, gremlin pool of 8 and boss thread pool of 1.
[INFO] GremlinServer - Channel started at port 8182.
这条线,具体来说,是有前途的:[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
它 "loads" 的图(我假设它必须初始化一个图)有零个顶点和边。
当我运行我的ajax调用时,正如我承诺的那样,我稍后会进入,我成功POST到服务器。已经 运行ning 了。一切顺利。
然而...
当我更改 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
。这应该是正确的。 json 文件可以找到 here, and the properties file follows the format of this 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 (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
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(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 而言,我什至从未加载过图表。也许它启动了一个图表,却忘记了从内存中删除它,对吧?
好吧,让我们创建自己的文件并只初始化一个顶点和一些奇怪的质数,没有边。我们称它为 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 (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
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 - Gremlin Server configured with worker thread pool of 1, gremlin pool of 8 and boss thread pool of 1.
[INFO] GremlinServer - 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 (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
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(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
和之前一样的错误。这到底是怎么回事?还有两件事引起了我的注意:
ERROR] GremlinServer - Gremlin Server Error
java.lang.IllegalArgumentException: Vertex with id already exists: 1
。是说只有一个顶点存在,还是存在ID为'1'的顶点?因为我的 none 个顶点的 ID 为 1。也就是说,直到...
您注意到这甚至没有加载我的文件! [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 查询以查看发生了什么
我有一个非常非常简单的查询,我 运行 和 post 使用 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 服务器以 [=214=] 一些数据的查询,它看起来像这样:
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]'
这个查询本质上应该是 return 一个节点和边的列表。现在,我想回顾一下三种情况:
tinkerpop-empty.properties(实际为空):
第一种情况是使用未更改的 tinkerpop-empty.properties 文件。请记住,当我加载它时,我得到的输出是:
[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
这意味着 tinkergraph 中应该没有任何信息。我应该收到一个空列表。但是,当我 运行 打电话时,我得到这个:
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]
。我还没有验证这是正确的......这不是那么容易。
小叮当-empty.properties 正在加载小叮当-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-server 将信息转储到该文件?如果您看到最后一行,它包含文件的原始内容:
{"id":{"@type":"g:Int64","@value":47284629},"label":"person"}
好吧,真的,@tinkerpop,这到底是怎么回事?
我想现在可以理解为什么当我第二次 运行 文件时,它再次抛出该错误并说 ID 为 1 的顶点已经存在!
好笑,我离题了!让我们删除该文件的非原始部分,只 运行 它与:
{"id":{"@type":"g:Int64","@value":47284629},"label":"person"}
好的,运行 很好,我应该期待正确的信息:[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!假设它正在加载一些东西,例如 and 附加我的文件,它应该是节点长度 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]
我认为这里开始出现问题:
When I change the tinkerpop-empty.properties folder to load a graph, things get really weird. I am going to change it as such:
gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
gremlin.tinkergraph.vertexIdManager=LONG
gremlin.tinkergraph.graphLocation=data/tinkerpop-crew.json
gremlin.tinkergraph.graphFormat=graphson
你得到你所做的错误是因为你错过了 Gremlin 服务器初始化脚本是 运行 - 你的 yaml 中的这一行:
https://github.com/apache/tinkerpop/blob/3.4.3/gremlin-server/conf/gremlin-server-rest-modern.yaml
所以这就是试图将 "modern" 图加载到你试图指定为 "crew" 图的图中(或者相反,我不记得加载了哪些首先,但我认为我做对了)。解决方案是:
- 在
scripts/generate-modern.groovy
中注释掉加载 "modern" 图表的行,并保持属性文件不变,或者
- 更改
scripts/generate-modern.groovy
初始化脚本以仅加载 "crew" 数据并保持属性文件不变以获得空图。
你有一长串其他 odds/ends 看起来很奇怪,但我想知道其中有多少是由于缺少 init 文件以及它对你做了什么 "behind your back"。这些知识是否有助于解决您所有的问题?如果没有,请告诉我还有什么问题,我可以尝试帮助解决它。
我有一系列荒谬的问题让我抓狂。我正在努力完成几件事:
我正在尝试将我的 gremlin 服务器设置为 "load" 某个
json
格式的json
文件,并在那里遇到非常奇怪的问题我再详细说。我正在尝试 运行 一个简单的 ajax 调用来查询该数据,但是 - 我不仅无法获得我想要的数据(这可能会使因为 gremlin 拒绝加载它),我似乎得到了一些我不知道它来自哪里的数据。
我想知道如何在我的终端上测试 gremlin 服务器,但我无法 运行 查询,因为
./gremlin-server.sh status
returnsServer not running
即使它是 100% 运行ning 并且我的 ajax 调用可以看到。
Gremlin 未加载文件
要启动,我是 运行ning Gremlin v.3.4.3,可以找到 here。我用于 运行 gremlin 的命令是
bin/gremlin-server.sh data/gremlin-server-rest-modern.yaml
Te yaml 文件随 Gremlin 服务器下载一起提供,其内容为:
#...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
现在,据我了解,要注意的重要事项是导致 properties
文件的组件 graph
。我正在加载的属性文件是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 (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
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 - Gremlin Server configured with worker thread pool of 1, gremlin pool of 8 and boss thread pool of 1.
[INFO] GremlinServer - Channel started at port 8182.
这条线,具体来说,是有前途的:[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
它 "loads" 的图(我假设它必须初始化一个图)有零个顶点和边。
当我运行我的ajax调用时,正如我承诺的那样,我稍后会进入,我成功POST到服务器。已经 运行ning 了。一切顺利。
然而...
当我更改 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
。这应该是正确的。 json 文件可以找到 here, and the properties file follows the format of this 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 (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
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(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 而言,我什至从未加载过图表。也许它启动了一个图表,却忘记了从内存中删除它,对吧?
好吧,让我们创建自己的文件并只初始化一个顶点和一些奇怪的质数,没有边。我们称它为 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 (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
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 - Gremlin Server configured with worker thread pool of 1, gremlin pool of 8 and boss thread pool of 1.
[INFO] GremlinServer - 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 (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
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(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
和之前一样的错误。这到底是怎么回事?还有两件事引起了我的注意:
ERROR] GremlinServer - Gremlin Server Error java.lang.IllegalArgumentException: Vertex with id already exists: 1
。是说只有一个顶点存在,还是存在ID为'1'的顶点?因为我的 none 个顶点的 ID 为 1。也就是说,直到...您注意到这甚至没有加载我的文件!
[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 查询以查看发生了什么
我有一个非常非常简单的查询,我 运行 和 post 使用 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 服务器以 [=214=] 一些数据的查询,它看起来像这样:
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]'
这个查询本质上应该是 return 一个节点和边的列表。现在,我想回顾一下三种情况:
tinkerpop-empty.properties(实际为空):
第一种情况是使用未更改的 tinkerpop-empty.properties 文件。请记住,当我加载它时,我得到的输出是:
[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
这意味着 tinkergraph 中应该没有任何信息。我应该收到一个空列表。但是,当我 运行 打电话时,我得到这个:
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]
。我还没有验证这是正确的......这不是那么容易。
小叮当-empty.properties 正在加载小叮当-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-server 将信息转储到该文件?如果您看到最后一行,它包含文件的原始内容:
{"id":{"@type":"g:Int64","@value":47284629},"label":"person"}
好吧,真的,@tinkerpop,这到底是怎么回事?
我想现在可以理解为什么当我第二次 运行 文件时,它再次抛出该错误并说 ID 为 1 的顶点已经存在!
好笑,我离题了!让我们删除该文件的非原始部分,只 运行 它与:
{"id":{"@type":"g:Int64","@value":47284629},"label":"person"}
好的,运行 很好,我应该期待正确的信息:[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!假设它正在加载一些东西,例如 and 附加我的文件,它应该是节点长度 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]
我认为这里开始出现问题:
When I change the tinkerpop-empty.properties folder to load a graph, things get really weird. I am going to change it as such:
gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph gremlin.tinkergraph.vertexIdManager=LONG gremlin.tinkergraph.graphLocation=data/tinkerpop-crew.json gremlin.tinkergraph.graphFormat=graphson
你得到你所做的错误是因为你错过了 Gremlin 服务器初始化脚本是 运行 - 你的 yaml 中的这一行:
https://github.com/apache/tinkerpop/blob/3.4.3/gremlin-server/conf/gremlin-server-rest-modern.yaml
所以这就是试图将 "modern" 图加载到你试图指定为 "crew" 图的图中(或者相反,我不记得加载了哪些首先,但我认为我做对了)。解决方案是:
- 在
scripts/generate-modern.groovy
中注释掉加载 "modern" 图表的行,并保持属性文件不变,或者 - 更改
scripts/generate-modern.groovy
初始化脚本以仅加载 "crew" 数据并保持属性文件不变以获得空图。
你有一长串其他 odds/ends 看起来很奇怪,但我想知道其中有多少是由于缺少 init 文件以及它对你做了什么 "behind your back"。这些知识是否有助于解决您所有的问题?如果没有,请告诉我还有什么问题,我可以尝试帮助解决它。