【发布时间】:2016-08-23 14:48:47
【问题描述】:
我目前正在使用嵌入式模式的 Java Graph API 评估 OrientDB,以便在未来的项目中使用。在分布式设置中使用事务图实现时,我观察到以下问题:
- 服务器启动并激活后,我通过 OrientGraphFactory::factory.getTx() 获取了一个图实例
-
在第一个节点上,我设置了一个简单的模式如下:
graph.getRawGraph().commit(); if (graph.getVertexType("Person") == null) graph.createVertexType("Person"); final OrientVertexType vtPerson = graph.getVertexType("Person"); if (vtPerson.getProperty("firstName") == null) vtPerson.createProperty("firstName", OType.STRING); if (vtPerson.getProperty("lastName") == null) vtPerson.createProperty("lastName", OType.STRING); vtPerson.createEdgeProperty(Direction.OUT, "lives"); vtPerson.createEdgeProperty(Direction.OUT, "history"); vtPerson.setStrictMode(true); - 我关闭第一个节点并重新启动它,然后我也启动第二个节点,启动后我获得了一个图实例,如 (1) 所述。
-
在第一个节点我尝试添加一个顶点:
try { final OrientVertex person = graph.addVertex("class:Person", "firstName", firstName, "lastName", lastName); graph.getRawGraph().commit(); return person; } catch (Exception e) { e.printStackTrace(); graph.rollback(); }
那是我收到 OSchemaException 的时候:
com.orientechnologies.orient.core.exception.OSchemaException: Cannot change the schema while a transaction is active. Schema changes are not transactional
DB name="test"
at com.orientechnologies.orient.core.metadata.schema.OSchemaShared.saveInternal(OSchemaShared.java:1284)
at com.orientechnologies.orient.core.metadata.schema.OSchemaShared.releaseSchemaWriteLock(OSchemaShared.java:606)
at com.orientechnologies.orient.core.metadata.schema.OClassImpl.releaseSchemaWriteLock(OClassImpl.java:2028)
at com.orientechnologies.orient.core.metadata.schema.OClassImpl.releaseSchemaWriteLock(OClassImpl.java:2023)
at com.orientechnologies.orient.core.metadata.schema.OClassImpl.setClusterSelectionInternal(OClassImpl.java:2062)
at com.orientechnologies.orient.server.distributed.impl.ODistributedAbstractPlugin.propagateSchemaChanges(ODistributedAbstractPlugin.java:1439)
at com.orientechnologies.orient.server.distributed.impl.ODistributedStorage.checkForCluster(ODistributedStorage.java:1803)
at com.orientechnologies.orient.server.distributed.impl.ODistributedTransactionManager.checkForClusterIds(ODistributedTransactionManager.java:275)
at com.orientechnologies.orient.server.distributed.impl.ODistributedTransactionManager.commit(ODistributedTransactionManager.java:87)
at com.orientechnologies.orient.server.distributed.impl.ODistributedStorage.commit(ODistributedStorage.java:1240)
at com.orientechnologies.orient.core.tx.OTransactionOptimistic.doCommit(OTransactionOptimistic.java:569)
at com.orientechnologies.orient.core.tx.OTransactionOptimistic.commit(OTransactionOptimistic.java:109)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:2667)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:2637)
当使用 OrientGraphNoTx 实现时,一切都按预期工作。但是,我更喜欢使用事务图,以便能够回滚事务。
【问题讨论】:
-
它告诉您架构更改不是事务性的。数据变化是。
标签: java transactions orientdb