@fluidframework/container-runtime 2.0.0-internal.3.0.0 → 2.0.0-internal.3.1.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 (327) hide show
  1. package/.eslintrc.js +19 -19
  2. package/.mocharc.js +2 -2
  3. package/api-extractor.json +2 -2
  4. package/dist/batchTracker.d.ts.map +1 -1
  5. package/dist/batchTracker.js +2 -1
  6. package/dist/batchTracker.js.map +1 -1
  7. package/dist/blobManager.d.ts +9 -2
  8. package/dist/blobManager.d.ts.map +1 -1
  9. package/dist/blobManager.js +80 -33
  10. package/dist/blobManager.js.map +1 -1
  11. package/dist/connectionTelemetry.d.ts.map +1 -1
  12. package/dist/connectionTelemetry.js +11 -9
  13. package/dist/connectionTelemetry.js.map +1 -1
  14. package/dist/containerHandleContext.d.ts.map +1 -1
  15. package/dist/containerHandleContext.js +3 -1
  16. package/dist/containerHandleContext.js.map +1 -1
  17. package/dist/containerRuntime.d.ts +10 -0
  18. package/dist/containerRuntime.d.ts.map +1 -1
  19. package/dist/containerRuntime.js +140 -72
  20. package/dist/containerRuntime.js.map +1 -1
  21. package/dist/dataStore.d.ts.map +1 -1
  22. package/dist/dataStore.js +11 -9
  23. package/dist/dataStore.js.map +1 -1
  24. package/dist/dataStoreContext.d.ts +18 -1
  25. package/dist/dataStoreContext.d.ts.map +1 -1
  26. package/dist/dataStoreContext.js +66 -15
  27. package/dist/dataStoreContext.js.map +1 -1
  28. package/dist/dataStoreContexts.d.ts.map +1 -1
  29. package/dist/dataStoreContexts.js +7 -3
  30. package/dist/dataStoreContexts.js.map +1 -1
  31. package/dist/dataStoreRegistry.d.ts.map +1 -1
  32. package/dist/dataStoreRegistry.js +3 -1
  33. package/dist/dataStoreRegistry.js.map +1 -1
  34. package/dist/dataStores.d.ts +26 -1
  35. package/dist/dataStores.d.ts.map +1 -1
  36. package/dist/dataStores.js +103 -18
  37. package/dist/dataStores.js.map +1 -1
  38. package/dist/deltaScheduler.d.ts.map +1 -1
  39. package/dist/deltaScheduler.js +8 -3
  40. package/dist/deltaScheduler.js.map +1 -1
  41. package/dist/garbageCollection.d.ts +34 -14
  42. package/dist/garbageCollection.d.ts.map +1 -1
  43. package/dist/garbageCollection.js +188 -93
  44. package/dist/garbageCollection.js.map +1 -1
  45. package/dist/garbageCollectionConstants.d.ts +3 -0
  46. package/dist/garbageCollectionConstants.d.ts.map +1 -1
  47. package/dist/garbageCollectionConstants.js +6 -1
  48. package/dist/garbageCollectionConstants.js.map +1 -1
  49. package/dist/garbageCollectionHelpers.d.ts +26 -0
  50. package/dist/garbageCollectionHelpers.d.ts.map +1 -0
  51. package/dist/garbageCollectionHelpers.js +45 -0
  52. package/dist/garbageCollectionHelpers.js.map +1 -0
  53. package/dist/gcSweepReadyUsageDetection.d.ts +5 -5
  54. package/dist/gcSweepReadyUsageDetection.d.ts.map +1 -1
  55. package/dist/gcSweepReadyUsageDetection.js +14 -10
  56. package/dist/gcSweepReadyUsageDetection.js.map +1 -1
  57. package/dist/index.d.ts +2 -2
  58. package/dist/index.d.ts.map +1 -1
  59. package/dist/index.js.map +1 -1
  60. package/dist/opLifecycle/batchManager.d.ts +5 -5
  61. package/dist/opLifecycle/batchManager.d.ts.map +1 -1
  62. package/dist/opLifecycle/batchManager.js +19 -12
  63. package/dist/opLifecycle/batchManager.js.map +1 -1
  64. package/dist/opLifecycle/definitions.d.ts.map +1 -1
  65. package/dist/opLifecycle/definitions.js.map +1 -1
  66. package/dist/opLifecycle/index.d.ts.map +1 -1
  67. package/dist/opLifecycle/index.js.map +1 -1
  68. package/dist/opLifecycle/opCompressor.d.ts.map +1 -1
  69. package/dist/opLifecycle/opCompressor.js.map +1 -1
  70. package/dist/opLifecycle/opDecompressor.d.ts.map +1 -1
  71. package/dist/opLifecycle/opDecompressor.js +5 -2
  72. package/dist/opLifecycle/opDecompressor.js.map +1 -1
  73. package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
  74. package/dist/opLifecycle/opSplitter.js +4 -1
  75. package/dist/opLifecycle/opSplitter.js.map +1 -1
  76. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  77. package/dist/opLifecycle/outbox.js +19 -17
  78. package/dist/opLifecycle/outbox.js.map +1 -1
  79. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  80. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  81. package/dist/opProperties.d.ts.map +1 -1
  82. package/dist/opProperties.js +1 -3
  83. package/dist/opProperties.js.map +1 -1
  84. package/dist/orderedClientElection.d.ts.map +1 -1
  85. package/dist/orderedClientElection.js +10 -4
  86. package/dist/orderedClientElection.js.map +1 -1
  87. package/dist/packageVersion.d.ts +1 -1
  88. package/dist/packageVersion.js +1 -1
  89. package/dist/packageVersion.js.map +1 -1
  90. package/dist/pendingStateManager.d.ts +7 -0
  91. package/dist/pendingStateManager.d.ts.map +1 -1
  92. package/dist/pendingStateManager.js +7 -4
  93. package/dist/pendingStateManager.js.map +1 -1
  94. package/dist/runWhileConnectedCoordinator.d.ts.map +1 -1
  95. package/dist/runWhileConnectedCoordinator.js.map +1 -1
  96. package/dist/runningSummarizer.d.ts.map +1 -1
  97. package/dist/runningSummarizer.js +34 -21
  98. package/dist/runningSummarizer.js.map +1 -1
  99. package/dist/scheduleManager.d.ts.map +1 -1
  100. package/dist/scheduleManager.js +3 -2
  101. package/dist/scheduleManager.js.map +1 -1
  102. package/dist/serializedSnapshotStorage.d.ts +2 -2
  103. package/dist/serializedSnapshotStorage.d.ts.map +1 -1
  104. package/dist/serializedSnapshotStorage.js +5 -3
  105. package/dist/serializedSnapshotStorage.js.map +1 -1
  106. package/dist/summarizer.d.ts +2 -2
  107. package/dist/summarizer.d.ts.map +1 -1
  108. package/dist/summarizer.js +37 -17
  109. package/dist/summarizer.js.map +1 -1
  110. package/dist/summarizerClientElection.d.ts.map +1 -1
  111. package/dist/summarizerClientElection.js.map +1 -1
  112. package/dist/summarizerHandle.d.ts.map +1 -1
  113. package/dist/summarizerHandle.js.map +1 -1
  114. package/dist/summarizerHeuristics.d.ts.map +1 -1
  115. package/dist/summarizerHeuristics.js +6 -9
  116. package/dist/summarizerHeuristics.js.map +1 -1
  117. package/dist/summarizerTypes.d.ts +21 -21
  118. package/dist/summarizerTypes.d.ts.map +1 -1
  119. package/dist/summarizerTypes.js.map +1 -1
  120. package/dist/summaryCollection.d.ts.map +1 -1
  121. package/dist/summaryCollection.js +18 -8
  122. package/dist/summaryCollection.js.map +1 -1
  123. package/dist/summaryFormat.d.ts +22 -0
  124. package/dist/summaryFormat.d.ts.map +1 -1
  125. package/dist/summaryFormat.js +18 -10
  126. package/dist/summaryFormat.js.map +1 -1
  127. package/dist/summaryGenerator.d.ts.map +1 -1
  128. package/dist/summaryGenerator.js +34 -15
  129. package/dist/summaryGenerator.js.map +1 -1
  130. package/dist/summaryManager.d.ts.map +1 -1
  131. package/dist/summaryManager.js +21 -9
  132. package/dist/summaryManager.js.map +1 -1
  133. package/dist/throttler.d.ts +2 -2
  134. package/dist/throttler.d.ts.map +1 -1
  135. package/dist/throttler.js +4 -4
  136. package/dist/throttler.js.map +1 -1
  137. package/garbageCollection.md +15 -2
  138. package/lib/batchTracker.d.ts.map +1 -1
  139. package/lib/batchTracker.js +2 -1
  140. package/lib/batchTracker.js.map +1 -1
  141. package/lib/blobManager.d.ts +9 -2
  142. package/lib/blobManager.d.ts.map +1 -1
  143. package/lib/blobManager.js +82 -35
  144. package/lib/blobManager.js.map +1 -1
  145. package/lib/connectionTelemetry.d.ts.map +1 -1
  146. package/lib/connectionTelemetry.js +11 -9
  147. package/lib/connectionTelemetry.js.map +1 -1
  148. package/lib/containerHandleContext.d.ts.map +1 -1
  149. package/lib/containerHandleContext.js +3 -1
  150. package/lib/containerHandleContext.js.map +1 -1
  151. package/lib/containerRuntime.d.ts +10 -0
  152. package/lib/containerRuntime.d.ts.map +1 -1
  153. package/lib/containerRuntime.js +146 -78
  154. package/lib/containerRuntime.js.map +1 -1
  155. package/lib/dataStore.d.ts.map +1 -1
  156. package/lib/dataStore.js +11 -9
  157. package/lib/dataStore.js.map +1 -1
  158. package/lib/dataStoreContext.d.ts +18 -1
  159. package/lib/dataStoreContext.d.ts.map +1 -1
  160. package/lib/dataStoreContext.js +68 -17
  161. package/lib/dataStoreContext.js.map +1 -1
  162. package/lib/dataStoreContexts.d.ts.map +1 -1
  163. package/lib/dataStoreContexts.js +7 -3
  164. package/lib/dataStoreContexts.js.map +1 -1
  165. package/lib/dataStoreRegistry.d.ts.map +1 -1
  166. package/lib/dataStoreRegistry.js +3 -1
  167. package/lib/dataStoreRegistry.js.map +1 -1
  168. package/lib/dataStores.d.ts +26 -1
  169. package/lib/dataStores.d.ts.map +1 -1
  170. package/lib/dataStores.js +109 -24
  171. package/lib/dataStores.js.map +1 -1
  172. package/lib/deltaScheduler.d.ts.map +1 -1
  173. package/lib/deltaScheduler.js +9 -4
  174. package/lib/deltaScheduler.js.map +1 -1
  175. package/lib/garbageCollection.d.ts +34 -14
  176. package/lib/garbageCollection.d.ts.map +1 -1
  177. package/lib/garbageCollection.js +190 -95
  178. package/lib/garbageCollection.js.map +1 -1
  179. package/lib/garbageCollectionConstants.d.ts +3 -0
  180. package/lib/garbageCollectionConstants.d.ts.map +1 -1
  181. package/lib/garbageCollectionConstants.js +5 -0
  182. package/lib/garbageCollectionConstants.js.map +1 -1
  183. package/lib/garbageCollectionHelpers.d.ts +26 -0
  184. package/lib/garbageCollectionHelpers.d.ts.map +1 -0
  185. package/lib/garbageCollectionHelpers.js +40 -0
  186. package/lib/garbageCollectionHelpers.js.map +1 -0
  187. package/lib/gcSweepReadyUsageDetection.d.ts +5 -5
  188. package/lib/gcSweepReadyUsageDetection.d.ts.map +1 -1
  189. package/lib/gcSweepReadyUsageDetection.js +14 -10
  190. package/lib/gcSweepReadyUsageDetection.js.map +1 -1
  191. package/lib/index.d.ts +2 -2
  192. package/lib/index.d.ts.map +1 -1
  193. package/lib/index.js +1 -1
  194. package/lib/index.js.map +1 -1
  195. package/lib/opLifecycle/batchManager.d.ts +5 -5
  196. package/lib/opLifecycle/batchManager.d.ts.map +1 -1
  197. package/lib/opLifecycle/batchManager.js +19 -12
  198. package/lib/opLifecycle/batchManager.js.map +1 -1
  199. package/lib/opLifecycle/definitions.d.ts.map +1 -1
  200. package/lib/opLifecycle/definitions.js.map +1 -1
  201. package/lib/opLifecycle/index.d.ts.map +1 -1
  202. package/lib/opLifecycle/index.js.map +1 -1
  203. package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
  204. package/lib/opLifecycle/opCompressor.js.map +1 -1
  205. package/lib/opLifecycle/opDecompressor.d.ts.map +1 -1
  206. package/lib/opLifecycle/opDecompressor.js +5 -2
  207. package/lib/opLifecycle/opDecompressor.js.map +1 -1
  208. package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
  209. package/lib/opLifecycle/opSplitter.js +5 -2
  210. package/lib/opLifecycle/opSplitter.js.map +1 -1
  211. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  212. package/lib/opLifecycle/outbox.js +19 -17
  213. package/lib/opLifecycle/outbox.js.map +1 -1
  214. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  215. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  216. package/lib/opProperties.d.ts.map +1 -1
  217. package/lib/opProperties.js +1 -3
  218. package/lib/opProperties.js.map +1 -1
  219. package/lib/orderedClientElection.d.ts.map +1 -1
  220. package/lib/orderedClientElection.js +10 -4
  221. package/lib/orderedClientElection.js.map +1 -1
  222. package/lib/packageVersion.d.ts +1 -1
  223. package/lib/packageVersion.js +1 -1
  224. package/lib/packageVersion.js.map +1 -1
  225. package/lib/pendingStateManager.d.ts +7 -0
  226. package/lib/pendingStateManager.d.ts.map +1 -1
  227. package/lib/pendingStateManager.js +7 -4
  228. package/lib/pendingStateManager.js.map +1 -1
  229. package/lib/runWhileConnectedCoordinator.d.ts.map +1 -1
  230. package/lib/runWhileConnectedCoordinator.js.map +1 -1
  231. package/lib/runningSummarizer.d.ts.map +1 -1
  232. package/lib/runningSummarizer.js +35 -22
  233. package/lib/runningSummarizer.js.map +1 -1
  234. package/lib/scheduleManager.d.ts.map +1 -1
  235. package/lib/scheduleManager.js +3 -2
  236. package/lib/scheduleManager.js.map +1 -1
  237. package/lib/serializedSnapshotStorage.d.ts +2 -2
  238. package/lib/serializedSnapshotStorage.d.ts.map +1 -1
  239. package/lib/serializedSnapshotStorage.js +5 -3
  240. package/lib/serializedSnapshotStorage.js.map +1 -1
  241. package/lib/summarizer.d.ts +2 -2
  242. package/lib/summarizer.d.ts.map +1 -1
  243. package/lib/summarizer.js +37 -17
  244. package/lib/summarizer.js.map +1 -1
  245. package/lib/summarizerClientElection.d.ts.map +1 -1
  246. package/lib/summarizerClientElection.js.map +1 -1
  247. package/lib/summarizerHandle.d.ts.map +1 -1
  248. package/lib/summarizerHandle.js.map +1 -1
  249. package/lib/summarizerHeuristics.d.ts.map +1 -1
  250. package/lib/summarizerHeuristics.js +6 -9
  251. package/lib/summarizerHeuristics.js.map +1 -1
  252. package/lib/summarizerTypes.d.ts +21 -21
  253. package/lib/summarizerTypes.d.ts.map +1 -1
  254. package/lib/summarizerTypes.js.map +1 -1
  255. package/lib/summaryCollection.d.ts.map +1 -1
  256. package/lib/summaryCollection.js +18 -8
  257. package/lib/summaryCollection.js.map +1 -1
  258. package/lib/summaryFormat.d.ts +22 -0
  259. package/lib/summaryFormat.d.ts.map +1 -1
  260. package/lib/summaryFormat.js +20 -12
  261. package/lib/summaryFormat.js.map +1 -1
  262. package/lib/summaryGenerator.d.ts.map +1 -1
  263. package/lib/summaryGenerator.js +34 -15
  264. package/lib/summaryGenerator.js.map +1 -1
  265. package/lib/summaryManager.d.ts.map +1 -1
  266. package/lib/summaryManager.js +21 -9
  267. package/lib/summaryManager.js.map +1 -1
  268. package/lib/throttler.d.ts +2 -2
  269. package/lib/throttler.d.ts.map +1 -1
  270. package/lib/throttler.js +4 -4
  271. package/lib/throttler.js.map +1 -1
  272. package/package.json +121 -149
  273. package/prettier.config.cjs +1 -1
  274. package/src/batchTracker.ts +54 -49
  275. package/src/blobManager.ts +793 -672
  276. package/src/connectionTelemetry.ts +280 -249
  277. package/src/containerHandleContext.ts +27 -29
  278. package/src/containerRuntime.ts +3168 -2940
  279. package/src/dataStore.ts +172 -159
  280. package/src/dataStoreContext.ts +1098 -996
  281. package/src/dataStoreContexts.ts +178 -161
  282. package/src/dataStoreRegistry.ts +25 -20
  283. package/src/dataStores.ts +884 -728
  284. package/src/deltaScheduler.ts +158 -150
  285. package/src/garbageCollection.ts +1883 -1692
  286. package/src/garbageCollectionConstants.ts +6 -0
  287. package/src/garbageCollectionHelpers.ts +61 -0
  288. package/src/gcSweepReadyUsageDetection.ts +89 -83
  289. package/src/index.ts +67 -66
  290. package/src/opLifecycle/README.md +152 -0
  291. package/src/opLifecycle/batchManager.ts +145 -141
  292. package/src/opLifecycle/definitions.ts +29 -29
  293. package/src/opLifecycle/index.ts +5 -5
  294. package/src/opLifecycle/opCompressor.ts +54 -53
  295. package/src/opLifecycle/opDecompressor.ts +100 -81
  296. package/src/opLifecycle/opSplitter.ts +214 -188
  297. package/src/opLifecycle/outbox.ts +204 -194
  298. package/src/opLifecycle/remoteMessageProcessor.ts +62 -62
  299. package/src/opProperties.ts +11 -9
  300. package/src/orderedClientElection.ts +489 -457
  301. package/src/packageVersion.ts +1 -1
  302. package/src/pendingStateManager.ts +384 -338
  303. package/src/runWhileConnectedCoordinator.ts +78 -71
  304. package/src/runningSummarizer.ts +619 -581
  305. package/src/scheduleManager.ts +299 -269
  306. package/src/serializedSnapshotStorage.ts +126 -112
  307. package/src/summarizer.ts +417 -381
  308. package/src/summarizerClientElection.ts +107 -100
  309. package/src/summarizerHandle.ts +11 -9
  310. package/src/summarizerHeuristics.ts +183 -186
  311. package/src/summarizerTypes.ts +344 -330
  312. package/src/summaryCollection.ts +378 -349
  313. package/src/summaryFormat.ts +170 -126
  314. package/src/summaryGenerator.ts +465 -406
  315. package/src/summaryManager.ts +377 -348
  316. package/src/throttler.ts +131 -122
  317. package/tsconfig.esnext.json +6 -6
  318. package/tsconfig.json +9 -13
  319. package/dist/garbageCollectionTombstoneUtils.d.ts +0 -14
  320. package/dist/garbageCollectionTombstoneUtils.d.ts.map +0 -1
  321. package/dist/garbageCollectionTombstoneUtils.js +0 -23
  322. package/dist/garbageCollectionTombstoneUtils.js.map +0 -1
  323. package/lib/garbageCollectionTombstoneUtils.d.ts +0 -14
  324. package/lib/garbageCollectionTombstoneUtils.d.ts.map +0 -1
  325. package/lib/garbageCollectionTombstoneUtils.js +0 -19
  326. package/lib/garbageCollectionTombstoneUtils.js.map +0 -1
  327. package/src/garbageCollectionTombstoneUtils.ts +0 -28
