@fluidframework/container-runtime 2.0.0-internal.3.0.5 → 2.0.0-internal.3.1.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 (329) 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 +11 -1
  18. package/dist/containerRuntime.d.ts.map +1 -1
  19. package/dist/containerRuntime.js +116 -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 -13
  25. package/dist/dataStoreContext.d.ts.map +1 -1
  26. package/dist/dataStoreContext.js +68 -55
  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 +33 -14
  42. package/dist/garbageCollection.d.ts.map +1 -1
  43. package/dist/garbageCollection.js +178 -92
  44. package/dist/garbageCollection.js.map +1 -1
  45. package/dist/garbageCollectionConstants.d.ts +1 -0
  46. package/dist/garbageCollectionConstants.d.ts.map +1 -1
  47. package/dist/garbageCollectionConstants.js +4 -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 +0 -4
  71. package/dist/opLifecycle/opDecompressor.d.ts.map +1 -1
  72. package/dist/opLifecycle/opDecompressor.js +7 -43
  73. package/dist/opLifecycle/opDecompressor.js.map +1 -1
  74. package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
  75. package/dist/opLifecycle/opSplitter.js +4 -1
  76. package/dist/opLifecycle/opSplitter.js.map +1 -1
  77. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  78. package/dist/opLifecycle/outbox.js +20 -19
  79. package/dist/opLifecycle/outbox.js.map +1 -1
  80. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  81. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  82. package/dist/opProperties.d.ts.map +1 -1
  83. package/dist/opProperties.js +1 -3
  84. package/dist/opProperties.js.map +1 -1
  85. package/dist/orderedClientElection.d.ts.map +1 -1
  86. package/dist/orderedClientElection.js +10 -4
  87. package/dist/orderedClientElection.js.map +1 -1
  88. package/dist/packageVersion.d.ts +1 -1
  89. package/dist/packageVersion.js +1 -1
  90. package/dist/packageVersion.js.map +1 -1
  91. package/dist/pendingStateManager.d.ts +7 -0
  92. package/dist/pendingStateManager.d.ts.map +1 -1
  93. package/dist/pendingStateManager.js +7 -4
  94. package/dist/pendingStateManager.js.map +1 -1
  95. package/dist/runWhileConnectedCoordinator.d.ts.map +1 -1
  96. package/dist/runWhileConnectedCoordinator.js.map +1 -1
  97. package/dist/runningSummarizer.d.ts.map +1 -1
  98. package/dist/runningSummarizer.js +34 -21
  99. package/dist/runningSummarizer.js.map +1 -1
  100. package/dist/scheduleManager.d.ts.map +1 -1
  101. package/dist/scheduleManager.js +3 -2
  102. package/dist/scheduleManager.js.map +1 -1
  103. package/dist/serializedSnapshotStorage.d.ts +2 -2
  104. package/dist/serializedSnapshotStorage.d.ts.map +1 -1
  105. package/dist/serializedSnapshotStorage.js +5 -3
  106. package/dist/serializedSnapshotStorage.js.map +1 -1
  107. package/dist/summarizer.d.ts +2 -2
  108. package/dist/summarizer.d.ts.map +1 -1
  109. package/dist/summarizer.js +37 -17
  110. package/dist/summarizer.js.map +1 -1
  111. package/dist/summarizerClientElection.d.ts.map +1 -1
  112. package/dist/summarizerClientElection.js.map +1 -1
  113. package/dist/summarizerHandle.d.ts.map +1 -1
  114. package/dist/summarizerHandle.js.map +1 -1
  115. package/dist/summarizerHeuristics.d.ts.map +1 -1
  116. package/dist/summarizerHeuristics.js +6 -9
  117. package/dist/summarizerHeuristics.js.map +1 -1
  118. package/dist/summarizerTypes.d.ts +21 -21
  119. package/dist/summarizerTypes.d.ts.map +1 -1
  120. package/dist/summarizerTypes.js.map +1 -1
  121. package/dist/summaryCollection.d.ts.map +1 -1
  122. package/dist/summaryCollection.js +18 -8
  123. package/dist/summaryCollection.js.map +1 -1
  124. package/dist/summaryFormat.d.ts +5 -2
  125. package/dist/summaryFormat.d.ts.map +1 -1
  126. package/dist/summaryFormat.js +18 -10
  127. package/dist/summaryFormat.js.map +1 -1
  128. package/dist/summaryGenerator.d.ts.map +1 -1
  129. package/dist/summaryGenerator.js +35 -16
  130. package/dist/summaryGenerator.js.map +1 -1
  131. package/dist/summaryManager.d.ts.map +1 -1
  132. package/dist/summaryManager.js +21 -9
  133. package/dist/summaryManager.js.map +1 -1
  134. package/dist/throttler.d.ts +2 -2
  135. package/dist/throttler.d.ts.map +1 -1
  136. package/dist/throttler.js +4 -4
  137. package/dist/throttler.js.map +1 -1
  138. package/garbageCollection.md +15 -2
  139. package/lib/batchTracker.d.ts.map +1 -1
  140. package/lib/batchTracker.js +2 -1
  141. package/lib/batchTracker.js.map +1 -1
  142. package/lib/blobManager.d.ts +9 -2
  143. package/lib/blobManager.d.ts.map +1 -1
  144. package/lib/blobManager.js +82 -35
  145. package/lib/blobManager.js.map +1 -1
  146. package/lib/connectionTelemetry.d.ts.map +1 -1
  147. package/lib/connectionTelemetry.js +11 -9
  148. package/lib/connectionTelemetry.js.map +1 -1
  149. package/lib/containerHandleContext.d.ts.map +1 -1
  150. package/lib/containerHandleContext.js +3 -1
  151. package/lib/containerHandleContext.js.map +1 -1
  152. package/lib/containerRuntime.d.ts +11 -1
  153. package/lib/containerRuntime.d.ts.map +1 -1
  154. package/lib/containerRuntime.js +122 -78
  155. package/lib/containerRuntime.js.map +1 -1
  156. package/lib/dataStore.d.ts.map +1 -1
  157. package/lib/dataStore.js +11 -9
  158. package/lib/dataStore.js.map +1 -1
  159. package/lib/dataStoreContext.d.ts +18 -13
  160. package/lib/dataStoreContext.d.ts.map +1 -1
  161. package/lib/dataStoreContext.js +71 -58
  162. package/lib/dataStoreContext.js.map +1 -1
  163. package/lib/dataStoreContexts.d.ts.map +1 -1
  164. package/lib/dataStoreContexts.js +7 -3
  165. package/lib/dataStoreContexts.js.map +1 -1
  166. package/lib/dataStoreRegistry.d.ts.map +1 -1
  167. package/lib/dataStoreRegistry.js +3 -1
  168. package/lib/dataStoreRegistry.js.map +1 -1
  169. package/lib/dataStores.d.ts +26 -1
  170. package/lib/dataStores.d.ts.map +1 -1
  171. package/lib/dataStores.js +109 -24
  172. package/lib/dataStores.js.map +1 -1
  173. package/lib/deltaScheduler.d.ts.map +1 -1
  174. package/lib/deltaScheduler.js +9 -4
  175. package/lib/deltaScheduler.js.map +1 -1
  176. package/lib/garbageCollection.d.ts +33 -14
  177. package/lib/garbageCollection.d.ts.map +1 -1
  178. package/lib/garbageCollection.js +180 -94
  179. package/lib/garbageCollection.js.map +1 -1
  180. package/lib/garbageCollectionConstants.d.ts +1 -0
  181. package/lib/garbageCollectionConstants.d.ts.map +1 -1
  182. package/lib/garbageCollectionConstants.js +3 -0
  183. package/lib/garbageCollectionConstants.js.map +1 -1
  184. package/lib/garbageCollectionHelpers.d.ts +26 -0
  185. package/lib/garbageCollectionHelpers.d.ts.map +1 -0
  186. package/lib/garbageCollectionHelpers.js +40 -0
  187. package/lib/garbageCollectionHelpers.js.map +1 -0
  188. package/lib/gcSweepReadyUsageDetection.d.ts +5 -5
  189. package/lib/gcSweepReadyUsageDetection.d.ts.map +1 -1
  190. package/lib/gcSweepReadyUsageDetection.js +14 -10
  191. package/lib/gcSweepReadyUsageDetection.js.map +1 -1
  192. package/lib/index.d.ts +2 -2
  193. package/lib/index.d.ts.map +1 -1
  194. package/lib/index.js +1 -1
  195. package/lib/index.js.map +1 -1
  196. package/lib/opLifecycle/batchManager.d.ts +5 -5
  197. package/lib/opLifecycle/batchManager.d.ts.map +1 -1
  198. package/lib/opLifecycle/batchManager.js +19 -12
  199. package/lib/opLifecycle/batchManager.js.map +1 -1
  200. package/lib/opLifecycle/definitions.d.ts.map +1 -1
  201. package/lib/opLifecycle/definitions.js.map +1 -1
  202. package/lib/opLifecycle/index.d.ts.map +1 -1
  203. package/lib/opLifecycle/index.js.map +1 -1
  204. package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
  205. package/lib/opLifecycle/opCompressor.js.map +1 -1
  206. package/lib/opLifecycle/opDecompressor.d.ts +0 -4
  207. package/lib/opLifecycle/opDecompressor.d.ts.map +1 -1
  208. package/lib/opLifecycle/opDecompressor.js +7 -43
  209. package/lib/opLifecycle/opDecompressor.js.map +1 -1
  210. package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
  211. package/lib/opLifecycle/opSplitter.js +5 -2
  212. package/lib/opLifecycle/opSplitter.js.map +1 -1
  213. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  214. package/lib/opLifecycle/outbox.js +20 -19
  215. package/lib/opLifecycle/outbox.js.map +1 -1
  216. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  217. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  218. package/lib/opProperties.d.ts.map +1 -1
  219. package/lib/opProperties.js +1 -3
  220. package/lib/opProperties.js.map +1 -1
  221. package/lib/orderedClientElection.d.ts.map +1 -1
  222. package/lib/orderedClientElection.js +10 -4
  223. package/lib/orderedClientElection.js.map +1 -1
  224. package/lib/packageVersion.d.ts +1 -1
  225. package/lib/packageVersion.js +1 -1
  226. package/lib/packageVersion.js.map +1 -1
  227. package/lib/pendingStateManager.d.ts +7 -0
  228. package/lib/pendingStateManager.d.ts.map +1 -1
  229. package/lib/pendingStateManager.js +7 -4
  230. package/lib/pendingStateManager.js.map +1 -1
  231. package/lib/runWhileConnectedCoordinator.d.ts.map +1 -1
  232. package/lib/runWhileConnectedCoordinator.js.map +1 -1
  233. package/lib/runningSummarizer.d.ts.map +1 -1
  234. package/lib/runningSummarizer.js +35 -22
  235. package/lib/runningSummarizer.js.map +1 -1
  236. package/lib/scheduleManager.d.ts.map +1 -1
  237. package/lib/scheduleManager.js +3 -2
  238. package/lib/scheduleManager.js.map +1 -1
  239. package/lib/serializedSnapshotStorage.d.ts +2 -2
  240. package/lib/serializedSnapshotStorage.d.ts.map +1 -1
  241. package/lib/serializedSnapshotStorage.js +5 -3
  242. package/lib/serializedSnapshotStorage.js.map +1 -1
  243. package/lib/summarizer.d.ts +2 -2
  244. package/lib/summarizer.d.ts.map +1 -1
  245. package/lib/summarizer.js +37 -17
  246. package/lib/summarizer.js.map +1 -1
  247. package/lib/summarizerClientElection.d.ts.map +1 -1
  248. package/lib/summarizerClientElection.js.map +1 -1
  249. package/lib/summarizerHandle.d.ts.map +1 -1
  250. package/lib/summarizerHandle.js.map +1 -1
  251. package/lib/summarizerHeuristics.d.ts.map +1 -1
  252. package/lib/summarizerHeuristics.js +6 -9
  253. package/lib/summarizerHeuristics.js.map +1 -1
  254. package/lib/summarizerTypes.d.ts +21 -21
  255. package/lib/summarizerTypes.d.ts.map +1 -1
  256. package/lib/summarizerTypes.js.map +1 -1
  257. package/lib/summaryCollection.d.ts.map +1 -1
  258. package/lib/summaryCollection.js +18 -8
  259. package/lib/summaryCollection.js.map +1 -1
  260. package/lib/summaryFormat.d.ts +5 -2
  261. package/lib/summaryFormat.d.ts.map +1 -1
  262. package/lib/summaryFormat.js +20 -12
  263. package/lib/summaryFormat.js.map +1 -1
  264. package/lib/summaryGenerator.d.ts.map +1 -1
  265. package/lib/summaryGenerator.js +35 -16
  266. package/lib/summaryGenerator.js.map +1 -1
  267. package/lib/summaryManager.d.ts.map +1 -1
  268. package/lib/summaryManager.js +21 -9
  269. package/lib/summaryManager.js.map +1 -1
  270. package/lib/throttler.d.ts +2 -2
  271. package/lib/throttler.d.ts.map +1 -1
  272. package/lib/throttler.js +4 -4
  273. package/lib/throttler.js.map +1 -1
  274. package/package.json +121 -115
  275. package/prettier.config.cjs +1 -1
  276. package/src/batchTracker.ts +54 -49
  277. package/src/blobManager.ts +793 -672
  278. package/src/connectionTelemetry.ts +280 -249
  279. package/src/containerHandleContext.ts +27 -29
  280. package/src/containerRuntime.ts +3168 -2988
  281. package/src/dataStore.ts +172 -159
  282. package/src/dataStoreContext.ts +1098 -1055
  283. package/src/dataStoreContexts.ts +178 -161
  284. package/src/dataStoreRegistry.ts +25 -20
  285. package/src/dataStores.ts +884 -728
  286. package/src/deltaScheduler.ts +158 -150
  287. package/src/garbageCollection.ts +1860 -1688
  288. package/src/garbageCollectionConstants.ts +3 -0
  289. package/src/garbageCollectionHelpers.ts +61 -0
  290. package/src/gcSweepReadyUsageDetection.ts +89 -83
  291. package/src/index.ts +67 -66
  292. package/src/opLifecycle/README.md +152 -0
  293. package/src/opLifecycle/batchManager.ts +145 -141
  294. package/src/opLifecycle/definitions.ts +29 -29
  295. package/src/opLifecycle/index.ts +5 -5
  296. package/src/opLifecycle/opCompressor.ts +54 -53
  297. package/src/opLifecycle/opDecompressor.ts +100 -128
  298. package/src/opLifecycle/opSplitter.ts +214 -188
  299. package/src/opLifecycle/outbox.ts +204 -195
  300. package/src/opLifecycle/remoteMessageProcessor.ts +62 -62
  301. package/src/opProperties.ts +11 -9
  302. package/src/orderedClientElection.ts +489 -457
  303. package/src/packageVersion.ts +1 -1
  304. package/src/pendingStateManager.ts +384 -338
  305. package/src/runWhileConnectedCoordinator.ts +78 -71
  306. package/src/runningSummarizer.ts +619 -581
  307. package/src/scheduleManager.ts +299 -269
  308. package/src/serializedSnapshotStorage.ts +126 -112
  309. package/src/summarizer.ts +417 -381
  310. package/src/summarizerClientElection.ts +107 -100
  311. package/src/summarizerHandle.ts +11 -9
  312. package/src/summarizerHeuristics.ts +183 -186
  313. package/src/summarizerTypes.ts +344 -330
  314. package/src/summaryCollection.ts +378 -349
  315. package/src/summaryFormat.ts +165 -143
  316. package/src/summaryGenerator.ts +465 -410
  317. package/src/summaryManager.ts +377 -348
  318. package/src/throttler.ts +131 -122
  319. package/tsconfig.esnext.json +6 -6
  320. package/tsconfig.json +9 -13
  321. package/dist/garbageCollectionTombstoneUtils.d.ts +0 -14
  322. package/dist/garbageCollectionTombstoneUtils.d.ts.map +0 -1
  323. package/dist/garbageCollectionTombstoneUtils.js +0 -23
  324. package/dist/garbageCollectionTombstoneUtils.js.map +0 -1
  325. package/lib/garbageCollectionTombstoneUtils.d.ts +0 -14
  326. package/lib/garbageCollectionTombstoneUtils.d.ts.map +0 -1
  327. package/lib/garbageCollectionTombstoneUtils.js +0 -19
  328. package/lib/garbageCollectionTombstoneUtils.js.map +0 -1
  329. package/src/garbageCollectionTombstoneUtils.ts +0 -28
