Open topic with navigation
Commit Strategies
.NET:
objectContainer.Commit();
Objects created or instantiated within one db4o transaction
are written to a temporary transaction area in the database file and are only
durable after the transaction is committed.
Transactions are committed implicitly when the
object container is closed.
.NET:
objectContainer.Close();
Advantage
Committing a transaction makes sure that all the changes are
effectively written to a storage location. Commit uses a special sequence of
actions, which ensures transactions. The following operations are done
during commit:
- flushing
modified class indexes
- flushing
changes of in-memory field indexes to file-based indexes
- writing
all intended pointer changes as a "pre-log" to the file
- writing
all pointer changes
- reorganizing
the free-space system
- deleting
the "pre log"
Effect
Commit is a costly operation as it includes disk writes and
flushes of the operating system disk cache. Too many commits can decrease your
application's performance. On the other hand long transaction increases the
risk of loosing your data in case of a system or a hardware failure.
Best Strategies
- You should call commit() at the end of every logical
operation, at a point where you want to make sure that all the changes done get
permanently stored to the database.
- If you are doing a bulk insert of many (say >100 000)
objects, it is a good idea to commit after every few thousand inserts,
depending on the complexity of your objects. If you don't do that, there is not
only a risk of losing the objects in a case of a failure, but also a good
chance of running out of memory and slowing down the operations due to memory
flushes to disk. The exact amount of inserts that can be done safely and
effectively within one transaction should be calculated for the concrete system
and will depend on available system resources and size and complexity of
objects.
- Don't forget to close db4o object container before the
application exits to make sure that all the changes will be saved to disk
during implicit commit.