@fluidframework/container-loader 2.0.0-rc.2.0.2 → 2.0.0-rc.3.0.1

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 (246) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/api-report/container-loader.api.md +13 -13
  3. package/dist/attachment.d.ts +6 -9
  4. package/dist/attachment.d.ts.map +1 -1
  5. package/dist/attachment.js +5 -5
  6. package/dist/attachment.js.map +1 -1
  7. package/dist/audience.d.ts +1 -1
  8. package/dist/audience.d.ts.map +1 -1
  9. package/dist/audience.js +4 -4
  10. package/dist/audience.js.map +1 -1
  11. package/dist/catchUpMonitor.d.ts +1 -1
  12. package/dist/catchUpMonitor.d.ts.map +1 -1
  13. package/dist/catchUpMonitor.js +2 -2
  14. package/dist/catchUpMonitor.js.map +1 -1
  15. package/dist/connectionManager.d.ts +4 -4
  16. package/dist/connectionManager.d.ts.map +1 -1
  17. package/dist/connectionManager.js +48 -43
  18. package/dist/connectionManager.js.map +1 -1
  19. package/dist/connectionStateHandler.d.ts +3 -3
  20. package/dist/connectionStateHandler.d.ts.map +1 -1
  21. package/dist/connectionStateHandler.js +27 -27
  22. package/dist/connectionStateHandler.js.map +1 -1
  23. package/dist/container.d.ts +9 -46
  24. package/dist/container.d.ts.map +1 -1
  25. package/dist/container.js +105 -116
  26. package/dist/container.js.map +1 -1
  27. package/dist/containerContext.d.ts +19 -7
  28. package/dist/containerContext.d.ts.map +1 -1
  29. package/dist/containerContext.js +7 -2
  30. package/dist/containerContext.js.map +1 -1
  31. package/dist/containerStorageAdapter.d.ts +3 -3
  32. package/dist/containerStorageAdapter.d.ts.map +1 -1
  33. package/dist/containerStorageAdapter.js +6 -6
  34. package/dist/containerStorageAdapter.js.map +1 -1
  35. package/dist/contracts.d.ts +4 -3
  36. package/dist/contracts.d.ts.map +1 -1
  37. package/dist/contracts.js +2 -2
  38. package/dist/contracts.js.map +1 -1
  39. package/dist/debugLogger.d.ts +2 -1
  40. package/dist/debugLogger.d.ts.map +1 -1
  41. package/dist/debugLogger.js +4 -4
  42. package/dist/debugLogger.js.map +1 -1
  43. package/dist/deltaManager.d.ts +11 -7
  44. package/dist/deltaManager.d.ts.map +1 -1
  45. package/dist/deltaManager.js +53 -50
  46. package/dist/deltaManager.js.map +1 -1
  47. package/dist/deltaQueue.d.ts +1 -1
  48. package/dist/deltaQueue.d.ts.map +1 -1
  49. package/dist/deltaQueue.js +5 -5
  50. package/dist/deltaQueue.js.map +1 -1
  51. package/dist/error.d.ts +3 -2
  52. package/dist/error.d.ts.map +1 -1
  53. package/dist/error.js +5 -5
  54. package/dist/error.js.map +1 -1
  55. package/dist/legacy.d.ts +29 -0
  56. package/dist/loader.d.ts +4 -4
  57. package/dist/loader.d.ts.map +1 -1
  58. package/dist/loader.js +23 -23
  59. package/dist/loader.js.map +1 -1
  60. package/dist/location-redirection-utilities/resolveWithLocationRedirection.d.ts +2 -2
  61. package/dist/location-redirection-utilities/resolveWithLocationRedirection.d.ts.map +1 -1
  62. package/dist/location-redirection-utilities/resolveWithLocationRedirection.js +2 -2
  63. package/dist/location-redirection-utilities/resolveWithLocationRedirection.js.map +1 -1
  64. package/dist/noopHeuristic.d.ts +1 -1
  65. package/dist/noopHeuristic.d.ts.map +1 -1
  66. package/dist/noopHeuristic.js +6 -6
  67. package/dist/noopHeuristic.js.map +1 -1
  68. package/dist/packageVersion.d.ts +1 -1
  69. package/dist/packageVersion.js +1 -1
  70. package/dist/packageVersion.js.map +1 -1
  71. package/dist/protocol.d.ts +1 -1
  72. package/dist/protocol.d.ts.map +1 -1
  73. package/dist/protocol.js +2 -2
  74. package/dist/protocol.js.map +1 -1
  75. package/dist/protocolTreeDocumentStorageService.d.ts +4 -4
  76. package/dist/protocolTreeDocumentStorageService.d.ts.map +1 -1
  77. package/dist/protocolTreeDocumentStorageService.js.map +1 -1
  78. package/dist/public.d.ts +14 -0
  79. package/dist/quorum.d.ts +1 -1
  80. package/dist/quorum.d.ts.map +1 -1
  81. package/dist/quorum.js +4 -0
  82. package/dist/quorum.js.map +1 -1
  83. package/dist/retriableDocumentStorageService.d.ts +2 -2
  84. package/dist/retriableDocumentStorageService.d.ts.map +1 -1
  85. package/dist/retriableDocumentStorageService.js +7 -7
  86. package/dist/retriableDocumentStorageService.js.map +1 -1
  87. package/dist/serializedStateManager.d.ts +86 -16
  88. package/dist/serializedStateManager.d.ts.map +1 -1
  89. package/dist/serializedStateManager.js +182 -82
  90. package/dist/serializedStateManager.js.map +1 -1
  91. package/dist/utils.d.ts +24 -9
  92. package/dist/utils.d.ts.map +1 -1
  93. package/dist/utils.js +82 -25
  94. package/dist/utils.js.map +1 -1
  95. package/internal.d.ts +11 -0
  96. package/legacy.d.ts +11 -0
  97. package/lib/attachment.d.ts +6 -9
  98. package/lib/attachment.d.ts.map +1 -1
  99. package/lib/attachment.js +1 -1
  100. package/lib/attachment.js.map +1 -1
  101. package/lib/audience.d.ts +1 -1
  102. package/lib/audience.d.ts.map +1 -1
  103. package/lib/audience.js +1 -1
  104. package/lib/audience.js.map +1 -1
  105. package/lib/catchUpMonitor.d.ts +1 -1
  106. package/lib/catchUpMonitor.d.ts.map +1 -1
  107. package/lib/catchUpMonitor.js +1 -1
  108. package/lib/catchUpMonitor.js.map +1 -1
  109. package/lib/connectionManager.d.ts +4 -4
  110. package/lib/connectionManager.d.ts.map +1 -1
  111. package/lib/connectionManager.js +11 -6
  112. package/lib/connectionManager.js.map +1 -1
  113. package/lib/connectionStateHandler.d.ts +3 -3
  114. package/lib/connectionStateHandler.d.ts.map +1 -1
  115. package/lib/connectionStateHandler.js +2 -2
  116. package/lib/connectionStateHandler.js.map +1 -1
  117. package/lib/container.d.ts +9 -46
  118. package/lib/container.d.ts.map +1 -1
  119. package/lib/container.js +37 -48
  120. package/lib/container.js.map +1 -1
  121. package/lib/containerContext.d.ts +19 -7
  122. package/lib/containerContext.d.ts.map +1 -1
  123. package/lib/containerContext.js +7 -2
  124. package/lib/containerContext.js.map +1 -1
  125. package/lib/containerStorageAdapter.d.ts +3 -3
  126. package/lib/containerStorageAdapter.d.ts.map +1 -1
  127. package/lib/containerStorageAdapter.js +2 -2
  128. package/lib/containerStorageAdapter.js.map +1 -1
  129. package/lib/contracts.d.ts +4 -3
  130. package/lib/contracts.d.ts.map +1 -1
  131. package/lib/contracts.js +1 -1
  132. package/lib/contracts.js.map +1 -1
  133. package/lib/debugLogger.d.ts +2 -1
  134. package/lib/debugLogger.d.ts.map +1 -1
  135. package/lib/debugLogger.js +1 -1
  136. package/lib/debugLogger.js.map +1 -1
  137. package/lib/deltaManager.d.ts +11 -7
  138. package/lib/deltaManager.d.ts.map +1 -1
  139. package/lib/deltaManager.js +13 -10
  140. package/lib/deltaManager.js.map +1 -1
  141. package/lib/deltaQueue.d.ts +1 -1
  142. package/lib/deltaQueue.d.ts.map +1 -1
  143. package/lib/deltaQueue.js +2 -2
  144. package/lib/deltaQueue.js.map +1 -1
  145. package/lib/error.d.ts +3 -2
  146. package/lib/error.d.ts.map +1 -1
  147. package/lib/error.js +2 -2
  148. package/lib/error.js.map +1 -1
  149. package/lib/legacy.d.ts +29 -0
  150. package/lib/loader.d.ts +4 -4
  151. package/lib/loader.d.ts.map +1 -1
  152. package/lib/loader.js +4 -4
  153. package/lib/loader.js.map +1 -1
  154. package/lib/location-redirection-utilities/resolveWithLocationRedirection.d.ts +2 -2
  155. package/lib/location-redirection-utilities/resolveWithLocationRedirection.d.ts.map +1 -1
  156. package/lib/location-redirection-utilities/resolveWithLocationRedirection.js +2 -2
  157. package/lib/location-redirection-utilities/resolveWithLocationRedirection.js.map +1 -1
  158. package/lib/noopHeuristic.d.ts +1 -1
  159. package/lib/noopHeuristic.d.ts.map +1 -1
  160. package/lib/noopHeuristic.js +2 -2
  161. package/lib/noopHeuristic.js.map +1 -1
  162. package/lib/packageVersion.d.ts +1 -1
  163. package/lib/packageVersion.js +1 -1
  164. package/lib/packageVersion.js.map +1 -1
  165. package/lib/protocol.d.ts +1 -1
  166. package/lib/protocol.d.ts.map +1 -1
  167. package/lib/protocol.js +1 -1
  168. package/lib/protocol.js.map +1 -1
  169. package/lib/protocolTreeDocumentStorageService.d.ts +4 -4
  170. package/lib/protocolTreeDocumentStorageService.d.ts.map +1 -1
  171. package/lib/protocolTreeDocumentStorageService.js.map +1 -1
  172. package/lib/public.d.ts +14 -0
  173. package/lib/quorum.d.ts +1 -1
  174. package/lib/quorum.d.ts.map +1 -1
  175. package/lib/quorum.js +4 -0
  176. package/lib/quorum.js.map +1 -1
  177. package/lib/retriableDocumentStorageService.d.ts +2 -2
  178. package/lib/retriableDocumentStorageService.d.ts.map +1 -1
  179. package/lib/retriableDocumentStorageService.js +3 -3
  180. package/lib/retriableDocumentStorageService.js.map +1 -1
  181. package/lib/serializedStateManager.d.ts +86 -16
  182. package/lib/serializedStateManager.d.ts.map +1 -1
  183. package/lib/serializedStateManager.js +174 -77
  184. package/lib/serializedStateManager.js.map +1 -1
  185. package/lib/utils.d.ts +24 -9
  186. package/lib/utils.d.ts.map +1 -1
  187. package/lib/utils.js +69 -15
  188. package/lib/utils.js.map +1 -1
  189. package/package.json +37 -58
  190. package/src/attachment.ts +10 -8
  191. package/src/audience.ts +3 -2
  192. package/src/catchUpMonitor.ts +2 -2
  193. package/src/connectionManager.ts +27 -20
  194. package/src/connectionStateHandler.ts +7 -7
  195. package/src/container.ts +90 -143
  196. package/src/containerContext.ts +22 -12
  197. package/src/containerStorageAdapter.ts +7 -6
  198. package/src/contracts.ts +4 -5
  199. package/src/debugLogger.ts +3 -4
  200. package/src/deltaManager.ts +40 -30
  201. package/src/deltaQueue.ts +2 -2
  202. package/src/error.ts +5 -4
  203. package/src/loader.ts +25 -23
  204. package/src/location-redirection-utilities/resolveWithLocationRedirection.ts +4 -4
  205. package/src/noopHeuristic.ts +3 -3
  206. package/src/packageVersion.ts +1 -1
  207. package/src/protocol.ts +2 -2
  208. package/src/protocolTreeDocumentStorageService.ts +4 -1
  209. package/src/quorum.ts +2 -1
  210. package/src/retriableDocumentStorageService.ts +6 -5
  211. package/src/serializedStateManager.ts +299 -111
  212. package/src/utils.ts +103 -24
  213. package/api-extractor-cjs.json +0 -8
  214. package/dist/container-loader-alpha.d.ts +0 -275
  215. package/dist/container-loader-beta.d.ts +0 -101
  216. package/dist/container-loader-public.d.ts +0 -101
  217. package/dist/container-loader-untrimmed.d.ts +0 -331
  218. package/lib/container-loader-alpha.d.ts +0 -275
  219. package/lib/container-loader-beta.d.ts +0 -101
  220. package/lib/container-loader-public.d.ts +0 -101
  221. package/lib/container-loader-untrimmed.d.ts +0 -331
  222. package/lib/test/attachment.spec.js +0 -380
  223. package/lib/test/attachment.spec.js.map +0 -1
  224. package/lib/test/catchUpMonitor.spec.js +0 -88
  225. package/lib/test/catchUpMonitor.spec.js.map +0 -1
  226. package/lib/test/connectionManager.spec.js +0 -201
  227. package/lib/test/connectionManager.spec.js.map +0 -1
  228. package/lib/test/connectionStateHandler.spec.js +0 -555
  229. package/lib/test/connectionStateHandler.spec.js.map +0 -1
  230. package/lib/test/container.spec.js +0 -64
  231. package/lib/test/container.spec.js.map +0 -1
  232. package/lib/test/deltaManager.spec.js +0 -405
  233. package/lib/test/deltaManager.spec.js.map +0 -1
  234. package/lib/test/loader.spec.js +0 -212
  235. package/lib/test/loader.spec.js.map +0 -1
  236. package/lib/test/locationRedirectionTests.spec.js +0 -44
  237. package/lib/test/locationRedirectionTests.spec.js.map +0 -1
  238. package/lib/test/serializedStateManager.spec.js +0 -148
  239. package/lib/test/serializedStateManager.spec.js.map +0 -1
  240. package/lib/test/snapshotConversionTest.spec.js +0 -79
  241. package/lib/test/snapshotConversionTest.spec.js.map +0 -1
  242. package/lib/test/types/validateContainerLoaderPrevious.generated.js +0 -38
  243. package/lib/test/types/validateContainerLoaderPrevious.generated.js.map +0 -1
  244. package/lib/test/utils.spec.js +0 -31
  245. package/lib/test/utils.spec.js.map +0 -1
  246. /package/{dist → lib}/tsdoc-metadata.json +0 -0