package/src/throttler.ts CHANGED
@@ -4,28 +4,28 @@
4
4
  */
5
5
 
6
6
  export interface IThrottler {
7
- /**
8
- * Computes what the throttle delay should be, and records an attempt
9
- * which will be used for calculating future attempt delays.
10
- */
11
- getDelay(): number;
12
-
13
- /**
14
- * Number of attempts that occurred within the sliding window as of
15
- * the most recent delay computation.
16
- */
17
- readonly numAttempts: number;
18
-
19
- /** Width of sliding delay window in milliseconds. */
20
- readonly delayWindowMs: number;
21
- /** Maximum delay allowed in milliseconds. */
22
- readonly maxDelayMs: number;
23
- /**
24
- * Delay function used to calculate what the delay should be.
25
- * The input is the number of attempts that occurred within the sliding window.
26
- * The result is the calculated delay in milliseconds.
27
- */
28
- readonly delayFn: (numAttempts: number) => number;
7
+ /**
8
+ * Computes what the throttle delay should be, and records an attempt
9
+ * which will be used for calculating future attempt delays.
10
+ */
11
+ getDelay(): number;
12
+
13
+ /**
14
+ * Number of attempts that occurred within the sliding window as of
15
+ * the most recent delay computation.
16
+ */
17
+ readonly numAttempts: number;
18
+
19
+ /** Width of sliding delay window in milliseconds. */
20
+ readonly delayWindowMs: number;
21
+ /** Maximum delay allowed in milliseconds. */
22
+ readonly maxDelayMs: number;
23
+ /**
24
+ * Delay function used to calculate what the delay should be.
25
+ * The input is the number of attempts that occurred within the sliding window.
26
+ * The result is the calculated delay in milliseconds.
27
+ */
28
+ readonly delayFn: (numAttempts: number) => number;
29
29
  }