package/src/summarizer.ts CHANGED
@@ -11,17 +11,17 @@ import { UsageError } from "@fluidframework/container-utils";
11
11
  import { DriverErrorType, DriverHeader } from "@fluidframework/driver-definitions";
12
12
  import { requestFluidObject } from "@fluidframework/runtime-utils";
13
13
  import {
14
- ChildLogger,
15
- IFluidErrorBase,
16
- isFluidError,
17
- LoggingError,
18
- wrapErrorAndLog,
14
+ ChildLogger,
15
+ IFluidErrorBase,
16
+ isFluidError,
17
+ LoggingError,
18
+ wrapErrorAndLog,
19
19
  } from "@fluidframework/telemetry-utils";
20
20
  import {
21
- FluidObject,
22
- IFluidHandleContext,
23
- IFluidHandle,
24
- IRequest,
21
+ FluidObject,
22
+ IFluidHandleContext,
23
+ IFluidHandle,
24
+ IRequest,
25
25
  } from "@fluidframework/core-interfaces";
26
26
  import { ISummaryConfiguration } from "./containerRuntime";
27
27
  import { ICancellableSummarizerController } from "./runWhileConnectedCoordinator";
@@ -30,11 +30,11 @@ import { IAckedSummary, SummaryCollection } from "./summaryCollection";
30
30
  import { SummarizerHandle } from "./summarizerHandle";