@@ -5,9 +5,9 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.RetriableDocumentStorageService = void 0;
8
- const core_utils_1 = require("@fluidframework/core-utils");
9
- const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
10
- const driver_utils_1 = require("@fluidframework/driver-utils");
8
+ const internal_1 = require("@fluidframework/core-utils/internal");
9
+ const internal_2 = require("@fluidframework/driver-utils/internal");
10
+ const internal_3 = require("@fluidframework/telemetry-utils/internal");
11
11
  class RetriableDocumentStorageService {
12
12
  constructor(internalStorageServiceP, logger) {
13
13
  this.internalStorageServiceP = internalStorageServiceP;
@@ -35,7 +35,7 @@ class RetriableDocumentStorageService {
35
35
  if (s.getSnapshot !== undefined) {
36
36
  return s.getSnapshot(snapshotFetchOptions);
37
37
  }
38
- throw new telemetry_utils_1.UsageError("getSnapshot api should exist on internal storage in RetriableDocStorageService class");
38
+ throw new internal_3.UsageError("getSnapshot api should exist on internal storage in RetriableDocStorageService class");
39
39
  }), "storage_getSnapshot");
40
40
  }
41
41
  async readBlob(id) {
@@ -54,7 +54,7 @@ class RetriableDocumentStorageService {
54
54
  // upload in 10 minutes - it's better to keep processing ops and retry later. Though caller needs to take
55
55
  // retryAfter into account!
56
56
  // But retry loop is required for creation flow (Container.attach)
57
- (0, core_utils_1.assert)((context.referenceSequenceNumber === 0) === (context.ackHandle === undefined), 0x251 /* "creation summary has to have seq=0 && handle === undefined" */);
57
+ (0, internal_1.assert)((context.referenceSequenceNumber === 0) === (context.ackHandle === undefined), 0x251 /* "creation summary has to have seq=0 && handle === undefined" */);
58
58
  if (context.referenceSequenceNumber !== 0) {
59
59
  return this.internalStorageServiceP.then(async (s) => s.uploadSummaryWithContext(summary, context));
60
60
  }
@@ -74,14 +74,14 @@ class RetriableDocumentStorageService {
74
74
  fetchCallName: callName, // fetchCallName matches logs in runWithRetry.ts
75
75
  }, error);
76
76
  // pre-0.58 error message: storageServiceDisposedCannotRetry
77
- throw new telemetry_utils_1.GenericError("Storage Service is disposed. Cannot retry", {
77
+ throw new internal_3.GenericError("Storage Service is disposed. Cannot retry", {
78
78
  canRetry: false,
79
79
  });
80
80
  }
81
81
  return;
82
82
  }
83
83
  async runWithRetry(api, callName) {
84
- return (0, driver_utils_1.runWithRetry)(api, callName, this.logger, {
84
+ return (0, internal_2.runWithRetry)(api, callName, this.logger, {
85
85
  onRetry: (_delayInMs, error) => this.checkStorageDisposed(callName, error),
86
86
  });
87
87
  }
@@ -1 +1 @@
1
- {"version":3,"file":"retriableDocumentStorageService.js","sourceRoot":"","sources":["../src/retriableDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2DAAoD;AAiBpD,qEAAgG;AAChG,+DAA4D;AAE5D,MAAa,+BAA+B;IAG3C,YACkB,uBAAyD,EACzD,MAA2B;QAD3B,4BAAuB,GAAvB,uBAAuB,CAAkC;QACzD,WAAM,GAAN,MAAM,CAAqB;QAJrC,cAAS,GAAG,KAAK,CAAC;QAMzB,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,sBAAsB,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC7F,CAAC;IAED,IAAW,QAAQ;QAClB,IAAI,IAAI,CAAC,sBAAsB,EAAE;YAChC,OAAO,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC;SAC5C;QACD,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACzD,CAAC;IACD,IAAW,QAAQ;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IACM,OAAO;QACb,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACvB,CAAC;IAEM,KAAK,CAAC,eAAe,CAC3B,OAAkB,EAClB,YAAqB;QAErB,OAAO,IAAI,CAAC,YAAY,CACvB,KAAK,IAAI,EAAE,CACV,IAAI,CAAC,uBAAuB,CAAC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CAAC,SAAS,EAAE;YACnB,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAC7B;gBACC,SAAS,EAAE,GAAG,QAAQ,yBAAyB;gBAC/C,aAAa,EAAE,QAAQ,EAAE,gDAAgD;aACzE,EACD,KAAK,CACL,CAAC;YACF,4DAA4D;YAC5D,MAAM,IAAI,8BAAY,CAAC,2CAA2C,EAAE;gBACnE,QAAQ,EAAE,KAAK;aACf,CAAC,CAAC;SACH;QACD,OAAO;IACR,CAAC;IAEO,KAAK,CAAC,YAAY,CAAI,GAAqB,EAAE,QAAgB;QACpE,OAAO,IAAA,2BAAY,EAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE;YAC/C,OAAO,EAAE,CAAC,UAAkB,EAAE,KAAc,EAAE,EAAE,CAC/C,IAAI,CAAC,oBAAoB,CAAC,QAAQ,EAAE,KAAK,CAAC;SAC3C,CAAC,CAAC;IACJ,CAAC;CACD;AA/ID,0EA+IC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport {\n\tFetchSource,\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tISnapshot,\n\tISnapshotFetchOptions,\n\tISummaryContext,\n} from \"@fluidframework/driver-definitions\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTree,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport { IDisposable } from \"@fluidframework/core-interfaces\";\nimport { GenericError, ITelemetryLoggerExt, UsageError } from \"@fluidframework/telemetry-utils\";\nimport { runWithRetry } from \"@fluidframework/driver-utils\";\n\nexport class RetriableDocumentStorageService implements IDocumentStorageService, IDisposable {\n\tprivate _disposed = false;\n\tprivate internalStorageService: IDocumentStorageService | undefined;\n\tconstructor(\n\t\tprivate readonly internalStorageServiceP: Promise<IDocumentStorageService>,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t) {\n\t\tthis.internalStorageServiceP.then((s) => (this.internalStorageService = s)).catch(() => {});\n\t}\n\n\tpublic get policies(): IDocumentStorageServicePolicies | undefined {\n\t\tif (this.internalStorageService) {\n\t\t\treturn this.internalStorageService.policies;\n\t\t}\n\t\tthrow new Error(\"storage service not yet instantiated\");\n\t}\n\tpublic get disposed() {\n\t\treturn this._disposed;\n\t}\n\tpublic dispose() {\n\t\tthis._disposed = true;\n\t}\n\n\tpublic async getSnapshotTree(\n\t\tversion?: IVersion,\n\t\tscenarioName?: string,\n\t): Promise<ISnapshotTree | null> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () =>\n\t\t\t\tthis.internalStorageServiceP.then(async (s) =>\n\t\t\t\t\ts.getSnapshotTree(version, scenarioName),\n\t\t\t\t),\n\t\t\t\"storage_getSnapshotTree\",\n\t\t);\n\t}\n\n\tpublic async getSnapshot(snapshotFetchOptions?: ISnapshotFetchOptions): Promise<ISnapshot> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () =>\n\t\t\t\tthis.internalStorageServiceP.then(async (s) => {\n\t\t\t\t\tif (s.getSnapshot !== undefined) {\n\t\t\t\t\t\treturn s.getSnapshot(snapshotFetchOptions);\n\t\t\t\t\t}\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"getSnapshot api should exist on internal storage in RetriableDocStorageService class\",\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t\"storage_getSnapshot\",\n\t\t);\n\t}\n\n\tpublic async readBlob(id: string): Promise<ArrayBufferLike> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () => this.internalStorageServiceP.then(async (s) => s.readBlob(id)),\n\t\t\t\"storage_readBlob\",\n\t\t);\n\t}\n\n\tpublic async getVersions(\n\t\tversionId: string | null,\n\t\tcount: number,\n\t\tscenarioName?: string,\n\t\tfetchSource?: FetchSource,\n\t): Promise<IVersion[]> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () =>\n\t\t\t\tthis.internalStorageServiceP.then(async (s) =>\n\t\t\t\t\ts.getVersions(versionId, count, scenarioName, fetchSource),\n\t\t\t\t),\n\t\t\t\"storage_getVersions\",\n\t\t);\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\t// Not using retry loop here. Couple reasons:\n\t\t// 1. If client lost connectivity, then retry loop will result in uploading stale summary\n\t\t// by stale summarizer after connectivity comes back. It will cause failures for this client and for\n\t\t// real (new) summarizer. This problem in particular should be solved in future by supplying abort handle\n\t\t// on all APIs and caller (ContainerRuntime.submitSummary) aborting call on loss of connectivity\n\t\t// 2. Similar, if we get 429 with retryAfter = 10 minutes, it's likely not the right call to retry summary\n\t\t// upload in 10 minutes - it's better to keep processing ops and retry later. Though caller needs to take\n\t\t// retryAfter into account!\n\t\t// But retry loop is required for creation flow (Container.attach)\n\t\tassert(\n\t\t\t(context.referenceSequenceNumber === 0) === (context.ackHandle === undefined),\n\t\t\t0x251 /* \"creation summary has to have seq=0 && handle === undefined\" */,\n\t\t);\n\t\tif (context.referenceSequenceNumber !== 0) {\n\t\t\treturn this.internalStorageServiceP.then(async (s) =>\n\t\t\t\ts.uploadSummaryWithContext(summary, context),\n\t\t\t);\n\t\t}\n\n\t\t// Creation flow with attachment blobs - need to do retries!\n\t\treturn this.runWithRetry(\n\t\t\tasync () =>\n\t\t\t\tthis.internalStorageServiceP.then(async (s) =>\n\t\t\t\t\ts.uploadSummaryWithContext(summary, context),\n\t\t\t\t),\n\t\t\t\"storage_uploadSummaryWithContext\",\n\t\t);\n\t}\n\n\tpublic async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () => this.internalStorageServiceP.then(async (s) => s.downloadSummary(handle)),\n\t\t\t\"storage_downloadSummary\",\n\t\t);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () => this.internalStorageServiceP.then(async (s) => s.createBlob(file)),\n\t\t\t\"storage_createBlob\",\n\t\t);\n\t}\n\n\tprivate checkStorageDisposed(callName: string, error: unknown) {\n\t\tif (this._disposed) {\n\t\t\tthis.logger.sendTelemetryEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: `${callName}_abortedStorageDisposed`,\n\t\t\t\t\tfetchCallName: callName, // fetchCallName matches logs in runWithRetry.ts\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\t\t\t// pre-0.58 error message: storageServiceDisposedCannotRetry\n\t\t\tthrow new GenericError(\"Storage Service is disposed. Cannot retry\", {\n\t\t\t\tcanRetry: false,\n\t\t\t});\n\t\t}\n\t\treturn;\n\t}\n\n\tprivate async runWithRetry<T>(api: () => Promise<T>, callName: string): Promise<T> {\n\t\treturn runWithRetry(api, callName, this.logger, {\n\t\t\tonRetry: (_delayInMs: number, error: unknown) =>\n\t\t\t\tthis.checkStorageDisposed(callName, error),\n\t\t});\n\t}\n}\n"]}
1
+ {"version":3,"file":"retriableDocumentStorageService.js","sourceRoot":"","sources":["../src/retriableDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAA6D;AAS7D,oEAAqE;AASrE,uEAAoF;AAEpF,MAAa,+BAA+B;IAG3C,YACkB,uBAAyD,EACzD,MAA2B;QAD3B,4BAAuB,GAAvB,uBAAuB,CAAkC;QACzD,WAAM,GAAN,MAAM,CAAqB;QAJrC,cAAS,GAAG,KAAK,CAAC;QAMzB,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,sBAAsB,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC7F,CAAC;IAED,IAAW,QAAQ;QAClB,IAAI,IAAI,CAAC,sBAAsB,EAAE;YAChC,OAAO,IAAI,CAAC,sBAAsB,CAAC,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rF,yBAAyB,CACzB,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,IAAqB;QAC5C,OAAO,IAAI,CAAC,YAAY,CACvB,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,EAC9E,oBAAoB,CACpB,CAAC;IACH,CAAC;IAEO,oBAAoB,CAAC,QAAgB,EAAE,KAAc;QAC5D,IAAI,IAAI,CAAC,SAAS,EAAE;YACnB,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAC7B;gBACC,SAAS,EAAE,GAAG,QAAQ,yBAAyB;gBAC/C,aAAa,EAAE,QAAQ,EAAE,gDAAgD;aACzE,EACD,KAAK,CACL,CAAC;YACF,4DAA4D;YAC5D,MAAM,IAAI,uBAAY,CAAC,2CAA2C,EAAE;gBACnE,QAAQ,EAAE,KAAK;aACf,CAAC,CAAC;SACH;QACD,OAAO;IACR,CAAC;IAEO,KAAK,CAAC,YAAY,CAAI,GAAqB,EAAE,QAAgB;QACpE,OAAO,IAAA,uBAAY,EAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE;YAC/C,OAAO,EAAE,CAAC,UAAkB,EAAE,KAAc,EAAE,EAAE,CAC/C,IAAI,CAAC,oBAAoB,CAAC,QAAQ,EAAE,KAAK,CAAC;SAC3C,CAAC,CAAC;IACJ,CAAC;CACD;AA/ID,0EA+IC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDisposable } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tFetchSource,\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tISnapshot,\n\tISnapshotFetchOptions,\n\tISummaryContext,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { runWithRetry } from \"@fluidframework/driver-utils/internal\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTree,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport { ITelemetryLoggerExt } from \"@fluidframework/telemetry-utils\";\nimport { GenericError, UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nexport class RetriableDocumentStorageService implements IDocumentStorageService, IDisposable {\n\tprivate _disposed = false;\n\tprivate internalStorageService: IDocumentStorageService | undefined;\n\tconstructor(\n\t\tprivate readonly internalStorageServiceP: Promise<IDocumentStorageService>,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t) {\n\t\tthis.internalStorageServiceP.then((s) => (this.internalStorageService = s)).catch(() => {});\n\t}\n\n\tpublic get policies(): IDocumentStorageServicePolicies | undefined {\n\t\tif (this.internalStorageService) {\n\t\t\treturn this.internalStorageService.policies;\n\t\t}\n\t\tthrow new Error(\"storage service not yet instantiated\");\n\t}\n\tpublic get disposed() {\n\t\treturn this._disposed;\n\t}\n\tpublic dispose() {\n\t\tthis._disposed = true;\n\t}\n\n\tpublic async getSnapshotTree(\n\t\tversion?: IVersion,\n\t\tscenarioName?: string,\n\t): Promise<ISnapshotTree | null> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () =>\n\t\t\t\tthis.internalStorageServiceP.then(async (s) =>\n\t\t\t\t\ts.getSnapshotTree(version, scenarioName),\n\t\t\t\t),\n\t\t\t\"storage_getSnapshotTree\",\n\t\t);\n\t}\n\n\tpublic async getSnapshot(snapshotFetchOptions?: ISnapshotFetchOptions): Promise<ISnapshot> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () =>\n\t\t\t\tthis.internalStorageServiceP.then(async (s) => {\n\t\t\t\t\tif (s.getSnapshot !== undefined) {\n\t\t\t\t\t\treturn s.getSnapshot(snapshotFetchOptions);\n\t\t\t\t\t}\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"getSnapshot api should exist on internal storage in RetriableDocStorageService class\",\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t\"storage_getSnapshot\",\n\t\t);\n\t}\n\n\tpublic async readBlob(id: string): Promise<ArrayBufferLike> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () => this.internalStorageServiceP.then(async (s) => s.readBlob(id)),\n\t\t\t\"storage_readBlob\",\n\t\t);\n\t}\n\n\tpublic async getVersions(\n\t\tversionId: string | null,\n\t\tcount: number,\n\t\tscenarioName?: string,\n\t\tfetchSource?: FetchSource,\n\t): Promise<IVersion[]> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () =>\n\t\t\t\tthis.internalStorageServiceP.then(async (s) =>\n\t\t\t\t\ts.getVersions(versionId, count, scenarioName, fetchSource),\n\t\t\t\t),\n\t\t\t\"storage_getVersions\",\n\t\t);\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\t// Not using retry loop here. Couple reasons:\n\t\t// 1. If client lost connectivity, then retry loop will result in uploading stale summary\n\t\t// by stale summarizer after connectivity comes back. It will cause failures for this client and for\n\t\t// real (new) summarizer. This problem in particular should be solved in future by supplying abort handle\n\t\t// on all APIs and caller (ContainerRuntime.submitSummary) aborting call on loss of connectivity\n\t\t// 2. Similar, if we get 429 with retryAfter = 10 minutes, it's likely not the right call to retry summary\n\t\t// upload in 10 minutes - it's better to keep processing ops and retry later. Though caller needs to take\n\t\t// retryAfter into account!\n\t\t// But retry loop is required for creation flow (Container.attach)\n\t\tassert(\n\t\t\t(context.referenceSequenceNumber === 0) === (context.ackHandle === undefined),\n\t\t\t0x251 /* \"creation summary has to have seq=0 && handle === undefined\" */,\n\t\t);\n\t\tif (context.referenceSequenceNumber !== 0) {\n\t\t\treturn this.internalStorageServiceP.then(async (s) =>\n\t\t\t\ts.uploadSummaryWithContext(summary, context),\n\t\t\t);\n\t\t}\n\n\t\t// Creation flow with attachment blobs - need to do retries!\n\t\treturn this.runWithRetry(\n\t\t\tasync () =>\n\t\t\t\tthis.internalStorageServiceP.then(async (s) =>\n\t\t\t\t\ts.uploadSummaryWithContext(summary, context),\n\t\t\t\t),\n\t\t\t\"storage_uploadSummaryWithContext\",\n\t\t);\n\t}\n\n\tpublic async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () => this.internalStorageServiceP.then(async (s) => s.downloadSummary(handle)),\n\t\t\t\"storage_downloadSummary\",\n\t\t);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\treturn this.runWithRetry(\n\t\t\tasync () => this.internalStorageServiceP.then(async (s) => s.createBlob(file)),\n\t\t\t\"storage_createBlob\",\n\t\t);\n\t}\n\n\tprivate checkStorageDisposed(callName: string, error: unknown) {\n\t\tif (this._disposed) {\n\t\t\tthis.logger.sendTelemetryEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: `${callName}_abortedStorageDisposed`,\n\t\t\t\t\tfetchCallName: callName, // fetchCallName matches logs in runWithRetry.ts\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\t\t\t// pre-0.58 error message: storageServiceDisposedCannotRetry\n\t\t\tthrow new GenericError(\"Storage Service is disposed. Cannot retry\", {\n\t\t\t\tcanRetry: false,\n\t\t\t});\n\t\t}\n\t\treturn;\n\t}\n\n\tprivate async runWithRetry<T>(api: () => Promise<T>, callName: string): Promise<T> {\n\t\treturn runWithRetry(api, callName, this.logger, {\n\t\t\tonRetry: (_delayInMs: number, error: unknown) =>\n\t\t\t\tthis.checkStorageDisposed(callName, error),\n\t\t});\n\t}\n}\n"]}
@@ -2,43 +2,113 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ import { IGetPendingLocalStateProps, IRuntime } from "@fluidframework/container-definitions/internal";
6
+ import { IDocumentStorageService, IResolvedUrl, ISnapshot } from "@fluidframework/driver-definitions/internal";
5
7
  import { ISequencedDocumentMessage, ISnapshotTree, IVersion } from "@fluidframework/protocol-definitions";
6
- import { IGetPendingLocalStateProps, IRuntime } from "@fluidframework/container-definitions";
7
8
  import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils";
8
- import { IDocumentStorageService, IResolvedUrl } from "@fluidframework/driver-definitions";
9
+ import { MonitoringContext } from "@fluidframework/telemetry-utils/internal";
9
10
  import { ISerializableBlobContents } from "./containerStorageAdapter.js";
10
- import { IPendingContainerState } from "./container.js";
11
+ export interface SnapshotWithBlobs {
12
+ /**
13
+ * Snapshot from which container initially loaded.
14
+ */
15
+ baseSnapshot: ISnapshotTree;
16
+ /**
17
+ * Serializable blobs from the base snapshot. Used to load offline since
18
+ * storage is not available.
19
+ */
20
+ snapshotBlobs: ISerializableBlobContents;
21
+ }
22
+ /**
23
+ * State saved by a container at close time, to be used to load a new instance
24
+ * of the container to the same state
25
+ * @internal
26
+ */
27
+ export interface IPendingContainerState extends SnapshotWithBlobs {
28
+ attached: true;
29
+ pendingRuntimeState: unknown;
30
+ /**
31
+ * All ops since base snapshot sequence number up to the latest op
32
+ * seen when the container was closed. Used to apply stashed (saved pending)
33
+ * ops at the same sequence number at which they were made.
34
+ */
35
+ savedOps: ISequencedDocumentMessage[];
36
+ url: string;
37
+ clientId?: string;
38
+ }
39
+ /**
40
+ * State saved by a container in detached state, to be used to load a new instance
41
+ * of the container to the same state (rehydrate)
42
+ * @internal
43
+ */
44
+ export interface IPendingDetachedContainerState extends SnapshotWithBlobs {
45
+ attached: false;
46
+ hasAttachmentBlobs: boolean;
47
+ pendingRuntimeState?: unknown;
48
+ }
49
+ export interface ISnapshotInfo extends SnapshotWithBlobs {
50
+ snapshotSequenceNumber: number;
51
+ }
11
52
  export declare class SerializedStateManager {
12
53
  private readonly pendingLocalState;
13
54
  private readonly storageAdapter;
14
55
  private readonly _offlineLoadEnabled;
56
+ private readonly newSnapshotFetched?;
15
57
  private readonly processedOps;
16
58
  private snapshot;
17
59
  private readonly mc;
18
- constructor(pendingLocalState: IPendingContainerState | undefined, subLogger: ITelemetryLoggerExt, storageAdapter: Pick<IDocumentStorageService, "readBlob" | "getSnapshotTree" | "getSnapshot" | "getVersions">, _offlineLoadEnabled: boolean);
60
+ private latestSnapshot;
61
+ private refreshSnapshot;
62
+ constructor(pendingLocalState: IPendingContainerState | undefined, subLogger: ITelemetryLoggerExt, storageAdapter: Pick<IDocumentStorageService, "readBlob" | "getSnapshotTree" | "getSnapshot" | "getVersions">, _offlineLoadEnabled: boolean, newSnapshotFetched?: (() => void) | undefined);
19
63
  get offlineLoadEnabled(): boolean;
20
64
  addProcessedOp(message: ISequencedDocumentMessage): void;
21
- private getVersion;
22
- fetchSnapshot(specifiedVersion: string | undefined, supportGetSnapshotApi: boolean | undefined): Promise<{
23
- snapshotTree: ISnapshotTree | undefined;
65
+ fetchSnapshot(specifiedVersion: string | undefined, supportGetSnapshotApi: boolean): Promise<{
66
+ baseSnapshot: ISnapshotTree;
24
67
  version: IVersion | undefined;
25
68
  }>;
26
- private fetchSnapshotCore;
27
69
  /**
28
- * Get the most recent snapshot, or a specific version.
29
- * @param specifiedVersion - The specific version of the snapshot to retrieve
30
- * @returns The snapshot requested, or the latest snapshot if no version was specified, plus version ID
70
+ * Updates class snapshot and processedOps if we have a new snapshot and it's among processedOps range.
31
71
  */
32
- private fetchSnapshotTree;
72
+ private updateSnapshotAndProcessedOpsMaybe;
33
73
  /**
34
74
  * This method is only meant to be used by Container.attach() to set the initial
35
75
  * base snapshot when attaching.
36
76
  * @param snapshot - snapshot and blobs collected while attaching
37
77
  */
38
- setSnapshot(snapshot: {
39
- tree: ISnapshotTree;
40
- blobs: ISerializableBlobContents;
41
- } | undefined): void;
78
+ setInitialSnapshot(snapshot: SnapshotWithBlobs | undefined): void;
42
79
  getPendingLocalStateCore(props: IGetPendingLocalStateProps, clientId: string | undefined, runtime: Pick<IRuntime, "getPendingLocalState">, resolvedUrl: IResolvedUrl): Promise<string>;
43
80
  }
81
+ /**
82
+ * Retrieves the most recent snapshot and returns its info.
83
+ *
84
+ * @param mc - The monitoring context.
85
+ * @param storageAdapter - The storage adapter providing methods to retrieve the snapshot.
86
+ * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree.
87
+ * @returns a SnapshotInfo object containing the snapshot tree, snapshot blobs and its sequence number.
88
+ */
89
+ export declare function getLatestSnapshotInfo(mc: MonitoringContext, storageAdapter: Pick<IDocumentStorageService, "getSnapshot" | "getSnapshotTree" | "getVersions" | "readBlob">, supportGetSnapshotApi: boolean): Promise<ISnapshotInfo | undefined>;
90
+ /**
91
+ * Fetches an ISnapshot from a storage adapter based on the specified version.
92
+ *
93
+ * @param mc - The monitoring context.
94
+ * @param storageAdapter - The storage adapter providing a getSnapshot method to retrieve the ISnapshot and version.
95
+ * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.
96
+ * @returns - The fetched snapshot tree and its version.
97
+ */
98
+ export declare function fetchISnapshot(mc: MonitoringContext, storageAdapter: Pick<IDocumentStorageService, "getSnapshot">, specifiedVersion: string | undefined): Promise<{
99
+ snapshot?: ISnapshot;
100
+ version?: IVersion;
101
+ }>;
102
+ /**
103
+ * Fetches an ISnapshotTree from a storage adapter based on the specified version.
104
+ *
105
+ * @param mc - The monitoring context.
106
+ * @param storageAdapter - The storage adapter providing methods to retrieve the ISnapshotTree and version.
107
+ * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.
108
+ * @returns - The fetched snapshot tree and its version.
109
+ */
110
+ export declare function fetchISnapshotTree(mc: MonitoringContext, storageAdapter: Pick<IDocumentStorageService, "getSnapshotTree" | "getVersions">, specifiedVersion: string | undefined): Promise<{
111
+ snapshot?: ISnapshotTree;
112
+ version?: IVersion | undefined;
113
+ }>;
44
114
  //# sourceMappingURL=serializedStateManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serializedStateManager.d.ts","sourceRoot":"","sources":["../src/serializedStateManager.ts"],"names":[],"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AAO,GAC5B,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAoBpC;AA8BD;;;;;;;GAOG;AACH,wBAAsB,cAAc,CACnC,EAAE,EAAE,iBAAiB,EACrB,cAAc,EAAE,IAAI,CAAC,uBAAuB,EAAE,aAAa,CAAC,EAC5D,gBAAgB,EAAE,MAAM,GAAG,SAAS,GAClC,OAAO,CAAC;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAC;IAAC,OAAO,CAAC,EAAE,QAAQ,CAAA;CAAE,CAAC,CAsBvD;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACvC,EAAE,EAAE,iBAAiB,EACrB,cAAc,EAAE,IAAI,CAAC,uBAAuB,EAAE,iBAAiB,GAAG,aAAa,CAAC,EAChF,gBAAgB,EAAE,MAAM,GAAG,SAAS,GAClC,OAAO,CAAC;IAAE,QAAQ,CAAC,EAAE,aAAa,CAAC;IAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;CAAE,CAAC,CAsBvE"}
@@ -4,18 +4,20 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.SerializedStateManager = void 0;
8
- const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
9
- const core_utils_1 = require("@fluidframework/core-utils");
10
- const driver_utils_1 = require("@fluidframework/driver-utils");
7
+ exports.fetchISnapshotTree = exports.fetchISnapshot = exports.getLatestSnapshotInfo = exports.SerializedStateManager = void 0;
8
+ const internal_1 = require("@fluidframework/core-utils/internal");
9
+ const internal_2 = require("@fluidframework/driver-utils/internal");
10
+ const internal_3 = require("@fluidframework/telemetry-utils/internal");
11
11
  const containerStorageAdapter_js_1 = require("./containerStorageAdapter.js");
12
+ const utils_js_1 = require("./utils.js");
12
13
  class SerializedStateManager {
13
- constructor(pendingLocalState, subLogger, storageAdapter, _offlineLoadEnabled) {
14
+ constructor(pendingLocalState, subLogger, storageAdapter, _offlineLoadEnabled, newSnapshotFetched) {
14
15
  this.pendingLocalState = pendingLocalState;
15
16
  this.storageAdapter = storageAdapter;
16
17
  this._offlineLoadEnabled = _offlineLoadEnabled;
18
+ this.newSnapshotFetched = newSnapshotFetched;
17
19
  this.processedOps = [];
18
- this.mc = (0, telemetry_utils_1.createChildMonitoringContext)({
20
+ this.mc = (0, internal_3.createChildMonitoringContext)({
19
21
  logger: subLogger,
20
22
  namespace: "serializedStateManager",
21
23
  });
@@ -26,116 +28,115 @@ class SerializedStateManager {
26
28
  addProcessedOp(message) {
27
29
  if (this.offlineLoadEnabled) {
28
30
  this.processedOps.push(message);
31
+ this.updateSnapshotAndProcessedOpsMaybe();
29
32
  }
30
33
  }
31
- async getVersion(version) {
32
- const versions = await this.storageAdapter.getVersions(version, 1);
33
- return versions[0];
34
- }
35
34
  async fetchSnapshot(specifiedVersion, supportGetSnapshotApi) {
36
- const { snapshot, version } = this.pendingLocalState === undefined
37
- ? await this.fetchSnapshotCore(specifiedVersion, supportGetSnapshotApi)
38
- : { snapshot: this.pendingLocalState.baseSnapshot, version: undefined };
39
- const snapshotTree = (0, driver_utils_1.isInstanceOfISnapshot)(snapshot)
40
- ? snapshot.snapshotTree
41
- : snapshot;
42
- if (this.pendingLocalState) {
43
- this.snapshot = {
44
- tree: this.pendingLocalState.baseSnapshot,
45
- blobs: this.pendingLocalState.snapshotBlobs,
46
- };
47
- }
48
- else {
49
- (0, core_utils_1.assert)(snapshotTree !== undefined, 0x8e4 /* Snapshot should exist */);
35
+ if (this.pendingLocalState === undefined) {
36
+ const { baseSnapshot, version } = await getSnapshotTree(this.mc, this.storageAdapter, supportGetSnapshotApi, specifiedVersion);
50
37
  // non-interactive clients will not have any pending state we want to save
51
38
  if (this.offlineLoadEnabled) {
52
- const blobs = await (0, containerStorageAdapter_js_1.getBlobContentsFromTree)(snapshotTree, this.storageAdapter);
53
- this.snapshot = { tree: snapshotTree, blobs };
54
- }
55
- }
56
- return { snapshotTree, version };
57
- }
58
- async fetchSnapshotCore(specifiedVersion, supportGetSnapshotApi) {
59
- if (this.mc.config.getBoolean("Fluid.Container.UseLoadingGroupIdForSnapshotFetch") ===
60
- true &&
61
- supportGetSnapshotApi === true) {
62
- const snapshot = (await this.storageAdapter.getSnapshot?.({
63
- versionId: specifiedVersion,
64
- })) ?? undefined;
65
- const version = snapshot?.snapshotTree.id === undefined
66
- ? undefined
67
- : {
68
- id: snapshot.snapshotTree.id,
69
- treeId: snapshot.snapshotTree.id,
39
+ const snapshotBlobs = await (0, containerStorageAdapter_js_1.getBlobContentsFromTree)(baseSnapshot, this.storageAdapter);
40
+ const attributes = await (0, utils_js_1.getDocumentAttributes)(this.storageAdapter, baseSnapshot);
41
+ this.snapshot = {
42
+ baseSnapshot,
43
+ snapshotBlobs,
44
+ snapshotSequenceNumber: attributes.sequenceNumber,
70
45
  };
71
- if (snapshot === undefined && specifiedVersion !== undefined) {
72
- this.mc.logger.sendErrorEvent({
73
- eventName: "getSnapshotTreeFailed",
74
- id: specifiedVersion,
75
- });
76
- // Not sure if this should be here actually
77
- }
78
- else if (snapshot !== undefined && version?.id === undefined) {
79
- this.mc.logger.sendErrorEvent({
80
- eventName: "getSnapshotFetchedTreeWithoutVersionId",
81
- hasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.
82
- });
83
46
  }
84
- return { snapshot, version };
47
+ return { baseSnapshot, version };
48
+ }
49
+ else {
50
+ const { baseSnapshot, snapshotBlobs } = this.pendingLocalState;
51
+ const attributes = await (0, utils_js_1.getDocumentAttributes)(this.storageAdapter, baseSnapshot);
52
+ this.snapshot = {
53
+ baseSnapshot,
54
+ snapshotBlobs,
55
+ snapshotSequenceNumber: attributes.sequenceNumber,
56
+ };
57
+ this.refreshSnapshot ?? (this.refreshSnapshot = (async () => {
58
+ this.latestSnapshot = await getLatestSnapshotInfo(this.mc, this.storageAdapter, supportGetSnapshotApi);
59
+ this.newSnapshotFetched?.();
60
+ this.updateSnapshotAndProcessedOpsMaybe();
61
+ })());
62
+ return { baseSnapshot, version: undefined };
85
63
  }
86
- return this.fetchSnapshotTree(specifiedVersion);
87
64
  }
88
65
  /**
89
- * Get the most recent snapshot, or a specific version.
90
- * @param specifiedVersion - The specific version of the snapshot to retrieve
91
- * @returns The snapshot requested, or the latest snapshot if no version was specified, plus version ID
66
+ * Updates class snapshot and processedOps if we have a new snapshot and it's among processedOps range.
92
67
  */
93
- async fetchSnapshotTree(specifiedVersion) {
94
- const version = await this.getVersion(specifiedVersion ?? null);
95
- if (version === undefined && specifiedVersion !== undefined) {
96
- // We should have a defined version to load from if specified version requested
97
- this.mc.logger.sendErrorEvent({
98
- eventName: "NoVersionFoundWhenSpecified",
99
- id: specifiedVersion,
100
- });
68
+ updateSnapshotAndProcessedOpsMaybe() {
69
+ if (this.latestSnapshot === undefined || this.processedOps.length === 0) {
70
+ // can't refresh latest snapshot until we have processed the ops up to it.
71
+ // Pending state would be behind the latest snapshot.
72
+ return;
101
73
  }
102
- const snapshot = (await this.storageAdapter.getSnapshotTree(version)) ?? undefined;
103
- if (snapshot === undefined && version !== undefined) {
104
- this.mc.logger.sendErrorEvent({ eventName: "getSnapshotTreeFailed", id: version.id });
74
+ const snapshotSequenceNumber = this.latestSnapshot.snapshotSequenceNumber;
75
+ const firstProcessedOpSequenceNumber = this.processedOps[0].sequenceNumber;
76
+ const lastProcessedOpSequenceNumber = this.processedOps[this.processedOps.length - 1].sequenceNumber;
77
+ if (snapshotSequenceNumber < firstProcessedOpSequenceNumber) {
78
+ // Snapshot seq number is older than our first processed op, which could mean we're fetching
79
+ // the same snapshot that we already have or snapshot is too old, implicating an unexpected behavior.
80
+ this.mc.logger.sendTelemetryEvent({
81
+ eventName: "OldSnapshotFetchWhileRefreshing",
82
+ snapshotSequenceNumber,
83
+ firstProcessedOpSequenceNumber,
84
+ lastProcessedOpSequenceNumber,
85
+ stashedSnapshotSequenceNumber: this.snapshot?.snapshotSequenceNumber,
86
+ });
87
+ this.latestSnapshot = undefined;
105
88
  }
106
- else if (snapshot !== undefined && version?.id === undefined) {
107
- this.mc.logger.sendErrorEvent({
108
- eventName: "getSnapshotFetchedTreeWithoutVersionId",
109
- hasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.
89
+ else if (snapshotSequenceNumber <= lastProcessedOpSequenceNumber) {
90
+ // Snapshot seq num is between the first and last processed op.
91
+ // Remove the ops that are already part of the snapshot
92
+ this.processedOps.splice(0, snapshotSequenceNumber - firstProcessedOpSequenceNumber + 1);
93
+ this.snapshot = this.latestSnapshot;
94
+ this.latestSnapshot = undefined;
95
+ this.mc.logger.sendTelemetryEvent({
96
+ eventName: "SnapshotRefreshed",
97
+ snapshotSequenceNumber,
98
+ firstProcessedOpSequenceNumber,
99
+ newFirstProcessedOpSequenceNumber: this.processedOps.length === 0
100
+ ? undefined
101
+ : this.processedOps[0].sequenceNumber,
110
102
  });
111
103
  }
112
- return { snapshot, version };
113
104
  }
114
105
  /**
115
106
  * This method is only meant to be used by Container.attach() to set the initial
116
107
  * base snapshot when attaching.
117
108
  * @param snapshot - snapshot and blobs collected while attaching
118
109
  */
119
- setSnapshot(snapshot) {
120
- this.snapshot = snapshot;
110
+ setInitialSnapshot(snapshot) {
111
+ if (this.offlineLoadEnabled) {
112
+ (0, internal_1.assert)(this.snapshot === undefined, 0x937 /* inital snapshot should only be defined once */);
113
+ (0, internal_1.assert)(snapshot !== undefined, 0x938 /* attachment snapshot should be defined */);
114
+ const { baseSnapshot, snapshotBlobs } = snapshot;
115
+ const attributesHash = ".protocol" in baseSnapshot.trees
116
+ ? baseSnapshot.trees[".protocol"].blobs.attributes
117
+ : baseSnapshot.blobs[".attributes"];
118
+ const attributes = JSON.parse(snapshotBlobs[attributesHash]);
119
+ (0, internal_1.assert)(attributes.sequenceNumber === 0, 0x939 /* trying to set a non attachment snapshot */);
120
+ this.snapshot = { ...snapshot, snapshotSequenceNumber: attributes.sequenceNumber };
121
+ }
121
122
  }
122
123
  async getPendingLocalStateCore(props, clientId, runtime, resolvedUrl) {
123
- return telemetry_utils_1.PerformanceEvent.timedExecAsync(this.mc.logger, {
124
+ return internal_3.PerformanceEvent.timedExecAsync(this.mc.logger, {
124
125
  eventName: "getPendingLocalState",
125
126
  notifyImminentClosure: props.notifyImminentClosure,
126
127
  processedOpsSize: this.processedOps.length,
127
128
  clientId,
128
129
  }, async () => {
129
130
  if (!this.offlineLoadEnabled) {
130
- throw new telemetry_utils_1.UsageError("Can't get pending local state unless offline load is enabled");
131
+ throw new internal_3.UsageError("Can't get pending local state unless offline load is enabled");
131
132
  }
132
- (0, core_utils_1.assert)(this.snapshot !== undefined, 0x8e5 /* no base data */);
133
+ (0, internal_1.assert)(this.snapshot !== undefined, 0x8e5 /* no base data */);
133
134
  const pendingRuntimeState = await runtime.getPendingLocalState(props);
134
135
  const pendingState = {
135
136
  attached: true,
136
137
  pendingRuntimeState,
137
- baseSnapshot: this.snapshot.tree,
138
- snapshotBlobs: this.snapshot.blobs,
138
+ baseSnapshot: this.snapshot.baseSnapshot,
139
+ snapshotBlobs: this.snapshot.snapshotBlobs,
139
140
  savedOps: this.processedOps,
140
141
  url: resolvedUrl.url,
141
142
  // no need to save this if there is no pending runtime state
@@ -146,4 +147,103 @@ class SerializedStateManager {
146
147
  }
147
148
  }
148
149
  exports.SerializedStateManager = SerializedStateManager;
150
+ /**
151
+ * Retrieves the most recent snapshot and returns its info.
152
+ *
153
+ * @param mc - The monitoring context.
154
+ * @param storageAdapter - The storage adapter providing methods to retrieve the snapshot.
155
+ * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree.
156
+ * @returns a SnapshotInfo object containing the snapshot tree, snapshot blobs and its sequence number.
157
+ */
158
+ async function getLatestSnapshotInfo(mc, storageAdapter, supportGetSnapshotApi) {
159
+ return internal_3.PerformanceEvent.timedExecAsync(mc.logger, { eventName: "GetLatestSnapshotInfo" }, async () => {
160
+ const { baseSnapshot } = await getSnapshotTree(mc, storageAdapter, supportGetSnapshotApi, undefined);
161
+ const snapshotBlobs = await (0, containerStorageAdapter_js_1.getBlobContentsFromTree)(baseSnapshot, storageAdapter);
162
+ const attributes = await (0, utils_js_1.getDocumentAttributes)(storageAdapter, baseSnapshot);
163
+ const snapshotSequenceNumber = attributes.sequenceNumber;
164
+ return { baseSnapshot, snapshotBlobs, snapshotSequenceNumber };
165
+ }).catch(() => undefined);
166
+ }
167
+ exports.getLatestSnapshotInfo = getLatestSnapshotInfo;
168
+ /**
169
+ * Retrieves a snapshot from the storage adapter and transforms it into an ISnapshotTree object.
170
+ *
171
+ * @param mc - The monitoring context.
172
+ * @param storageAdapter - The storage adapter providing methods to retrieve the snapshot.
173
+ * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree.
174
+ * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.
175
+ * @returns - An ISnapshotTree and its version.
176
+ */
177
+ async function getSnapshotTree(mc, storageAdapter, supportGetSnapshotApi, specifiedVersion) {
178
+ const { snapshot, version } = supportGetSnapshotApi
179
+ ? await fetchISnapshot(mc, storageAdapter, specifiedVersion)
180
+ : await fetchISnapshotTree(mc, storageAdapter, specifiedVersion);
181
+ const baseSnapshot = (0, internal_2.isInstanceOfISnapshot)(snapshot)
182
+ ? snapshot.snapshotTree
183
+ : snapshot;
184
+ (0, internal_1.assert)(baseSnapshot !== undefined, 0x8e4 /* Snapshot should exist */);
185
+ return { baseSnapshot, version };
186
+ }
187
+ /**
188
+ * Fetches an ISnapshot from a storage adapter based on the specified version.
189
+ *
190
+ * @param mc - The monitoring context.
191
+ * @param storageAdapter - The storage adapter providing a getSnapshot method to retrieve the ISnapshot and version.
192
+ * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.
193
+ * @returns - The fetched snapshot tree and its version.
194
+ */
195
+ async function fetchISnapshot(mc, storageAdapter, specifiedVersion) {
196
+ const snapshot = await storageAdapter.getSnapshot?.({ versionId: specifiedVersion });
197
+ const version = snapshot?.snapshotTree.id === undefined
198
+ ? undefined
199
+ : {
200
+ id: snapshot.snapshotTree.id,
201
+ treeId: snapshot.snapshotTree.id,
202
+ };
203
+ if (snapshot === undefined && specifiedVersion !== undefined) {
204
+ mc.logger.sendErrorEvent({
205
+ eventName: "getSnapshotTreeFailed",
206
+ id: specifiedVersion,
207
+ });
208
+ }
209
+ else if (snapshot !== undefined && version?.id === undefined) {
210
+ mc.logger.sendErrorEvent({
211
+ eventName: "getSnapshotFetchedTreeWithoutVersionId",
212
+ hasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.
213
+ });
214
+ }
215
+ return { snapshot, version };
216
+ }
217
+ exports.fetchISnapshot = fetchISnapshot;
218
+ /**
219
+ * Fetches an ISnapshotTree from a storage adapter based on the specified version.
220
+ *
221
+ * @param mc - The monitoring context.
222
+ * @param storageAdapter - The storage adapter providing methods to retrieve the ISnapshotTree and version.
223
+ * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.
224
+ * @returns - The fetched snapshot tree and its version.
225
+ */
226
+ async function fetchISnapshotTree(mc, storageAdapter, specifiedVersion) {
227
+ const versions = await storageAdapter.getVersions(specifiedVersion ?? null, 1);
228
+ const version = versions[0];
229
+ if (version === undefined && specifiedVersion !== undefined) {
230
+ // We should have a defined version to load from if specified version requested
231
+ mc.logger.sendErrorEvent({
232
+ eventName: "NoVersionFoundWhenSpecified",
233
+ id: specifiedVersion,
234
+ });
235
+ }
236
+ const snapshot = (await storageAdapter.getSnapshotTree(version)) ?? undefined;
237
+ if (snapshot === undefined && version !== undefined) {
238
+ mc.logger.sendErrorEvent({ eventName: "getSnapshotTreeFailed", id: version.id });
239
+ }
240
+ else if (snapshot !== undefined && version?.id === undefined) {
241
+ mc.logger.sendErrorEvent({
242
+ eventName: "getSnapshotFetchedTreeWithoutVersionId",
243
+ hasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.
244
+ });
245
+ }
246
+ return { snapshot, version };
247
+ }
248
+ exports.fetchISnapshotTree = fetchISnapshotTree;
149
249
  //# sourceMappingURL=serializedStateManager.js.map