Database Titan索引更新时间太长
即使在空数据库上,在Titan 1.0中创建索引也需要几分钟。时间似乎很准确,这表明有不必要的延误 我的问题是:如何缩短或消除Titan重新编制索引所需的时间?从概念上讲,因为没有工作要做,所以时间应该是最少的,当然不是四分钟 (注意,我之前提到过一种解决方案,它只是让Titan等待完全延迟而不超时。这是错误的解决方案-我想完全消除延迟。) 我用来从头开始设置数据库的代码是:Database Titan索引更新时间太长,database,titan,tinkerpop,gremlin-server,Database,Titan,Tinkerpop,Gremlin Server,即使在空数据库上,在Titan 1.0中创建索引也需要几分钟。时间似乎很准确,这表明有不必要的延误 我的问题是:如何缩短或消除Titan重新编制索引所需的时间?从概念上讲,因为没有工作要做,所以时间应该是最少的,当然不是四分钟 (注意,我之前提到过一种解决方案,它只是让Titan等待完全延迟而不超时。这是错误的解决方案-我想完全消除延迟。) 我用来从头开始设置数据库的代码是: graph = ... a local cassandra instance ... graph.tx().rollba
graph = ... a local cassandra instance ...
graph.tx().rollback()
// 1. Check if the index already exists
mgmt = graph.openManagement()
i = mgmt.getGraphIndex('byIdent')
if(! i) {
// 1a. If the index does not exist, add it
idKey = mgmt.getPropertyKey('ident')
idKey = idKey ? idKey : mgmt.makePropertyKey('ident').dataType(String.class).make()
mgmt.buildIndex('byIdent', Vertex.class).addKey(idKey).buildCompositeIndex()
mgmt.commit()
graph.tx().commit()
mgmt = graph.openManagement()
idKey = mgmt.getPropertyKey('ident')
idx = mgmt.getGraphIndex('byIdent')
// 1b. Wait for index availability
if ( idx.getIndexStatus(idKey).equals(SchemaStatus.INSTALLED) ) {
mgmt.awaitGraphIndexStatus(graph, 'byIdent').status(SchemaStatus.REGISTERED).call()
}
// 1c. Now reindex, even though the DB is usually empty.
mgmt.updateIndex(mgmt.getGraphIndex('byIdent'), SchemaAction.REINDEX).get()
mgmt.commit()
mgmt.awaitGraphIndexStatus(graph, 'byIdent').status(SchemaStatus.ENABLED).call()
} else { mgmt.commit() }
似乎是updateIndex…REINDEX
调用阻止超时。这是一个已知的问题还是工作表单?我做错什么了吗
编辑:如注释中所述,禁用重新索引实际上并不是一个修复方法,因为索引似乎没有变为活动状态。我现在看到:
WARN com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx - Query requires iterating over all vertices [(myindexedkey = somevalue)]. For better performance, use indexes
时间延迟完全没有必要,这是因为我误用了Titan(尽管该模式确实出现在Titan 1.0.0文档第28章) 不要在事务中阻塞强> 而不是:
mgmt = graph.openManagement()
idKey = mgmt.getPropertyKey('ident')
idx = mgmt.getGraphIndex('byIdent')
// 1b. Wait for index availability
if ( idx.getIndexStatus(idKey).equals(SchemaStatus.INSTALLED) ) {
mgmt.awaitGraphIndexStatus(graph, 'byIdent').status(SchemaStatus.REGISTERED).call()
}
考虑:
mgmt = graph.openManagement()
idKey = mgmt.getPropertyKey('ident')
idx = mgmt.getGraphIndex('byIdent')
// Wait for index availability
if ( idx.getIndexStatus(idKey).equals(SchemaStatus.INSTALLED) ) {
mgmt.commit()
mgmt.awaitGraphIndexStatus(graph, 'byIdent').status(SchemaStatus.REGISTERED).call()
} else { mgmt.commit() }
使用启用索引
不是:mgmt.updateIndex(mgmt.getGraphIndex('byIdent')、SchemaAction.REINDEX.get()
相反:
mgmt.updateIndex(mgmt.getGraphIndex('byIdent')、SchemaAction.ENABLE_INDEX).get()
如果没有现有数据,比如第一次创建属性键和索引时,可能会重复调用REINDEX
。@JasonPlurad这对于我的大多数使用来说是一个很好的策略。如果在创建索引时数据库很小怎么办?比如说,如果我的垂直度非常小,但不是零,怎么办?我必须重新编制索引并招致这种看似毫无意义的延迟(至少在我提交拉取请求之前)?是的,如果你有数据在那里,那么你需要重新编制索引。最佳实践是预先定义模式和索引并将其锁定。