Janusgraph - 警告在创建模式和索引之后迭代所有顶点

时间:2018-04-16 19:31:16

标签: gremlin tinkerpop3 janusgraph gremlin-server

我正在使用JanusGraph和Cassandra以及ElasticSearch后端。我使用以下脚本来创建我的架构和索引。

// Create a Janus Graph instance, according to the configuration file provided
// in the open() method below, and define the schema and index.
// This is intended to be loaded and run inside the Gremlin Console from the Janus
// Graph download. Usage :load janus-ualschema.groovy

println "\n=======================================";[]
println "Creating in-memory Janus Graph instance";[]
println "=======================================\n";[]
// Create a new graph instance
graph = JanusGraphFactory.open("conf/janusgraph-useractivitylogs.properties")
mgmt = graph.openManagement()

println "\n====================";[]
println "Defining EDGE labels";[]
println "====================\n";[]
// Define edge labels and their usage
mgmt.makeEdgeLabel('logsIn').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('launches').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('accesses').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('enters').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('exits').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('logsOut').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('timesOut').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('assignedTo').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('connectedWith').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('operates').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('hosts').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('provisioned').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('supports').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('runsOn').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('owns').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('belongsTo').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('deployedFrom').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('implements').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('instanceOf').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('viewedOn').multiplicity(MULTI).make()
mgmt.makeEdgeLabel('compatibleWith').multiplicity(MULTI).make()
mgmt.commit()

println "\n======================";[]
println "Defining VERTEX labels";[]
println "======================\n";[]
// Define vertex labels
mgmt = graph.openManagement()
mgmt.makeVertexLabel('browser').make()
mgmt.makeVertexLabel('os').make()
mgmt.makeVertexLabel('device').make()
mgmt.makeVertexLabel('environment').make()
mgmt.makeVertexLabel('tenant').make()
mgmt.makeVertexLabel('user').make()
mgmt.makeVertexLabel('session').make()
mgmt.makeVertexLabel('application').make()
mgmt.makeVertexLabel('applicationInstance').make()
mgmt.makeVertexLabel('screen').make()
mgmt.makeVertexLabel('screenInstance').make()
mgmt.makeVertexLabel('company').make()
mgmt.makeVertexLabel('cloudSuite').make()
mgmt.commit()


