@itwin/core-backend 4.2.0-dev.15 → 4.2.0-dev.16
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/CHANGELOG.md +13 -1
- package/lib/cjs/CheckpointManager.js +1 -1
- package/lib/cjs/CheckpointManager.js.map +1 -1
- package/lib/cjs/CloudSqlite.d.ts +72 -33
- package/lib/cjs/CloudSqlite.d.ts.map +1 -1
- package/lib/cjs/CloudSqlite.js +5 -7
- package/lib/cjs/CloudSqlite.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts +3 -1
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +3 -1
- package/lib/cjs/IModelDb.js.map +1 -1
- package/package.json +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
# Change Log - @itwin/core-backend
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 06 Sep 2023 20:04:30 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.1.3
|
|
6
|
+
Wed, 30 Aug 2023 15:35:27 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 4.1.2
|
|
11
|
+
Wed, 23 Aug 2023 15:25:29 GMT
|
|
12
|
+
|
|
13
|
+
### Updates
|
|
14
|
+
|
|
15
|
+
- add TileStorage.getCachedTilesGenerator
|
|
4
16
|
|
|
5
17
|
## 4.1.1
|
|
6
18
|
Fri, 18 Aug 2023 13:02:53 GMT
|
|
@@ -97,7 +97,7 @@ class V2CheckpointManager {
|
|
|
97
97
|
core_bentley_1.Logger.logWarning(loggerCategory, `No evidence of the iTwinDaemon in provided CHECKPOINT_CACHE_DIR: ${process.env.CHECKPOINT_CACHE_DIR}, using ${cacheDir} instead.`);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
this._cloudCache = CloudSqlite_1.CloudSqlite.CloudCaches.getCache({ cacheName: this.cloudCacheName, cacheDir });
|
|
100
|
+
this._cloudCache = CloudSqlite_1.CloudSqlite.CloudCaches.getCache({ cacheName: this.cloudCacheName, cacheDir, cacheSize: "50G" });
|
|
101
101
|
// Its fine if its not a daemon, but lets log an info message
|
|
102
102
|
if (!this._cloudCache.isDaemon)
|
|
103
103
|
core_bentley_1.Logger.logInfo(loggerCategory, "V2Checkpoint manager running with no iTwinDaemon.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckpointManager.js","sourceRoot":"","sources":["../../src/CheckpointManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,2BAA2B;AAE3B,6BAA6B;AAC7B,8DAAgE;AAChE,sDAA+I;AAC/I,oDAE4B;AAE5B,mEAAgE;AAChE,yDAAsD;AACtD,+CAA4C;AAC5C,6CAA0C;AAC1C,6CAA0C;AAC1C,yCAAkD;AAElD,MAAM,cAAc,GAAG,6CAAqB,CAAC,QAAQ,CAAC;AAyBtD;;GAEG;AACH,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,yBAAyB;IACzB,2DAAY,CAAA;IACZ,sBAAsB;IACtB,qDAAS,CAAA;AACX,CAAC,EALW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAKzB;AAmCD,gBAAgB;AAChB,MAAa,SAAS;IAGZ,MAAM,CAAC,KAAK,CAAC,OAAO,CAAI,GAAgB,EAAE,EAAoC;QACpF,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,gDAAgD;QACvF,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC/B,IAAI;YACF,OAAO,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;SACtB;gBAAS;YACR,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;SAC9B;IACH,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,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E;oBAC5C,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;oBAC1B,OAAO,qBAAU,CAAC,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;iBACvD;aACF;SACF;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;;AA5JsB,8BAAY,GAAG,IAAI,sBAAO,EAA8B,CAAC;AACzD,8BAAY,GAAG,IAAI,sBAAO,EAA8B,CAAC;AAFrE,8CAAiB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module iModels\r\n */\r\n\r\n// cspell:ignore BLOCKCACHE\r\n\r\nimport * as path from \"path\";\r\nimport { NativeLoggerCategory } from \"@bentley/imodeljs-native\";\r\nimport { BeEvent, ChangeSetStatus, Guid, GuidString, IModelStatus, Logger, LogLevel, Mutable, OpenMode, StopWatch } from \"@itwin/core-bentley\";\r\nimport {\r\n BriefcaseIdValue, ChangesetId, ChangesetIdWithIndex, ChangesetIndexAndId, IModelError, IModelVersion, LocalDirName, LocalFileName,\r\n} from \"@itwin/core-common\";\r\nimport { V2CheckpointAccessProps } from \"./BackendHubAccess\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { BriefcaseManager } from \"./BriefcaseManager\";\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { SnapshotDb, TokenArg } from \"./IModelDb\";\r\n\r\nconst loggerCategory = BackendLoggerCategory.IModelDb;\r\n\r\n/**\r\n * Properties of a checkpoint\r\n * @public\r\n */\r\nexport interface CheckpointProps extends TokenArg {\r\n readonly expectV2?: boolean;\r\n\r\n /** iTwin that the iModel belongs to */\r\n readonly iTwinId: GuidString;\r\n\r\n /** Id of the iModel */\r\n readonly iModelId: GuidString;\r\n\r\n /** changeset for the checkpoint */\r\n readonly changeset: ChangesetIdWithIndex;\r\n\r\n /** If true, then the latest successful v2 checkpoint at or before the provided changeset will be returned when calling queryV2Checkpoint. */\r\n readonly allowPreceding?: boolean;\r\n\r\n /** The number of seconds before the current token expires to attempt to reacquire a new token. Default is 1 hour. */\r\n readonly reattachSafetySeconds?: number;\r\n}\r\n\r\n/** Return value from [[ProgressFunction]].\r\n * @public\r\n */\r\nexport enum ProgressStatus {\r\n /** Continue download. */\r\n Continue = 0,\r\n /** Abort download. */\r\n Abort = 1,\r\n}\r\n\r\n/** Called to show progress during a download. If this function returns non-zero, the download is aborted.\r\n * @public\r\n */\r\nexport type ProgressFunction = (loaded: number, total: number) => ProgressStatus;\r\n\r\n/** The parameters that specify a request to download a checkpoint file from iModelHub.\r\n * @internal\r\n */\r\nexport interface DownloadRequest {\r\n /** name of local file to hold the downloaded data. */\r\n localFile: LocalFileName;\r\n\r\n /** A list of full fileName paths to test before downloading. If a valid file exists by one of these names,\r\n * no download is performed and `localFile` is updated to reflect the fact that the file exists with that name.\r\n * This can be used, for example, to look for checkpoints from previous versions if the naming strategy changes.\r\n */\r\n readonly aliasFiles?: ReadonlyArray<string>;\r\n\r\n /** Properties of the checkpoint to be downloaded */\r\n readonly checkpoint: CheckpointProps;\r\n\r\n /** If present, this function will be called to indicate progress as the briefcase is downloaded. If this\r\n * function returns a non-zero value, the download is aborted.\r\n */\r\n readonly onProgress?: ProgressFunction;\r\n}\r\n\r\n/** @internal */\r\nexport interface DownloadJob {\r\n request: DownloadRequest;\r\n promise?: Promise<any>;\r\n}\r\n\r\n/** @internal */\r\nexport class Downloads {\r\n private static _active = new Map<string, DownloadJob>();\r\n\r\n private static async process<T>(job: DownloadJob, fn: (job: DownloadJob) => Promise<T>) {\r\n const jobName = job.request.localFile; // save this, it can change inside call to `fn`!\r\n this._active.set(jobName, job);\r\n try {\r\n return await fn(job);\r\n } finally {\r\n this._active.delete(jobName);\r\n }\r\n }\r\n\r\n public static isInProgress(pathName: LocalFileName): DownloadJob | undefined {\r\n return this._active.get(pathName);\r\n }\r\n\r\n public static async download<T>(request: DownloadRequest, downloadFn: (job: DownloadJob) => Promise<T>) {\r\n const pathName = request.localFile;\r\n let job = this.isInProgress(pathName);\r\n if (undefined !== job)\r\n return job.promise;\r\n\r\n IModelJsFs.recursiveMkDirSync(path.dirname(pathName));\r\n job = { request };\r\n return job.promise = this.process(job, downloadFn);\r\n }\r\n}\r\n\r\n/**\r\n * Utility class for opening V2 checkpoints from cloud containers, and also for downloading them.\r\n * @internal\r\n*/\r\nexport class V2CheckpointManager {\r\n public static readonly cloudCacheName = \"v2Checkpoints\";\r\n private static _cloudCache?: CloudSqlite.CloudCache;\r\n private static containers = new Map<string, CloudSqlite.CloudContainer>();\r\n\r\n public static getFolder(): LocalDirName {\r\n const cloudCachePath = path.join(BriefcaseManager.cacheDir, V2CheckpointManager.cloudCacheName);\r\n if (!(IModelJsFs.existsSync(cloudCachePath))) {\r\n IModelJsFs.recursiveMkDirSync(cloudCachePath);\r\n }\r\n return cloudCachePath;\r\n }\r\n\r\n /* only used by tests that reset the state of the v2CheckpointManager. all dbs should be closed before calling this function. */\r\n public static cleanup(): void {\r\n for (const [_, value] of this.containers.entries()) {\r\n if (value.isConnected)\r\n value.disconnect({ detach: true });\r\n }\r\n\r\n CloudSqlite.CloudCaches.dropCache(this.cloudCacheName)?.destroy();\r\n this._cloudCache = undefined;\r\n this.containers.clear();\r\n }\r\n\r\n public static getFileName(checkpoint: CheckpointProps): LocalFileName {\r\n const changesetId = checkpoint.changeset.id || \"first\";\r\n return path.join(this.getFolder(), `${changesetId}.bim`);\r\n }\r\n\r\n private static get cloudCache(): CloudSqlite.CloudCache {\r\n if (!this._cloudCache) {\r\n let cacheDir = process.env.CHECKPOINT_CACHE_DIR;\r\n if (!cacheDir) {\r\n cacheDir = this.getFolder();\r\n Logger.logWarning(loggerCategory, `No CHECKPOINT_CACHE_DIR found in process.env, using ${cacheDir} instead.`);\r\n } else {\r\n // Make sure the checkpoint_cache_dir has an iTwinDaemon specific file in it, otherwise fall back to other directory.\r\n if (!(IModelJsFs.existsSync(path.join(cacheDir, \"portnumber.bcv\")))) {\r\n cacheDir = this.getFolder();\r\n Logger.logWarning(loggerCategory, `No evidence of the iTwinDaemon in provided CHECKPOINT_CACHE_DIR: ${process.env.CHECKPOINT_CACHE_DIR}, using ${cacheDir} instead.`);\r\n }\r\n }\r\n\r\n this._cloudCache = CloudSqlite.CloudCaches.getCache({ cacheName: this.cloudCacheName, cacheDir });\r\n\r\n // Its fine if its not a daemon, but lets log an info message\r\n if (!this._cloudCache.isDaemon)\r\n Logger.logInfo(loggerCategory, \"V2Checkpoint manager running with no iTwinDaemon.\");\r\n }\r\n return this._cloudCache;\r\n }\r\n\r\n /** Member names differ slightly between the V2Checkpoint api and the CloudSqlite api. Add aliases `accessName` for `accountName` and `accessToken` for `sasToken` */\r\n private static toCloudContainerProps(from: V2CheckpointAccessProps): CloudSqlite.ContainerAccessProps {\r\n return { ...from, baseUri: `https://${from.accountName}.blob.core.windows.net`, accessToken: from.sasToken, storageType: \"azure\" };\r\n }\r\n\r\n private static getContainer(v2Props: V2CheckpointAccessProps) {\r\n let container = this.containers.get(v2Props.containerId);\r\n if (!container) {\r\n // note checkpoint tokens can't be auto-refreshed because they rely on user credentials supplied through RPC. They're refreshed in SnapshotDb._refreshSas.\r\n container = CloudSqlite.createCloudContainer({ ...this.toCloudContainerProps(v2Props), tokenRefreshSeconds: -1, logId: process.env.POD_NAME });\r\n this.containers.set(v2Props.containerId, container);\r\n }\r\n return container;\r\n }\r\n\r\n public static async attach(checkpoint: CheckpointProps): Promise<{ dbName: string, container: CloudSqlite.CloudContainer }> {\r\n let v2props: V2CheckpointAccessProps | undefined;\r\n try {\r\n v2props = await IModelHost.hubAccess.queryV2Checkpoint(checkpoint);\r\n if (!v2props)\r\n throw new Error(\"no checkpoint\");\r\n } catch (err: any) {\r\n throw new IModelError(IModelStatus.NotFound, `V2 checkpoint not found: err: ${err.message}`);\r\n }\r\n\r\n try {\r\n const container = this.getContainer(v2props);\r\n const dbName = v2props.dbName;\r\n if (!container.isConnected)\r\n container.connect(this.cloudCache);\r\n container.checkForChanges();\r\n const dbStats = container.queryDatabase(dbName);\r\n if (IModelHost.appWorkspace.settings.getBoolean(\"Checkpoints/prefetch\", false)) {\r\n const getPrefetchConfig = (name: string, defaultVal: number) => IModelHost.appWorkspace.settings.getNumber(`Checkpoints/prefetch/${name}`, defaultVal);\r\n const minRequests = getPrefetchConfig(\"minRequests\", 3);\r\n const maxRequests = getPrefetchConfig(\"maxRequests\", 6);\r\n const timeout = getPrefetchConfig(\"timeout\", 100);\r\n const maxBlocks = getPrefetchConfig(\"maxBlocks\", 500); // default size of 2GB. Assumes a checkpoint block size of 4MB.\r\n if (dbStats?.totalBlocks !== undefined && dbStats.totalBlocks <= maxBlocks && dbStats.nPrefetch === 0) {\r\n const logPrefetch = async (prefetch: CloudSqlite.CloudPrefetch) => {\r\n const stopwatch = new StopWatch(`[${container.containerId}/${dbName}]`, true);\r\n Logger.logInfo(loggerCategory, `Starting prefetch of ${stopwatch.description}`, { minRequests, maxRequests, timeout });\r\n const done = await prefetch.promise;\r\n Logger.logInfo(loggerCategory, `Prefetch of ${stopwatch.description} complete=${done} (${stopwatch.elapsedSeconds} seconds)`, { minRequests, maxRequests, timeout });\r\n };\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n logPrefetch(CloudSqlite.startCloudPrefetch(container, dbName, { minRequests, nRequests: maxRequests, timeout }));\r\n } else {\r\n Logger.logInfo(loggerCategory, `Skipping prefetch due to size limits or ongoing prefetch.`, { maxBlocks, numPrefetches: dbStats?.nPrefetch, totalBlocksInDb: dbStats?.totalBlocks, v2props });\r\n }\r\n }\r\n return { dbName, container };\r\n } catch (e: any) {\r\n const error = `Cloud cache connect failed: ${e.message}`;\r\n if (checkpoint.expectV2)\r\n Logger.logError(loggerCategory, error);\r\n\r\n throw new IModelError(e.errorNumber, error);\r\n }\r\n }\r\n\r\n private static async performDownload(job: DownloadJob): Promise<ChangesetId> {\r\n const request = job.request;\r\n const v2props: V2CheckpointAccessProps | undefined = await IModelHost.hubAccess.queryV2Checkpoint({ ...request.checkpoint, allowPreceding: true });\r\n if (!v2props)\r\n throw new IModelError(IModelStatus.NotFound, \"V2 checkpoint not found\");\r\n\r\n CheckpointManager.onDownloadV2.raiseEvent(job);\r\n const container = CloudSqlite.createCloudContainer(this.toCloudContainerProps(v2props));\r\n await CloudSqlite.transferDb(\"download\", container, { dbName: v2props.dbName, localFileName: request.localFile, onProgress: request.onProgress });\r\n return request.checkpoint.changeset.id;\r\n }\r\n\r\n /** Fully download a V2 checkpoint to a local file that can be used to create a briefcase or to work offline.\r\n * @returns a Promise that is resolved when the download completes with the changesetId of the downloaded checkpoint (which will\r\n * be the same as the requested changesetId or the most recent checkpoint before it.)\r\n */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<ChangesetId> {\r\n return Downloads.download(request, async (job: DownloadJob) => this.performDownload(job));\r\n }\r\n}\r\n\r\n/** Utility class to deal with downloading V1 checkpoints from iModelHub.\r\n * @internal\r\n */\r\nexport class V1CheckpointManager {\r\n public static getFolder(iModelId: GuidString): LocalDirName {\r\n return path.join(BriefcaseManager.getIModelPath(iModelId), \"checkpoints\");\r\n }\r\n\r\n public static getFileName(checkpoint: CheckpointProps): LocalFileName {\r\n const changesetId = checkpoint.changeset.id || \"first\";\r\n return path.join(this.getFolder(checkpoint.iModelId), `${changesetId}.bim`);\r\n }\r\n\r\n public static async getCheckpointDb(request: DownloadRequest): Promise<SnapshotDb> {\r\n const db = SnapshotDb.tryFindByKey(CheckpointManager.getKey(request.checkpoint));\r\n return (undefined !== db) ? db : Downloads.download(request, async (job: DownloadJob) => this.downloadAndOpen(job));\r\n }\r\n\r\n /** Download a V1 checkpoint */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<ChangesetId> {\r\n return Downloads.download(request, async (job: DownloadJob) => this.performDownload(job));\r\n }\r\n\r\n private static async downloadAndOpen(job: DownloadJob) {\r\n const db = CheckpointManager.tryOpenLocalFile(job.request);\r\n if (db)\r\n return db;\r\n await this.performDownload(job);\r\n await CheckpointManager.updateToRequestedVersion(job.request);\r\n return SnapshotDb.openCheckpointV1(job.request.localFile, job.request.checkpoint);\r\n }\r\n\r\n private static async performDownload(job: DownloadJob): Promise<ChangesetId> {\r\n CheckpointManager.onDownloadV1.raiseEvent(job);\r\n // eslint-disable-next-line deprecation/deprecation\r\n return (await IModelHost.hubAccess.downloadV1Checkpoint(job.request)).id;\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class CheckpointManager {\r\n public static readonly onDownloadV1 = new BeEvent<(job: DownloadJob) => void>();\r\n public static readonly onDownloadV2 = new BeEvent<(job: DownloadJob) => void>();\r\n public static getKey(checkpoint: CheckpointProps) { return `${checkpoint.iModelId}:${checkpoint.changeset.id}`; }\r\n\r\n private static async doDownload(request: DownloadRequest): Promise<ChangesetId> {\r\n try {\r\n // first see if there's a V2 checkpoint available.\r\n const stopwatch = new StopWatch(`[${request.checkpoint.changeset.id}]`, true);\r\n Logger.logInfo(loggerCategory, `Starting download of V2 checkpoint with id ${stopwatch.description}`);\r\n const changesetId = await V2CheckpointManager.downloadCheckpoint(request);\r\n Logger.logInfo(loggerCategory, `Downloaded V2 checkpoint with id ${stopwatch.description} (${stopwatch.elapsedSeconds} seconds)`);\r\n if (changesetId !== request.checkpoint.changeset.id)\r\n Logger.logInfo(loggerCategory, `Downloaded previous v2 checkpoint because requested checkpoint not found.`, { requestedChangesetId: request.checkpoint.changeset.id, iModelId: request.checkpoint.iModelId, changesetId, iTwinId: request.checkpoint.iTwinId });\r\n else\r\n Logger.logInfo(loggerCategory, `Downloaded v2 checkpoint.`, { iModelId: request.checkpoint.iModelId, changesetId: request.checkpoint.changeset.id, iTwinId: request.checkpoint.iTwinId });\r\n return changesetId;\r\n } catch (error: any) {\r\n if (error.errorNumber === IModelStatus.NotFound) { // No V2 checkpoint available, try a v1 checkpoint\r\n const changeset = await V1CheckpointManager.downloadCheckpoint(request);\r\n Logger.logWarning(loggerCategory, `Got an error downloading v2 checkpoint, but downloaded v1 checkpoint successfully!`, { error, iModelId: request.checkpoint.iModelId, iTwinId: request.checkpoint.iTwinId, requestedChangesetId: request.checkpoint.changeset.id, changesetId: changeset });\r\n return changeset;\r\n }\r\n throw error; // most likely, was aborted\r\n }\r\n }\r\n\r\n public static async updateToRequestedVersion(request: DownloadRequest) {\r\n const checkpoint = request.checkpoint;\r\n const targetFile = request.localFile;\r\n const traceInfo = { iTwinId: checkpoint.iTwinId, iModelId: checkpoint.iModelId, changeset: checkpoint.changeset };\r\n try {\r\n // Open checkpoint for write\r\n Logger.setLevel(NativeLoggerCategory.SQLite, LogLevel.None); // Ignores noisy error messages when applying changesets.\r\n const db = SnapshotDb.openForApplyChangesets(targetFile);\r\n const nativeDb = db.nativeDb;\r\n try {\r\n\r\n if (nativeDb.hasPendingTxns()) {\r\n Logger.logWarning(loggerCategory, \"Checkpoint with Txns found - deleting them\", () => traceInfo);\r\n nativeDb.deleteAllTxns();\r\n }\r\n\r\n if (nativeDb.getBriefcaseId() !== BriefcaseIdValue.Unassigned)\r\n nativeDb.resetBriefcaseId(BriefcaseIdValue.Unassigned);\r\n\r\n CheckpointManager.validateCheckpointGuids(checkpoint, db);\r\n // Apply change sets if necessary\r\n const currentChangeset: Mutable<ChangesetIndexAndId> = nativeDb.getCurrentChangeset();\r\n if (currentChangeset.id !== checkpoint.changeset.id) {\r\n const accessToken = checkpoint.accessToken;\r\n const toIndex = checkpoint.changeset.index ??\r\n (await IModelHost.hubAccess.getChangesetFromVersion({ accessToken, iModelId: checkpoint.iModelId, version: IModelVersion.asOfChangeSet(checkpoint.changeset.id) })).index;\r\n await BriefcaseManager.pullAndApplyChangesets(db, { accessToken, toIndex });\r\n } else {\r\n // make sure the parent changeset index is saved in the file - old versions didn't have it.\r\n currentChangeset.index = checkpoint.changeset.index!; // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n nativeDb.saveLocalValue(\"parentChangeSet\", JSON.stringify(currentChangeset));\r\n }\r\n } finally {\r\n Logger.setLevel(NativeLoggerCategory.SQLite, LogLevel.Error); // Turn logging back on after applying changesets.\r\n db.saveChanges();\r\n db.close();\r\n }\r\n } catch (error: any) {\r\n\r\n Logger.logError(loggerCategory, \"Error downloading checkpoint - deleting it\", () => traceInfo);\r\n IModelJsFs.removeSync(targetFile);\r\n\r\n if (error.errorNumber === ChangeSetStatus.CorruptedChangeStream || error.errorNumber === ChangeSetStatus.InvalidId || error.errorNumber === ChangeSetStatus.InvalidVersion) {\r\n Logger.logError(loggerCategory, \"Detected potential corruption of change sets. Deleting them to enable retries\", () => traceInfo);\r\n BriefcaseManager.deleteChangeSetsFromLocalDisk(checkpoint.iModelId);\r\n }\r\n throw error;\r\n }\r\n }\r\n\r\n /** Download a checkpoint file from iModelHub into a local file specified in the request parameters. */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<void> {\r\n if (this.verifyCheckpoint(request.checkpoint, request.localFile))\r\n return;\r\n\r\n if (request.aliasFiles) {\r\n for (const alias of request.aliasFiles) {\r\n if (this.verifyCheckpoint(request.checkpoint, alias)) {\r\n request.localFile = alias;\r\n return;\r\n }\r\n }\r\n }\r\n\r\n await this.doDownload(request);\r\n return this.updateToRequestedVersion(request);\r\n }\r\n\r\n /** checks a file's dbGuid & iTwinId for consistency, and updates the dbGuid when possible */\r\n public static validateCheckpointGuids(checkpoint: CheckpointProps, snapshotDb: SnapshotDb) {\r\n const traceInfo = { iTwinId: checkpoint.iTwinId, iModelId: checkpoint.iModelId };\r\n\r\n const nativeDb = snapshotDb.nativeDb;\r\n const dbChangeset = nativeDb.getCurrentChangeset();\r\n const iModelId = Guid.normalize(nativeDb.getIModelId());\r\n if (iModelId !== Guid.normalize(checkpoint.iModelId)) {\r\n if (nativeDb.isReadonly())\r\n throw new IModelError(IModelStatus.ValidationFailed, \"iModelId is not properly set up in the checkpoint\");\r\n\r\n Logger.logWarning(loggerCategory, \"iModelId is not properly set up in the checkpoint. Updated checkpoint to the correct iModelId.\", () => ({ ...traceInfo, dbGuid: iModelId }));\r\n const iModelIdNormalized = Guid.normalize(checkpoint.iModelId);\r\n nativeDb.setIModelId(iModelIdNormalized);\r\n (snapshotDb as any)._iModelId = iModelIdNormalized;\r\n // Required to reset the ChangeSetId because setDbGuid clears the value.\r\n nativeDb.saveLocalValue(\"ParentChangeSetId\", dbChangeset.id);\r\n if (undefined !== dbChangeset.index)\r\n nativeDb.saveLocalValue(\"parentChangeSet\", JSON.stringify(dbChangeset));\r\n }\r\n\r\n const iTwinId = Guid.normalize(nativeDb.getITwinId());\r\n if (iTwinId !== Guid.normalize(checkpoint.iTwinId))\r\n throw new IModelError(IModelStatus.ValidationFailed, \"iTwinId was not properly set up in the checkpoint\");\r\n }\r\n\r\n /** @returns true if the file is the checkpoint requested */\r\n public static verifyCheckpoint(checkpoint: CheckpointProps, fileName: LocalFileName): boolean {\r\n if (!IModelJsFs.existsSync(fileName))\r\n return false;\r\n\r\n const nativeDb = new IModelHost.platform.DgnDb();\r\n try {\r\n nativeDb.openIModel(fileName, OpenMode.Readonly);\r\n } catch (error) {\r\n return false;\r\n }\r\n\r\n const isValid = checkpoint.iModelId === nativeDb.getIModelId() && checkpoint.changeset.id === nativeDb.getCurrentChangeset().id;\r\n nativeDb.closeIModel();\r\n if (!isValid)\r\n IModelJsFs.removeSync(fileName);\r\n\r\n return isValid;\r\n }\r\n\r\n /** try to open an existing local file to satisfy a download request */\r\n public static tryOpenLocalFile(request: DownloadRequest): SnapshotDb | undefined {\r\n const checkpoint = request.checkpoint;\r\n if (this.verifyCheckpoint(checkpoint, request.localFile))\r\n return SnapshotDb.openCheckpointV1(request.localFile, checkpoint);\r\n\r\n // check a list of aliases for finding checkpoints downloaded to non-default locations (e.g. from older versions)\r\n if (request.aliasFiles) {\r\n for (const alias of request.aliasFiles) {\r\n if (this.verifyCheckpoint(checkpoint, alias)) {\r\n request.localFile = alias;\r\n return SnapshotDb.openCheckpointV1(alias, checkpoint);\r\n }\r\n }\r\n }\r\n return undefined;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"CheckpointManager.js","sourceRoot":"","sources":["../../src/CheckpointManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,2BAA2B;AAE3B,6BAA6B;AAC7B,8DAAgE;AAChE,sDAA+I;AAC/I,oDAE4B;AAE5B,mEAAgE;AAChE,yDAAsD;AACtD,+CAA4C;AAC5C,6CAA0C;AAC1C,6CAA0C;AAC1C,yCAAkD;AAElD,MAAM,cAAc,GAAG,6CAAqB,CAAC,QAAQ,CAAC;AAyBtD;;GAEG;AACH,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,yBAAyB;IACzB,2DAAY,CAAA;IACZ,sBAAsB;IACtB,qDAAS,CAAA;AACX,CAAC,EALW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAKzB;AAmCD,gBAAgB;AAChB,MAAa,SAAS;IAGZ,MAAM,CAAC,KAAK,CAAC,OAAO,CAAI,GAAgB,EAAE,EAAoC;QACpF,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,gDAAgD;QACvF,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC/B,IAAI;YACF,OAAO,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;SACtB;gBAAS;YACR,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;SAC9B;IACH,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,QAAuB;QAChD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAI,OAAwB,EAAE,UAA4C;QACpG,MAAM,QAAQ,GAAG,OAAO,CAAC,SAA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AAC;;AA5JsB,8BAAY,GAAG,IAAI,sBAAO,EAA8B,CAAC;AACzD,8BAAY,GAAG,IAAI,sBAAO,EAA8B,CAAC;AAFrE,8CAAiB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module iModels\r\n */\r\n\r\n// cspell:ignore BLOCKCACHE\r\n\r\nimport * as path from \"path\";\r\nimport { NativeLoggerCategory } from \"@bentley/imodeljs-native\";\r\nimport { BeEvent, ChangeSetStatus, Guid, GuidString, IModelStatus, Logger, LogLevel, Mutable, OpenMode, StopWatch } from \"@itwin/core-bentley\";\r\nimport {\r\n BriefcaseIdValue, ChangesetId, ChangesetIdWithIndex, ChangesetIndexAndId, IModelError, IModelVersion, LocalDirName, LocalFileName,\r\n} from \"@itwin/core-common\";\r\nimport { V2CheckpointAccessProps } from \"./BackendHubAccess\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { BriefcaseManager } from \"./BriefcaseManager\";\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\nimport { SnapshotDb, TokenArg } from \"./IModelDb\";\r\n\r\nconst loggerCategory = BackendLoggerCategory.IModelDb;\r\n\r\n/**\r\n * Properties of a checkpoint\r\n * @public\r\n */\r\nexport interface CheckpointProps extends TokenArg {\r\n readonly expectV2?: boolean;\r\n\r\n /** iTwin that the iModel belongs to */\r\n readonly iTwinId: GuidString;\r\n\r\n /** Id of the iModel */\r\n readonly iModelId: GuidString;\r\n\r\n /** changeset for the checkpoint */\r\n readonly changeset: ChangesetIdWithIndex;\r\n\r\n /** If true, then the latest successful v2 checkpoint at or before the provided changeset will be returned when calling queryV2Checkpoint. */\r\n readonly allowPreceding?: boolean;\r\n\r\n /** The number of seconds before the current token expires to attempt to reacquire a new token. Default is 1 hour. */\r\n readonly reattachSafetySeconds?: number;\r\n}\r\n\r\n/** Return value from [[ProgressFunction]].\r\n * @public\r\n */\r\nexport enum ProgressStatus {\r\n /** Continue download. */\r\n Continue = 0,\r\n /** Abort download. */\r\n Abort = 1,\r\n}\r\n\r\n/** Called to show progress during a download. If this function returns non-zero, the download is aborted.\r\n * @public\r\n */\r\nexport type ProgressFunction = (loaded: number, total: number) => ProgressStatus;\r\n\r\n/** The parameters that specify a request to download a checkpoint file from iModelHub.\r\n * @internal\r\n */\r\nexport interface DownloadRequest {\r\n /** name of local file to hold the downloaded data. */\r\n localFile: LocalFileName;\r\n\r\n /** A list of full fileName paths to test before downloading. If a valid file exists by one of these names,\r\n * no download is performed and `localFile` is updated to reflect the fact that the file exists with that name.\r\n * This can be used, for example, to look for checkpoints from previous versions if the naming strategy changes.\r\n */\r\n readonly aliasFiles?: ReadonlyArray<string>;\r\n\r\n /** Properties of the checkpoint to be downloaded */\r\n readonly checkpoint: CheckpointProps;\r\n\r\n /** If present, this function will be called to indicate progress as the briefcase is downloaded. If this\r\n * function returns a non-zero value, the download is aborted.\r\n */\r\n readonly onProgress?: ProgressFunction;\r\n}\r\n\r\n/** @internal */\r\nexport interface DownloadJob {\r\n request: DownloadRequest;\r\n promise?: Promise<any>;\r\n}\r\n\r\n/** @internal */\r\nexport class Downloads {\r\n private static _active = new Map<string, DownloadJob>();\r\n\r\n private static async process<T>(job: DownloadJob, fn: (job: DownloadJob) => Promise<T>) {\r\n const jobName = job.request.localFile; // save this, it can change inside call to `fn`!\r\n this._active.set(jobName, job);\r\n try {\r\n return await fn(job);\r\n } finally {\r\n this._active.delete(jobName);\r\n }\r\n }\r\n\r\n public static isInProgress(pathName: LocalFileName): DownloadJob | undefined {\r\n return this._active.get(pathName);\r\n }\r\n\r\n public static async download<T>(request: DownloadRequest, downloadFn: (job: DownloadJob) => Promise<T>) {\r\n const pathName = request.localFile;\r\n let job = this.isInProgress(pathName);\r\n if (undefined !== job)\r\n return job.promise;\r\n\r\n IModelJsFs.recursiveMkDirSync(path.dirname(pathName));\r\n job = { request };\r\n return job.promise = this.process(job, downloadFn);\r\n }\r\n}\r\n\r\n/**\r\n * Utility class for opening V2 checkpoints from cloud containers, and also for downloading them.\r\n * @internal\r\n*/\r\nexport class V2CheckpointManager {\r\n public static readonly cloudCacheName = \"v2Checkpoints\";\r\n private static _cloudCache?: CloudSqlite.CloudCache;\r\n private static containers = new Map<string, CloudSqlite.CloudContainer>();\r\n\r\n public static getFolder(): LocalDirName {\r\n const cloudCachePath = path.join(BriefcaseManager.cacheDir, V2CheckpointManager.cloudCacheName);\r\n if (!(IModelJsFs.existsSync(cloudCachePath))) {\r\n IModelJsFs.recursiveMkDirSync(cloudCachePath);\r\n }\r\n return cloudCachePath;\r\n }\r\n\r\n /* only used by tests that reset the state of the v2CheckpointManager. all dbs should be closed before calling this function. */\r\n public static cleanup(): void {\r\n for (const [_, value] of this.containers.entries()) {\r\n if (value.isConnected)\r\n value.disconnect({ detach: true });\r\n }\r\n\r\n CloudSqlite.CloudCaches.dropCache(this.cloudCacheName)?.destroy();\r\n this._cloudCache = undefined;\r\n this.containers.clear();\r\n }\r\n\r\n public static getFileName(checkpoint: CheckpointProps): LocalFileName {\r\n const changesetId = checkpoint.changeset.id || \"first\";\r\n return path.join(this.getFolder(), `${changesetId}.bim`);\r\n }\r\n\r\n private static get cloudCache(): CloudSqlite.CloudCache {\r\n if (!this._cloudCache) {\r\n let cacheDir = process.env.CHECKPOINT_CACHE_DIR;\r\n if (!cacheDir) {\r\n cacheDir = this.getFolder();\r\n Logger.logWarning(loggerCategory, `No CHECKPOINT_CACHE_DIR found in process.env, using ${cacheDir} instead.`);\r\n } else {\r\n // Make sure the checkpoint_cache_dir has an iTwinDaemon specific file in it, otherwise fall back to other directory.\r\n if (!(IModelJsFs.existsSync(path.join(cacheDir, \"portnumber.bcv\")))) {\r\n cacheDir = this.getFolder();\r\n Logger.logWarning(loggerCategory, `No evidence of the iTwinDaemon in provided CHECKPOINT_CACHE_DIR: ${process.env.CHECKPOINT_CACHE_DIR}, using ${cacheDir} instead.`);\r\n }\r\n }\r\n\r\n this._cloudCache = CloudSqlite.CloudCaches.getCache({ cacheName: this.cloudCacheName, cacheDir, cacheSize: \"50G\" });\r\n\r\n // Its fine if its not a daemon, but lets log an info message\r\n if (!this._cloudCache.isDaemon)\r\n Logger.logInfo(loggerCategory, \"V2Checkpoint manager running with no iTwinDaemon.\");\r\n }\r\n return this._cloudCache;\r\n }\r\n\r\n /** Member names differ slightly between the V2Checkpoint api and the CloudSqlite api. Add aliases `accessName` for `accountName` and `accessToken` for `sasToken` */\r\n private static toCloudContainerProps(from: V2CheckpointAccessProps): CloudSqlite.ContainerAccessProps {\r\n return { ...from, baseUri: `https://${from.accountName}.blob.core.windows.net`, accessToken: from.sasToken, storageType: \"azure\" };\r\n }\r\n\r\n private static getContainer(v2Props: V2CheckpointAccessProps) {\r\n let container = this.containers.get(v2Props.containerId);\r\n if (!container) {\r\n // note checkpoint tokens can't be auto-refreshed because they rely on user credentials supplied through RPC. They're refreshed in SnapshotDb._refreshSas.\r\n container = CloudSqlite.createCloudContainer({ ...this.toCloudContainerProps(v2Props), tokenRefreshSeconds: -1, logId: process.env.POD_NAME });\r\n this.containers.set(v2Props.containerId, container);\r\n }\r\n return container;\r\n }\r\n\r\n public static async attach(checkpoint: CheckpointProps): Promise<{ dbName: string, container: CloudSqlite.CloudContainer }> {\r\n let v2props: V2CheckpointAccessProps | undefined;\r\n try {\r\n v2props = await IModelHost.hubAccess.queryV2Checkpoint(checkpoint);\r\n if (!v2props)\r\n throw new Error(\"no checkpoint\");\r\n } catch (err: any) {\r\n throw new IModelError(IModelStatus.NotFound, `V2 checkpoint not found: err: ${err.message}`);\r\n }\r\n\r\n try {\r\n const container = this.getContainer(v2props);\r\n const dbName = v2props.dbName;\r\n if (!container.isConnected)\r\n container.connect(this.cloudCache);\r\n container.checkForChanges();\r\n const dbStats = container.queryDatabase(dbName);\r\n if (IModelHost.appWorkspace.settings.getBoolean(\"Checkpoints/prefetch\", false)) {\r\n const getPrefetchConfig = (name: string, defaultVal: number) => IModelHost.appWorkspace.settings.getNumber(`Checkpoints/prefetch/${name}`, defaultVal);\r\n const minRequests = getPrefetchConfig(\"minRequests\", 3);\r\n const maxRequests = getPrefetchConfig(\"maxRequests\", 6);\r\n const timeout = getPrefetchConfig(\"timeout\", 100);\r\n const maxBlocks = getPrefetchConfig(\"maxBlocks\", 500); // default size of 2GB. Assumes a checkpoint block size of 4MB.\r\n if (dbStats?.totalBlocks !== undefined && dbStats.totalBlocks <= maxBlocks && dbStats.nPrefetch === 0) {\r\n const logPrefetch = async (prefetch: CloudSqlite.CloudPrefetch) => {\r\n const stopwatch = new StopWatch(`[${container.containerId}/${dbName}]`, true);\r\n Logger.logInfo(loggerCategory, `Starting prefetch of ${stopwatch.description}`, { minRequests, maxRequests, timeout });\r\n const done = await prefetch.promise;\r\n Logger.logInfo(loggerCategory, `Prefetch of ${stopwatch.description} complete=${done} (${stopwatch.elapsedSeconds} seconds)`, { minRequests, maxRequests, timeout });\r\n };\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n logPrefetch(CloudSqlite.startCloudPrefetch(container, dbName, { minRequests, nRequests: maxRequests, timeout }));\r\n } else {\r\n Logger.logInfo(loggerCategory, `Skipping prefetch due to size limits or ongoing prefetch.`, { maxBlocks, numPrefetches: dbStats?.nPrefetch, totalBlocksInDb: dbStats?.totalBlocks, v2props });\r\n }\r\n }\r\n return { dbName, container };\r\n } catch (e: any) {\r\n const error = `Cloud cache connect failed: ${e.message}`;\r\n if (checkpoint.expectV2)\r\n Logger.logError(loggerCategory, error);\r\n\r\n throw new IModelError(e.errorNumber, error);\r\n }\r\n }\r\n\r\n private static async performDownload(job: DownloadJob): Promise<ChangesetId> {\r\n const request = job.request;\r\n const v2props: V2CheckpointAccessProps | undefined = await IModelHost.hubAccess.queryV2Checkpoint({ ...request.checkpoint, allowPreceding: true });\r\n if (!v2props)\r\n throw new IModelError(IModelStatus.NotFound, \"V2 checkpoint not found\");\r\n\r\n CheckpointManager.onDownloadV2.raiseEvent(job);\r\n const container = CloudSqlite.createCloudContainer(this.toCloudContainerProps(v2props));\r\n await CloudSqlite.transferDb(\"download\", container, { dbName: v2props.dbName, localFileName: request.localFile, onProgress: request.onProgress });\r\n return request.checkpoint.changeset.id;\r\n }\r\n\r\n /** Fully download a V2 checkpoint to a local file that can be used to create a briefcase or to work offline.\r\n * @returns a Promise that is resolved when the download completes with the changesetId of the downloaded checkpoint (which will\r\n * be the same as the requested changesetId or the most recent checkpoint before it.)\r\n */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<ChangesetId> {\r\n return Downloads.download(request, async (job: DownloadJob) => this.performDownload(job));\r\n }\r\n}\r\n\r\n/** Utility class to deal with downloading V1 checkpoints from iModelHub.\r\n * @internal\r\n */\r\nexport class V1CheckpointManager {\r\n public static getFolder(iModelId: GuidString): LocalDirName {\r\n return path.join(BriefcaseManager.getIModelPath(iModelId), \"checkpoints\");\r\n }\r\n\r\n public static getFileName(checkpoint: CheckpointProps): LocalFileName {\r\n const changesetId = checkpoint.changeset.id || \"first\";\r\n return path.join(this.getFolder(checkpoint.iModelId), `${changesetId}.bim`);\r\n }\r\n\r\n public static async getCheckpointDb(request: DownloadRequest): Promise<SnapshotDb> {\r\n const db = SnapshotDb.tryFindByKey(CheckpointManager.getKey(request.checkpoint));\r\n return (undefined !== db) ? db : Downloads.download(request, async (job: DownloadJob) => this.downloadAndOpen(job));\r\n }\r\n\r\n /** Download a V1 checkpoint */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<ChangesetId> {\r\n return Downloads.download(request, async (job: DownloadJob) => this.performDownload(job));\r\n }\r\n\r\n private static async downloadAndOpen(job: DownloadJob) {\r\n const db = CheckpointManager.tryOpenLocalFile(job.request);\r\n if (db)\r\n return db;\r\n await this.performDownload(job);\r\n await CheckpointManager.updateToRequestedVersion(job.request);\r\n return SnapshotDb.openCheckpointV1(job.request.localFile, job.request.checkpoint);\r\n }\r\n\r\n private static async performDownload(job: DownloadJob): Promise<ChangesetId> {\r\n CheckpointManager.onDownloadV1.raiseEvent(job);\r\n // eslint-disable-next-line deprecation/deprecation\r\n return (await IModelHost.hubAccess.downloadV1Checkpoint(job.request)).id;\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class CheckpointManager {\r\n public static readonly onDownloadV1 = new BeEvent<(job: DownloadJob) => void>();\r\n public static readonly onDownloadV2 = new BeEvent<(job: DownloadJob) => void>();\r\n public static getKey(checkpoint: CheckpointProps) { return `${checkpoint.iModelId}:${checkpoint.changeset.id}`; }\r\n\r\n private static async doDownload(request: DownloadRequest): Promise<ChangesetId> {\r\n try {\r\n // first see if there's a V2 checkpoint available.\r\n const stopwatch = new StopWatch(`[${request.checkpoint.changeset.id}]`, true);\r\n Logger.logInfo(loggerCategory, `Starting download of V2 checkpoint with id ${stopwatch.description}`);\r\n const changesetId = await V2CheckpointManager.downloadCheckpoint(request);\r\n Logger.logInfo(loggerCategory, `Downloaded V2 checkpoint with id ${stopwatch.description} (${stopwatch.elapsedSeconds} seconds)`);\r\n if (changesetId !== request.checkpoint.changeset.id)\r\n Logger.logInfo(loggerCategory, `Downloaded previous v2 checkpoint because requested checkpoint not found.`, { requestedChangesetId: request.checkpoint.changeset.id, iModelId: request.checkpoint.iModelId, changesetId, iTwinId: request.checkpoint.iTwinId });\r\n else\r\n Logger.logInfo(loggerCategory, `Downloaded v2 checkpoint.`, { iModelId: request.checkpoint.iModelId, changesetId: request.checkpoint.changeset.id, iTwinId: request.checkpoint.iTwinId });\r\n return changesetId;\r\n } catch (error: any) {\r\n if (error.errorNumber === IModelStatus.NotFound) { // No V2 checkpoint available, try a v1 checkpoint\r\n const changeset = await V1CheckpointManager.downloadCheckpoint(request);\r\n Logger.logWarning(loggerCategory, `Got an error downloading v2 checkpoint, but downloaded v1 checkpoint successfully!`, { error, iModelId: request.checkpoint.iModelId, iTwinId: request.checkpoint.iTwinId, requestedChangesetId: request.checkpoint.changeset.id, changesetId: changeset });\r\n return changeset;\r\n }\r\n throw error; // most likely, was aborted\r\n }\r\n }\r\n\r\n public static async updateToRequestedVersion(request: DownloadRequest) {\r\n const checkpoint = request.checkpoint;\r\n const targetFile = request.localFile;\r\n const traceInfo = { iTwinId: checkpoint.iTwinId, iModelId: checkpoint.iModelId, changeset: checkpoint.changeset };\r\n try {\r\n // Open checkpoint for write\r\n Logger.setLevel(NativeLoggerCategory.SQLite, LogLevel.None); // Ignores noisy error messages when applying changesets.\r\n const db = SnapshotDb.openForApplyChangesets(targetFile);\r\n const nativeDb = db.nativeDb;\r\n try {\r\n\r\n if (nativeDb.hasPendingTxns()) {\r\n Logger.logWarning(loggerCategory, \"Checkpoint with Txns found - deleting them\", () => traceInfo);\r\n nativeDb.deleteAllTxns();\r\n }\r\n\r\n if (nativeDb.getBriefcaseId() !== BriefcaseIdValue.Unassigned)\r\n nativeDb.resetBriefcaseId(BriefcaseIdValue.Unassigned);\r\n\r\n CheckpointManager.validateCheckpointGuids(checkpoint, db);\r\n // Apply change sets if necessary\r\n const currentChangeset: Mutable<ChangesetIndexAndId> = nativeDb.getCurrentChangeset();\r\n if (currentChangeset.id !== checkpoint.changeset.id) {\r\n const accessToken = checkpoint.accessToken;\r\n const toIndex = checkpoint.changeset.index ??\r\n (await IModelHost.hubAccess.getChangesetFromVersion({ accessToken, iModelId: checkpoint.iModelId, version: IModelVersion.asOfChangeSet(checkpoint.changeset.id) })).index;\r\n await BriefcaseManager.pullAndApplyChangesets(db, { accessToken, toIndex });\r\n } else {\r\n // make sure the parent changeset index is saved in the file - old versions didn't have it.\r\n currentChangeset.index = checkpoint.changeset.index!; // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n nativeDb.saveLocalValue(\"parentChangeSet\", JSON.stringify(currentChangeset));\r\n }\r\n } finally {\r\n Logger.setLevel(NativeLoggerCategory.SQLite, LogLevel.Error); // Turn logging back on after applying changesets.\r\n db.saveChanges();\r\n db.close();\r\n }\r\n } catch (error: any) {\r\n\r\n Logger.logError(loggerCategory, \"Error downloading checkpoint - deleting it\", () => traceInfo);\r\n IModelJsFs.removeSync(targetFile);\r\n\r\n if (error.errorNumber === ChangeSetStatus.CorruptedChangeStream || error.errorNumber === ChangeSetStatus.InvalidId || error.errorNumber === ChangeSetStatus.InvalidVersion) {\r\n Logger.logError(loggerCategory, \"Detected potential corruption of change sets. Deleting them to enable retries\", () => traceInfo);\r\n BriefcaseManager.deleteChangeSetsFromLocalDisk(checkpoint.iModelId);\r\n }\r\n throw error;\r\n }\r\n }\r\n\r\n /** Download a checkpoint file from iModelHub into a local file specified in the request parameters. */\r\n public static async downloadCheckpoint(request: DownloadRequest): Promise<void> {\r\n if (this.verifyCheckpoint(request.checkpoint, request.localFile))\r\n return;\r\n\r\n if (request.aliasFiles) {\r\n for (const alias of request.aliasFiles) {\r\n if (this.verifyCheckpoint(request.checkpoint, alias)) {\r\n request.localFile = alias;\r\n return;\r\n }\r\n }\r\n }\r\n\r\n await this.doDownload(request);\r\n return this.updateToRequestedVersion(request);\r\n }\r\n\r\n /** checks a file's dbGuid & iTwinId for consistency, and updates the dbGuid when possible */\r\n public static validateCheckpointGuids(checkpoint: CheckpointProps, snapshotDb: SnapshotDb) {\r\n const traceInfo = { iTwinId: checkpoint.iTwinId, iModelId: checkpoint.iModelId };\r\n\r\n const nativeDb = snapshotDb.nativeDb;\r\n const dbChangeset = nativeDb.getCurrentChangeset();\r\n const iModelId = Guid.normalize(nativeDb.getIModelId());\r\n if (iModelId !== Guid.normalize(checkpoint.iModelId)) {\r\n if (nativeDb.isReadonly())\r\n throw new IModelError(IModelStatus.ValidationFailed, \"iModelId is not properly set up in the checkpoint\");\r\n\r\n Logger.logWarning(loggerCategory, \"iModelId is not properly set up in the checkpoint. Updated checkpoint to the correct iModelId.\", () => ({ ...traceInfo, dbGuid: iModelId }));\r\n const iModelIdNormalized = Guid.normalize(checkpoint.iModelId);\r\n nativeDb.setIModelId(iModelIdNormalized);\r\n (snapshotDb as any)._iModelId = iModelIdNormalized;\r\n // Required to reset the ChangeSetId because setDbGuid clears the value.\r\n nativeDb.saveLocalValue(\"ParentChangeSetId\", dbChangeset.id);\r\n if (undefined !== dbChangeset.index)\r\n nativeDb.saveLocalValue(\"parentChangeSet\", JSON.stringify(dbChangeset));\r\n }\r\n\r\n const iTwinId = Guid.normalize(nativeDb.getITwinId());\r\n if (iTwinId !== Guid.normalize(checkpoint.iTwinId))\r\n throw new IModelError(IModelStatus.ValidationFailed, \"iTwinId was not properly set up in the checkpoint\");\r\n }\r\n\r\n /** @returns true if the file is the checkpoint requested */\r\n public static verifyCheckpoint(checkpoint: CheckpointProps, fileName: LocalFileName): boolean {\r\n if (!IModelJsFs.existsSync(fileName))\r\n return false;\r\n\r\n const nativeDb = new IModelHost.platform.DgnDb();\r\n try {\r\n nativeDb.openIModel(fileName, OpenMode.Readonly);\r\n } catch (error) {\r\n return false;\r\n }\r\n\r\n const isValid = checkpoint.iModelId === nativeDb.getIModelId() && checkpoint.changeset.id === nativeDb.getCurrentChangeset().id;\r\n nativeDb.closeIModel();\r\n if (!isValid)\r\n IModelJsFs.removeSync(fileName);\r\n\r\n return isValid;\r\n }\r\n\r\n /** try to open an existing local file to satisfy a download request */\r\n public static tryOpenLocalFile(request: DownloadRequest): SnapshotDb | undefined {\r\n const checkpoint = request.checkpoint;\r\n if (this.verifyCheckpoint(checkpoint, request.localFile))\r\n return SnapshotDb.openCheckpointV1(request.localFile, checkpoint);\r\n\r\n // check a list of aliases for finding checkpoints downloaded to non-default locations (e.g. from older versions)\r\n if (request.aliasFiles) {\r\n for (const alias of request.aliasFiles) {\r\n if (this.verifyCheckpoint(checkpoint, alias)) {\r\n request.localFile = alias;\r\n return SnapshotDb.openCheckpointV1(alias, checkpoint);\r\n }\r\n }\r\n }\r\n return undefined;\r\n }\r\n}\r\n"]}
|
package/lib/cjs/CloudSqlite.d.ts
CHANGED
|
@@ -14,19 +14,19 @@ export declare namespace CloudSqlite {
|
|
|
14
14
|
* Request a new AccessToken for a cloud container using the [[BlobContainer]] service.
|
|
15
15
|
* If the service is unavailable or returns an error, an empty token is returned.
|
|
16
16
|
*/
|
|
17
|
-
function requestToken(args: Optional<BlobContainer.RequestTokenProps, "userToken">): Promise<AccessToken>;
|
|
17
|
+
export function requestToken(args: Optional<BlobContainer.RequestTokenProps, "userToken">): Promise<AccessToken>;
|
|
18
18
|
/**
|
|
19
19
|
* Create a new CloudContainer from a ContainerAccessProps. For non-public containers, a valid accessToken must be provided before the container
|
|
20
20
|
* can be used (e.g. via [[CloudSqlite.requestToken]]).
|
|
21
21
|
* @note After the container is successfully connected to a CloudCache, it will begin auto-refreshing its accessToken every `tokenRefreshSeconds` seconds (default is 1 hour)
|
|
22
22
|
* until it is disconnected. However, if the container is public, or if `tokenRefreshSeconds` is <=0, auto-refresh is not enabled.
|
|
23
23
|
*/
|
|
24
|
-
function createCloudContainer(args: ContainerAccessProps & {
|
|
24
|
+
export function createCloudContainer(args: ContainerAccessProps & {
|
|
25
25
|
accessLevel?: BlobContainer.RequestAccessLevel;
|
|
26
26
|
}): CloudContainer;
|
|
27
27
|
/** Begin prefetching all blocks for a database in a CloudContainer in the background. */
|
|
28
|
-
function startCloudPrefetch(container: CloudContainer, dbName: string, args?: PrefetchProps): CloudPrefetch;
|
|
29
|
-
interface ContainerProps {
|
|
28
|
+
export function startCloudPrefetch(container: CloudContainer, dbName: string, args?: PrefetchProps): CloudPrefetch;
|
|
29
|
+
export interface ContainerProps {
|
|
30
30
|
/** The type of storage provider. */
|
|
31
31
|
storageType: "azure" | "google";
|
|
32
32
|
/** The base URI for the container. */
|
|
@@ -37,7 +37,7 @@ export declare namespace CloudSqlite {
|
|
|
37
37
|
isPublic?: boolean;
|
|
38
38
|
}
|
|
39
39
|
/** Properties to access a CloudContainer. */
|
|
40
|
-
interface ContainerAccessProps extends ContainerProps {
|
|
40
|
+
export interface ContainerAccessProps extends ContainerProps {
|
|
41
41
|
/** an alias for the container. Defaults to `containerId` */
|
|
42
42
|
alias?: string;
|
|
43
43
|
/** SAS token that grants access to the container. */
|
|
@@ -54,7 +54,7 @@ export declare namespace CloudSqlite {
|
|
|
54
54
|
tokenRefreshSeconds?: number;
|
|
55
55
|
}
|
|
56
56
|
/** Returned from `CloudContainer.queryDatabase` describing one database in the container */
|
|
57
|
-
interface CachedDbProps {
|
|
57
|
+
export interface CachedDbProps {
|
|
58
58
|
/** The total number of blocks in the database. */
|
|
59
59
|
readonly totalBlocks: number;
|
|
60
60
|
/** the number of blocks of the database that have been downloaded into the CloudCache */
|
|
@@ -73,7 +73,7 @@ export declare namespace CloudSqlite {
|
|
|
73
73
|
/** Filter options passed to CloudContainer.queryHttpLog
|
|
74
74
|
* @internal
|
|
75
75
|
*/
|
|
76
|
-
interface BcvHttpLogFilterOptions {
|
|
76
|
+
export interface BcvHttpLogFilterOptions {
|
|
77
77
|
/** only return rows whose ID is >= the provided id */
|
|
78
78
|
startFromId?: number;
|
|
79
79
|
/** only return rows whose endTime is null OR >= the provided endTime. */
|
|
@@ -84,7 +84,7 @@ export declare namespace CloudSqlite {
|
|
|
84
84
|
/** Returned from 'CloudContainer.queryHttpLog' describing a row in the bcv_http_log table.
|
|
85
85
|
* @internal
|
|
86
86
|
*/
|
|
87
|
-
interface BcvHttpLog {
|
|
87
|
+
export interface BcvHttpLog {
|
|
88
88
|
/** Unique, monotonically increasing id value */
|
|
89
89
|
readonly id: number;
|
|
90
90
|
/** Time request was made, as iso-8601 */
|
|
@@ -102,35 +102,64 @@ export declare namespace CloudSqlite {
|
|
|
102
102
|
/** HTTP response code (e.g. 200) */
|
|
103
103
|
readonly httpcode: number;
|
|
104
104
|
}
|
|
105
|
+
/** Filter options passed to 'CloudContainer.queryBcvStats'
|
|
106
|
+
* @internal
|
|
107
|
+
*/
|
|
108
|
+
interface BcvStatsFilterOptions {
|
|
109
|
+
/** if true, adds activeClients, totalClients, ongoingPrefetches, and attachedContainers to the result. */
|
|
110
|
+
addClientInformation?: boolean;
|
|
111
|
+
}
|
|
112
|
+
/** Returned from 'CloudContainer.queryBcvStats' describing the rows in the bcv_stat table.
|
|
113
|
+
* Also gathers additional statistics using the other virtual tables bcv_container, bcv_database such as totalClients, ongoingPrefetches, activeClients and attachedContainers.
|
|
114
|
+
* @internal
|
|
115
|
+
*/
|
|
116
|
+
export interface BcvStats {
|
|
117
|
+
/** The total number of cache slots that are currently in use or 'locked' by ongoing client read transactions. In daemonless mode, this value is always 0.
|
|
118
|
+
* A locked cache slot implies that it is not eligible for eviction in the event of a full cachefile.
|
|
119
|
+
*/
|
|
120
|
+
readonly lockedCacheslots: number;
|
|
121
|
+
/** The current number of slots with data in them in the cache. */
|
|
122
|
+
readonly populatedCacheslots: number;
|
|
123
|
+
/** The configured size of the cache, in number of slots. */
|
|
124
|
+
readonly totalCacheslots: number;
|
|
125
|
+
/** The total number of clients opened on this cache */
|
|
126
|
+
readonly totalClients?: number;
|
|
127
|
+
/** The total number of ongoing prefetches on this cache */
|
|
128
|
+
readonly ongoingPrefetches?: number;
|
|
129
|
+
/** The total number of active clients on this cache. An active client is one which has an open read txn. */
|
|
130
|
+
readonly activeClients?: number;
|
|
131
|
+
/** The total number of attached containers on this cache. */
|
|
132
|
+
readonly attachedContainers?: number;
|
|
133
|
+
}
|
|
105
134
|
/** The name of a CloudSqlite database within a CloudContainer. */
|
|
106
|
-
interface DbNameProp {
|
|
135
|
+
export interface DbNameProp {
|
|
107
136
|
/** the name of the database within the CloudContainer.
|
|
108
137
|
* @note names of databases within a CloudContainer are always **case sensitive** on all platforms.*/
|
|
109
138
|
dbName: string;
|
|
110
139
|
}
|
|
111
140
|
/** Properties for accessing a database within a CloudContainer */
|
|
112
|
-
interface DbProps extends DbNameProp {
|
|
141
|
+
export interface DbProps extends DbNameProp {
|
|
113
142
|
/** the name of the local file to access the database. */
|
|
114
143
|
localFileName: LocalFileName;
|
|
115
144
|
}
|
|
116
|
-
type TransferDirection = "upload" | "download";
|
|
117
|
-
interface TransferProgress {
|
|
145
|
+
export type TransferDirection = "upload" | "download";
|
|
146
|
+
export interface TransferProgress {
|
|
118
147
|
/** a user-supplied progress function called during the transfer operation. Return a non-0 value to abort the transfer. */
|
|
119
148
|
onProgress?: (loaded: number, total: number) => number;
|
|
120
149
|
}
|
|
121
|
-
interface CloudHttpProps {
|
|
150
|
+
export interface CloudHttpProps {
|
|
122
151
|
/** The number of simultaneous HTTP requests. Default is 6. */
|
|
123
152
|
nRequests?: number;
|
|
124
153
|
}
|
|
125
|
-
interface PrefetchProps extends CloudHttpProps {
|
|
154
|
+
export interface PrefetchProps extends CloudHttpProps {
|
|
126
155
|
/** timeout between requests, in milliseconds. Default is 100. */
|
|
127
156
|
timeout?: number;
|
|
128
157
|
/** The number of prefetch requests to issue while there is foreground activity. Default is 3. */
|
|
129
158
|
minRequests?: number;
|
|
130
159
|
}
|
|
131
|
-
type TransferDbProps = DbProps & TransferProgress & CloudHttpProps;
|
|
160
|
+
export type TransferDbProps = DbProps & TransferProgress & CloudHttpProps;
|
|
132
161
|
/** Properties for creating a CloudCache. */
|
|
133
|
-
interface CacheProps extends CloudHttpProps {
|
|
162
|
+
export interface CacheProps extends CloudHttpProps {
|
|
134
163
|
/** full path of directory for cache to store its files. Must be on a (preferably fast) local drive, and must be empty when the cache is first created. */
|
|
135
164
|
rootDir: string;
|
|
136
165
|
/** name of this cache. It is possible to have more than one CloudCache in the same session, but each must have a unique name. */
|
|
@@ -141,7 +170,7 @@ export declare namespace CloudSqlite {
|
|
|
141
170
|
curlDiagnostics?: boolean;
|
|
142
171
|
}
|
|
143
172
|
/** Parameters used to obtain the write lock on a cloud container */
|
|
144
|
-
interface ObtainLockParams {
|
|
173
|
+
export interface ObtainLockParams {
|
|
145
174
|
/** a string that identifies me to others if I hold the lock while they attempt to acquire it. */
|
|
146
175
|
user?: string;
|
|
147
176
|
/** number of times to retry in the event the lock currently held by someone else.
|
|
@@ -157,7 +186,7 @@ export declare namespace CloudSqlite {
|
|
|
157
186
|
onFailure?: WriteLockBusyHandler;
|
|
158
187
|
}
|
|
159
188
|
/** @internal */
|
|
160
|
-
interface LockAndOpenArgs extends SQLiteDb.WithOpenDbArgs {
|
|
189
|
+
export interface LockAndOpenArgs extends SQLiteDb.WithOpenDbArgs {
|
|
161
190
|
/** a string that identifies me to others if I hold the lock while they attempt to acquire it. */
|
|
162
191
|
user: string;
|
|
163
192
|
/** the name of the database within the container */
|
|
@@ -170,7 +199,7 @@ export declare namespace CloudSqlite {
|
|
|
170
199
|
openMode?: OpenMode;
|
|
171
200
|
}
|
|
172
201
|
/** Logging categories for `CloudCache.setLogMask` */
|
|
173
|
-
enum LoggingMask {
|
|
202
|
+
export enum LoggingMask {
|
|
174
203
|
/** log all HTTP requests and responses */
|
|
175
204
|
HTTP = 1,
|
|
176
205
|
/** log as blocks become dirty and must be uploaded */
|
|
@@ -203,7 +232,7 @@ export declare namespace CloudSqlite {
|
|
|
203
232
|
* - The contents of the cache directory are entirely controlled by CloudSqlite and should be empty when the cache is
|
|
204
233
|
* first created and never modified directly thereafter.
|
|
205
234
|
*/
|
|
206
|
-
interface CloudCache {
|
|
235
|
+
export interface CloudCache {
|
|
207
236
|
/** `true` if this CloudCache is connected to a daemon process */
|
|
208
237
|
get isDaemon(): boolean;
|
|
209
238
|
/** The name for this CloudCache. */
|
|
@@ -241,7 +270,7 @@ export declare namespace CloudSqlite {
|
|
|
241
270
|
* - when a CloudContainer is created, it may either be readonly or writeable. If a container is never meant to be used for writes,
|
|
242
271
|
* it is slightly more efficient to indicate that by passing `writeable: false`
|
|
243
272
|
*/
|
|
244
|
-
interface CloudContainer {
|
|
273
|
+
export interface CloudContainer {
|
|
245
274
|
onConnect?: (container: CloudContainer, cache: CloudCache) => void;
|
|
246
275
|
onConnected?: (container: CloudContainer) => void;
|
|
247
276
|
onDisconnect?: (container: CloudContainer, detach: boolean) => void;
|
|
@@ -257,6 +286,10 @@ export declare namespace CloudSqlite {
|
|
|
257
286
|
get alias(): string;
|
|
258
287
|
/** The logId. */
|
|
259
288
|
get logId(): string;
|
|
289
|
+
/** The time that the write lock expires. Of the form 'YYYY-MM-DDTHH:MM:SS.000Z' in UTC.
|
|
290
|
+
* Returns empty string if write lock is not held.
|
|
291
|
+
*/
|
|
292
|
+
get writeLockExpires(): string;
|
|
260
293
|
/** true if this CloudContainer is currently connected to a CloudCache via the `connect` method. */
|
|
261
294
|
get isConnected(): boolean;
|
|
262
295
|
/** true if this CloudContainer was created with the `writeable` flag (and its `accessToken` supplies write access). */
|
|
@@ -386,6 +419,11 @@ export declare namespace CloudSqlite {
|
|
|
386
419
|
* @internal
|
|
387
420
|
*/
|
|
388
421
|
queryHttpLog(filterOptions?: BcvHttpLogFilterOptions): CloudSqlite.BcvHttpLog[];
|
|
422
|
+
/**
|
|
423
|
+
* query the bcv_stat table.
|
|
424
|
+
* @internal
|
|
425
|
+
*/
|
|
426
|
+
queryBcvStats(filterOptions?: BcvStatsFilterOptions): CloudSqlite.BcvStats;
|
|
389
427
|
/**
|
|
390
428
|
* Get the SHA1 hash of the content of a database.
|
|
391
429
|
* @param dbName the name of the database of interest
|
|
@@ -397,7 +435,7 @@ export declare namespace CloudSqlite {
|
|
|
397
435
|
* Object returned by [[CloudSqlite.startCloudPrefetch]].
|
|
398
436
|
* It holds a promise that is fulfilled when a Prefetch is completed. May also be used to cancel an in-progress prefetch.
|
|
399
437
|
*/
|
|
400
|
-
interface CloudPrefetch {
|
|
438
|
+
export interface CloudPrefetch {
|
|
401
439
|
readonly cloudContainer: CloudContainer;
|
|
402
440
|
readonly dbName: string;
|
|
403
441
|
/** Cancel a currently pending prefetch. The promise will be resolved immediately after this call. */
|
|
@@ -414,13 +452,13 @@ export declare namespace CloudSqlite {
|
|
|
414
452
|
promise: Promise<boolean>;
|
|
415
453
|
}
|
|
416
454
|
/** @internal */
|
|
417
|
-
function transferDb(direction: TransferDirection, container: CloudContainer, props: TransferDbProps): Promise<void>;
|
|
455
|
+
export function transferDb(direction: TransferDirection, container: CloudContainer, props: TransferDbProps): Promise<void>;
|
|
418
456
|
/** Upload a local SQLite database file into a CloudContainer.
|
|
419
457
|
* @param container the CloudContainer holding the database. Must be connected.
|
|
420
458
|
* @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.
|
|
421
459
|
* @note this function requires that the write lock be held on the container
|
|
422
460
|
*/
|
|
423
|
-
function uploadDb(container: CloudContainer, props: TransferDbProps): Promise<void>;
|
|
461
|
+
export function uploadDb(container: CloudContainer, props: TransferDbProps): Promise<void>;
|
|
424
462
|
/** Download a database from a CloudContainer.
|
|
425
463
|
* @param container the CloudContainer holding the database. Must be connected.
|
|
426
464
|
* @param props the properties that describe the database to be downloaded, plus optionally an `onProgress` function.
|
|
@@ -428,30 +466,30 @@ export declare namespace CloudSqlite {
|
|
|
428
466
|
* @note the download is "restartable." If the transfer is aborted and then re-requested, it will continue from where
|
|
429
467
|
* it left off rather than re-downloading the entire file.
|
|
430
468
|
*/
|
|
431
|
-
function downloadDb(container: CloudContainer, props: TransferDbProps): Promise<void>;
|
|
469
|
+
export function downloadDb(container: CloudContainer, props: TransferDbProps): Promise<void>;
|
|
432
470
|
/** Optional method to be called when an attempt to acquire the write lock fails because another user currently holds it.
|
|
433
471
|
* @param lockedBy The identifier supplied by the application/user that currently holds the lock.
|
|
434
472
|
* @param expires a stringified Date (in local time) indicating when the lock will expire.
|
|
435
473
|
* @return "stop" to give up and stop retrying. Generally, it's a good idea to wait for some time before returning.
|
|
436
474
|
*/
|
|
437
|
-
type WriteLockBusyHandler = (lockedBy: string, expires: string) => Promise<void | "stop">;
|
|
475
|
+
export type WriteLockBusyHandler = (lockedBy: string, expires: string) => Promise<void | "stop">;
|
|
438
476
|
/**
|
|
439
477
|
* Attempt to acquire the write lock for a container, with retries.
|
|
440
478
|
* If write lock is held by another user, call busyHandler if supplied. If no busyHandler, or handler returns "stop", throw. Otherwise try again.
|
|
441
|
-
* @note if write lock is already held, this function
|
|
479
|
+
* @note if write lock is already held by the same user, this function will refresh the write lock's expiry time.
|
|
442
480
|
* @param user the name to be displayed to other users in the event they attempt to obtain the lock while it is held by us
|
|
443
481
|
* @param container the CloudContainer for which the lock is to be acquired
|
|
444
482
|
* @param busyHandler if present, function called when the write lock is currently held by another user.
|
|
445
483
|
* @throws if [[container]] is not connected to a CloudCache.
|
|
446
484
|
*/
|
|
447
|
-
function acquireWriteLock(args: {
|
|
485
|
+
export function acquireWriteLock(args: {
|
|
448
486
|
user: string;
|
|
449
487
|
container: CloudContainer;
|
|
450
488
|
busyHandler?: WriteLockBusyHandler;
|
|
451
489
|
}): Promise<void>;
|
|
452
490
|
/**
|
|
453
491
|
* Perform an asynchronous write operation on a CloudContainer with the write lock held.
|
|
454
|
-
* 1. if write lock is already held by the current user, call operation and return.
|
|
492
|
+
* 1. if write lock is already held by the current user, refresh write lock's expiry time, call operation and return.
|
|
455
493
|
* 2. attempt to acquire the write lock, with retries. Throw if unable to obtain write lock.
|
|
456
494
|
* 3. perform the operation
|
|
457
495
|
* 3.a if the operation throws, abandon all changes and re-throw
|
|
@@ -463,13 +501,13 @@ export declare namespace CloudSqlite {
|
|
|
463
501
|
* @param busyHandler if present, function called when the write lock is currently held by another user.
|
|
464
502
|
* @returns a Promise with the result of `operation`
|
|
465
503
|
*/
|
|
466
|
-
function withWriteLock<T>(args: {
|
|
504
|
+
export function withWriteLock<T>(args: {
|
|
467
505
|
user: string;
|
|
468
506
|
container: CloudContainer;
|
|
469
507
|
busyHandler?: WriteLockBusyHandler;
|
|
470
508
|
}, operation: () => Promise<T>): Promise<T>;
|
|
471
509
|
/** Arguments to create or find a CloudCache */
|
|
472
|
-
interface CreateCloudCacheArg {
|
|
510
|
+
export interface CreateCloudCacheArg {
|
|
473
511
|
/** The name of the CloudCache. CloudCache names must be unique. */
|
|
474
512
|
cacheName: string;
|
|
475
513
|
/** A string that specifies the maximum size of the CloudCache. It should be a number followed by "K",
|
|
@@ -481,7 +519,7 @@ export declare namespace CloudSqlite {
|
|
|
481
519
|
cacheDir?: string;
|
|
482
520
|
}
|
|
483
521
|
/** The collection of currently extant `CloudCache`s, by name. */
|
|
484
|
-
class CloudCaches {
|
|
522
|
+
export class CloudCaches {
|
|
485
523
|
private static readonly cloudCaches;
|
|
486
524
|
/** create a new CloudCache */
|
|
487
525
|
private static makeCache;
|
|
@@ -497,7 +535,7 @@ export declare namespace CloudSqlite {
|
|
|
497
535
|
static getCache(args: CreateCloudCacheArg): CloudCache;
|
|
498
536
|
}
|
|
499
537
|
/** Class that provides convenient local access to a SQLite database in a CloudContainer. */
|
|
500
|
-
class DbAccess<DbType extends VersionedSqliteDb, ReadMethods = DbType, WriteMethods = DbType> {
|
|
538
|
+
export class DbAccess<DbType extends VersionedSqliteDb, ReadMethods = DbType, WriteMethods = DbType> {
|
|
501
539
|
/** The name of the database within the cloud container. */
|
|
502
540
|
readonly dbName: string;
|
|
503
541
|
/** Parameters for obtaining the write lock for this container. */
|
|
@@ -603,5 +641,6 @@ export declare namespace CloudSqlite {
|
|
|
603
641
|
*/
|
|
604
642
|
get reader(): PickMethods<ReadMethods>;
|
|
605
643
|
}
|
|
644
|
+
export {};
|
|
606
645
|
}
|
|
607
646
|
//# sourceMappingURL=CloudSqlite.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CloudSqlite.d.ts","sourceRoot":"","sources":["../../src/CloudSqlite.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,EACL,WAAW,EAA+B,WAAW,EAAE,UAAU,EAAU,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,EAAE,WAAW,EAC7H,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAKvD,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAI9D;;;GAGG;AACH,yBAAiB,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AAC,SAAS,CAAC,EAAE,KAAK,GAAG,IAAI,CAAA;SAAE;QAatJ;;;;;;;WAOG;QACI,oBAAoB;QAK3B;;;WAGG;QACI,WAAW,IAAI,MAAM;QAM5B;;;;;;;;WAQG;QACU,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE;YAAE,aAAa,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;QAmC1I,wFAAwF;QACxF,OAAO,CAAC,WAAW;QAOnB;;;;;;;;;;;;WAYG;QACH,IAAW,WAAW,mCAOrB;QAED;;;WAGG;QACH,IAAW,MAAM,6BAOhB;KACF;;CACF"}
|
package/lib/cjs/CloudSqlite.js
CHANGED
|
@@ -156,7 +156,7 @@ var CloudSqlite;
|
|
|
156
156
|
/**
|
|
157
157
|
* Attempt to acquire the write lock for a container, with retries.
|
|
158
158
|
* If write lock is held by another user, call busyHandler if supplied. If no busyHandler, or handler returns "stop", throw. Otherwise try again.
|
|
159
|
-
* @note if write lock is already held, this function
|
|
159
|
+
* @note if write lock is already held by the same user, this function will refresh the write lock's expiry time.
|
|
160
160
|
* @param user the name to be displayed to other users in the event they attempt to obtain the lock while it is held by us
|
|
161
161
|
* @param container the CloudContainer for which the lock is to be acquired
|
|
162
162
|
* @param busyHandler if present, function called when the write lock is currently held by another user.
|
|
@@ -167,8 +167,9 @@ var CloudSqlite;
|
|
|
167
167
|
while (true) {
|
|
168
168
|
try {
|
|
169
169
|
if (container.hasWriteLock) {
|
|
170
|
-
if (container.writeLockHeldBy === args.user)
|
|
171
|
-
return; //
|
|
170
|
+
if (container.writeLockHeldBy === args.user) {
|
|
171
|
+
return container.acquireWriteLock(args.user); // refresh the write lock's expiry time.
|
|
172
|
+
}
|
|
172
173
|
const err = new Error(); // lock held by another user within this process
|
|
173
174
|
err.errorNumber = 5;
|
|
174
175
|
err.lockedBy = container.writeLockHeldBy;
|
|
@@ -187,7 +188,7 @@ var CloudSqlite;
|
|
|
187
188
|
CloudSqlite.acquireWriteLock = acquireWriteLock;
|
|
188
189
|
/**
|
|
189
190
|
* Perform an asynchronous write operation on a CloudContainer with the write lock held.
|
|
190
|
-
* 1. if write lock is already held by the current user, call operation and return.
|
|
191
|
+
* 1. if write lock is already held by the current user, refresh write lock's expiry time, call operation and return.
|
|
191
192
|
* 2. attempt to acquire the write lock, with retries. Throw if unable to obtain write lock.
|
|
192
193
|
* 3. perform the operation
|
|
193
194
|
* 3.a if the operation throws, abandon all changes and re-throw
|
|
@@ -206,18 +207,15 @@ var CloudSqlite;
|
|
|
206
207
|
if (containerInternal.writeLockHeldBy === args.user) // If the user already had the write lock, then don't release it.
|
|
207
208
|
return await operation();
|
|
208
209
|
containerInternal.writeLockHeldBy = args.user;
|
|
209
|
-
containerInternal.writeLockExpires = new Date(Date.now() + 1000 * containerInternal.lockExpireSeconds).toLocaleString();
|
|
210
210
|
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
211
211
|
const val = await operation(); // wait for work to finish or fail
|
|
212
212
|
containerInternal.releaseWriteLock();
|
|
213
213
|
containerInternal.writeLockHeldBy = undefined;
|
|
214
|
-
containerInternal.writeLockExpires = undefined;
|
|
215
214
|
return val;
|
|
216
215
|
}
|
|
217
216
|
catch (e) {
|
|
218
217
|
args.container.abandonChanges(); // if operation threw, abandon all changes
|
|
219
218
|
containerInternal.writeLockHeldBy = undefined;
|
|
220
|
-
containerInternal.writeLockExpires = undefined;
|
|
221
219
|
throw e;
|
|
222
220
|
}
|
|
223
221
|
}
|