@fluidframework/container-runtime 2.0.0-internal.3.1.0 → 2.0.0-internal.3.2.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 (351) hide show
  1. package/dist/blobManager.d.ts +6 -0
  2. package/dist/blobManager.d.ts.map +1 -1
  3. package/dist/blobManager.js +31 -6
  4. package/dist/blobManager.js.map +1 -1
  5. package/dist/containerRuntime.d.ts +17 -15
  6. package/dist/containerRuntime.d.ts.map +1 -1
  7. package/dist/containerRuntime.js +158 -121
  8. package/dist/containerRuntime.js.map +1 -1
  9. package/dist/dataStoreContext.d.ts +21 -12
  10. package/dist/dataStoreContext.d.ts.map +1 -1
  11. package/dist/dataStoreContext.js +76 -50
  12. package/dist/dataStoreContext.js.map +1 -1
  13. package/dist/dataStores.d.ts +9 -10
  14. package/dist/dataStores.d.ts.map +1 -1
  15. package/dist/dataStores.js +42 -49
  16. package/dist/dataStores.js.map +1 -1
  17. package/dist/{garbageCollection.d.ts → gc/garbageCollection.d.ts} +5 -200
  18. package/dist/gc/garbageCollection.d.ts.map +1 -0
  19. package/dist/{garbageCollection.js → gc/garbageCollection.js} +77 -353
  20. package/dist/gc/garbageCollection.js.map +1 -0
  21. package/dist/gc/gcDefinitions.d.ts +189 -0
  22. package/dist/gc/gcDefinitions.d.ts.map +1 -0
  23. package/dist/{garbageCollectionConstants.js → gc/gcDefinitions.js} +24 -2
  24. package/dist/gc/gcDefinitions.js.map +1 -0
  25. package/{lib/garbageCollectionHelpers.d.ts → dist/gc/gcHelpers.d.ts} +5 -1
  26. package/dist/gc/gcHelpers.d.ts.map +1 -0
  27. package/dist/{garbageCollectionHelpers.js → gc/gcHelpers.js} +27 -7
  28. package/dist/gc/gcHelpers.js.map +1 -0
  29. package/dist/gc/gcSummaryStateTracker.d.ts +86 -0
  30. package/dist/gc/gcSummaryStateTracker.d.ts.map +1 -0
  31. package/dist/gc/gcSummaryStateTracker.js +246 -0
  32. package/dist/gc/gcSummaryStateTracker.js.map +1 -0
  33. package/dist/gc/gcSweepReadyUsageDetection.d.ts.map +1 -0
  34. package/dist/{gcSweepReadyUsageDetection.js → gc/gcSweepReadyUsageDetection.js} +2 -2
  35. package/dist/gc/gcSweepReadyUsageDetection.js.map +1 -0
  36. package/dist/gc/gcUnreferencedStateTracker.d.ts +34 -0
  37. package/dist/gc/gcUnreferencedStateTracker.d.ts.map +1 -0
  38. package/dist/gc/gcUnreferencedStateTracker.js +94 -0
  39. package/dist/gc/gcUnreferencedStateTracker.js.map +1 -0
  40. package/dist/gc/index.d.ts +11 -0
  41. package/dist/gc/index.d.ts.map +1 -0
  42. package/dist/gc/index.js +40 -0
  43. package/dist/gc/index.js.map +1 -0
  44. package/dist/index.d.ts +2 -5
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +6 -9
  47. package/dist/index.js.map +1 -1
  48. package/dist/opLifecycle/batchManager.d.ts +2 -13
  49. package/dist/opLifecycle/batchManager.d.ts.map +1 -1
  50. package/dist/opLifecycle/batchManager.js +7 -36
  51. package/dist/opLifecycle/batchManager.js.map +1 -1
  52. package/dist/opLifecycle/definitions.d.ts +4 -0
  53. package/dist/opLifecycle/definitions.d.ts.map +1 -1
  54. package/dist/opLifecycle/definitions.js.map +1 -1
  55. package/dist/opLifecycle/opCompressor.d.ts.map +1 -1
  56. package/dist/opLifecycle/opCompressor.js +1 -0
  57. package/dist/opLifecycle/opCompressor.js.map +1 -1
  58. package/dist/opLifecycle/opSplitter.d.ts +1 -1
  59. package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
  60. package/dist/opLifecycle/opSplitter.js +20 -12
  61. package/dist/opLifecycle/opSplitter.js.map +1 -1
  62. package/dist/opLifecycle/outbox.d.ts +19 -3
  63. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  64. package/dist/opLifecycle/outbox.js +59 -28
  65. package/dist/opLifecycle/outbox.js.map +1 -1
  66. package/dist/packageVersion.d.ts +1 -1
  67. package/dist/packageVersion.js +1 -1
  68. package/dist/packageVersion.js.map +1 -1
  69. package/dist/pendingStateManager.d.ts +1 -2
  70. package/dist/pendingStateManager.d.ts.map +1 -1
  71. package/dist/pendingStateManager.js +14 -9
  72. package/dist/pendingStateManager.js.map +1 -1
  73. package/dist/summary/index.d.ts +17 -0
  74. package/dist/summary/index.d.ts.map +1 -0
  75. package/dist/summary/index.js +47 -0
  76. package/dist/summary/index.js.map +1 -0
  77. package/dist/summary/orderedClientElection.d.ts.map +1 -0
  78. package/dist/summary/orderedClientElection.js.map +1 -0
  79. package/dist/summary/runWhileConnectedCoordinator.d.ts.map +1 -0
  80. package/dist/summary/runWhileConnectedCoordinator.js.map +1 -0
  81. package/{lib → dist/summary}/runningSummarizer.d.ts +19 -18
  82. package/dist/summary/runningSummarizer.d.ts.map +1 -0
  83. package/dist/{runningSummarizer.js → summary/runningSummarizer.js} +158 -56
  84. package/dist/summary/runningSummarizer.js.map +1 -0
  85. package/dist/{summarizer.d.ts → summary/summarizer.d.ts} +2 -4
  86. package/dist/summary/summarizer.d.ts.map +1 -0
  87. package/dist/{summarizer.js → summary/summarizer.js} +1 -61
  88. package/dist/summary/summarizer.js.map +1 -0
  89. package/dist/summary/summarizerClientElection.d.ts.map +1 -0
  90. package/dist/summary/summarizerClientElection.js.map +1 -0
  91. package/dist/summary/summarizerHandle.d.ts.map +1 -0
  92. package/dist/summary/summarizerHandle.js.map +1 -0
  93. package/dist/{summarizerHeuristics.d.ts → summary/summarizerHeuristics.d.ts} +1 -1
  94. package/dist/summary/summarizerHeuristics.d.ts.map +1 -0
  95. package/dist/summary/summarizerHeuristics.js.map +1 -0
  96. package/{lib → dist/summary}/summarizerTypes.d.ts +1 -1
  97. package/dist/summary/summarizerTypes.d.ts.map +1 -0
  98. package/dist/summary/summarizerTypes.js.map +1 -0
  99. package/dist/summary/summaryCollection.d.ts.map +1 -0
  100. package/dist/summary/summaryCollection.js.map +1 -0
  101. package/{lib → dist/summary}/summaryFormat.d.ts +1 -43
  102. package/dist/summary/summaryFormat.d.ts.map +1 -0
  103. package/dist/{summaryFormat.js → summary/summaryFormat.js} +1 -10
  104. package/dist/summary/summaryFormat.js.map +1 -0
  105. package/dist/summary/summaryGenerator.d.ts.map +1 -0
  106. package/dist/{summaryGenerator.js → summary/summaryGenerator.js} +1 -2
  107. package/dist/summary/summaryGenerator.js.map +1 -0
  108. package/dist/{summaryManager.d.ts → summary/summaryManager.d.ts} +1 -1
  109. package/dist/summary/summaryManager.d.ts.map +1 -0
  110. package/dist/summary/summaryManager.js.map +1 -0
  111. package/lib/blobManager.d.ts +6 -0
  112. package/lib/blobManager.d.ts.map +1 -1
  113. package/lib/blobManager.js +28 -3
  114. package/lib/blobManager.js.map +1 -1
  115. package/lib/containerRuntime.d.ts +17 -15
  116. package/lib/containerRuntime.d.ts.map +1 -1
  117. package/lib/containerRuntime.js +127 -90
  118. package/lib/containerRuntime.js.map +1 -1
  119. package/lib/dataStoreContext.d.ts +21 -12
  120. package/lib/dataStoreContext.d.ts.map +1 -1
  121. package/lib/dataStoreContext.js +64 -38
  122. package/lib/dataStoreContext.js.map +1 -1
  123. package/lib/dataStores.d.ts +9 -10
  124. package/lib/dataStores.d.ts.map +1 -1
  125. package/lib/dataStores.js +33 -40
  126. package/lib/dataStores.js.map +1 -1
  127. package/lib/{garbageCollection.d.ts → gc/garbageCollection.d.ts} +5 -200
  128. package/lib/gc/garbageCollection.d.ts.map +1 -0
  129. package/lib/{garbageCollection.js → gc/garbageCollection.js} +44 -319
  130. package/lib/gc/garbageCollection.js.map +1 -0
  131. package/lib/gc/gcDefinitions.d.ts +189 -0
  132. package/lib/gc/gcDefinitions.d.ts.map +1 -0
  133. package/lib/{garbageCollectionConstants.js → gc/gcDefinitions.js} +23 -1
  134. package/lib/gc/gcDefinitions.js.map +1 -0
  135. package/{dist/garbageCollectionHelpers.d.ts → lib/gc/gcHelpers.d.ts} +5 -1
  136. package/lib/gc/gcHelpers.d.ts.map +1 -0
  137. package/lib/{garbageCollectionHelpers.js → gc/gcHelpers.js} +20 -2
  138. package/lib/gc/gcHelpers.js.map +1 -0
  139. package/lib/gc/gcSummaryStateTracker.d.ts +86 -0
  140. package/lib/gc/gcSummaryStateTracker.d.ts.map +1 -0
  141. package/lib/gc/gcSummaryStateTracker.js +242 -0
  142. package/lib/gc/gcSummaryStateTracker.js.map +1 -0
  143. package/lib/gc/gcSweepReadyUsageDetection.d.ts.map +1 -0
  144. package/lib/{gcSweepReadyUsageDetection.js → gc/gcSweepReadyUsageDetection.js} +1 -1
  145. package/lib/gc/gcSweepReadyUsageDetection.js.map +1 -0
  146. package/lib/gc/gcUnreferencedStateTracker.d.ts +34 -0
  147. package/lib/gc/gcUnreferencedStateTracker.d.ts.map +1 -0
  148. package/lib/gc/gcUnreferencedStateTracker.js +90 -0
  149. package/lib/gc/gcUnreferencedStateTracker.js.map +1 -0
  150. package/lib/gc/index.d.ts +11 -0
  151. package/lib/gc/index.d.ts.map +1 -0
  152. package/lib/gc/index.js +11 -0
  153. package/lib/gc/index.js.map +1 -0
  154. package/lib/index.d.ts +2 -5
  155. package/lib/index.d.ts.map +1 -1
  156. package/lib/index.js +1 -4
  157. package/lib/index.js.map +1 -1
  158. package/lib/opLifecycle/batchManager.d.ts +2 -13
  159. package/lib/opLifecycle/batchManager.d.ts.map +1 -1
  160. package/lib/opLifecycle/batchManager.js +7 -36
  161. package/lib/opLifecycle/batchManager.js.map +1 -1
  162. package/lib/opLifecycle/definitions.d.ts +4 -0
  163. package/lib/opLifecycle/definitions.d.ts.map +1 -1
  164. package/lib/opLifecycle/definitions.js.map +1 -1
  165. package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
  166. package/lib/opLifecycle/opCompressor.js +1 -0
  167. package/lib/opLifecycle/opCompressor.js.map +1 -1
  168. package/lib/opLifecycle/opSplitter.d.ts +1 -1
  169. package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
  170. package/lib/opLifecycle/opSplitter.js +20 -12
  171. package/lib/opLifecycle/opSplitter.js.map +1 -1
  172. package/lib/opLifecycle/outbox.d.ts +19 -3
  173. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  174. package/lib/opLifecycle/outbox.js +60 -29
  175. package/lib/opLifecycle/outbox.js.map +1 -1
  176. package/lib/packageVersion.d.ts +1 -1
  177. package/lib/packageVersion.js +1 -1
  178. package/lib/packageVersion.js.map +1 -1
  179. package/lib/pendingStateManager.d.ts +1 -2
  180. package/lib/pendingStateManager.d.ts.map +1 -1
  181. package/lib/pendingStateManager.js +14 -9
  182. package/lib/pendingStateManager.js.map +1 -1
  183. package/lib/summary/index.d.ts +17 -0
  184. package/lib/summary/index.d.ts.map +1 -0
  185. package/lib/summary/index.js +16 -0
  186. package/lib/summary/index.js.map +1 -0
  187. package/lib/summary/orderedClientElection.d.ts.map +1 -0
  188. package/lib/summary/orderedClientElection.js.map +1 -0
  189. package/lib/summary/runWhileConnectedCoordinator.d.ts.map +1 -0
  190. package/lib/summary/runWhileConnectedCoordinator.js.map +1 -0
  191. package/{dist → lib/summary}/runningSummarizer.d.ts +19 -18
  192. package/lib/summary/runningSummarizer.d.ts.map +1 -0
  193. package/lib/{runningSummarizer.js → summary/runningSummarizer.js} +159 -57
  194. package/lib/summary/runningSummarizer.js.map +1 -0
  195. package/lib/{summarizer.d.ts → summary/summarizer.d.ts} +2 -4
  196. package/lib/summary/summarizer.d.ts.map +1 -0
  197. package/lib/{summarizer.js → summary/summarizer.js} +3 -63
  198. package/lib/summary/summarizer.js.map +1 -0
  199. package/lib/summary/summarizerClientElection.d.ts.map +1 -0
  200. package/lib/summary/summarizerClientElection.js.map +1 -0
  201. package/lib/summary/summarizerHandle.d.ts.map +1 -0
  202. package/lib/summary/summarizerHandle.js.map +1 -0
  203. package/lib/{summarizerHeuristics.d.ts → summary/summarizerHeuristics.d.ts} +1 -1
  204. package/lib/summary/summarizerHeuristics.d.ts.map +1 -0
  205. package/lib/summary/summarizerHeuristics.js.map +1 -0
  206. package/{dist → lib/summary}/summarizerTypes.d.ts +1 -1
  207. package/lib/summary/summarizerTypes.d.ts.map +1 -0
  208. package/lib/summary/summarizerTypes.js.map +1 -0
  209. package/lib/summary/summaryCollection.d.ts.map +1 -0
  210. package/lib/summary/summaryCollection.js.map +1 -0
  211. package/{dist → lib/summary}/summaryFormat.d.ts +1 -43
  212. package/lib/summary/summaryFormat.d.ts.map +1 -0
  213. package/lib/{summaryFormat.js → summary/summaryFormat.js} +0 -8
  214. package/lib/summary/summaryFormat.js.map +1 -0
  215. package/lib/summary/summaryGenerator.d.ts.map +1 -0
  216. package/lib/{summaryGenerator.js → summary/summaryGenerator.js} +1 -2
  217. package/lib/summary/summaryGenerator.js.map +1 -0
  218. package/lib/{summaryManager.d.ts → summary/summaryManager.d.ts} +1 -1
  219. package/lib/summary/summaryManager.d.ts.map +1 -0
  220. package/lib/summary/summaryManager.js.map +1 -0
  221. package/package.json +125 -122
  222. package/src/blobManager.ts +33 -3
  223. package/src/containerRuntime.ts +178 -106
  224. package/src/dataStoreContext.ts +90 -49
  225. package/src/dataStores.ts +44 -51
  226. package/{garbageCollection.md → src/gc/garbageCollection.md} +2 -2
  227. package/src/{garbageCollection.ts → gc/garbageCollection.ts} +90 -560
  228. package/src/gc/gcDefinitions.ts +244 -0
  229. package/src/{garbageCollectionHelpers.ts → gc/gcHelpers.ts} +26 -1
  230. package/src/gc/gcSummaryStateTracker.ts +339 -0
  231. package/src/{gcSweepReadyUsageDetection.ts → gc/gcSweepReadyUsageDetection.ts} +1 -1
  232. package/src/gc/gcUnreferencedStateTracker.ts +114 -0
  233. package/src/gc/index.ts +40 -0
  234. package/src/index.ts +10 -14
  235. package/src/opLifecycle/batchManager.ts +7 -54
  236. package/src/opLifecycle/definitions.ts +4 -0
  237. package/src/opLifecycle/opCompressor.ts +1 -0
  238. package/src/opLifecycle/opSplitter.ts +33 -14
  239. package/src/opLifecycle/outbox.ts +84 -38
  240. package/src/packageVersion.ts +1 -1
  241. package/src/pendingStateManager.ts +26 -14
  242. package/src/summary/index.ts +99 -0
  243. package/src/{runningSummarizer.ts → summary/runningSummarizer.ts} +279 -139
  244. package/src/{summarizer.ts → summary/summarizer.ts} +5 -76
  245. package/src/{summarizerHeuristics.ts → summary/summarizerHeuristics.ts} +1 -1
  246. package/src/{summarizerTypes.ts → summary/summarizerTypes.ts} +1 -1
  247. package/src/{summaryFormat.ts → summary/summaryFormat.ts} +1 -53
  248. package/src/{summaryGenerator.ts → summary/summaryGenerator.ts} +9 -9
  249. package/src/{summaryManager.ts → summary/summaryManager.ts} +1 -1
  250. package/dist/garbageCollection.d.ts.map +0 -1
  251. package/dist/garbageCollection.js.map +0 -1
  252. package/dist/garbageCollectionConstants.d.ts +0 -26
  253. package/dist/garbageCollectionConstants.d.ts.map +0 -1
  254. package/dist/garbageCollectionConstants.js.map +0 -1
  255. package/dist/garbageCollectionHelpers.d.ts.map +0 -1
  256. package/dist/garbageCollectionHelpers.js.map +0 -1
  257. package/dist/gcSweepReadyUsageDetection.d.ts.map +0 -1
  258. package/dist/gcSweepReadyUsageDetection.js.map +0 -1
  259. package/dist/orderedClientElection.d.ts.map +0 -1
  260. package/dist/orderedClientElection.js.map +0 -1
  261. package/dist/runWhileConnectedCoordinator.d.ts.map +0 -1
  262. package/dist/runWhileConnectedCoordinator.js.map +0 -1
  263. package/dist/runningSummarizer.d.ts.map +0 -1
  264. package/dist/runningSummarizer.js.map +0 -1
  265. package/dist/summarizer.d.ts.map +0 -1
  266. package/dist/summarizer.js.map +0 -1
  267. package/dist/summarizerClientElection.d.ts.map +0 -1
  268. package/dist/summarizerClientElection.js.map +0 -1
  269. package/dist/summarizerHandle.d.ts.map +0 -1
  270. package/dist/summarizerHandle.js.map +0 -1
  271. package/dist/summarizerHeuristics.d.ts.map +0 -1
  272. package/dist/summarizerHeuristics.js.map +0 -1
  273. package/dist/summarizerTypes.d.ts.map +0 -1
  274. package/dist/summarizerTypes.js.map +0 -1
  275. package/dist/summaryCollection.d.ts.map +0 -1
  276. package/dist/summaryCollection.js.map +0 -1
  277. package/dist/summaryFormat.d.ts.map +0 -1
  278. package/dist/summaryFormat.js.map +0 -1
  279. package/dist/summaryGenerator.d.ts.map +0 -1
  280. package/dist/summaryGenerator.js.map +0 -1
  281. package/dist/summaryManager.d.ts.map +0 -1
  282. package/dist/summaryManager.js.map +0 -1
  283. package/lib/garbageCollection.d.ts.map +0 -1
  284. package/lib/garbageCollection.js.map +0 -1
  285. package/lib/garbageCollectionConstants.d.ts +0 -26
  286. package/lib/garbageCollectionConstants.d.ts.map +0 -1
  287. package/lib/garbageCollectionConstants.js.map +0 -1
  288. package/lib/garbageCollectionHelpers.d.ts.map +0 -1
  289. package/lib/garbageCollectionHelpers.js.map +0 -1
  290. package/lib/gcSweepReadyUsageDetection.d.ts.map +0 -1
  291. package/lib/gcSweepReadyUsageDetection.js.map +0 -1
  292. package/lib/orderedClientElection.d.ts.map +0 -1
  293. package/lib/orderedClientElection.js.map +0 -1
  294. package/lib/runWhileConnectedCoordinator.d.ts.map +0 -1
  295. package/lib/runWhileConnectedCoordinator.js.map +0 -1
  296. package/lib/runningSummarizer.d.ts.map +0 -1
  297. package/lib/runningSummarizer.js.map +0 -1
  298. package/lib/summarizer.d.ts.map +0 -1
  299. package/lib/summarizer.js.map +0 -1
  300. package/lib/summarizerClientElection.d.ts.map +0 -1
  301. package/lib/summarizerClientElection.js.map +0 -1
  302. package/lib/summarizerHandle.d.ts.map +0 -1
  303. package/lib/summarizerHandle.js.map +0 -1
  304. package/lib/summarizerHeuristics.d.ts.map +0 -1
  305. package/lib/summarizerHeuristics.js.map +0 -1
  306. package/lib/summarizerTypes.d.ts.map +0 -1
  307. package/lib/summarizerTypes.js.map +0 -1
  308. package/lib/summaryCollection.d.ts.map +0 -1
  309. package/lib/summaryCollection.js.map +0 -1
  310. package/lib/summaryFormat.d.ts.map +0 -1
  311. package/lib/summaryFormat.js.map +0 -1
  312. package/lib/summaryGenerator.d.ts.map +0 -1
  313. package/lib/summaryGenerator.js.map +0 -1
  314. package/lib/summaryManager.d.ts.map +0 -1
  315. package/lib/summaryManager.js.map +0 -1
  316. package/src/garbageCollectionConstants.ts +0 -44
  317. /package/dist/{gcSweepReadyUsageDetection.d.ts → gc/gcSweepReadyUsageDetection.d.ts} +0 -0
  318. /package/dist/{orderedClientElection.d.ts → summary/orderedClientElection.d.ts} +0 -0
  319. /package/dist/{orderedClientElection.js → summary/orderedClientElection.js} +0 -0
  320. /package/dist/{runWhileConnectedCoordinator.d.ts → summary/runWhileConnectedCoordinator.d.ts} +0 -0
  321. /package/dist/{runWhileConnectedCoordinator.js → summary/runWhileConnectedCoordinator.js} +0 -0
  322. /package/dist/{summarizerClientElection.d.ts → summary/summarizerClientElection.d.ts} +0 -0
  323. /package/dist/{summarizerClientElection.js → summary/summarizerClientElection.js} +0 -0
  324. /package/dist/{summarizerHandle.d.ts → summary/summarizerHandle.d.ts} +0 -0
  325. /package/dist/{summarizerHandle.js → summary/summarizerHandle.js} +0 -0
  326. /package/dist/{summarizerHeuristics.js → summary/summarizerHeuristics.js} +0 -0
  327. /package/dist/{summarizerTypes.js → summary/summarizerTypes.js} +0 -0
  328. /package/dist/{summaryCollection.d.ts → summary/summaryCollection.d.ts} +0 -0
  329. /package/dist/{summaryCollection.js → summary/summaryCollection.js} +0 -0
  330. /package/dist/{summaryGenerator.d.ts → summary/summaryGenerator.d.ts} +0 -0
  331. /package/dist/{summaryManager.js → summary/summaryManager.js} +0 -0
  332. /package/lib/{gcSweepReadyUsageDetection.d.ts → gc/gcSweepReadyUsageDetection.d.ts} +0 -0
  333. /package/lib/{orderedClientElection.d.ts → summary/orderedClientElection.d.ts} +0 -0
  334. /package/lib/{orderedClientElection.js → summary/orderedClientElection.js} +0 -0
  335. /package/lib/{runWhileConnectedCoordinator.d.ts → summary/runWhileConnectedCoordinator.d.ts} +0 -0
  336. /package/lib/{runWhileConnectedCoordinator.js → summary/runWhileConnectedCoordinator.js} +0 -0
  337. /package/lib/{summarizerClientElection.d.ts → summary/summarizerClientElection.d.ts} +0 -0
  338. /package/lib/{summarizerClientElection.js → summary/summarizerClientElection.js} +0 -0
  339. /package/lib/{summarizerHandle.d.ts → summary/summarizerHandle.d.ts} +0 -0
  340. /package/lib/{summarizerHandle.js → summary/summarizerHandle.js} +0 -0
  341. /package/lib/{summarizerHeuristics.js → summary/summarizerHeuristics.js} +0 -0
  342. /package/lib/{summarizerTypes.js → summary/summarizerTypes.js} +0 -0
  343. /package/lib/{summaryCollection.d.ts → summary/summaryCollection.d.ts} +0 -0
  344. /package/lib/{summaryCollection.js → summary/summaryCollection.js} +0 -0
  345. /package/lib/{summaryGenerator.d.ts → summary/summaryGenerator.d.ts} +0 -0
  346. /package/lib/{summaryManager.js → summary/summaryManager.js} +0 -0
  347. /package/src/{orderedClientElection.ts → summary/orderedClientElection.ts} +0 -0
  348. /package/src/{runWhileConnectedCoordinator.ts → summary/runWhileConnectedCoordinator.ts} +0 -0
  349. /package/src/{summarizerClientElection.ts → summary/summarizerClientElection.ts} +0 -0
  350. /package/src/{summarizerHandle.ts → summary/summarizerHandle.ts} +0 -0
  351. /package/src/{summaryCollection.ts → summary/summaryCollection.ts} +0 -0
