@itwin/core-backend 5.9.0-dev.7 → 5.9.0-dev.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/BackendHubAccess.d.ts +38 -0
- package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
- package/lib/cjs/BackendHubAccess.js.map +1 -1
- package/lib/cjs/IModelDb.js +1 -1
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/IpcHost.d.ts.map +1 -1
- package/lib/cjs/IpcHost.js +13 -4
- package/lib/cjs/IpcHost.js.map +1 -1
- package/lib/cjs/LockControl.d.ts +85 -1
- package/lib/cjs/LockControl.d.ts.map +1 -1
- package/lib/cjs/LockControl.js.map +1 -1
- package/lib/cjs/TxnManager.d.ts +100 -4
- package/lib/cjs/TxnManager.d.ts.map +1 -1
- package/lib/cjs/TxnManager.js +171 -8
- package/lib/cjs/TxnManager.js.map +1 -1
- package/lib/cjs/internal/HubMock.d.ts +2 -0
- package/lib/cjs/internal/HubMock.d.ts.map +1 -1
- package/lib/cjs/internal/HubMock.js +7 -0
- package/lib/cjs/internal/HubMock.js.map +1 -1
- package/lib/cjs/internal/NoLocks.d.ts.map +1 -1
- package/lib/cjs/internal/NoLocks.js +6 -0
- package/lib/cjs/internal/NoLocks.js.map +1 -1
- package/lib/cjs/internal/ServerBasedLocks.d.ts +12 -0
- package/lib/cjs/internal/ServerBasedLocks.d.ts.map +1 -1
- package/lib/cjs/internal/ServerBasedLocks.js +285 -4
- package/lib/cjs/internal/ServerBasedLocks.js.map +1 -1
- package/lib/esm/BackendHubAccess.d.ts +38 -0
- package/lib/esm/BackendHubAccess.d.ts.map +1 -1
- package/lib/esm/BackendHubAccess.js.map +1 -1
- package/lib/esm/IModelDb.js +1 -1
- package/lib/esm/IModelDb.js.map +1 -1
- package/lib/esm/IpcHost.d.ts.map +1 -1
- package/lib/esm/IpcHost.js +13 -4
- package/lib/esm/IpcHost.js.map +1 -1
- package/lib/esm/LockControl.d.ts +85 -1
- package/lib/esm/LockControl.d.ts.map +1 -1
- package/lib/esm/LockControl.js.map +1 -1
- package/lib/esm/TxnManager.d.ts +100 -4
- package/lib/esm/TxnManager.d.ts.map +1 -1
- package/lib/esm/TxnManager.js +171 -8
- package/lib/esm/TxnManager.js.map +1 -1
- package/lib/esm/internal/HubMock.d.ts +2 -0
- package/lib/esm/internal/HubMock.d.ts.map +1 -1
- package/lib/esm/internal/HubMock.js +7 -0
- package/lib/esm/internal/HubMock.js.map +1 -1
- package/lib/esm/internal/NoLocks.d.ts.map +1 -1
- package/lib/esm/internal/NoLocks.js +6 -0
- package/lib/esm/internal/NoLocks.js.map +1 -1
- package/lib/esm/internal/ServerBasedLocks.d.ts +12 -0
- package/lib/esm/internal/ServerBasedLocks.d.ts.map +1 -1
- package/lib/esm/internal/ServerBasedLocks.js +286 -5
- package/lib/esm/internal/ServerBasedLocks.js.map +1 -1
- package/lib/esm/test/standalone/ServerBasedLocks.test.js +907 -3
- package/lib/esm/test/standalone/ServerBasedLocks.test.js.map +1 -1
- package/package.json +12 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerBasedLocks.js","sourceRoot":"","sources":["../../../src/internal/ServerBasedLocks.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AA8N/F,wDAEC;AA9ND;;GAEG;AAEH,sDAAkG;AAClG,oDAAoE;AAIpE,8CAA2C;AAC3C,0CAAuC;AACvC,uCAA2H;AAmB3H,MAAa,gBAAgB;IACX,CAAC,mCAAyB,CAAC,GAAG,SAAS,CAAC;IAExD,IAAW,aAAa,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;IACxB,MAAM,GAAG,IAAI,mBAAQ,EAAE,CAAC;IACxB,SAAS,CAAc;IAE1C,YAAmB,MAAmB;QACpC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC;QACxB,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,mBAAS,CAAC,CAAC,mBAAmB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,CAAC,EAAE,CAAC;oBAC9B,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,uBAAS,CAAC,SAAS,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,wGAAwG;IACjG,CAAC,4BAAkB,CAAC,CAAC,EAAc;QACxC,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,uBAAS,CAAC,SAAS,gCAAwB,CAAC;QAChE,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAED,yDAAyD;IACzD,IAAY,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAElF,uGAAuG;IAChG,kBAAkB,CAAC,EAAc,EAAE,IAAY,EAAE,SAAiB;QACvE,IAAI,IAAI,CAAC,iBAAiB,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;YACxD,MAAM,IAAI,yBAAW,CAAC,2BAAY,CAAC,WAAW,EAAE,8BAA8B,IAAI,QAAQ,SAAS,QAAQ,EAAE,GAAG,CAAC,CAAC;IACtH,CAAC;IAED,kGAAkG;IAC3F,eAAe,CAAC,EAAc,EAAE,IAAY,EAAE,SAAiB;QACpE,IAAI,IAAI,CAAC,iBAAiB,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC;YACrD,MAAM,IAAI,yBAAW,CAAC,2BAAY,CAAC,WAAW,EAAE,2BAA2B,IAAI,QAAQ,SAAS,QAAQ,EAAE,GAAG,CAAC,CAAC;IACnH,CAAC;CAEF;AA5LD,4CA4LC;AAED,SAAgB,sBAAsB,CAAC,MAAmB;IACxD,OAAO,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\n/** @packageDocumentation\n * @module iModels\n */\n\nimport { DbResult, Id64, Id64Arg, Id64String, IModelStatus, OpenMode } from \"@itwin/core-bentley\";\nimport { IModel, IModelError, LockState } from \"@itwin/core-common\";\nimport { LockMap } from \"../BackendHubAccess\";\nimport { BriefcaseDb } from \"../IModelDb\";\nimport { LockControl } from \"../LockControl\";\nimport { IModelHost } from \"../IModelHost\";\nimport { SQLiteDb } from \"../SQLiteDb\";\nimport { _close, _elementWasCreated, _hubAccess, _implementationProhibited, _nativeDb, _releaseAllLocks } from \"./Symbols\";\n\n/**\n * Both the Model and Parent of an element are considered \"owners\" of their member elements. That means:\n * 1) they must hold at least a shared lock before an exclusive lock can be acquired for their members\n * 2) if they hold an exclusive lock, then all of their members are exclusively locked implicitly.\n */\ninterface ElementOwners {\n readonly modelId: Id64String;\n readonly parentId: Id64String | undefined;\n}\n\n// eslint-disable-next-line no-restricted-syntax\nconst enum LockOrigin {\n Acquired = 0,\n NewElement = 1,\n Discovered = 2,\n}\n\nexport class ServerBasedLocks implements LockControl {\n public readonly [_implementationProhibited] = undefined;\n\n public get isServerBased() { return true; }\n protected readonly lockDb = new SQLiteDb();\n protected readonly briefcase: BriefcaseDb;\n\n public constructor(iModel: BriefcaseDb) {\n this.briefcase = iModel;\n const dbName = `${iModel[_nativeDb].getTempFileBaseName()}-locks`;\n try {\n this.lockDb.openDb(dbName, OpenMode.ReadWrite);\n } catch {\n this.lockDb.createDb(dbName);\n this.lockDb.executeSQL(\"CREATE TABLE locks(id INTEGER PRIMARY KEY NOT NULL,state INTEGER NOT NULL,origin INTEGER)\");\n this.lockDb.saveChanges();\n }\n }\n\n public [_close]() {\n if (this.lockDb.isOpen)\n this.lockDb.closeDb();\n }\n\n private getOwners(id: Id64String): ElementOwners {\n return this.briefcase.withPreparedSqliteStatement(\"SELECT ModelId,ParentId FROM bis_Element WHERE id=?\", (stmt) => {\n stmt.bindId(1, id);\n const rc = stmt.step();\n if (DbResult.BE_SQLITE_ROW !== rc)\n throw new IModelError(rc, `element ${id} not found`);\n\n return { modelId: stmt.getValueId(0), parentId: stmt.getValueId(1) };\n });\n }\n\n private getLockState(id?: Id64String): LockState | undefined {\n return (id === undefined || !Id64.isValid(id)) ? undefined : this.lockDb.withPreparedSqliteStatement(\"SELECT state FROM locks WHERE id=?\", (stmt) => {\n stmt.bindId(1, id);\n return (DbResult.BE_SQLITE_ROW === stmt.step()) ? stmt.getValueInteger(0) : undefined;\n });\n }\n\n /** Clear the cache of locally held locks.\n * Note: does *not* release locks from server.\n */\n private clearAllLocks() {\n this.lockDb.executeSQL(\"DELETE FROM locks\");\n this.lockDb.saveChanges();\n }\n\n /** only for tests */\n public getLockCount(state: LockState): number {\n return this.lockDb.withSqliteStatement(\"SELECT count(*) FROM locks WHERE state=?\", (stmt) => {\n stmt.bindInteger(1, state);\n stmt.step();\n return stmt.getValueInteger(0);\n });\n }\n\n public async [_releaseAllLocks](): Promise<void> {\n await IModelHost[_hubAccess].releaseAllLocks(this.briefcase); // throws if unsuccessful\n this.clearAllLocks();\n }\n\n public async releaseAllLocks(): Promise<void> {\n if (this.briefcase.txns.hasLocalChanges) {\n throw new Error(\"Locks cannot be released while the briefcase contains local changes\");\n }\n\n return this[_releaseAllLocks]();\n }\n\n private insertLock(id: Id64String, state: LockState, origin: LockOrigin): true {\n this.lockDb.withPreparedSqliteStatement(\"INSERT INTO locks(id,state,origin) VALUES (?,?,?) ON CONFLICT(id) DO UPDATE SET state=excluded.state,origin=excluded.origin\", (stmt) => {\n stmt.bindId(1, id);\n stmt.bindInteger(2, state);\n stmt.bindInteger(3, origin);\n const rc = stmt.step();\n if (DbResult.BE_SQLITE_DONE !== rc)\n throw new IModelError(rc, \"can't insert lock into database\");\n });\n return true;\n }\n\n private ownerHoldsExclusiveLock(id: Id64String | undefined): boolean {\n if (id === undefined || id === IModel.rootSubjectId)\n return false; // has no owners\n\n const { modelId, parentId } = this.getOwners(id);\n if (this.getLockState(modelId) === LockState.Exclusive || this.getLockState(parentId) === LockState.Exclusive)\n return true;\n\n // see if this model is exclusively locked by one of its owners. If so, save that fact on modelId so future tests won't have to descend.\n if (this.ownerHoldsExclusiveLock(modelId))\n return this.insertLock(modelId, LockState.Exclusive, LockOrigin.Discovered);\n\n // see if the parent is exclusively locked by one of its owners. If so, save that fact on parentId so future tests won't have to descend.\n return this.ownerHoldsExclusiveLock(parentId) ? this.insertLock(parentId!, LockState.Exclusive, LockOrigin.Discovered) : false; // eslint-disable-line @typescript-eslint/no-non-null-assertion\n }\n\n /** Determine whether an the exclusive lock is already held by an element (or one of its owners) */\n public holdsExclusiveLock(id: Id64String): boolean {\n // see if we hold the exclusive lock. or if one of the element's owners is exclusively locked (recursively)\n return this.getLockState(id) === LockState.Exclusive || this.ownerHoldsExclusiveLock(id);\n }\n\n public holdsSharedLock(id: Id64String): boolean {\n const state = this.getLockState(id);\n // see if we hold shared or exclusive lock, or if an owner has exclusive lock. If so we implicitly have shared lock, but owner holding shared lock doesn't help.\n return (state === LockState.Shared || state === LockState.Exclusive) || this.ownerHoldsExclusiveLock(id);\n }\n\n /** if the shared lock on the element supplied is not already held, add it to the set of shared locks required. Then, check owners. */\n private addSharedLock(id: Id64String | undefined, locks: Set<Id64String>) {\n // if the id is not valid, or of the lock is already in the set, or if we already hold a shared lock, we're done\n // Note: if we hold a shared lock, it is guaranteed that we also hold all required shared locks on owners.\n if (id === undefined || !Id64.isValid(id) || locks.has(id) || this.holdsSharedLock(id))\n return;\n\n locks.add(id); // add to set of needed shared locks\n this.addOwnerSharedLocks(id, locks); // check parent models and groups\n }\n\n /** add owners (recursively) of an element to a list of required shared locks, if not already held. */\n private addOwnerSharedLocks(id: Id64String, locks: Set<Id64String>) {\n const el = this.getOwners(id);\n this.addSharedLock(el.parentId, locks); // if this element is in a group\n this.addSharedLock(el.modelId, locks); // check its model\n }\n\n /** attempt to acquire all necessary locks for a set of elements */\n private async acquireAllLocks(locks: LockMap) {\n if (locks.size === 0) // no locks are required.\n return;\n\n const sharedLocks = new Set<Id64String>();\n for (const lock of locks)\n this.addOwnerSharedLocks(lock[0], sharedLocks);\n\n for (const shared of sharedLocks) {\n if (!locks.has(shared)) // we may already be asking for exclusive lock\n locks.set(shared, LockState.Shared);\n }\n\n await IModelHost[_hubAccess].acquireLocks(this.briefcase, locks); // throws if unsuccessful\n for (const lock of locks)\n this.insertLock(lock[0], lock[1], LockOrigin.Acquired);\n this.lockDb.saveChanges();\n }\n\n public async acquireLocks(arg: { shared?: Id64Arg, exclusive?: Id64Arg }): Promise<void> {\n const locks = new Map<Id64String, LockState>();\n if (arg.shared) {\n for (const id of Id64.iterable(arg.shared)) {\n if (!this.holdsSharedLock(id))\n locks.set(id, LockState.Shared);\n }\n }\n if (arg.exclusive) {\n for (const id of Id64.iterable(arg.exclusive)) {\n if (!this.holdsExclusiveLock(id))\n locks.set(id, LockState.Exclusive);\n }\n }\n return this.acquireAllLocks(locks);\n }\n\n /** When an element is newly created in a session, we hold the lock on it implicitly. Save that fact. */\n public [_elementWasCreated](id: Id64String) {\n this.insertLock(id, LockState.Exclusive, LockOrigin.NewElement);\n this.lockDb.saveChanges();\n }\n\n /** locks are not necessary during change propagation. */\n private get _locksAreRequired() { return !this.briefcase.txns.isIndirectChanges; }\n\n /** throw if locks are currently required and the exclusive lock is not held on the supplied element */\n public checkExclusiveLock(id: Id64String, type: string, operation: string) {\n if (this._locksAreRequired && !this.holdsExclusiveLock(id))\n throw new IModelError(IModelStatus.LockNotHeld, `exclusive lock not held on ${type} for ${operation} (id=${id})`);\n }\n\n /** throw if locks are currently required and a shared lock is not held on the supplied element */\n public checkSharedLock(id: Id64String, type: string, operation: string) {\n if (this._locksAreRequired && !this.holdsSharedLock(id))\n throw new IModelError(IModelStatus.LockNotHeld, `shared lock not held on ${type} for ${operation} (id=${id})`);\n }\n\n}\n\nexport function createServerBasedLocks(iModel: BriefcaseDb): LockControl {\n return new ServerBasedLocks(iModel);\n}\n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,iBAAiB,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC;YACrD,MAAM,IAAI,yBAAW,CAAC,2BAAY,CAAC,WAAW,EAAE,2BAA2B,IAAI,QAAQ,SAAS,QAAQ,EAAE,GAAG,CAAC,CAAC;IACnH,CAAC;CAEF;AAngBD,4CAmgBC;AAED,SAAgB,sBAAsB,CAAC,MAAmB;IACxD,OAAO,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\n/** @packageDocumentation\n * @module iModels\n */\n\nimport { DbResult, Id64, Id64Arg, Id64String, IModelStatus, OpenMode } from \"@itwin/core-bentley\";\nimport { IModel, IModelError, LockState, ServerBasedLocksError } from \"@itwin/core-common\";\nimport { LockMap } from \"../BackendHubAccess\";\nimport { BriefcaseDb } from \"../IModelDb\";\nimport { LockControl } from \"../LockControl\";\nimport { IModelHost } from \"../IModelHost\";\nimport { SQLiteDb } from \"../SQLiteDb\";\nimport { _close, _elementWasCreated, _hubAccess, _implementationProhibited, _nativeDb, _releaseAllLocks } from \"./Symbols\";\n\n/**\n * Both the Model and Parent of an element are considered \"owners\" of their member elements. That means:\n * 1) they must hold at least a shared lock before an exclusive lock can be acquired for their members\n * 2) if they hold an exclusive lock, then all of their members are exclusively locked implicitly.\n */\ninterface ElementOwners {\n readonly modelId: Id64String;\n readonly parentId: Id64String | undefined;\n}\n\n// eslint-disable-next-line no-restricted-syntax\nconst enum LockOrigin {\n Acquired = 0,\n NewElement = 1,\n Discovered = 2,\n}\n\nexport class ServerBasedLocks implements LockControl {\n public readonly [_implementationProhibited] = undefined;\n\n public get isServerBased() { return true; }\n protected readonly lockDb = new SQLiteDb();\n protected readonly briefcase: BriefcaseDb;\n private _removeOnCommitListener: () => void;\n private readonly _unsavedChangesTxnId = \"0x7FFFFFFFFFFFFFFF\"; // a placeholder txn id for locks acquired in the current unsaved Txn\n\n public constructor(iModel: BriefcaseDb) {\n this.briefcase = iModel;\n const dbName = `${iModel[_nativeDb].getTempFileBaseName()}-locks`;\n\n try {\n this.lockDb.openDb(dbName, OpenMode.ReadWrite);\n } catch {\n this.lockDb.createDb(dbName);\n }\n\n // Tracks the locks that are actively held.\n this.lockDb.executeSQL(\"CREATE TABLE IF NOT EXISTS locks(id INTEGER PRIMARY KEY NOT NULL,state INTEGER NOT NULL,origin INTEGER)\");\n // Tracks the locks that are required by each Txn. They may or may not currently be held.\n this.lockDb.executeSQL(`\n CREATE TABLE IF NOT EXISTS txn_locks(\n txnId INTEGER NOT NULL,\n elementId INTEGER NOT NULL,\n state INTEGER NOT NULL,\n origin INTEGER NOT NULL,\n abandoned BOOLEAN NOT NULL,\n PRIMARY KEY (txnId, elementId))`);\n this.lockDb.saveChanges();\n\n this._removeOnCommitListener = this.briefcase.txns.onCommit.addListener(() => {\n const committedTxnId = this.briefcase.txns.queryPreviousTxnId(this.briefcase.txns.getCurrentTxnId())\n\n // With this commit, any reversed txns with the committed txn's ID or greater are no longer reinstatable,\n // so clear out the record of their locks. If the locks are still held, sorry, it's too late!\n this.clearTxnLockRecords(committedTxnId);\n\n // All of the \"current\" changes are now part of a real txn, so update the txn id accordingly.\n this.lockDb.withPreparedSqliteStatement(\"UPDATE txn_locks SET txnId=? WHERE txnId=?\", (stmt) => {\n stmt.bindId(1, committedTxnId);\n stmt.bindId(2, this._unsavedChangesTxnId);\n const rc = stmt.step();\n if (DbResult.BE_SQLITE_DONE !== rc)\n ServerBasedLocksError.throwError(\"lock-database-problem\", `can't update locks database with txn ID of unsaved changes txn upon saving (error code ${rc})`);\n });\n\n this.lockDb.saveChanges();\n });\n }\n\n public [_close]() {\n this._removeOnCommitListener();\n\n if (this.lockDb.isOpen)\n this.lockDb.closeDb();\n }\n\n private getOwners(id: Id64String): ElementOwners {\n return this.briefcase.withPreparedSqliteStatement(\"SELECT ModelId,ParentId FROM bis_Element WHERE id=?\", (stmt) => {\n stmt.bindId(1, id);\n const rc = stmt.step();\n if (DbResult.BE_SQLITE_ROW !== rc)\n throw new IModelError(rc, `element ${id} not found`);\n\n return { modelId: stmt.getValueId(0), parentId: stmt.getValueId(1) };\n });\n }\n\n private getLockState(id?: Id64String): LockState | undefined {\n return (id === undefined || !Id64.isValid(id)) ? undefined : this.lockDb.withPreparedSqliteStatement(\"SELECT state FROM locks WHERE id=?\", (stmt) => {\n stmt.bindId(1, id);\n return (DbResult.BE_SQLITE_ROW === stmt.step()) ? stmt.getValueInteger(0) : undefined;\n });\n }\n\n /** Clear the cache of locally held locks.\n * Note: does *not* release locks from server.\n */\n private clearAllLocks() {\n this.lockDb.executeSQL(\"DELETE FROM locks\");\n this.lockDb.executeSQL(\"DELETE FROM txn_locks\");\n this.lockDb.saveChanges();\n }\n\n /** only for tests */\n public getLockCount(state: LockState): number {\n return this.lockDb.withSqliteStatement(\"SELECT count(*) FROM locks WHERE state=?\", (stmt) => {\n stmt.bindInteger(1, state);\n stmt.step();\n return stmt.getValueInteger(0);\n });\n }\n\n public async [_releaseAllLocks](): Promise<void> {\n await IModelHost[_hubAccess].releaseAllLocks(this.briefcase); // throws if unsuccessful\n this.clearAllLocks();\n }\n\n public async releaseAllLocks(): Promise<void> {\n if (this.briefcase.txns.hasLocalChanges) {\n ServerBasedLocksError.throwError(\"has-unsaved-changes\", \"Locks cannot be released while the briefcase contains local changes\");\n }\n\n return this[_releaseAllLocks]();\n }\n\n public async abandonAllLocks(): Promise<void> {\n if (this.briefcase.txns.hasLocalChanges) {\n ServerBasedLocksError.throwError(\"has-unsaved-changes\", \"Locks cannot be abandoned while the briefcase contains local changes\");\n }\n\n if (IModelHost[_hubAccess].abandonAllLocks === undefined) {\n // If the IModelHub doesn't support an explicit abandon, call release with a blank changeset to indicate\n // that locks should be released without updating the changeset associated with the locks.\n await IModelHost[_hubAccess].releaseAllLocks({\n iModelId: this.briefcase.iModelId,\n briefcaseId: this.briefcase.briefcaseId,\n changeset: { id: \"\", index: 0 }\n });\n } else {\n await IModelHost[_hubAccess].abandonAllLocks(this.briefcase);\n }\n\n this.clearAllLocks();\n }\n\n private insertLock(id: Id64String, state: LockState, origin: LockOrigin): true {\n this.lockDb.withPreparedSqliteStatement(\"INSERT INTO locks(id,state,origin) VALUES (?,?,?) ON CONFLICT(id) DO UPDATE SET state=excluded.state,origin=excluded.origin\", (stmt) => {\n stmt.bindId(1, id);\n stmt.bindInteger(2, state);\n stmt.bindInteger(3, origin);\n const rc = stmt.step();\n if (DbResult.BE_SQLITE_DONE !== rc)\n throw new IModelError(rc, \"can't insert lock into database\");\n });\n\n return true;\n }\n\n private insertTxnLockRecord(id: Id64String, state: LockState, origin: LockOrigin): void {\n // Locks are always acquired in the current txn, which isn't a real txn until it's committed.\n // So use a placeholder txn id for now, and we'll update to the real txn id on commit.\n // This is important to distinguish new locks acquired in the current txn from locks acquired in previous reversed txns, which will only\n // be cleared (no longer reinstateable) on commit.\n this.lockDb.withPreparedSqliteStatement(`\n INSERT INTO txn_locks(txnId,elementId,state,origin,abandoned)\n VALUES (?,?,?,?,FALSE)\n ON CONFLICT(txnId,elementId)\n DO UPDATE SET\n state=excluded.state,\n origin=excluded.origin,\n abandoned=excluded.abandoned`, (stmt) => {\n stmt.bindId(1, this._unsavedChangesTxnId);\n stmt.bindId(2, id);\n stmt.bindInteger(3, state);\n stmt.bindInteger(4, origin);\n const rc = stmt.step();\n if (DbResult.BE_SQLITE_DONE !== rc)\n ServerBasedLocksError.throwError(\"lock-database-problem\", `can't insert txn lock record into database (error code ${rc})`);\n });\n }\n\n private ownerHoldsExclusiveLock(id: Id64String | undefined): boolean {\n if (id === undefined || id === IModel.rootSubjectId)\n return false; // has no owners\n\n const { modelId, parentId } = this.getOwners(id);\n if (this.getLockState(modelId) === LockState.Exclusive || this.getLockState(parentId) === LockState.Exclusive)\n return true;\n\n // see if this model is exclusively locked by one of its owners. If so, save that fact on modelId so future tests won't have to descend.\n if (this.ownerHoldsExclusiveLock(modelId))\n return this.insertLock(modelId, LockState.Exclusive, LockOrigin.Discovered);\n\n // see if the parent is exclusively locked by one of its owners. If so, save that fact on parentId so future tests won't have to descend.\n return this.ownerHoldsExclusiveLock(parentId) ? this.insertLock(parentId!, LockState.Exclusive, LockOrigin.Discovered) : false; // eslint-disable-line @typescript-eslint/no-non-null-assertion\n }\n\n /** Determine whether an the exclusive lock is already held by an element (or one of its owners) */\n public holdsExclusiveLock(id: Id64String): boolean {\n // see if we hold the exclusive lock. or if one of the element's owners is exclusively locked (recursively)\n return this.getLockState(id) === LockState.Exclusive || this.ownerHoldsExclusiveLock(id);\n }\n\n public holdsSharedLock(id: Id64String): boolean {\n const state = this.getLockState(id);\n // see if we hold shared or exclusive lock, or if an owner has exclusive lock. If so we implicitly have shared lock, but owner holding shared lock doesn't help.\n return (state === LockState.Shared || state === LockState.Exclusive) || this.ownerHoldsExclusiveLock(id);\n }\n\n /** if the shared lock on the element supplied is not already held, add it to the set of shared locks required. Then, check owners. */\n private addSharedLock(id: Id64String | undefined, locks: Set<Id64String>) {\n // if the id is not valid, or of the lock is already in the set, or if we already hold a shared lock, we're done\n // Note: if we hold a shared lock, it is guaranteed that we also hold all required shared locks on owners.\n if (id === undefined || !Id64.isValid(id) || locks.has(id) || this.holdsSharedLock(id))\n return;\n\n locks.add(id); // add to set of needed shared locks\n this.addOwnerSharedLocks(id, locks); // check parent models and groups\n }\n\n /** add owners (recursively) of an element to a list of required shared locks, if not already held. */\n private addOwnerSharedLocks(id: Id64String, locks: Set<Id64String>) {\n const el = this.getOwners(id);\n this.addSharedLock(el.parentId, locks); // if this element is in a group\n this.addSharedLock(el.modelId, locks); // check its model\n }\n\n /** attempt to acquire all necessary locks for a set of elements */\n private async acquireAllLocks(locks: LockMap) {\n if (locks.size === 0) // no locks are required.\n return;\n\n const sharedLocks = new Set<Id64String>();\n for (const lock of locks)\n this.addOwnerSharedLocks(lock[0], sharedLocks);\n\n for (const shared of sharedLocks) {\n if (!locks.has(shared)) // we may already be asking for exclusive lock\n locks.set(shared, LockState.Shared);\n }\n\n await IModelHost[_hubAccess].acquireLocks(this.briefcase, locks); // throws if unsuccessful\n for (const lock of locks) {\n this.insertLock(lock[0], lock[1], LockOrigin.Acquired);\n this.insertTxnLockRecord(lock[0], lock[1], LockOrigin.Acquired);\n }\n this.lockDb.saveChanges();\n }\n\n public async acquireLocks(arg: { shared?: Id64Arg, exclusive?: Id64Arg }): Promise<void> {\n const locks = new Map<Id64String, LockState>();\n if (arg.shared) {\n for (const id of Id64.iterable(arg.shared)) {\n if (!this.holdsSharedLock(id))\n locks.set(id, LockState.Shared);\n }\n }\n if (arg.exclusive) {\n for (const id of Id64.iterable(arg.exclusive)) {\n if (!this.holdsExclusiveLock(id))\n locks.set(id, LockState.Exclusive);\n }\n }\n return this.acquireAllLocks(locks);\n }\n\n private async abandonLocks(locks: LockMap): Promise<void> {\n if (IModelHost[_hubAccess].abandonLocks === undefined) {\n // If the IModelHub doesn't support an explicit abandon, call acquireLocks with a blank changeset to indicate\n // that locks should be released without updating the changeset associated with the locks.\n await IModelHost[_hubAccess].acquireLocks({\n iModelId: this.briefcase.iModelId,\n briefcaseId: this.briefcase.briefcaseId,\n changeset: { id: \"\", index: 0 }\n }, locks);\n } else {\n await IModelHost[_hubAccess].abandonLocks(this.briefcase, locks);\n }\n }\n\n public async abandonLocksForCurrentUnsavedTxn(): Promise<boolean> {\n return this.abandonLocksForReversedTxn(this._unsavedChangesTxnId);\n }\n\n public async abandonLocksForReversedTxn(txnId: Id64String): Promise<boolean> {\n if (this.briefcase.txns.hasUnsavedChanges)\n ServerBasedLocksError.throwError(\"has-unsaved-changes\", `cannot abandon locks for txn ${txnId} because the current txn has unsaved changes`);\n\n const txnProps = this.briefcase.txns.getTxnProps(txnId);\n if (txnProps === undefined) {\n // The current txn commonly won't exist on the TxnManager yet. It's often just a placeholder for not-yet-saved changes.\n // (Sometimes it will exist and refer to a reversed Txn).\n // The unsavedChangesTxnId won't exist on the TxnManager either, of course.\n // But all other txn ids must be known to the TxnManager or it is an error.\n if (txnId !== this.briefcase.txns.getCurrentTxnId() && txnId !== this._unsavedChangesTxnId)\n ServerBasedLocksError.throwError(\"txn-id-not-found\", `cannot abandon locks for txn ${txnId} because it does not exist`);\n } else {\n // If the txn id is known to the TxnManager, then we require that it has already been reversed.\n if (!txnProps.reversed)\n ServerBasedLocksError.throwError(\"txn-not-reversed\", `cannot abandon locks for txn ${txnId} because it has not been reversed`);\n }\n\n let locksReleased = false;\n\n // Abandon locks for unsaved (and now abandoned) changes.\n if (txnId !== this._unsavedChangesTxnId) {\n locksReleased = await this.abandonLocksForCurrentUnsavedTxn();\n }\n\n // At this point, we know:\n // 1. There are no unsaved changes, and the associated locks have been abandoned.\n // 2. The given txn ID has been reversed, which means any later txns are sure to have been reversed, too.\n\n // So we simply have to find all non-abandoned locks associated with the given txn or later, abandon them (or restore\n // them to their previous state), and mark them as abandoned in txn_locks.\n\n // Find all locks associated with the given txnId or later.\n // For each elementId, find the previous state of the lock before this Txn (if any), or None otherwise.\n // This is the state that we will restore the element's lock to. The reason we do this is to account for\n // lock upgrades. If an earlier Txn acquired a Shared lock on this element, and this Txn acquired an\n // Exclusive lock, we should restore the Shared lock.\n const allTxnLocks = new Map<Id64String, LockState>();\n const locksToRelease = new Map<Id64String, LockState>();\n this.lockDb.withPreparedSqliteStatement(\n `\n SELECT\n current.elementId,\n current.origin,\n IFNULL(\n (SELECT previous.state\n FROM txn_locks previous\n WHERE previous.elementId = current.elementId\n AND previous.txnId < ?2\n AND previous.abandoned=FALSE\n ORDER BY previous.txnId DESC\n LIMIT 1\n ),\n ?1\n ) AS previousState\n FROM txn_locks current\n WHERE current.txnId>=?2\n AND current.abandoned=FALSE\n ORDER BY current.txnId DESC\n `,\n (stmt) => {\n stmt.bindInteger(1, LockState.None);\n stmt.bindId(2, txnId);\n\n while (DbResult.BE_SQLITE_ROW === stmt.step()) {\n const elementId = stmt.getValueId(0);\n const origin = stmt.getValueInteger(1);\n const previousState = stmt.getValueInteger(2);\n allTxnLocks.set(elementId, previousState);\n if (origin !== LockOrigin.NewElement)\n locksToRelease.set(elementId, previousState);\n }\n });\n\n // Release the locks on the server.\n if (locksToRelease.size > 0)\n await this.abandonLocks(locksToRelease);\n\n // Mark the txn locks as abandoned.\n if (txnId === this._unsavedChangesTxnId) {\n // After abandoning locks held for the \"unsaved\" txn, we clear them completely because they are not reinstateable.\n this.lockDb.withPreparedSqliteStatement(\"DELETE FROM txn_locks WHERE txnId=?\", (stmt) => {\n stmt.bindId(1, this._unsavedChangesTxnId);\n const rc = stmt.step();\n if (DbResult.BE_SQLITE_DONE !== rc)\n ServerBasedLocksError.throwError(\"lock-database-problem\", `can't delete txn locks for unsaved changes in database (error code ${rc})`);\n });\n } else {\n this.lockDb.withPreparedSqliteStatement(\"UPDATE txn_locks SET abandoned=TRUE WHERE txnId>=?\", (stmt) => {\n stmt.bindId(1, txnId);\n const rc = stmt.step();\n if (DbResult.BE_SQLITE_DONE !== rc)\n ServerBasedLocksError.throwError(\"lock-database-problem\", `can't mark txn locks as abandoned in database (error code ${rc})`);\n });\n }\n\n // Restore each lock to its previous state (if any) in the local cache. Usually this means deleting it.\n for (const [elementId, previousState] of allTxnLocks) {\n if (previousState === LockState.None) {\n this.lockDb.withPreparedSqliteStatement(\"DELETE FROM locks WHERE id=?\", (stmt) => {\n stmt.bindId(1, elementId);\n const rc = stmt.step();\n if (DbResult.BE_SQLITE_DONE !== rc)\n ServerBasedLocksError.throwError(\"lock-database-problem\", `can't delete lock from database (error code ${rc})`);\n });\n } else {\n this.lockDb.withPreparedSqliteStatement(\"UPDATE locks SET state=? WHERE id=?\", (stmt) => {\n stmt.bindInteger(1, previousState);\n stmt.bindId(2, elementId);\n const rc = stmt.step();\n if (DbResult.BE_SQLITE_DONE !== rc)\n ServerBasedLocksError.throwError(\"lock-database-problem\", `can't update lock in database (error code ${rc})`);\n });\n }\n }\n\n // Ideally we'd only invalidate \"Discovered\" locks that are related to this Txn's Shared and\n // Exclusive locks. But that is a lot of added complexity for little benefit.\n // Clearing them all will have no impact on correctness and a minimal impact on performance.\n this.clearDiscoveredLocks();\n\n this.lockDb.saveChanges();\n\n return locksReleased || allTxnLocks.size > 0;\n }\n\n private getAbandonedLocksForTxn(txnId: Id64String): {\n newElementLocks: Map<Id64String, LockState>,\n locksToAcquire: Map<Id64String, LockState>\n } {\n const newElementLocks = new Map<Id64String, LockState>();\n const locksToAcquire = new Map<Id64String, LockState>();\n this.lockDb.withPreparedSqliteStatement(\n \"SELECT elementId, state, origin FROM txn_locks WHERE txnId<=? AND abandoned=TRUE\",\n (stmt) => {\n stmt.bindId(1, txnId);\n\n while (DbResult.BE_SQLITE_ROW === stmt.step()) {\n const elementId = stmt.getValueId(0);\n const state = stmt.getValueInteger(1);\n const origin = stmt.getValueInteger(2);\n if (origin === LockOrigin.NewElement)\n newElementLocks.set(elementId, state);\n else\n locksToAcquire.set(elementId, state);\n }\n });\n\n return { newElementLocks, locksToAcquire };\n }\n\n public async acquireLocksForReinstatingTxn(txnId: Id64String): Promise<boolean> {\n if (this.briefcase.txns.hasUnsavedChanges)\n ServerBasedLocksError.throwError(\"has-unsaved-changes\", `cannot acquire locks for reinstating txn ${txnId} because the current txn has unsaved changes`);\n\n // If the Txn is known to the TxnManager, we can proceed. We don't need to check if it is currently\n // reversed, because if it isn't, then abandonLocksForReversedTxn couldn't have been called, and so the\n // locks are still held. Proceeding with this method will be a no-op, but it will be harmless.\n // However, if the Txn Id is unknown, it may have been canceled or refer to the current Txn\n // whose unsaved changes were just abandoned. Or it's just plain-old invalid. In any case, we can't\n // re-acquire the associated locks.\n const txnProps = this.briefcase.txns.getTxnProps(txnId);\n if (txnProps === undefined) {\n ServerBasedLocksError.throwError(\"txn-id-not-found\", `cannot acquire locks for txn ${txnId} because it does not exist or has not been saved`);\n }\n\n // Find all locks associated with the given txnId.\n const { newElementLocks, locksToAcquire } = this.getAbandonedLocksForTxn(txnId);\n\n // Attempt to acquire the locks on the server. This may fail if the locks are no longer available!\n if (locksToAcquire.size > 0)\n await IModelHost[_hubAccess].acquireLocks(this.briefcase, locksToAcquire); // throws if unsuccessful\n\n // Mark the txn locks as no longer abandoned.\n this.lockDb.withPreparedSqliteStatement(\"UPDATE txn_locks SET abandoned=FALSE WHERE txnId<=?\", (stmt) => {\n stmt.bindId(1, txnId);\n const rc = stmt.step();\n if (DbResult.BE_SQLITE_DONE !== rc)\n ServerBasedLocksError.throwError(\"lock-database-problem\", `can't mark txn locks as no longer abandoned in database (error code ${rc})`);\n });\n\n // Insert the newly-acquired locks in the local cache. Note that we don't need to insert entries in the txn_locks table,\n // because these locks are already associated with the Txn.\n for (const [elementId, state] of locksToAcquire) {\n this.insertLock(elementId, state, LockOrigin.Acquired);\n }\n for (const [elementId, state] of newElementLocks) {\n this.insertLock(elementId, state, LockOrigin.NewElement);\n }\n\n // Ideally we'd only invalidate \"Discovered\" locks that are related to this Txn's Shared and\n // Exclusive locks. But that is a lot of added complexity for little benefit.\n // Clearing them all will have no impact on correctness and a minimal impact on performance.\n this.clearDiscoveredLocks();\n\n this.lockDb.saveChanges();\n\n return locksToAcquire.size > 0 || newElementLocks.size > 0;\n }\n\n public holdsNecessaryLocksForReinstatingTxn(txnId: Id64String): boolean {\n const locks = this.getAbandonedLocksForTxn(txnId);\n return locks.locksToAcquire.size === 0 && locks.newElementLocks.size === 0;\n }\n\n public clearTxnLockRecords(txnId: Id64String) {\n this.lockDb.withPreparedSqliteStatement(\"DELETE FROM txn_locks WHERE txnId!=? AND txnId>=?\", (stmt) => {\n stmt.bindId(1, this._unsavedChangesTxnId);\n stmt.bindId(2, txnId);\n const rc = stmt.step();\n if (DbResult.BE_SQLITE_DONE !== rc)\n ServerBasedLocksError.throwError(\"lock-database-problem\", `can't delete txn lock records from database (error code ${rc})`);\n });\n\n this.lockDb.saveChanges();\n }\n\n /** When an element is newly created in a session, we hold the lock on it implicitly. Save that fact. */\n public [_elementWasCreated](id: Id64String) {\n this.insertLock(id, LockState.Exclusive, LockOrigin.NewElement);\n this.insertTxnLockRecord(id, LockState.Exclusive, LockOrigin.NewElement);\n this.lockDb.saveChanges();\n }\n\n private clearDiscoveredLocks() {\n this.lockDb.withPreparedSqliteStatement(\"DELETE FROM locks WHERE origin=?\", (stmt) => {\n stmt.bindInteger(1, LockOrigin.Discovered);\n const rc = stmt.step();\n if (DbResult.BE_SQLITE_DONE !== rc)\n ServerBasedLocksError.throwError(\"lock-database-problem\", `can't delete discovered locks from database (error code ${rc})`);\n });\n }\n\n /** locks are not necessary during change propagation. */\n private get _locksAreRequired() { return !this.briefcase.txns.isIndirectChanges; }\n\n /** throw if locks are currently required and the exclusive lock is not held on the supplied element */\n public checkExclusiveLock(id: Id64String, type: string, operation: string) {\n if (this._locksAreRequired && !this.holdsExclusiveLock(id))\n throw new IModelError(IModelStatus.LockNotHeld, `exclusive lock not held on ${type} for ${operation} (id=${id})`);\n }\n\n /** throw if locks are currently required and a shared lock is not held on the supplied element */\n public checkSharedLock(id: Id64String, type: string, operation: string) {\n if (this._locksAreRequired && !this.holdsSharedLock(id))\n throw new IModelError(IModelStatus.LockNotHeld, `shared lock not held on ${type} for ${operation} (id=${id})`);\n }\n\n}\n\nexport function createServerBasedLocks(iModel: BriefcaseDb): LockControl {\n return new ServerBasedLocks(iModel);\n}\n"]}
|
|
@@ -197,10 +197,48 @@ export interface BackendHubAccess {
|
|
|
197
197
|
* @throws ConflictingLocksError if one or more requested locks are held by other briefcases.
|
|
198
198
|
*/
|
|
199
199
|
acquireLocks: (arg: BriefcaseDbArg, locks: LockMap) => Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Abandons the specified locks when none of the associated elements have
|
|
202
|
+
* been or will be modified. Depending on the {@link LockState} specified for the lock,
|
|
203
|
+
* it may be returned to the {@link LockState.Shared} state or released entirely. It is only
|
|
204
|
+
* valid to call this method when none of the elements protected by the locks have been edited, or if all edits
|
|
205
|
+
* have been reversed or abandoned without pushing them.
|
|
206
|
+
*
|
|
207
|
+
* The locks are released on the IModelHub, but the changeset associated with the locks is not updated.
|
|
208
|
+
*
|
|
209
|
+
* It is an error to specify {@link LockState.Exclusive} for any element, to specify {@link LockState.Shared}
|
|
210
|
+
* for an element where the Exclusive lock is not currently held, or to include any element for which no lock
|
|
211
|
+
* is currently held.
|
|
212
|
+
*
|
|
213
|
+
* This method is optional, so not all IModelHubs will implement it. If this method is not implemented
|
|
214
|
+
* explicitly by an IModelHub, it will be implemented implicitly by calling
|
|
215
|
+
* {@link BackendHubAccess.acquireLocks} with the same locks and passing `changeset.id=""` and
|
|
216
|
+
* `changeset.index=0` in the first argument to indicate that the lock state should change without updating
|
|
217
|
+
* the changeset associated with the locks.
|
|
218
|
+
*
|
|
219
|
+
* @beta
|
|
220
|
+
*/
|
|
221
|
+
abandonLocks?: (arg: BriefcaseIdArg, locks: LockMap) => Promise<void>;
|
|
200
222
|
/** Get the list of all held locks for a briefcase. This can be very expensive and is currently used only for tests. */
|
|
201
223
|
queryAllLocks: (arg: BriefcaseDbArg) => Promise<LockProps[]>;
|
|
202
224
|
/** Release all currently held locks */
|
|
203
225
|
releaseAllLocks: (arg: BriefcaseDbArg) => Promise<void>;
|
|
226
|
+
/**
|
|
227
|
+
* Abandons all currently held locks when none of the associated elements have been or will be modified.
|
|
228
|
+
* It is only valid to call this method when none of the elements protected by the locks have been edited,
|
|
229
|
+
* or if all edits have been reversed or abandoned without pushing them.
|
|
230
|
+
*
|
|
231
|
+
* The locks are released on the IModelHub, but the changeset associated with the locks is not updated.
|
|
232
|
+
*
|
|
233
|
+
* This method is optional, so not all IModelHubs will implement it. If this method is not implemented
|
|
234
|
+
* explicitly by an IModelHub, it will be implemented implicitly by calling
|
|
235
|
+
* {@link BackendHubAccess.releaseAllLocks}, passing `changeset.id=""` and `changeset.index=0` in the
|
|
236
|
+
* first argument to indicate that the lock state should change without updating the changeset associated
|
|
237
|
+
* with the locks.
|
|
238
|
+
*
|
|
239
|
+
* @beta
|
|
240
|
+
*/
|
|
241
|
+
abandonAllLocks?: (arg: BriefcaseIdArg) => Promise<void>;
|
|
204
242
|
/** Get the iModelId of an iModel by name. Undefined if no iModel with that name exists. */
|
|
205
243
|
queryIModelByName: (arg: IModelNameArg) => Promise<GuidString | undefined>;
|
|
206
244
|
/** create a new iModel. Returns the Guid of the newly created iModel */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackendHubAccess.d.ts","sourceRoot":"","sources":["../../src/BackendHubAccess.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAmB,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EACL,WAAW,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,cAAc,EAAE,kBAAkB,EAAE,cAAc,EAAE,cAAc,EACzH,SAAS,IAAI,eAAe,EAAE,WAAW,EAAE,aAAa,EACxD,YAAY,EAAE,aAAa,EAC5B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;EAEE;AACF,qBAAa,YAAa,SAAQ,WAAW;IAEzC,mCAAmC;aACnB,WAAW,EAAE,WAAW;IACxC,sCAAsC;aACtB,cAAc,EAAE,MAAM;;IAHtC,mCAAmC;IACnB,WAAW,EAAE,WAAW;IACxC,sCAAsC;IACtB,cAAc,EAAE,MAAM,EACtC,GAAG,EAAE,qBAAqB,GAAG,gCAAgC;CAIhE;AAED;;;GAGG;AACH,oBAAY,SAAS;IACnB,gCAAgC;IAChC,IAAI,IAAI;IACR,mJAAmJ;IACnJ,MAAM,IAAI;IACV;;OAEG;IACH,SAAS,IAAI;CACd;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,+BAA+B;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,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;;GAGG;AACH,MAAM,CAAN,IAAY,SASX;AATD,WAAY,SAAS;IACnB,gCAAgC;IAChC,yCAAQ,CAAA;IACR,mJAAmJ;IACnJ,6CAAU,CAAA;IACV;;OAEG;IACH,mDAAa,CAAA;AACf,CAAC,EATW,SAAS,KAAT,SAAS,QASpB","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module HubAccess\n */\n\nimport { AccessToken, GuidString, Id64String, IModelHubStatus } from \"@itwin/core-bentley\";\nimport {\n BriefcaseId, ChangesetFileProps, ChangesetIdWithIndex, ChangesetIndex, ChangesetIndexOrId, ChangesetProps, ChangesetRange,\n LockState as CommonLockState, IModelError, IModelVersion,\n LocalDirName, LocalFileName,\n} from \"@itwin/core-common\";\nimport { CheckpointProps, ProgressFunction } from \"./CheckpointManager\";\nimport type { TokenArg } from \"./IModelDb\";\n\n/** Exception thrown if lock cannot be acquired.\n * @beta\n*/\nexport class LockConflict extends IModelError {\n public constructor(\n /** Id of Briefcase holding lock */\n public readonly briefcaseId: BriefcaseId,\n /** Alias of Briefcase holding lock */\n public readonly briefcaseAlias: string,\n msg: \"shared lock is held\" | \"exclusive lock is already held\",\n ) {\n super(IModelHubStatus.LockOwnedByAnotherBriefcase, msg);\n }\n}\n\n/** The state of a lock. See [Acquiring locks on elements.]($docs/learning/backend/ConcurrencyControl.md#acquiring-locks-on-elements).\n * @deprecated in 4.7 - will not be removed until after 2026-06-13. Use [LockState]($common)\n * @public\n */\nexport enum LockState {\n /** The element is not locked */\n None = 0,\n /** Holding a shared lock on an element blocks other users from acquiring the Exclusive lock it. More than one user may acquire the shared lock. */\n Shared = 1,\n /** A Lock that permits modifications to an element and blocks other users from making modifications to it.\n * Holding an exclusive lock on an \"owner\" (a model or a parent element), implicitly exclusively locks all its members.\n */\n Exclusive = 2,\n}\n\n/**\n * The properties to access a V2 checkpoint through a daemon.\n * @public\n */\nexport interface V2CheckpointAccessProps {\n /** blob store account name. */\n readonly accountName: string;\n /** AccessToken that grants access to the container. */\n readonly sasToken: AccessToken;\n /** The name of the iModel's blob store container holding all checkpoints. */\n readonly containerId: string;\n /** The name of the virtual file within the container, used for the checkpoint */\n readonly dbName: string;\n /** blob storage module: e.g. \"azure\", \"google\", \"aws\". May also include URI style parameters. */\n readonly storageType: string;\n}\n\n/**\n * Maps element Ids to their corresponding [LockState]($common)s.\n * @public\n */\nexport type LockMap = Map<Id64String, CommonLockState>;\n\n/**\n * The properties of a lock that may be obtained from a lock server.\n * @public\n */\nexport interface LockProps {\n /** The elementId for the lock */\n readonly id: Id64String;\n /** the lock state */\n readonly state: CommonLockState;\n}\n\n/**\n * Argument for cancelling and tracking download progress.\n * @public\n */\nexport interface DownloadProgressArg {\n /** Called to show progress during a download. If this function returns non-zero, the download is aborted. */\n progressCallback?: ProgressFunction;\n}\n\n/**\n * Argument for methods that must supply an iTwinId\n * @public\n */\nexport interface ITwinIdArg {\n readonly iTwinId: GuidString;\n}\n\n/**\n * Argument for methods that must supply an IModelId\n * @public\n */\nexport interface IModelIdArg extends TokenArg {\n readonly iModelId: GuidString;\n}\n\n/**\n * Argument for acquiring a new BriefcaseId\n * @public\n */\nexport interface AcquireNewBriefcaseIdArg extends IModelIdArg {\n /** A string to be reported to other users to identify this briefcase, for example in the case of conflicts or lock collisions. */\n readonly briefcaseAlias?: string;\n /** A string to represent the device that holds the briefcase. */\n readonly deviceName?: string;\n}\n\n/** Argument for methods that must supply an IModel name and iTwinId\n * @public\n */\nexport interface IModelNameArg extends TokenArg, ITwinIdArg {\n readonly iModelName: string;\n}\n\n/** Argument for methods that must supply an IModelId and a BriefcaseId\n * @public\n */\nexport interface BriefcaseIdArg extends IModelIdArg {\n readonly briefcaseId: BriefcaseId;\n}\n\n/** Argument for methods that must supply a briefcaseId and a changeset\n * @public\n */\nexport interface BriefcaseDbArg extends BriefcaseIdArg {\n readonly changeset: ChangesetIdWithIndex;\n}\n\n/** Argument for methods that must supply an IModelId and a changeset\n * @public\n */\nexport interface ChangesetArg extends IModelIdArg {\n readonly changeset: ChangesetIndexOrId;\n}\n\n/** Argument for downloading a changeset.\n * @public\n */\nexport interface DownloadChangesetArg extends ChangesetArg, DownloadProgressArg {\n /** Directory where the changeset should be downloaded. */\n targetDir: LocalDirName;\n}\n\n/** @internal */\nexport interface ChangesetIndexArg extends IModelIdArg {\n readonly changeset: ChangesetIdWithIndex;\n}\n\n/** Argument for methods that must supply an IModelId and a range of Changesets.\n * @public\n */\nexport interface ChangesetRangeArg extends IModelIdArg {\n /** the range of changesets desired. If is undefined, *all* changesets are returned. */\n readonly range?: ChangesetRange;\n}\n\n/** Argument for downloading a changeset range.\n * @public\n */\nexport interface DownloadChangesetRangeArg extends ChangesetRangeArg, DownloadProgressArg {\n /** Directory where the changesets should be downloaded. */\n targetDir: LocalDirName;\n}\n\n/**\n * Arguments to create a new iModel in iModelHub\n * @public\n */\nexport interface CreateNewIModelProps extends IModelNameArg {\n readonly description?: string;\n readonly version0?: LocalFileName;\n readonly noLocks?: true;\n}\n\n/**\n * Methods for accessing services of IModelHub from an iTwin.js backend.\n * Generally direct access to these methods should not be required, since higher-level apis are provided.\n * @public\n */\nexport interface BackendHubAccess {\n /** Download all the changesets in the specified range. */\n downloadChangesets: (arg: DownloadChangesetRangeArg) => Promise<ChangesetFileProps[]>;\n /** Download a single changeset. */\n downloadChangeset: (arg: DownloadChangesetArg) => Promise<ChangesetFileProps>;\n /** Query the changeset properties given a ChangesetIndex */\n queryChangeset: (arg: ChangesetArg) => Promise<ChangesetProps>;\n /** Query an array of changeset properties given a range of ChangesetIndexes */\n queryChangesets: (arg: ChangesetRangeArg) => Promise<ChangesetProps[]>;\n /** Push a changeset to iModelHub. Returns the newly pushed changeset's index */\n pushChangeset: (arg: IModelIdArg & { changesetProps: ChangesetFileProps }) => Promise<ChangesetIndex>;\n /** Get the ChangesetProps of the most recent changeset */\n getLatestChangeset: (arg: IModelIdArg) => Promise<ChangesetProps>;\n /** Get the ChangesetProps for an IModelVersion */\n getChangesetFromVersion: (arg: IModelIdArg & { version: IModelVersion }) => Promise<ChangesetProps>;\n /** Get the ChangesetProps for a named version */\n getChangesetFromNamedVersion: (arg: IModelIdArg & { versionName: string }) => Promise<ChangesetProps>;\n\n /** Acquire a new briefcaseId for the supplied iModelId\n * @note usually there should only be one briefcase per iModel per user.\n */\n acquireNewBriefcaseId: (arg: AcquireNewBriefcaseIdArg) => Promise<BriefcaseId>;\n /** Release a briefcaseId. After this call it is illegal to generate changesets for the released briefcaseId. */\n releaseBriefcase: (arg: BriefcaseIdArg) => Promise<void>;\n\n /** get an array of the briefcases assigned to a user. */\n getMyBriefcaseIds: (arg: IModelIdArg) => Promise<BriefcaseId[]>;\n\n /** Get the access props for a V2 checkpoint. Returns undefined if no V2 checkpoint exists. */\n queryV2Checkpoint: (arg: CheckpointProps) => Promise<V2CheckpointAccessProps | undefined>;\n\n /**\n * acquire one or more locks. Throws if unsuccessful. If *any* lock cannot be obtained, no locks are acquired\n * @throws ConflictingLocksError if one or more requested locks are held by other briefcases.\n */\n acquireLocks: (arg: BriefcaseDbArg, locks: LockMap) => Promise<void>;\n\n /** Get the list of all held locks for a briefcase. This can be very expensive and is currently used only for tests. */\n queryAllLocks: (arg: BriefcaseDbArg) => Promise<LockProps[]>;\n\n /** Release all currently held locks */\n releaseAllLocks: (arg: BriefcaseDbArg) => Promise<void>;\n\n /** Get the iModelId of an iModel by name. Undefined if no iModel with that name exists. */\n queryIModelByName: (arg: IModelNameArg) => Promise<GuidString | undefined>;\n\n /** create a new iModel. Returns the Guid of the newly created iModel */\n createNewIModel: (arg: CreateNewIModelProps) => Promise<GuidString>;\n\n /** delete an iModel */\n deleteIModel: (arg: IModelIdArg & ITwinIdArg) => Promise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BackendHubAccess.js","sourceRoot":"","sources":["../../src/BackendHubAccess.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAuC,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EAEyB,WAAW,GAE1C,MAAM,oBAAoB,CAAC;AAI5B;;EAEE;AACF,MAAM,OAAO,YAAa,SAAQ,WAAW;IAGzB;IAEA;IAJlB;IACE,mCAAmC;IACnB,WAAwB;IACxC,sCAAsC;IACtB,cAAsB,EACtC,GAA6D;QAE7D,KAAK,CAAC,eAAe,CAAC,2BAA2B,EAAE,GAAG,CAAC,CAAC;QALxC,gBAAW,GAAX,WAAW,CAAa;QAExB,mBAAc,GAAd,cAAc,CAAQ;IAIxC,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,CAAN,IAAY,SASX;AATD,WAAY,SAAS;IACnB,gCAAgC;IAChC,yCAAQ,CAAA;IACR,mJAAmJ;IACnJ,6CAAU,CAAA;IACV;;OAEG;IACH,mDAAa,CAAA;AACf,CAAC,EATW,SAAS,KAAT,SAAS,QASpB","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module HubAccess\n */\n\nimport { AccessToken, GuidString, Id64String, IModelHubStatus } from \"@itwin/core-bentley\";\nimport {\n BriefcaseId, ChangesetFileProps, ChangesetIdWithIndex, ChangesetIndex, ChangesetIndexOrId, ChangesetProps, ChangesetRange,\n LockState as CommonLockState, IModelError, IModelVersion,\n LocalDirName, LocalFileName,\n} from \"@itwin/core-common\";\nimport { CheckpointProps, ProgressFunction } from \"./CheckpointManager\";\nimport type { TokenArg } from \"./IModelDb\";\n\n/** Exception thrown if lock cannot be acquired.\n * @beta\n*/\nexport class LockConflict extends IModelError {\n public constructor(\n /** Id of Briefcase holding lock */\n public readonly briefcaseId: BriefcaseId,\n /** Alias of Briefcase holding lock */\n public readonly briefcaseAlias: string,\n msg: \"shared lock is held\" | \"exclusive lock is already held\",\n ) {\n super(IModelHubStatus.LockOwnedByAnotherBriefcase, msg);\n }\n}\n\n/** The state of a lock. See [Acquiring locks on elements.]($docs/learning/backend/ConcurrencyControl.md#acquiring-locks-on-elements).\n * @deprecated in 4.7 - will not be removed until after 2026-06-13. Use [LockState]($common)\n * @public\n */\nexport enum LockState {\n /** The element is not locked */\n None = 0,\n /** Holding a shared lock on an element blocks other users from acquiring the Exclusive lock it. More than one user may acquire the shared lock. */\n Shared = 1,\n /** A Lock that permits modifications to an element and blocks other users from making modifications to it.\n * Holding an exclusive lock on an \"owner\" (a model or a parent element), implicitly exclusively locks all its members.\n */\n Exclusive = 2,\n}\n\n/**\n * The properties to access a V2 checkpoint through a daemon.\n * @public\n */\nexport interface V2CheckpointAccessProps {\n /** blob store account name. */\n readonly accountName: string;\n /** AccessToken that grants access to the container. */\n readonly sasToken: AccessToken;\n /** The name of the iModel's blob store container holding all checkpoints. */\n readonly containerId: string;\n /** The name of the virtual file within the container, used for the checkpoint */\n readonly dbName: string;\n /** blob storage module: e.g. \"azure\", \"google\", \"aws\". May also include URI style parameters. */\n readonly storageType: string;\n}\n\n/**\n * Maps element Ids to their corresponding [LockState]($common)s.\n * @public\n */\nexport type LockMap = Map<Id64String, CommonLockState>;\n\n/**\n * The properties of a lock that may be obtained from a lock server.\n * @public\n */\nexport interface LockProps {\n /** The elementId for the lock */\n readonly id: Id64String;\n /** the lock state */\n readonly state: CommonLockState;\n}\n\n/**\n * Argument for cancelling and tracking download progress.\n * @public\n */\nexport interface DownloadProgressArg {\n /** Called to show progress during a download. If this function returns non-zero, the download is aborted. */\n progressCallback?: ProgressFunction;\n}\n\n/**\n * Argument for methods that must supply an iTwinId\n * @public\n */\nexport interface ITwinIdArg {\n readonly iTwinId: GuidString;\n}\n\n/**\n * Argument for methods that must supply an IModelId\n * @public\n */\nexport interface IModelIdArg extends TokenArg {\n readonly iModelId: GuidString;\n}\n\n/**\n * Argument for acquiring a new BriefcaseId\n * @public\n */\nexport interface AcquireNewBriefcaseIdArg extends IModelIdArg {\n /** A string to be reported to other users to identify this briefcase, for example in the case of conflicts or lock collisions. */\n readonly briefcaseAlias?: string;\n /** A string to represent the device that holds the briefcase. */\n readonly deviceName?: string;\n}\n\n/** Argument for methods that must supply an IModel name and iTwinId\n * @public\n */\nexport interface IModelNameArg extends TokenArg, ITwinIdArg {\n readonly iModelName: string;\n}\n\n/** Argument for methods that must supply an IModelId and a BriefcaseId\n * @public\n */\nexport interface BriefcaseIdArg extends IModelIdArg {\n readonly briefcaseId: BriefcaseId;\n}\n\n/** Argument for methods that must supply a briefcaseId and a changeset\n * @public\n */\nexport interface BriefcaseDbArg extends BriefcaseIdArg {\n readonly changeset: ChangesetIdWithIndex;\n}\n\n/** Argument for methods that must supply an IModelId and a changeset\n * @public\n */\nexport interface ChangesetArg extends IModelIdArg {\n readonly changeset: ChangesetIndexOrId;\n}\n\n/** Argument for downloading a changeset.\n * @public\n */\nexport interface DownloadChangesetArg extends ChangesetArg, DownloadProgressArg {\n /** Directory where the changeset should be downloaded. */\n targetDir: LocalDirName;\n}\n\n/** @internal */\nexport interface ChangesetIndexArg extends IModelIdArg {\n readonly changeset: ChangesetIdWithIndex;\n}\n\n/** Argument for methods that must supply an IModelId and a range of Changesets.\n * @public\n */\nexport interface ChangesetRangeArg extends IModelIdArg {\n /** the range of changesets desired. If is undefined, *all* changesets are returned. */\n readonly range?: ChangesetRange;\n}\n\n/** Argument for downloading a changeset range.\n * @public\n */\nexport interface DownloadChangesetRangeArg extends ChangesetRangeArg, DownloadProgressArg {\n /** Directory where the changesets should be downloaded. */\n targetDir: LocalDirName;\n}\n\n/**\n * Arguments to create a new iModel in iModelHub\n * @public\n */\nexport interface CreateNewIModelProps extends IModelNameArg {\n readonly description?: string;\n readonly version0?: LocalFileName;\n readonly noLocks?: true;\n}\n\n/**\n * Methods for accessing services of IModelHub from an iTwin.js backend.\n * Generally direct access to these methods should not be required, since higher-level apis are provided.\n * @public\n */\nexport interface BackendHubAccess {\n /** Download all the changesets in the specified range. */\n downloadChangesets: (arg: DownloadChangesetRangeArg) => Promise<ChangesetFileProps[]>;\n /** Download a single changeset. */\n downloadChangeset: (arg: DownloadChangesetArg) => Promise<ChangesetFileProps>;\n /** Query the changeset properties given a ChangesetIndex */\n queryChangeset: (arg: ChangesetArg) => Promise<ChangesetProps>;\n /** Query an array of changeset properties given a range of ChangesetIndexes */\n queryChangesets: (arg: ChangesetRangeArg) => Promise<ChangesetProps[]>;\n /** Push a changeset to iModelHub. Returns the newly pushed changeset's index */\n pushChangeset: (arg: IModelIdArg & { changesetProps: ChangesetFileProps }) => Promise<ChangesetIndex>;\n /** Get the ChangesetProps of the most recent changeset */\n getLatestChangeset: (arg: IModelIdArg) => Promise<ChangesetProps>;\n /** Get the ChangesetProps for an IModelVersion */\n getChangesetFromVersion: (arg: IModelIdArg & { version: IModelVersion }) => Promise<ChangesetProps>;\n /** Get the ChangesetProps for a named version */\n getChangesetFromNamedVersion: (arg: IModelIdArg & { versionName: string }) => Promise<ChangesetProps>;\n\n /** Acquire a new briefcaseId for the supplied iModelId\n * @note usually there should only be one briefcase per iModel per user.\n */\n acquireNewBriefcaseId: (arg: AcquireNewBriefcaseIdArg) => Promise<BriefcaseId>;\n /** Release a briefcaseId. After this call it is illegal to generate changesets for the released briefcaseId. */\n releaseBriefcase: (arg: BriefcaseIdArg) => Promise<void>;\n\n /** get an array of the briefcases assigned to a user. */\n getMyBriefcaseIds: (arg: IModelIdArg) => Promise<BriefcaseId[]>;\n\n /** Get the access props for a V2 checkpoint. Returns undefined if no V2 checkpoint exists. */\n queryV2Checkpoint: (arg: CheckpointProps) => Promise<V2CheckpointAccessProps | undefined>;\n\n /**\n * acquire one or more locks. Throws if unsuccessful. If *any* lock cannot be obtained, no locks are acquired\n * @throws ConflictingLocksError if one or more requested locks are held by other briefcases.\n */\n acquireLocks: (arg: BriefcaseDbArg, locks: LockMap) => Promise<void>;\n\n /**\n * Abandons the specified locks when none of the associated elements have\n * been or will be modified. Depending on the {@link LockState} specified for the lock,\n * it may be returned to the {@link LockState.Shared} state or released entirely. It is only\n * valid to call this method when none of the elements protected by the locks have been edited, or if all edits\n * have been reversed or abandoned without pushing them.\n *\n * The locks are released on the IModelHub, but the changeset associated with the locks is not updated.\n *\n * It is an error to specify {@link LockState.Exclusive} for any element, to specify {@link LockState.Shared}\n * for an element where the Exclusive lock is not currently held, or to include any element for which no lock\n * is currently held.\n *\n * This method is optional, so not all IModelHubs will implement it. If this method is not implemented\n * explicitly by an IModelHub, it will be implemented implicitly by calling\n * {@link BackendHubAccess.acquireLocks} with the same locks and passing `changeset.id=\"\"` and\n * `changeset.index=0` in the first argument to indicate that the lock state should change without updating\n * the changeset associated with the locks.\n *\n * @beta\n */\n abandonLocks?: (arg: BriefcaseIdArg, locks: LockMap) => Promise<void>;\n\n /** Get the list of all held locks for a briefcase. This can be very expensive and is currently used only for tests. */\n queryAllLocks: (arg: BriefcaseDbArg) => Promise<LockProps[]>;\n\n /** Release all currently held locks */\n releaseAllLocks: (arg: BriefcaseDbArg) => Promise<void>;\n\n /**\n * Abandons all currently held locks when none of the associated elements have been or will be modified.\n * It is only valid to call this method when none of the elements protected by the locks have been edited,\n * or if all edits have been reversed or abandoned without pushing them.\n *\n * The locks are released on the IModelHub, but the changeset associated with the locks is not updated.\n *\n * This method is optional, so not all IModelHubs will implement it. If this method is not implemented\n * explicitly by an IModelHub, it will be implemented implicitly by calling\n * {@link BackendHubAccess.releaseAllLocks}, passing `changeset.id=\"\"` and `changeset.index=0` in the\n * first argument to indicate that the lock state should change without updating the changeset associated\n * with the locks.\n *\n * @beta\n */\n abandonAllLocks?: (arg: BriefcaseIdArg) => Promise<void>;\n\n /** Get the iModelId of an iModel by name. Undefined if no iModel with that name exists. */\n queryIModelByName: (arg: IModelNameArg) => Promise<GuidString | undefined>;\n\n /** create a new iModel. Returns the Guid of the newly created iModel */\n createNewIModel: (arg: CreateNewIModelProps) => Promise<GuidString>;\n\n /** delete an iModel */\n deleteIModel: (arg: IModelIdArg & ITwinIdArg) => Promise<void>;\n}\n"]}
|
package/lib/esm/IModelDb.js
CHANGED
|
@@ -2927,7 +2927,7 @@ export class BriefcaseDb extends IModelDb {
|
|
|
2927
2927
|
}
|
|
2928
2928
|
// attempt to release locks must happen after changes are undone successfully
|
|
2929
2929
|
Logger.logInfo(loggerCategory, "Releasing locks after discarding changes");
|
|
2930
|
-
await this.locks.
|
|
2930
|
+
await this.locks.abandonAllLocks();
|
|
2931
2931
|
}
|
|
2932
2932
|
/**
|
|
2933
2933
|
* The Guid that identifies the *context* that owns this iModel.
|