30
30
 
31
31
  /**
@@ -33,74 +33,74 @@ export interface IThrottler {
33
33
  * Delay is based on previous attempts within specified time window, subtracting delay time.
34
34
  */
35
35
  export class Throttler implements IThrottler {
36
- private startTimes: number[] = [];
37
-
38
- public get numAttempts() {
39
- return this.startTimes.length;
40
- }
41
-
42
- /**
43
- * Gets all attempt start times after compensating for the delay times
44
- * by adding the delay times to the actual times.
45
- */
46
- public getAttempts(): readonly number[] {
47
- return [...this.startTimes];
48
- }
49
-
50
- /**
51
- * Latest attempt time after compensating for the delay time itself
52
- * by adding the delay time to the actual time.
53
- */
54
- public get latestAttemptTime() {
55
- return this.startTimes.length > 0 ? this.startTimes[this.startTimes.length - 1] : undefined;
56
- }
57
-
58
- constructor(
59
- /** Width of sliding delay window in milliseconds. */
60
- public readonly delayWindowMs: number,
61
- /** Maximum delay allowed in milliseconds. */
62
- public readonly maxDelayMs: number,
63
- /**
64
- * Delay function used to calculate what the delay should be.
65
- * The input is the number of attempts that occurred within the sliding window.
66
- * The result is the calculated delay in milliseconds.
67
- */
68
- public readonly delayFn: (numAttempts: number) => number,
69
- ) { }
70
-
71
- public getDelay() {
72
- const now = Date.now();
73
-
74
- const latestAttemptTime = this.latestAttemptTime;
75
- if (latestAttemptTime !== undefined) {
76
- // If getDelay was called sooner than the most recent delay,
77
- // subtract the remaining time, since we previously added it.
78
- const earlyMs = latestAttemptTime - now;
79
- if (earlyMs > 0) {
80
- this.startTimes = this.startTimes.map((t) => t - earlyMs);
81
- }
82
- }
83
-
84
- // Remove all attempts that have already fallen out of the window.
85
- this.startTimes = this.startTimes.filter((t) => (now - t) < this.delayWindowMs);
86
-
87
- // Compute delay, but do not exceed the specified max delay.
88
- const delayMs = Math.min(this.delayFn(this.startTimes.length), this.maxDelayMs);
89
-
90
- // Record this attempt start time.
91
- this.startTimes.push(now);
92
-
93
- // Account for the delay time, by effectively removing it from the delay window.
94
- this.startTimes = this.startTimes.map((t) => t + delayMs);
95
-
96
- if (delayMs === this.maxDelayMs) {
97
- // We hit max delay, so adding more won't affect anything.
98
- // Shift off oldest time to stop this array from growing forever.
99
- this.startTimes.shift();
100
- }
101
-
102
- return delayMs;
103
- }
36
+ private startTimes: number[] = [];
37
+
38
+ public get numAttempts() {
39
+ return this.startTimes.length;
40
+ }
41
+
42
+ /**
43
+ * Gets all attempt start times after compensating for the delay times
44
+ * by adding the delay times to the actual times.
45
+ */
46
+ public getAttempts(): readonly number[] {
47
+ return [...this.startTimes];
48
+ }
49
+
50
+ /**
51
+ * Latest attempt time after compensating for the delay time itself
52
+ * by adding the delay time to the actual time.
53
+ */
54
+ public get latestAttemptTime() {
55
+ return this.startTimes.length > 0 ? this.startTimes[this.startTimes.length - 1] : undefined;
56
+ }
57
+
58
+ constructor(
59
+ /** Width of sliding delay window in milliseconds. */
60
+ public readonly delayWindowMs: number,
61
+ /** Maximum delay allowed in milliseconds. */
62
+ public readonly maxDelayMs: number,
63
+ /**
64
+ * Delay function used to calculate what the delay should be.
65
+ * The input is the number of attempts that occurred within the sliding window.
66
+ * The result is the calculated delay in milliseconds.
67
+ */
68
+ public readonly delayFn: (numAttempts: number) => number,
69
+ ) {}
70
+
71
+ public getDelay() {
72
+ const now = Date.now();
73
+
74
+ const latestAttemptTime = this.latestAttemptTime;
75
+ if (latestAttemptTime !== undefined) {
76
+ // If getDelay was called sooner than the most recent delay,
77
+ // subtract the remaining time, since we previously added it.
78
+ const earlyMs = latestAttemptTime - now;
79
+ if (earlyMs > 0) {
80
+ this.startTimes = this.startTimes.map((t) => t - earlyMs);
81
+ }
82
+ }
83
+
84
+ // Remove all attempts that have already fallen out of the window.
85
+ this.startTimes = this.startTimes.filter((t) => now - t < this.delayWindowMs);
86
+
87
+ // Compute delay, but do not exceed the specified max delay.
88
+ const delayMs = Math.min(this.delayFn(this.startTimes.length), this.maxDelayMs);
89
+
90
+ // Record this attempt start time.
91
+ this.startTimes.push(now);
92
+
93
+ // Account for the delay time, by effectively removing it from the delay window.
94
+ this.startTimes = this.startTimes.map((t) => t + delayMs);
95
+
96
+ if (delayMs === this.maxDelayMs) {
97
+ // We hit max delay, so adding more won't affect anything.
98
+ // Shift off oldest time to stop this array from growing forever.
99
+ this.startTimes.shift();
100
+ }
101
+
102
+ return delayMs;
103
+ }
104
104
  }
