gpt4 book ai didi

scala - 使用 Scala Future 处理 TitanDB 中的异步事务时遇到问题

转载 作者:行者123 更新时间:2023-12-03 01:18:09 27 4
gpt4 key购买 nike

我正在使用 Titan 事务 API 来处理代码中的事务。工作正常,

这是我的代码:

同步事务:

 def  syncTransaction()={

val transaction = titanGraph.newTransaction

// doing some modification and query , creation vertex

transaction.commit()
}

我正在调用上面的方法来实现 1000 条记录的持久化。它工作正常。

异步事务:

 def  aysncTransaction()= Future{

val transaction = titanGraph.newTransaction

// doing some modification and query , creation vertex

transaction.commit()
}

当上面的代码包装在 Scala Future 中时(Scala future 用于非阻塞和异步代码执行),它会抛出以下异常:

[ERROR] - [2016-05-16 14:01:04,849] -           [com.thinkaurelius.titan.graphdb.database.StandardTitanGraph] Could not commit transaction [2] due to exception
com.thinkaurelius.titan.diskstorage.locking.PermanentLockingException: Local lock contention
at com.thinkaurelius.titan.diskstorage.locking.AbstractLocker.writeLock(AbstractLocker.java:313) ~[titan-core-1.1.0-SNAPSHOT.jar:na]
at com.thinkaurelius.titan.diskstorage.locking.consistentkey.ExpectedValueCheckingStore.acquireLock(ExpectedValueCheckingStore.java:89) ~[titan-core-1.1.0-SNAPSHOT.jar:na]
at com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVSProxy.acquireLock(KCVSProxy.java:40) ~[titan-core-1.1.0-SNAPSHOT.jar:na]
at com.thinkaurelius.titan.diskstorage.BackendTransaction.acquireIndexLock(BackendTransaction.java:240) ~[titan-core-1.1.0-SNAPSHOT.jar:na]
at com.thinkaurelius.titan.graphdb.database.StandardTitanGraph.prepareCommit(StandardTitanGraph.java:554) ~[titan-core-1.1.0-SNAPSHOT.jar:na]
at com.thinkaurelius.titan.graphdb.database.StandardTitanGraph.commit(StandardTitanGraph.java:683) ~[titan-core-1.1.0-SNAPSHOT.jar:na]
at com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx.commit(StandardTitanTx.java:1352) [titan-core-1.1.0-SNAPSHOT.jar:na]
at com.freebird.titan.connect.GraphFactory$class.withTransaction(GraphFactory.scala:25) [classes/:na]
at com.freebird.oag.ingestion.TitanDBPersistentActorImpl.withTransaction(TitanDBPersistentActor.scala:25) [classes/:na]
at com.freebird.titan.connect.GraphFactory$$anonfun$withAsyncTransaction$1.apply(GraphFactory.scala:17) [classes/:na]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) [scala-library-2.11.7.jar:na]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) [scala-library-2.11.7.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_77]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_77]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_77]

谁能告诉我我在这里做错了什么。任何帮助表示赞赏。谢谢

最佳答案

根据我的经验,发生这种情况是因为多个线程正在改变同一顶点或边。来自 Titan Docs :

PermanentLockingException(Local lock contention): Another local thread has already been granted a conflicting lock.

我建议按照 Titan 的建议进行操作,即简单地重试交易多次。当然,这因用例而异。再次形成Titan Docs :

try {
if (g.V().has("name", name).iterator().hasNext())
throw new IllegalArgumentException("Username already taken: " + name)
user = graph.addVertex()
user.property("name", name)
graph.tx().commit()
} catch (Exception e) {
//Recover, retry, or return error message
println(e.getMessage())
}

泰坦自己说过:

In fact, transactions will eventually fail in sufficiently large systems.

关于scala - 使用 Scala Future 处理 TitanDB 中的异步事务时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37260341/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com