无法创建复合索引,卡在INSTALLED

Foo*_*ook 16 amazon-dynamodb gremlin titan

我无法创建索引.我的Gremlin代码如下:

usernameProperty = mgmt.getPropertyKey('username')
usernameIndex = mgmt.buildIndex('byUsernameUnique', Vertex.class).addKey(usernameProperty).unique().buildCompositeIndex()
mgmt.setConsistency(usernameIndex, ConsistencyModifier.LOCK)
mgmt.commit()
Run Code Online (Sandbox Code Playgroud)

我收到两个错误后不久:

18:04:57 ERROR com.thinkaurelius.titan.graphdb.database.management.ManagementLogger - 从缓存中驱逐[1 @ 0a00009d2537-ip-10-0-0-1572]但等待交易结束的时间太长.过时的交易警报:[standardtitantx [0x6549ce71]] 18:04:57 ERROR com.thinkaurelius.titan.graphdb.database.management.ManagementLogger - 从缓存中驱逐[1 @ 0a00009d2537-ip-10-0-0-1572]但是等待交易结束的时间过长.过时的交易警报:[standardtitantx [0x2a2815cc],standardtitantx [0x025dc2c0]]

索引的状态停留在INSTALLED:

usernameIndex.getIndexStatus(usernameProperty)
==>INSTALLED
Run Code Online (Sandbox Code Playgroud)

我读到失败的实例可能会导致问题,但检查正在运行的实例只显示一个:

mgmt.getOpenInstances()
==>0a00009d3011-ip-10-0-0-1572(current)
Run Code Online (Sandbox Code Playgroud)

我也尝试发布一个REGISTER_INDEX动作,它也会从事务缓存中逐出,并带有类似的错误消息:

mgmt.updateIndex(usernameIndex, SchemaAction.REGISTER_INDEX).get()
mgmt.commit()
Run Code Online (Sandbox Code Playgroud)

我也尝试过多次重启服务器.

注册过程似乎只是超时,导致事务缓存"逐出".我等了48个小时才确定这不是一个缓慢的过程.对Titan的正常读取,写入和关联提交似乎工作正常,我只是无法创建此索引.我被卡住了,还有什么我可以尝试的吗?有没有办法延长该事务的超时?

我正在使用DynamoDB后端运行Titan 1.0.0(使用AWS提供的CloudFormation模板进行设置).

编辑:这是我正在粘贴Gremlin的完整命令,添加awaitGraphStatus了@MTA建议的步骤:

mgmt = graph.openManagement();
usernameIndex = mgmt.getPropertyKey('usernameIndex');
mgmt.buildIndex('byUsername',Vertex.class).addKey(usernameIndex).unique().buildCompositeIndex();
// I have tried with and without a commit here: mgmt.commit();
mgmt.awaitGraphIndexStatus(graph, 'byUsername').status(SchemaStatus.REGISTERED).timeout(10, java.time.temporal.ChronoUnit.MINUTES).call();
Run Code Online (Sandbox Code Playgroud)

这会导致以下错误:

com.thinkaurelius.titan.graphdb.database.management.GraphIndexStatusWatcher.call(GraphIndexStatusWatcher.java:52)中的java.lang.NullPointerException,地址为com.thinkaurelius.titan.graphdb.database.management.GraphIndexStatusWatcher.call(GraphIndexStatusWatcher.java:18) )atg.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)中的java_util_concurrent_Callable $ call.call(未知来源)atg.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java) :110)org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:114)at groovysh_evaluate.run(groovysh_evaluate:3)at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface. java:215)org.codehaus.groovy.tools.shell.Interpreter.evaluate(Interpreter.groovy:69)org.codehaus.groovy.tools.shell.Groovysh.execute(Groovysh.groovy:185)at org.codehaus .groovy.tools.shell.Shell.leftShift(Shell.groovy:119)在org.codehaus.groovy.tools.shell.ShellRunner.work(谢尔 lRunner.groovy:94)

我还要注意,禁用和删除索引的例程也失败了.

mgmt = graph.openManagement()
theIndex = mgmt.getGraphIndex('byUsername')
mgmt.updateIndex(theIndex, SchemaAction.DISABLE_INDEX).get()
mgmt.commit()
mgmt.awaitGraphIndexStatus(graph, 'byUsername').status(SchemaStatus.DISABLED).timeout(10, java.time.temporal.ChronoUnit.MINUTES).call();
m = graph.openManagement()
i = m.getGraphIndex('byUsername')
m.updateIndex(i, SchemaAction.REMOVE_INDEX).get()
m.commit()
Run Code Online (Sandbox Code Playgroud)

19:26:26 ERROR com.thinkaurelius.titan.graphdb.database.management.ManagementLogger - 从缓存中驱逐[1 @ ac1f3fa810472-ip-172-31-63-1681]但等待事务关闭的时间太长.陈旧的交易警告:standardtitantx [0x2314cd97],standardtitantx [0x39f8adc0],standardtitantx [0x09de1b85]

编辑2:尝试在同一事务中创建新的属性键和索引工作!但这是否意味着我无法在现有属性键上创建索引?

graph.tx().rollback();
mgmt = graph.openManagement();
indexName = 'byUsernameTest2';
propertyKeyName = 'testPropertyName2';
propertyKey = mgmt.makePropertyKey(propertyKeyName).dataType(String.class).cardinality(Cardinality.SINGLE).make();
mgmt.buildIndex(indexName,Vertex.class).addKey(propertyKey).buildCompositeIndex();
mgmt.commit();
graph.tx().commit();
mgmt.awaitGraphIndexStatus(graph, indexName).status(SchemaStatus.REGISTERED).timeout(10, java.time.temporal.ChronoUnit.MINUTES).call();
mgmt.commit();
Run Code Online (Sandbox Code Playgroud)

暂停后,这会导致:

此管理系统实例已关闭

尝试获取新索引会导致:

mgmt = graph.openManagement();
index = mgmt.getGraphIndex('byUsernameTest2');
propkey = mgmt.getPropertyKey('testPropertyName2');
index.getIndexStatus(propkey);
Run Code Online (Sandbox Code Playgroud)

==>已启用

Moh*_*aie 4

您需要等待 Titan 和 DynamoDB 注册索引。您可以通过以下方式做到这一点:

ManagementSystem.awaitGraphIndexStatus(graph, propertyKeyIndexName)
                    .status(SchemaStatus.REGISTERED)
                    .timeout(10, java.time.temporal.ChronoUnit.MINUTES) // set timeout to 10 min
                    .call();
Run Code Online (Sandbox Code Playgroud)

默认超时通常不够长,因此您可以将其增加到 10 分钟,这通常可以在 Dynamo 支持的情况下完成。

仅当索引处于 REGISTERED 状态时,才可以执行重新索引。一旦重新索引完成,您需要等待它被启用。通过重用上面的代码示例并将状态更改为“启用”。

有关更多信息,请参阅文档

编辑

让我分享一下一直在 Berkeley 和 Dynamo DB 后端与我配合使用的代码。

    graph.tx().rollback(); //Never create new indexes while a transaction is active
    TitanManagement mgmt=graph.openManagement();
    PropertyKey propertyKey=getOrCreatePropertyKeyIfNotExist(mgmt, propertyKeyName);
    String indexName = makePropertyKeyIndexName(propertyKey);

    if (mgmt.getGraphIndex(indexName)==null) { 
        mgmt.buildIndex(indexName, Vertex.class).addKey(propertyKey).buildCompositeIndex();
        mgmt.commit(); // you MUST commit mgmt
        graph.tx().commit(); // and commit the transaction too
        ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(SchemaStatus.REGISTERED).call();
    }else { // already defined.
        mgmt.rollback();
        graph.tx().rollback();
    }

private static PropertyKey getOrCreatePropertyKeyIfNotExist(TitanManagement mgmt, String s) {
    PropertyKey key = mgmt.getPropertyKey(s);
    if (key != null)
        return key;
    else
        return mgmt.makePropertyKey(s).dataType(String.class).make();
}

private static String makePropertyKeyIndexName(PropertyKey pk) {
    return pk.name() + Tokens.INDEX_SUFFIX;
}
Run Code Online (Sandbox Code Playgroud)

从我看到的错误来看,泰坦似乎无法获取索引,这意味着您正在等待甚至未定义的索引。在这里查看导致错误的行。

确保将正确的索引名称传递给awaitGraphIndexStatus.