@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.
- package/.eslintrc.js +5 -7
- package/.mocharc.js +2 -2
- package/README.md +3 -0
- package/api-extractor.json +2 -2
- package/dist/channelContext.d.ts.map +1 -1
- package/dist/channelContext.js.map +1 -1
- package/dist/channelDeltaConnection.d.ts.map +1 -1
- package/dist/channelDeltaConnection.js.map +1 -1
- package/dist/channelStorageService.d.ts.map +1 -1
- package/dist/channelStorageService.js +1 -3
- package/dist/channelStorageService.js.map +1 -1
- package/dist/dataStoreRuntime.d.ts +11 -24
- package/dist/dataStoreRuntime.d.ts.map +1 -1
- package/dist/dataStoreRuntime.js +68 -86
- package/dist/dataStoreRuntime.js.map +1 -1
- package/dist/fluidHandle.d.ts.map +1 -1
- package/dist/fluidHandle.js.map +1 -1
- package/dist/localChannelContext.d.ts.map +1 -1
- package/dist/localChannelContext.js +9 -5
- package/dist/localChannelContext.js.map +1 -1
- package/dist/localChannelStorageService.d.ts.map +1 -1
- package/dist/localChannelStorageService.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/remoteChannelContext.d.ts.map +1 -1
- package/dist/remoteChannelContext.js +2 -2
- package/dist/remoteChannelContext.js.map +1 -1
- package/lib/channelContext.d.ts.map +1 -1
- package/lib/channelContext.js.map +1 -1
- package/lib/channelDeltaConnection.d.ts.map +1 -1
- package/lib/channelDeltaConnection.js.map +1 -1
- package/lib/channelStorageService.d.ts.map +1 -1
- package/lib/channelStorageService.js +1 -3
- package/lib/channelStorageService.js.map +1 -1
- package/lib/dataStoreRuntime.d.ts +11 -24
- package/lib/dataStoreRuntime.d.ts.map +1 -1
- package/lib/dataStoreRuntime.js +71 -89
- package/lib/dataStoreRuntime.js.map +1 -1
- package/lib/fluidHandle.d.ts.map +1 -1
- package/lib/fluidHandle.js.map +1 -1
- package/lib/localChannelContext.d.ts.map +1 -1
- package/lib/localChannelContext.js +9 -5
- package/lib/localChannelContext.js.map +1 -1
- package/lib/localChannelStorageService.d.ts.map +1 -1
- package/lib/localChannelStorageService.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/remoteChannelContext.d.ts.map +1 -1
- package/lib/remoteChannelContext.js +2 -2
- package/lib/remoteChannelContext.js.map +1 -1
- package/package.json +111 -110
- package/prettier.config.cjs +1 -1
- package/src/channelContext.ts +66 -65
- package/src/channelDeltaConnection.ts +50 -44
- package/src/channelStorageService.ts +58 -54
- package/src/dataStoreRuntime.ts +1122 -1086
- package/src/fluidHandle.ts +87 -91
- package/src/localChannelContext.ts +302 -255
- package/src/localChannelStorageService.ts +47 -45
- package/src/packageVersion.ts +1 -1
- package/src/remoteChannelContext.ts +300 -291
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +9 -13
package/src/dataStoreRuntime.ts
CHANGED
|
@@ -5,1078 +5,1110 @@
|
|
|
5
5
|
|
|
6
6
|
import { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
FluidObject,
|
|
9
|
+
IFluidHandle,
|
|
10
|
+
IFluidHandleContext,
|
|
11
|
+
IRequest,
|
|
12
|
+
IResponse,
|
|
13
13
|
} from "@fluidframework/core-interfaces";
|
|
14
14
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
IAudience,
|
|
16
|
+
IDeltaManager,
|
|
17
|
+
AttachState,
|
|
18
|
+
ILoaderOptions,
|
|
19
19
|
} from "@fluidframework/container-definitions";
|
|
20
20
|
import { DataProcessingError, UsageError } from "@fluidframework/container-utils";
|
|
21
21
|
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
assert,
|
|
23
|
+
Deferred,
|
|
24
|
+
LazyPromise,
|
|
25
|
+
TypedEventEmitter,
|
|
26
|
+
unreachableCase,
|
|
27
27
|
} from "@fluidframework/common-utils";
|
|
28
|
-
import {
|
|
29
|
-
ChildLogger,
|
|
30
|
-
generateStack,
|
|
31
|
-
LoggingError,
|
|
32
|
-
loggerToMonitoringContext,
|
|
33
|
-
MonitoringContext,
|
|
34
|
-
raiseConnectedEvent,
|
|
35
|
-
TelemetryDataTag,
|
|
36
|
-
} from "@fluidframework/telemetry-utils";
|
|
28
|
+
import { ChildLogger, LoggingError, raiseConnectedEvent } from "@fluidframework/telemetry-utils";
|
|
37
29
|
import { buildSnapshotTree } from "@fluidframework/driver-utils";
|
|
38
30
|
import {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
IClientDetails,
|
|
32
|
+
IDocumentMessage,
|
|
33
|
+
ISequencedDocumentMessage,
|
|
34
|
+
SummaryType,
|
|
35
|
+
ISummaryBlob,
|
|
36
|
+
ISummaryTree,
|
|
37
|
+
IQuorumClients,
|
|
46
38
|
} from "@fluidframework/protocol-definitions";
|
|
47
39
|
import {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
40
|
+
BindState,
|
|
41
|
+
CreateSummarizerNodeSource,
|
|
42
|
+
IAttachMessage,
|
|
43
|
+
IEnvelope,
|
|
44
|
+
IFluidDataStoreContext,
|
|
45
|
+
IFluidDataStoreChannel,
|
|
46
|
+
IGarbageCollectionData,
|
|
47
|
+
IGarbageCollectionDetailsBase,
|
|
48
|
+
IInboundSignalMessage,
|
|
49
|
+
ISummaryTreeWithStats,
|
|
50
|
+
VisibilityState,
|
|
51
|
+
ITelemetryContext,
|
|
60
52
|
} from "@fluidframework/runtime-definitions";
|
|
61
53
|
import {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
packagePathToTelemetryProperty,
|
|
54
|
+
convertSnapshotTreeToSummaryTree,
|
|
55
|
+
convertSummaryTreeToITree,
|
|
56
|
+
generateHandleContextPath,
|
|
57
|
+
RequestParser,
|
|
58
|
+
SummaryTreeBuilder,
|
|
59
|
+
create404Response,
|
|
60
|
+
createResponseError,
|
|
61
|
+
exceptionToResponse,
|
|
62
|
+
requestFluidObject,
|
|
72
63
|
} from "@fluidframework/runtime-utils";
|
|
73
64
|
import {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
65
|
+
IChannel,
|
|
66
|
+
IFluidDataStoreRuntime,
|
|
67
|
+
IFluidDataStoreRuntimeEvents,
|
|
68
|
+
IChannelFactory,
|
|
78
69
|
} from "@fluidframework/datastore-definitions";
|
|
79
70
|
import {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
71
|
+
GCDataBuilder,
|
|
72
|
+
removeRouteFromAllNodes,
|
|
73
|
+
unpackChildNodesGCDetails,
|
|
74
|
+
unpackChildNodesUsedRoutes,
|
|
84
75
|
} from "@fluidframework/garbage-collector";
|
|
85
76
|
import { v4 as uuid } from "uuid";
|
|
86
77
|
import { IChannelContext, summarizeChannel } from "./channelContext";
|
|
87
|
-
import {
|
|
78
|
+
import {
|
|
79
|
+
LocalChannelContext,
|
|
80
|
+
LocalChannelContextBase,
|
|
81
|
+
RehydratedLocalChannelContext,
|
|
82
|
+
} from "./localChannelContext";
|
|
88
83
|
import { RemoteChannelContext } from "./remoteChannelContext";
|
|
89
84
|
import { FluidObjectHandle } from "./fluidHandle";
|
|
90
85
|
|
|
91
86
|
export enum DataStoreMessageType {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
// Creates a new channel
|
|
88
|
+
Attach = "attach",
|
|
89
|
+
ChannelOp = "op",
|
|
95
90
|
}
|
|
96
91
|
|
|
97
92
|
export interface ISharedObjectRegistry {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
93
|
+
// TODO consider making this async. A consequence is that either the creation of a distributed data type
|
|
94
|
+
// is async or we need a new API to split the synchronous vs. asynchronous creation.
|
|
95
|
+
get(name: string): IChannelFactory | undefined;
|
|
101
96
|
}
|
|
102
97
|
|
|
103
98
|
/**
|
|
104
99
|
* Base data store class
|
|
105
100
|
*/
|
|
106
|
-
export class FluidDataStoreRuntime
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
101
|
+
export class FluidDataStoreRuntime
|
|
102
|
+
extends TypedEventEmitter<IFluidDataStoreRuntimeEvents>
|
|
103
|
+
implements IFluidDataStoreChannel, IFluidDataStoreRuntime, IFluidHandleContext
|
|
104
|
+
{
|
|
105
|
+
/**
|
|
106
|
+
* @deprecated - Instantiate the class using its constructor instead.
|
|
107
|
+
*
|
|
108
|
+
* Loads the data store runtime
|
|
109
|
+
* @param context - The data store context
|
|
110
|
+
* @param sharedObjectRegistry - The registry of shared objects used by this data store
|
|
111
|
+
* @param existing - If loading from an existing file.
|
|
112
|
+
*/
|
|
113
|
+
public static load(
|
|
114
|
+
context: IFluidDataStoreContext,
|
|
115
|
+
sharedObjectRegistry: ISharedObjectRegistry,
|
|
116
|
+
existing: boolean,
|
|
117
|
+
): FluidDataStoreRuntime {
|
|
118
|
+
return new FluidDataStoreRuntime(
|
|
119
|
+
context,
|
|
120
|
+
sharedObjectRegistry,
|
|
121
|
+
existing,
|
|
122
|
+
async (dataStoreRuntime) => requestFluidObject(dataStoreRuntime, "/"),
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IFluidDataStoreRuntime.entryPoint}
|
|
128
|
+
*/
|
|
129
|
+
public readonly entryPoint?: IFluidHandle<FluidObject>;
|
|
130
|
+
|
|
131
|
+
public get IFluidRouter() {
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public get connected(): boolean {
|
|
136
|
+
return this.dataStoreContext.connected;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public get clientId(): string | undefined {
|
|
140
|
+
return this.dataStoreContext.clientId;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public get clientDetails(): IClientDetails {
|
|
144
|
+
return this.dataStoreContext.clientDetails;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public get isAttached(): boolean {
|
|
148
|
+
return this.attachState !== AttachState.Detached;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
public get attachState(): AttachState {
|
|
152
|
+
return this._attachState;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
public get absolutePath(): string {
|
|
156
|
+
return generateHandleContextPath(this.id, this.routeContext);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public get routeContext(): IFluidHandleContext {
|
|
160
|
+
return this.dataStoreContext.IFluidHandleContext;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
public get IFluidHandleContext() {
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public get rootRoutingContext() {
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
public get channelsRoutingContext() {
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
public get objectsRoutingContext() {
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private _disposed = false;
|
|
178
|
+
public get disposed() {
|
|
179
|
+
return this._disposed;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private readonly contexts = new Map<string, IChannelContext>();
|
|
183
|
+
private readonly contextsDeferred = new Map<string, Deferred<IChannelContext>>();
|
|
184
|
+
private readonly pendingAttach = new Map<string, IAttachMessage>();
|
|
185
|
+
|
|
186
|
+
private bindState: BindState;
|
|
187
|
+
private readonly deferredAttached = new Deferred<void>();
|
|
188
|
+
private readonly localChannelContextQueue = new Map<string, LocalChannelContextBase>();
|
|
189
|
+
private readonly notBoundedChannelContextSet = new Set<string>();
|
|
190
|
+
private _attachState: AttachState;
|
|
191
|
+
public visibilityState: VisibilityState;
|
|
192
|
+
// A list of handles that are bound when the data store is not visible. We have to make them visible when the data
|
|
193
|
+
// store becomes visible.
|
|
194
|
+
private readonly pendingHandlesToMakeVisible: Set<IFluidHandle> = new Set();
|
|
195
|
+
|
|
196
|
+
public readonly id: string;
|
|
197
|
+
public readonly options: ILoaderOptions;
|
|
198
|
+
public readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>;
|
|
199
|
+
private readonly quorum: IQuorumClients;
|
|
200
|
+
private readonly audience: IAudience;
|
|
201
|
+
public readonly logger: ITelemetryLogger;
|
|
202
|
+
|
|
203
|
+
// A map of child channel context ids to the their base GC details. This is used to initialize the GC state of the
|
|
204
|
+
// channel contexts.
|
|
205
|
+
private readonly channelsBaseGCDetails: LazyPromise<Map<string, IGarbageCollectionDetailsBase>>;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Invokes the given callback and expects that no ops are submitted
|
|
209
|
+
* until execution finishes. If an op is submitted, an error will be raised.
|
|
210
|
+
*
|
|
211
|
+
* Can be disabled by feature gate `Fluid.ContainerRuntime.DisableOpReentryCheck`
|
|
212
|
+
*
|
|
213
|
+
* @param callback - the callback to be invoked
|
|
214
|
+
*/
|
|
215
|
+
public ensureNoDataModelChanges<T>(callback: () => T): T {
|
|
216
|
+
// back-compat ADO:2309
|
|
217
|
+
return this.dataStoreContext.ensureNoDataModelChanges === undefined
|
|
218
|
+
? callback()
|
|
219
|
+
: this.dataStoreContext.ensureNoDataModelChanges(callback);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Create an instance of a DataStore runtime.
|
|
224
|
+
*
|
|
225
|
+
* @param dataStoreContext - Context object for the runtime.
|
|
226
|
+
* @param sharedObjectRegistry - The registry of shared objects that this data store will be able to instantiate.
|
|
227
|
+
* @param existing - Pass 'true' if loading this datastore from an existing file; pass 'false' otherwise.
|
|
228
|
+
* @param initializeEntryPoint - Function to initialize the entryPoint object for the data store runtime. The
|
|
229
|
+
* handle to this data store runtime will point to the object returned by this function. If this function is not
|
|
230
|
+
* provided, the handle will be left undefined. This is here so we can start making handles a first-class citizen
|
|
231
|
+
* and the primary way of interacting with some Fluid objects, and should be used if possible.
|
|
232
|
+
*/
|
|
233
|
+
public constructor(
|
|
234
|
+
private readonly dataStoreContext: IFluidDataStoreContext,
|
|
235
|
+
private readonly sharedObjectRegistry: ISharedObjectRegistry,
|
|
236
|
+
existing: boolean,
|
|
237
|
+
initializeEntryPoint?: (runtime: IFluidDataStoreRuntime) => Promise<FluidObject>,
|
|
238
|
+
) {
|
|
239
|
+
super();
|
|
240
|
+
|
|
241
|
+
assert(
|
|
242
|
+
!dataStoreContext.id.includes("/"),
|
|
243
|
+
0x30e /* Id cannot contain slashes. DataStoreContext should have validated this. */,
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
this.logger = ChildLogger.create(dataStoreContext.logger, "FluidDataStoreRuntime", {
|
|
247
|
+
all: { dataStoreId: uuid() },
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
this.id = dataStoreContext.id;
|
|
251
|
+
this.options = dataStoreContext.options;
|
|
252
|
+
this.deltaManager = dataStoreContext.deltaManager;
|
|
253
|
+
this.quorum = dataStoreContext.getQuorum();
|
|
254
|
+
this.audience = dataStoreContext.getAudience();
|
|
255
|
+
|
|
256
|
+
const tree = dataStoreContext.baseSnapshot;
|
|
257
|
+
|
|
258
|
+
this.channelsBaseGCDetails = new LazyPromise(async () => {
|
|
259
|
+
const baseGCDetails = await this.dataStoreContext.getBaseGCDetails();
|
|
260
|
+
return unpackChildNodesGCDetails(baseGCDetails);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// Must always receive the data store type inside of the attributes
|
|
264
|
+
if (tree?.trees !== undefined) {
|
|
265
|
+
Object.keys(tree.trees).forEach((path) => {
|
|
266
|
+
// Issue #4414
|
|
267
|
+
if (path === "_search") {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
let channelContext: IChannelContext;
|
|
272
|
+
// If already exists on storage, then create a remote channel. However, if it is case of rehydrating a
|
|
273
|
+
// container from snapshot where we load detached container from a snapshot, isLocalDataStore would be
|
|
274
|
+
// true. In this case create a RehydratedLocalChannelContext.
|
|
275
|
+
if (dataStoreContext.isLocalDataStore) {
|
|
276
|
+
channelContext = new RehydratedLocalChannelContext(
|
|
277
|
+
path,
|
|
278
|
+
this.sharedObjectRegistry,
|
|
279
|
+
this,
|
|
280
|
+
this.dataStoreContext,
|
|
281
|
+
this.dataStoreContext.storage,
|
|
282
|
+
this.logger,
|
|
283
|
+
(content, localOpMetadata) =>
|
|
284
|
+
this.submitChannelOp(path, content, localOpMetadata),
|
|
285
|
+
(address: string) => this.setChannelDirty(address),
|
|
286
|
+
(srcHandle: IFluidHandle, outboundHandle: IFluidHandle) =>
|
|
287
|
+
this.addedGCOutboundReference(srcHandle, outboundHandle),
|
|
288
|
+
tree.trees[path],
|
|
289
|
+
);
|
|
290
|
+
// This is the case of rehydrating a detached container from snapshot. Now due to delay loading of
|
|
291
|
+
// data store, if the data store is loaded after the container is attached, then we missed making
|
|
292
|
+
// the channel visible. So do it now. Otherwise, add it to local channel context queue, so
|
|
293
|
+
// that it can be make it visible later with the data store.
|
|
294
|
+
if (dataStoreContext.attachState !== AttachState.Detached) {
|
|
295
|
+
(channelContext as LocalChannelContextBase).makeVisible();
|
|
296
|
+
} else {
|
|
297
|
+
this.localChannelContextQueue.set(
|
|
298
|
+
path,
|
|
299
|
+
channelContext as LocalChannelContextBase,
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
} else {
|
|
303
|
+
channelContext = new RemoteChannelContext(
|
|
304
|
+
this,
|
|
305
|
+
dataStoreContext,
|
|
306
|
+
dataStoreContext.storage,
|
|
307
|
+
(content, localOpMetadata) =>
|
|
308
|
+
this.submitChannelOp(path, content, localOpMetadata),
|
|
309
|
+
(address: string) => this.setChannelDirty(address),
|
|
310
|
+
(srcHandle: IFluidHandle, outboundHandle: IFluidHandle) =>
|
|
311
|
+
this.addedGCOutboundReference(srcHandle, outboundHandle),
|
|
312
|
+
path,
|
|
313
|
+
tree.trees[path],
|
|
314
|
+
this.sharedObjectRegistry,
|
|
315
|
+
undefined /* extraBlobs */,
|
|
316
|
+
this.dataStoreContext.getCreateChildSummarizerNodeFn(path, {
|
|
317
|
+
type: CreateSummarizerNodeSource.FromSummary,
|
|
318
|
+
}),
|
|
319
|
+
async () => this.getChannelBaseGCDetails(path),
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
const deferred = new Deferred<IChannelContext>();
|
|
323
|
+
deferred.resolve(channelContext);
|
|
324
|
+
|
|
325
|
+
this.contexts.set(path, channelContext);
|
|
326
|
+
this.contextsDeferred.set(path, deferred);
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (initializeEntryPoint) {
|
|
331
|
+
const promise = new LazyPromise(async () => initializeEntryPoint(this));
|
|
332
|
+
this.entryPoint = new FluidObjectHandle<FluidObject>(
|
|
333
|
+
promise,
|
|
334
|
+
"",
|
|
335
|
+
this.objectsRoutingContext,
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
this.attachListener();
|
|
340
|
+
// If exists on storage or loaded from a snapshot, it should already be bound.
|
|
341
|
+
this.bindState = existing ? BindState.Bound : BindState.NotBound;
|
|
342
|
+
this._attachState = dataStoreContext.attachState;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* If existing flag is false, this is a new data store and is not visible. The existing flag can be true in two
|
|
346
|
+
* conditions:
|
|
347
|
+
*
|
|
348
|
+
* 1. It's a local data store that is created when a detached container is rehydrated. In this case, the data
|
|
349
|
+
* store is locally visible because the snapshot it is loaded from contains locally visible data stores only.
|
|
350
|
+
*
|
|
351
|
+
* 2. It's a remote data store that is created when an attached container is loaded is loaded from snapshot or
|
|
352
|
+
* when an attach op comes in. In both these cases, the data store is already globally visible.
|
|
353
|
+
*/
|
|
354
|
+
if (existing) {
|
|
355
|
+
this.visibilityState =
|
|
356
|
+
dataStoreContext.attachState === AttachState.Detached
|
|
357
|
+
? VisibilityState.LocallyVisible
|
|
358
|
+
: VisibilityState.GloballyVisible;
|
|
359
|
+
} else {
|
|
360
|
+
this.visibilityState = VisibilityState.NotVisible;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// If it's existing we know it has been attached.
|
|
364
|
+
if (existing) {
|
|
365
|
+
this.deferredAttached.resolve();
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
public dispose(): void {
|
|
370
|
+
if (this._disposed) {
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
this._disposed = true;
|
|
374
|
+
|
|
375
|
+
this.emit("dispose");
|
|
376
|
+
this.removeAllListeners();
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
public async resolveHandle(request: IRequest): Promise<IResponse> {
|
|
380
|
+
return this.request(request);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
public async request(request: IRequest): Promise<IResponse> {
|
|
384
|
+
try {
|
|
385
|
+
const parser = RequestParser.create(request);
|
|
386
|
+
const id = parser.pathParts[0];
|
|
387
|
+
|
|
388
|
+
if (id === "_channels" || id === "_custom") {
|
|
389
|
+
return this.request(parser.createSubRequest(1));
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// Check for a data type reference first
|
|
393
|
+
if (this.contextsDeferred.has(id) && parser.isLeaf(1)) {
|
|
394
|
+
try {
|
|
395
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
396
|
+
const value = await this.contextsDeferred.get(id)!.promise;
|
|
397
|
+
const channel = await value.getChannel();
|
|
398
|
+
|
|
399
|
+
return { mimeType: "fluid/object", status: 200, value: channel };
|
|
400
|
+
} catch (error) {
|
|
401
|
+
this.logger.sendErrorEvent({ eventName: "GetChannelFailedInRequest" }, error);
|
|
402
|
+
|
|
403
|
+
return createResponseError(500, `Failed to get Channel: ${error}`, request);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// Otherwise defer to an attached request handler
|
|
408
|
+
return create404Response(request);
|
|
409
|
+
} catch (error) {
|
|
410
|
+
return exceptionToResponse(error);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
public async getChannel(id: string): Promise<IChannel> {
|
|
415
|
+
this.verifyNotClosed();
|
|
416
|
+
|
|
417
|
+
// TODO we don't assume any channels (even root) in the runtime. If you request a channel that doesn't exist
|
|
418
|
+
// we will never resolve the promise. May want a flag to getChannel that doesn't wait for the promise if
|
|
419
|
+
// it doesn't exist
|
|
420
|
+
if (!this.contextsDeferred.has(id)) {
|
|
421
|
+
this.contextsDeferred.set(id, new Deferred<IChannelContext>());
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
425
|
+
const context = await this.contextsDeferred.get(id)!.promise;
|
|
426
|
+
const channel = await context.getChannel();
|
|
427
|
+
|
|
428
|
+
return channel;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
public createChannel(id: string = uuid(), type: string): IChannel {
|
|
432
|
+
if (id.includes("/")) {
|
|
433
|
+
throw new UsageError(`Id cannot contain slashes: ${id}`);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
this.verifyNotClosed();
|
|
437
|
+
|
|
438
|
+
assert(!this.contexts.has(id), 0x179 /* "createChannel() with existing ID" */);
|
|
439
|
+
this.notBoundedChannelContextSet.add(id);
|
|
440
|
+
const context = new LocalChannelContext(
|
|
441
|
+
id,
|
|
442
|
+
this.sharedObjectRegistry,
|
|
443
|
+
type,
|
|
444
|
+
this,
|
|
445
|
+
this.dataStoreContext,
|
|
446
|
+
this.dataStoreContext.storage,
|
|
447
|
+
this.logger,
|
|
448
|
+
(content, localOpMetadata) => this.submitChannelOp(id, content, localOpMetadata),
|
|
449
|
+
(address: string) => this.setChannelDirty(address),
|
|
450
|
+
(srcHandle: IFluidHandle, outboundHandle: IFluidHandle) =>
|
|
451
|
+
this.addedGCOutboundReference(srcHandle, outboundHandle),
|
|
452
|
+
);
|
|
453
|
+
this.contexts.set(id, context);
|
|
454
|
+
|
|
455
|
+
if (this.contextsDeferred.has(id)) {
|
|
456
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
457
|
+
this.contextsDeferred.get(id)!.resolve(context);
|
|
458
|
+
} else {
|
|
459
|
+
const deferred = new Deferred<IChannelContext>();
|
|
460
|
+
deferred.resolve(context);
|
|
461
|
+
this.contextsDeferred.set(id, deferred);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
assert(!!context.channel, 0x17a /* "Channel should be loaded when created!!" */);
|
|
465
|
+
return context.channel;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Binds a channel with the runtime. If the runtime is attached we will attach the channel right away.
|
|
470
|
+
* If the runtime is not attached we will defer the attach until the runtime attaches.
|
|
471
|
+
* @param channel - channel to be registered.
|
|
472
|
+
*/
|
|
473
|
+
public bindChannel(channel: IChannel): void {
|
|
474
|
+
assert(
|
|
475
|
+
this.notBoundedChannelContextSet.has(channel.id),
|
|
476
|
+
0x17b /* "Channel to be binded should be in not bounded set" */,
|
|
477
|
+
);
|
|
478
|
+
this.notBoundedChannelContextSet.delete(channel.id);
|
|
479
|
+
// If our data store is attached, then attach the channel.
|
|
480
|
+
if (this.isAttached) {
|
|
481
|
+
this.attachChannel(channel);
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* If this channel is already waiting to be made visible, do nothing. This can happen during attachGraph() when
|
|
487
|
+
* a channel's graph is attached. It calls bindToContext on the shared object which will end up back here.
|
|
488
|
+
*/
|
|
489
|
+
if (this.pendingHandlesToMakeVisible.has(channel.handle)) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
this.bind(channel.handle);
|
|
494
|
+
|
|
495
|
+
// If our data store is local then add the channel to the queue
|
|
496
|
+
if (!this.localChannelContextQueue.has(channel.id)) {
|
|
497
|
+
this.localChannelContextQueue.set(
|
|
498
|
+
channel.id,
|
|
499
|
+
this.contexts.get(channel.id) as LocalChannelContextBase,
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* This function is called when a data store becomes root. It does the following:
|
|
506
|
+
*
|
|
507
|
+
* 1. Marks the data store locally visible in the container.
|
|
508
|
+
*
|
|
509
|
+
* 2. Attaches the graph of all the handles bound to it.
|
|
510
|
+
*
|
|
511
|
+
* 3. Calls into the data store context to mark it visible in the container too. If the container is globally
|
|
512
|
+
* visible, it will mark us globally visible. Otherwise, it will mark us globally visible when it becomes
|
|
513
|
+
* globally visible.
|
|
514
|
+
*/
|
|
515
|
+
public makeVisibleAndAttachGraph() {
|
|
516
|
+
if (this.visibilityState !== VisibilityState.NotVisible) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
this.visibilityState = VisibilityState.LocallyVisible;
|
|
520
|
+
|
|
521
|
+
this.pendingHandlesToMakeVisible.forEach((handle) => {
|
|
522
|
+
handle.attachGraph();
|
|
523
|
+
});
|
|
524
|
+
this.pendingHandlesToMakeVisible.clear();
|
|
525
|
+
this.bindToContext();
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* This function is called when a handle to this data store is added to a visible DDS.
|
|
530
|
+
*/
|
|
531
|
+
public attachGraph() {
|
|
532
|
+
this.makeVisibleAndAttachGraph();
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* @deprecated - Not necessary if consumers add a new dataStore to the container by storing its handle.
|
|
537
|
+
* Binds this runtime to the container
|
|
538
|
+
* This includes the following:
|
|
539
|
+
* 1. Sending an Attach op that includes all existing state
|
|
540
|
+
* 2. Attaching the graph if the data store becomes attached.
|
|
541
|
+
*/
|
|
542
|
+
public bindToContext() {
|
|
543
|
+
if (this.bindState !== BindState.NotBound) {
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
this.bindState = BindState.Binding;
|
|
547
|
+
this.dataStoreContext.bindToContext();
|
|
548
|
+
this.bindState = BindState.Bound;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
public bind(handle: IFluidHandle): void {
|
|
552
|
+
// If visible, attach the incoming handle's graph. Else, this will be done when we become visible.
|
|
553
|
+
if (this.visibilityState !== VisibilityState.NotVisible) {
|
|
554
|
+
handle.attachGraph();
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
this.pendingHandlesToMakeVisible.add(handle);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
public setConnectionState(connected: boolean, clientId?: string) {
|
|
561
|
+
this.verifyNotClosed();
|
|
562
|
+
|
|
563
|
+
for (const [, object] of this.contexts) {
|
|
564
|
+
object.setConnectionState(connected, clientId);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
raiseConnectedEvent(this.logger, this, connected, clientId);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
public getQuorum(): IQuorumClients {
|
|
571
|
+
return this.quorum;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
public getAudience(): IAudience {
|
|
575
|
+
return this.audience;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
public async uploadBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>> {
|
|
579
|
+
this.verifyNotClosed();
|
|
580
|
+
|
|
581
|
+
return this.dataStoreContext.uploadBlob(blob);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
public process(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {
|
|
585
|
+
this.verifyNotClosed();
|
|
586
|
+
|
|
587
|
+
try {
|
|
588
|
+
// catches as data processing error whether or not they come from async pending queues
|
|
589
|
+
switch (message.type) {
|
|
590
|
+
case DataStoreMessageType.Attach: {
|
|
591
|
+
const attachMessage = message.contents as IAttachMessage;
|
|
592
|
+
const id = attachMessage.id;
|
|
593
|
+
|
|
594
|
+
// If a non-local operation then go and create the object
|
|
595
|
+
// Otherwise mark it as officially attached.
|
|
596
|
+
if (local) {
|
|
597
|
+
assert(
|
|
598
|
+
this.pendingAttach.has(id),
|
|
599
|
+
0x17c /* "Unexpected attach (local) channel OP" */,
|
|
600
|
+
);
|
|
601
|
+
this.pendingAttach.delete(id);
|
|
602
|
+
} else {
|
|
603
|
+
assert(
|
|
604
|
+
!this.contexts.has(id),
|
|
605
|
+
0x17d /* `Unexpected attach channel OP,
|
|
590
606
|
is in pendingAttach set: ${this.pendingAttach.has(id)},
|
|
591
|
-
is local channel contexts: ${this.contexts.get(id) instanceof LocalChannelContextBase}`
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
607
|
+
is local channel contexts: ${this.contexts.get(id) instanceof LocalChannelContextBase}` */,
|
|
608
|
+
);
|
|
609
|
+
|
|
610
|
+
const flatBlobs = new Map<string, ArrayBufferLike>();
|
|
611
|
+
const snapshotTree = buildSnapshotTree(
|
|
612
|
+
attachMessage.snapshot.entries,
|
|
613
|
+
flatBlobs,
|
|
614
|
+
);
|
|
615
|
+
|
|
616
|
+
const remoteChannelContext = new RemoteChannelContext(
|
|
617
|
+
this,
|
|
618
|
+
this.dataStoreContext,
|
|
619
|
+
this.dataStoreContext.storage,
|
|
620
|
+
(content, localContentMetadata) =>
|
|
621
|
+
this.submitChannelOp(id, content, localContentMetadata),
|
|
622
|
+
(address: string) => this.setChannelDirty(address),
|
|
623
|
+
(srcHandle: IFluidHandle, outboundHandle: IFluidHandle) =>
|
|
624
|
+
this.addedGCOutboundReference(srcHandle, outboundHandle),
|
|
625
|
+
id,
|
|
626
|
+
snapshotTree,
|
|
627
|
+
this.sharedObjectRegistry,
|
|
628
|
+
flatBlobs,
|
|
629
|
+
this.dataStoreContext.getCreateChildSummarizerNodeFn(id, {
|
|
630
|
+
type: CreateSummarizerNodeSource.FromAttach,
|
|
631
|
+
sequenceNumber: message.sequenceNumber,
|
|
632
|
+
snapshot: attachMessage.snapshot,
|
|
633
|
+
}),
|
|
634
|
+
async () => this.getChannelBaseGCDetails(id),
|
|
635
|
+
attachMessage.type,
|
|
636
|
+
);
|
|
637
|
+
|
|
638
|
+
this.contexts.set(id, remoteChannelContext);
|
|
639
|
+
if (this.contextsDeferred.has(id)) {
|
|
640
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
641
|
+
this.contextsDeferred.get(id)!.resolve(remoteChannelContext);
|
|
642
|
+
} else {
|
|
643
|
+
const deferred = new Deferred<IChannelContext>();
|
|
644
|
+
deferred.resolve(remoteChannelContext);
|
|
645
|
+
this.contextsDeferred.set(id, deferred);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
break;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
case DataStoreMessageType.ChannelOp:
|
|
652
|
+
this.processChannelOp(message, local, localOpMetadata);
|
|
653
|
+
break;
|
|
654
|
+
default:
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
this.emit("op", message);
|
|
658
|
+
} catch (error) {
|
|
659
|
+
throw DataProcessingError.wrapIfUnrecognized(
|
|
660
|
+
error,
|
|
661
|
+
"fluidDataStoreRuntimeFailedToProcessMessage",
|
|
662
|
+
message,
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
public processSignal(message: IInboundSignalMessage, local: boolean) {
|
|
668
|
+
this.emit("signal", message, local);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
private isChannelAttached(id: string): boolean {
|
|
672
|
+
return (
|
|
673
|
+
// Added in createChannel
|
|
674
|
+
// Removed when bindChannel is called
|
|
675
|
+
!this.notBoundedChannelContextSet.has(id) &&
|
|
676
|
+
// Added in bindChannel only if this is not attached yet
|
|
677
|
+
// Removed when this is attached by calling attachGraph
|
|
678
|
+
!this.localChannelContextQueue.has(id) &&
|
|
679
|
+
// Added in attachChannel called by bindChannel
|
|
680
|
+
// Removed when attach op is broadcast
|
|
681
|
+
!this.pendingAttach.has(id)
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Returns the outbound routes of this channel. Currently, all contexts in this channel are considered
|
|
687
|
+
* referenced and are hence outbound. This will change when we have root and non-root channel contexts.
|
|
688
|
+
* The only root contexts will be considered as referenced.
|
|
689
|
+
*/
|
|
690
|
+
private getOutboundRoutes(): string[] {
|
|
691
|
+
const outboundRoutes: string[] = [];
|
|
692
|
+
for (const [contextId] of this.contexts) {
|
|
693
|
+
outboundRoutes.push(`${this.absolutePath}/${contextId}`);
|
|
694
|
+
}
|
|
695
|
+
return outboundRoutes;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Updates the GC nodes of this channel. It does the following:
|
|
700
|
+
* - Adds a back route to self to all its child GC nodes.
|
|
701
|
+
* - Adds a node for this channel.
|
|
702
|
+
* @param builder - The builder that contains the GC nodes for this channel's children.
|
|
703
|
+
*/
|
|
704
|
+
private updateGCNodes(builder: GCDataBuilder) {
|
|
705
|
+
// Add a back route to self in each child's GC nodes. If any child is referenced, then its parent should
|
|
706
|
+
// be considered referenced as well.
|
|
707
|
+
builder.addRouteToAllNodes(this.absolutePath);
|
|
708
|
+
|
|
709
|
+
// Get the outbound routes and add a GC node for this channel.
|
|
710
|
+
builder.addNode("/", this.getOutboundRoutes());
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Generates data used for garbage collection. This includes a list of GC nodes that represent this channel
|
|
715
|
+
* including any of its child channel contexts. Each node has a set of outbound routes to other GC nodes in the
|
|
716
|
+
* document. It does the following:
|
|
717
|
+
*
|
|
718
|
+
* 1. Calls into each child context to get its GC data.
|
|
719
|
+
*
|
|
720
|
+
* 2. Prefixes the child context's id to the GC nodes in the child's GC data. This makes sure that the node can be
|
|
721
|
+
* identified as belonging to the child.
|
|
722
|
+
*
|
|
723
|
+
* 3. Adds a GC node for this channel to the nodes received from the children. All these nodes together represent
|
|
724
|
+
* the GC data of this channel.
|
|
725
|
+
*
|
|
726
|
+
* @param fullGC - true to bypass optimizations and force full generation of GC data.
|
|
727
|
+
*/
|
|
728
|
+
public async getGCData(fullGC: boolean = false): Promise<IGarbageCollectionData> {
|
|
729
|
+
const builder = new GCDataBuilder();
|
|
730
|
+
// Iterate over each channel context and get their GC data.
|
|
731
|
+
await Promise.all(
|
|
732
|
+
Array.from(this.contexts)
|
|
733
|
+
.filter(([contextId, _]) => {
|
|
734
|
+
// Get GC data only for attached contexts. Detached contexts are not connected in the GC reference
|
|
735
|
+
// graph so any references they might have won't be connected as well.
|
|
736
|
+
return this.isChannelAttached(contextId);
|
|
737
|
+
})
|
|
738
|
+
.map(async ([contextId, context]) => {
|
|
739
|
+
const contextGCData = await context.getGCData(fullGC);
|
|
740
|
+
// Prefix the child's id to the ids of its GC nodes so they can be identified as belonging to the child.
|
|
741
|
+
// This also gradually builds the id of each node to be a path from the root.
|
|
742
|
+
builder.prefixAndAddNodes(contextId, contextGCData.gcNodes);
|
|
743
|
+
}),
|
|
744
|
+
);
|
|
745
|
+
|
|
746
|
+
this.updateGCNodes(builder);
|
|
747
|
+
return builder.getGCData();
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* After GC has run, called to notify this channel of routes that are used in it. It calls the child contexts to
|
|
752
|
+
* update their used routes.
|
|
753
|
+
* @param usedRoutes - The routes that are used in all contexts in this channel.
|
|
754
|
+
*/
|
|
755
|
+
public updateUsedRoutes(usedRoutes: string[]) {
|
|
756
|
+
// Get a map of channel ids to routes used in it.
|
|
757
|
+
const usedContextRoutes = unpackChildNodesUsedRoutes(usedRoutes);
|
|
758
|
+
|
|
759
|
+
// Verify that the used routes are correct.
|
|
760
|
+
for (const [id] of usedContextRoutes) {
|
|
761
|
+
assert(
|
|
762
|
+
this.contexts.has(id),
|
|
763
|
+
0x17e /* "Used route does not belong to any known context" */,
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// Update the used routes in each context. Used routes is empty for unused context.
|
|
768
|
+
for (const [contextId, context] of this.contexts) {
|
|
769
|
+
context.updateUsedRoutes(usedContextRoutes.get(contextId) ?? []);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Called when a new outbound reference is added to another node. This is used by garbage collection to identify
|
|
775
|
+
* all references added in the system.
|
|
776
|
+
* @param srcHandle - The handle of the node that added the reference.
|
|
777
|
+
* @param outboundHandle - The handle of the outbound node that is referenced.
|
|
778
|
+
*/
|
|
779
|
+
private addedGCOutboundReference(srcHandle: IFluidHandle, outboundHandle: IFluidHandle) {
|
|
780
|
+
this.dataStoreContext.addedGCOutboundReference?.(srcHandle, outboundHandle);
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* Returns the base GC details for the channel with the given id. This is used to initialize its GC state.
|
|
785
|
+
* @param channelId - The id of the channel context that is asked for the initial GC details.
|
|
786
|
+
* @returns the requested channel's base GC details.
|
|
787
|
+
*/
|
|
788
|
+
private async getChannelBaseGCDetails(
|
|
789
|
+
channelId: string,
|
|
790
|
+
): Promise<IGarbageCollectionDetailsBase> {
|
|
791
|
+
let channelBaseGCDetails = (await this.channelsBaseGCDetails).get(channelId);
|
|
792
|
+
if (channelBaseGCDetails === undefined) {
|
|
793
|
+
channelBaseGCDetails = {};
|
|
794
|
+
} else if (channelBaseGCDetails.gcData?.gcNodes !== undefined) {
|
|
795
|
+
// Note: if the child channel has an explicit handle route to its parent, it will be removed here and
|
|
796
|
+
// expected to be added back by the parent when getGCData is called.
|
|
797
|
+
removeRouteFromAllNodes(channelBaseGCDetails.gcData.gcNodes, this.absolutePath);
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// Currently, channel context's are always considered used. So, it there are no used routes for it, we still
|
|
801
|
+
// need to mark it as used. Add self-route (empty string) to the channel context's used routes.
|
|
802
|
+
if (
|
|
803
|
+
channelBaseGCDetails.usedRoutes === undefined ||
|
|
804
|
+
channelBaseGCDetails.usedRoutes.length === 0
|
|
805
|
+
) {
|
|
806
|
+
channelBaseGCDetails.usedRoutes = [""];
|
|
807
|
+
}
|
|
808
|
+
return channelBaseGCDetails;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
/**
|
|
812
|
+
* Returns a summary at the current sequence number.
|
|
813
|
+
* @param fullTree - true to bypass optimizations and force a full summary tree
|
|
814
|
+
* @param trackState - This tells whether we should track state from this summary.
|
|
815
|
+
* @param telemetryContext - summary data passed through the layers for telemetry purposes
|
|
816
|
+
*/
|
|
817
|
+
public async summarize(
|
|
818
|
+
fullTree: boolean = false,
|
|
819
|
+
trackState: boolean = true,
|
|
820
|
+
telemetryContext?: ITelemetryContext,
|
|
821
|
+
): Promise<ISummaryTreeWithStats> {
|
|
822
|
+
const summaryBuilder = new SummaryTreeBuilder();
|
|
823
|
+
|
|
824
|
+
// Iterate over each data store and ask it to summarize
|
|
825
|
+
await Promise.all(
|
|
826
|
+
Array.from(this.contexts)
|
|
827
|
+
.filter(([contextId, _]) => {
|
|
828
|
+
const isAttached = this.isChannelAttached(contextId);
|
|
829
|
+
// We are not expecting local dds! Summary may not capture local state.
|
|
830
|
+
assert(
|
|
831
|
+
isAttached,
|
|
832
|
+
0x17f /* "Not expecting detached channels during summarize" */,
|
|
833
|
+
);
|
|
834
|
+
// If the object is registered - and we have received the sequenced op creating the object
|
|
835
|
+
// (i.e. it has a base mapping) - then we go ahead and summarize
|
|
836
|
+
return isAttached;
|
|
837
|
+
})
|
|
838
|
+
.map(async ([contextId, context]) => {
|
|
839
|
+
const contextSummary = await context.summarize(
|
|
840
|
+
fullTree,
|
|
841
|
+
trackState,
|
|
842
|
+
telemetryContext,
|
|
843
|
+
);
|
|
844
|
+
summaryBuilder.addWithStats(contextId, contextSummary);
|
|
845
|
+
}),
|
|
846
|
+
);
|
|
847
|
+
|
|
848
|
+
return summaryBuilder.getSummaryTree();
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
public getAttachSummary(telemetryContext?: ITelemetryContext): ISummaryTreeWithStats {
|
|
852
|
+
/**
|
|
853
|
+
* back-compat 0.59.1000 - getAttachSummary() is called when making a data store globally visible (previously
|
|
854
|
+
* attaching state). Ideally, attachGraph() should have already be called making it locally visible. However,
|
|
855
|
+
* before visibility state was added, this may not have been the case and getAttachSummary() could be called:
|
|
856
|
+
*
|
|
857
|
+
* 1. Before attaching the data store - When a detached container is attached.
|
|
858
|
+
*
|
|
859
|
+
* 2. After attaching the data store - When a data store is created and bound in an attached container.
|
|
860
|
+
*
|
|
861
|
+
* The basic idea is that all local object should become locally visible before they are globally visible.
|
|
862
|
+
*/
|
|
863
|
+
this.attachGraph();
|
|
864
|
+
|
|
865
|
+
// This assert cannot be added now due to back-compat. To be uncommented when the following issue is fixed -
|
|
866
|
+
// https://github.com/microsoft/FluidFramework/issues/9688.
|
|
867
|
+
//
|
|
868
|
+
// assert(this.visibilityState === VisibilityState.LocallyVisible,
|
|
869
|
+
// "The data store should be locally visible when generating attach summary",
|
|
870
|
+
// );
|
|
871
|
+
|
|
872
|
+
const summaryBuilder = new SummaryTreeBuilder();
|
|
873
|
+
|
|
874
|
+
// Craft the .attributes file for each shared object
|
|
875
|
+
for (const [contextId, context] of this.contexts) {
|
|
876
|
+
if (!(context instanceof LocalChannelContextBase)) {
|
|
877
|
+
throw new LoggingError("Should only be called with local channel handles");
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
if (!this.notBoundedChannelContextSet.has(contextId)) {
|
|
881
|
+
let summaryTree: ISummaryTreeWithStats;
|
|
882
|
+
if (context.isLoaded) {
|
|
883
|
+
const contextSummary = context.getAttachSummary(telemetryContext);
|
|
884
|
+
assert(
|
|
885
|
+
contextSummary.summary.type === SummaryType.Tree,
|
|
886
|
+
0x180 /* "getAttachSummary should always return a tree" */,
|
|
887
|
+
);
|
|
888
|
+
summaryTree = { stats: contextSummary.stats, summary: contextSummary.summary };
|
|
889
|
+
} else {
|
|
890
|
+
// If this channel is not yet loaded, then there should be no changes in the snapshot from which
|
|
891
|
+
// it was created as it is detached container. So just use the previous snapshot.
|
|
892
|
+
assert(
|
|
893
|
+
!!this.dataStoreContext.baseSnapshot,
|
|
894
|
+
0x181 /* "BaseSnapshot should be there as detached container loaded from snapshot" */,
|
|
895
|
+
);
|
|
896
|
+
summaryTree = convertSnapshotTreeToSummaryTree(
|
|
897
|
+
this.dataStoreContext.baseSnapshot.trees[contextId],
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
summaryBuilder.addWithStats(contextId, summaryTree);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
return summaryBuilder.getSummaryTree();
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
public submitMessage(type: DataStoreMessageType, content: any, localOpMetadata: unknown) {
|
|
908
|
+
this.submit(type, content, localOpMetadata);
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
public submitSignal(type: string, content: any) {
|
|
912
|
+
this.verifyNotClosed();
|
|
913
|
+
return this.dataStoreContext.submitSignal(type, content);
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
/**
|
|
917
|
+
* Will return when the data store is attached.
|
|
918
|
+
*/
|
|
919
|
+
public async waitAttached(): Promise<void> {
|
|
920
|
+
return this.deferredAttached.promise;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* Attach channel should only be called after the data store has been attached
|
|
925
|
+
*/
|
|
926
|
+
private attachChannel(channel: IChannel): void {
|
|
927
|
+
this.verifyNotClosed();
|
|
928
|
+
// If this handle is already attached no need to attach again.
|
|
929
|
+
if (channel.handle.isAttached) {
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
channel.handle.attachGraph();
|
|
934
|
+
|
|
935
|
+
assert(this.isAttached, 0x182 /* "Data store should be attached to attach the channel." */);
|
|
936
|
+
assert(
|
|
937
|
+
this.visibilityState === VisibilityState.GloballyVisible,
|
|
938
|
+
0x2d0 /* "Data store should be globally visible to attach channels." */,
|
|
939
|
+
);
|
|
940
|
+
|
|
941
|
+
const summarizeResult = summarizeChannel(
|
|
942
|
+
channel,
|
|
943
|
+
true /* fullTree */,
|
|
944
|
+
false /* trackState */,
|
|
945
|
+
);
|
|
946
|
+
// Attach message needs the summary in ITree format. Convert the ISummaryTree into an ITree.
|
|
947
|
+
const snapshot = convertSummaryTreeToITree(summarizeResult.summary);
|
|
948
|
+
|
|
949
|
+
const message: IAttachMessage = {
|
|
950
|
+
id: channel.id,
|
|
951
|
+
snapshot,
|
|
952
|
+
type: channel.attributes.type,
|
|
953
|
+
};
|
|
954
|
+
this.pendingAttach.set(channel.id, message);
|
|
955
|
+
this.submit(DataStoreMessageType.Attach, message);
|
|
956
|
+
|
|
957
|
+
const context = this.contexts.get(channel.id) as LocalChannelContextBase;
|
|
958
|
+
context.makeVisible();
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
private submitChannelOp(address: string, contents: any, localOpMetadata: unknown) {
|
|
962
|
+
const envelope: IEnvelope = { address, contents };
|
|
963
|
+
this.submit(DataStoreMessageType.ChannelOp, envelope, localOpMetadata);
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
private submit(
|
|
967
|
+
type: DataStoreMessageType,
|
|
968
|
+
content: any,
|
|
969
|
+
localOpMetadata: unknown = undefined,
|
|
970
|
+
): void {
|
|
971
|
+
this.verifyNotClosed();
|
|
972
|
+
this.dataStoreContext.submitMessage(type, content, localOpMetadata);
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* For messages of type MessageType.Operation, finds the right channel and asks it to resubmit the message.
|
|
977
|
+
* For all other messages, just submit it again.
|
|
978
|
+
* This typically happens when we reconnect and there are unacked messages.
|
|
979
|
+
* @param content - The content of the original message.
|
|
980
|
+
* @param localOpMetadata - The local metadata associated with the original message.
|
|
981
|
+
*/
|
|
982
|
+
public reSubmit(type: DataStoreMessageType, content: any, localOpMetadata: unknown) {
|
|
983
|
+
this.verifyNotClosed();
|
|
984
|
+
|
|
985
|
+
switch (type) {
|
|
986
|
+
case DataStoreMessageType.ChannelOp: {
|
|
987
|
+
// For Operations, find the right channel and trigger resubmission on it.
|
|
988
|
+
const envelope = content as IEnvelope;
|
|
989
|
+
const channelContext = this.contexts.get(envelope.address);
|
|
990
|
+
assert(
|
|
991
|
+
!!channelContext,
|
|
992
|
+
0x183 /* "There should be a channel context for the op" */,
|
|
993
|
+
);
|
|
994
|
+
channelContext.reSubmit(envelope.contents, localOpMetadata);
|
|
995
|
+
break;
|
|
996
|
+
}
|
|
997
|
+
case DataStoreMessageType.Attach:
|
|
998
|
+
// For Attach messages, just submit them again.
|
|
999
|
+
this.submit(type, content, localOpMetadata);
|
|
1000
|
+
break;
|
|
1001
|
+
default:
|
|
1002
|
+
unreachableCase(type);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
/**
|
|
1007
|
+
* Revert a local op.
|
|
1008
|
+
* @param content - The content of the original message.
|
|
1009
|
+
* @param localOpMetadata - The local metadata associated with the original message.
|
|
1010
|
+
*/
|
|
1011
|
+
public rollback?(type: DataStoreMessageType, content: any, localOpMetadata: unknown) {
|
|
1012
|
+
this.verifyNotClosed();
|
|
1013
|
+
|
|
1014
|
+
switch (type) {
|
|
1015
|
+
case DataStoreMessageType.ChannelOp: {
|
|
1016
|
+
// For Operations, find the right channel and trigger resubmission on it.
|
|
1017
|
+
const envelope = content as IEnvelope;
|
|
1018
|
+
const channelContext = this.contexts.get(envelope.address);
|
|
1019
|
+
assert(
|
|
1020
|
+
!!channelContext,
|
|
1021
|
+
0x2ed /* "There should be a channel context for the op" */,
|
|
1022
|
+
);
|
|
1023
|
+
channelContext.rollback(envelope.contents, localOpMetadata);
|
|
1024
|
+
break;
|
|
1025
|
+
}
|
|
1026
|
+
default:
|
|
1027
|
+
throw new LoggingError(`Can't rollback ${type} message`);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
public async applyStashedOp(content: any): Promise<unknown> {
|
|
1032
|
+
const envelope = content as IEnvelope;
|
|
1033
|
+
const channelContext = this.contexts.get(envelope.address);
|
|
1034
|
+
assert(!!channelContext, 0x184 /* "There should be a channel context for the op" */);
|
|
1035
|
+
await channelContext.getChannel();
|
|
1036
|
+
return channelContext.applyStashedOp(envelope.contents);
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
private setChannelDirty(address: string): void {
|
|
1040
|
+
this.verifyNotClosed();
|
|
1041
|
+
this.dataStoreContext.setChannelDirty(address);
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
private processChannelOp(
|
|
1045
|
+
message: ISequencedDocumentMessage,
|
|
1046
|
+
local: boolean,
|
|
1047
|
+
localOpMetadata: unknown,
|
|
1048
|
+
) {
|
|
1049
|
+
this.verifyNotClosed();
|
|
1050
|
+
|
|
1051
|
+
const envelope = message.contents as IEnvelope;
|
|
1052
|
+
|
|
1053
|
+
const transformed: ISequencedDocumentMessage = {
|
|
1054
|
+
...message,
|
|
1055
|
+
contents: envelope.contents,
|
|
1056
|
+
};
|
|
1057
|
+
|
|
1058
|
+
const channelContext = this.contexts.get(envelope.address);
|
|
1059
|
+
assert(!!channelContext, 0x185 /* "Channel not found" */);
|
|
1060
|
+
channelContext.processOp(transformed, local, localOpMetadata);
|
|
1061
|
+
|
|
1062
|
+
return channelContext;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
private attachListener() {
|
|
1066
|
+
this.setMaxListeners(Number.MAX_SAFE_INTEGER);
|
|
1067
|
+
this.dataStoreContext.once("attaching", () => {
|
|
1068
|
+
/**
|
|
1069
|
+
* back-compat 0.59.1000 - Ideally, attachGraph() should have already been called making the data store
|
|
1070
|
+
* locally visible. However, before visibility state was added, this may not have been the case and data
|
|
1071
|
+
* store can move to "attaching" state in 2 scenarios:
|
|
1072
|
+
* 1) Before attachGraph() is called - When a data store is created and bound in an attached container.
|
|
1073
|
+
* 2) After attachGraph() is called - When a detached container is attached.
|
|
1074
|
+
*
|
|
1075
|
+
* The basic idea is that all local object should become locally visible before they are globally visible.
|
|
1076
|
+
*/
|
|
1077
|
+
this.attachGraph();
|
|
1078
|
+
|
|
1079
|
+
this._attachState = AttachState.Attaching;
|
|
1080
|
+
|
|
1081
|
+
assert(
|
|
1082
|
+
this.visibilityState === VisibilityState.LocallyVisible,
|
|
1083
|
+
0x2d1 /* "Data store should be locally visible before it can become globally visible." */,
|
|
1084
|
+
);
|
|
1085
|
+
|
|
1086
|
+
// Mark the data store globally visible and make its child channels visible as well.
|
|
1087
|
+
this.visibilityState = VisibilityState.GloballyVisible;
|
|
1088
|
+
this.localChannelContextQueue.forEach((channel) => {
|
|
1089
|
+
channel.makeVisible();
|
|
1090
|
+
});
|
|
1091
|
+
this.localChannelContextQueue.clear();
|
|
1092
|
+
|
|
1093
|
+
// This promise resolution will be moved to attached event once we fix the scheduler.
|
|
1094
|
+
this.deferredAttached.resolve();
|
|
1095
|
+
this.emit("attaching");
|
|
1096
|
+
});
|
|
1097
|
+
this.dataStoreContext.once("attached", () => {
|
|
1098
|
+
assert(
|
|
1099
|
+
this.visibilityState === VisibilityState.GloballyVisible,
|
|
1100
|
+
0x2d2 /* "Data store should be globally visible when its attached." */,
|
|
1101
|
+
);
|
|
1102
|
+
this._attachState = AttachState.Attached;
|
|
1103
|
+
this.emit("attached");
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
private verifyNotClosed() {
|
|
1108
|
+
if (this._disposed) {
|
|
1109
|
+
throw new LoggingError("Runtime is closed");
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1080
1112
|
}
|
|
1081
1113
|
|
|
1082
1114
|
/**
|
|
@@ -1086,17 +1118,18 @@ export class FluidDataStoreRuntime extends
|
|
|
1086
1118
|
* @param requestHandler - request handler to mix in
|
|
1087
1119
|
*/
|
|
1088
1120
|
export const mixinRequestHandler = (
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
) =>
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
}
|
|
1121
|
+
requestHandler: (request: IRequest, runtime: FluidDataStoreRuntime) => Promise<IResponse>,
|
|
1122
|
+
Base: typeof FluidDataStoreRuntime = FluidDataStoreRuntime,
|
|
1123
|
+
) =>
|
|
1124
|
+
class RuntimeWithRequestHandler extends Base {
|
|
1125
|
+
public async request(request: IRequest) {
|
|
1126
|
+
const response = await super.request(request);
|
|
1127
|
+
if (response.status === 404) {
|
|
1128
|
+
return requestHandler(request, this);
|
|
1129
|
+
}
|
|
1130
|
+
return response;
|
|
1131
|
+
}
|
|
1132
|
+
} as typeof FluidDataStoreRuntime;
|
|
1100
1133
|
|
|
1101
1134
|
/**
|
|
1102
1135
|
* Mixin class that adds await for DataObject to finish initialization before we proceed to summary.
|
|
@@ -1105,38 +1138,41 @@ export const mixinRequestHandler = (
|
|
|
1105
1138
|
* @param Base - base class, inherits from FluidDataStoreRuntime
|
|
1106
1139
|
*/
|
|
1107
1140
|
export const mixinSummaryHandler = (
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
) =>
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
}
|
|
1141
|
+
handler: (
|
|
1142
|
+
runtime: FluidDataStoreRuntime,
|
|
1143
|
+
) => Promise<{ path: string[]; content: string } | undefined>,
|
|
1144
|
+
Base: typeof FluidDataStoreRuntime = FluidDataStoreRuntime,
|
|
1145
|
+
) =>
|
|
1146
|
+
class RuntimeWithSummarizerHandler extends Base {
|
|
1147
|
+
private addBlob(summary: ISummaryTreeWithStats, path: string[], content: string) {
|
|
1148
|
+
const firstName = path.shift();
|
|
1149
|
+
if (firstName === undefined) {
|
|
1150
|
+
throw new LoggingError("Path can't be empty");
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
let blob: ISummaryTree | ISummaryBlob = {
|
|
1154
|
+
type: SummaryType.Blob,
|
|
1155
|
+
content,
|
|
1156
|
+
};
|
|
1157
|
+
summary.stats.blobNodeCount++;
|
|
1158
|
+
summary.stats.totalBlobSize += content.length;
|
|
1159
|
+
|
|
1160
|
+
for (const name of path.reverse()) {
|
|
1161
|
+
blob = {
|
|
1162
|
+
type: SummaryType.Tree,
|
|
1163
|
+
tree: { [name]: blob },
|
|
1164
|
+
};
|
|
1165
|
+
summary.stats.treeNodeCount++;
|
|
1166
|
+
}
|
|
1167
|
+
summary.summary.tree[firstName] = blob;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
async summarize(...args: any[]) {
|
|
1171
|
+
const summary = await super.summarize(...args);
|
|
1172
|
+
const content = await handler(this);
|
|
1173
|
+
if (content !== undefined) {
|
|
1174
|
+
this.addBlob(summary, content.path, content.content);
|
|
1175
|
+
}
|
|
1176
|
+
return summary;
|
|
1177
|
+
}
|
|
1178
|
+
} as typeof FluidDataStoreRuntime;
|