Skip to content

Add file-based transaction support and enhance revert functionality to support large size and number of changesets#9322

Open
khanaffan wants to merge 11 commits into
masterfrom
affank/file-based-txns
Open

Add file-based transaction support and enhance revert functionality to support large size and number of changesets#9322
khanaffan wants to merge 11 commits into
masterfrom
affank/file-based-txns

Conversation

@khanaffan
Copy link
Copy Markdown
Contributor

imodel-native: iTwin/imodel-native#1438

Issue

RevertTimelineChanges could not handle large amounts of changes or very large changesets. The limitation is SQLite's inability to store blobs greater than 2 GB in the dgn_Txn table. Reverting anything exceeding 2 GB resulted in a failure when SQLite could not allocate the blob.

Solution

Add support for file-based transaction storage. When enabled, changeset data is written to individual .txn files on disk (LZMA-compressed) rather than stored as blobs in dgn_Txns. Only a small header (signature + uncompressed size + SHA1 checksum) is stored in the Change column.

This is activated automatically when calling RevertTimelineChanges, which enables the fileBasedTxns briefcase-local property and saves each reverted changeset individually with SaveChanges("reverted changeset ").

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances backend revert functionality to support very large changesets by leveraging native file-based transaction storage, and adds new API surface to control/inspect file-based transaction mode while improving revert cleanup behavior.

Changes:

  • Add internal BriefcaseDb APIs to enable/disable and query file-based transaction mode (fileBasedTxns local value).
  • Extend revertAndPushChanges to restore the pre-call file-based txn setting and add configurable failure cleanup via inCaseOfFailure.
  • Add an integration test that reverts schema+data changesets and verifies the resulting state across two briefcases.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
full-stack-tests/backend/src/integration/TxnManager.test.ts Adds an integration test covering revertAndPushChanges across two briefcases and validates reverted schema/data state.
core/backend/src/IModelDb.ts Adds file-based txn toggles and updates revertAndPushChanges cleanup/restore logic and failure handling.
core/backend/src/BriefcaseManager.ts Extends RevertChangesArgs with inCaseOfFailure to control cleanup strategy on failure.
common/changes/@itwin/core-backend/affank-file-based-txns_2026-05-20-15-09.json Changelog entry for the revert robustness improvement.
common/api/core-backend.api.md Updates extracted API to include new internal members and the updated RevertChangesArgs shape.

Comment thread core/backend/src/IModelDb.ts
Comment thread full-stack-tests/backend/src/integration/TxnManager.test.ts Outdated
Comment thread core/backend/src/IModelDb.ts Outdated
Comment thread core/backend/src/IModelDb.ts Outdated
Comment thread core/backend/src/BriefcaseManager.ts Outdated
Comment thread core/backend/src/BriefcaseManager.ts Outdated
Comment thread core/backend/src/IModelDb.ts
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
khanaffan and others added 2 commits May 20, 2026 11:53
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread full-stack-tests/backend/src/integration/TxnManager.test.ts Fixed
Comment thread full-stack-tests/backend/src/integration/TxnManager.test.ts Fixed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread full-stack-tests/backend/src/integration/TxnManager.test.ts Outdated
Comment thread core/backend/src/IModelDb.ts Outdated
Comment thread core/backend/src/IModelDb.ts
Comment thread core/backend/src/IModelDb.ts Outdated
throw err;
} finally {
this[_nativeDb].abandonChanges();
if (!wasFileBasedTxnsEnabled && !nativeDb.hasPendingTxns() && !nativeDb.hasUnsavedChanges())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!wasFileBasedTxnsEnabled && !nativeDb.hasPendingTxns() && !nativeDb.hasUnsavedChanges())
if (!wasFileBasedTxnsEnabled && !nativeDb.hasPendingTxns() && !nativeDb.hasUnsavedChanges() && this.isOpen)

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.

5 participants