@@ -0,0 +1,86 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IGarbageCollectionSnapshotData, IGarbageCollectionState, ISummarizeResult } from "@fluidframework/runtime-definitions";
6
+ import { ReadAndParseBlob, RefreshSummaryResult } from "@fluidframework/runtime-utils";
7
+ import { MonitoringContext } from "@fluidframework/telemetry-utils";
8
+ import { GCVersion } from "./gcDefinitions";
9
+ /**
10
+ * Encapsulates the garbage collection state that is tracked across summaries.
11
+ * It maintains the GC state as per the latest summary in by the server. It updates state when a summary tracked by this
12
+ * client is acked by the server or from a snapshot is downloaded from the server.
13
+ * On summarize, it decides whether to write new state or re-use previous summary's state.
14
+ */
15
+ export declare class GCSummaryStateTracker {
16
+ private readonly shouldRunGC;
17
+ private readonly trackGCState;
18
+ private readonly tombstoneMode;
19
+ private readonly mc;
20
+ readonly currentGCVersion: GCVersion;
21
+ private latestSummaryGCVersion;
22
+ private latestSummaryData;
23
+ private pendingSummaryData;
24
+ private wasGCRunInLatestSummary;
25
+ constructor(shouldRunGC: boolean, trackGCState: boolean, tombstoneMode: boolean, mc: MonitoringContext, wasGCRunInBaseSnapshot: boolean, gcVersionInBaseSnapshot: GCVersion | undefined);
26
+ /**
27
+ * Tells whether the GC state needs to be reset. This can happen under 3 conditions:
28
+ *
29
+ * 1. The base snapshot contains GC state but GC is disabled. This will happen the first time GC is disabled after
30
+ * it was enabled before. GC state needs to be removed from summary and all nodes should be marked referenced.
31
+ *
32
+ * 2. The base snapshot does not have GC state but GC is enabled. This will happen the very first time GC runs on
33
+ * a document and the first time GC is enabled after is was disabled before.
34
+ *
35
+ * 3. GC is enabled and the latest summary state is refreshed from a snapshot that had GC disabled and vice-versa.
36
+ *
37
+ * Note that the state will be reset only once for the first summary generated after this returns true. After that,
38
+ * this will return false.
39
+ */
40
+ doesGCStateNeedReset(): boolean;
41
+ /**
42
+ * Tells whether the GC state needs to be reset in the next summary. We need to do this if:
43
+ *
44
+ * 1. GC was enabled and is now disabled. The GC state needs to be removed and everything becomes referenced.
45
+ *
46
+ * 2. GC was disabled and is now enabled. The GC state needs to be regenerated and added to summary.
47
+ *
48
+ * 3. GC is enabled and the latest summary state is refreshed from a snapshot that had GC disabled and vice-versa.
49
+ *
50
+ * 4. The GC version in the latest summary is different from the current GC version. This can happen if:
51
+ *
52
+ * 4.1. The summary this client loaded with has data from a different GC version.
53
+ *
54
+ * 4.2. This client's latest summary was updated from a snapshot that has a different GC version.
55
+ */
56
+ doesSummaryStateNeedReset(): boolean;
57
+ /**
58
+ * Summarizes three component of the GC data - GC state, tombstones and deleted nodes.
59
+ * It does incremental summary, i.e., it writes summary tree / summary blob only for the component that changed.
60
+ * For components that did not change, a summary handle is returned that points to the previous successful summary.
61
+ * If none of the components changed, it returns a summary handle for the entire GC data.
62
+ */
63
+ summarize(fullTree: boolean, trackState: boolean, gcState: IGarbageCollectionState, deletedNodes: Set<string>, tombstones: string[]): ISummarizeResult | undefined;
64
+ /**
65
+ * Builds the GC summary tree which contains GC state, deleted nodes and tombstones.
66
+ * If trackState is false, all of GC state, deleted nodes and tombstones are written as summary blobs.
67
+ * If trackState is true, only states that changed are written. Rest are written as handles.
68
+ * @param serializedGCState - The GC state serialized as string.
69
+ * @param serializedTombstones - The tombstone state serialized as string.
70
+ * @param serializedDeletedNodes - Deleted nodes serialized as string.
71
+ * @param trackState - Whether we are tracking GC state across summaries.
72
+ * @returns the GC summary tree.
73
+ */
74
+ private buildGCSummaryTree;
75
+ /**
76
+ * Called to refresh the latest summary state. This happens when either a pending summary is acked or a snapshot
77
+ * is downloaded and should be used to update the state.
78
+ */
79
+ refreshLatestSummary(proposalHandle: string | undefined, result: RefreshSummaryResult, readAndParseBlob: ReadAndParseBlob): Promise<IGarbageCollectionSnapshotData | undefined>;
80
+ /**
81
+ * Update state from the given snapshot data. This is done during load and during refreshing state from a snapshot.
82
+ * @param gcSnapshotData - The GC snapshot data to update state from.
83
+ */
84
+ updateStateFromSnapshotData(gcSnapshotData: IGarbageCollectionSnapshotData | undefined): void;
85
+ }
86
+ //# sourceMappingURL=gcSummaryStateTracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gcSummaryStateTracker.d.ts","sourceRoot":"","sources":["../../src/gc/gcSummaryStateTracker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAKN,8BAA8B,EAC9B,uBAAuB,EACvB,gBAAgB,EAEhB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAEN,gBAAgB,EAChB,oBAAoB,EAEpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAEpE,OAAO,EAEN,SAAS,EAGT,MAAM,iBAAiB,CAAC;AAYzB;;;;;GAKG;AACH,qBAAa,qBAAqB;IAgBhC,OAAO,CAAC,QAAQ,CAAC,WAAW;IAE5B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAE7B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,EAAE;IAnBpB,SAAgB,gBAAgB,EAAE,SAAS,CAAC;IAE5C,OAAO,CAAC,sBAAsB,CAAY;IAG1C,OAAO,CAAC,iBAAiB,CAAqC;IAE9D,OAAO,CAAC,kBAAkB,CAAqC;IAG/D,OAAO,CAAC,uBAAuB,CAAU;gBAIvB,WAAW,EAAE,OAAO,EAEpB,YAAY,EAAE,OAAO,EAErB,aAAa,EAAE,OAAO,EACtB,EAAE,EAAE,iBAAiB,EAEtC,sBAAsB,EAAE,OAAO,EAE/B,uBAAuB,EAAE,SAAS,GAAG,SAAS;IAa/C;;;;;;;;;;;;;OAaG;IACI,oBAAoB,IAAI,OAAO;IAItC;;;;;;;;;;;;;;OAcG;IACI,yBAAyB,IAAI,OAAO;IAO3C;;;;;OAKG;IACI,SAAS,CACf,QAAQ,EAAE,OAAO,EACjB,UAAU,EAAE,OAAO,EACnB,OAAO,EAAE,uBAAuB,EAChC,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,EACzB,UAAU,EAAE,MAAM,EAAE,GAClB,gBAAgB,GAAG,SAAS;IAiE/B;;;;;;;;;OASG;IACH,OAAO,CAAC,kBAAkB;IAsD1B;;;OAGG;IACU,oBAAoB,CAChC,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,MAAM,EAAE,oBAAoB,EAC5B,gBAAgB,EAAE,gBAAgB,GAChC,OAAO,CAAC,8BAA8B,GAAG,SAAS,CAAC;IA2CtD;;;OAGG;IACI,2BAA2B,CAAC,cAAc,EAAE,8BAA8B,GAAG,SAAS;CAgB7F"}
@@ -0,0 +1,246 @@
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.GCSummaryStateTracker = void 0;
8
+ const garbage_collector_1 = require("@fluidframework/garbage-collector");
9
+ const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
10
+ const runtime_definitions_1 = require("@fluidframework/runtime-definitions");
11
+ const runtime_utils_1 = require("@fluidframework/runtime-utils");
12
+ const summary_1 = require("../summary");
13
+ const gcDefinitions_1 = require("./gcDefinitions");
14
+ const gcHelpers_1 = require("./gcHelpers");
15
+ /**
16
+ * Encapsulates the garbage collection state that is tracked across summaries.
17
+ * It maintains the GC state as per the latest summary in by the server. It updates state when a summary tracked by this
18
+ * client is acked by the server or from a snapshot is downloaded from the server.
19
+ * On summarize, it decides whether to write new state or re-use previous summary's state.
20
+ */
21
+ class GCSummaryStateTracker {
22
+ constructor(
23
+ // Tells whether GC should run or not.
24
+ shouldRunGC,
25
+ // Tells whether GC state should be tracked across summaries or not.
26
+ trackGCState,
27
+ // Tells whether tombstone mode is enabled or not.
28
+ tombstoneMode, mc,
29
+ // Tells whether GC was run in the base snapshot this container loaded from.
30
+ wasGCRunInBaseSnapshot,
31
+ // The GC version in the base snapshot this container loaded from.
32
+ gcVersionInBaseSnapshot) {
33
+ this.shouldRunGC = shouldRunGC;
34
+ this.trackGCState = trackGCState;
35
+ this.tombstoneMode = tombstoneMode;
36
+ this.mc = mc;
37
+ this.wasGCRunInLatestSummary = wasGCRunInBaseSnapshot;
38
+ // If version upgrade is not enabled, fall back to the stable GC version.
39
+ this.currentGCVersion =
40
+ this.mc.config.getBoolean(gcDefinitions_1.gcVersionUpgradeToV2Key) === true
41
+ ? gcDefinitions_1.currentGCVersion
42
+ : gcDefinitions_1.stableGCVersion;
43
+ // For existing document, the latest summary is the one that we loaded from. So, use its GC version as the
44
+ // latest tracked GC version. For new documents, we will be writing the first summary with the current version.
45
+ this.latestSummaryGCVersion = gcVersionInBaseSnapshot !== null && gcVersionInBaseSnapshot !== void 0 ? gcVersionInBaseSnapshot : this.currentGCVersion;
46
+ }
47
+ /**
48
+ * Tells whether the GC state needs to be reset. This can happen under 3 conditions:
49
+ *
50
+ * 1. The base snapshot contains GC state but GC is disabled. This will happen the first time GC is disabled after
51
+ * it was enabled before. GC state needs to be removed from summary and all nodes should be marked referenced.
52
+ *
53
+ * 2. The base snapshot does not have GC state but GC is enabled. This will happen the very first time GC runs on
54
+ * a document and the first time GC is enabled after is was disabled before.
55
+ *
56
+ * 3. GC is enabled and the latest summary state is refreshed from a snapshot that had GC disabled and vice-versa.
57
+ *
58
+ * Note that the state will be reset only once for the first summary generated after this returns true. After that,
59
+ * this will return false.
60
+ */
61
+ doesGCStateNeedReset() {
62
+ return this.wasGCRunInLatestSummary !== this.shouldRunGC;
63
+ }
64
+ /**
65
+ * Tells whether the GC state needs to be reset in the next summary. We need to do this if:
66
+ *
67
+ * 1. GC was enabled and is now disabled. The GC state needs to be removed and everything becomes referenced.
68
+ *
69
+ * 2. GC was disabled and is now enabled. The GC state needs to be regenerated and added to summary.
70
+ *
71
+ * 3. GC is enabled and the latest summary state is refreshed from a snapshot that had GC disabled and vice-versa.
72
+ *
73
+ * 4. The GC version in the latest summary is different from the current GC version. This can happen if:
74
+ *
75
+ * 4.1. The summary this client loaded with has data from a different GC version.
76
+ *
77
+ * 4.2. This client's latest summary was updated from a snapshot that has a different GC version.
78
+ */
79
+ doesSummaryStateNeedReset() {
80
+ return (this.doesGCStateNeedReset() ||
81
+ (this.shouldRunGC && this.latestSummaryGCVersion !== this.currentGCVersion));
82
+ }
83
+ /**
84
+ * Summarizes three component of the GC data - GC state, tombstones and deleted nodes.
85
+ * It does incremental summary, i.e., it writes summary tree / summary blob only for the component that changed.
86
+ * For components that did not change, a summary handle is returned that points to the previous successful summary.
87
+ * If none of the components changed, it returns a summary handle for the entire GC data.
88
+ */
89
+ summarize(fullTree, trackState, gcState, deletedNodes, tombstones) {
90
+ if (!this.shouldRunGC) {
91
+ return;
92
+ }
93
+ const serializedGCState = JSON.stringify((0, gcHelpers_1.generateSortedGCState)(gcState));
94
+ // Serialize and write deleted nodes, if any. This is done irrespective of whether sweep is enabled or not so
95
+ // to identify deleted nodes' usage.
96
+ const serializedDeletedNodes = deletedNodes.size > 0 ? JSON.stringify(Array.from(deletedNodes).sort()) : undefined;
97
+ // If running in tombstone mode, serialize and write tombstones, if any.
98
+ const serializedTombstones = this.tombstoneMode
99
+ ? tombstones.length > 0
100
+ ? JSON.stringify(tombstones.sort())
101
+ : undefined
102
+ : undefined;
103
+ /**
104
+ * Incremental summary of GC data - If none of GC state, deleted nodes or tombstones changed since last summary,
105
+ * write summary handle instead of summary tree for GC.
106
+ * Otherwise, write the GC summary tree. In the tree, for each of these that changed, write a summary blob and
107
+ * for each of these that did not change, write a summary handle.
108
+ */
109
+ if (this.trackGCState) {
110
+ this.pendingSummaryData = {
111
+ serializedGCState,
112
+ serializedTombstones,
113
+ serializedDeletedNodes,
114
+ };
115
+ if (trackState && !fullTree && this.latestSummaryData !== undefined) {
116
+ // If nothing changed since last summary, send a summary handle for the entire GC data.
117
+ if (this.latestSummaryData.serializedGCState === serializedGCState &&
118
+ this.latestSummaryData.serializedTombstones === serializedTombstones) {
119
+ const stats = (0, runtime_utils_1.mergeStats)();
120
+ stats.handleNodeCount++;
121
+ return {
122
+ summary: {
123
+ type: protocol_definitions_1.SummaryType.Handle,
124
+ handle: `/${runtime_definitions_1.gcTreeKey}`,
125
+ handleType: protocol_definitions_1.SummaryType.Tree,
126
+ },
127
+ stats,
128
+ };
129
+ }
130
+ // If some state changed, build a GC summary tree.
131
+ return this.buildGCSummaryTree(serializedGCState, serializedTombstones, serializedDeletedNodes, true /* trackState */);
132
+ }
133
+ }
134
+ // If not tracking GC state, build a GC summary tree without any summary handles.
135
+ return this.buildGCSummaryTree(serializedGCState, serializedTombstones, serializedDeletedNodes, false /* trackState */);
136
+ }
137
+ /**
138
+ * Builds the GC summary tree which contains GC state, deleted nodes and tombstones.
139
+ * If trackState is false, all of GC state, deleted nodes and tombstones are written as summary blobs.
140
+ * If trackState is true, only states that changed are written. Rest are written as handles.
141
+ * @param serializedGCState - The GC state serialized as string.
142
+ * @param serializedTombstones - The tombstone state serialized as string.
143
+ * @param serializedDeletedNodes - Deleted nodes serialized as string.
144
+ * @param trackState - Whether we are tracking GC state across summaries.
145
+ * @returns the GC summary tree.
146
+ */
147
+ buildGCSummaryTree(serializedGCState, serializedTombstones, serializedDeletedNodes, trackState) {
148
+ var _a, _b, _c;
149
+ const gcStateBlobKey = `${runtime_definitions_1.gcBlobPrefix}_root`;
150
+ const builder = new runtime_utils_1.SummaryTreeBuilder();
151
+ // If the GC state hasn't changed, write a summary handle, else write a summary blob for it.
152
+ if (((_a = this.latestSummaryData) === null || _a === void 0 ? void 0 : _a.serializedGCState) === serializedGCState && trackState) {
153
+ builder.addHandle(gcStateBlobKey, protocol_definitions_1.SummaryType.Blob, `/${runtime_definitions_1.gcTreeKey}/${gcStateBlobKey}`);
154
+ }
155
+ else {
156
+ builder.addBlob(gcStateBlobKey, serializedGCState);
157
+ }
158
+ // If tombstones exist, write a summary handle if it hasn't changed. If it has changed, write a
159
+ // summary blob.
160
+ if (serializedTombstones !== undefined) {
161
+ if (((_b = this.latestSummaryData) === null || _b === void 0 ? void 0 : _b.serializedTombstones) === serializedTombstones &&
162
+ trackState) {
163
+ builder.addHandle(runtime_definitions_1.gcTombstoneBlobKey, protocol_definitions_1.SummaryType.Blob, `/${runtime_definitions_1.gcTreeKey}/${runtime_definitions_1.gcTombstoneBlobKey}`);
164
+ }
165
+ else {
166
+ builder.addBlob(runtime_definitions_1.gcTombstoneBlobKey, serializedTombstones);
167
+ }
168
+ }
169
+ // If there are no deleted nodes, return the summary tree.
170
+ if (serializedDeletedNodes === undefined) {
171
+ return builder.getSummaryTree();
172
+ }
173
+ // If the deleted nodes hasn't changed, write a summary handle, else write a summary blob for it.
174
+ if (((_c = this.latestSummaryData) === null || _c === void 0 ? void 0 : _c.serializedDeletedNodes) === serializedDeletedNodes &&
175
+ trackState) {
176
+ builder.addHandle(runtime_definitions_1.gcDeletedBlobKey, protocol_definitions_1.SummaryType.Blob, `/${runtime_definitions_1.gcTreeKey}/${runtime_definitions_1.gcDeletedBlobKey}`);
177
+ }
178
+ else {
179
+ builder.addBlob(runtime_definitions_1.gcDeletedBlobKey, serializedDeletedNodes);
180
+ }
181
+ return builder.getSummaryTree();
182
+ }
183
+ /**
184
+ * Called to refresh the latest summary state. This happens when either a pending summary is acked or a snapshot
185
+ * is downloaded and should be used to update the state.
186
+ */
187
+ async refreshLatestSummary(proposalHandle, result, readAndParseBlob) {
188
+ // If the latest summary was updated and the summary was tracked, this client is the one that generated this
189
+ // summary. So, update wasGCRunInLatestSummary.
190
+ // Note that this has to be updated if GC did not run too. Otherwise, `gcStateNeedsReset` will always return
191
+ // true in scenarios where GC is disabled but enabled in the snapshot we loaded from.
192
+ if (result.latestSummaryUpdated && result.wasSummaryTracked) {
193
+ this.wasGCRunInLatestSummary = this.shouldRunGC;
194
+ }
195
+ if (!result.latestSummaryUpdated || !this.shouldRunGC) {
196
+ return undefined;
197
+ }
198
+ // If the summary was tracked by this client, it was the one that generated the summary in the first place.
199
+ // Update latest state from pending.
200
+ if (result.wasSummaryTracked) {
201
+ this.latestSummaryGCVersion = this.currentGCVersion;
202
+ if (this.trackGCState) {
203
+ this.latestSummaryData = this.pendingSummaryData;
204
+ this.pendingSummaryData = undefined;
205
+ }
206
+ return undefined;
207
+ }
208
+ // If the summary was not tracked by this client, the state should be updated from the downloaded snapshot.
209
+ const snapshotTree = result.snapshotTree;
210
+ const metadataBlobId = snapshotTree.blobs[summary_1.metadataBlobName];
211
+ if (metadataBlobId) {
212
+ const metadata = await readAndParseBlob(metadataBlobId);
213
+ this.latestSummaryGCVersion = (0, gcHelpers_1.getGCVersion)(metadata);
214
+ }
215
+ const gcSnapshotTree = snapshotTree.trees[runtime_definitions_1.gcTreeKey];
216
+ // If GC ran in the container that generated this snapshot, it will have a GC tree.
217
+ this.wasGCRunInLatestSummary = gcSnapshotTree !== undefined;
218
+ let latestGCData;
219
+ if (gcSnapshotTree !== undefined) {
220
+ latestGCData = await (0, garbage_collector_1.getGCDataFromSnapshot)(gcSnapshotTree, readAndParseBlob);
221
+ }
222
+ this.pendingSummaryData = undefined;
223
+ return latestGCData;
224
+ }
225
+ /**
226
+ * Update state from the given snapshot data. This is done during load and during refreshing state from a snapshot.
227
+ * @param gcSnapshotData - The GC snapshot data to update state from.
228
+ */
229
+ updateStateFromSnapshotData(gcSnapshotData) {
230
+ // If there is no snapshot data, it means this snapshot was generated with GC disabled. Unset all GC state.
231
+ if (gcSnapshotData === undefined) {
232
+ this.latestSummaryData = undefined;
233
+ return;
234
+ }
235
+ // If tracking state across summaries, update latest summary data from the snapshot's GC data.
236
+ if (this.trackGCState) {
237
+ this.latestSummaryData = {
238
+ serializedGCState: JSON.stringify((0, gcHelpers_1.generateSortedGCState)(gcSnapshotData.gcState)),
239
+ serializedTombstones: JSON.stringify(gcSnapshotData.tombstones),
240
+ serializedDeletedNodes: JSON.stringify(gcSnapshotData.deletedNodes),
241
+ };
242
+ }
243
+ }
244
+ }
245
+ exports.GCSummaryStateTracker = GCSummaryStateTracker;
246
+ //# sourceMappingURL=gcSummaryStateTracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gcSummaryStateTracker.js","sourceRoot":"","sources":["../../src/gc/gcSummaryStateTracker.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yEAA0E;AAC1E,+EAAmE;AACnE,6EAS6C;AAC7C,iEAKuC;AAEvC,wCAAyE;AACzE,mDAKyB;AACzB,2CAAkE;AAWlE;;;;;GAKG;AACH,MAAa,qBAAqB;IAcjC;IACC,sCAAsC;IACrB,WAAoB;IACrC,oEAAoE;IACnD,YAAqB;IACtC,kDAAkD;IACjC,aAAsB,EACtB,EAAqB;IACtC,4EAA4E;IAC5E,sBAA+B;IAC/B,kEAAkE;IAClE,uBAA8C;QAT7B,gBAAW,GAAX,WAAW,CAAS;QAEpB,iBAAY,GAAZ,YAAY,CAAS;QAErB,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CAAC;SAC7E;QACD,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;QACpC,OAAO,YAAY,CAAC;IACrB,CAAC;IAED;;;OAGG;IACI,2BAA2B,CAAC,cAA0D;QAC5F,2GAA2G;QAC3G,IAAI,cAAc,KAAK,SAAS,EAAE;YACjC,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAC;YACnC,OAAO;SACP;QAED,8FAA8F;QAC9F,IAAI,IAAI,CAAC,YAAY,EAAE;YACtB,IAAI,CAAC,iBAAiB,GAAG;gBACxB,iBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,IAAA,iCAAqB,EAAC,cAAc,CAAC,OAAO,CAAC,CAAC;gBAChF,oBAAoB,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,UAAU,CAAC;gBAC/D,sBAAsB,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,YAAY,CAAC;aACnE,CAAC;SACF;IACF,CAAC;CACD;AAlSD,sDAkSC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { getGCDataFromSnapshot } from \"@fluidframework/garbage-collector\";\nimport { SummaryType } from \"@fluidframework/protocol-definitions\";\nimport {\n\tgcBlobPrefix,\n\tgcDeletedBlobKey,\n\tgcTombstoneBlobKey,\n\tgcTreeKey,\n\tIGarbageCollectionSnapshotData,\n\tIGarbageCollectionState,\n\tISummarizeResult,\n\tISummaryTreeWithStats,\n} from \"@fluidframework/runtime-definitions\";\nimport {\n\tmergeStats,\n\tReadAndParseBlob,\n\tRefreshSummaryResult,\n\tSummaryTreeBuilder,\n} from \"@fluidframework/runtime-utils\";\nimport { MonitoringContext } from \"@fluidframework/telemetry-utils\";\nimport { IContainerRuntimeMetadata, metadataBlobName } from \"../summary\";\nimport {\n\tcurrentGCVersion,\n\tGCVersion,\n\tgcVersionUpgradeToV2Key,\n\tstableGCVersion,\n} from \"./gcDefinitions\";\nimport { generateSortedGCState, getGCVersion } from \"./gcHelpers\";\n\n/**\n * The GC data that is tracked for a summary.\n */\ninterface IGCSummaryTrackingData {\n\tserializedGCState: string | undefined;\n\tserializedTombstones: string | undefined;\n\tserializedDeletedNodes: string | undefined;\n}\n\n/**\n * Encapsulates the garbage collection state that is tracked across summaries.\n * It maintains the GC state as per the latest summary in by the server. It updates state when a summary tracked by this\n * client is acked by the server or from a snapshot is downloaded from the server.\n * On summarize, it decides whether to write new state or re-use previous summary's state.\n */\nexport class GCSummaryStateTracker {\n\t// The current version of GC running.\n\tpublic readonly currentGCVersion: GCVersion;\n\t// This is the version of GC data in the latest summary being tracked.\n\tprivate latestSummaryGCVersion: GCVersion;\n\n\t// Keeps track of the GC data from the latest summary successfully acked by the server.\n\tprivate latestSummaryData: IGCSummaryTrackingData | undefined;\n\t// Keeps track of the GC data from the last summary submitted to the server but not yet acked.\n\tprivate pendingSummaryData: IGCSummaryTrackingData | undefined;\n\n\t// Tracks whether there was GC was run in latest summary being tracked.\n\tprivate wasGCRunInLatestSummary: boolean;\n\n\tconstructor(\n\t\t// Tells whether GC should run or not.\n\t\tprivate readonly shouldRunGC: boolean,\n\t\t// Tells whether GC state should be tracked across summaries or not.\n\t\tprivate readonly trackGCState: boolean,\n\t\t// Tells whether tombstone mode is enabled or not.\n\t\tprivate readonly tombstoneMode: boolean,\n\t\tprivate readonly mc: MonitoringContext,\n\t\t// Tells whether GC was run in the base snapshot this container loaded from.\n\t\twasGCRunInBaseSnapshot: boolean,\n\t\t// The GC version in the base snapshot this container loaded from.\n\t\tgcVersionInBaseSnapshot: GCVersion | undefined,\n\t) {\n\t\tthis.wasGCRunInLatestSummary = wasGCRunInBaseSnapshot;\n\t\t// If version upgrade is not enabled, fall back to the stable GC version.\n\t\tthis.currentGCVersion =\n\t\t\tthis.mc.config.getBoolean(gcVersionUpgradeToV2Key) === true\n\t\t\t\t? currentGCVersion\n\t\t\t\t: stableGCVersion;\n\t\t// For existing document, the latest summary is the one that we loaded from. So, use its GC version as the\n\t\t// latest tracked GC version. For new documents, we will be writing the first summary with the current version.\n\t\tthis.latestSummaryGCVersion = gcVersionInBaseSnapshot ?? this.currentGCVersion;\n\t}\n\n\t/**\n\t * Tells whether the GC state needs to be reset. This can happen under 3 conditions:\n\t *\n\t * 1. The base snapshot contains GC state but GC is disabled. This will happen the first time GC is disabled after\n\t * it was enabled before. GC state needs to be removed from summary and all nodes should be marked referenced.\n\t *\n\t * 2. The base snapshot does not have GC state but GC is enabled. This will happen the very first time GC runs on\n\t * a document and the first time GC is enabled after is was disabled before.\n\t *\n\t * 3. GC is enabled and the latest summary state is refreshed from a snapshot that had GC disabled and vice-versa.\n\t *\n\t * Note that the state will be reset only once for the first summary generated after this returns true. After that,\n\t * this will return false.\n\t */\n\tpublic doesGCStateNeedReset(): boolean {\n\t\treturn this.wasGCRunInLatestSummary !== this.shouldRunGC;\n\t}\n\n\t/**\n\t * Tells whether the GC state needs to be reset in the next summary. We need to do this if:\n\t *\n\t * 1. GC was enabled and is now disabled. The GC state needs to be removed and everything becomes referenced.\n\t *\n\t * 2. GC was disabled and is now enabled. The GC state needs to be regenerated and added to summary.\n\t *\n\t * 3. GC is enabled and the latest summary state is refreshed from a snapshot that had GC disabled and vice-versa.\n\t *\n\t * 4. The GC version in the latest summary is different from the current GC version. This can happen if:\n\t *\n\t * 4.1. The summary this client loaded with has data from a different GC version.\n\t *\n\t * 4.2. This client's latest summary was updated from a snapshot that has a different GC version.\n\t */\n\tpublic doesSummaryStateNeedReset(): boolean {\n\t\treturn (\n\t\t\tthis.doesGCStateNeedReset() ||\n\t\t\t(this.shouldRunGC && this.latestSummaryGCVersion !== this.currentGCVersion)\n\t\t);\n\t}\n\n\t/**\n\t * Summarizes three component of the GC data - GC state, tombstones and deleted nodes.\n\t * It does incremental summary, i.e., it writes summary tree / summary blob only for the component that changed.\n\t * For components that did not change, a summary handle is returned that points to the previous successful summary.\n\t * If none of the components changed, it returns a summary handle for the entire GC data.\n\t */\n\tpublic summarize(\n\t\tfullTree: boolean,\n\t\ttrackState: boolean,\n\t\tgcState: IGarbageCollectionState,\n\t\tdeletedNodes: Set<string>,\n\t\ttombstones: string[],\n\t): ISummarizeResult | undefined {\n\t\tif (!this.shouldRunGC) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst serializedGCState = JSON.stringify(generateSortedGCState(gcState));\n\t\t// Serialize and write deleted nodes, if any. This is done irrespective of whether sweep is enabled or not so\n\t\t// to identify deleted nodes' usage.\n\t\tconst serializedDeletedNodes =\n\t\t\tdeletedNodes.size > 0 ? JSON.stringify(Array.from(deletedNodes).sort()) : undefined;\n\t\t// If running in tombstone mode, serialize and write tombstones, if any.\n\t\tconst serializedTombstones = this.tombstoneMode\n\t\t\t? tombstones.length > 0\n\t\t\t\t? JSON.stringify(tombstones.sort())\n\t\t\t\t: undefined\n\t\t\t: undefined;\n\n\t\t/**\n\t\t * Incremental summary of GC data - If none of GC state, deleted nodes or tombstones changed since last summary,\n\t\t * write summary handle instead of summary tree for GC.\n\t\t * Otherwise, write the GC summary tree. In the tree, for each of these that changed, write a summary blob and\n\t\t * for each of these that did not change, write a summary handle.\n\t\t */\n\t\tif (this.trackGCState) {\n\t\t\tthis.pendingSummaryData = {\n\t\t\t\tserializedGCState,\n\t\t\t\tserializedTombstones,\n\t\t\t\tserializedDeletedNodes,\n\t\t\t};\n\t\t\tif (trackState && !fullTree && this.latestSummaryData !== undefined) {\n\t\t\t\t// If nothing changed since last summary, send a summary handle for the entire GC data.\n\t\t\t\tif (\n\t\t\t\t\tthis.latestSummaryData.serializedGCState === serializedGCState &&\n\t\t\t\t\tthis.latestSummaryData.serializedTombstones === serializedTombstones\n\t\t\t\t) {\n\t\t\t\t\tconst stats = mergeStats();\n\t\t\t\t\tstats.handleNodeCount++;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tsummary: {\n\t\t\t\t\t\t\ttype: SummaryType.Handle,\n\t\t\t\t\t\t\thandle: `/${gcTreeKey}`,\n\t\t\t\t\t\t\thandleType: SummaryType.Tree,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tstats,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t// If some state changed, build a GC summary tree.\n\t\t\t\treturn this.buildGCSummaryTree(\n\t\t\t\t\tserializedGCState,\n\t\t\t\t\tserializedTombstones,\n\t\t\t\t\tserializedDeletedNodes,\n\t\t\t\t\ttrue /* trackState */,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\t// If not tracking GC state, build a GC summary tree without any summary handles.\n\t\treturn this.buildGCSummaryTree(\n\t\t\tserializedGCState,\n\t\t\tserializedTombstones,\n\t\t\tserializedDeletedNodes,\n\t\t\tfalse /* trackState */,\n\t\t);\n\t}\n\n\t/**\n\t * Builds the GC summary tree which contains GC state, deleted nodes and tombstones.\n\t * If trackState is false, all of GC state, deleted nodes and tombstones are written as summary blobs.\n\t * If trackState is true, only states that changed are written. Rest are written as handles.\n\t * @param serializedGCState - The GC state serialized as string.\n\t * @param serializedTombstones - The tombstone state serialized as string.\n\t * @param serializedDeletedNodes - Deleted nodes serialized as string.\n\t * @param trackState - Whether we are tracking GC state across summaries.\n\t * @returns the GC summary tree.\n\t */\n\tprivate buildGCSummaryTree(\n\t\tserializedGCState: string,\n\t\tserializedTombstones: string | undefined,\n\t\tserializedDeletedNodes: string | undefined,\n\t\ttrackState: boolean,\n\t): ISummaryTreeWithStats {\n\t\tconst gcStateBlobKey = `${gcBlobPrefix}_root`;\n\t\tconst builder = new SummaryTreeBuilder();\n\n\t\t// If the GC state hasn't changed, write a summary handle, else write a summary blob for it.\n\t\tif (this.latestSummaryData?.serializedGCState === serializedGCState && trackState) {\n\t\t\tbuilder.addHandle(gcStateBlobKey, SummaryType.Blob, `/${gcTreeKey}/${gcStateBlobKey}`);\n\t\t} else {\n\t\t\tbuilder.addBlob(gcStateBlobKey, serializedGCState);\n\t\t}\n\n\t\t// If tombstones exist, write a summary handle if it hasn't changed. If it has changed, write a\n\t\t// summary blob.\n\t\tif (serializedTombstones !== undefined) {\n\t\t\tif (\n\t\t\t\tthis.latestSummaryData?.serializedTombstones === serializedTombstones &&\n\t\t\t\ttrackState\n\t\t\t) {\n\t\t\t\tbuilder.addHandle(\n\t\t\t\t\tgcTombstoneBlobKey,\n\t\t\t\t\tSummaryType.Blob,\n\t\t\t\t\t`/${gcTreeKey}/${gcTombstoneBlobKey}`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tbuilder.addBlob(gcTombstoneBlobKey, serializedTombstones);\n\t\t\t}\n\t\t}\n\n\t\t// If there are no deleted nodes, return the summary tree.\n\t\tif (serializedDeletedNodes === undefined) {\n\t\t\treturn builder.getSummaryTree();\n\t\t}\n\n\t\t// If the deleted nodes hasn't changed, write a summary handle, else write a summary blob for it.\n\t\tif (\n\t\t\tthis.latestSummaryData?.serializedDeletedNodes === serializedDeletedNodes &&\n\t\t\ttrackState\n\t\t) {\n\t\t\tbuilder.addHandle(\n\t\t\t\tgcDeletedBlobKey,\n\t\t\t\tSummaryType.Blob,\n\t\t\t\t`/${gcTreeKey}/${gcDeletedBlobKey}`,\n\t\t\t);\n\t\t} else {\n\t\t\tbuilder.addBlob(gcDeletedBlobKey, serializedDeletedNodes);\n\t\t}\n\t\treturn builder.getSummaryTree();\n\t}\n\n\t/**\n\t * Called to refresh the latest summary state. This happens when either a pending summary is acked or a snapshot\n\t * is downloaded and should be used to update the state.\n\t */\n\tpublic async refreshLatestSummary(\n\t\tproposalHandle: string | undefined,\n\t\tresult: RefreshSummaryResult,\n\t\treadAndParseBlob: ReadAndParseBlob,\n\t): Promise<IGarbageCollectionSnapshotData | undefined> {\n\t\t// If the latest summary was updated and the summary was tracked, this client is the one that generated this\n\t\t// summary. So, update wasGCRunInLatestSummary.\n\t\t// Note that this has to be updated if GC did not run too. Otherwise, `gcStateNeedsReset` will always return\n\t\t// true in scenarios where GC is disabled but enabled in the snapshot we loaded from.\n\t\tif (result.latestSummaryUpdated && result.wasSummaryTracked) {\n\t\t\tthis.wasGCRunInLatestSummary = this.shouldRunGC;\n\t\t}\n\n\t\tif (!result.latestSummaryUpdated || !this.shouldRunGC) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// If the summary was tracked by this client, it was the one that generated the summary in the first place.\n\t\t// Update latest state from pending.\n\t\tif (result.wasSummaryTracked) {\n\t\t\tthis.latestSummaryGCVersion = this.currentGCVersion;\n\t\t\tif (this.trackGCState) {\n\t\t\t\tthis.latestSummaryData = this.pendingSummaryData;\n\t\t\t\tthis.pendingSummaryData = undefined;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// If the summary was not tracked by this client, the state should be updated from the downloaded snapshot.\n\t\tconst snapshotTree = result.snapshotTree;\n\t\tconst metadataBlobId = snapshotTree.blobs[metadataBlobName];\n\t\tif (metadataBlobId) {\n\t\t\tconst metadata = await readAndParseBlob<IContainerRuntimeMetadata>(metadataBlobId);\n\t\t\tthis.latestSummaryGCVersion = getGCVersion(metadata);\n\t\t}\n\n\t\tconst gcSnapshotTree = snapshotTree.trees[gcTreeKey];\n\t\t// If GC ran in the container that generated this snapshot, it will have a GC tree.\n\t\tthis.wasGCRunInLatestSummary = gcSnapshotTree !== undefined;\n\t\tlet latestGCData: IGarbageCollectionSnapshotData | undefined;\n\t\tif (gcSnapshotTree !== undefined) {\n\t\t\tlatestGCData = await getGCDataFromSnapshot(gcSnapshotTree, readAndParseBlob);\n\t\t}\n\t\tthis.pendingSummaryData = undefined;\n\t\treturn latestGCData;\n\t}\n\n\t/**\n\t * Update state from the given snapshot data. This is done during load and during refreshing state from a snapshot.\n\t * @param gcSnapshotData - The GC snapshot data to update state from.\n\t */\n\tpublic updateStateFromSnapshotData(gcSnapshotData: IGarbageCollectionSnapshotData | undefined) {\n\t\t// If there is no snapshot data, it means this snapshot was generated with GC disabled. Unset all GC state.\n\t\tif (gcSnapshotData === undefined) {\n\t\t\tthis.latestSummaryData = undefined;\n\t\t\treturn;\n\t\t}\n\n\t\t// If tracking state across summaries, update latest summary data from the snapshot's GC data.\n\t\tif (this.trackGCState) {\n\t\t\tthis.latestSummaryData = {\n\t\t\t\tserializedGCState: JSON.stringify(generateSortedGCState(gcSnapshotData.gcState)),\n\t\t\t\tserializedTombstones: JSON.stringify(gcSnapshotData.tombstones),\n\t\t\t\tserializedDeletedNodes: JSON.stringify(gcSnapshotData.deletedNodes),\n\t\t\t};\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gcSweepReadyUsageDetection.d.ts","sourceRoot":"","sources":["../../src/gc/gcSweepReadyUsageDetection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAEN,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,MAAM,iCAAiC,CAAC;AAGzC;;;GAGG;AACH,eAAO,MAAM,sBAAsB,iFAC4C,CAAC;AAEhF;;;GAGG;AACH,eAAO,MAAM,0BAA0B,sEAC6B,CAAC;AAqBrE;;;;;;;GAOG;AACH,qBAAa,oBAAqB,SAAQ,YAAa,YAAW,eAAe;IAChF,oHAAoH;IAC7G,SAAS,EAAE,MAAM,CAAiD;CACzE;AAED;;;;;;;GAOG;AACH,qBAAa,+BAA+B;IAI1C,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,OAAO;IALzB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAuC;gBAGlD,kBAAkB,EAAE,MAAM,EAC1B,EAAE,EAAE,iBAAiB,EACrB,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,uBAAuB,KAAK,IAAI,EACnE,oBAAoB,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC;IAc5D;;;;;;OAMG;IACI,gCAAgC,CAAC,UAAU,EAAE,oBAAoB;CA+CxE"}
@@ -6,7 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.SweepReadyUsageDetectionHandler = exports.SweepReadyUsageError = exports.closuresMapLocalStorageKey = exports.skipClosureForXDaysKey = void 0;
8
8
  const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
