当我尝试保存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]
答案 0 :(得分:1)
发生此异常是因为您在多版本控制检查(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();
}
}
maxRetries 是重新加载的最大尝试次数。
有关更多信息,请查看官方文档:http://www.orientechnologies.com/docs/last/orientdb.wiki/Troubleshooting-Java.html