Hi, Great question. It took some discussion to come up with a good answer. Honestly I'm not sure this answer is as good an answer as this question would deserve, but it is a summary of the discussions I've been involved with off-list and that I am now moving to the list. Combine this with the holidays and you might get to a point where it's understandable that the response took so long.
There are a couple of reasons why read operations need to be performed in transactions. * Isolation. Transactions (could be used to) provide isolation between a reading operation and a writing operation in a concurrent thread. It does that to some degree today, but only by keeping the uncommitted changes of the writing transaction isolated from the rest of the world. We could add isolation from the readers perspective as well, ensuring that a certain value doesn't change within the transaction once it's read, we've had that discussion before and the conclusion then was that this level of isolation would not be very useful, and the cases where it could be useful does not outweigh the added complexity to the code. * API consistency. It's easier to declare that "all operations need to be performed within a transaction" than to go into details about which operations are read operations and which operations are write operations, thus require transactions. It might not be so difficult on the Neo4j-layer, but in applications using Neo4j it could be harder to tell whether an operation is purely read or if it has writing side effects, such as lazily initializing data structures. * It simplifies the internal implementation. This is usually a bad reason, but if it improves performance it might be acceptable. This was the case in earlier versions, but with more recent versions the need for transactions for read operations is almost completely removed internally. The contract of requiring a transaction is kept for historical reasons and the previous points. Given the fact that the need for open transactions for read operations is less than it used to be, and the fact that a number of people seem to be questioning the fact that transactions are required to read from Neo4j, perhaps it's time to change this. We'll have a meeting with the dev team next week to discuss this. In the meantime it would be great to get some input from all of you guys on the list. Do you think we should remove the requirement for transactions for read operations? Why/Why not? Another idea would be to start off "lightly" with the specific case that spurred this thread, and let traversers handle transactions automatically internally. This would mean that you could create and start a traversal without opening any transactions. You could even iterate through the entire resulting set of nodes, but not perform any actions on them (for that you would need a transaction in this case). This would give the user more fine grained control over when transactions can be opened and closed for traversals. Would this be enough, or would it be "too complicated", a rule that transactions are not needed for read operations, only for writing is definitely much simpler. Happy Hacking, and a Happy new year! /Tobias On Mon, Dec 28, 2009 at 8:05 PM, Rick Bullotta < [email protected]> wrote: > I had the same question a couple weeks ago, Laurent. It still isn't clear > to me why traversals/reads need to be wrapped in a transaction. > > -----Original Message----- > From: [email protected] [mailto:[email protected]] > On > Behalf Of Laurent Laborde > Sent: Monday, December 28, 2009 11:29 AM > To: Neo user discussions > Subject: Re: [Neo] Transaction for traverser ? > > > > > tx = neo.beginTx(); > > for(Node node : traverser) { > > //Some setProperty stuff. > > } > > tx.success(); tx.finish(); > > Exception in thread "main" java.lang.OutOfMemoryError: Java heap space > With 512m ... Bleh :( > > -- > Laurent "ker2x" Laborde > Sysadmin & DBA at http://www.over-blog.com/ > _______________________________________________ > Neo mailing list > [email protected] > https://lists.neo4j.org/mailman/listinfo/user > > _______________________________________________ > Neo mailing list > [email protected] > https://lists.neo4j.org/mailman/listinfo/user > -- Tobias Ivarsson <[email protected]> Hacker, Neo Technology www.neotechnology.com Cellphone: +46 706 534857 _______________________________________________ Neo mailing list [email protected] https://lists.neo4j.org/mailman/listinfo/user

