@fluidframework/runtime-utils 1.4.0-121020 → 2.0.0-dev-rc.1.0.0.225277

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 (188) hide show
  1. package/.eslintrc.js +5 -7
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +191 -0
  4. package/README.md +68 -1
  5. package/api-extractor-esm.json +4 -0
  6. package/api-extractor-lint.json +4 -0
  7. package/api-extractor.json +2 -2
  8. package/api-report/runtime-utils.api.md +201 -0
  9. package/dist/{dataStoreHandleContextUtils.js → dataStoreHandleContextUtils.cjs} +5 -2
  10. package/dist/dataStoreHandleContextUtils.cjs.map +1 -0
  11. package/dist/dataStoreHandleContextUtils.d.ts +1 -0
  12. package/dist/dataStoreHandleContextUtils.d.ts.map +1 -1
  13. package/dist/{dataStoreHelpers.js → dataStoreHelpers.cjs} +44 -25
  14. package/dist/dataStoreHelpers.cjs.map +1 -0
  15. package/dist/dataStoreHelpers.d.ts +23 -4
  16. package/dist/dataStoreHelpers.d.ts.map +1 -1
  17. package/dist/index.cjs +44 -0
  18. package/dist/index.cjs.map +1 -0
  19. package/dist/index.d.ts +9 -9
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/{objectstoragepartition.js → objectstoragepartition.cjs} +4 -3
  22. package/dist/objectstoragepartition.cjs.map +1 -0
  23. package/dist/objectstoragepartition.d.ts +1 -0
  24. package/dist/objectstoragepartition.d.ts.map +1 -1
  25. package/dist/{objectstorageutils.js → objectstorageutils.cjs} +11 -15
  26. package/dist/objectstorageutils.cjs.map +1 -0
  27. package/dist/objectstorageutils.d.ts +6 -0
  28. package/dist/objectstorageutils.d.ts.map +1 -1
  29. package/dist/{requestParser.js → requestParser.cjs} +7 -11
  30. package/dist/requestParser.cjs.map +1 -0
  31. package/dist/requestParser.d.ts +1 -0
  32. package/dist/requestParser.d.ts.map +1 -1
  33. package/dist/runtime-utils-alpha.d.ts +155 -0
  34. package/dist/runtime-utils-beta.d.ts +103 -0
  35. package/dist/runtime-utils-public.d.ts +103 -0
  36. package/dist/runtime-utils-untrimmed.d.ts +306 -0
  37. package/dist/{runtimeFactoryHelper.js → runtimeFactoryHelper.cjs} +11 -12
  38. package/dist/runtimeFactoryHelper.cjs.map +1 -0
  39. package/dist/runtimeFactoryHelper.d.ts +4 -1
  40. package/dist/runtimeFactoryHelper.d.ts.map +1 -1
  41. package/dist/{summaryUtils.js → summaryUtils.cjs} +138 -34
  42. package/dist/summaryUtils.cjs.map +1 -0
  43. package/dist/summaryUtils.d.ts +66 -4
  44. package/dist/summaryUtils.d.ts.map +1 -1
  45. package/dist/tsdoc-metadata.json +11 -0
  46. package/dist/unpackUsedRoutes.cjs +34 -0
  47. package/dist/unpackUsedRoutes.cjs.map +1 -0
  48. package/dist/unpackUsedRoutes.d.ts +12 -0
  49. package/dist/unpackUsedRoutes.d.ts.map +1 -0
  50. package/dist/{utils.js → utils.cjs} +2 -1
  51. package/dist/utils.cjs.map +1 -0
  52. package/dist/utils.d.ts +7 -2
  53. package/dist/utils.d.ts.map +1 -1
  54. package/lib/{dataStoreHandleContextUtils.d.ts → dataStoreHandleContextUtils.d.mts} +2 -1
  55. package/lib/dataStoreHandleContextUtils.d.mts.map +1 -0
  56. package/lib/{dataStoreHandleContextUtils.js → dataStoreHandleContextUtils.mjs} +5 -2
  57. package/lib/dataStoreHandleContextUtils.mjs.map +1 -0
  58. package/lib/{dataStoreHelpers.d.ts → dataStoreHelpers.d.mts} +24 -5
  59. package/lib/dataStoreHelpers.d.mts.map +1 -0
  60. package/lib/{dataStoreHelpers.js → dataStoreHelpers.mjs} +42 -22
  61. package/lib/dataStoreHelpers.mjs.map +1 -0
  62. package/lib/index.d.mts +14 -0
  63. package/lib/index.d.mts.map +1 -0
  64. package/lib/index.mjs +14 -0
  65. package/lib/index.mjs.map +1 -0
  66. package/lib/{objectstoragepartition.d.ts → objectstoragepartition.d.mts} +2 -1
  67. package/lib/objectstoragepartition.d.mts.map +1 -0
  68. package/lib/{objectstoragepartition.js → objectstoragepartition.mjs} +3 -2
  69. package/lib/objectstoragepartition.mjs.map +1 -0
  70. package/lib/{objectstorageutils.d.ts → objectstorageutils.d.mts} +7 -1
  71. package/lib/objectstorageutils.d.mts.map +1 -0
  72. package/lib/{objectstorageutils.js → objectstorageutils.mjs} +11 -15
  73. package/lib/objectstorageutils.mjs.map +1 -0
  74. package/lib/{requestParser.d.ts → requestParser.d.mts} +2 -5
  75. package/lib/requestParser.d.mts.map +1 -0
  76. package/lib/{requestParser.js → requestParser.mjs} +7 -11
  77. package/lib/requestParser.mjs.map +1 -0
  78. package/lib/runtime-utils-alpha.d.mts +155 -0
  79. package/lib/runtime-utils-beta.d.mts +103 -0
  80. package/lib/runtime-utils-public.d.mts +103 -0
  81. package/lib/runtime-utils-untrimmed.d.mts +306 -0
  82. package/lib/{runtimeFactoryHelper.d.ts → runtimeFactoryHelper.d.mts} +5 -2
  83. package/lib/runtimeFactoryHelper.d.mts.map +1 -0
  84. package/lib/runtimeFactoryHelper.mjs +24 -0
  85. package/lib/runtimeFactoryHelper.mjs.map +1 -0
  86. package/lib/{summaryUtils.d.ts → summaryUtils.d.mts} +67 -5
  87. package/lib/summaryUtils.d.mts.map +1 -0
  88. package/lib/{summaryUtils.js → summaryUtils.mjs} +129 -26
  89. package/lib/summaryUtils.mjs.map +1 -0
  90. package/lib/unpackUsedRoutes.d.mts +12 -0
  91. package/lib/unpackUsedRoutes.d.mts.map +1 -0
  92. package/lib/unpackUsedRoutes.mjs +30 -0
  93. package/lib/unpackUsedRoutes.mjs.map +1 -0
  94. package/lib/{utils.d.ts → utils.d.mts} +8 -3
  95. package/lib/utils.d.mts.map +1 -0
  96. package/lib/{utils.js → utils.mjs} +2 -1
  97. package/lib/utils.mjs.map +1 -0
  98. package/package.json +134 -65
  99. package/prettier.config.cjs +8 -0
  100. package/src/dataStoreHandleContextUtils.ts +24 -16
  101. package/src/dataStoreHelpers.ts +106 -83
  102. package/src/index.ts +31 -9
  103. package/src/objectstoragepartition.ts +18 -14
  104. package/src/objectstorageutils.ts +37 -36
  105. package/src/requestParser.ts +81 -86
  106. package/src/runtimeFactoryHelper.ts +27 -26
  107. package/src/summaryUtils.ts +425 -299
  108. package/src/unpackUsedRoutes.ts +31 -0
  109. package/src/utils.ts +12 -7
  110. package/tsc-multi.test.json +4 -0
  111. package/tsconfig.json +10 -12
  112. package/dist/dataStoreHandleContextUtils.js.map +0 -1
  113. package/dist/dataStoreHelpers.js.map +0 -1
  114. package/dist/index.js +0 -26
  115. package/dist/index.js.map +0 -1
  116. package/dist/objectstoragepartition.js.map +0 -1
  117. package/dist/objectstorageutils.js.map +0 -1
  118. package/dist/packageVersion.d.ts +0 -9
  119. package/dist/packageVersion.d.ts.map +0 -1
  120. package/dist/packageVersion.js +0 -12
  121. package/dist/packageVersion.js.map +0 -1
  122. package/dist/requestParser.js.map +0 -1
  123. package/dist/runtimeFactoryHelper.js.map +0 -1
  124. package/dist/summarizerNode/index.d.ts +0 -8
  125. package/dist/summarizerNode/index.d.ts.map +0 -1
  126. package/dist/summarizerNode/index.js +0 -12
  127. package/dist/summarizerNode/index.js.map +0 -1
  128. package/dist/summarizerNode/summarizerNode.d.ts +0 -139
  129. package/dist/summarizerNode/summarizerNode.d.ts.map +0 -1
  130. package/dist/summarizerNode/summarizerNode.js +0 -480
  131. package/dist/summarizerNode/summarizerNode.js.map +0 -1
  132. package/dist/summarizerNode/summarizerNodeUtils.d.ts +0 -161
  133. package/dist/summarizerNode/summarizerNodeUtils.d.ts.map +0 -1
  134. package/dist/summarizerNode/summarizerNodeUtils.js +0 -225
  135. package/dist/summarizerNode/summarizerNodeUtils.js.map +0 -1
  136. package/dist/summarizerNode/summarizerNodeWithGc.d.ts +0 -133
  137. package/dist/summarizerNode/summarizerNodeWithGc.d.ts.map +0 -1
  138. package/dist/summarizerNode/summarizerNodeWithGc.js +0 -294
  139. package/dist/summarizerNode/summarizerNodeWithGc.js.map +0 -1
  140. package/dist/summaryUtils.js.map +0 -1
  141. package/dist/utils.js.map +0 -1
  142. package/lib/dataStoreHandleContextUtils.d.ts.map +0 -1
  143. package/lib/dataStoreHandleContextUtils.js.map +0 -1
  144. package/lib/dataStoreHelpers.d.ts.map +0 -1
  145. package/lib/dataStoreHelpers.js.map +0 -1
  146. package/lib/index.d.ts +0 -14
  147. package/lib/index.d.ts.map +0 -1
  148. package/lib/index.js +0 -14
  149. package/lib/index.js.map +0 -1
  150. package/lib/objectstoragepartition.d.ts.map +0 -1
  151. package/lib/objectstoragepartition.js.map +0 -1
  152. package/lib/objectstorageutils.d.ts.map +0 -1
  153. package/lib/objectstorageutils.js.map +0 -1
  154. package/lib/packageVersion.d.ts +0 -9
  155. package/lib/packageVersion.d.ts.map +0 -1
  156. package/lib/packageVersion.js +0 -9
  157. package/lib/packageVersion.js.map +0 -1
  158. package/lib/requestParser.d.ts.map +0 -1
  159. package/lib/requestParser.js.map +0 -1
  160. package/lib/runtimeFactoryHelper.d.ts.map +0 -1
  161. package/lib/runtimeFactoryHelper.js +0 -25
  162. package/lib/runtimeFactoryHelper.js.map +0 -1
  163. package/lib/summarizerNode/index.d.ts +0 -8
  164. package/lib/summarizerNode/index.d.ts.map +0 -1
  165. package/lib/summarizerNode/index.js +0 -7
  166. package/lib/summarizerNode/index.js.map +0 -1
  167. package/lib/summarizerNode/summarizerNode.d.ts +0 -139
  168. package/lib/summarizerNode/summarizerNode.d.ts.map +0 -1
  169. package/lib/summarizerNode/summarizerNode.js +0 -475
  170. package/lib/summarizerNode/summarizerNode.js.map +0 -1
  171. package/lib/summarizerNode/summarizerNodeUtils.d.ts +0 -161
  172. package/lib/summarizerNode/summarizerNodeUtils.d.ts.map +0 -1
  173. package/lib/summarizerNode/summarizerNodeUtils.js +0 -216
  174. package/lib/summarizerNode/summarizerNodeUtils.js.map +0 -1
  175. package/lib/summarizerNode/summarizerNodeWithGc.d.ts +0 -133
  176. package/lib/summarizerNode/summarizerNodeWithGc.d.ts.map +0 -1
  177. package/lib/summarizerNode/summarizerNodeWithGc.js +0 -289
  178. package/lib/summarizerNode/summarizerNodeWithGc.js.map +0 -1
  179. package/lib/summaryUtils.d.ts.map +0 -1
  180. package/lib/summaryUtils.js.map +0 -1
  181. package/lib/utils.d.ts.map +0 -1
  182. package/lib/utils.js.map +0 -1
  183. package/src/packageVersion.ts +0 -9
  184. package/src/summarizerNode/index.ts +0 -8
  185. package/src/summarizerNode/summarizerNode.ts +0 -662
  186. package/src/summarizerNode/summarizerNodeUtils.ts +0 -339
  187. package/src/summarizerNode/summarizerNodeWithGc.ts +0 -459
  188. package/tsconfig.esnext.json +0 -7
