[ https://issues.apache.org/jira/browse/TINKERPOP-3141?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18008144#comment-18008144 ]
ASF GitHub Bot commented on TINKERPOP-3141: ------------------------------------------- Cole-Greer commented on code in PR #3161: URL: https://github.com/apache/tinkerpop/pull/3161#discussion_r2216821853 ########## tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerTransactionGraphTest.java: ########## @@ -1503,4 +1504,53 @@ public void shouldHandleCorrectlyHandleCountForChangedAndReadElement() { assertFalse(vertex.inUse()); } + + @Test + public void shouldAllowDropThenInsertInSameTransaction() { + final TinkerTransactionGraph g = TinkerTransactionGraph.open(); + final TinkerTransaction tx = (TinkerTransaction) g.tx(); + final int vertexId = 1; + + // create initial vertex with a property + final GraphTraversalSource gtx = tx.begin(); + gtx.addV().property(T.id, vertexId).property("name", "test").next(); + gtx.tx().commit(); + + verifyCommittedSingleVertexWithId(g, vertexId); + final TinkerVertex originalVertex = g.getVertices().get(vertexId).getUnmodified(); + assertEquals("test", originalVertex.properties.get("name").get(0).value()); + final long originalVersion = originalVertex.version(); + + // drop the vertex and re-create it without any properties in the same transaction + final GraphTraversalSource gtx2 = tx.begin(); + gtx2.V().drop().iterate(); + gtx2.addV().property(T.id, vertexId).next(); + gtx2.tx().commit(); + + verifyCommittedSingleVertexWithId(g, vertexId); + final TinkerElementContainer<TinkerVertex> container = g.getVertices().get(vertexId); + final TinkerVertex updatedVertex = container.getUnmodified(); + assertNull(updatedVertex.properties); + // version should have been updated + assertNotEquals(originalVersion, updatedVertex.version()); Review Comment: Would be nice to throw in an edge on the vertex and ensure the edge remains dropped after gtx2 is committed ```suggestion gtx.addV().property(T.id, vertexId).property("name", "test").next(); gtx.addE().from(V(vertexId)).to(V(vertexId)) gtx.tx().commit(); verifyCommittedSingleVertexWithId(g, vertexId); final TinkerVertex originalVertex = g.getVertices().get(vertexId).getUnmodified(); assertEquals("test", originalVertex.properties.get("name").get(0).value()); assertEquals(1, g.getEdgesCount()); final long originalVersion = originalVertex.version(); // drop the vertex and re-create it without any properties in the same transaction final GraphTraversalSource gtx2 = tx.begin(); gtx2.V().drop().iterate(); gtx2.addV().property(T.id, vertexId).next(); gtx2.tx().commit(); verifyCommittedSingleVertexWithId(g, vertexId); final TinkerElementContainer<TinkerVertex> container = g.getVertices().get(vertexId); final TinkerVertex updatedVertex = container.getUnmodified(); assertNull(updatedVertex.properties); assertEquals(0, g.getEdgesCount()); // version should have been updated assertNotEquals(originalVersion, updatedVertex.version()); ``` > 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)