println "\n====================";[]
println "Creating VERTEX keys";[]
println "====================\n";[]
// Define vertex property keys
mgmt = graph.openManagement()
mgmt.makePropertyKey('browserType').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('browserVersion').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('osFamily').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('osVersion').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('deviceFamily').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('deviceBrand').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('deviceModel').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('deviceType').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('deviceIsTouchCapable').dataType(Boolean.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('environmentServer').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('environmentType').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('tenantId').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('userId').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('sessionId').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('sessionIPAddress').dataType(String.class).cardinality(Cardinality.SET).make()
mgmt.makePropertyKey('sessionStart').dataType(Float.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('sessionEnd').dataType(Float.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('sessionTimeOut').dataType(Float.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('applicationName').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('applicationInstanceId').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('screenName').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('screenInstanceId').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('companyName').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('cloudSuiteName').dataType(String.class).cardinality(Cardinality.SINGLE).make()
mgmt.commit()


println "\n==================";[]
println "Creating EDGE keys";[]
println "====================\n";[]
// Define edge property keys
mgmt = graph.openManagement()
mgmt.makePropertyKey('logsInTimestamp').dataType(Float.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('launchesTimestamp').dataType(Float.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('accessesTimestamp').dataType(Float.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('entersTimestamp').dataType(Float.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('exitsTimestamp').dataType(Float.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('logsOutTimestamp').dataType(Float.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey('timesOutTimestamp').dataType(Float.class).cardinality(Cardinality.SINGLE).make()
mgmt.commit()


println "\n==========================";[]
println "Preparing keys for indexes";[]
println "==========================\n";[]

// Creates composite index
graph.tx().rollback()
mgmt = graph.openManagement()

browserType = mgmt.getPropertyKey('browserType')
browserVersion = mgmt.getPropertyKey('browserVersion')
osFamily = mgmt.getPropertyKey('osFamily')
osVersion = mgmt.getPropertyKey('osVersion')
deviceFamily = mgmt.getPropertyKey('deviceFamily')
deviceBrand = mgmt.getPropertyKey('deviceBrand')
deviceModel = mgmt.getPropertyKey('deviceModel')
deviceType = mgmt.getPropertyKey('deviceType')
deviceIsTouchCapable = mgmt.getPropertyKey('deviceIsTouchCapable')
environmentServer = mgmt.getPropertyKey('environmentServer')
environmentType = mgmt.getPropertyKey('environmentType')
tenantId = mgmt.getPropertyKey('tenantId')
userId = mgmt.getPropertyKey('userId')
sessionId = mgmt.getPropertyKey('sessionId')
sessionIPAddress = mgmt.getPropertyKey('sessionIPAddress')
sessionStart = mgmt.getPropertyKey('sessionStart')
sessionEnd = mgmt.getPropertyKey('sessionEnd')
sessionTimeOut = mgmt.getPropertyKey('sessionTimeOut')
applicationName = mgmt.getPropertyKey('applicationName')
applicationInstanceId = mgmt.getPropertyKey('applicationInstanceId')
screenName = mgmt.getPropertyKey('screenName')
screenInstanceId = mgmt.getPropertyKey('screenInstanceId')
companyName = mgmt.getPropertyKey('companyName')
cloudSuiteName = mgmt.getPropertyKey('cloudSuiteName')
logsInTimestamp = mgmt.getPropertyKey('logsInTimestamp')
launchesTimestamp = mgmt.getPropertyKey('launchesTimestamp')
accessesTimestamp = mgmt.getPropertyKey('accessesTimestamp')
entersTimestamp = mgmt.getPropertyKey('entersTimestamp')
exitsTimestamp = mgmt.getPropertyKey('exitsTimestamp')
logsOutTimestamp = mgmt.getPropertyKey('logsOutTimestamp')
timesOutTimestamp = mgmt.getPropertyKey('timesOutTimestamp')




println "\n================";[]
println "Building indexes";[]
println "================\n";[]
mgmt.buildIndex('byBrowserTypeComposite', Vertex.class).addKey(browserType).buildCompositeIndex()
mgmt.buildIndex('byBrowserTypeAndVersionUnique', Vertex.class).addKey(browserType).addKey(browserVersion).unique().buildCompositeIndex()
mgmt.buildIndex('byOSFamilyComposite', Vertex.class).addKey(osFamily).buildCompositeIndex()
mgmt.buildIndex('byOSFamilyAndVersionUnique', Vertex.class).addKey(osFamily).addKey(osVersion).unique().buildCompositeIndex()
mgmt.buildIndex('byDeviceModelAndBrandUnique', Vertex.class).addKey(deviceModel).addKey(deviceBrand).unique().buildCompositeIndex()
mgmt.buildIndex('byDeviceModelComposite', Vertex.class).addKey(deviceModel).buildCompositeIndex()
mgmt.buildIndex('byDeviceTypeAndBrandComposite', Vertex.class).addKey(deviceType).addKey(deviceBrand).buildCompositeIndex()
mgmt.buildIndex('byDeviceTypeAndTouchCapabilityComposite', Vertex.class).addKey(deviceType).addKey(deviceIsTouchCapable).buildCompositeIndex()
mgmt.buildIndex('byEnvironmentServerComposite', Vertex.class).addKey(environmentServer).buildCompositeIndex()
mgmt.buildIndex('byEnvironmentTypeComposite', Vertex.class).addKey(environmentType).buildCompositeIndex()
mgmt.buildIndex('byEnvironmentServerAndTypeUnique', Vertex.class).addKey(environmentServer).addKey(environmentType).unique().buildCompositeIndex()
mgmt.buildIndex('byTenandIdUnique', Vertex.class).addKey(tenantId).unique().buildCompositeIndex()
mgmt.buildIndex('byUserIdUnique', Vertex.class).addKey(userId).unique().buildCompositeIndex()
mgmt.buildIndex('bySessionIdUnique', Vertex.class).addKey(sessionId).unique().buildCompositeIndex()
mgmt.buildIndex('bySessionIPAddressComposite', Vertex.class).addKey(sessionIPAddress).buildCompositeIndex()
mgmt.buildIndex('bySessionIdAndIPAddressComposite', Vertex.class).addKey(sessionId).addKey(sessionIPAddress).buildCompositeIndex()
mgmt.buildIndex('bySessionIdAndStartMixed', Vertex.class).addKey(sessionId).addKey(sessionStart).buildMixedIndex("search")
mgmt.buildIndex('bySessionIdAndEndMixed', Vertex.class).addKey(sessionId).addKey(sessionEnd).buildMixedIndex("search")
mgmt.buildIndex('bySessionIdAndTimeOutMixed', Vertex.class).addKey(sessionId).addKey(sessionTimeOut).buildMixedIndex("search")
mgmt.buildIndex('byApplicationNameUnique', Vertex.class).addKey(applicationName).unique().buildCompositeIndex()
mgmt.buildIndex('byApplicationInstanceIdUnique', Vertex.class).addKey(applicationInstanceId).unique().buildCompositeIndex()
mgmt.buildIndex('byScreenNameUnique', Vertex.class).addKey(screenName).unique().buildCompositeIndex()
mgmt.buildIndex('byScreenInstanceIdUnique', Vertex.class).addKey(screenInstanceId).unique().buildCompositeIndex()
mgmt.buildIndex('byCompanyNameUnique', Vertex.class).addKey(companyName).unique().buildCompositeIndex()
mgmt.buildIndex('byCloudSuiteNameUnique', Vertex.class).addKey(cloudSuiteName).unique().buildCompositeIndex()
mgmt.buildIndex('byLogsInTimestampMixed', Edge.class).addKey(logsInTimestamp).buildMixedIndex("search")
mgmt.buildIndex('byLaunchesTimestampMixed', Edge.class).addKey(launchesTimestamp).buildMixedIndex("search")
mgmt.buildIndex('byAccessesTimestampMixed', Edge.class).addKey(accessesTimestamp).buildMixedIndex("search")
mgmt.buildIndex('byEntersTimestampMixed', Edge.class).addKey(entersTimestamp).buildMixedIndex("search")
mgmt.buildIndex('byExitsTimestampMixed', Edge.class).addKey(exitsTimestamp).buildMixedIndex("search")
mgmt.buildIndex('byLogsOutTimestampMixed', Edge.class).addKey(logsOutTimestamp).buildMixedIndex("search")
mgmt.buildIndex('byTimesOutTimestampMixed', Edge.class).addKey(timesOutTimestamp).buildMixedIndex("search")

mgmt.commit()

println "\n=================================";[]
println "Waiting for the index to be ready";[]
println "=================================\n";[]
mgmt.awaitGraphIndexStatus(graph, 'byBrowserTypeComposite').call()
mgmt.awaitGraphIndexStatus(graph, 'byBrowserTypeAndVersionUnique').call()
mgmt.awaitGraphIndexStatus(graph, 'byOSFamilyComposite').call()
mgmt.awaitGraphIndexStatus(graph, 'byOSFamilyAndVersionUnique').call()
mgmt.awaitGraphIndexStatus(graph, 'byDeviceModelAndBrandUnique').call()
mgmt.awaitGraphIndexStatus(graph, 'byDeviceModelComposite').call()
mgmt.awaitGraphIndexStatus(graph, 'byDeviceTypeAndBrandComposite').call()
mgmt.awaitGraphIndexStatus(graph, 'byDeviceTypeAndTouchCapabilityComposite').call()
mgmt.awaitGraphIndexStatus(graph, 'byEnvironmentServerComposite').call()
mgmt.awaitGraphIndexStatus(graph, 'byEnvironmentTypeComposite').call()
mgmt.awaitGraphIndexStatus(graph, 'byEnvironmentServerAndTypeUnique').call()
mgmt.awaitGraphIndexStatus(graph, 'byTenandIdUnique').call()
mgmt.awaitGraphIndexStatus(graph, 'byUserIdUnique').call()
mgmt.awaitGraphIndexStatus(graph, 'bySessionIdUnique').call()
mgmt.awaitGraphIndexStatus(graph, 'bySessionIPAddressComposite').call()
mgmt.awaitGraphIndexStatus(graph, 'bySessionIdAndIPAddressComposite').call()
mgmt.awaitGraphIndexStatus(graph, 'bySessionIdAndStartMixed').call()
mgmt.awaitGraphIndexStatus(graph, 'bySessionIdAndEndMixed').call()
mgmt.awaitGraphIndexStatus(graph, 'bySessionIdAndTimeOutMixed').call()
mgmt.awaitGraphIndexStatus(graph, 'byApplicationNameUnique').call()
mgmt.awaitGraphIndexStatus(graph, 'byApplicationInstanceIdUnique').call()
mgmt.awaitGraphIndexStatus(graph, 'byScreenNameUnique').call()
mgmt.awaitGraphIndexStatus(graph, 'byScreenInstanceIdUnique').call()
mgmt.awaitGraphIndexStatus(graph, 'byCompanyNameUnique').call()
mgmt.awaitGraphIndexStatus(graph, 'byCloudSuiteNameUnique').call()
mgmt.awaitGraphIndexStatus(graph, 'byLogsInTimestampMixed').call()
mgmt.awaitGraphIndexStatus(graph, 'byLaunchesTimestampMixed').call()
mgmt.awaitGraphIndexStatus(graph, 'byAccessesTimestampMixed').call()
mgmt.awaitGraphIndexStatus(graph, 'byEntersTimestampMixed').call()
mgmt.awaitGraphIndexStatus(graph, 'byExitsTimestampMixed').call()
mgmt.awaitGraphIndexStatus(graph, 'byLogsOutTimestampMixed').call()
mgmt.awaitGraphIndexStatus(graph, 'byTimesOutTimestampMixed').call()

//mgmt = graph.openManagement()

//println "\n===========";[]
//println "re-indexing";[]
//println "===========\n";[]
//mgmt.updateIndex(mgmt.getGraphIndex('byBrowserTypeComposite'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byBrowserTypeAndVersionUnique'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byOSFamilyComposite'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byOSFamilyAndVersionUnique'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byDeviceModelAndBrandUnique'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byDeviceModelComposite'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byDeviceTypeAndBrandComposite'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byDeviceTypeAndTouchCapabilityComposite'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byEnvironmentServerComposite'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byEnvironmentTypeComposite'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byEnvironmentServerAndTypeUnique'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byTenandIdUnique'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byUserIdUnique'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('bySessionIdUnique'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('bySessionIPAddressComposite'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('bySessionIdAndIPAddressComposite'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('bySessionIdAndStartMixed'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('bySessionIdAndEndMixed'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('bySessionIdAndTimeOutMixed'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byApplicationNameUnique'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byApplicationInstanceIdUnique'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byScreenNameUnique'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byScreenInstanceIdUnique'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byCompanyNameUnique'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byCloudSuiteNameUnique'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byLogsInTimestamp'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byLaunchesTimestamp'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byAccessesTimestamp'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byEntersTimestamp'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byExitsTimestamp'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byLogsOutTimestamp'), SchemaAction.REINDEX).get()
//mgmt.updateIndex(mgmt.getGraphIndex('byTimesOutTimestamp'), SchemaAction.REINDEX).get()
//mgmt.commit()
println "\n===========";[]
println "done";[]
println "===========\n";[]

图表上没有数据,我运行了脚本,没有错误。但是现在我插入了一些数据,每当我尝试运行任何查询时,例如:    的gremlin> 。g.V()hasLabel('浏览器&#39)。groupCount()由(' browserType&#39)。

我最后收到如下警告:

15:28:00 WARN  org.janusgraph.graphdb.transaction.StandardJanusGraphTx  - 

查询需要迭代所有顶点[(~label = browser)]。为了更好的    性能,使用索引    ==> [Safari浏览器:44,铬:1813,IE:199,火狐:34]

关于什么可能出错的任何想法?还有任何TinkerPop或JanusGraph命令,我可以用它来查看架构和其上定义的所有索引?

提前感谢你的帮助。

- MD

1 个答案:

答案 0 :(得分:2)

像这样的查询:

g.V().hasLabel('browser').groupCount().by('browserType')

需要完整的顶点扫描,因为JanusGraph目前不允许您在顶点标签上创建索引。 Issue 283可以跟踪该增强功能。

要调查哪些索引可用,您可以使用此wiki中提到的工具。