9
- const garbageCollectionConstants_1 = require("./garbageCollectionConstants");
9
+ const gcDefinitions_1 = require("./gcDefinitions");
10
10
  /**
11
11
  * Feature Gate Key -
12
12
  * How many days between closing the container from this error (avoids locking user out of their file altogether)
@@ -106,7 +106,7 @@ class SweepReadyUsageDetectionHandler {
106
106
  lastCloseTime = (_a = pastClosuresMap[this.uniqueContainerKey]) === null || _a === void 0 ? void 0 : _a.lastCloseTime;
107
107
  // Don't close if we did already within the Skip Closure Period
108
108
  if (lastCloseTime !== undefined &&
109
- Date.now() < lastCloseTime + skipClosureForXDays * garbageCollectionConstants_1.oneDayMs) {
109
+ Date.now() < lastCloseTime + skipClosureForXDays * gcDefinitions_1.oneDayMs) {
110
110
  shouldClose = false;
111
111
  }
112
112
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gcSweepReadyUsageDetection.js","sourceRoot":"","sources":["../../src/gc/gcSweepReadyUsageDetection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,qEAKyC;AACzC,mDAA2C;AAE3C;;;GAGG;AACU,QAAA,sBAAsB,GAClC,8EAA8E,CAAC;AAEhF;;;GAGG;AACU,QAAA,0BAA0B,GACtC,mEAAmE,CAAC;AAErE;;;GAGG;AACH,MAAM,+BAA+B,GAAG;IACvC,IAAI,CAAC,MAAuB;QAC3B,MAAM,2BAA2B,GAChC,0DAA0D,CAAC;QAC5D,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC;QAC5D,IAAI,KAAK,KAAK,SAAS,EAAE;YACxB,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,C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AK,CAAC,CAAC;SACpB;aAAM;YACN,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,+BAA+B,EAAE,EAAE,KAAK,CAAC,CAAC;SACrF;IACF,CAAC;CACD;AA3ED,0EA2EC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryProperties } from \"@fluidframework/common-definitions\";\nimport { ICriticalContainerError } from \"@fluidframework/container-definitions\";\nimport {\n\tIConfigProvider,\n\tIFluidErrorBase,\n\tLoggingError,\n\tMonitoringContext,\n} from \"@fluidframework/telemetry-utils\";\nimport { oneDayMs } from \"./gcDefinitions\";\n\n/**\n * Feature Gate Key -\n * How many days between closing the container from this error (avoids locking user out of their file altogether)\n */\nexport const skipClosureForXDaysKey =\n\t\"Fluid.GarbageCollection.Dogfood.SweepReadyUsageDetection.SkipClosureForXDays\";\n\n/**\n * LocalStorage key (NOT via feature gate / monitoring context)\n * A map from docId to info about the last time we closed due to this error\n */\nexport const closuresMapLocalStorageKey =\n\t\"Fluid.GarbageCollection.Dogfood.SweepReadyUsageDetection.Closures\";\n\n/**\n * Feature gate key to enable closing the container if SweepReady objects are used.\n * Value should contain keywords \"interactiveClient\" and/or \"summarizer\" to enable detection in each container type\n */\nconst sweepReadyUsageDetectionSetting = {\n\tread(config: IConfigProvider) {\n\t\tconst sweepReadyUsageDetectionKey =\n\t\t\t\"Fluid.GarbageCollection.Dogfood.SweepReadyUsageDetection\";\n\t\tconst value = config.getString(sweepReadyUsageDetectionKey);\n\t\tif (value === undefined) {\n\t\t\treturn { interactiveClient: false, summarizer: false };\n\t\t}\n\t\treturn {\n\t\t\tinteractiveClient: value.includes(\"interactiveClient\"),\n\t\t\tsummarizer: value.includes(\"summarizer\"),\n\t\t};\n\t},\n};\n\n/**\n * Error class raised when a SweepReady object is used, indicating a bug in how\n * references are managed in the container by the application, or a bug in how\n * GC tracks those references.\n *\n * There's a chance for false positives when this error is raised by an Interactive Container,\n * since only the Summarizer has the latest truth about unreferenced node tracking\n */\nexport class SweepReadyUsageError extends LoggingError implements IFluidErrorBase {\n\t/** This errorType will be in temporary use (until Sweep is fully implemented) so don't add to any errorType type */\n\tpublic errorType: string = \"unreferencedObjectUsedAfterGarbageCollected\";\n}\n\n/**\n * This class encapsulates the logic around what to do when a SweepReady object is used.\n * There are several tactics we plan to use in Dogfood environments to aid diagnosis of these cases:\n * - Closing the interactive container when either the interactive or summarizer client detects this kind of violation\n * (via sweepReadyUsageDetectionSetting above)\n * - Throttling the frequency of these crashes via a \"Skip Closure Period\" per container per device\n * (via skipClosureForXDaysKey above. Uses localStorage and closuresMapLocalStorageKey to implement this behavior)\n */\nexport class SweepReadyUsageDetectionHandler {\n\tprivate readonly localStorage: Pick<Storage, \"getItem\" | \"setItem\">;\n\n\tconstructor(\n\t\tprivate readonly uniqueContainerKey: string,\n\t\tprivate readonly mc: MonitoringContext,\n\t\tprivate readonly closeFn: (error?: ICriticalContainerError) => void,\n\t\tlocalStorageOverride?: Pick<Storage, \"getItem\" | \"setItem\">,\n\t) {\n\t\tconst noopStorage = { getItem: () => null, setItem: () => {} };\n\t\t// localStorage is not defined in Node environment, so fall back to noopStorage if needed.\n\t\tthis.localStorage = localStorageOverride ?? globalThis.localStorage ?? noopStorage;\n\n\t\tif (this.localStorage === noopStorage) {\n\t\t\t// This means the Skip Closure Period logic will not work.\n\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"SweepReadyUsageDetectionHandlerNoopStorage\",\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * If SweepReady Usage Detection is enabled, close the interactive container.\n\t * If the SkipClosureForXDays setting is set, don't close the container more than once in that period.\n\t *\n\t * Once Sweep is fully implemented, this will be removed since the objects will be gone\n\t * and errors will arise elsewhere in the runtime\n\t */\n\tpublic usageDetectedInInteractiveClient(errorProps: ITelemetryProperties) {\n\t\tif (!sweepReadyUsageDetectionSetting.read(this.mc.config).interactiveClient) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Default stance is we close every time - this reflects the severity of SweepReady Object Usage.\n\t\t// However, we may choose to \"throttle\" the closures by setting the SkipClosureForXDays setting,\n\t\t// which will only allow the container to close once during that period, to avoid locking users out.\n\t\tlet shouldClose: boolean = true;\n\t\tlet pastClosuresMap: Record<string, { lastCloseTime: number } | undefined> = {};\n\t\tlet lastCloseTime: number | undefined;\n\t\tconst skipClosureForXDays = this.mc.config.getNumber(skipClosureForXDaysKey);\n\t\tif (skipClosureForXDays !== undefined) {\n\t\t\t// Read pastClosuresMap from localStorage then extract the lastCloseTime from the map\n\t\t\ttry {\n\t\t\t\tconst rawValue = this.localStorage.getItem(closuresMapLocalStorageKey);\n\t\t\t\tconst parsedValue = rawValue === null ? {} : JSON.parse(rawValue);\n\t\t\t\tif (typeof parsedValue === \"object\") {\n\t\t\t\t\tpastClosuresMap = parsedValue;\n\t\t\t\t}\n\t\t\t} catch (e) {}\n\t\t\tlastCloseTime = pastClosuresMap[this.uniqueContainerKey]?.lastCloseTime;\n\n\t\t\t// Don't close if we did already within the Skip Closure Period\n\t\t\tif (\n\t\t\t\tlastCloseTime !== undefined &&\n\t\t\t\tDate.now() < lastCloseTime + skipClosureForXDays * oneDayMs\n\t\t\t) {\n\t\t\t\tshouldClose = false;\n\t\t\t}\n\t\t}\n\n\t\tconst error = new SweepReadyUsageError(\"SweepReady object used in Non-Summarizer Client\", {\n\t\t\terrorDetails: JSON.stringify({ ...errorProps, lastCloseTime, skipClosureForXDays }),\n\t\t});\n\t\tif (shouldClose) {\n\t\t\t// Update closures map in localStorage before closing\n\t\t\t// Note there is a race condition between different tabs updating localStorage and overwriting\n\t\t\t// each others' updates. If so, some tab will crash again. Just reload one at a time to get unstuck\n\t\t\tpastClosuresMap[this.uniqueContainerKey] = { lastCloseTime: Date.now() };\n\t\t\tthis.localStorage.setItem(closuresMapLocalStorageKey, JSON.stringify(pastClosuresMap));\n\n\t\t\tthis.closeFn(error);\n\t\t} else {\n\t\t\tthis.mc.logger.sendErrorEvent({ eventName: \"SweepReadyObject_UsageAllowed\" }, error);\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,34 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { UnreferencedState } from "./gcDefinitions";
6
+ /**
7
+ * Helper class that tracks the state of an unreferenced node such as the time it was unreferenced and if it can
8
+ * be deleted by the sweep phase.
9
+ */
10
+ export declare class UnreferencedStateTracker {
11
+ readonly unreferencedTimestampMs: number;
12
+ /** The time after which node transitions to Inactive state. */
13
+ private readonly inactiveTimeoutMs;
14
+ /** The time after which node transitions to SweepReady state; undefined if session expiry is disabled. */
15
+ private readonly sweepTimeoutMs;
16
+ private _state;
17
+ get state(): UnreferencedState;
18
+ /** Timer to indicate when an unreferenced object is considered Inactive */
19
+ private readonly inactiveTimer;
20
+ /** Timer to indicate when an unreferenced object is Sweep-Ready */
21
+ private readonly sweepTimer;
22
+ constructor(unreferencedTimestampMs: number,
23
+ /** The time after which node transitions to Inactive state. */
24
+ inactiveTimeoutMs: number,
25
+ /** The current reference timestamp used to track how long this node has been unreferenced for. */
26
+ currentReferenceTimestampMs: number,
27
+ /** The time after which node transitions to SweepReady state; undefined if session expiry is disabled. */
28
+ sweepTimeoutMs: number | undefined);
29
+ updateTracking(currentReferenceTimestampMs: number): void;
30
+ private clearTimers;
31
+ /** Stop tracking this node. Reset the unreferenced timers and state, if any. */
32
+ stopTracking(): void;
33
+ }
34
+ //# sourceMappingURL=gcUnreferencedStateTracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gcUnreferencedStateTracker.d.ts","sourceRoot":"","sources":["../../src/gc/gcUnreferencedStateTracker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAoBpD;;;GAGG;AACH,qBAAa,wBAAwB;aAYnB,uBAAuB,EAAE,MAAM;IAC/C,+DAA+D;IAC/D,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAGlC,0GAA0G;IAC1G,OAAO,CAAC,QAAQ,CAAC,cAAc;IAjBhC,OAAO,CAAC,MAAM,CAA+C;IAC7D,IAAW,KAAK,IAAI,iBAAiB,CAEpC;IAED,2EAA2E;IAC3E,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4B;IAC1D,mEAAmE;IACnE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA4B;gBAGtC,uBAAuB,EAAE,MAAM;IAC/C,+DAA+D;IAC9C,iBAAiB,EAAE,MAAM;IAC1C,kGAAkG;IAClG,2BAA2B,EAAE,MAAM;IACnC,0GAA0G;IACzF,cAAc,EAAE,MAAM,GAAG,SAAS;IA6B7C,cAAc,CAAC,2BAA2B,EAAE,MAAM;IA0BzD,OAAO,CAAC,WAAW;IAKnB,gFAAgF;IACzE,YAAY;CAInB"}
@@ -0,0 +1,94 @@
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.UnreferencedStateTracker = void 0;
8
+ const common_utils_1 = require("@fluidframework/common-utils");
9
+ const gcDefinitions_1 = require("./gcDefinitions");
10
+ /** A wrapper around common-utils Timer that requires the timeout when calling start/restart */
11
+ class TimerWithNoDefaultTimeout extends common_utils_1.Timer {
12
+ constructor(callback) {
13
+ // The default timeout/handlers will never be used since start/restart pass overrides below
14
+ super(0, () => {
15
+ throw new Error("DefaultHandler should not be used");
16
+ });
17
+ this.callback = callback;
18
+ }
19
+ start(timeoutMs) {
20
+ super.start(timeoutMs, this.callback);
21
+ }
22
+ restart(timeoutMs) {
23
+ super.restart(timeoutMs, this.callback);
24
+ }
25
+ }
26
+ /**
27
+ * Helper class that tracks the state of an unreferenced node such as the time it was unreferenced and if it can
28
+ * be deleted by the sweep phase.
29
+ */
30
+ class UnreferencedStateTracker {
31
+ constructor(unreferencedTimestampMs,
32
+ /** The time after which node transitions to Inactive state. */
33
+ inactiveTimeoutMs,
34
+ /** The current reference timestamp used to track how long this node has been unreferenced for. */
35
+ currentReferenceTimestampMs,
36
+ /** The time after which node transitions to SweepReady state; undefined if session expiry is disabled. */
37
+ sweepTimeoutMs) {
38
+ this.unreferencedTimestampMs = unreferencedTimestampMs;
39
+ this.inactiveTimeoutMs = inactiveTimeoutMs;
40
+ this.sweepTimeoutMs = sweepTimeoutMs;
41
+ this._state = gcDefinitions_1.UnreferencedState.Active;
42
+ if (this.sweepTimeoutMs !== undefined) {
43
+ (0, common_utils_1.assert)(this.inactiveTimeoutMs <= this.sweepTimeoutMs, 0x3b0 /* inactive timeout must not be greater than the sweep timeout */);
44
+ }
45
+ this.sweepTimer = new TimerWithNoDefaultTimeout(() => {
46
+ this._state = gcDefinitions_1.UnreferencedState.SweepReady;
47
+ (0, common_utils_1.assert)(!this.inactiveTimer.hasTimer, 0x3b1 /* inactiveTimer still running after sweepTimer fired! */);
48
+ });
49
+ this.inactiveTimer = new TimerWithNoDefaultTimeout(() => {
50
+ this._state = gcDefinitions_1.UnreferencedState.Inactive;
51
+ // After the node becomes inactive, start the sweep timer after which the node will be ready for sweep.
52
+ if (this.sweepTimeoutMs !== undefined) {
53
+ this.sweepTimer.restart(this.sweepTimeoutMs - this.inactiveTimeoutMs);
54
+ }
55
+ });
56
+ this.updateTracking(currentReferenceTimestampMs);
57
+ }
58
+ get state() {
59
+ return this._state;
60
+ }
61
+ /* Updates the unreferenced state based on the provided timestamp. */
62
+ updateTracking(currentReferenceTimestampMs) {
63
+ const unreferencedDurationMs = currentReferenceTimestampMs - this.unreferencedTimestampMs;
64
+ // If the node has been unreferenced for sweep timeout amount of time, update the state to SweepReady.
65
+ if (this.sweepTimeoutMs !== undefined && unreferencedDurationMs >= this.sweepTimeoutMs) {
66
+ this._state = gcDefinitions_1.UnreferencedState.SweepReady;
67
+ this.clearTimers();
68
+ return;
69
+ }
70
+ // If the node has been unreferenced for inactive timeoutMs amount of time, update the state to inactive.
71
+ // Also, start a timer for the sweep timeout.
72
+ if (unreferencedDurationMs >= this.inactiveTimeoutMs) {
73
+ this._state = gcDefinitions_1.UnreferencedState.Inactive;
74
+ this.inactiveTimer.clear();
75
+ if (this.sweepTimeoutMs !== undefined) {
76
+ this.sweepTimer.restart(this.sweepTimeoutMs - unreferencedDurationMs);
77
+ }
78
+ return;
79
+ }
80
+ // The node is still active. Ensure the inactive timer is running with the proper remaining duration.
81
+ this.inactiveTimer.restart(this.inactiveTimeoutMs - unreferencedDurationMs);
82
+ }
83
+ clearTimers() {
84
+ this.inactiveTimer.clear();
85
+ this.sweepTimer.clear();
86
+ }
87
+ /** Stop tracking this node. Reset the unreferenced timers and state, if any. */
88
+ stopTracking() {
89
+ this.clearTimers();
90
+ this._state = gcDefinitions_1.UnreferencedState.Active;
91
+ }
92
+ }
93
+ exports.UnreferencedStateTracker = UnreferencedStateTracker;
94
+ //# sourceMappingURL=gcUnreferencedStateTracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gcUnreferencedStateTracker.js","sourceRoot":"","sources":["../../src/gc/gcUnreferencedStateTracker.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA6D;AAC7D,mDAAoD;AAEpD,+FAA+F;AAC/F,MAAM,yBAA0B,SAAQ,oBAAK;IAC5C,YAA6B,QAAoB;QAChD,2FAA2F;QAC3F,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE;YACb,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;QAJyB,aAAQ,GAAR,QAAQ,CAAY;IAKjD,CAAC;IAED,KAAK,CAAC,SAAiB;QACtB,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,CAAC,SAAiB;QACxB,KAAK,CAAC,OAA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;IAC9D,cAAc,CAAC,2BAAmC;QACxD,MAAM,sBAAsB,GAAG,2BAA2B,GAAG,IAAI,CAAC,uBAAuB,CAAC;QAE1F,sGAAsG;QACtG,IAAI,IAAI,CAAC,cAAc,KAAK,SAAS,IAAI,sBAAsB,IAAI,IAAI,CAAC,cAAc,EAAE;YACvF,IAAI,CAAC,MAAM,GAAG,iCAAiB,CAAC,UAAU,CAAC;YAC3C,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,OAAO;SACP;QAED,yGAAyG;QACzG,6CAA6C;QAC7C,IAAI,sBAAsB,IAAI,IAAI,CAAC,iBAAiB,EAAE;YACrD,IAAI,CAAC,MAAM,GAAG,iCAAiB,CAAC,QAAQ,CAAC;YACzC,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;YAE3B,IAAI,IAAI,CAAC,cAAc,KAAK,SAAS,EAAE;gBACtC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,GAAG,sBAAsB,CAAC,CAAC;aACtE;YACD,OAAO;SACP;QAED,qGAAqG;QACrG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,GAAG,sBAAsB,CAAC,CAAC;IAC7E,CAAC;IAEO,WAAW;QAClB,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAC3B,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;IAED,gFAAgF;IACzE,YAAY;QAClB,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,iCAAiB,CAAC,MAAM,CAAC;IACxC,CAAC;CACD;AAnFD,4DAmFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, Timer } from \"@fluidframework/common-utils\";\nimport { UnreferencedState } from \"./gcDefinitions\";\n\n/** A wrapper around common-utils Timer that requires the timeout when calling start/restart */\nclass TimerWithNoDefaultTimeout extends Timer {\n\tconstructor(private readonly callback: () => void) {\n\t\t// The default timeout/handlers will never be used since start/restart pass overrides below\n\t\tsuper(0, () => {\n\t\t\tthrow new Error(\"DefaultHandler should not be used\");\n\t\t});\n\t}\n\n\tstart(timeoutMs: number) {\n\t\tsuper.start(timeoutMs, this.callback);\n\t}\n\n\trestart(timeoutMs: number): void {\n\t\tsuper.restart(timeoutMs, this.callback);\n\t}\n}\n\n/**\n * Helper class that tracks the state of an unreferenced node such as the time it was unreferenced and if it can\n * be deleted by the sweep phase.\n */\nexport class UnreferencedStateTracker {\n\tprivate _state: UnreferencedState = UnreferencedState.Active;\n\tpublic get state(): UnreferencedState {\n\t\treturn this._state;\n\t}\n\n\t/** Timer to indicate when an unreferenced object is considered Inactive */\n\tprivate readonly inactiveTimer: TimerWithNoDefaultTimeout;\n\t/** Timer to indicate when an unreferenced object is Sweep-Ready */\n\tprivate readonly sweepTimer: TimerWithNoDefaultTimeout;\n\n\tconstructor(\n\t\tpublic readonly unreferencedTimestampMs: number,\n\t\t/** The time after which node transitions to Inactive state. */\n\t\tprivate readonly inactiveTimeoutMs: number,\n\t\t/** The current reference timestamp used to track how long this node has been unreferenced for. */\n\t\tcurrentReferenceTimestampMs: number,\n\t\t/** The time after which node transitions to SweepReady state; undefined if session expiry is disabled. */\n\t\tprivate readonly sweepTimeoutMs: number | undefined,\n\t) {\n\t\tif (this.sweepTimeoutMs !== undefined) {\n\t\t\tassert(\n\t\t\t\tthis.inactiveTimeoutMs <= this.sweepTimeoutMs,\n\t\t\t\t0x3b0 /* inactive timeout must not be greater than the sweep timeout */,\n\t\t\t);\n\t\t}\n\n\t\tthis.sweepTimer = new TimerWithNoDefaultTimeout(() => {\n\t\t\tthis._state = UnreferencedState.SweepReady;\n\t\t\tassert(\n\t\t\t\t!this.inactiveTimer.hasTimer,\n\t\t\t\t0x3b1 /* inactiveTimer still running after sweepTimer fired! */,\n\t\t\t);\n\t\t});\n\n\t\tthis.inactiveTimer = new TimerWithNoDefaultTimeout(() => {\n\t\t\tthis._state = UnreferencedState.Inactive;\n\n\t\t\t// After the node becomes inactive, start the sweep timer after which the node will be ready for sweep.\n\t\t\tif (this.sweepTimeoutMs !== undefined) {\n\t\t\t\tthis.sweepTimer.restart(this.sweepTimeoutMs - this.inactiveTimeoutMs);\n\t\t\t}\n\t\t});\n\t\tthis.updateTracking(currentReferenceTimestampMs);\n\t}\n\n\t/* Updates the unreferenced state based on the provided timestamp. */\n\tpublic updateTracking(currentReferenceTimestampMs: number) {\n\t\tconst unreferencedDurationMs = currentReferenceTimestampMs - this.unreferencedTimestampMs;\n\n\t\t// If the node has been unreferenced for sweep timeout amount of time, update the state to SweepReady.\n\t\tif (this.sweepTimeoutMs !== undefined && unreferencedDurationMs >= this.sweepTimeoutMs) {\n\t\t\tthis._state = UnreferencedState.SweepReady;\n\t\t\tthis.clearTimers();\n\t\t\treturn;\n\t\t}\n\n\t\t// If the node has been unreferenced for inactive timeoutMs amount of time, update the state to inactive.\n\t\t// Also, start a timer for the sweep timeout.\n\t\tif (unreferencedDurationMs >= this.inactiveTimeoutMs) {\n\t\t\tthis._state = UnreferencedState.Inactive;\n\t\t\tthis.inactiveTimer.clear();\n\n\t\t\tif (this.sweepTimeoutMs !== undefined) {\n\t\t\t\tthis.sweepTimer.restart(this.sweepTimeoutMs - unreferencedDurationMs);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// The node is still active. Ensure the inactive timer is running with the proper remaining duration.\n\t\tthis.inactiveTimer.restart(this.inactiveTimeoutMs - unreferencedDurationMs);\n\t}\n\n\tprivate clearTimers() {\n\t\tthis.inactiveTimer.clear();\n\t\tthis.sweepTimer.clear();\n\t}\n\n\t/** Stop tracking this node. Reset the unreferenced timers and state, if any. */\n\tpublic stopTracking() {\n\t\tthis.clearTimers();\n\t\tthis._state = UnreferencedState.Active;\n\t}\n}\n"]}
@@ -0,0 +1,11 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { GarbageCollector } from "./garbageCollection";
6
+ export { currentGCVersion, defaultInactiveTimeoutMs, defaultSessionExpiryDurationMs, disableSweepLogKey, GCNodeType, gcTestModeKey, gcTombstoneGenerationOptionName, GCVersion, gcVersionUpgradeToV2Key, IGarbageCollectionRuntime, IGarbageCollector, IGarbageCollectorCreateParams, IGCMetadata, IGCStats, oneDayMs, runGCKey, runSessionExpiryKey, runSweepKey, stableGCVersion, sweepAttachmentBlobsKey, sweepDatastoresKey, throwOnTombstoneLoadKey, throwOnTombstoneUsageKey, UnreferencedState, } from "./gcDefinitions";
7
+ export { sendGCUnexpectedUsageEvent, shouldAllowGcTombstoneEnforcement } from "./gcHelpers";
8
+ export { GCSummaryStateTracker } from "./gcSummaryStateTracker";
9
+ export { skipClosureForXDaysKey, closuresMapLocalStorageKey, SweepReadyUsageDetectionHandler, } from "./gcSweepReadyUsageDetection";
10
+ export { UnreferencedStateTracker } from "./gcUnreferencedStateTracker";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gc/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EACN,gBAAgB,EAChB,wBAAwB,EACxB,8BAA8B,EAC9B,kBAAkB,EAClB,UAAU,EACV,aAAa,EACb,+BAA+B,EAC/B,SAAS,EACT,uBAAuB,EACvB,yBAAyB,EACzB,iBAAiB,EACjB,6BAA6B,EAC7B,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,0BAA0B,EAAE,iCAAiC,EAAE,MAAM,aAAa,CAAC;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EACN,sBAAsB,EACtB,0BAA0B,EAC1B,+BAA+B,GAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC"}