Skip to content

docs: rewrite Concurrency Control as a learning guide - #9648

Open
khanaffan wants to merge 21 commits into
masterfrom
affan/concurrency-control-doc
Open

docs: rewrite Concurrency Control as a learning guide#9648
khanaffan wants to merge 21 commits into
masterfrom
affan/concurrency-control-doc

Conversation

@khanaffan

Copy link
Copy Markdown
Contributor

Summary

docs/learning/backend/ConcurrencyControl.md had drifted from the implementation — most visibly it told readers to call locks.acquireExclusiveLock / acquireSharedLock, which no longer exist on LockControl. This rewrites it as a learning document explaining how concurrency works when multiple users edit an iModel.

Every claim was verified against the current source: LockControl.ts, internal/ServerBasedLocks.ts, internal/NoLocks.ts, IModelDb.ts, Element.ts, Model.ts, ElementAspect.ts, EditTxn.ts, LocalHub.ts, and BackendHubAccess.ts.

What the doc now covers

  • Policies — locking (default) vs noLocks, and the flow that selects ServerBasedLocks vs the no-op LockControl when a BriefcaseDb is opened.
  • Editing lifecycle — pull → lock → change → save → push → release, as a sequence diagram.
  • Acquiring locks — the all-or-nothing request, and the three failure modes learners routinely conflate: LockOwnedByAnotherBriefcase (contention), PullIsRequired (stale briefcase), and LockNotHeld (local edit-time check). Includes the per-lock freshness rules for shared vs exclusive acquisition.
  • Ownership hierarchy — implicit downward locking and automatic upward shared locks on models/parents.
  • Per-operation lock table — elements, aspects, models, changeElementParent, and changeElementModel (which requires exclusive locks on the entire moved subtree).
  • Locks acquired automatically — newly created elements, owner locks, schema import, dropSchemas, profile/domain upgrade, and the exemption for indirect changes during ElementDrivesElement propagation.
  • The Schema Lock — why it locks the whole iModel, plus the Schema Sync and semantic-rebase relaxations, and the fact that upgradeSchemas only takes the lock when a data transformation is required.
  • Releasing locks — push/release/abandon semantics, and the beta Txn-level lock APIs used by undo/redo workflows.
  • Local lock tracking — the locks / txn_locks / metadata tables and the Acquired / NewElement / Discovered origins.

