【问题标题】:Titan index update takes too longTitan 索引更新耗时过长
【发布时间】:2016-10-01 10:22:03
【问题描述】:

即使在空数据库上,在 Titan 1.0 中创建索引也需要几分钟时间。时间似乎很准确,这表明存在不必要的延迟。

我的问题是:我如何缩短或消除 Titan 重新索引所需的时间? 从概念上讲,由于没有完成任何工作,所以时间应该很短,当然不是四分钟。

(请注意,我之前曾有人指出一个解决方案,它只是让 Titan 等待完全延迟而不超时。这是错误的解决方案 - 我想完全消除延迟。)

我用来从头开始设置数据库的代码是:

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 调用阻塞直到超时。这是一个已知问题还是无法修复的工作表?我做错了吗?

编辑:禁用 REINDEX,正如 cmets 中所讨论的那样,实际上并不是一个修复,因为索引似乎没有变得活跃。我现在看到了:

WARN  com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx  - Query requires iterating over all vertices [(myindexedkey = somevalue)]. For better performance, use indexes

【问题讨论】:

  • 如果没有现有数据(例如第一次创建属性键和索引时),请消除对 REINDEX 的调用。
  • @JasonPlurad 这对于我的大多数用途来说是一个很好的策略。如果在创建索引时数据库很小怎么办?说,如果我有很少但非零的顶点怎么办?我是否必须重新索引并招致这种看似毫无意义的延迟(至少在我提交拉取请求之前)?
  • 是的,如果你有数据,在这种情况下你需要REINDEX。最佳做法是预先定义架构和索引并将其锁定。

标签: database titan tinkerpop gremlin-server


【解决方案1】:

由于我对 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() }

使用 ENABLE_INDEX

不是:mgmt.updateIndex(mgmt.getGraphIndex('byIdent'), SchemaAction.REINDEX).get()

而是:mgmt.updateIndex(mgmt.getGraphIndex('byIdent'),SchemaAction.ENABLE_INDEX).get()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-27
    • 1970-01-01
    • 2016-08-09
    • 1970-01-01
    相关资源
    最近更新 更多