105
105
 
106
106
  /**
@@ -114,28 +114,37 @@ export class Throttler implements IThrottler {
114
114
  * Use initialDelay to decide what should happen when numAttempts is 0,
115
115
  * leave it undefined to not special case.
116
116
  */
117
- export const formExponentialFn = ({
118
- multiplier = 2,
119
- coefficient = 1,
120
- offset = 0,
121
- initialDelay = undefined as number | undefined,
122
- } = {}): IThrottler["delayFn"] => (numAttempts) => Math.max(0,
123
- numAttempts <= 0 && initialDelay !== undefined
124
- ? initialDelay
125
- : coefficient * (Math.pow(multiplier, numAttempts)) + offset);
117
+ export const formExponentialFn =
118
+ ({
119
+ multiplier = 2,
120
+ coefficient = 1,
121
+ offset = 0,
122
+ initialDelay = undefined as number | undefined,
123
+ } = {}): IThrottler["delayFn"] =>
124
+ (numAttempts) =>
125
+ Math.max(
126
+ 0,
127
+ numAttempts <= 0 && initialDelay !== undefined
128
+ ? initialDelay
129
+ : coefficient * Math.pow(multiplier, numAttempts) + offset,
130
+ );
126
131
 
127
132
  /** f(n) = C x (B^(n+A)) + F = (C x B^A) x B^n + F */
