Skip to content

Instantly share code, notes, and snippets.

@helgridly
Last active September 4, 2015 18:03
Show Gist options
  • Save helgridly/0c153a79fa746fa3e266 to your computer and use it in GitHub Desktop.
Save helgridly/0c153a79fa746fa3e266 to your computer and use it in GitHub Desktop.
Orient 2.1.1 leaky transactions
val dbName = "blah"
val factory = new OrientGraphFactory("memory:"+dbName, "admin", "admin")
factory.setThreadMode(THREAD_MODE.MANUAL)
factory.setAutoStartTx(false)
factory.setUseClassForEdgeLabel(false)
factory.setUseLightweightEdges(true)
//Initial setup of DB.
val graph = factory.getTx
graph.begin()
val root = graph.asInstanceOf[OrientGraph].addVertex(s"class:Test", Map.empty[String, Object].asJava)
val v2 = graph.asInstanceOf[OrientGraph].addVertex(s"class:OtherSide", Map.empty[String, Object].asJava)
root.addEdge("foo", v2)
graph.commit()
new Thread(new Runnable {
def run() {
//Thread switches out the vertex on the other side of the "foo" edge.
val graph = factory.getTx
graph.begin()
println("t1 open")
Thread.sleep(1000)
val root = graph.asInstanceOf[OrientGraph].getVerticesOfClass("Test").head
root.getEdges(Direction.OUT, "foo").map( v => graph.removeVertex(v.getVertex(Direction.IN)) )
println("t1 removed vtx")
val v2 = graph.asInstanceOf[OrientGraph].addVertex(s"class:OtherSide", Map.empty[String, Object].asJava)
root.addEdge("foo", v2)
println("t1 readded vtx")
graph.commit()
}
}).start()
Thread.sleep(500)
val graph2 = factory.getTx
graph2.begin()
//If I move this line after the 550 sleep (i.e. after t1 commits), it's fine.
val root2 = graph2.asInstanceOf[OrientGraph].getVerticesOfClass("Test").head
println("t2 got root")
Thread.sleep(550)
println("t2 looking for verts")
//This assertion fails.
assert( root2.getEdges(Direction.OUT, "foo").size > 0 )
@helgridly
Copy link
Author

Since this is a concurrency issue, you might need to adjust the timings to repro this. The printlns should appear in the following order:

t1 open
t2 got root
t1 removed vtx
t1 readded vtx
t2 looking for verts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment