Skip to content

Add TransactionOptions::setAtSnapshotNumber() and Transaction::getSnapshotNumber() - #75

Open
fdcastel wants to merge 1 commit into
asfernandes:mainfrom
fdcastel:transaction-snapshot-number
Open

fdcastel wants to merge 1 commit into
asfernandes:mainfrom
fdcastel:transaction-snapshot-number

Conversation

@fdcastel

Copy link
Copy Markdown
Contributor

Addresses item 1 of #74 (feedback).

Adds support for shared snapshots (Firebird 4.0+), so that several transactions, in the same or in different attachments, can read the same database state. For example, a scan split across N connections stays consistent while other transactions write to the table.

Changes

  • TransactionOptions::setAtSnapshotNumber(std::uint64_t) / getAtSnapshotNumber(): adds isc_tpb_at_snapshot_number to the TPB. Requires the SNAPSHOT isolation level, and the transaction that owns the snapshot must still be active.
  • Transaction::getSnapshotNumber(): reads fb_info_tra_snapshot_number through ITransaction::getInfo(). The info response is parsed the same way as in Blob::getLength(). It throws FbCppException if the server doesn't return the item (Firebird < 4.0).

Tests

TransactionSuite/atSnapshotNumber:

  1. A SNAPSHOT transaction on attachment 1 reads its snapshot number.
  2. Another transaction then inserts and commits a row.
  3. A transaction on a second attachment, started at that snapshot number, reports the same snapshot number and still sees only the first row, the same as the original transaction.
  4. A fresh SNAPSHOT transaction gets a larger number and sees both rows.

Full suite: 349 test cases pass (Windows, MSVC, Firebird 5.0.3 server).

…pshotNumber()

Allows starting transactions (in the same or other attachments) that share the same database snapshot, using isc_tpb_at_snapshot_number and fb_info_tra_snapshot_number (Firebird 4.0+).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant