@fluidframework/datastore 2.0.0-internal.3.0.5 → 2.0.0-internal.3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/.eslintrc.js +5 -7
  2. package/.mocharc.js +2 -2
  3. package/README.md +3 -0
  4. package/api-extractor.json +2 -2
  5. package/dist/channelContext.d.ts.map +1 -1
  6. package/dist/channelContext.js.map +1 -1
  7. package/dist/channelDeltaConnection.d.ts.map +1 -1
  8. package/dist/channelDeltaConnection.js.map +1 -1
  9. package/dist/channelStorageService.d.ts.map +1 -1
  10. package/dist/channelStorageService.js +1 -3
  11. package/dist/channelStorageService.js.map +1 -1
  12. package/dist/dataStoreRuntime.d.ts +11 -24
  13. package/dist/dataStoreRuntime.d.ts.map +1 -1
  14. package/dist/dataStoreRuntime.js +68 -86
  15. package/dist/dataStoreRuntime.js.map +1 -1
  16. package/dist/fluidHandle.d.ts.map +1 -1
  17. package/dist/fluidHandle.js.map +1 -1
  18. package/dist/localChannelContext.d.ts.map +1 -1
  19. package/dist/localChannelContext.js +9 -5
  20. package/dist/localChannelContext.js.map +1 -1
  21. package/dist/localChannelStorageService.d.ts.map +1 -1
  22. package/dist/localChannelStorageService.js.map +1 -1
  23. package/dist/packageVersion.d.ts +1 -1
  24. package/dist/packageVersion.js +1 -1
  25. package/dist/packageVersion.js.map +1 -1
  26. package/dist/remoteChannelContext.d.ts.map +1 -1
  27. package/dist/remoteChannelContext.js +2 -2
  28. package/dist/remoteChannelContext.js.map +1 -1
  29. package/lib/channelContext.d.ts.map +1 -1
  30. package/lib/channelContext.js.map +1 -1
  31. package/lib/channelDeltaConnection.d.ts.map +1 -1
  32. package/lib/channelDeltaConnection.js.map +1 -1
  33. package/lib/channelStorageService.d.ts.map +1 -1
  34. package/lib/channelStorageService.js +1 -3
  35. package/lib/channelStorageService.js.map +1 -1
  36. package/lib/dataStoreRuntime.d.ts +11 -24
  37. package/lib/dataStoreRuntime.d.ts.map +1 -1
  38. package/lib/dataStoreRuntime.js +71 -89
  39. package/lib/dataStoreRuntime.js.map +1 -1
  40. package/lib/fluidHandle.d.ts.map +1 -1
  41. package/lib/fluidHandle.js.map +1 -1
  42. package/lib/localChannelContext.d.ts.map +1 -1
  43. package/lib/localChannelContext.js +9 -5
  44. package/lib/localChannelContext.js.map +1 -1
  45. package/lib/localChannelStorageService.d.ts.map +1 -1
  46. package/lib/localChannelStorageService.js.map +1 -1
  47. package/lib/packageVersion.d.ts +1 -1
  48. package/lib/packageVersion.js +1 -1
  49. package/lib/packageVersion.js.map +1 -1
  50. package/lib/remoteChannelContext.d.ts.map +1 -1
  51. package/lib/remoteChannelContext.js +2 -2
  52. package/lib/remoteChannelContext.js.map +1 -1
  53. package/package.json +111 -110
  54. package/prettier.config.cjs +1 -1
  55. package/src/channelContext.ts +66 -65
  56. package/src/channelDeltaConnection.ts +50 -44
  57. package/src/channelStorageService.ts +58 -54
  58. package/src/dataStoreRuntime.ts +1122 -1086
  59. package/src/fluidHandle.ts +87 -91
  60. package/src/localChannelContext.ts +302 -255
  61. package/src/localChannelStorageService.ts +47 -45
  62. package/src/packageVersion.ts +1 -1
  63. package/src/remoteChannelContext.ts +300 -291
  64. package/tsconfig.esnext.json +6 -6
  65. package/tsconfig.json +9 -13
@@ -8,308 +8,317 @@ import { assert } from "@fluidframework/common-utils";
8
8
  import { DataCorruptionError } from "@fluidframework/container-utils";
9
9
  import { IFluidHandle } from "@fluidframework/core-interfaces";
10
10
  import {
11
- IChannel,
12
- IChannelAttributes,
13
- IFluidDataStoreRuntime,
14
- IChannelFactory,
11
+ IChannel,
12
+ IChannelAttributes,
13
+ IFluidDataStoreRuntime,
14
+ IChannelFactory,
15
15
  } from "@fluidframework/datastore-definitions";
16
16
  import { IDocumentStorageService } from "@fluidframework/driver-definitions";
17
17
  import { readAndParse } from "@fluidframework/driver-utils";
18
+ import { ISequencedDocumentMessage, ISnapshotTree } from "@fluidframework/protocol-definitions";
18
19
  import {
19
- ISequencedDocumentMessage,
20
- ISnapshotTree,
21
- } from "@fluidframework/protocol-definitions";
22
- import {
23
- CreateChildSummarizerNodeFn,
24
- IFluidDataStoreContext,
25
- IGarbageCollectionData,
26
- IGarbageCollectionDetailsBase,
27
- ISummarizeInternalResult,
28
- ISummarizeResult,
29
- ISummarizerNodeWithGC,
30
- ITelemetryContext,
20
+ CreateChildSummarizerNodeFn,
21
+ IFluidDataStoreContext,
22
+ IGarbageCollectionData,
23
+ IGarbageCollectionDetailsBase,
24
+ ISummarizeInternalResult,
25
+ ISummarizeResult,
26
+ ISummarizerNodeWithGC,
27
+ ITelemetryContext,
31
28
  } from "@fluidframework/runtime-definitions";
32
29
  import { ChildLogger, TelemetryDataTag, ThresholdCounter } from "@fluidframework/telemetry-utils";
33
30
  import {
34
- attributesBlobKey,
35
- createServiceEndpoints,
36
- IChannelContext,
37
- summarizeChannelAsync,
31
+ attributesBlobKey,
32
+ createServiceEndpoints,
33
+ IChannelContext,
34
+ summarizeChannelAsync,
38
35
  } from "./channelContext";
39
36
  import { ChannelDeltaConnection } from "./channelDeltaConnection";
40
37
  import { ChannelStorageService } from "./channelStorageService";
41
38
  import { ISharedObjectRegistry } from "./dataStoreRuntime";
42
39
 