Conflict-resolution details are deferred to PullMerge.md rather than duplicated (the old doc's conflict table had gone stale).

Notable corrections vs the old text

Old text Reality
locks.acquireExclusiveLock(...) / acquireSharedLock(...) locks.acquireLocks({ shared, exclusive })
pullChanges does not release locks; only push/explicit release does
"obtain the Schema Lock" before every import/upgrade upgradeSchemas is optimistic, acquiring the schema lock only on DataTransformRequired; Schema Sync and semantic rebase further relax imports
Standalone optimistic conflict-resolution table Deferred to PullMerge.md, which is the authoritative description

The #acquiring-locks-on-elements anchor is preserved, since BackendHubAccess.ts and IModelError.ts doc comments link to it.

Diagrams

Adds mermaid diagrams (matching the fence/style already used in Settings.md and Workspace.md), including sequence diagrams for the edit lifecycle, schema import, and two briefcases contending for the same element.

Testing

Docs-only change. Verified all relative links and heading anchors resolve, that every ($backend)/($common) symbol referenced exists and is public, and that code fences are balanced. No rush change file — no published package is affected.

The existing ConcurrencyControl.md had drifted from the implementation:
it referenced `locks.acquireExclusiveLock`/`acquireSharedLock`, which no
longer exist on `LockControl`, and described lock/merge behavior that has
since changed.

Rewrite it as a learning-oriented document covering how concurrency works
when multiple users edit an iModel, verified against the current source:

- Locking vs `noLocks` policies, and how `ServerBasedLocks`/`NoLocks` is
  selected when a BriefcaseDb is opened.
- The pull -> lock -> change -> save -> push -> release lifecycle.
- Lock types, the model/parent ownership hierarchy, implicit downward
  locking and automatic upward shared locks.
- The per-operation lock table, including aspects, models, changeParent
  and changeModel (which requires exclusive locks on the whole subtree).
- Locks acquired automatically: newly created elements, owner locks,
  schema import, dropSchemas, profile/domain upgrade (which only takes the
  schema lock when a data transformation is required), and the exemption
  for indirect changes during change propagation.
- The Schema Lock, plus the Schema Sync and semantic-rebase variations.
- Distinguishes LockOwnedByAnotherBriefcase, PullIsRequired and
  LockNotHeld, and documents the per-lock freshness rules.
- Release/abandon semantics and the beta Txn-level lock APIs.
- How the briefcase tracks locks locally (locks/txn_locks/metadata).

Conflict-resolution details are deferred to PullMerge.md rather than
duplicated. Adds mermaid diagrams, including sequence diagrams for the
edit lifecycle, schema import, and two briefcases contending for the same
element, and links the doc from the backend learning index.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread docs/learning/backend/ConcurrencyControl.md Outdated
Comment thread docs/learning/backend/ConcurrencyControl.md Outdated
Comment thread docs/learning/backend/ConcurrencyControl.md Outdated
Comment thread docs/learning/backend/ConcurrencyControl.md Outdated
Comment thread docs/learning/backend/ConcurrencyControl.md Outdated
Comment thread docs/learning/backend/ConcurrencyControl.md
khanaffan and others added 3 commits August 24, 2026 10:32
@aruniverse

Copy link
Copy Markdown
Member

is this a rewrite of #9645

Comment thread core/backend/src/IModelDb.ts Outdated
@khanaffan
khanaffan marked this pull request as ready for review August 31, 2026 19:42
@khanaffan
khanaffan requested review from a team as code owners August 31, 2026 19:42
@mergify

mergify Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

This pull request is now in conflicts. Could you fix it @khanaffan? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

@khanaffan

Copy link
Copy Markdown
Contributor Author

is this a rewrite of #9645

Its a complete rewrite but it includes what #9645 fixed which was incorrect method names used for exclusive and shared lock.

Comment thread docs/learning/backend/ConcurrencyControl.md Outdated
Comment thread docs/learning/backend/ConcurrencyControl.md Outdated
Comment thread docs/learning/backend/ConcurrencyControl.md Outdated
Comment thread docs/learning/backend/ConcurrencyControl.md Outdated
Comment thread docs/learning/backend/ConcurrencyControl.md Outdated
Comment thread docs/learning/backend/ConcurrencyControl.md Outdated
Comment thread docs/learning/backend/ConcurrencyControl.md Outdated
Comment thread docs/learning/backend/ConcurrencyControl.md Outdated
Comment thread docs/learning/backend/ConcurrencyControl.md Outdated
Comment thread core/backend/src/test/standalone/ServerBasedLocks.test.ts Outdated
khanaffan and others added 10 commits September 4, 2026 12:20
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Bill Goehrig <33036725+wgoehrig@users.noreply.github.com>
Co-authored-by: Bill Goehrig <33036725+wgoehrig@users.noreply.github.com>
Co-authored-by: Bill Goehrig <33036725+wgoehrig@users.noreply.github.com>
Co-authored-by: Bill Goehrig <33036725+wgoehrig@users.noreply.github.com>
Co-authored-by: Bill Goehrig <33036725+wgoehrig@users.noreply.github.com>
Co-authored-by: Bill Goehrig <33036725+wgoehrig@users.noreply.github.com>
Co-authored-by: Bill Goehrig <33036725+wgoehrig@users.noreply.github.com>
Co-authored-by: Bill Goehrig <33036725+wgoehrig@users.noreply.github.com>
Co-authored-by: Bill Goehrig <33036725+wgoehrig@users.noreply.github.com>
khanaffan and others added 7 commits September 8, 2026 10:36
Co-authored-by: Bill Goehrig <33036725+wgoehrig@users.noreply.github.com>
Co-authored-by: Bill Goehrig <33036725+wgoehrig@users.noreply.github.com>
Co-authored-by: Bill Goehrig <33036725+wgoehrig@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants