This project is read-only.

NDatabase Transaction

NDatabase uses transactions to guarantee database integrity (ACID properties).

When an NDatabase database is opened, a session (NDatabase2.Odb.Core.Transaction.ISession) is automatically created. The session contains a special object, a NDatabase2.Odb.Core.Transaction.ITransaction.

The ITransaction instance manage all the data and behavior of the current transaction.

When executing an operation (insert, update, delete, …) that modifies the database, some parts of the operation can be directly written to the database file (see Buffers for IO performance) other can not.


When inserting a new object, the object can be written directly to the database but references to this object can not. In this case, references are written in the transaction (as a list of NDatabase2.Odb.Core.Transaction.IWriteAction).

So basically, NDatabase is being optimistic and write almost everything to the database. Only pointers and data from update and delete are written in the Transaction File. The writing in Transaction file begins as soon as the implicit transaction is created by NDatabase. On commit, the transaction content is applied to main database file.

The Transaction keep a list of IWriteAction (that contain data that can not be written directly) in memory and in a special file (extension .transaction). On Commit, if all Write Actions are on memory, NDatabase simply apply them to the database file. If not, NDatabase first loads them from the transaction file and then apply them to the database file. After commit, the transaction file is deleted. On failure, the transaction file remains on the disk and already written objects remain in the NDatabase database file but without any reference to them so they do not exist for the database.

Commit Process

The database can be divided into 2 different zones:
  • Committed Zone - the committed zone contains all committed work.
  • Uncommitted (Unconnected) zone - uncommitted zone contains all the work that has not been committed yet,work of open transactions. All new objects and modifications must be created in the uncommitted zone.

Uncommitted zone can be divided in 2 sub-one:
  • Unconnected Zone - new objects zone.
  • Connected Zone - modifications zone.

The Unconnected Zone contains all the new objects without any link (pointers) from the committed zone. All new objects are actually written in the database file and will stay in the database in case of rollback but they will be unreachable so it will not bring inconsistency!

The Connected Zone contains Write Actions (that represents object updates and deletes) that will be applied to the committed zone when committed.

When committing

  • Uncommitted Transaction Zone - all first new objects must be connected to last committed objects (previous object OID and next object OID). This must be done for all new objects types.
  • Connected TransactionZone - WriteActions must be applied to the committed zone.

The commit operation must use a Storage Engine Scope Mutex.

Last edited Oct 13, 2012 at 7:39 PM by jacek, version 6


No comments yet.