128
- export const formExponentialFnWithAttemptOffset = (attemptOffset: number, {
129
- multiplier = 2,
130
- coefficient = 1,
131
- offset = 0,
132
- initialDelay = undefined as number | undefined,
133
- } = {}) => formExponentialFn({
134
- multiplier,
135
- coefficient: coefficient * Math.pow(multiplier, attemptOffset),
136
- offset,
137
- initialDelay,
138
- });
133
+ export const formExponentialFnWithAttemptOffset = (
134
+ attemptOffset: number,
135
+ {
136
+ multiplier = 2,
137
+ coefficient = 1,
138
+ offset = 0,
139
+ initialDelay = undefined as number | undefined,
140
+ } = {},
141
+ ) =>
142
+ formExponentialFn({
143
+ multiplier,
144
+ coefficient: coefficient * Math.pow(multiplier, attemptOffset),
145
+ offset,
146
+ initialDelay,
147
+ });
139
148
 
140
149
  /**
141
150
  * Helper function to generate simple linear throttle functions.
@@ -144,17 +153,17 @@ export const formExponentialFnWithAttemptOffset = (attemptOffset: number, {
144
153
  * If not provided, coefficient will default to 1, and offset to 0, yielding:
145
154
  * 0 ms, 1 ms, 2 ms, 3 ms, ..., n ms delays; a linear back-off.
146
155
  */
