[
https://issues.apache.org/jira/browse/TINKERPOP-3141?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18008157#comment-18008157
]
ASF GitHub Bot commented on TINKERPOP-3141:
-------------------------------------------
andreachild commented on code in PR #3161:
URL: https://github.com/apache/tinkerpop/pull/3161#discussion_r2216896726
##########
tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerTransactionGraph.java:
##########
@@ -152,11 +152,19 @@ public Vertex addVertex(final Object... keyValues) {
if (container != null && container.get() != null)
throw Exceptions.vertexWithIdAlreadyExists(idValue);
+ long version = txNumber;
+ if (container != null && container.isDeleted() &&
container.getModified() != null) {
+ // vertex being added was previously deleted
+ // we need to reference the version from the deleted state when
adding the vertex back
+ version = container.getModified().version();
+ container.unmarkDeleted((TinkerTransaction) tx());
+ }
+
// no existing container, let's use new one
if (container == null)
container = newContainer;
- final TinkerVertex vertex = new TinkerVertex(idValue, label, this,
txNumber);
+ final TinkerVertex vertex = new TinkerVertex(idValue, label, this,
version);
Review Comment:
From my understanding the transaction number is specifically not set on the
vertex until commit is called and until then, the vertex should retain the
original version (except when adding a brand new vertex which will by default
have a version set to the transaction number).
```
public void commit(final long txVersion) {
updateUsesCount();
if (isDeletedInTx.get()) {
// created and deleted in same tx
if (null != element)
element.removed = true;
element = null;
isDeleted = true;
} else if (isModifiedInTx.get()){
element = transactionUpdatedValue.get();
element.currentVersion = txVersion;
}
reset();
}
```
Did I misunderstand?
> TinkerTransactionGraph doesn't allow deleting and adding element back in same
> transaction
> -----------------------------------------------------------------------------------------
>
> Key: TINKERPOP-3141
> URL: https://issues.apache.org/jira/browse/TINKERPOP-3141
> Project: TinkerPop
> Issue Type: Bug
> Components: tinkergraph
> Affects Versions: 3.7.3
> Reporter: Ken Hu
> Priority: Critical
>
> Originally discovered from:
> https://stackoverflow.com/questions/79467860/issue-with-transactions-in-local-tinkerpop-gremlin-setup
> [https://groups.google.com/g/gremlin-users/c/NRwb4xy2eXs]
>
> An element with the same Id cannot be dropped and then added back in the same
> transaction.
>
> {code:java}
> @Test
> public void shouldAllowDropThenInsert() throws InterruptedException {
> final TinkerTransactionGraph g = TinkerTransactionGraph.open();
> final GraphTraversalSource gtx = g.tx().begin();
> gtx.addV().property(T.id, 1).next();
> gtx.tx().commit();
> GraphTraversalSource gtx2 = g.tx().begin();
> gtx2.V().drop().iterate();
> gtx.addV().property(T.id, 1).next();
> gtx2.tx().commit();
> assertEquals(1, g.getVertices().size());
> } {code}
> throws a TransactionException.
> This occurs when the transaction attempts to get updated, the old
> vertex"isDeletedInTx" but has a different txNumber than the newly created
> vertex.
> [https://github.com/apache/tinkerpop/blob/3.7.3/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerElementContainer.java#L185]
> should probably allow this case through.
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)