@itwin/core-backend 4.2.0-dev.8 → 4.3.0-dev.0

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +57 -1
  2. package/lib/cjs/BlobContainerService.d.ts +6 -2
  3. package/lib/cjs/BlobContainerService.d.ts.map +1 -1
  4. package/lib/cjs/BlobContainerService.js.map +1 -1
  5. package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
  6. package/lib/cjs/BriefcaseManager.js +5 -1
  7. package/lib/cjs/BriefcaseManager.js.map +1 -1
  8. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  9. package/lib/cjs/CheckpointManager.js +6 -3
  10. package/lib/cjs/CheckpointManager.js.map +1 -1
  11. package/lib/cjs/CloudSqlite.d.ts +79 -34
  12. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  13. package/lib/cjs/CloudSqlite.js +7 -9
  14. package/lib/cjs/CloudSqlite.js.map +1 -1
  15. package/lib/cjs/IModelDb.d.ts +23 -4
  16. package/lib/cjs/IModelDb.d.ts.map +1 -1
  17. package/lib/cjs/IModelDb.js +171 -42
  18. package/lib/cjs/IModelDb.js.map +1 -1
  19. package/lib/cjs/SQLiteDb.js +1 -1
  20. package/lib/cjs/SQLiteDb.js.map +1 -1
  21. package/lib/cjs/SchemaSync.d.ts +41 -0
  22. package/lib/cjs/SchemaSync.d.ts.map +1 -0
  23. package/lib/cjs/SchemaSync.js +77 -0
  24. package/lib/cjs/SchemaSync.js.map +1 -0
  25. package/lib/cjs/SchemaUtils.d.ts.map +1 -1
  26. package/lib/cjs/SchemaUtils.js +3 -3
  27. package/lib/cjs/SchemaUtils.js.map +1 -1
  28. package/lib/cjs/TileStorage.d.ts +16 -5
  29. package/lib/cjs/TileStorage.d.ts.map +1 -1
  30. package/lib/cjs/TileStorage.js +34 -3
  31. package/lib/cjs/TileStorage.js.map +1 -1
  32. package/lib/cjs/TxnManager.d.ts +41 -0
  33. package/lib/cjs/TxnManager.d.ts.map +1 -1
  34. package/lib/cjs/TxnManager.js +38 -0
  35. package/lib/cjs/TxnManager.js.map +1 -1
  36. package/lib/cjs/core-backend.d.ts +1 -0
  37. package/lib/cjs/core-backend.d.ts.map +1 -1
  38. package/lib/cjs/core-backend.js +1 -0
  39. package/lib/cjs/core-backend.js.map +1 -1
  40. package/package.json +18 -15
package/CHANGELOG.md CHANGED
@@ -1,6 +1,47 @@
1
1
  # Change Log - @itwin/core-backend
2
2
 
3
- This log was last generated on Tue, 15 Aug 2023 19:39:59 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 29 Sep 2023 18:24:48 GMT and should not be manually modified.
4
+
5
+ ## 4.1.7
6
+ Thu, 28 Sep 2023 21:41:33 GMT
7
+
8
+ _Version update only_
9
+
10
+ ## 4.1.6
11
+ Tue, 12 Sep 2023 15:38:52 GMT
12
+
13
+ _Version update only_
14
+
15
+ ## 4.1.5
16
+ Fri, 08 Sep 2023 13:37:23 GMT
17
+
18
+ _Version update only_
19
+
20
+ ## 4.1.4
21
+ Thu, 07 Sep 2023 18:26:02 GMT
22
+
23
+ ### Updates
24
+
25
+ - restart default txn after 10 minutes inactivity on v2 checkpoints
26
+
27
+ ## 4.1.3
28
+ Wed, 30 Aug 2023 15:35:27 GMT
29
+
30
+ _Version update only_
31
+
32
+ ## 4.1.2
33
+ Wed, 23 Aug 2023 15:25:29 GMT
34
+
35
+ ### Updates
36
+
37
+ - add TileStorage.getCachedTilesGenerator
38
+
39
+ ## 4.1.1
40
+ Fri, 18 Aug 2023 13:02:53 GMT
41
+
42
+ ### Updates
43
+
44
+ - add `internal` `codeValueBehavior` API
4
45
 
5
46
  ## 4.1.0
6
47
  Mon, 14 Aug 2023 14:36:34 GMT
@@ -91,6 +132,21 @@ Mon, 22 May 2023 15:34:14 GMT
91
132
  - allow passing a custom schema read context to IModelDb.importSchemas
92
133
  - Added test to verify Id serialization to hex for system properties.
93
134
 
135
+ ## 3.7.14
136
+ Fri, 29 Sep 2023 16:57:16 GMT
137
+
138
+ _Version update only_
139
+
140
+ ## 3.7.13
141
+ Tue, 08 Aug 2023 19:49:18 GMT
142
+
143
+ _Version update only_
144
+
145
+ ## 3.7.12
146
+ Thu, 27 Jul 2023 21:50:57 GMT
147
+
148
+ _Version update only_
149
+
94
150
  ## 3.7.11
95
151
  Tue, 11 Jul 2023 17:17:21 GMT
96
152
 
@@ -77,6 +77,11 @@ export declare namespace BlobContainer {
77
77
  interface AccessContainerProps extends UriAndId {
78
78
  userToken: UserToken;
79
79
  }
80
+ /** Information about a newly created container. */
81
+ interface CreatedContainerProps extends UriAndId {
82
+ /** name of the blob storage provider. */
83
+ provider: Provider;
84
+ }
80
85
  /**
81
86
  * Access level to request for token.
82
87
  * - `"write"`: request a writeable AccessToken.
@@ -88,7 +93,6 @@ export declare namespace BlobContainer {
88
93
  type RequestAccessLevel = "write" | "read" | "admin" | "writeIfPossible";
89
94
  /** Information required to request an access token for a container. */
90
95
  interface RequestTokenProps extends AccessContainerProps {
91
- storageType: Provider;
92
96
  /** the level of access requested. If not specified, defaults to `"writeIfPossible"`. */
93
97
  accessLevel?: RequestAccessLevel;
94
98
  /** the number of seconds before the token should expire.
@@ -113,7 +117,7 @@ export declare namespace BlobContainer {
113
117
  /** Methods to create, delete, and access blob containers. */
114
118
  interface ContainerService {
115
119
  /** Create a new blob container. Throws on failure (e.g. access denied or container already exists.) */
116
- create(props: CreateNewContainerProps): Promise<UriAndId>;
120
+ create(props: CreateNewContainerProps): Promise<CreatedContainerProps>;
117
121
  /**
118
122
  * Delete an existing blob container.
119
123
  * @note This method requires that the user be authorized with "delete container" RBAC role for the iTwin.
@@ -1 +1 @@
1
- {"version":3,"file":"BlobContainerService.d.ts","sourceRoot":"","sources":["../../src/BlobContainerService.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAA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CAAC;QAEhF,qEAAqE;QACrE,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;KAC7D;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"BlobContainerService.js","sourceRoot":"","sources":["../../src/BlobContainerService.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAOH;;;GAGG;AACH,IAAiB,aAAa,CA4I7B;AA5ID,WAAiB,aAAa;AA4I9B,CAAC,EA5IgB,aAAa,GAAb,qBAAa,KAAb,qBAAa,QA4I7B","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 BlobContainers\r\n */\r\n\r\n// spell:ignore datacenter\r\n\r\nimport { AccessToken, GuidString, Id64String } from \"@itwin/core-bentley\";\r\nimport { SettingObject } from \"./workspace/Settings\";\r\n\r\n/**\r\n * Types and functions for creating, deleting and authorizing access to cloud-based blob containers for an iTwin.\r\n * @beta\r\n */\r\nexport namespace BlobContainer {\r\n\r\n /** Object that implements the methods to create, delete, and request access to a container. */\r\n export let service: BlobContainer.ContainerService | undefined;\r\n\r\n /** name of cloud provider for a container. */\r\n export type Provider = \"azure\" | \"google\";\r\n\r\n /** the name of the container within its `Scope` */\r\n export type ContainerId = string;\r\n\r\n /** token that authenticates a user. This token is required to obtain a `ContainerToken`. */\r\n export type UserToken = AccessToken;\r\n\r\n /** token that authenticates access to a container for either read or write. */\r\n export type ContainerToken = AccessToken;\r\n\r\n /**\r\n * The scope for a container. This determines:\r\n * - the \"owner\" organization, including the contract that governs its legal and commercial terms and obligations\r\n * - the administrators who may configure RBAC permissions\r\n * - the datacenter for the container. Every container resides in a datacenter as determined by the iTwinId. This\r\n * determines the region for data residency requirements.\r\n * - the lifecycle constraints for the container. No container can outlive its iTwin or its iModel (if defined). That is,\r\n * when the iTwin/iModel is deleted (either explicitly or due to contract expiration), the container is also deleted.\r\n */\r\n export interface Scope {\r\n /** iTwinId of the owner of this container. */\r\n iTwinId: Id64String;\r\n /** optionally, an iModelId within the iTwin. If present, container is deleted when the iModel is deleted. */\r\n iModelId?: Id64String;\r\n /** the user GUID an individual, if this container is private. */\r\n ownerGuid?: GuidString;\r\n }\r\n\r\n /**\r\n * Metadata about the use of a container so that:\r\n * - administrators can understand why a container exists for assigning RBAC permissions appropriately\r\n * - usage reports can aggregate types of containers\r\n * - applications can identify their containers\r\n * - applications can store properties about their containers\r\n */\r\n export interface Metadata {\r\n /** The machine-readable string that describes what the container is being used for (e.g. \"workspace\"). Always lowercase and singular. */\r\n containerType: string;\r\n /** Human-readable name for the container. This will be displayed in the administrator RBAC panel, and on usage reports. Not required to be unique.*/\r\n label: string;\r\n /** Optional human-readable explanation of the information held in the container. This will be displayed in the administrator RBAC panel, and on usage reports. */\r\n description?: string;\r\n /** optional properties for the container */\r\n json?: SettingObject;\r\n }\r\n\r\n /** Properties returned by `Service.requestToken` */\r\n export interface TokenProps {\r\n /**\r\n * expiring token that provides the requested access to the container. Should be used in all subsequent requests for blobs within the container,\r\n * and must be refreshed before it expires\r\n */\r\n token: ContainerToken;\r\n /** scope of the container. */\r\n scope: Scope;\r\n /** name of the blob storage provider. */\r\n provider: Provider;\r\n /** Time at which the token will expire. The token should be refreshed (that is, a new token should be requested) before this time. */\r\n expiration: Date;\r\n /** Metadata of the container. */\r\n metadata: Metadata;\r\n }\r\n\r\n /** The URI and Id of the container. */\r\n export interface UriAndId {\r\n baseUri: string;\r\n containerId: ContainerId;\r\n }\r\n\r\n /** Information required to access an existing container. */\r\n export interface AccessContainerProps extends UriAndId {\r\n userToken: UserToken;\r\n }\r\n\r\n /**\r\n * Access level to request for token.\r\n * - `\"write\"`: request a writeable AccessToken.\r\n * - `\"read\"`: request a read-only AccessToken.\r\n * - `\"admin\"`: request a admin AccessToken.\r\n * - `\"writeIfPossible\"`: first request a writeable AccessToken. If the user is not authorized for write, request a read-only AccessToken.\r\n * If the user is not authorized for the level requested, an exception is thrown.\r\n */\r\n export type RequestAccessLevel = \"write\" | \"read\" | \"admin\" | \"writeIfPossible\";\r\n\r\n /** Information required to request an access token for a container. */\r\n export interface RequestTokenProps extends AccessContainerProps {\r\n storageType: Provider;\r\n /** the level of access requested. If not specified, defaults to `\"writeIfPossible\"`. */\r\n accessLevel?: RequestAccessLevel;\r\n /** the number of seconds before the token should expire.\r\n * @note A maximum duration is determined by the service. If no value is supplied, or the value is larger than the maximum, the maximum duration is used.\r\n */\r\n durationSeconds?: number;\r\n }\r\n\r\n /** Information required to create a new container. */\r\n export interface CreateNewContainerProps {\r\n /** the scope of the new container */\r\n scope: Scope;\r\n /** metadata to be stored on the new container */\r\n metadata: Metadata;\r\n /** The user's access token. The user must be authorized with \"create container\" RBAC role for the iTwin. */\r\n userToken: UserToken;\r\n /**\r\n * the id for the container. Useful for tests.\r\n * @internal\r\n */\r\n containerId?: ContainerId;\r\n }\r\n\r\n /** Methods to create, delete, and access blob containers. */\r\n export interface ContainerService {\r\n /** Create a new blob container. Throws on failure (e.g. access denied or container already exists.) */\r\n create(props: CreateNewContainerProps): Promise<UriAndId>;\r\n\r\n /**\r\n * Delete an existing blob container.\r\n * @note This method requires that the user be authorized with \"delete container\" RBAC role for the iTwin.\r\n */\r\n delete(container: AccessContainerProps): Promise<void>;\r\n\r\n /** query the Scope for a container */\r\n queryScope(container: AccessContainerProps): Promise<Scope>;\r\n\r\n /** query the Metadata for a container */\r\n queryMetadata(container: AccessContainerProps): Promise<Metadata>;\r\n\r\n /** update the json properties of this container */\r\n updateJson(container: AccessContainerProps, json: SettingObject): Promise<void>;\r\n\r\n /** Request a `ContainerToken` for a container. Throws on failure. */\r\n requestToken(props: RequestTokenProps): Promise<TokenProps>;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"BlobContainerService.js","sourceRoot":"","sources":["../../src/BlobContainerService.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAOH;;;GAGG;AACH,IAAiB,aAAa,CAiJ7B;AAjJD,WAAiB,aAAa;AAiJ9B,CAAC,EAjJgB,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAiJ7B","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 BlobContainers\r\n */\r\n\r\n// spell:ignore datacenter\r\n\r\nimport { AccessToken, GuidString, Id64String } from \"@itwin/core-bentley\";\r\nimport { SettingObject } from \"./workspace/Settings\";\r\n\r\n/**\r\n * Types and functions for creating, deleting and authorizing access to cloud-based blob containers for an iTwin.\r\n * @beta\r\n */\r\nexport namespace BlobContainer {\r\n\r\n /** Object that implements the methods to create, delete, and request access to a container. */\r\n export let service: BlobContainer.ContainerService | undefined;\r\n\r\n /** name of cloud provider for a container. */\r\n export type Provider = \"azure\" | \"google\";\r\n\r\n /** the name of the container within its `Scope` */\r\n export type ContainerId = string;\r\n\r\n /** token that authenticates a user. This token is required to obtain a `ContainerToken`. */\r\n export type UserToken = AccessToken;\r\n\r\n /** token that authenticates access to a container for either read or write. */\r\n export type ContainerToken = AccessToken;\r\n\r\n /**\r\n * The scope for a container. This determines:\r\n * - the \"owner\" organization, including the contract that governs its legal and commercial terms and obligations\r\n * - the administrators who may configure RBAC permissions\r\n * - the datacenter for the container. Every container resides in a datacenter as determined by the iTwinId. This\r\n * determines the region for data residency requirements.\r\n * - the lifecycle constraints for the container. No container can outlive its iTwin or its iModel (if defined). That is,\r\n * when the iTwin/iModel is deleted (either explicitly or due to contract expiration), the container is also deleted.\r\n */\r\n export interface Scope {\r\n /** iTwinId of the owner of this container. */\r\n iTwinId: Id64String;\r\n /** optionally, an iModelId within the iTwin. If present, container is deleted when the iModel is deleted. */\r\n iModelId?: Id64String;\r\n /** the user GUID an individual, if this container is private. */\r\n ownerGuid?: GuidString;\r\n }\r\n\r\n /**\r\n * Metadata about the use of a container so that:\r\n * - administrators can understand why a container exists for assigning RBAC permissions appropriately\r\n * - usage reports can aggregate types of containers\r\n * - applications can identify their containers\r\n * - applications can store properties about their containers\r\n */\r\n export interface Metadata {\r\n /** The machine-readable string that describes what the container is being used for (e.g. \"workspace\"). Always lowercase and singular. */\r\n containerType: string;\r\n /** Human-readable name for the container. This will be displayed in the administrator RBAC panel, and on usage reports. Not required to be unique.*/\r\n label: string;\r\n /** Optional human-readable explanation of the information held in the container. This will be displayed in the administrator RBAC panel, and on usage reports. */\r\n description?: string;\r\n /** optional properties for the container */\r\n json?: SettingObject;\r\n }\r\n\r\n /** Properties returned by `Service.requestToken` */\r\n export interface TokenProps {\r\n /**\r\n * expiring token that provides the requested access to the container. Should be used in all subsequent requests for blobs within the container,\r\n * and must be refreshed before it expires\r\n */\r\n token: ContainerToken;\r\n /** scope of the container. */\r\n scope: Scope;\r\n /** name of the blob storage provider. */\r\n provider: Provider;\r\n /** Time at which the token will expire. The token should be refreshed (that is, a new token should be requested) before this time. */\r\n expiration: Date;\r\n /** Metadata of the container. */\r\n metadata: Metadata;\r\n }\r\n\r\n /** The URI and Id of the container. */\r\n export interface UriAndId {\r\n baseUri: string;\r\n containerId: ContainerId;\r\n }\r\n\r\n /** Information required to access an existing container. */\r\n export interface AccessContainerProps extends UriAndId {\r\n userToken: UserToken;\r\n }\r\n\r\n /** Information about a newly created container. */\r\n export interface CreatedContainerProps extends UriAndId {\r\n /** name of the blob storage provider. */\r\n provider: Provider;\r\n }\r\n\r\n /**\r\n * Access level to request for token.\r\n * - `\"write\"`: request a writeable AccessToken.\r\n * - `\"read\"`: request a read-only AccessToken.\r\n * - `\"admin\"`: request a admin AccessToken.\r\n * - `\"writeIfPossible\"`: first request a writeable AccessToken. If the user is not authorized for write, request a read-only AccessToken.\r\n * If the user is not authorized for the level requested, an exception is thrown.\r\n */\r\n export type RequestAccessLevel = \"write\" | \"read\" | \"admin\" | \"writeIfPossible\";\r\n\r\n /** Information required to request an access token for a container. */\r\n export interface RequestTokenProps extends AccessContainerProps {\r\n /** the level of access requested. If not specified, defaults to `\"writeIfPossible\"`. */\r\n accessLevel?: RequestAccessLevel;\r\n /** the number of seconds before the token should expire.\r\n * @note A maximum duration is determined by the service. If no value is supplied, or the value is larger than the maximum, the maximum duration is used.\r\n */\r\n durationSeconds?: number;\r\n }\r\n\r\n /** Information required to create a new container. */\r\n export interface CreateNewContainerProps {\r\n /** the scope of the new container */\r\n scope: Scope;\r\n /** metadata to be stored on the new container */\r\n metadata: Metadata;\r\n /** The user's access token. The user must be authorized with \"create container\" RBAC role for the iTwin. */\r\n userToken: UserToken;\r\n /**\r\n * the id for the container. Useful for tests.\r\n * @internal\r\n */\r\n containerId?: ContainerId;\r\n }\r\n\r\n /** Methods to create, delete, and access blob containers. */\r\n export interface ContainerService {\r\n /** Create a new blob container. Throws on failure (e.g. access denied or container already exists.) */\r\n create(props: CreateNewContainerProps): Promise<CreatedContainerProps>;\r\n\r\n /**\r\n * Delete an existing blob container.\r\n * @note This method requires that the user be authorized with \"delete container\" RBAC role for the iTwin.\r\n */\r\n delete(container: AccessContainerProps): Promise<void>;\r\n\r\n /** query the Scope for a container */\r\n queryScope(container: AccessContainerProps): Promise<Scope>;\r\n\r\n /** query the Metadata for a container */\r\n queryMetadata(container: AccessContainerProps): Promise<Metadata>;\r\n\r\n /** update the json properties of this container */\r\n updateJson(container: AccessContainerProps, json: SettingObject): Promise<void>;\r\n\r\n /** Request a `ContainerToken` for a container. Throws on failure. */\r\n requestToken(props: RequestTokenProps): Promise<TokenProps>;\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"BriefcaseManager.d.ts","sourceRoot":"","sources":["../../src/BriefcaseManager.ts"],"names":[],"mappings":"AAIA;;GAEG;AAKH,OAAO,EACL,WAAW,EAAE,UAAU,EAAmB,UAAU,EACrD,MAAM,qBAA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clC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAenC,4EAA4E;WACxD,cAAc,CAAC,GAAG,EAAE;QAAE,QAAQ,EAAE,UAAU,CAAC;QAAC,SAAS,EAAE,kBAAkB,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAIzH,gFAAgF;WAC5D,eAAe,CAAC,GAAG,EAAE;QAAE,QAAQ,EAAE,UAAU,CAAC;QAAC,KAAK,EAAE,cAAc,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAIpH,wEAAwE;WACpD,kBAAkB,CAAC,GAAG,EAAE;QAAE,QAAQ,EAAE,UAAU,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAI9F;;;OAGG;WACiB,iBAAiB,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAI1F;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,uBAAuB;mBAajB,oBAAoB;IAWzC,gBAAgB;WACI,sBAAsB,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAmC7F,4EAA4E;mBACvD,WAAW;IA4ChC;;OAEG;WACiB,aAAa,CAAC,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAcxF"}
@@ -345,8 +345,12 @@ class BriefcaseManager {
345
345
  return; // nothing to apply
346
346
  if (reverse)
347
347
  changesets.reverse();
348
- for (const changeset of changesets)
348
+ for (const changeset of changesets) {
349
+ const stopwatch = new core_bentley_1.StopWatch(`[${changeset.id}]`, true);
350
+ core_bentley_1.Logger.logInfo(loggerCategory, `Starting application of changeset with id ${stopwatch.description}`);
349
351
  await this.applySingleChangeset(db, changeset);
352
+ core_bentley_1.Logger.logInfo(loggerCategory, `Applied changeset with id ${stopwatch.description} (${stopwatch.elapsedSeconds} seconds)`);
353
+ }
350
354
  // notify listeners
351
355
  db.notifyChangesetApplied();
352
356
  }
@@ -1 +1 @@
1
- {"version":3,"file":"BriefcaseManager.js","sourceRoot":"","sources":["../../src/BriefcaseManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,qCAAqC;AAErC,6BAA6B;AAC7B,sDAE6B;AAC7B,oDAG4B;AAE5B,mEAAgE;AAChE,2DAA2F;AAC3F,yCAA6D;AAC7D,6CAA0C;AAC1C,6CAA0C;AAE1C,MAAM,cAAc,GAAG,6CAAqB,CAAC,QAAQ,CAAC;AAkDtD;;GAEG;AACH,MAAa,gBAAgB;IAC3B,wFAAwF;IACjF,MAAM,CAAC,aAAa,CAAC,QAAoB,IAAkB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE/G,gBAAgB;IACT,MAAM,CAAC,iBAAiB,CAAC,QAAoB,IAAkB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAErI,gBAAgB;IACT,MAAM,CAAC,sBAAsB,CAAC,QAAoB,IAAmB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;IAEhK,gBAAgB;IACT,MAAM,CAAC,0BAA0B,CAAC,QAAoB,IAAmB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAGhK,gGAAgG;IACzF,MAAM,CAAC,oBAAoB,CAAC,QAAoB;QACrD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,EA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vB,KAAK,8BAAe,CAAC,kBAAkB,CAAC;wBACxC,KAAK,8BAAe,CAAC,yBAAyB,CAAC;wBAC/C,KAAK,8BAAe,CAAC,eAAe;4BAClC,OAAO,IAAI,CAAC;qBACf;oBACD,OAAO,KAAK,CAAC;gBACf,CAAC,CAAC;gBAEF,IAAI,CAAC,WAAW,EAAE,EAAE;oBAClB,EAAE,CAAC,QAAQ,CAAC,sBAAsB,EAAE,CAAC;oBACrC,MAAM,GAAG,CAAC;iBACX;aACF;oBAAS;gBACR,uBAAU,CAAC,UAAU,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;aAChD;SACF;IACH,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,EAAe,EAAE,GAAoB;QACrE,IAAI,UAAU,GAAG,GAAG,CAAC,eAAe,IAAI,CAAC,CAAC;QAC1C,OAAO,IAAI,EAAE;YACX,IAAI;gBACF,MAAM,gBAAgB,CAAC,sBAAsB,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;gBACvD,OAAO,MAAM,gBAAgB,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;aACpD;YAAC,OAAO,GAAQ,EAAE;gBACjB,IAAI,UAAU,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,WAAW,KAAK,8BAAe,CAAC,cAAc;oBACzE,MAAM,CAAC,GAAG,CAAC,CAAC;gBACd,MAAM,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aACjE;SACF;IACH,CAAC;;AAnac,iCAAgB,GAAG,YAAY,CAAC;AAbpC,4CAAgB","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 cset csets ecchanges\r\n\r\nimport * as path from \"path\";\r\nimport {\r\n AccessToken, BeDuration, ChangeSetStatus, GuidString, IModelHubStatus, IModelStatus, Logger, OpenMode,\r\n} from \"@itwin/core-bentley\";\r\nimport {\r\n BriefcaseId, BriefcaseIdValue, BriefcaseProps, ChangesetFileProps, ChangesetIndex, ChangesetIndexOrId, ChangesetProps, ChangesetRange, ChangesetType, IModelError, IModelVersion, LocalBriefcaseProps,\r\n LocalDirName, LocalFileName, RequestNewBriefcaseProps,\r\n} from \"@itwin/core-common\";\r\nimport { AcquireNewBriefcaseIdArg, IModelNameArg } from \"./BackendHubAccess\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { CheckpointManager, CheckpointProps, ProgressFunction } from \"./CheckpointManager\";\r\nimport { BriefcaseDb, IModelDb, TokenArg } from \"./IModelDb\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\n\r\nconst loggerCategory = BackendLoggerCategory.IModelDb;\r\n\r\n/** The argument for [[BriefcaseManager.downloadBriefcase]]\r\n * @public\r\n*/\r\nexport interface RequestNewBriefcaseArg extends TokenArg, RequestNewBriefcaseProps {\r\n /** If present, a function called periodically during the download to indicate progress.\r\n * @note return non-zero from this function to abort the download.\r\n */\r\n onProgress?: ProgressFunction;\r\n}\r\n\r\n/**\r\n * Parameters for pushing changesets to iModelHub\r\n * @public\r\n */\r\nexport interface PushChangesArgs extends TokenArg {\r\n /** A description of the changes. This is visible on the iModel's timeline. */\r\n description: string;\r\n /** if present, the locks are retained after the operation. Otherwise, *all* locks are released after the changeset is successfully pushed. */\r\n retainLocks?: true;\r\n /** number of times to retry pull/merge if other users are pushing at the same time. Default is 5 */\r\n mergeRetryCount?: number;\r\n /** delay to wait between pull/merge retry attempts. Default is 3 seconds */\r\n mergeRetryDelay?: BeDuration;\r\n /** the number of time to attempt to retry to push the changeset upon failure. Default is 3 */\r\n pushRetryCount?: number;\r\n /** The delay to wait between retry attempts on failed pushes. Default is 3 seconds. */\r\n pushRetryDelay?: BeDuration;\r\n}\r\n\r\n/**\r\n * Specifies a specific index for pulling changes.\r\n * @public\r\n */\r\nexport interface ToChangesetArgs extends TokenArg {\r\n /** The last ChangesetIndex to pull. If not present, pull *all* newer changesets. */\r\n toIndex?: ChangesetIndex;\r\n}\r\n\r\n/** Arguments for [[BriefcaseManager.pullAndApplyChangesets]]\r\n * @public\r\n */\r\nexport type PullChangesArgs = ToChangesetArgs & {\r\n /** If present, a function called periodically during the download to indicate progress.\r\n * @note return non-zero from this function to abort the download.\r\n */\r\n onProgress?: ProgressFunction;\r\n};\r\n\r\n/** Manages downloading Briefcases and downloading and uploading changesets.\r\n * @public\r\n */\r\nexport class BriefcaseManager {\r\n /** Get the local path of the folder storing files that are associated with an imodel */\r\n public static getIModelPath(iModelId: GuidString): LocalDirName { return path.join(this._cacheDir, iModelId); }\r\n\r\n /** @internal */\r\n public static getChangeSetsPath(iModelId: GuidString): LocalDirName { return path.join(this.getIModelPath(iModelId), \"changesets\"); }\r\n\r\n /** @internal */\r\n public static getChangeCachePathName(iModelId: GuidString): LocalFileName { return path.join(this.getIModelPath(iModelId), iModelId.concat(\".bim.ecchanges\")); }\r\n\r\n /** @internal */\r\n public static getChangedElementsPathName(iModelId: GuidString): LocalFileName { return path.join(this.getIModelPath(iModelId), iModelId.concat(\".bim.elems\")); }\r\n\r\n private static _briefcaseSubDir = \"briefcases\";\r\n /** Get the local path of the folder storing briefcases associated with the specified iModel. */\r\n public static getBriefcaseBasePath(iModelId: GuidString): LocalDirName {\r\n return path.join(this.getIModelPath(iModelId), this._briefcaseSubDir);\r\n }\r\n\r\n /** Get the name of the local file that holds, or will hold, a local briefcase in the briefcase cache.\r\n * @note The briefcase cache is a local directory established in the call to [[BriefcaseManager.initialize]].\r\n * @param briefcase the iModelId and BriefcaseId for the filename\r\n * @see getIModelPath\r\n */\r\n public static getFileName(briefcase: BriefcaseProps): LocalFileName {\r\n return path.join(this.getBriefcaseBasePath(briefcase.iModelId), `${briefcase.briefcaseId}.bim`);\r\n }\r\n\r\n private static setupCacheDir(cacheRootDir: LocalDirName) {\r\n this._cacheDir = cacheRootDir;\r\n IModelJsFs.recursiveMkDirSync(this._cacheDir);\r\n }\r\n\r\n private static _initialized?: boolean;\r\n /** Initialize BriefcaseManager\r\n * @param cacheRootDir The root directory for storing a cache of downloaded briefcase files on the local computer.\r\n * Briefcases are stored relative to this path in sub-folders organized by IModelId.\r\n * @note It is perfectly valid for applications to store briefcases in locations they manage, outside of `cacheRootDir`.\r\n */\r\n public static initialize(cacheRootDir: LocalDirName) {\r\n if (this._initialized)\r\n return;\r\n this.setupCacheDir(cacheRootDir);\r\n IModelHost.onBeforeShutdown.addOnce(() => this.finalize());\r\n this._initialized = true;\r\n }\r\n\r\n private static finalize() {\r\n this._initialized = false;\r\n }\r\n\r\n /** Get a list of the local briefcase held in the briefcase cache, optionally for a single iModelId\r\n * @param iModelId if present, only briefcases for this iModelId are returned, otherwise all briefcases for all\r\n * iModels in the briefcase cache are returned.\r\n * @note usually there should only be one briefcase per iModel.\r\n */\r\n public static getCachedBriefcases(iModelId?: GuidString): LocalBriefcaseProps[] {\r\n const briefcaseList: LocalBriefcaseProps[] = [];\r\n const iModelDirs = IModelJsFs.readdirSync(this._cacheDir);\r\n for (const iModelDir of iModelDirs) {\r\n if (iModelId && iModelId !== iModelDir)\r\n continue;\r\n const bcPath = path.join(this._cacheDir, iModelDir, this._briefcaseSubDir);\r\n try {\r\n if (!IModelJsFs.lstatSync(bcPath)?.isDirectory)\r\n continue;\r\n } catch (err) {\r\n continue;\r\n }\r\n\r\n const briefcases = IModelJsFs.readdirSync(bcPath);\r\n for (const briefcaseName of briefcases) {\r\n if (briefcaseName.endsWith(\".bim\")) {\r\n try {\r\n const fileName = path.join(bcPath, briefcaseName);\r\n const fileSize = IModelJsFs.lstatSync(fileName)?.size ?? 0;\r\n const db = IModelDb.openDgnDb({ path: fileName }, OpenMode.Readonly);\r\n briefcaseList.push({ fileName, iTwinId: db.getITwinId(), iModelId: db.getIModelId(), briefcaseId: db.getBriefcaseId(), changeset: db.getCurrentChangeset(), fileSize });\r\n db.closeIModel();\r\n } catch (_err) {\r\n }\r\n }\r\n }\r\n }\r\n return briefcaseList;\r\n }\r\n\r\n private static _cacheDir: LocalDirName;\r\n /** Get the root directory for the briefcase cache */\r\n public static get cacheDir(): LocalDirName { return this._cacheDir; }\r\n\r\n /** Determine whether the supplied briefcaseId is in the range of assigned BriefcaseIds issued by iModelHub\r\n * @note this does check whether the id was actually acquired by the caller.\r\n */\r\n public static isValidBriefcaseId(id: BriefcaseId) {\r\n return id >= BriefcaseIdValue.FirstValid && id <= BriefcaseIdValue.LastValid;\r\n }\r\n\r\n /** Acquire a new briefcaseId from iModelHub for the supplied iModelId\r\n * @note usually there should only be one briefcase per iModel per user. If a single user acquires more than one briefcaseId,\r\n * it's a good idea to supply different aliases for each of them.\r\n */\r\n public static async acquireNewBriefcaseId(arg: AcquireNewBriefcaseIdArg): Promise<BriefcaseId> {\r\n return IModelHost.hubAccess.acquireNewBriefcaseId(arg);\r\n }\r\n\r\n /**\r\n * Download a new briefcase from iModelHub for the supplied iModelId.\r\n *\r\n * Briefcases are local files holding a copy of an iModel.\r\n * Briefcases may either be specific to an individual user (so that it can be modified to create changesets), or it can be readonly so it can accept but not create changesets.\r\n * Every briefcase internally holds its [[BriefcaseId]]. Writeable briefcases have a `BriefcaseId` \"assigned\" to them by iModelHub. No two users will ever have the same BriefcaseId.\r\n * Readonly briefcases are \"unassigned\" with the special value [[BriefcaseId.Unassigned]].\r\n *\r\n * Typically a given user will have only one briefcase on their machine for a given iModelId. Rarely, it may be necessary to use more than one\r\n * briefcase to make isolated independent sets of changes, but that is exceedingly complicated and rare.\r\n *\r\n * Callers of this method may supply a BriefcaseId, or if none is supplied, a new one is acquired from iModelHub.\r\n *\r\n * @param arg The arguments that specify the briefcase file to be downloaded.\r\n * @returns The properties of the local briefcase in a Promise that is resolved after the briefcase is fully downloaded and the briefcase file is ready for use via [BriefcaseDb.open]($backend).\r\n * @note The location of the local file to hold the briefcase is arbitrary and may be any valid *local* path on your machine. If you don't supply\r\n * a filename, the local briefcase cache is used by creating a file with the briefcaseId as its name in the `briefcases` folder below the folder named\r\n * for the IModelId.\r\n * @note *It is invalid to edit briefcases on a shared network drive* and that is a sure way to corrupt your briefcase (see https://www.sqlite.org/howtocorrupt.html)\r\n */\r\n public static async downloadBriefcase(arg: RequestNewBriefcaseArg): Promise<LocalBriefcaseProps> {\r\n const briefcaseId = arg.briefcaseId ?? await this.acquireNewBriefcaseId(arg);\r\n const fileName = arg.fileName ?? this.getFileName({ ...arg, briefcaseId });\r\n\r\n if (IModelJsFs.existsSync(fileName))\r\n throw new IModelError(IModelStatus.FileAlreadyExists, `Briefcase \"${fileName}\" already exists`);\r\n\r\n const asOf = arg.asOf ?? IModelVersion.latest().toJSON();\r\n const changeset = await IModelHost.hubAccess.getChangesetFromVersion({ ...arg, version: IModelVersion.fromJSON(asOf) });\r\n const checkpoint: CheckpointProps = { ...arg, changeset };\r\n\r\n try {\r\n await CheckpointManager.downloadCheckpoint({ localFile: fileName, checkpoint, onProgress: arg.onProgress });\r\n } catch (error: unknown) {\r\n if (arg.accessToken && arg.briefcaseId === undefined)\r\n await this.releaseBriefcase(arg.accessToken, { briefcaseId, iModelId: arg.iModelId });\r\n\r\n throw error;\r\n }\r\n\r\n const fileSize = IModelJsFs.lstatSync(fileName)?.size ?? 0;\r\n const response: LocalBriefcaseProps = {\r\n fileName,\r\n briefcaseId,\r\n iModelId: arg.iModelId,\r\n iTwinId: arg.iTwinId,\r\n changeset: checkpoint.changeset,\r\n fileSize,\r\n };\r\n\r\n // now open the downloaded checkpoint and reset its BriefcaseId\r\n const nativeDb = new IModelHost.platform.DgnDb();\r\n try {\r\n nativeDb.openIModel(fileName, OpenMode.ReadWrite);\r\n } catch (err: any) {\r\n throw new IModelError(err.errorNumber, `Could not open downloaded briefcase for write access: ${fileName}, err=${err.message}`);\r\n }\r\n try {\r\n nativeDb.enableWalMode(); // local briefcases should use WAL journal mode\r\n nativeDb.resetBriefcaseId(briefcaseId);\r\n if (nativeDb.getCurrentChangeset().id !== checkpoint.changeset.id)\r\n throw new IModelError(IModelStatus.InvalidId, `Downloaded briefcase has wrong changesetId: ${fileName}`);\r\n } finally {\r\n nativeDb.saveChanges();\r\n nativeDb.closeIModel();\r\n }\r\n return response;\r\n }\r\n\r\n /** Deletes change sets of an iModel from local disk\r\n * @internal\r\n */\r\n public static deleteChangeSetsFromLocalDisk(iModelId: string) {\r\n const changesetsPath = BriefcaseManager.getChangeSetsPath(iModelId);\r\n BriefcaseManager.deleteFolderAndContents(changesetsPath);\r\n }\r\n\r\n /** Releases a briefcaseId from iModelHub. After this call it is illegal to generate changesets for the released briefcaseId.\r\n * @note generally, this method should not be called directly. Instead use [[deleteBriefcaseFiles]].\r\n * @see deleteBriefcaseFiles\r\n */\r\n public static async releaseBriefcase(accessToken: AccessToken, briefcase: BriefcaseProps): Promise<void> {\r\n if (this.isValidBriefcaseId(briefcase.briefcaseId))\r\n return IModelHost.hubAccess.releaseBriefcase({ accessToken, iModelId: briefcase.iModelId, briefcaseId: briefcase.briefcaseId });\r\n }\r\n\r\n /**\r\n * Delete and clean up a briefcase and all of its associated files. First, this method opens the supplied filename to determine its briefcaseId.\r\n * Then, if a requestContext is supplied, it releases a BriefcaseId from iModelHub. Finally it deletes the local briefcase file and\r\n * associated files (that is, all files in the same directory that start with the briefcase name).\r\n * @param filePath the full file name of the Briefcase to delete\r\n * @param accessToken for releasing the briefcaseId\r\n */\r\n public static async deleteBriefcaseFiles(filePath: LocalFileName, accessToken?: AccessToken): Promise<void> {\r\n try {\r\n const db = IModelDb.openDgnDb({ path: filePath }, OpenMode.Readonly);\r\n const briefcase: BriefcaseProps = {\r\n iModelId: db.getIModelId(),\r\n briefcaseId: db.getBriefcaseId(),\r\n };\r\n db.closeIModel();\r\n\r\n if (accessToken) {\r\n if (this.isValidBriefcaseId(briefcase.briefcaseId)) {\r\n await BriefcaseManager.releaseBriefcase(accessToken, briefcase);\r\n }\r\n }\r\n } catch (error) {\r\n }\r\n\r\n // first try to delete the briefcase file\r\n try {\r\n if (IModelJsFs.existsSync(filePath))\r\n IModelJsFs.unlinkSync(filePath);\r\n } catch (err) {\r\n throw new IModelError(IModelStatus.BadRequest, `cannot delete briefcase file ${err}`);\r\n }\r\n\r\n // next, delete all files that start with the briefcase's filePath (e.g. \"a.bim-locks\", \"a.bim-journal\", etc.)\r\n try {\r\n const dirName = path.dirname(filePath);\r\n const fileName = path.basename(filePath);\r\n const files = IModelJsFs.readdirSync(dirName);\r\n for (const file of files) {\r\n if (file.startsWith(fileName))\r\n this.deleteFile(path.join(dirName, file)); // don't throw on error\r\n }\r\n } catch (err) {\r\n }\r\n }\r\n\r\n /** Deletes a file\r\n * - Does not throw any error, but logs it instead\r\n * - Returns true if the delete was successful\r\n */\r\n private static deleteFile(pathname: LocalFileName): boolean {\r\n try {\r\n IModelJsFs.unlinkSync(pathname);\r\n } catch (error) {\r\n Logger.logError(loggerCategory, `Cannot delete file ${pathname}, ${error}`);\r\n return false;\r\n }\r\n return true;\r\n }\r\n\r\n /** Deletes a folder, checking if it's empty\r\n * - Does not throw any error, but logs it instead\r\n * - Returns true if the delete was successful\r\n */\r\n private static deleteFolderIfEmpty(folderPathname: LocalDirName): boolean {\r\n try {\r\n const files = IModelJsFs.readdirSync(folderPathname);\r\n if (files.length > 0)\r\n return false;\r\n\r\n IModelJsFs.rmdirSync(folderPathname);\r\n } catch (error) {\r\n Logger.logError(loggerCategory, `Cannot delete folder: ${folderPathname}`);\r\n return false;\r\n }\r\n return true;\r\n }\r\n\r\n /** Deletes the contents of a folder, but not the folder itself\r\n * - Does not throw any errors, but logs them.\r\n * - returns true if the delete was successful.\r\n */\r\n private static deleteFolderContents(folderPathname: LocalDirName): boolean {\r\n if (!IModelJsFs.existsSync(folderPathname))\r\n return false;\r\n\r\n let status = true;\r\n const files = IModelJsFs.readdirSync(folderPathname);\r\n for (const file of files) {\r\n const curPath = path.join(folderPathname, file);\r\n const locStatus = (IModelJsFs.lstatSync(curPath)?.isDirectory) ? BriefcaseManager.deleteFolderAndContents(curPath) : BriefcaseManager.deleteFile(curPath);\r\n if (!locStatus)\r\n status = false;\r\n }\r\n return status;\r\n }\r\n\r\n /** Query the hub for the properties for a ChangesetIndex or ChangesetId */\r\n public static async queryChangeset(arg: { iModelId: GuidString, changeset: ChangesetIndexOrId }): Promise<ChangesetProps> {\r\n return IModelHost.hubAccess.queryChangeset({ ...arg, accessToken: await IModelHost.getAccessToken() });\r\n }\r\n\r\n /** Query the hub for an array of changeset properties given a ChangesetRange */\r\n public static async queryChangesets(arg: { iModelId: GuidString, range: ChangesetRange }): Promise<ChangesetProps[]> {\r\n return IModelHost.hubAccess.queryChangesets({ ...arg, accessToken: await IModelHost.getAccessToken() });\r\n }\r\n\r\n /** Query the hub for the ChangesetProps of the most recent changeset */\r\n public static async getLatestChangeset(arg: { iModelId: GuidString }): Promise<ChangesetProps> {\r\n return IModelHost.hubAccess.getLatestChangeset({ ...arg, accessToken: await IModelHost.getAccessToken() });\r\n }\r\n\r\n /** Query the Id of an iModel by name.\r\n * @param arg Identifies the iModel of interest\r\n * @returns the Id of the corresponding iModel, or `undefined` if no such iModel exists.\r\n */\r\n public static async queryIModelByName(arg: IModelNameArg): Promise<GuidString | undefined> {\r\n return IModelHost.hubAccess.queryIModelByName(arg);\r\n }\r\n\r\n /** Deletes a folder and all it's contents.\r\n * - Does not throw any errors, but logs them.\r\n * - returns true if the delete was successful.\r\n */\r\n private static deleteFolderAndContents(folderPathname: LocalDirName): boolean {\r\n if (!IModelJsFs.existsSync(folderPathname))\r\n return true;\r\n\r\n let status = false;\r\n status = BriefcaseManager.deleteFolderContents(folderPathname);\r\n if (!status)\r\n return false;\r\n\r\n status = BriefcaseManager.deleteFolderIfEmpty(folderPathname);\r\n return status;\r\n }\r\n\r\n private static async applySingleChangeset(db: IModelDb, changesetFile: ChangesetFileProps) {\r\n if (changesetFile.changesType === ChangesetType.Schema)\r\n db.clearCaches(); // for schema changesets, statement caches may become invalid. Do this *before* applying, in case db needs to be closed (open statements hold db open.)\r\n\r\n db.nativeDb.applyChangeset(changesetFile);\r\n db.changeset = db.nativeDb.getCurrentChangeset();\r\n\r\n // we're done with this changeset, delete it\r\n IModelJsFs.removeSync(changesetFile.pathname);\r\n }\r\n\r\n /** @internal */\r\n public static async pullAndApplyChangesets(db: IModelDb, arg: PullChangesArgs): Promise<void> {\r\n if (!db.isOpen || db.nativeDb.isReadonly()) // don't use db.isReadonly - we reopen the file writable just for this operation but db.isReadonly is still true\r\n throw new IModelError(ChangeSetStatus.ApplyError, \"Briefcase must be open ReadWrite to process change sets\");\r\n\r\n let currentIndex = db.changeset.index;\r\n if (currentIndex === undefined)\r\n currentIndex = (await IModelHost.hubAccess.queryChangeset({ accessToken: arg.accessToken, iModelId: db.iModelId, changeset: { id: db.changeset.id } })).index;\r\n\r\n const reverse = (arg.toIndex && arg.toIndex < currentIndex) ? true : false;\r\n\r\n // Download change sets\r\n const changesets = await IModelHost.hubAccess.downloadChangesets({\r\n accessToken: arg.accessToken,\r\n iModelId: db.iModelId,\r\n range: { first: reverse ? arg.toIndex! + 1 : currentIndex + 1, end: reverse ? currentIndex : arg.toIndex }, // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n targetDir: BriefcaseManager.getChangeSetsPath(db.iModelId),\r\n progressCallback: arg.onProgress,\r\n });\r\n\r\n if (changesets.length === 0)\r\n return; // nothing to apply\r\n\r\n if (reverse)\r\n changesets.reverse();\r\n\r\n for (const changeset of changesets)\r\n await this.applySingleChangeset(db, changeset);\r\n\r\n // notify listeners\r\n db.notifyChangesetApplied();\r\n }\r\n\r\n /** create a changeset from the current changes, and push it to iModelHub */\r\n private static async pushChanges(db: BriefcaseDb, arg: PushChangesArgs): Promise<void> {\r\n const changesetProps = db.nativeDb.startCreateChangeset() as ChangesetFileProps;\r\n changesetProps.briefcaseId = db.briefcaseId;\r\n changesetProps.description = arg.description;\r\n const fileSize = IModelJsFs.lstatSync(changesetProps.pathname)?.size;\r\n if (!fileSize) // either undefined or 0 means error\r\n throw new IModelError(IModelStatus.NoContent, \"error creating changeset\");\r\n\r\n changesetProps.size = fileSize;\r\n\r\n let retryCount = arg.pushRetryCount ?? 3;\r\n while (true) {\r\n try {\r\n const accessToken = await IModelHost.getAccessToken();\r\n const index = await IModelHost.hubAccess.pushChangeset({ accessToken, iModelId: db.iModelId, changesetProps });\r\n db.nativeDb.completeCreateChangeset({ index });\r\n db.changeset = db.nativeDb.getCurrentChangeset();\r\n if (!arg.retainLocks)\r\n await db.locks.releaseAllLocks();\r\n\r\n return;\r\n } catch (err: any) {\r\n const shouldRetry = () => {\r\n if (retryCount-- <= 0)\r\n return false;\r\n switch (err.errorNumber) {\r\n case IModelHubStatus.AnotherUserPushing:\r\n case IModelHubStatus.DatabaseTemporarilyLocked:\r\n case IModelHubStatus.OperationFailed:\r\n return true;\r\n }\r\n return false;\r\n };\r\n\r\n if (!shouldRetry()) {\r\n db.nativeDb.abandonCreateChangeset();\r\n throw err;\r\n }\r\n } finally {\r\n IModelJsFs.removeSync(changesetProps.pathname);\r\n }\r\n }\r\n }\r\n\r\n /** Pull/merge (if necessary), then push all local changes as a changeset. Called by [[BriefcaseDb.pushChanges]]\r\n * @internal\r\n */\r\n public static async pullMergePush(db: BriefcaseDb, arg: PushChangesArgs): Promise<void> {\r\n let retryCount = arg.mergeRetryCount ?? 5;\r\n while (true) {\r\n try {\r\n await BriefcaseManager.pullAndApplyChangesets(db, arg);\r\n return await BriefcaseManager.pushChanges(db, arg);\r\n } catch (err: any) {\r\n if (retryCount-- <= 0 || err.errorNumber !== IModelHubStatus.PullIsRequired)\r\n throw (err);\r\n await (arg.mergeRetryDelay ?? BeDuration.fromSeconds(3)).wait();\r\n }\r\n }\r\n }\r\n\r\n}\r\n"]}
1
+ {"version":3,"file":"BriefcaseManager.js","source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AAgB,GAAG,YAAY,CAAC;AAbpC,4CAAgB","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 cset csets ecchanges\r\n\r\nimport * as path from \"path\";\r\nimport {\r\n AccessToken, BeDuration, ChangeSetStatus, GuidString, IModelHubStatus, IModelStatus, Logger, OpenMode, StopWatch,\r\n} from \"@itwin/core-bentley\";\r\nimport {\r\n BriefcaseId, BriefcaseIdValue, BriefcaseProps, ChangesetFileProps, ChangesetIndex, ChangesetIndexOrId, ChangesetProps, ChangesetRange, ChangesetType, IModelError, IModelVersion, LocalBriefcaseProps,\r\n LocalDirName, LocalFileName, RequestNewBriefcaseProps,\r\n} from \"@itwin/core-common\";\r\nimport { AcquireNewBriefcaseIdArg, IModelNameArg } from \"./BackendHubAccess\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { CheckpointManager, CheckpointProps, ProgressFunction } from \"./CheckpointManager\";\r\nimport { BriefcaseDb, IModelDb, TokenArg } from \"./IModelDb\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { IModelJsFs } from \"./IModelJsFs\";\r\n\r\nconst loggerCategory = BackendLoggerCategory.IModelDb;\r\n\r\n/** The argument for [[BriefcaseManager.downloadBriefcase]]\r\n * @public\r\n*/\r\nexport interface RequestNewBriefcaseArg extends TokenArg, RequestNewBriefcaseProps {\r\n /** If present, a function called periodically during the download to indicate progress.\r\n * @note return non-zero from this function to abort the download.\r\n */\r\n onProgress?: ProgressFunction;\r\n}\r\n\r\n/**\r\n * Parameters for pushing changesets to iModelHub\r\n * @public\r\n */\r\nexport interface PushChangesArgs extends TokenArg {\r\n /** A description of the changes. This is visible on the iModel's timeline. */\r\n description: string;\r\n /** if present, the locks are retained after the operation. Otherwise, *all* locks are released after the changeset is successfully pushed. */\r\n retainLocks?: true;\r\n /** number of times to retry pull/merge if other users are pushing at the same time. Default is 5 */\r\n mergeRetryCount?: number;\r\n /** delay to wait between pull/merge retry attempts. Default is 3 seconds */\r\n mergeRetryDelay?: BeDuration;\r\n /** the number of time to attempt to retry to push the changeset upon failure. Default is 3 */\r\n pushRetryCount?: number;\r\n /** The delay to wait between retry attempts on failed pushes. Default is 3 seconds. */\r\n pushRetryDelay?: BeDuration;\r\n}\r\n\r\n/**\r\n * Specifies a specific index for pulling changes.\r\n * @public\r\n */\r\nexport interface ToChangesetArgs extends TokenArg {\r\n /** The last ChangesetIndex to pull. If not present, pull *all* newer changesets. */\r\n toIndex?: ChangesetIndex;\r\n}\r\n\r\n/** Arguments for [[BriefcaseManager.pullAndApplyChangesets]]\r\n * @public\r\n */\r\nexport type PullChangesArgs = ToChangesetArgs & {\r\n /** If present, a function called periodically during the download to indicate progress.\r\n * @note return non-zero from this function to abort the download.\r\n */\r\n onProgress?: ProgressFunction;\r\n};\r\n\r\n/** Manages downloading Briefcases and downloading and uploading changesets.\r\n * @public\r\n */\r\nexport class BriefcaseManager {\r\n /** Get the local path of the folder storing files that are associated with an imodel */\r\n public static getIModelPath(iModelId: GuidString): LocalDirName { return path.join(this._cacheDir, iModelId); }\r\n\r\n /** @internal */\r\n public static getChangeSetsPath(iModelId: GuidString): LocalDirName { return path.join(this.getIModelPath(iModelId), \"changesets\"); }\r\n\r\n /** @internal */\r\n public static getChangeCachePathName(iModelId: GuidString): LocalFileName { return path.join(this.getIModelPath(iModelId), iModelId.concat(\".bim.ecchanges\")); }\r\n\r\n /** @internal */\r\n public static getChangedElementsPathName(iModelId: GuidString): LocalFileName { return path.join(this.getIModelPath(iModelId), iModelId.concat(\".bim.elems\")); }\r\n\r\n private static _briefcaseSubDir = \"briefcases\";\r\n /** Get the local path of the folder storing briefcases associated with the specified iModel. */\r\n public static getBriefcaseBasePath(iModelId: GuidString): LocalDirName {\r\n return path.join(this.getIModelPath(iModelId), this._briefcaseSubDir);\r\n }\r\n\r\n /** Get the name of the local file that holds, or will hold, a local briefcase in the briefcase cache.\r\n * @note The briefcase cache is a local directory established in the call to [[BriefcaseManager.initialize]].\r\n * @param briefcase the iModelId and BriefcaseId for the filename\r\n * @see getIModelPath\r\n */\r\n public static getFileName(briefcase: BriefcaseProps): LocalFileName {\r\n return path.join(this.getBriefcaseBasePath(briefcase.iModelId), `${briefcase.briefcaseId}.bim`);\r\n }\r\n\r\n private static setupCacheDir(cacheRootDir: LocalDirName) {\r\n this._cacheDir = cacheRootDir;\r\n IModelJsFs.recursiveMkDirSync(this._cacheDir);\r\n }\r\n\r\n private static _initialized?: boolean;\r\n /** Initialize BriefcaseManager\r\n * @param cacheRootDir The root directory for storing a cache of downloaded briefcase files on the local computer.\r\n * Briefcases are stored relative to this path in sub-folders organized by IModelId.\r\n * @note It is perfectly valid for applications to store briefcases in locations they manage, outside of `cacheRootDir`.\r\n */\r\n public static initialize(cacheRootDir: LocalDirName) {\r\n if (this._initialized)\r\n return;\r\n this.setupCacheDir(cacheRootDir);\r\n IModelHost.onBeforeShutdown.addOnce(() => this.finalize());\r\n this._initialized = true;\r\n }\r\n\r\n private static finalize() {\r\n this._initialized = false;\r\n }\r\n\r\n /** Get a list of the local briefcase held in the briefcase cache, optionally for a single iModelId\r\n * @param iModelId if present, only briefcases for this iModelId are returned, otherwise all briefcases for all\r\n * iModels in the briefcase cache are returned.\r\n * @note usually there should only be one briefcase per iModel.\r\n */\r\n public static getCachedBriefcases(iModelId?: GuidString): LocalBriefcaseProps[] {\r\n const briefcaseList: LocalBriefcaseProps[] = [];\r\n const iModelDirs = IModelJsFs.readdirSync(this._cacheDir);\r\n for (const iModelDir of iModelDirs) {\r\n if (iModelId && iModelId !== iModelDir)\r\n continue;\r\n const bcPath = path.join(this._cacheDir, iModelDir, this._briefcaseSubDir);\r\n try {\r\n if (!IModelJsFs.lstatSync(bcPath)?.isDirectory)\r\n continue;\r\n } catch (err) {\r\n continue;\r\n }\r\n\r\n const briefcases = IModelJsFs.readdirSync(bcPath);\r\n for (const briefcaseName of briefcases) {\r\n if (briefcaseName.endsWith(\".bim\")) {\r\n try {\r\n const fileName = path.join(bcPath, briefcaseName);\r\n const fileSize = IModelJsFs.lstatSync(fileName)?.size ?? 0;\r\n const db = IModelDb.openDgnDb({ path: fileName }, OpenMode.Readonly);\r\n briefcaseList.push({ fileName, iTwinId: db.getITwinId(), iModelId: db.getIModelId(), briefcaseId: db.getBriefcaseId(), changeset: db.getCurrentChangeset(), fileSize });\r\n db.closeIModel();\r\n } catch (_err) {\r\n }\r\n }\r\n }\r\n }\r\n return briefcaseList;\r\n }\r\n\r\n private static _cacheDir: LocalDirName;\r\n /** Get the root directory for the briefcase cache */\r\n public static get cacheDir(): LocalDirName { return this._cacheDir; }\r\n\r\n /** Determine whether the supplied briefcaseId is in the range of assigned BriefcaseIds issued by iModelHub\r\n * @note this does check whether the id was actually acquired by the caller.\r\n */\r\n public static isValidBriefcaseId(id: BriefcaseId) {\r\n return id >= BriefcaseIdValue.FirstValid && id <= BriefcaseIdValue.LastValid;\r\n }\r\n\r\n /** Acquire a new briefcaseId from iModelHub for the supplied iModelId\r\n * @note usually there should only be one briefcase per iModel per user. If a single user acquires more than one briefcaseId,\r\n * it's a good idea to supply different aliases for each of them.\r\n */\r\n public static async acquireNewBriefcaseId(arg: AcquireNewBriefcaseIdArg): Promise<BriefcaseId> {\r\n return IModelHost.hubAccess.acquireNewBriefcaseId(arg);\r\n }\r\n\r\n /**\r\n * Download a new briefcase from iModelHub for the supplied iModelId.\r\n *\r\n * Briefcases are local files holding a copy of an iModel.\r\n * Briefcases may either be specific to an individual user (so that it can be modified to create changesets), or it can be readonly so it can accept but not create changesets.\r\n * Every briefcase internally holds its [[BriefcaseId]]. Writeable briefcases have a `BriefcaseId` \"assigned\" to them by iModelHub. No two users will ever have the same BriefcaseId.\r\n * Readonly briefcases are \"unassigned\" with the special value [[BriefcaseId.Unassigned]].\r\n *\r\n * Typically a given user will have only one briefcase on their machine for a given iModelId. Rarely, it may be necessary to use more than one\r\n * briefcase to make isolated independent sets of changes, but that is exceedingly complicated and rare.\r\n *\r\n * Callers of this method may supply a BriefcaseId, or if none is supplied, a new one is acquired from iModelHub.\r\n *\r\n * @param arg The arguments that specify the briefcase file to be downloaded.\r\n * @returns The properties of the local briefcase in a Promise that is resolved after the briefcase is fully downloaded and the briefcase file is ready for use via [BriefcaseDb.open]($backend).\r\n * @note The location of the local file to hold the briefcase is arbitrary and may be any valid *local* path on your machine. If you don't supply\r\n * a filename, the local briefcase cache is used by creating a file with the briefcaseId as its name in the `briefcases` folder below the folder named\r\n * for the IModelId.\r\n * @note *It is invalid to edit briefcases on a shared network drive* and that is a sure way to corrupt your briefcase (see https://www.sqlite.org/howtocorrupt.html)\r\n */\r\n public static async downloadBriefcase(arg: RequestNewBriefcaseArg): Promise<LocalBriefcaseProps> {\r\n const briefcaseId = arg.briefcaseId ?? await this.acquireNewBriefcaseId(arg);\r\n const fileName = arg.fileName ?? this.getFileName({ ...arg, briefcaseId });\r\n\r\n if (IModelJsFs.existsSync(fileName))\r\n throw new IModelError(IModelStatus.FileAlreadyExists, `Briefcase \"${fileName}\" already exists`);\r\n\r\n const asOf = arg.asOf ?? IModelVersion.latest().toJSON();\r\n const changeset = await IModelHost.hubAccess.getChangesetFromVersion({ ...arg, version: IModelVersion.fromJSON(asOf) });\r\n const checkpoint: CheckpointProps = { ...arg, changeset };\r\n\r\n try {\r\n await CheckpointManager.downloadCheckpoint({ localFile: fileName, checkpoint, onProgress: arg.onProgress });\r\n } catch (error: unknown) {\r\n if (arg.accessToken && arg.briefcaseId === undefined)\r\n await this.releaseBriefcase(arg.accessToken, { briefcaseId, iModelId: arg.iModelId });\r\n\r\n throw error;\r\n }\r\n\r\n const fileSize = IModelJsFs.lstatSync(fileName)?.size ?? 0;\r\n const response: LocalBriefcaseProps = {\r\n fileName,\r\n briefcaseId,\r\n iModelId: arg.iModelId,\r\n iTwinId: arg.iTwinId,\r\n changeset: checkpoint.changeset,\r\n fileSize,\r\n };\r\n\r\n // now open the downloaded checkpoint and reset its BriefcaseId\r\n const nativeDb = new IModelHost.platform.DgnDb();\r\n try {\r\n nativeDb.openIModel(fileName, OpenMode.ReadWrite);\r\n } catch (err: any) {\r\n throw new IModelError(err.errorNumber, `Could not open downloaded briefcase for write access: ${fileName}, err=${err.message}`);\r\n }\r\n try {\r\n nativeDb.enableWalMode(); // local briefcases should use WAL journal mode\r\n nativeDb.resetBriefcaseId(briefcaseId);\r\n if (nativeDb.getCurrentChangeset().id !== checkpoint.changeset.id)\r\n throw new IModelError(IModelStatus.InvalidId, `Downloaded briefcase has wrong changesetId: ${fileName}`);\r\n } finally {\r\n nativeDb.saveChanges();\r\n nativeDb.closeIModel();\r\n }\r\n return response;\r\n }\r\n\r\n /** Deletes change sets of an iModel from local disk\r\n * @internal\r\n */\r\n public static deleteChangeSetsFromLocalDisk(iModelId: string) {\r\n const changesetsPath = BriefcaseManager.getChangeSetsPath(iModelId);\r\n BriefcaseManager.deleteFolderAndContents(changesetsPath);\r\n }\r\n\r\n /** Releases a briefcaseId from iModelHub. After this call it is illegal to generate changesets for the released briefcaseId.\r\n * @note generally, this method should not be called directly. Instead use [[deleteBriefcaseFiles]].\r\n * @see deleteBriefcaseFiles\r\n */\r\n public static async releaseBriefcase(accessToken: AccessToken, briefcase: BriefcaseProps): Promise<void> {\r\n if (this.isValidBriefcaseId(briefcase.briefcaseId))\r\n return IModelHost.hubAccess.releaseBriefcase({ accessToken, iModelId: briefcase.iModelId, briefcaseId: briefcase.briefcaseId });\r\n }\r\n\r\n /**\r\n * Delete and clean up a briefcase and all of its associated files. First, this method opens the supplied filename to determine its briefcaseId.\r\n * Then, if a requestContext is supplied, it releases a BriefcaseId from iModelHub. Finally it deletes the local briefcase file and\r\n * associated files (that is, all files in the same directory that start with the briefcase name).\r\n * @param filePath the full file name of the Briefcase to delete\r\n * @param accessToken for releasing the briefcaseId\r\n */\r\n public static async deleteBriefcaseFiles(filePath: LocalFileName, accessToken?: AccessToken): Promise<void> {\r\n try {\r\n const db = IModelDb.openDgnDb({ path: filePath }, OpenMode.Readonly);\r\n const briefcase: BriefcaseProps = {\r\n iModelId: db.getIModelId(),\r\n briefcaseId: db.getBriefcaseId(),\r\n };\r\n db.closeIModel();\r\n\r\n if (accessToken) {\r\n if (this.isValidBriefcaseId(briefcase.briefcaseId)) {\r\n await BriefcaseManager.releaseBriefcase(accessToken, briefcase);\r\n }\r\n }\r\n } catch (error) {\r\n }\r\n\r\n // first try to delete the briefcase file\r\n try {\r\n if (IModelJsFs.existsSync(filePath))\r\n IModelJsFs.unlinkSync(filePath);\r\n } catch (err) {\r\n throw new IModelError(IModelStatus.BadRequest, `cannot delete briefcase file ${err}`);\r\n }\r\n\r\n // next, delete all files that start with the briefcase's filePath (e.g. \"a.bim-locks\", \"a.bim-journal\", etc.)\r\n try {\r\n const dirName = path.dirname(filePath);\r\n const fileName = path.basename(filePath);\r\n const files = IModelJsFs.readdirSync(dirName);\r\n for (const file of files) {\r\n if (file.startsWith(fileName))\r\n this.deleteFile(path.join(dirName, file)); // don't throw on error\r\n }\r\n } catch (err) {\r\n }\r\n }\r\n\r\n /** Deletes a file\r\n * - Does not throw any error, but logs it instead\r\n * - Returns true if the delete was successful\r\n */\r\n private static deleteFile(pathname: LocalFileName): boolean {\r\n try {\r\n IModelJsFs.unlinkSync(pathname);\r\n } catch (error) {\r\n Logger.logError(loggerCategory, `Cannot delete file ${pathname}, ${error}`);\r\n return false;\r\n }\r\n return true;\r\n }\r\n\r\n /** Deletes a folder, checking if it's empty\r\n * - Does not throw any error, but logs it instead\r\n * - Returns true if the delete was successful\r\n */\r\n private static deleteFolderIfEmpty(folderPathname: LocalDirName): boolean {\r\n try {\r\n const files = IModelJsFs.readdirSync(folderPathname);\r\n if (files.length > 0)\r\n return false;\r\n\r\n IModelJsFs.rmdirSync(folderPathname);\r\n } catch (error) {\r\n Logger.logError(loggerCategory, `Cannot delete folder: ${folderPathname}`);\r\n return false;\r\n }\r\n return true;\r\n }\r\n\r\n /** Deletes the contents of a folder, but not the folder itself\r\n * - Does not throw any errors, but logs them.\r\n * - returns true if the delete was successful.\r\n */\r\n private static deleteFolderContents(folderPathname: LocalDirName): boolean {\r\n if (!IModelJsFs.existsSync(folderPathname))\r\n return false;\r\n\r\n let status = true;\r\n const files = IModelJsFs.readdirSync(folderPathname);\r\n for (const file of files) {\r\n const curPath = path.join(folderPathname, file);\r\n const locStatus = (IModelJsFs.lstatSync(curPath)?.isDirectory) ? BriefcaseManager.deleteFolderAndContents(curPath) : BriefcaseManager.deleteFile(curPath);\r\n if (!locStatus)\r\n status = false;\r\n }\r\n return status;\r\n }\r\n\r\n /** Query the hub for the properties for a ChangesetIndex or ChangesetId */\r\n public static async queryChangeset(arg: { iModelId: GuidString, changeset: ChangesetIndexOrId }): Promise<ChangesetProps> {\r\n return IModelHost.hubAccess.queryChangeset({ ...arg, accessToken: await IModelHost.getAccessToken() });\r\n }\r\n\r\n /** Query the hub for an array of changeset properties given a ChangesetRange */\r\n public static async queryChangesets(arg: { iModelId: GuidString, range: ChangesetRange }): Promise<ChangesetProps[]> {\r\n return IModelHost.hubAccess.queryChangesets({ ...arg, accessToken: await IModelHost.getAccessToken() });\r\n }\r\n\r\n /** Query the hub for the ChangesetProps of the most recent changeset */\r\n public static async getLatestChangeset(arg: { iModelId: GuidString }): Promise<ChangesetProps> {\r\n return IModelHost.hubAccess.getLatestChangeset({ ...arg, accessToken: await IModelHost.getAccessToken() });\r\n }\r\n\r\n /** Query the Id of an iModel by name.\r\n * @param arg Identifies the iModel of interest\r\n * @returns the Id of the corresponding iModel, or `undefined` if no such iModel exists.\r\n */\r\n public static async queryIModelByName(arg: IModelNameArg): Promise<GuidString | undefined> {\r\n return IModelHost.hubAccess.queryIModelByName(arg);\r\n }\r\n\r\n /** Deletes a folder and all it's contents.\r\n * - Does not throw any errors, but logs them.\r\n * - returns true if the delete was successful.\r\n */\r\n private static deleteFolderAndContents(folderPathname: LocalDirName): boolean {\r\n if (!IModelJsFs.existsSync(folderPathname))\r\n return true;\r\n\r\n let status = false;\r\n status = BriefcaseManager.deleteFolderContents(folderPathname);\r\n if (!status)\r\n return false;\r\n\r\n status = BriefcaseManager.deleteFolderIfEmpty(folderPathname);\r\n return status;\r\n }\r\n\r\n private static async applySingleChangeset(db: IModelDb, changesetFile: ChangesetFileProps) {\r\n if (changesetFile.changesType === ChangesetType.Schema)\r\n db.clearCaches(); // for schema changesets, statement caches may become invalid. Do this *before* applying, in case db needs to be closed (open statements hold db open.)\r\n\r\n db.nativeDb.applyChangeset(changesetFile);\r\n db.changeset = db.nativeDb.getCurrentChangeset();\r\n\r\n // we're done with this changeset, delete it\r\n IModelJsFs.removeSync(changesetFile.pathname);\r\n }\r\n\r\n /** @internal */\r\n public static async pullAndApplyChangesets(db: IModelDb, arg: PullChangesArgs): Promise<void> {\r\n if (!db.isOpen || db.nativeDb.isReadonly()) // don't use db.isReadonly - we reopen the file writable just for this operation but db.isReadonly is still true\r\n throw new IModelError(ChangeSetStatus.ApplyError, \"Briefcase must be open ReadWrite to process change sets\");\r\n\r\n let currentIndex = db.changeset.index;\r\n if (currentIndex === undefined)\r\n currentIndex = (await IModelHost.hubAccess.queryChangeset({ accessToken: arg.accessToken, iModelId: db.iModelId, changeset: { id: db.changeset.id } })).index;\r\n\r\n const reverse = (arg.toIndex && arg.toIndex < currentIndex) ? true : false;\r\n\r\n // Download change sets\r\n const changesets = await IModelHost.hubAccess.downloadChangesets({\r\n accessToken: arg.accessToken,\r\n iModelId: db.iModelId,\r\n range: { first: reverse ? arg.toIndex! + 1 : currentIndex + 1, end: reverse ? currentIndex : arg.toIndex }, // eslint-disable-line @typescript-eslint/no-non-null-assertion\r\n targetDir: BriefcaseManager.getChangeSetsPath(db.iModelId),\r\n progressCallback: arg.onProgress,\r\n });\r\n\r\n if (changesets.length === 0)\r\n return; // nothing to apply\r\n\r\n if (reverse)\r\n changesets.reverse();\r\n\r\n for (const changeset of changesets) {\r\n const stopwatch = new StopWatch(`[${changeset.id}]`, true);\r\n Logger.logInfo(loggerCategory, `Starting application of changeset with id ${stopwatch.description}`);\r\n await this.applySingleChangeset(db, changeset);\r\n Logger.logInfo(loggerCategory, `Applied changeset with id ${stopwatch.description} (${stopwatch.elapsedSeconds} seconds)`);\r\n }\r\n // notify listeners\r\n db.notifyChangesetApplied();\r\n }\r\n\r\n /** create a changeset from the current changes, and push it to iModelHub */\r\n private static async pushChanges(db: BriefcaseDb, arg: PushChangesArgs): Promise<void> {\r\n const changesetProps = db.nativeDb.startCreateChangeset() as ChangesetFileProps;\r\n changesetProps.briefcaseId = db.briefcaseId;\r\n changesetProps.description = arg.description;\r\n const fileSize = IModelJsFs.lstatSync(changesetProps.pathname)?.size;\r\n if (!fileSize) // either undefined or 0 means error\r\n throw new IModelError(IModelStatus.NoContent, \"error creating changeset\");\r\n\r\n changesetProps.size = fileSize;\r\n\r\n let retryCount = arg.pushRetryCount ?? 3;\r\n while (true) {\r\n try {\r\n const accessToken = await IModelHost.getAccessToken();\r\n const index = await IModelHost.hubAccess.pushChangeset({ accessToken, iModelId: db.iModelId, changesetProps });\r\n db.nativeDb.completeCreateChangeset({ index });\r\n db.changeset = db.nativeDb.getCurrentChangeset();\r\n if (!arg.retainLocks)\r\n await db.locks.releaseAllLocks();\r\n\r\n return;\r\n } catch (err: any) {\r\n const shouldRetry = () => {\r\n if (retryCount-- <= 0)\r\n return false;\r\n switch (err.errorNumber) {\r\n case IModelHubStatus.AnotherUserPushing:\r\n case IModelHubStatus.DatabaseTemporarilyLocked:\r\n case IModelHubStatus.OperationFailed:\r\n return true;\r\n }\r\n return false;\r\n };\r\n\r\n if (!shouldRetry()) {\r\n db.nativeDb.abandonCreateChangeset();\r\n throw err;\r\n }\r\n } finally {\r\n IModelJsFs.removeSync(changesetProps.pathname);\r\n }\r\n }\r\n }\r\n\r\n /** Pull/merge (if necessary), then push all local changes as a changeset. Called by [[BriefcaseDb.pushChanges]]\r\n * @internal\r\n */\r\n public static async pullMergePush(db: BriefcaseDb, arg: PushChangesArgs): Promise<void> {\r\n let retryCount = arg.mergeRetryCount ?? 5;\r\n while (true) {\r\n try {\r\n await BriefcaseManager.pullAndApplyChangesets(db, arg);\r\n return await BriefcaseManager.pushChanges(db, arg);\r\n } catch (err: any) {\r\n if (retryCount-- <= 0 || err.errorNumber !== IModelHubStatus.PullIsRequired)\r\n throw (err);\r\n await (arg.mergeRetryDelay ?? BeDuration.fromSeconds(3)).wait();\r\n }\r\n }\r\n }\r\n\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CheckpointManager.d.ts","sourceRoot":"","sources":["../../src/CheckpointManager.ts"],"names":[],"mappings":"AAIA;;GAEG;AAMH,OAAO,EAAE,OAAO,EAAyB,UAAU,EAAgE,MAAM,qBAAqB,CAAC;AAC/I,OAAO,EACa,WAAW,EAAE,oBAAoB,EAAmD,YAAY,EAAE,aAAa,EAClI,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAIlD;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,QAAQ;IAC/C,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAE5B,uCAAuC;IACvC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAE7B,uBAAuB;IACvB,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAE9B,mCAAmC;IACnC,QAAQ,CAAC,SAAS,EAAE,oBAAoB,CAAC;IAEzC,8IAA8I;IAC9I,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAElC,qHAAqH;IACrH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;CACzC;AAED;;GAEG;AACH,oBAAY,cAAc;IACxB,yBAAyB;IACzB,QAAQ,IAAI;IACZ,sBAA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AkB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;mBAIjE,eAAe;mBASf,eAAe;CAKrC;AAED,iBAAiB;AACjB,qBAAa,iBAAiB;IAC5B,gBAAuB,YAAY,gBAAqB,WAAW,KAAK,IAAI,EAAI;IAChF,gBAAuB,YAAY,gBAAqB,WAAW,KAAK,IAAI,EAAI;WAClE,MAAM,CAAC,UAAU,EAAE,eAAe;mBAE3B,UAAU;WAsBX,wBAAwB,CAAC,OAAO,EAAE,eAAe;IAkDrE,uGAAuG;WACnF,kBAAkB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB/E,6FAA6F;WAC/E,uBAAuB,CAAC,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU;IAyBzF,4DAA4D;WAC9C,gBAAgB,CAAC,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO;IAmB7F,uEAAuE;WACzD,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,UAAU,GAAG,SAAS;CAgBjF"}
@@ -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.");
@@ -140,7 +140,7 @@ class V2CheckpointManager {
140
140
  const maxRequests = getPrefetchConfig("maxRequests", 6);
141
141
  const timeout = getPrefetchConfig("timeout", 100);
142
142
  const maxBlocks = getPrefetchConfig("maxBlocks", 500); // default size of 2GB. Assumes a checkpoint block size of 4MB.
143
- if (dbStats?.totalBlocks !== undefined && dbStats.totalBlocks <= maxBlocks) {
143
+ if (dbStats?.totalBlocks !== undefined && dbStats.totalBlocks <= maxBlocks && dbStats.nPrefetch === 0) {
144
144
  const logPrefetch = async (prefetch) => {
145
145
  const stopwatch = new core_bentley_1.StopWatch(`[${container.containerId}/${dbName}]`, true);
146
146
  core_bentley_1.Logger.logInfo(loggerCategory, `Starting prefetch of ${stopwatch.description}`, { minRequests, maxRequests, timeout });
@@ -151,7 +151,7 @@ class V2CheckpointManager {
151
151
  logPrefetch(CloudSqlite_1.CloudSqlite.startCloudPrefetch(container, dbName, { minRequests, nRequests: maxRequests, timeout }));
152
152
  }
153
153
  else {
154
- core_bentley_1.Logger.logInfo(loggerCategory, `Skipping prefetch due to size limits.`, { maxBlocks, totalBlocksInDb: dbStats?.totalBlocks, v2props });
154
+ core_bentley_1.Logger.logInfo(loggerCategory, `Skipping prefetch due to size limits or ongoing prefetch.`, { maxBlocks, numPrefetches: dbStats?.nPrefetch, totalBlocksInDb: dbStats?.totalBlocks, v2props });
155
155
  }
156
156
  }
157
157
  return { dbName, container };
@@ -224,7 +224,10 @@ class CheckpointManager {
224
224
  static async doDownload(request) {
225
225
  try {
226
226
  // first see if there's a V2 checkpoint available.
227
+ const stopwatch = new core_bentley_1.StopWatch(`[${request.checkpoint.changeset.id}]`, true);
228
+ core_bentley_1.Logger.logInfo(loggerCategory, `Starting download of V2 checkpoint with id ${stopwatch.description}`);
227
229
  const changesetId = await V2CheckpointManager.downloadCheckpoint(request);
230
+ core_bentley_1.Logger.logInfo(loggerCategory, `Downloaded V2 checkpoint with id ${stopwatch.description} (${stopwatch.elapsedSeconds} seconds)`);
228
231
  if (changesetId !== request.checkpoint.changeset.id)
229
232
  core_bentley_1.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 });
230
233
  else
@@ -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,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,SAAS,CAAC;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C,EAAE,KAAK,QAAQ,CAAC,mBAAmB,EAAE,CAAC,EAAE,CAAC;QAChI,QAAQ,CAAC,WAAW,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO;YACV,uBAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAElC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,uEAAuE;IAChE,MAAM,CAAC,gBAAgB,CAAC,OAAwB;QACrD,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACtC,IAAI,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC;YACtD,OAAO,qBAAU,CAAC,gBAAgB,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAEpE,iHAAiH;QACjH,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,UAAU,EAAE;gBACtC,IAAI,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE;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;;AAzJsB,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) {\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.`, { maxBlocks, 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 changesetId = await V2CheckpointManager.downloadCheckpoint(request);\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,G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,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAEpE,iHAAiH;QACjH,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,UAAU,EAAE;gBACtC,IAAI,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE;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, 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"]}