43
40
  export class RemoteChannelContext implements IChannelContext {
44
- private isLoaded = false;
45
- private pending: ISequencedDocumentMessage[] | undefined = [];
46
- private channelP: Promise<IChannel> | undefined;
47
- private channel: IChannel | undefined;
48
- private readonly services: {
49
- readonly deltaConnection: ChannelDeltaConnection;
50
- readonly objectStorage: ChannelStorageService;
51
- };
52
- private readonly summarizerNode: ISummarizerNodeWithGC;
53
- private readonly subLogger: ITelemetryLogger;
54
- private readonly thresholdOpsCounter: ThresholdCounter;
55
- private static readonly pendingOpsCountThreshold = 1000;
56
-
57
- constructor(
58
- private readonly runtime: IFluidDataStoreRuntime,
59
- private readonly dataStoreContext: IFluidDataStoreContext,
60
- storageService: IDocumentStorageService,
61
- submitFn: (content: any, localOpMetadata: unknown) => void,
62
- dirtyFn: (address: string) => void,
63
- addedGCOutboundReferenceFn: (srcHandle: IFluidHandle, outboundHandle: IFluidHandle) => void,
64
- private readonly id: string,
65
- baseSnapshot: ISnapshotTree,
66
- private readonly registry: ISharedObjectRegistry,
67
- extraBlobs: Map<string, ArrayBufferLike> | undefined,
68
- createSummarizerNode: CreateChildSummarizerNodeFn,
69
- getBaseGCDetails: () => Promise<IGarbageCollectionDetailsBase>,
70
- private readonly attachMessageType?: string,
71
- ) {
72
- assert(!this.id.includes("/"), 0x310 /* Channel context ID cannot contain slashes */);
73
-
74
- this.subLogger = ChildLogger.create(this.runtime.logger, "RemoteChannelContext");
75
-
76
- this.services = createServiceEndpoints(
77
- this.id,
78
- this.dataStoreContext.connected,
79
- submitFn,
80
- () => dirtyFn(this.id),
81
- addedGCOutboundReferenceFn,
82
- storageService,
83
- this.subLogger,
84
- baseSnapshot,
85
- extraBlobs);
86
-
87
- const thisSummarizeInternal =
88
- async (fullTree: boolean, trackState: boolean, telemetryContext?: ITelemetryContext) =>
89
- this.summarizeInternal(fullTree, trackState, telemetryContext);
90
-
91
- this.summarizerNode = createSummarizerNode(
92
- thisSummarizeInternal,
93
- async (fullGC?: boolean) => this.getGCDataInternal(fullGC),
94
- async () => getBaseGCDetails(),
95
- );
96
-
97
- this.thresholdOpsCounter = new ThresholdCounter(
98
- RemoteChannelContext.pendingOpsCountThreshold,
99
- this.subLogger,
100
- );
101
- }
102
-
103
- // eslint-disable-next-line @typescript-eslint/promise-function-async
104
- public getChannel(): Promise<IChannel> {
105
- if (this.channelP === undefined) {
106
- this.channelP = this.loadChannel();
107
- }
108
-
109
- return this.channelP;
110
- }
111
-
112
- public setConnectionState(connected: boolean, clientId?: string) {
113
- // Connection events are ignored if the data store is not yet loaded
114
- if (!this.isLoaded) {
115
- return;
116
- }
117
-
118
- this.services.deltaConnection.setConnectionState(connected);
119
- }
120
-
121
- public applyStashedOp(message: ISequencedDocumentMessage): unknown {
122
- assert(this.isLoaded, 0x194 /* "Remote channel must be loaded when rebasing op" */);
123
- return this.services.deltaConnection.applyStashedOp(message);
124
- }
125
-
126
- public processOp(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void {
127
- this.summarizerNode.invalidate(message.sequenceNumber);
128
-
129
- if (this.isLoaded) {
130
- this.services.deltaConnection.process(message, local, localOpMetadata);
131
- } else {
132
- assert(!local, 0x195 /* "Remote channel must not be local when processing op" */);
133
- assert(this.pending !== undefined, 0x23e /* "pending is undefined" */);
134
- this.pending.push(message);
135
- this.thresholdOpsCounter.sendIfMultiple("StorePendingOps", this.pending.length);
136
- }
137
- }
138
-
139
- public reSubmit(content: any, localOpMetadata: unknown) {
140
- assert(this.isLoaded, 0x196 /* "Remote channel must be loaded when resubmitting op" */);
141
-
142
- this.services.deltaConnection.reSubmit(content, localOpMetadata);
143
- }
144
-
145
- public rollback(content: any, localOpMetadata: unknown) {
146
- assert(this.isLoaded, 0x2f0 /* "Remote channel must be loaded when rolling back op" */);
147
-
148
- this.services.deltaConnection.rollback(content, localOpMetadata);
149
- }
150
-
151
- /**
152
- * Returns a summary at the current sequence number.
153
- * @param fullTree - true to bypass optimizations and force a full summary tree
154
- * @param trackState - This tells whether we should track state from this summary.
155
- * @param telemetryContext - summary data passed through the layers for telemetry purposes
156
- */
157
- public async summarize(
158
- fullTree: boolean = false,
159
- trackState: boolean = true,
160
- telemetryContext?: ITelemetryContext,
161
- ): Promise<ISummarizeResult> {
162
- return this.summarizerNode.summarize(fullTree, trackState, telemetryContext);
163
- }
164
-
165
- private async summarizeInternal(
166
- fullTree: boolean,
167
- trackState: boolean,
168
- telemetryContext?: ITelemetryContext,
169
- ): Promise<ISummarizeInternalResult> {
170
- const channel = await this.getChannel();
171
- const summarizeResult = await summarizeChannelAsync(channel, fullTree, trackState, telemetryContext);
172
- return { ...summarizeResult, id: this.id };
173
- }
174
-
175
- private async loadChannel(): Promise<IChannel> {
176
- assert(!this.isLoaded, 0x197 /* "Remote channel must not already be loaded when loading" */);
177
-
178
- let attributes: IChannelAttributes | undefined;
179
- if (await this.services.objectStorage.contains(attributesBlobKey)) {
180
- attributes = await readAndParse<IChannelAttributes | undefined>(
181
- this.services.objectStorage,
182
- attributesBlobKey);
183
- }
184
-
185
- let factory: IChannelFactory | undefined;
186
- // this is a backward compatibility case where
187
- // the attach message doesn't include
188
- // the attributes. Since old attach messages
189
- // will not have attributes we need to keep
190
- // this as long as we support old attach messages
191
- if (attributes === undefined) {
192
- if (this.attachMessageType === undefined) {
193
- // TODO: dataStoreId may require a different tag from PackageData #7488
194
- throw new DataCorruptionError("channelTypeNotAvailable", {
195
- channelId: {
196
- value: this.id,
197
- tag: TelemetryDataTag.CodeArtifact,
198
- },
199
- dataStoreId: {
200
- value: this.dataStoreContext.id,
201
- tag: TelemetryDataTag.CodeArtifact,
202
- },
203
- dataStorePackagePath: this.dataStoreContext.packagePath.join("/"),
204
- });
205
- }
206
- factory = this.registry.get(this.attachMessageType);
207
- if (factory === undefined) {
208
- // TODO: dataStoreId may require a different tag from PackageData #7488
209
- throw new DataCorruptionError("channelFactoryNotRegisteredForAttachMessageType", {
210
- channelId: {
211
- value: this.id,
212
- tag: TelemetryDataTag.CodeArtifact,
213
- },
214
- dataStoreId: {
215
- value: this.dataStoreContext.id,
216
- tag: TelemetryDataTag.CodeArtifact,
217
- },
218
- dataStorePackagePath: this.dataStoreContext.packagePath.join("/"),
219
- channelFactoryType: this.attachMessageType,
220
- });
221
- }
222
- attributes = factory.attributes;
223
- } else {
224
- factory = this.registry.get(attributes.type);
225
- if (factory === undefined) {
226
- // TODO: dataStoreId may require a different tag from PackageData #7488
227
- throw new DataCorruptionError("channelFactoryNotRegisteredForGivenType", {
228
- channelId: {
229
- value: this.id,
230
- tag: TelemetryDataTag.CodeArtifact,
231
- },
232
- dataStoreId: {
233
- value: this.dataStoreContext.id,
234
- tag: TelemetryDataTag.CodeArtifact,
235
- },
236
- dataStorePackagePath: this.dataStoreContext.packagePath.join("/"),
237
- channelFactoryType: attributes.type,
238
- });
239
- }
240
- }
241
-
242
- // Compare snapshot version to collaborative object version
243
- if (attributes.snapshotFormatVersion !== undefined
244
- && attributes.snapshotFormatVersion !== factory.attributes.snapshotFormatVersion) {
245
- this.subLogger.sendTelemetryEvent(
246
- {
247
- eventName: "ChannelAttributesVersionMismatch",
248
- channelType: { value: attributes.type, tag: TelemetryDataTag.CodeArtifact },
249
- channelSnapshotVersion: {
250
- value: `${attributes.snapshotFormatVersion}@${attributes.packageVersion}`,
251
- tag: TelemetryDataTag.CodeArtifact,
252
- },
253
- channelCodeVersion: {
254
- value: `${factory.attributes.snapshotFormatVersion}@${factory.attributes.packageVersion}`,
255
- tag: TelemetryDataTag.CodeArtifact,
256
- },
257
- },
258
- );
259
- }
260
-
261
- const channel = await factory.load(
262
- this.runtime,
263
- this.id,
264
- this.services,
265
- attributes);
266
-
267
- // Send all pending messages to the channel
268
- assert(this.pending !== undefined, 0x23f /* "pending undefined" */);
269
- for (const message of this.pending) {
270
- this.services.deltaConnection.process(message, false, undefined /* localOpMetadata */);
271
- }
272
- this.thresholdOpsCounter.send("ProcessPendingOps", this.pending.length);
273
-
274
- // Commit changes.
275
- this.channel = channel;
276
- this.pending = undefined;
277
- this.isLoaded = true;
278
-
279
- // Because have some await between we created the service and here, the connection state might have changed
280
- // and we don't propagate the connection state when we are not loaded. So we have to set it again here.
281
- this.services.deltaConnection.setConnectionState(this.dataStoreContext.connected);
282
- return this.channel;
283
- }
284
-
285
- /**
286
- * Returns the data used for garbage collection. This includes a list of GC nodes that represent this context.
287
- * Each node has a set of outbound routes to other GC nodes in the document.
288
- * If there is no new data in this context since the last summary, previous GC data is used.
289
- * If there is new data, the GC data is generated again (by calling getGCDataInternal).
290
- * @param fullGC - true to bypass optimizations and force full generation of GC data.
291
- */
292
- public async getGCData(fullGC: boolean = false): Promise<IGarbageCollectionData> {
293
- return this.summarizerNode.getGCData(fullGC);
294
- }
295
-
296
- /**
297
- * Generates the data used for garbage collection. This is called when there is new data since last summary. It
298
- * loads the context and calls into the channel to get its GC data.
299
- * @param fullGC - true to bypass optimizations and force full generation of GC data.
300
- */
301
- private async getGCDataInternal(fullGC: boolean = false): Promise<IGarbageCollectionData> {
302
- const channel = await this.getChannel();
303
- return channel.getGCData(fullGC);
304
- }
305
-
306
- public updateUsedRoutes(usedRoutes: string[]) {
307
- /**
308
- * Currently, DDSes are always considered referenced and are not garbage collected. Update the summarizer node's
309
- * used routes to contain a route to this channel context.
310
- * Once we have GC at DDS level, this will be updated to use the passed usedRoutes. See -
311
- * https://github.com/microsoft/FluidFramework/issues/4611
312
- */
313
- this.summarizerNode.updateUsedRoutes([""]);
314
- }
41
+ private isLoaded = false;
42
+ private pending: ISequencedDocumentMessage[] | undefined = [];
43
+ private channelP: Promise<IChannel> | undefined;
44
+ private channel: IChannel | undefined;
45
+ private readonly services: {
46
+ readonly deltaConnection: ChannelDeltaConnection;
47
+ readonly objectStorage: ChannelStorageService;
48
+ };
49
+ private readonly summarizerNode: ISummarizerNodeWithGC;
50
+ private readonly subLogger: ITelemetryLogger;
51
+ private readonly thresholdOpsCounter: ThresholdCounter;
52
+ private static readonly pendingOpsCountThreshold = 1000;
53
+
54
+ constructor(
55
+ private readonly runtime: IFluidDataStoreRuntime,
56
+ private readonly dataStoreContext: IFluidDataStoreContext,
57
+ storageService: IDocumentStorageService,
58
+ submitFn: (content: any, localOpMetadata: unknown) => void,
59
+ dirtyFn: (address: string) => void,
60
+ addedGCOutboundReferenceFn: (srcHandle: IFluidHandle, outboundHandle: IFluidHandle) => void,
61
+ private readonly id: string,
62
+ baseSnapshot: ISnapshotTree,
63
+ private readonly registry: ISharedObjectRegistry,
64
+ extraBlobs: Map<string, ArrayBufferLike> | undefined,
65
+ createSummarizerNode: CreateChildSummarizerNodeFn,
66
+ getBaseGCDetails: () => Promise<IGarbageCollectionDetailsBase>,
67
+ private readonly attachMessageType?: string,
68
+ ) {
69
+ assert(!this.id.includes("/"), 0x310 /* Channel context ID cannot contain slashes */);
70
+
71
+ this.subLogger = ChildLogger.create(this.runtime.logger, "RemoteChannelContext");
72
+
73
+ this.services = createServiceEndpoints(
74
+ this.id,
75
+ this.dataStoreContext.connected,
76
+ submitFn,
77
+ () => dirtyFn(this.id),
78
+ addedGCOutboundReferenceFn,
79
+ storageService,
80
+ this.subLogger,
81
+ baseSnapshot,
82
+ extraBlobs,
83
+ );
84
+
85
+ const thisSummarizeInternal = async (
86
+ fullTree: boolean,
87
+ trackState: boolean,
88
+ telemetryContext?: ITelemetryContext,
89
+ ) => this.summarizeInternal(fullTree, trackState, telemetryContext);
90
+
91
+ this.summarizerNode = createSummarizerNode(
92
+ thisSummarizeInternal,
93
+ async (fullGC?: boolean) => this.getGCDataInternal(fullGC),
94
+ async () => getBaseGCDetails(),
95
+ );
96
+
97
+ this.thresholdOpsCounter = new ThresholdCounter(
98
+ RemoteChannelContext.pendingOpsCountThreshold,
99
+ this.subLogger,
100
+ );
101
+ }
102
+
103
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
104
+ public getChannel(): Promise<IChannel> {
105
+ if (this.channelP === undefined) {
106
+ this.channelP = this.loadChannel();
107
+ }
108
+
109
+ return this.channelP;
110
+ }
111
+
112
+ public setConnectionState(connected: boolean, clientId?: string) {
113
+ // Connection events are ignored if the data store is not yet loaded
114
+ if (!this.isLoaded) {
115
+ return;
116
+ }
117
+
118
+ this.services.deltaConnection.setConnectionState(connected);
119
+ }
120
+
121
+ public applyStashedOp(message: ISequencedDocumentMessage): unknown {
122
+ assert(this.isLoaded, 0x194 /* "Remote channel must be loaded when rebasing op" */);
123
+ return this.services.deltaConnection.applyStashedOp(message);
124
+ }
125
+
126
+ public processOp(
127
+ message: ISequencedDocumentMessage,
128
+ local: boolean,
129
+ localOpMetadata: unknown,
130
+ ): void {
131
+ this.summarizerNode.invalidate(message.sequenceNumber);
132
+
133
+ if (this.isLoaded) {
134
+ this.services.deltaConnection.process(message, local, localOpMetadata);
135
+ } else {
136
+ assert(!local, 0x195 /* "Remote channel must not be local when processing op" */);
137
+ assert(this.pending !== undefined, 0x23e /* "pending is undefined" */);
138
+ this.pending.push(message);
139
+ this.thresholdOpsCounter.sendIfMultiple("StorePendingOps", this.pending.length);
140
+ }
141
+ }
142
+
143
+ public reSubmit(content: any, localOpMetadata: unknown) {
144
+ assert(this.isLoaded, 0x196 /* "Remote channel must be loaded when resubmitting op" */);
145
+
146
+ this.services.deltaConnection.reSubmit(content, localOpMetadata);
147
+ }
148
+
149
+ public rollback(content: any, localOpMetadata: unknown) {
150
+ assert(this.isLoaded, 0x2f0 /* "Remote channel must be loaded when rolling back op" */);
151
+
152
+ this.services.deltaConnection.rollback(content, localOpMetadata);
153
+ }
154
+
155
+ /**
156
+ * Returns a summary at the current sequence number.
157
+ * @param fullTree - true to bypass optimizations and force a full summary tree
158
+ * @param trackState - This tells whether we should track state from this summary.
159
+ * @param telemetryContext - summary data passed through the layers for telemetry purposes
160
+ */
161
+ public async summarize(
162
+ fullTree: boolean = false,
163
+ trackState: boolean = true,
164
+ telemetryContext?: ITelemetryContext,
165
+ ): Promise<ISummarizeResult> {
166
+ return this.summarizerNode.summarize(fullTree, trackState, telemetryContext);
167
+ }
168
+
169
+ private async summarizeInternal(
170
+ fullTree: boolean,
171
+ trackState: boolean,
172
+ telemetryContext?: ITelemetryContext,
173
+ ): Promise<ISummarizeInternalResult> {
174
+ const channel = await this.getChannel();
175
+ const summarizeResult = await summarizeChannelAsync(
176
+ channel,
177
+ fullTree,
178
+ trackState,
179
+ telemetryContext,
180
+ );
181
+ return { ...summarizeResult, id: this.id };
182
+ }
183
+
184
+ private async loadChannel(): Promise<IChannel> {
185
+ assert(
186
+ !this.isLoaded,
187
+ 0x197 /* "Remote channel must not already be loaded when loading" */,
188
+ );
189
+
190
+ let attributes: IChannelAttributes | undefined;
191
+ if (await this.services.objectStorage.contains(attributesBlobKey)) {
192
+ attributes = await readAndParse<IChannelAttributes | undefined>(
193
+ this.services.objectStorage,
194
+ attributesBlobKey,
195
+ );
196
+ }
197
+
198
+ let factory: IChannelFactory | undefined;
199
+ // this is a backward compatibility case where
200
+ // the attach message doesn't include
201
+ // the attributes. Since old attach messages
202
+ // will not have attributes we need to keep
203
+ // this as long as we support old attach messages
204
+ if (attributes === undefined) {
205
+ if (this.attachMessageType === undefined) {
206
+ // TODO: dataStoreId may require a different tag from PackageData #7488
207
+ throw new DataCorruptionError("channelTypeNotAvailable", {
208
+ channelId: {
209
+ value: this.id,
210
+ tag: TelemetryDataTag.CodeArtifact,
211
+ },
212
+ dataStoreId: {
213
+ value: this.dataStoreContext.id,
214
+ tag: TelemetryDataTag.CodeArtifact,
215
+ },
216
+ dataStorePackagePath: this.dataStoreContext.packagePath.join("/"),
217
+ });
218
+ }
219
+ factory = this.registry.get(this.attachMessageType);
220
+ if (factory === undefined) {
221
+ // TODO: dataStoreId may require a different tag from PackageData #7488
222
+ throw new DataCorruptionError("channelFactoryNotRegisteredForAttachMessageType", {
223
+ channelId: {
224
+ value: this.id,
225
+ tag: TelemetryDataTag.CodeArtifact,
226
+ },
227
+ dataStoreId: {
228
+ value: this.dataStoreContext.id,
229
+ tag: TelemetryDataTag.CodeArtifact,
230
+ },
231
+ dataStorePackagePath: this.dataStoreContext.packagePath.join("/"),
232
+ channelFactoryType: this.attachMessageType,
233
+ });
234
+ }
235
+ attributes = factory.attributes;
236
+ } else {
237
+ factory = this.registry.get(attributes.type);
238
+ if (factory === undefined) {
239
+ // TODO: dataStoreId may require a different tag from PackageData #7488
240
+ throw new DataCorruptionError("channelFactoryNotRegisteredForGivenType", {
241
+ channelId: {
242
+ value: this.id,
243
+ tag: TelemetryDataTag.CodeArtifact,
244
+ },
245
+ dataStoreId: {
246
+ value: this.dataStoreContext.id,
247
+ tag: TelemetryDataTag.CodeArtifact,
248
+ },
249
+ dataStorePackagePath: this.dataStoreContext.packagePath.join("/"),
250
+ channelFactoryType: attributes.type,
251
+ });
252
+ }
253
+ }
254
+
255
+ // Compare snapshot version to collaborative object version
256
+ if (
257
+ attributes.snapshotFormatVersion !== undefined &&
258
+ attributes.snapshotFormatVersion !== factory.attributes.snapshotFormatVersion
259
+ ) {
260
+ this.subLogger.sendTelemetryEvent({
261
+ eventName: "ChannelAttributesVersionMismatch",
262
+ channelType: { value: attributes.type, tag: TelemetryDataTag.CodeArtifact },
263
+ channelSnapshotVersion: {
264
+ value: `${attributes.snapshotFormatVersion}@${attributes.packageVersion}`,
265
+ tag: TelemetryDataTag.CodeArtifact,
266
+ },
267
+ channelCodeVersion: {
268
+ value: `${factory.attributes.snapshotFormatVersion}@${factory.attributes.packageVersion}`,
269
+ tag: TelemetryDataTag.CodeArtifact,
270
+ },
271
+ });
272
+ }
273
+
274
+ const channel = await factory.load(this.runtime, this.id, this.services, attributes);
275
+
276
+ // Send all pending messages to the channel
277
+ assert(this.pending !== undefined, 0x23f /* "pending undefined" */);
278
+ for (const message of this.pending) {
279
+ this.services.deltaConnection.process(message, false, undefined /* localOpMetadata */);
280
+ }
281
+ this.thresholdOpsCounter.send("ProcessPendingOps", this.pending.length);
282
+
283
+ // Commit changes.
284
+ this.channel = channel;
285
+ this.pending = undefined;
286
+ this.isLoaded = true;
287
+
288
+ // Because have some await between we created the service and here, the connection state might have changed
289
+ // and we don't propagate the connection state when we are not loaded. So we have to set it again here.
290
+ this.services.deltaConnection.setConnectionState(this.dataStoreContext.connected);
291
+ return this.channel;
292
+ }
293
+
294
+ /**
295
+ * Returns the data used for garbage collection. This includes a list of GC nodes that represent this context.
296
+ * Each node has a set of outbound routes to other GC nodes in the document.
297
+ * If there is no new data in this context since the last summary, previous GC data is used.
298
+ * If there is new data, the GC data is generated again (by calling getGCDataInternal).
299
+ * @param fullGC - true to bypass optimizations and force full generation of GC data.
300
+ */
301
+ public async getGCData(fullGC: boolean = false): Promise<IGarbageCollectionData> {
302
+ return this.summarizerNode.getGCData(fullGC);
303
+ }
304
+
305
+ /**
306
+ * Generates the data used for garbage collection. This is called when there is new data since last summary. It
307
+ * loads the context and calls into the channel to get its GC data.
308
+ * @param fullGC - true to bypass optimizations and force full generation of GC data.
309
+ */
310
+ private async getGCDataInternal(fullGC: boolean = false): Promise<IGarbageCollectionData> {
311
+ const channel = await this.getChannel();
312
+ return channel.getGCData(fullGC);
313
+ }
314
+
315
+ public updateUsedRoutes(usedRoutes: string[]) {
316
+ /**
317
+ * Currently, DDSes are always considered referenced and are not garbage collected. Update the summarizer node's
318
+ * used routes to contain a route to this channel context.
319
+ * Once we have GC at DDS level, this will be updated to use the passed usedRoutes. See -
320
+ * https://github.com/microsoft/FluidFramework/issues/4611
321
+ */
322
+ this.summarizerNode.updateUsedRoutes([""]);
323
+ }
315
324
  }
@@ -1,7 +1,7 @@
1
1
  {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./lib",
5
- "module": "esnext"
6
- },
7
- }
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./lib",
5
+ "module": "esnext",
6
+ },
7
+ }