31
31
  import { RunningSummarizer } from "./runningSummarizer";
32
32
  import {
33
- ISummarizer,
34
- ISummarizerInternalsProvider,
35
- ISummarizerRuntime,
36
- ISummarizingWarning,
37
- SummarizerStopReason,
33
+ ISummarizer,
34
+ ISummarizerInternalsProvider,
35
+ ISummarizerRuntime,
36
+ ISummarizingWarning,
37
+ SummarizerStopReason,
38
38
  } from "./summarizerTypes";
39
39
  import { SummarizeHeuristicData } from "./summarizerHeuristics";
40
40
  import { SummarizeResultBuilder } from "./summaryGenerator";
@@ -42,25 +42,25 @@ import { IConnectableRuntime } from ".";
42
42
 
43
43
  const summarizingError = "summarizingError";
44
44
 
45
- export class SummarizingWarning extends LoggingError implements ISummarizingWarning, IFluidErrorBase {
46
- readonly errorType = summarizingError;
47
- readonly canRetry = true;
48
-
49
- constructor(
50
- errorMessage: string,
51
- readonly logged: boolean = false,
52
- ) {
53
- super(errorMessage);
54
- }
55
-
56
- static wrap(error: any, logged: boolean = false, logger: ITelemetryLogger) {
57
- const newErrorFn = (errMsg: string) => new SummarizingWarning(errMsg, logged);
58
- return wrapErrorAndLog<SummarizingWarning>(error, newErrorFn, logger);
59
- }
45
+ export class SummarizingWarning
46
+ extends LoggingError
47
+ implements ISummarizingWarning, IFluidErrorBase
48
+ {
49
+ readonly errorType = summarizingError;
50
+ readonly canRetry = true;
51
+
52
+ constructor(errorMessage: string, readonly logged: boolean = false) {
53
+ super(errorMessage);
54
+ }
55
+
56
+ static wrap(error: any, logged: boolean = false, logger: ITelemetryLogger) {
57
+ const newErrorFn = (errMsg: string) => new SummarizingWarning(errMsg, logged);
58
+ return wrapErrorAndLog<SummarizingWarning>(error, newErrorFn, logger);
59
+ }
60
60
  }
61
61
 
62
- export const createSummarizingWarning =
63
- (errorMessage: string, logged: boolean) => new SummarizingWarning(errorMessage, logged);
62
+ export const createSummarizingWarning = (errorMessage: string, logged: boolean) =>
63
+ new SummarizingWarning(errorMessage, logged);
64
64
 
65
65
  /**
66
66
  * Summarizer is responsible for coordinating when to generate and send summaries.
@@ -68,354 +68,390 @@ export const createSummarizingWarning =
68
68
  * It is created only by summarizing container (i.e. one with clientType === "summarizer")
69
69
  */
70
70
  export class Summarizer extends EventEmitter implements ISummarizer {
71
- public get IFluidLoadable() { return this; }
72
- public get ISummarizer() { return this; }
73
-
74
- private readonly logger: ITelemetryLogger;
75
- private runningSummarizer?: RunningSummarizer;
76
- private _disposed: boolean = false;
77
- private starting: boolean = false;
78
-
79
- private readonly innerHandle: IFluidHandle<this>;
80
-
81
- public get handle(): IFluidHandle<this> { return this.innerHandle; }
82
- private readonly stopDeferred = new Deferred<SummarizerStopReason>();
83
-
84
- constructor(
85
- url: string,
86
- /** Reference to runtime that created this object.
87
- * i.e. runtime with clientType === "summarizer"
88
- */
89
- private readonly runtime: ISummarizerRuntime,
90
- private readonly configurationGetter: () => ISummaryConfiguration,
91
- /** Represents an object that can generate summary.
92
- * In practical terms, it's same runtime (this.runtime) with clientType === "summarizer".
93
- */
94
- private readonly internalsProvider: ISummarizerInternalsProvider,
95
- handleContext: IFluidHandleContext,
96
- public readonly summaryCollection: SummaryCollection,
97
- private readonly runCoordinatorCreateFn:
98
- (runtime: IConnectableRuntime) => Promise<ICancellableSummarizerController>,
99
- ) {
100
- super();
101
- this.logger = ChildLogger.create(this.runtime.logger, "Summarizer");
102
- this.innerHandle = new SummarizerHandle(this, url, handleContext);
103
- }
104
-
105
- /**
106
- * Creates a Summarizer and its underlying client.
107
- * Note that different implementations of ILoader will handle the URL differently.
108
- * ILoader provided by a ContainerRuntime is a RelativeLoader, which will treat URL's
109
- * starting with "/" as relative to the Container. The general ILoader
110
- * interface will expect an absolute URL and will not handle "/".
111
- * @param loader - the loader that resolves the request
112
- * @param url - the URL used to resolve the container
113
- */
114
- public static async create(
115
- loader: ILoader,
116
- url: string): Promise<ISummarizer> {
117
- const request: IRequest = {
118
- headers: {
119
- [LoaderHeader.cache]: false,
120
- [LoaderHeader.clientDetails]: {
121
- capabilities: { interactive: false },
122
- type: summarizerClientType,
123
- },
124
- [DriverHeader.summarizingClient]: true,
125
- [LoaderHeader.reconnect]: false,
126
- },
127
- url,
128
- };
129
-
130
- const resolvedContainer = await loader.resolve(request);
131
- const fluidObject =
132
- await requestFluidObject<FluidObject<ISummarizer>>(resolvedContainer, { url: "_summarizer" });
133
- if (fluidObject.ISummarizer === undefined) {
134
- throw new UsageError("Fluid object does not implement ISummarizer");
135
- }
136
- return fluidObject.ISummarizer;
137
- }
138
-
139
- public async run(onBehalfOf: string): Promise<SummarizerStopReason> {
140
- try {
141
- return await this.runCore(onBehalfOf);
142
- } catch (error) {
143
- this.stop("summarizerException");
144
- throw SummarizingWarning.wrap(error, false /* logged */, this.logger);
145
- } finally {
146
- this.close();
147
- }
148
- }
149
-
150
- /**
151
- * Stops the summarizer from running. This will complete
152
- * the run promise, and also close the container.
153
- * @param reason - reason code for stopping
154
- */
155
- public stop(reason: SummarizerStopReason) {
156
- this.stopDeferred.resolve(reason);
157
- }
158
-
159
- public close() {
160
- // This will result in "summarizerClientDisconnected" stop reason recorded in telemetry,
161
- // unless stop() was called earlier
162
- this.dispose();
163
- (this.runtime.disposeFn ?? this.runtime.closeFn)();
164
- }
165
-
166
- private async runCore(onBehalfOf: string): Promise<SummarizerStopReason> {
167
- const runCoordinator: ICancellableSummarizerController = await this.runCoordinatorCreateFn(this.runtime);
168
-
169
- // Wait for either external signal to cancel, or loss of connectivity.
170
- const stopP = Promise.race([runCoordinator.waitCancelled, this.stopDeferred.promise]);
171
- void stopP.then((reason) => {
172
- this.logger.sendTelemetryEvent({
173
- eventName: "StoppingSummarizer",
174
- onBehalfOf,
175
- reason,
176
- });
177
- });
178
-
179
- if (runCoordinator.cancelled) {
180
- return runCoordinator.waitCancelled;
181
- }
182
-
183
- const runningSummarizer = await this.start(onBehalfOf, runCoordinator);
184
-
185
- // Wait for either external signal to cancel, or loss of connectivity.
186
- const stopReason = await stopP;
187
-
188
- // There are two possible approaches here:
189
- // 1. Propagate cancellation from this.stopDeferred to runCoordinator. This will ensure that we move to the exit
190
- // faster, including breaking out of the RunningSummarizer.trySummarize() faster.
191
- // We could create new coordinator and pass it to waitStop() -> trySummarizeOnce("lastSummary") flow.
192
- // The con of this approach is that we might cancel active summary, and lastSummary will fail because it
193
- // did not wait for ack/nack from previous summary. Plus we disregard any 429 kind of info from service
194
- // that way (i.e. trySummarize() loop might have been waiting for 5 min because storage told us so).
195
- // In general, it's more wasted resources.
196
- // 2. We can not do it and make waitStop() do last summary only if there was no active summary. This ensures
197
- // that client behaves properly (from server POV) and we do not waste resources. But, it may mean we wait
198
- // substantially longer for trySummarize() retries to play out and thus this summary loop may run into
199
- // conflict with new summarizer client starting on different client.
200
- // As of now, #2 is implemented. It's more forward looking, as issue #7279 suggests changing design for new
201
- // summarizer client to not be created until current summarizer fully moves to exit, and that would reduce
202
- // cons of #2 substantially.
203
-
204
- // Cleanup after running
205
- await runningSummarizer.waitStop(
206
- !runCoordinator.cancelled && Summarizer.stopReasonCanRunLastSummary(stopReason));
207
-
208
- // Propagate reason and ensure that if someone is waiting for cancellation token, they are moving to exit
209
- runCoordinator.stop(stopReason);
210
-
211
- return stopReason;
212
- }
213
-
214
- /**
215
- * Should we try to run a last summary for the given stop reason?
216
- * Currently only allows "parentNotConnected"
217
- * @param stopReason - SummarizerStopReason
218
- * @returns - true if the stop reason can run a last summary
219
- */
220
- public static stopReasonCanRunLastSummary(stopReason: SummarizerStopReason): boolean {
221
- return stopReason === "parentNotConnected";
222
- }
223
-
224
- /**
225
- * Put the summarizer in a started state, including creating and initializing the RunningSummarizer.
226
- * The start request can come either from the SummaryManager (in the auto-summarize case) or from the user
227
- * (in the on-demand case).
228
- * @param onBehalfOf - ID of the client that requested that the summarizer start
229
- * @param runCoordinator - cancellation token
230
- * @param newConfig - Summary configuration to override the existing config when invoking the RunningSummarizer.
231
- * @returns - Promise that is fulfilled when the RunningSummarizer is ready
232
- */
233
- private async start(
234
- onBehalfOf: string,
235
- runCoordinator: ICancellableSummarizerController): Promise<RunningSummarizer> {
236
- if (this.runningSummarizer) {
237
- if (this.runningSummarizer.disposed) {
238
- throw new UsageError("Starting a disposed summarizer");
239
- }
240
- return this.runningSummarizer;
241
- }
242
- if (this.starting) {
243
- throw new UsageError("Attempting to start a summarizer that is already starting");
244
- }
245
- this.starting = true;
246
- // Initialize values and first ack (time is not exact)
247
- this.logger.sendTelemetryEvent({
248
- eventName: "RunningSummarizer",
249
- onBehalfOf,
250
- initSummarySeqNumber: this.runtime.deltaManager.initialSequenceNumber,
251
- config: JSON.stringify(this.configurationGetter()),
252
- });
253
-
254
- // Summarizing container ID (with clientType === "summarizer")
255
- const clientId = this.runtime.clientId;
256
- if (clientId === undefined) {
257
- throw new UsageError("clientId should be defined if connected.");
258
- }
259
-
260
- const runningSummarizer = await RunningSummarizer.start(
261
- this.logger,
262
- this.summaryCollection.createWatcher(clientId),
263
- this.configurationGetter(),
264
- async (...args) => this.internalsProvider.submitSummary(...args), // submitSummaryCallback
265
- new SummarizeHeuristicData(
266
- this.runtime.deltaManager.lastSequenceNumber,
267
- { /** summary attempt baseline for heuristics */
268
- refSequenceNumber: this.runtime.deltaManager.initialSequenceNumber,
269
- summaryTime: Date.now(),
270
- } as const,
271
- ),
272
- (errorMessage: string) => {
273
- if (!this._disposed) {
274
- this.logger.sendErrorEvent({ eventName: "summarizingError" },
275
- createSummarizingWarning(errorMessage, true));
276
- }
277
- },
278
- this.summaryCollection,
279
- runCoordinator /* cancellationToken */,
280
- (reason) => runCoordinator.stop(reason), /* stopSummarizerCallback */
281
- this.runtime,
282
- );
283
- this.runningSummarizer = runningSummarizer;
284
- this.starting = false;
285
-
286
- // Handle summary acks
287
- // Note: no exceptions are thrown from handleSummaryAcks handler as it handles all exceptions
288
- this.handleSummaryAcks().catch((error) => {
289
- this.logger.sendErrorEvent({ eventName: "HandleSummaryAckFatalError" }, error);
290
- });
291
-
292
- return runningSummarizer;
293
- }
294
-
295
- /**
296
- * Disposes of resources after running. This cleanup will
297
- * clear any outstanding timers and reset some of the state
298
- * properties.
299
- * Called by ContainerRuntime when it is disposed, as well as at the end the run().
300
- */
301
- public dispose() {
302
- // Given that the call can come from own ContainerRuntime, ensure that we stop all the processes.
303
- this.stop("summarizerClientDisconnected");
304
-
305
- this._disposed = true;
306
- if (this.runningSummarizer) {
307
- this.runningSummarizer.dispose();
308
- this.runningSummarizer = undefined;
309
- }
310
- }
311
-
312
- public readonly summarizeOnDemand: ISummarizer["summarizeOnDemand"] = (...args) => {
313
- try {
314
- if (this._disposed || this.runningSummarizer?.disposed) {
315
- throw new UsageError("Summarizer is already disposed.");
316
- }
317
- if (this.runtime.summarizerClientId !== undefined &&
318
- this.runtime.summarizerClientId !== this.runtime.clientId) {
319
- // If there is an elected summarizer, and it's not this one, don't allow on-demand summary.
320
- // This is to prevent the on-demand summary and heuristic-based summary from stepping on
321
- // each other.
322
- throw new UsageError("On-demand summary attempted while an elected summarizer is present");
323
- }
324
- const builder = new SummarizeResultBuilder();
325
- if (this.runningSummarizer) {
326
- // Summarizer is already running. Go ahead and start.
327
- return this.runningSummarizer.summarizeOnDemand(builder, ...args);
328
- }
329
-
330
- // Summarizer isn't running, so we need to start it, which is an async operation.
331
- // Manage the promise related to creating the cancellation token here.
332
- // The promises related to starting, summarizing,
333
- // and submitting are communicated to the caller through the results builder.
334
- const coordinatorCreateP = this.runCoordinatorCreateFn(this.runtime);
335
-
336
- coordinatorCreateP.then((runCoordinator) => {
337
- // Successfully created the cancellation token. Start the summarizer.
338
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
339
- const startP = this.start(this.runtime.clientId!, runCoordinator);
340
- startP.then(async (runningSummarizer) => {
341
- // Successfully started the summarizer. Run it.
342
- runningSummarizer.summarizeOnDemand(builder, ...args);
343
- // Wait for a command to stop or loss of connectivity before tearing down the summarizer and client.
344
- const stopReason = await Promise.race([this.stopDeferred.promise, runCoordinator.waitCancelled]);
345
- await runningSummarizer.waitStop(false);
346
- runCoordinator.stop(stopReason);
347
- this.close();
348
- }).catch((reason) => {
349
- builder.fail("Failed to start summarizer", reason);
350
- });
351
- }).catch((reason) => {
352
- builder.fail("Failed to create cancellation token", reason);
353
- });
354
-
355
- return builder.build();
356
- } catch (error) {
357
- throw SummarizingWarning.wrap(error, false /* logged */, this.logger);
358
- }
359
- };
360
-
361
- public readonly enqueueSummarize: ISummarizer["enqueueSummarize"] = (...args) => {
362
- if (this._disposed || this.runningSummarizer === undefined || this.runningSummarizer.disposed) {
363
- throw new UsageError("Summarizer is not running or already disposed.");
364
- }
365
- return this.runningSummarizer.enqueueSummarize(...args);
366
- };
367
-
368
- private async handleSummaryAcks() {
369
- let refSequenceNumber = this.runtime.deltaManager.initialSequenceNumber;
370
- let ack: IAckedSummary | undefined;
371
- while (this.runningSummarizer) {
372
- const summaryLogger = this.runningSummarizer.tryGetCorrelatedLogger(refSequenceNumber) ?? this.logger;
373
- try {
374
- // Initialize ack with undefined if exception happens inside of waitSummaryAck on second iteration,
375
- // we record undefined, not previous handles.
376
- ack = undefined;
377
- ack = await this.summaryCollection.waitSummaryAck(refSequenceNumber);
378
- refSequenceNumber = ack.summaryOp.referenceSequenceNumber;
379
- const summaryOpHandle = ack.summaryOp.contents.handle;
380
- const summaryAckHandle = ack.summaryAck.contents.handle;
381
- // Make sure we block any summarizer from being executed/enqueued while
382
- // executing the refreshLatestSummaryAck.
383
- // https://dev.azure.com/fluidframework/internal/_workitems/edit/779
384
- await this.runningSummarizer.lockedRefreshSummaryAckAction(async () =>
385
- this.internalsProvider.refreshLatestSummaryAck({
386
- proposalHandle: summaryOpHandle,
387
- ackHandle: summaryAckHandle,
388
- summaryRefSeq: refSequenceNumber,
389
- summaryLogger },
390
- ).catch(async (error) => {
391
- // If the error is 404, so maybe the fetched version no longer exists on server. We just
392
- // ignore this error in that case, as that means we will have another summaryAck for the
393
- // latest version with which we will refresh the state. However in case of single commit
394
- // summary, we might me missing a summary ack, so in that case we are still fine as the
395
- // code in `submitSummary` function in container runtime, will refresh the latest state
396
- // by calling `refreshLatestSummaryAckFromServer` and we will be fine.
397
- if (isFluidError(error)
398
- && error.errorType === DriverErrorType.fileNotFoundOrAccessDeniedError) {
399
- summaryLogger.sendTelemetryEvent({
400
- eventName: "HandleSummaryAckErrorIgnored",
401
- referenceSequenceNumber: refSequenceNumber,
402
- proposalHandle: summaryOpHandle,
403
- ackHandle: summaryAckHandle,
404
- }, error);
405
- } else {
406
- throw error;
407
- }
408
- }),
409
- );
410
- } catch (error) {
411
- summaryLogger.sendErrorEvent({
412
- eventName: "HandleSummaryAckError",
413
- referenceSequenceNumber: refSequenceNumber,
414
- handle: ack?.summaryOp?.contents?.handle,
415
- ackHandle: ack?.summaryAck?.contents?.handle,
416
- }, error);
417
- }
418
- refSequenceNumber++;
419
- }
420
- }
71
+ public get IFluidLoadable() {
72
+ return this;
73
+ }
74
+ public get ISummarizer() {
75
+ return this;
76
+ }
77
+
78
+ private readonly logger: ITelemetryLogger;
79
+ private runningSummarizer?: RunningSummarizer;
80
+ private _disposed: boolean = false;
81
+ private starting: boolean = false;
82
+
83
+ private readonly innerHandle: IFluidHandle<this>;
84
+
85
+ public get handle(): IFluidHandle<this> {
86
+ return this.innerHandle;
87
+ }
88
+ private readonly stopDeferred = new Deferred<SummarizerStopReason>();
89
+
90
+ constructor(
91
+ url: string,
92
+ /** Reference to runtime that created this object.
93
+ * i.e. runtime with clientType === "summarizer"
94
+ */
95
+ private readonly runtime: ISummarizerRuntime,
96
+ private readonly configurationGetter: () => ISummaryConfiguration,
97
+ /** Represents an object that can generate summary.
98
+ * In practical terms, it's same runtime (this.runtime) with clientType === "summarizer".
99
+ */
100
+ private readonly internalsProvider: ISummarizerInternalsProvider,
101
+ handleContext: IFluidHandleContext,
102
+ public readonly summaryCollection: SummaryCollection,
103
+ private readonly runCoordinatorCreateFn: (
104
+ runtime: IConnectableRuntime,
105
+ ) => Promise<ICancellableSummarizerController>,
106
+ ) {
107
+ super();
108
+ this.logger = ChildLogger.create(this.runtime.logger, "Summarizer");
109
+ this.innerHandle = new SummarizerHandle(this, url, handleContext);
110
+ }
111
+
112
+ /**
113
+ * Creates a Summarizer and its underlying client.
114
+ * Note that different implementations of ILoader will handle the URL differently.
115
+ * ILoader provided by a ContainerRuntime is a RelativeLoader, which will treat URL's
116
+ * starting with "/" as relative to the Container. The general ILoader
117
+ * interface will expect an absolute URL and will not handle "/".
118
+ * @param loader - the loader that resolves the request
119
+ * @param url - the URL used to resolve the container
120
+ */
121
+ public static async create(loader: ILoader, url: string): Promise<ISummarizer> {
122
+ const request: IRequest = {
123
+ headers: {
124
+ [LoaderHeader.cache]: false,
125
+ [LoaderHeader.clientDetails]: {
126
+ capabilities: { interactive: false },
127
+ type: summarizerClientType,
128
+ },
129
+ [DriverHeader.summarizingClient]: true,
130
+ [LoaderHeader.reconnect]: false,
131
+ },
132
+ url,
133
+ };
134
+
135
+ const resolvedContainer = await loader.resolve(request);
136
+ const fluidObject = await requestFluidObject<FluidObject<ISummarizer>>(resolvedContainer, {
137
+ url: "_summarizer",
138
+ });
139
+ if (fluidObject.ISummarizer === undefined) {
140
+ throw new UsageError("Fluid object does not implement ISummarizer");
141
+ }
142
+ return fluidObject.ISummarizer;
143
+ }
144
+
145
+ public async run(onBehalfOf: string): Promise<SummarizerStopReason> {
146
+ try {
147
+ return await this.runCore(onBehalfOf);
148
+ } catch (error) {
149
+ this.stop("summarizerException");
150
+ throw SummarizingWarning.wrap(error, false /* logged */, this.logger);
151
+ } finally {
152
+ this.close();
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Stops the summarizer from running. This will complete
158
+ * the run promise, and also close the container.
159
+ * @param reason - reason code for stopping
160
+ */
161
+ public stop(reason: SummarizerStopReason) {
162
+ this.stopDeferred.resolve(reason);
163
+ }
164
+
165
+ public close() {
166
+ // This will result in "summarizerClientDisconnected" stop reason recorded in telemetry,
167
+ // unless stop() was called earlier
168
+ this.dispose();
169
+ (this.runtime.disposeFn ?? this.runtime.closeFn)();
170
+ }
171
+
172
+ private async runCore(onBehalfOf: string): Promise<SummarizerStopReason> {
173
+ const runCoordinator: ICancellableSummarizerController = await this.runCoordinatorCreateFn(
174
+ this.runtime,
175
+ );
176
+
177
+ // Wait for either external signal to cancel, or loss of connectivity.
178
+ const stopP = Promise.race([runCoordinator.waitCancelled, this.stopDeferred.promise]);
179
+ void stopP.then((reason) => {
180
+ this.logger.sendTelemetryEvent({
181
+ eventName: "StoppingSummarizer",
182
+ onBehalfOf,
183
+ reason,
184
+ });
185
+ });
186
+
187
+ if (runCoordinator.cancelled) {
188
+ return runCoordinator.waitCancelled;
189
+ }
190
+
191
+ const runningSummarizer = await this.start(onBehalfOf, runCoordinator);
192
+
193
+ // Wait for either external signal to cancel, or loss of connectivity.
194
+ const stopReason = await stopP;
195
+
196
+ // There are two possible approaches here:
197
+ // 1. Propagate cancellation from this.stopDeferred to runCoordinator. This will ensure that we move to the exit
198
+ // faster, including breaking out of the RunningSummarizer.trySummarize() faster.
199
+ // We could create new coordinator and pass it to waitStop() -> trySummarizeOnce("lastSummary") flow.
200
+ // The con of this approach is that we might cancel active summary, and lastSummary will fail because it
201
+ // did not wait for ack/nack from previous summary. Plus we disregard any 429 kind of info from service
202
+ // that way (i.e. trySummarize() loop might have been waiting for 5 min because storage told us so).
203
+ // In general, it's more wasted resources.
204
+ // 2. We can not do it and make waitStop() do last summary only if there was no active summary. This ensures
205
+ // that client behaves properly (from server POV) and we do not waste resources. But, it may mean we wait
206
+ // substantially longer for trySummarize() retries to play out and thus this summary loop may run into
207
+ // conflict with new summarizer client starting on different client.
208
+ // As of now, #2 is implemented. It's more forward looking, as issue #7279 suggests changing design for new
209
+ // summarizer client to not be created until current summarizer fully moves to exit, and that would reduce
210
+ // cons of #2 substantially.
211
+
212
+ // Cleanup after running
213
+ await runningSummarizer.waitStop(
214
+ !runCoordinator.cancelled && Summarizer.stopReasonCanRunLastSummary(stopReason),
215
+ );
216
+
217
+ // Propagate reason and ensure that if someone is waiting for cancellation token, they are moving to exit
218
+ runCoordinator.stop(stopReason);
219
+
220
+ return stopReason;
221
+ }
222
+
223
+ /**
224
+ * Should we try to run a last summary for the given stop reason?
225
+ * Currently only allows "parentNotConnected"
226
+ * @param stopReason - SummarizerStopReason
227
+ * @returns - true if the stop reason can run a last summary
228
+ */
229
+ public static stopReasonCanRunLastSummary(stopReason: SummarizerStopReason): boolean {
230
+ return stopReason === "parentNotConnected";
231
+ }
232
+
233
+ /**
234
+ * Put the summarizer in a started state, including creating and initializing the RunningSummarizer.
235
+ * The start request can come either from the SummaryManager (in the auto-summarize case) or from the user
236
+ * (in the on-demand case).
237
+ * @param onBehalfOf - ID of the client that requested that the summarizer start
238
+ * @param runCoordinator - cancellation token
239
+ * @param newConfig - Summary configuration to override the existing config when invoking the RunningSummarizer.
240
+ * @returns - Promise that is fulfilled when the RunningSummarizer is ready
241
+ */
242
+ private async start(
243
+ onBehalfOf: string,
244
+ runCoordinator: ICancellableSummarizerController,
245
+ ): Promise<RunningSummarizer> {
246
+ if (this.runningSummarizer) {
247
+ if (this.runningSummarizer.disposed) {
248
+ throw new UsageError("Starting a disposed summarizer");
249
+ }
250
+ return this.runningSummarizer;
251
+ }
252
+ if (this.starting) {
253
+ throw new UsageError("Attempting to start a summarizer that is already starting");
254
+ }
255
+ this.starting = true;
256
+ // Initialize values and first ack (time is not exact)
257
+ this.logger.sendTelemetryEvent({
258
+ eventName: "RunningSummarizer",
259
+ onBehalfOf,
260
+ initSummarySeqNumber: this.runtime.deltaManager.initialSequenceNumber,
261
+ config: JSON.stringify(this.configurationGetter()),
262
+ });
263
+
264
+ // Summarizing container ID (with clientType === "summarizer")
265
+ const clientId = this.runtime.clientId;
266
+ if (clientId === undefined) {
267
+ throw new UsageError("clientId should be defined if connected.");
268
+ }
269
+
270
+ const runningSummarizer = await RunningSummarizer.start(
271
+ this.logger,
272
+ this.summaryCollection.createWatcher(clientId),
273
+ this.configurationGetter(),
274
+ async (...args) => this.internalsProvider.submitSummary(...args), // submitSummaryCallback
275
+ new SummarizeHeuristicData(this.runtime.deltaManager.lastSequenceNumber, {
276
+ /** summary attempt baseline for heuristics */
277
+ refSequenceNumber: this.runtime.deltaManager.initialSequenceNumber,
278
+ summaryTime: Date.now(),
279
+ } as const),
280
+ (errorMessage: string) => {
281
+ if (!this._disposed) {
282
+ this.logger.sendErrorEvent(
283
+ { eventName: "summarizingError" },
284
+ createSummarizingWarning(errorMessage, true),
285
+ );
286
+ }
287
+ },
288
+ this.summaryCollection,
289
+ runCoordinator /* cancellationToken */,
290
+ (reason) => runCoordinator.stop(reason) /* stopSummarizerCallback */,
291
+ this.runtime,
292
+ );
293
+ this.runningSummarizer = runningSummarizer;
294
+ this.starting = false;
295
+
296
+ // Handle summary acks
297
+ // Note: no exceptions are thrown from handleSummaryAcks handler as it handles all exceptions
298
+ this.handleSummaryAcks().catch((error) => {
299
+ this.logger.sendErrorEvent({ eventName: "HandleSummaryAckFatalError" }, error);
300
+ });
301
+
302
+ return runningSummarizer;
303
+ }
304
+
305
+ /**
306
+ * Disposes of resources after running. This cleanup will
307
+ * clear any outstanding timers and reset some of the state
308
+ * properties.
309
+ * Called by ContainerRuntime when it is disposed, as well as at the end the run().
310
+ */
311
+ public dispose() {
312
+ // Given that the call can come from own ContainerRuntime, ensure that we stop all the processes.
313
+ this.stop("summarizerClientDisconnected");
314
+
315
+ this._disposed = true;
316
+ if (this.runningSummarizer) {
317
+ this.runningSummarizer.dispose();
318
+ this.runningSummarizer = undefined;
319
+ }
320
+ }
321
+
322
+ public readonly summarizeOnDemand: ISummarizer["summarizeOnDemand"] = (...args) => {
323
+ try {
324
+ if (this._disposed || this.runningSummarizer?.disposed) {
325
+ throw new UsageError("Summarizer is already disposed.");
326
+ }
327
+ if (
328
+ this.runtime.summarizerClientId !== undefined &&
329
+ this.runtime.summarizerClientId !== this.runtime.clientId
330
+ ) {
331
+ // If there is an elected summarizer, and it's not this one, don't allow on-demand summary.
332
+ // This is to prevent the on-demand summary and heuristic-based summary from stepping on
333
+ // each other.
334
+ throw new UsageError(
335
+ "On-demand summary attempted while an elected summarizer is present",
336
+ );
337
+ }
338
+ const builder = new SummarizeResultBuilder();
339
+ if (this.runningSummarizer) {
340
+ // Summarizer is already running. Go ahead and start.
341
+ return this.runningSummarizer.summarizeOnDemand(builder, ...args);
342
+ }
343
+
344
+ // Summarizer isn't running, so we need to start it, which is an async operation.
345
+ // Manage the promise related to creating the cancellation token here.
346
+ // The promises related to starting, summarizing,
347
+ // and submitting are communicated to the caller through the results builder.
348
+ const coordinatorCreateP = this.runCoordinatorCreateFn(this.runtime);
349
+
350
+ coordinatorCreateP
351
+ .then((runCoordinator) => {
352
+ // Successfully created the cancellation token. Start the summarizer.
353
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
354
+ const startP = this.start(this.runtime.clientId!, runCoordinator);
355
+ startP
356
+ .then(async (runningSummarizer) => {
357
+ // Successfully started the summarizer. Run it.
358
+ runningSummarizer.summarizeOnDemand(builder, ...args);
359
+ // Wait for a command to stop or loss of connectivity before tearing down the summarizer and client.
360
+ const stopReason = await Promise.race([
361
+ this.stopDeferred.promise,
362
+ runCoordinator.waitCancelled,
363
+ ]);
364
+ await runningSummarizer.waitStop(false);
365
+ runCoordinator.stop(stopReason);
366
+ this.close();
367
+ })
368
+ .catch((reason) => {
369
+ builder.fail("Failed to start summarizer", reason);
370
+ });
371
+ })
372
+ .catch((reason) => {
373
+ builder.fail("Failed to create cancellation token", reason);
374
+ });
375
+
376
+ return builder.build();
377
+ } catch (error) {
378
+ throw SummarizingWarning.wrap(error, false /* logged */, this.logger);
379
+ }
380
+ };
381
+
382
+ public readonly enqueueSummarize: ISummarizer["enqueueSummarize"] = (...args) => {
383
+ if (
384
+ this._disposed ||
385
+ this.runningSummarizer === undefined ||
386
+ this.runningSummarizer.disposed
387
+ ) {
388
+ throw new UsageError("Summarizer is not running or already disposed.");
389
+ }
390
+ return this.runningSummarizer.enqueueSummarize(...args);
391
+ };
392
+
393
+ private async handleSummaryAcks() {
394
+ let refSequenceNumber = this.runtime.deltaManager.initialSequenceNumber;
395
+ let ack: IAckedSummary | undefined;
396
+ while (this.runningSummarizer) {
397
+ const summaryLogger =
398
+ this.runningSummarizer.tryGetCorrelatedLogger(refSequenceNumber) ?? this.logger;
399
+ try {
400
+ // Initialize ack with undefined if exception happens inside of waitSummaryAck on second iteration,
401
+ // we record undefined, not previous handles.
402
+ ack = undefined;
403
+ ack = await this.summaryCollection.waitSummaryAck(refSequenceNumber);
404
+ refSequenceNumber = ack.summaryOp.referenceSequenceNumber;
405
+ const summaryOpHandle = ack.summaryOp.contents.handle;
406
+ const summaryAckHandle = ack.summaryAck.contents.handle;
407
+ // Make sure we block any summarizer from being executed/enqueued while
408
+ // executing the refreshLatestSummaryAck.
409
+ // https://dev.azure.com/fluidframework/internal/_workitems/edit/779
410
+ await this.runningSummarizer.lockedRefreshSummaryAckAction(async () =>
411
+ this.internalsProvider
412
+ .refreshLatestSummaryAck({
413
+ proposalHandle: summaryOpHandle,
414
+ ackHandle: summaryAckHandle,
415
+ summaryRefSeq: refSequenceNumber,
416
+ summaryLogger,
417
+ })
418
+ .catch(async (error) => {
419
+ // If the error is 404, so maybe the fetched version no longer exists on server. We just
420
+ // ignore this error in that case, as that means we will have another summaryAck for the
421
+ // latest version with which we will refresh the state. However in case of single commit
422
+ // summary, we might me missing a summary ack, so in that case we are still fine as the
423
+ // code in `submitSummary` function in container runtime, will refresh the latest state
424
+ // by calling `refreshLatestSummaryAckFromServer` and we will be fine.
425
+ if (
426
+ isFluidError(error) &&
427
+ error.errorType === DriverErrorType.fileNotFoundOrAccessDeniedError
428
+ ) {
429
+ summaryLogger.sendTelemetryEvent(
430
+ {
431
+ eventName: "HandleSummaryAckErrorIgnored",
432
+ referenceSequenceNumber: refSequenceNumber,
433
+ proposalHandle: summaryOpHandle,
434
+ ackHandle: summaryAckHandle,
435
+ },
436
+ error,
437
+ );
438
+ } else {
439
+ throw error;
440
+ }
441
+ }),
442
+ );
443
+ } catch (error) {
444
+ summaryLogger.sendErrorEvent(
445
+ {
446
+ eventName: "HandleSummaryAckError",
447
+ referenceSequenceNumber: refSequenceNumber,
448
+ handle: ack?.summaryOp?.contents?.handle,
449
+ ackHandle: ack?.summaryAck?.contents?.handle,
450
+ },
451
+ error,
452
+ );
453
+ }
454
+ refSequenceNumber++;
455
+ }
456
+ }
421
457
  }