147
- export const formLinearFn = ({
148
- coefficient = 1,
149
- offset = 0,
150
- } = {}): IThrottler["delayFn"] => (numAttempts) => Math.max(0,
151
- coefficient * numAttempts + offset);
156
+ export const formLinearFn =
157
+ ({ coefficient = 1, offset = 0 } = {}): IThrottler["delayFn"] =>
158
+ (numAttempts) =>
159
+ Math.max(0, coefficient * numAttempts + offset);
152
160
 
153
161
  /** f(n) = C x (n+A) + F = C x n + (C x A + F) */
154
- export const formLinearFnWithAttemptOffset = (attemptOffset: number, {
155
- coefficient = 1,
156
- offset = 0,
157
- } = {}) => formLinearFn({
158
- coefficient,
159
- offset: coefficient * attemptOffset + offset,
160
- });
162
+ export const formLinearFnWithAttemptOffset = (
163
+ attemptOffset: number,
164
+ { coefficient = 1, offset = 0 } = {},
165
+ ) =>
166
+ formLinearFn({
167
+ coefficient,
168
+ offset: coefficient * attemptOffset + offset,
169
+ });
@@ -1,7 +1,7 @@
1
1
  {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./lib",
5
- "module": "esnext"
6
- },
7
- }
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./lib",
5
+ "module": "esnext",
6
+ },
7
+ }
package/tsconfig.json CHANGED
@@ -1,14 +1,10 @@
1
1
  {
2
- "extends": "@fluidframework/build-common/ts-common-config.json",
3
- "compilerOptions": {
4
- "composite": true,
5
- "rootDir": "./src",
6
- "outDir": "./dist"
7
- },
8
- "include": [
9
- "src/**/*"
10
- ],
11
- "exclude": [
12
- "src/test/**/*"
13
- ]
14
- }
2
+ "extends": "@fluidframework/build-common/ts-common-config.json",
3
+ "compilerOptions": {
4
+ "composite": true,
5
+ "rootDir": "./src",
6
+ "outDir": "./dist",
7
+ },
8
+ "include": ["src/**/*"],
9
+ "exclude": ["src/test/**/*"],
10
+ }
@@ -1,14 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { ITelemetryGenericEvent } from "@fluidframework/common-definitions";
6
- import { MonitoringContext } from "@fluidframework/telemetry-utils";
7
- /**
8
- * Consolidates info / logic for logging when we encounter a Tombstone
9
- */
10
- export declare function sendGCTombstoneEvent(mc: MonitoringContext, event: ITelemetryGenericEvent & {
11
- category: "error" | "generic";
12
- isSummarizerClient: boolean;
13
- }, packagePath: readonly string[] | undefined, error?: unknown): void;
14
- //# sourceMappingURL=garbageCollectionTombstoneUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"garbageCollectionTombstoneUtils.d.ts","sourceRoot":"","sources":["../src/garbageCollectionTombstoneUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAE5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAGpE;;GAEG;AACH,wBAAgB,oBAAoB,CAChC,EAAE,EAAE,iBAAiB,EACrB,KAAK,EAAE,sBAAsB,GAAG;IAAE,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;IAAC,kBAAkB,EAAE,OAAO,CAAA;CAAE,EAC9F,WAAW,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EAC1C,KAAK,CAAC,EAAE,OAAO,QAUlB"}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.sendGCTombstoneEvent = void 0;
8
- const runtime_utils_1 = require("@fluidframework/runtime-utils");
9
- const garbageCollectionConstants_1 = require("./garbageCollectionConstants");
10
- /**
11
- * Consolidates info / logic for logging when we encounter a Tombstone
12
- */
13
- function sendGCTombstoneEvent(mc, event, packagePath, error) {
14
- event.pkg = (0, runtime_utils_1.packagePathToTelemetryProperty)(packagePath);
15
- event.tombstoneFlags = JSON.stringify({
16
- DisableTombstone: mc.config.getBoolean(garbageCollectionConstants_1.disableTombstoneKey),
17
- ThrowOnTombstoneUsage: mc.config.getBoolean(garbageCollectionConstants_1.throwOnTombstoneUsageKey),
18
- ThrowOnTombstoneLoad: mc.config.getBoolean(garbageCollectionConstants_1.throwOnTombstoneLoadKey),
19
- });
20
- mc.logger.sendTelemetryEvent(event, error);
21
- }
22
- exports.sendGCTombstoneEvent = sendGCTombstoneEvent;
23
- //# sourceMappingURL=garbageCollectionTombstoneUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"garbageCollectionTombstoneUtils.js","sourceRoot":"","sources":["../src/garbageCollectionTombstoneUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,iEAA+E;AAE/E,6EAAsH;AAEtH;;GAEG;AACH,SAAgB,oBAAoB,CAChC,EAAqB,EACrB,KAA8F,EAC9F,WAA0C,EAC1C,KAAe;IAEf,KAAK,CAAC,GAAG,GAAG,IAAA,8CAA8B,EAAC,WAAW,CAAC,CAAC;IACxD,KAAK,CAAC,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC;QAClC,gBAAgB,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,gDAAmB,CAAC;QAC3D,qBAAqB,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,qDAAwB,CAAC;QACrE,oBAAoB,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,oDAAuB,CAAC;KACtE,CAAC,CAAC;IAEH,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC/C,CAAC;AAdD,oDAcC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryGenericEvent } from \"@fluidframework/common-definitions\";\nimport { packagePathToTelemetryProperty } from \"@fluidframework/runtime-utils\";\nimport { MonitoringContext } from \"@fluidframework/telemetry-utils\";\nimport { disableTombstoneKey, throwOnTombstoneLoadKey, throwOnTombstoneUsageKey } from \"./garbageCollectionConstants\";\n\n/**\n * Consolidates info / logic for logging when we encounter a Tombstone\n */\nexport function sendGCTombstoneEvent(\n mc: MonitoringContext,\n event: ITelemetryGenericEvent & { category: \"error\" | \"generic\", isSummarizerClient: boolean },\n packagePath: readonly string[] | undefined,\n error?: unknown,\n) {\n event.pkg = packagePathToTelemetryProperty(packagePath);\n event.tombstoneFlags = JSON.stringify({\n DisableTombstone: mc.config.getBoolean(disableTombstoneKey),\n ThrowOnTombstoneUsage: mc.config.getBoolean(throwOnTombstoneUsageKey),\n ThrowOnTombstoneLoad: mc.config.getBoolean(throwOnTombstoneLoadKey),\n });\n\n mc.logger.sendTelemetryEvent(event, error);\n}\n"]}
@@ -1,14 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { ITelemetryGenericEvent } from "@fluidframework/common-definitions";
6
- import { MonitoringContext } from "@fluidframework/telemetry-utils";
7
- /**
8
- * Consolidates info / logic for logging when we encounter a Tombstone
9
- */
10
- export declare function sendGCTombstoneEvent(mc: MonitoringContext, event: ITelemetryGenericEvent & {
11
- category: "error" | "generic";
12
- isSummarizerClient: boolean;
13
- }, packagePath: readonly string[] | undefined, error?: unknown): void;
14
- //# sourceMappingURL=garbageCollectionTombstoneUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"garbageCollectionTombstoneUtils.d.ts","sourceRoot":"","sources":["../src/garbageCollectionTombstoneUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAE5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAGpE;;GAEG;AACH,wBAAgB,oBAAoB,CAChC,EAAE,EAAE,iBAAiB,EACrB,KAAK,EAAE,sBAAsB,GAAG;IAAE,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;IAAC,kBAAkB,EAAE,OAAO,CAAA;CAAE,EAC9F,WAAW,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EAC1C,KAAK,CAAC,EAAE,OAAO,QAUlB"}
@@ -1,19 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { packagePathToTelemetryProperty } from "@fluidframework/runtime-utils";
6
- import { disableTombstoneKey, throwOnTombstoneLoadKey, throwOnTombstoneUsageKey } from "./garbageCollectionConstants";
7
- /**
8
- * Consolidates info / logic for logging when we encounter a Tombstone
9
- */
10
- export function sendGCTombstoneEvent(mc, event, packagePath, error) {
11
- event.pkg = packagePathToTelemetryProperty(packagePath);
12
- event.tombstoneFlags = JSON.stringify({
13
- DisableTombstone: mc.config.getBoolean(disableTombstoneKey),
14
- ThrowOnTombstoneUsage: mc.config.getBoolean(throwOnTombstoneUsageKey),
15
- ThrowOnTombstoneLoad: mc.config.getBoolean(throwOnTombstoneLoadKey),
16
- });
17
- mc.logger.sendTelemetryEvent(event, error);
18
- }
19
- //# sourceMappingURL=garbageCollectionTombstoneUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"garbageCollectionTombstoneUtils.js","sourceRoot":"","sources":["../src/garbageCollectionTombstoneUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAE/E,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAEtH;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAChC,EAAqB,EACrB,KAA8F,EAC9F,WAA0C,EAC1C,KAAe;IAEf,KAAK,CAAC,GAAG,GAAG,8BAA8B,CAAC,WAAW,CAAC,CAAC;IACxD,KAAK,CAAC,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC;QAClC,gBAAgB,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,mBAAmB,CAAC;QAC3D,qBAAqB,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,wBAAwB,CAAC;QACrE,oBAAoB,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,uBAAuB,CAAC;KACtE,CAAC,CAAC;IAEH,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryGenericEvent } from \"@fluidframework/common-definitions\";\nimport { packagePathToTelemetryProperty } from \"@fluidframework/runtime-utils\";\nimport { MonitoringContext } from \"@fluidframework/telemetry-utils\";\nimport { disableTombstoneKey, throwOnTombstoneLoadKey, throwOnTombstoneUsageKey } from \"./garbageCollectionConstants\";\n\n/**\n * Consolidates info / logic for logging when we encounter a Tombstone\n */\nexport function sendGCTombstoneEvent(\n mc: MonitoringContext,\n event: ITelemetryGenericEvent & { category: \"error\" | \"generic\", isSummarizerClient: boolean },\n packagePath: readonly string[] | undefined,\n error?: unknown,\n) {\n event.pkg = packagePathToTelemetryProperty(packagePath);\n event.tombstoneFlags = JSON.stringify({\n DisableTombstone: mc.config.getBoolean(disableTombstoneKey),\n ThrowOnTombstoneUsage: mc.config.getBoolean(throwOnTombstoneUsageKey),\n ThrowOnTombstoneLoad: mc.config.getBoolean(throwOnTombstoneLoadKey),\n });\n\n mc.logger.sendTelemetryEvent(event, error);\n}\n"]}
@@ -1,28 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { ITelemetryGenericEvent } from "@fluidframework/common-definitions";
7
- import { packagePathToTelemetryProperty } from "@fluidframework/runtime-utils";
8
- import { MonitoringContext } from "@fluidframework/telemetry-utils";
9
- import { disableTombstoneKey, throwOnTombstoneLoadKey, throwOnTombstoneUsageKey } from "./garbageCollectionConstants";
10
-
11
- /**
12
- * Consolidates info / logic for logging when we encounter a Tombstone
13
- */
14
- export function sendGCTombstoneEvent(
15
- mc: MonitoringContext,
16
- event: ITelemetryGenericEvent & { category: "error" | "generic", isSummarizerClient: boolean },
17
- packagePath: readonly string[] | undefined,
18
- error?: unknown,
19
- ) {
20
- event.pkg = packagePathToTelemetryProperty(packagePath);
21
- event.tombstoneFlags = JSON.stringify({
22
- DisableTombstone: mc.config.getBoolean(disableTombstoneKey),
23
- ThrowOnTombstoneUsage: mc.config.getBoolean(throwOnTombstoneUsageKey),
24
- ThrowOnTombstoneLoad: mc.config.getBoolean(throwOnTombstoneLoadKey),
25
- });
26
-
27
- mc.logger.sendTelemetryEvent(event, error);
28
- }