Snapshot Transactions

From NexusWiki
Jump to: navigation, search

The snapshot transaction does not guarantee that you will see the whole database as it was at the moment you started the snapshot transaction. What it does do is to guarantee that you see the whole database in a transactionally consistent state.

Only snapshot pages of tables that are required to guarantee a transactionally consistent state (in other words, only snapshots that are required so that you will never see only some changes from a transaction, but only the whole transaction or nothing of it) are kept.

As such they provide exactly the same isolation properites then a normal transaction (which is working with shared locks as long as you only read).

The moment you first read from a table in the context of a snapshot transaction, that table will become part of that snapshot transaction and you will always see that table in the state it was in at that moment.

If another transaction is committed and writes changes to a table which is part of a snapshot transaction, then the pre-commit state of all tables written to in this transaction will become part of the snapshot transaction.

So the rules are:

If you start a snapshot transaction, but never read from any table, no snapshots are being kept.

If you read from a table, snapshots will be kept from that moment on.

If another transaction writes changes to tables that you have not yet read from and does NOT touch any of the other tables that are already part of your snapshot transaction, then yes, when you get around to this table later you will see these changes.

If another transaction writes changes to a table that is already part of a snapshot transaction you will not see these changes. Also, if the same transaction writes to any table which is not yet part of the snapshot transaction, it will become part of the snapshot transaction and you will not see these changes.