java - OrientGraph 中的 OConcurrentModificationException

标签 java orientdb

当我尝试保存 OrientGraph 数据库时,出现以下异常。

这是我实现提交的代码。

代码:

    OrientGraph orientGraph = null;
    String source = enrichData.getSource();


    orientGraph = orientConfiguration.open();
    LocationDocument location = enrichData.getGeoLocation();

    Vertex locationVertex = null;
    Vertex contentVertex = null;
    Vertex userVertex = null;

    if ((location != null) && !location.isNull()) {
        locationVertex = getLocationVertex(location, orientGraph);
    }

    ContentDocument content = enrichData.getContent();
    if ((content != null) && (StringUtils.isNotBlank(content.getTweetId()))) {
        contentVertex = getContentVertex(orientGraph, content, source);
    }

    UserDocument user = enrichData.getUserInfo();
    if ((user != null) && (StringUtils.isNotBlank(user.getUserId()))) {
        userVertex = createUser(orientGraph, user, source);
    }

    if (locationVertex != null) {
        orientGraph.addEdge(null, userVertex, locationVertex, "lives_at");
    }
    if ((contentVertex != null) && (userVertex != null)) {
        orientGraph.addEdge(null, contentVertex, userVertex, "posted_by");
    }
    orientGraph.commit();

    if (orientGraph != null) {
        orientConfiguration.close(orientGraph);
    }

输出:

      java.lang.RuntimeException: com.orientechnologies.orient.core.exception.OConcurrentModificationException: Cannot UPDATE the record #13:8 because the version is not the latest. Probably you are updating an old record or it has been modified by another user (db=v7 your=v6)
at backtype.storm.utils.DisruptorQueue.consumeBatchToCursor(DisruptorQueue.java:90) ~[storm-core-0.9.0.1.jar:na]
at backtype.storm.utils.DisruptorQueue.consumeBatchWhenAvailable(DisruptorQueue.java:61) ~[storm-core-0.9.0.1.jar:na]
at backtype.storm.disruptor$consume_batch_when_available.invoke(disruptor.clj:62) ~[storm-core-0.9.0.1.jar:na]
at backtype.storm.daemon.executor$fn__3498$fn__3510$fn__3557.invoke(executor.clj:730) ~[storm-core-0.9.0.1.jar:na]
at backtype.storm.util$async_loop$fn__444.invoke(util.clj:403) ~[storm-core-0.9.0.1.jar:na]
at clojure.lang.AFn.run(AFn.java:24) [clojure-1.4.0.jar:na]
at java.lang.Thread.run(Thread.java:722) [na:1.7.0_17]
Caused by: com.orientechnologies.orient.core.exception.OConcurrentModificationException: Cannot UPDATE the record #13:8 because the version is not the latest. Probably you are updating an old record or it has been modified by another user (db=v7 your=v6)
at com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage.updateRecord(OLocalPaginatedStorage.java:797) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.db.raw.ODatabaseRaw.save(ODatabaseRaw.java:273) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.executeSaveRecord(ODatabaseRecordAbstract.java:1132) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.tx.OTransactionOptimistic.addRecord(OTransactionOptimistic.java:422) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.tx.OTransactionOptimistic.saveRecord(OTransactionOptimistic.java:365) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.db.record.ODatabaseRecordTx.save(ODatabaseRecordTx.java:319) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.db.record.ODatabaseRecordTx.save(ODatabaseRecordTx.java:40) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.record.ORecordAbstract.save(ORecordAbstract.java:334) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1458) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1447) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1436) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:81) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.db.record.ridbag.embedded.OEmbeddedRidBag.serialize(OEmbeddedRidBag.java:291) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.db.record.ridbag.ORidBag.toStream(ORidBag.java:222) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerCSVAbstract.fieldToStream(ORecordSerializerCSVAbstract.java:542) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerSchemaAware2CSV.toString(ORecordSerializerSchemaAware2CSV.java:495) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerStringAbstract.toStream(ORecordSerializerStringAbstract.java:669) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerSchemaAware2CSV.toStream(ORecordSerializerSchemaAware2CSV.java:258) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.record.ORecordSchemaAwareAbstract.toStream(ORecordSchemaAwareAbstract.java:420) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.record.ORecordSchemaAwareAbstract.toStream(ORecordSchemaAwareAbstract.java:415) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.record.impl.ODocument.toStream(ODocument.java:446) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage.commitEntry(OLocalPaginatedStorage.java:2102) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage.commit(OLocalPaginatedStorage.java:1078) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.tx.OTransactionOptimistic.doCommit(OTransactionOptimistic.java:132) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.tx.OTransactionOptimistic.commit(OTransactionOptimistic.java:105) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.db.record.ODatabaseRecordTx.commit(ODatabaseRecordTx.java:142) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:504) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:496) ~[orientdb-core-1.7.6.jar:1.7.6]
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.commit(ONetworkProtocolBinary.java:1096) ~[orientdb-server-1.7.2.jar:1.7.2]
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.executeRequest(ONetworkProtocolBinary.java:344) ~[orientdb-server-1.7.2.jar:1.7.2]
at com.orientechnologies.orient.server.network.protocol.binary.OBinaryNetworkProtocolAbstract.execute(OBinaryNetworkProtocolAbstract.java:169) ~[orientdb-server-1.7.2.jar:1.7.2]
at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:45) ~[orient-commons-1.7.6.jar:1.7.6]

最佳答案

发生此异常的原因是您正在多版本控制检查 (MVCC) 系统中运行,并且另一个线程/用户已更新您正在保存的记录。要解决此问题,您可以:

如果您正在多线程应用程序中运行,并且您的 JVM 是写入数据库的唯一客户端,那么禁用 Level1 缓存就足够了。 如果您使用 GraphDB API,请查看:并发性 如果你想离开MVCC并编写并发证明代码:

for (int retry = 0; retry < maxRetries; ++retry) {
  try {
    // APPLY CHANGES
    document.field(name, "Luca");

    document.save();
    break;
  } catch(ONeedRetryException e) {
    // RELOAD IT TO GET LAST VERSION
    document.reload();
  }
}

交易中相同:

for (int retry = 0; retry < maxRetries; ++retry) {
  db.begin();
  try {
    // CREATE A NEW ITEM
    ODocument invoiceItem = new ODocument("InvoiceItem");
    invoiceItem.field(price, 213231);
    invoiceItem.save();

    // ADD IT TO THE INVOICE
    Collection<ODocument> items = invoice.field(items);
    items.add(invoiceItem);
    invoice.save();

    db.commit();
    break;
  } catch (OTransactionException e) {
    // RELOAD IT TO GET LAST VERSION
    invoice.reload();
  }
}

其中ma​​xRetries是尝试重新加载的最大次数。

更多信息请查看官方文档:http://www.orientechnologies.com/docs/last/orientdb.wiki/Troubleshooting-Java.html

关于java - OrientGraph 中的 OConcurrentModificationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25601318/

相关文章:

java - 如何提取 RestEasy 的 JacksonProvider 用来解析 .json 文件的 ObjectMapper?

java - SQL 使用两个不同列中的值进行排序

csv - OrientDB etl加载csv但看不到类中的记录

java - OrientDB无法使用java远程获取图形实例

java - OrientDB SQL 连接替代方案

orientdb - 在 OrientDb 中查找并删除重复边

java - Java 中的事件键箭头

java - WebSphere 身份验证问题——也可能打开文件

orientdb - OrientJS:如何从查询中获取标准 JSON(序列化)

java - 使用 Java 与数据库进行数据更新