@@ -1,459 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { ITelemetryLogger } from "@fluidframework/common-definitions";
7
- import { assert, LazyPromise } from "@fluidframework/common-utils";
8
- import { cloneGCData } from "@fluidframework/garbage-collector";
9
- import { ISnapshotTree } from "@fluidframework/protocol-definitions";
10
- import {
11
- CreateChildSummarizerNodeParam,
12
- gcBlobKey,
13
- IGarbageCollectionData,
14
- IGarbageCollectionDetailsBase,
15
- IGarbageCollectionSummaryDetails,
16
- ISummarizeInternalResult,
17
- ISummarizeResult,
18
- ISummarizerNodeConfigWithGC,
19
- ISummarizerNodeWithGC,
20
- SummarizeInternalFn,
21
- ITelemetryContext,
22
- } from "@fluidframework/runtime-definitions";
23
- import { ReadAndParseBlob } from "../utils";
24
- import { SummarizerNode } from "./summarizerNode";
25
- import {
26
- EscapedPath,
27
- ICreateChildDetails,
28
- IInitialSummary,
29
- ISummarizerNodeRootContract,
30
- SummaryNode,
31
- } from "./summarizerNodeUtils";
32
-
33
- export interface IRootSummarizerNodeWithGC extends ISummarizerNodeWithGC, ISummarizerNodeRootContract {}
34
-
35
- // Extend SummaryNode to add used routes tracking to it.
36
- class SummaryNodeWithGC extends SummaryNode {
37
- constructor(
38
- public readonly serializedUsedRoutes: string,
39
- summary: {
40
- readonly referenceSequenceNumber: number;
41
- readonly basePath: EscapedPath | undefined;
42
- readonly localPath: EscapedPath;
43
- additionalPath?: EscapedPath;
44
- },
45
- ) {
46
- super(summary);
47
- }
48
- }
49
-
50
- /**
51
- * Extends the functionality of SummarizerNode to manage this node's garbage collection data:
52
- * - Adds a new API `getGCData` to return GC data of this node.
53
- * - Caches the result of `getGCData` to be used if nothing changes between summaries.
54
- * - Manages the used routes of this node. These are used to identify if this node is referenced in the document
55
- * and to determine if the node's used state changed since last summary.
56
- * - Adds trackState param to summarize. If trackState is false, it bypasses the SummarizerNode and calls
57
- * directly into summarizeInternal method.
58
- */
59
- export class SummarizerNodeWithGC extends SummarizerNode implements IRootSummarizerNodeWithGC {
60
- // Tracks the work-in-progress used routes during summary.
61
- private wipSerializedUsedRoutes: string | undefined;
62
-
63
- // This is the last known used routes of this node as seen by the server as part of a summary.
64
- private referenceUsedRoutes: string[] | undefined;
65
-
66
- // The base GC details of this node used to initialize the GC state.
67
- private readonly baseGCDetailsP: LazyPromise<IGarbageCollectionDetailsBase>;
68
-
69
- // Keeps track of whether we have loaded the base details to ensure that we on;y do it once.
70
- private baseGCDetailsLoaded: boolean = false;
71
-
72
- private gcData: IGarbageCollectionData | undefined;
73
-
74
- // Set used routes to have self route by default. This makes the node referenced by default. This is done to ensure
75
- // that this node is not marked as collected when running GC has been disabled. Once, the option to disable GC is
76
- // removed (from runGC flag in IContainerRuntimeOptions), this should be changed to be have no routes by default.
77
- private usedRoutes: string[] = [""];
78
-
79
- // If this node is marked as unreferenced, the time when it marked as such.
80
- private unreferencedTimestampMs: number | undefined;
81
-
82
- // True if GC is disabled for this node. If so, do not track GC specific state for a summary.
83
- private readonly gcDisabled: boolean;
84
-
85
- /**
86
- * Do not call constructor directly.
87
- * Use createRootSummarizerNodeWithGC to create root node, or createChild to create child nodes.
88
- */
89
- public constructor(
90
- logger: ITelemetryLogger,
91
- private readonly summarizeFn: (
92
- fullTree: boolean,
93
- trackState: boolean,
94
- telemetryContext?: ITelemetryContext,
95
- ) => Promise<ISummarizeInternalResult>,
96
- config: ISummarizerNodeConfigWithGC,
97
- changeSequenceNumber: number,
98
- /** Undefined means created without summary */
99
- latestSummary?: SummaryNode,
100
- initialSummary?: IInitialSummary,
101
- wipSummaryLogger?: ITelemetryLogger,
102
- private readonly getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>,
103
- getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>,
104
- ) {
105
- super(
106
- logger,
107
- async (fullTree: boolean, _trackState: boolean, telemetryContext?: ITelemetryContext) =>
108
- summarizeFn(fullTree, true /* trackState */, telemetryContext),
109
- config,
110
- changeSequenceNumber,
111
- latestSummary,
112
- initialSummary,
113
- wipSummaryLogger,
114
- );
115
-
116
- this.gcDisabled = config.gcDisabled === true;
117
-
118
- this.baseGCDetailsP = new LazyPromise(async () => {
119
- return (await getBaseGCDetailsFn?.()) ?? { usedRoutes: [] };
120
- });
121
- }
122
-
123
- /**
124
- * @deprecated - Renamed to getBaseGCDetails.
125
- */
126
- public getGCSummaryDetails(): IGarbageCollectionSummaryDetails {
127
- return this.getBaseGCDetails();
128
- }
129
-
130
- // Returns the GC details to be added to this node's summary and is used to initialize new nodes' GC state.
131
- public getBaseGCDetails(): IGarbageCollectionDetailsBase {
132
- return {
133
- gcData: this.gcData,
134
- usedRoutes: this.usedRoutes,
135
- unrefTimestamp: this.unreferencedTimestampMs,
136
- };
137
- }
138
-
139
- /**
140
- * Loads state from this node's initial GC summary details. This contains the following data from the last summary
141
- * seen by the server for this client:
142
- * - usedRoutes: This is used to figure out if the used state of this node changed since last summary.
143
- * - gcData: The garbage collection data of this node that is required for running GC.
144
- */
145
- private async loadBaseGCDetails() {
146
- const baseGCDetails = await this.baseGCDetailsP;
147
-
148
- // Possible race - If there were parallel calls to loadBaseGCDetails, we want to make sure that we only update
149
- // the state from the base details only once.
150
- if (this.baseGCDetailsLoaded) {
151
- return;
152
- }
153
- this.baseGCDetailsLoaded = true;
154
-
155
- // If the GC details has GC data, initialize our GC data from it.
156
- if (baseGCDetails.gcData !== undefined) {
157
- this.gcData = cloneGCData(baseGCDetails.gcData);
158
- }
159
- // Sort the used routes because we compare them with the current used routes to check if they changed between
160
- // summaries. Both are sorted so that the order of elements is the same.
161
- this.referenceUsedRoutes = baseGCDetails.usedRoutes?.sort();
162
- this.unreferencedTimestampMs = baseGCDetails.unrefTimestamp;
163
- }
164
-
165
- public async summarize(
166
- fullTree: boolean,
167
- trackState: boolean = true,
168
- telemetryContext?: ITelemetryContext,
169
- ): Promise<ISummarizeResult> {
170
- // If GC is not disabled and we are tracking a summary, GC should have run and updated the used routes for this
171
- // summary by calling updateUsedRoutes which sets wipSerializedUsedRoutes.
172
- if (!this.gcDisabled && this.isTrackingInProgress()) {
173
- assert(this.wipSerializedUsedRoutes !== undefined,
174
- 0x1b1 /* "wip used routes should be set if tracking a summary" */);
175
- }
176
-
177
- // If trackState is true, get summary from base summarizer node which tracks summary state.
178
- // If trackState is false, get summary from summarizeInternal.
179
- return trackState
180
- ? super.summarize(fullTree, true /* trackState */, telemetryContext)
181
- : this.summarizeFn(fullTree, trackState, telemetryContext);
182
- }
183
-
184
- /**
185
- * Returns the GC data of this node. If nothing has changed since last summary, it tries to reuse the data from
186
- * the previous summary. Else, it gets new GC data from the underlying Fluid object.
187
- * @param fullGC - true to bypass optimizations and force full generation of GC data.
188
- */
189
- public async getGCData(fullGC: boolean = false): Promise<IGarbageCollectionData> {
190
- assert(!this.gcDisabled, 0x1b2 /* "Getting GC data should not be called when GC is disabled!" */);
191
- assert(this.getGCDataFn !== undefined, 0x1b3 /* "GC data cannot be retrieved without getGCDataFn" */);
192
-
193
- // Load GC details from the initial summary, if not already loaded. If this is the first time this function is
194
- // called and the node's data has not changed since last summary, the GC data in initial details is returned.
195
- await this.loadBaseGCDetails();
196
-
197
- // If there is no new data since last summary and we have GC data from the previous run, return it. We may not
198
- // have data from previous GC run for clients with older summary format before GC was added. They won't have
199
- // GC details in their initial summary.
200
- if (!fullGC && !this.hasDataChanged() && this.gcData !== undefined) {
201
- return cloneGCData(this.gcData);
202
- }
203
-
204
- const gcData = await this.getGCDataFn(fullGC);
205
- this.gcData = cloneGCData(gcData);
206
- return gcData;
207
- }
208
-
209
- /**
210
- * Called during the start of a summary. Updates the work-in-progress used routes.
211
- */
212
- public startSummary(referenceSequenceNumber: number, summaryLogger: ITelemetryLogger) {
213
- // If GC is disabled, skip setting wip used routes since we should not track GC state.
214
- if (!this.gcDisabled) {
215
- assert(
216
- this.wipSerializedUsedRoutes === undefined,
217
- 0x1b4 /* "We should not already be tracking used routes when to track a new summary" */);
218
- }
219
- super.startSummary(referenceSequenceNumber, summaryLogger);
220
- }
221
-
222
- /**
223
- * Called after summary has been uploaded to the server. Add the work-in-progress state to the pending
224
- * summary queue. We track this until we get an ack from the server for this summary.
225
- */
226
- protected completeSummaryCore(
227
- proposalHandle: string,
228
- parentPath: EscapedPath | undefined,
229
- parentSkipRecursion: boolean,
230
- ) {
231
- let wipSerializedUsedRoutes: string | undefined;
232
- // If GC is disabled, don't set wip used routes.
233
- if (!this.gcDisabled) {
234
- wipSerializedUsedRoutes = this.wipSerializedUsedRoutes;
235
- assert(wipSerializedUsedRoutes !== undefined, 0x1b5 /* "We should have been tracking used routes" */);
236
- }
237
-
238
- super.completeSummaryCore(proposalHandle, parentPath, parentSkipRecursion);
239
-
240
- // If GC is disabled, skip setting pending summary with GC state.
241
- if (!this.gcDisabled) {
242
- const summaryNode = this.pendingSummaries.get(proposalHandle);
243
- if (summaryNode !== undefined) {
244
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
245
- const summaryNodeWithGC = new SummaryNodeWithGC(wipSerializedUsedRoutes!, summaryNode);
246
- this.pendingSummaries.set(proposalHandle, summaryNodeWithGC);
247
- }
248
- }
249
- }
250
-
251
- /**
252
- * Clears the work-in-progress state.
253
- */
254
- public clearSummary() {
255
- this.wipSerializedUsedRoutes = undefined;
256
- super.clearSummary();
257
- }
258
-
259
- /**
260
- * Called when we get an ack from the server for a summary we sent. Update the reference state of this node
261
- * from the state in the pending summary queue.
262
- */
263
- protected refreshLatestSummaryFromPending(
264
- proposalHandle: string,
265
- referenceSequenceNumber: number,
266
- ): void {
267
- // If GC is disabled, skip setting referenced used routes since we are not tracking GC state.
268
- if (!this.gcDisabled) {
269
- const summaryNode = this.pendingSummaries.get(proposalHandle) as SummaryNodeWithGC;
270
- if (summaryNode !== undefined) {
271
- this.referenceUsedRoutes = JSON.parse(summaryNode.serializedUsedRoutes);
272
- }
273
- }
274
-
275
- return super.refreshLatestSummaryFromPending(proposalHandle, referenceSequenceNumber);
276
- }
277
-
278
- /**
279
- * Called when we need to upload the reference state from the given summary. Read the GC blob and get the state
280
- * to upload from it.
281
- */
282
- protected async refreshLatestSummaryFromSnapshot(
283
- referenceSequenceNumber: number,
284
- snapshotTree: ISnapshotTree,
285
- basePath: EscapedPath | undefined,
286
- localPath: EscapedPath,
287
- correlatedSummaryLogger: ITelemetryLogger,
288
- readAndParseBlob: ReadAndParseBlob,
289
- ): Promise<void> {
290
- // If GC is disabled, skip setting referenced used routes since we are not tracking GC state.
291
- if (!this.gcDisabled) {
292
- const gcDetailsBlob = snapshotTree.blobs[gcBlobKey];
293
- if (gcDetailsBlob !== undefined) {
294
- const gcDetails = await readAndParseBlob<IGarbageCollectionDetailsBase>(gcDetailsBlob);
295
-
296
- // Possible re-entrancy. If we have already seen a summary later than this one, ignore it.
297
- if (this.referenceSequenceNumber >= referenceSequenceNumber) {
298
- return;
299
- }
300
-
301
- this.referenceUsedRoutes = gcDetails.usedRoutes;
302
- }
303
- }
304
-
305
- return super.refreshLatestSummaryFromSnapshot(
306
- referenceSequenceNumber,
307
- snapshotTree,
308
- basePath,
309
- localPath,
310
- correlatedSummaryLogger,
311
- readAndParseBlob,
312
- );
313
- }
314
-
315
- /**
316
- * Override the createChild method to return an instance of SummarizerNodeWithGC.
317
- */
318
- public createChild(
319
- /** Summarize function */
320
- summarizeInternalFn: SummarizeInternalFn,
321
- /** Initial id or path part of this node */
322
- id: string,
323
- /**
324
- * Information needed to create the node.
325
- * If it is from a base summary, it will assert that a summary has been seen.
326
- * Attach information if it is created from an attach op.
327
- */
328
- createParam: CreateChildSummarizerNodeParam,
329
- config: ISummarizerNodeConfigWithGC = {},
330
- getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>,
331
- getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>,
332
- ): ISummarizerNodeWithGC {
333
- assert(!this.children.has(id), 0x1b6 /* "Create SummarizerNode child already exists" */);
334
-
335
- const createDetails: ICreateChildDetails = this.getCreateDetailsForChild(id, createParam);
336
- const child = new SummarizerNodeWithGC(
337
- this.defaultLogger,
338
- summarizeInternalFn,
339
- {
340
- ...config,
341
- // Propagate our gcDisabled state to the child if its not explicity specified in child's config.
342
- gcDisabled: config.gcDisabled ?? this.gcDisabled,
343
- },
344
- createDetails.changeSequenceNumber,
345
- createDetails.latestSummary,
346
- createDetails.initialSummary,
347
- this.wipSummaryLogger,
348
- getGCDataFn,
349
- getBaseGCDetailsFn,
350
- );
351
-
352
- // There may be additional state that has to be updated in this child. For example, if a summary is being
353
- // tracked, the child's summary tracking state needs to be updated too.
354
- this.maybeUpdateChildState(child);
355
-
356
- this.children.set(id, child);
357
- return child;
358
- }
359
-
360
- /**
361
- * Deletes the child node with the given id.
362
- */
363
- public deleteChild(id: string): void {
364
- this.children.delete(id);
365
- }
366
-
367
- /**
368
- * Override the getChild method to return an instance of SummarizerNodeWithGC.
369
- */
370
- public getChild(id: string): ISummarizerNodeWithGC | undefined {
371
- return this.children.get(id) as SummarizerNodeWithGC;
372
- }
373
-
374
- public isReferenced(): boolean {
375
- return this.usedRoutes.includes("") || this.usedRoutes.includes("/");
376
- }
377
-
378
- public updateUsedRoutes(usedRoutes: string[], gcTimestamp?: number) {
379
- // Sort the given routes before updating. This will ensure that the routes compared in hasUsedStateChanged()
380
- // are in the same order.
381
- this.usedRoutes = usedRoutes.sort();
382
-
383
- // If GC is not disabled and we are tracking a summary, update the work-in-progress used routes so that it can
384
- // be tracked for this summary.
385
- if (!this.gcDisabled && this.isTrackingInProgress()) {
386
- this.wipSerializedUsedRoutes = JSON.stringify(this.usedRoutes);
387
- }
388
-
389
- if (this.isReferenced()) {
390
- this.unreferencedTimestampMs = undefined;
391
- return;
392
- }
393
-
394
- // If this node just became unreferenced, update its unreferencedTimestampMs.
395
- if (this.unreferencedTimestampMs === undefined) {
396
- this.unreferencedTimestampMs = gcTimestamp;
397
- }
398
- }
399
-
400
- /**
401
- * Override the hasChanged method. If this node data or its used state changed, the node is considered changed.
402
- */
403
- protected hasChanged(): boolean {
404
- return this.hasDataChanged() || this.hasUsedStateChanged();
405
- }
406
-
407
- /**
408
- * This tells whether the data in this node has changed or not.
409
- */
410
- private hasDataChanged(): boolean {
411
- return super.hasChanged();
412
- }
413
-
414
- /**
415
- * This tells whether the used state of this node has changed since last successful summary. If the used routes
416
- * of this node changed, its used state is considered changed. Basically, if this node or any of its child nodes
417
- * was previously used and became unused (or vice versa), its used state has changed.
418
- */
419
- private hasUsedStateChanged(): boolean {
420
- // If GC is disabled, we are not tracking used state, return false.
421
- if (this.gcDisabled) {
422
- return false;
423
- }
424
-
425
- return this.referenceUsedRoutes === undefined ||
426
- JSON.stringify(this.usedRoutes) !== JSON.stringify(this.referenceUsedRoutes);
427
- }
428
- }
429
-
430
- /**
431
- * Creates a root summarizer node with GC functionality built-in.
432
- * @param logger - Logger to use within SummarizerNode
433
- * @param summarizeInternalFn - Function to generate summary
434
- * @param changeSequenceNumber - Sequence number of latest change to new node/subtree
435
- * @param referenceSequenceNumber - Reference sequence number of last acked summary,
436
- * or undefined if not loaded from summary
437
- * @param config - Configure behavior of summarizer node
438
- * @param getGCDataFn - Function to get the GC data of this node
439
- * @param baseGCDetailsP - Function to get the initial GC details of this node
440
- */
441
- export const createRootSummarizerNodeWithGC = (
442
- logger: ITelemetryLogger,
443
- summarizeInternalFn: SummarizeInternalFn,
444
- changeSequenceNumber: number,
445
- referenceSequenceNumber: number | undefined,
446
- config: ISummarizerNodeConfigWithGC = {},
447
- getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>,
448
- getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>,
449
- ): IRootSummarizerNodeWithGC => new SummarizerNodeWithGC(
450
- logger,
451
- summarizeInternalFn,
452
- config,
453
- changeSequenceNumber,
454
- referenceSequenceNumber === undefined ? undefined : SummaryNode.createForRoot(referenceSequenceNumber),
455
- undefined /* initialSummary */,
456
- undefined /* wipSummaryLogger */,
457
- getGCDataFn,
458
- getBaseGCDetailsFn,
459
- );
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./lib",
5
- "module": "esnext"
6
- },
7
- }