Wrapping multiple database queries in one transaction

378 Views Asked by At

I am using Neo4j in embedded mode in my java application.

Before upgrading to Neo4j 2.x, I was wrapping multiple db operations in one transaction. After upgrading to 2.x, I am explicitly performing each db operation in one separate transaction (this is the canonical way, as documentation also suggests). However, the speed of creating database has severely decreased.

Is there a way, I can wrap multiple db operations (both insert and query) in one transaction? I do understand that in case of rollback I will have to deal with lost CRUD operations.

Please also pour in general recommendations to scale a database that will eventually have over 600 million nodes and relationships and over 2 billion annotations.

1

There are 1 best solutions below

0
On

The requirement for neo4j is that all operations have to be within a transaction. There is no requirement that each operation has to be in its own transaction, and doing that would be a bad idea both for performance reasons, and also because this would make it impossible to group multiple logical operations under one transaction.

I think the solution here is to not wrap each operation in one transaction, and to do it exactly as you did prior to upgrading.

This may be a misunderstanding; in the documentation, they show example operations wrapped in transactions, but it doesn't say anywhere that 1 operation = 1 transaction. In fact, you can do as many different read/write operations within one transaction as you like. The requirement is that all operations must be within a transaction.