Skip to content

Commit 514980f

Browse files
Avoid depending on runtime inside of SharedTreeKernel (#23855)
## Description Use IIDCompressor instead of IFluidDataStoreRuntime in SharedTreeKernel
1 parent 8c11bdc commit 514980f

File tree

4 files changed

+42
-60
lines changed

4 files changed

+42
-60
lines changed

packages/dds/tree/src/feature-libraries/schema-index/schemaSummarizer.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55

66
import { bufferToString } from "@fluid-internal/client-utils";
77
import { assert } from "@fluidframework/core-utils/internal";
8-
import type {
9-
IFluidDataStoreRuntime,
10-
IChannelStorageService,
11-
} from "@fluidframework/datastore-definitions/internal";
8+
import type { IChannelStorageService } from "@fluidframework/datastore-definitions/internal";
129
import { SummaryType } from "@fluidframework/driver-definitions";
1310
import type {
1411
IExperimentalIncrementalSummaryContext,
@@ -45,7 +42,6 @@ export class SchemaSummarizer implements Summarizable {
4542
private schemaIndexLastChangedSeq: number | undefined;
4643

4744
public constructor(
48-
private readonly runtime: IFluidDataStoreRuntime,
4945
private readonly schema: MutableTreeStoredSchema,
5046
options: ICodecOptions,
5147
collabWindow: CollabWindow,

packages/dds/tree/src/shared-tree-core/sharedTreeCore.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
*/
55

66
import { assert } from "@fluidframework/core-utils/internal";
7-
import type {
8-
IFluidDataStoreRuntime,
9-
IChannelStorageService,
10-
} from "@fluidframework/datastore-definitions/internal";
7+
import type { IChannelStorageService } from "@fluidframework/datastore-definitions/internal";
118
import type { IIdCompressor } from "@fluidframework/id-compressor";
129
import type { ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
1310
import type {
@@ -99,8 +96,6 @@ export class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange>
9996
MessageEncodingContext
10097
>;
10198

102-
private readonly idCompressor: IIdCompressor;
103-
10499
private readonly resubmitMachine: ResubmitMachine<TChange>;
105100
public readonly commitEnricher: BranchCommitEnricher<TChange>;
106101

@@ -126,7 +121,7 @@ export class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange>
126121
changeFamily: ChangeFamily<TEditor, TChange>,
127122
options: ICodecOptions,
128123
formatOptions: ExplicitCoreCodecVersions,
129-
runtime: IFluidDataStoreRuntime,
124+
private readonly idCompressor: IIdCompressor,
130125
schema: TreeStoredSchemaRepository,
131126
schemaPolicy: SchemaPolicy,
132127
resubmitMachine?: ResubmitMachine<TChange>,
@@ -143,18 +138,13 @@ export class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange>
143138
namespace: "Rebase",
144139
});
145140

146-
assert(
147-
runtime.idCompressor !== undefined,
148-
0x886 /* IdCompressor must be enabled to use SharedTree */,
149-
);
150-
this.idCompressor = runtime.idCompressor;
151141
this.mintRevisionTag = () => this.idCompressor.generateCompressedId();
152142
/**
153143
* A random ID that uniquely identifies this client in the collab session.
154144
* This is sent alongside every op to identify which client the op originated from.
155145
* This is used rather than the Fluid client ID because the Fluid client ID is not stable across reconnections.
156146
*/
157-
const localSessionId = runtime.idCompressor.localSessionId;
147+
const localSessionId = idCompressor.localSessionId;
158148
this.editManager = new EditManager(
159149
changeFamily,
160150
localSessionId,
@@ -174,7 +164,7 @@ export class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange>
174164
}
175165
});
176166

177-
const revisionTagCodec = new RevisionTagCodec(runtime.idCompressor);
167+
const revisionTagCodec = new RevisionTagCodec(idCompressor);
178168
const editManagerCodec = makeEditManagerCodec(
179169
this.editManager.changeFamily.codecs,
180170
revisionTagCodec,
@@ -197,7 +187,7 @@ export class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange>
197187

198188
this.messageCodec = makeMessageCodec(
199189
changeFamily.codecs,
200-
new RevisionTagCodec(runtime.idCompressor),
190+
new RevisionTagCodec(idCompressor),
201191
options,
202192
formatOptions.message,
203193
);

packages/dds/tree/src/shared-tree/sharedTree.ts

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,17 @@ export class SharedTree extends SharedObject implements ISharedTree, WithBreakab
235235
telemetryContextPrefix: string = "fluid_sharedTree_",
236236
) {
237237
super(id, runtime, attributes, telemetryContextPrefix);
238+
if (runtime.idCompressor === undefined) {
239+
throw new UsageError("IdCompressor must be enabled to use SharedTree");
240+
}
238241
this.kernel = new SharedTreeKernel(
239242
this.breaker,
240243
this,
241244
this.serializer,
242245
(content, localOpMetadata) => this.submitLocalMessage(content, localOpMetadata),
243246
() => this.deltaManager.lastSequenceNumber,
244247
this.logger,
245-
runtime,
248+
runtime.idCompressor,
246249
optionsParam,
247250
);
248251
}
@@ -341,25 +344,21 @@ class SharedTreeKernel extends SharedTreeCore<SharedTreeEditBuilder, SharedTreeC
341344
submitLocalMessage: (content: unknown, localOpMetadata?: unknown) => void,
342345
lastSequenceNumber: () => number | undefined,
343346
logger: ITelemetryLoggerExt | undefined,
344-
runtime: IFluidDataStoreRuntime,
347+
idCompressor: IIdCompressor,
345348
optionsParam: SharedTreeOptionsInternal,
346349
) {
347-
if (runtime.idCompressor === undefined) {
348-
throw new UsageError("IdCompressor must be enabled to use SharedTree");
349-
}
350-
351350
const options = { ...defaultSharedTreeOptions, ...optionsParam };
352351
const codecVersions = getCodecVersions(options.formatVersion);
353352
const schema = new TreeStoredSchemaRepository();
354-
const forest = buildConfiguredForest(options.forest, schema, runtime.idCompressor);
355-
const revisionTagCodec = new RevisionTagCodec(runtime.idCompressor);
353+
const forest = buildConfiguredForest(options.forest, schema, idCompressor);
354+
const revisionTagCodec = new RevisionTagCodec(idCompressor);
356355
const removedRoots = makeDetachedFieldIndex(
357356
"repair",
358357
revisionTagCodec,
359-
runtime.idCompressor,
358+
idCompressor,
360359
options,
361360
);
362-
const schemaSummarizer = new SchemaSummarizer(runtime, schema, options, {
361+
const schemaSummarizer = new SchemaSummarizer(schema, options, {
363362
getCurrentSeq: lastSequenceNumber,
364363
});
365364
const fieldBatchCodec = makeFieldBatchCodec(options, codecVersions.fieldBatch);
@@ -370,24 +369,24 @@ class SharedTreeKernel extends SharedTreeCore<SharedTreeEditBuilder, SharedTreeC
370369
policy: defaultSchemaPolicy,
371370
},
372371
encodeType: options.treeEncodeType,
373-
originatorId: runtime.idCompressor.localSessionId,
374-
idCompressor: runtime.idCompressor,
372+
originatorId: idCompressor.localSessionId,
373+
idCompressor,
375374
};
376375
const forestSummarizer = new ForestSummarizer(
377376
forest,
378377
revisionTagCodec,
379378
fieldBatchCodec,
380379
encoderContext,
381380
options,
382-
runtime.idCompressor,
381+
idCompressor,
383382
);
384383
const removedRootsSummarizer = new DetachedFieldIndexSummarizer(removedRoots);
385384
const innerChangeFamily = new SharedTreeChangeFamily(
386385
revisionTagCodec,
387386
fieldBatchCodec,
388387
options,
389388
options.treeEncodeType,
390-
runtime.idCompressor,
389+
idCompressor,
391390
);
392391
const changeFamily = makeMitigatedChangeFamily(
393392
innerChangeFamily,
@@ -422,7 +421,7 @@ class SharedTreeKernel extends SharedTreeCore<SharedTreeEditBuilder, SharedTreeC
422421
changeFamily,
423422
options,
424423
codecVersions,
425-
runtime,
424+
idCompressor,
426425
schema,
427426
defaultSchemaPolicy,
428427
new DefaultResubmitMachine(
@@ -433,23 +432,18 @@ class SharedTreeKernel extends SharedTreeCore<SharedTreeEditBuilder, SharedTreeC
433432
changeEnricher,
434433
);
435434
const localBranch = this.getLocalBranch();
436-
this.checkout = createTreeCheckout(
437-
runtime.idCompressor,
438-
this.mintRevisionTag,
439-
revisionTagCodec,
440-
{
441-
branch: localBranch,
442-
changeFamily,
443-
schema,
444-
forest,
445-
fieldBatchCodec,
446-
removedRoots,
447-
chunkCompressionStrategy: options.treeEncodeType,
448-
logger,
449-
breaker: this.breaker,
450-
disposeForksAfterTransaction: options.disposeForksAfterTransaction,
451-
},
452-
);
435+
this.checkout = createTreeCheckout(idCompressor, this.mintRevisionTag, revisionTagCodec, {
436+
branch: localBranch,
437+
changeFamily,
438+
schema,
439+
forest,
440+
fieldBatchCodec,
441+
removedRoots,
442+
chunkCompressionStrategy: options.treeEncodeType,
443+
logger,
444+
breaker: this.breaker,
445+
disposeForksAfterTransaction: options.disposeForksAfterTransaction,
446+
});
453447

454448
this.checkout.transaction.events.on("started", () => {
455449
if (sharedObject.isAttached()) {

packages/dds/tree/src/test/shared-tree-core/utils.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ import type {
5151
IExperimentalIncrementalSummaryContext,
5252
ITelemetryContext,
5353
} from "@fluidframework/runtime-definitions/internal";
54-
import { createIdCompressor } from "@fluidframework/id-compressor/internal";
54+
import {
55+
createIdCompressor,
56+
type IIdCompressor,
57+
} from "@fluidframework/id-compressor/internal";
5558
import type {
5659
IFluidHandle,
5760
IFluidLoadable,
@@ -93,7 +96,7 @@ export function createTree<TIndexes extends readonly Summarizable[]>(
9396
logger,
9497
indexes,
9598
TreeCompressionStrategy.Uncompressed,
96-
new MockFluidDataStoreRuntime({ idCompressor: createIdCompressor() }),
99+
createIdCompressor(),
97100
new TreeStoredSchemaRepository(),
98101
resubmitMachine,
99102
enricher,
@@ -128,17 +131,15 @@ function createTreeInner(
128131
logger: ITelemetryBaseLogger | undefined,
129132
summarizables: readonly Summarizable[],
130133
chunkCompressionStrategy: TreeCompressionStrategy,
131-
runtime: IFluidDataStoreRuntime,
134+
idCompressor: IIdCompressor,
132135
schema: TreeStoredSchemaRepository,
133136
resubmitMachine?: ResubmitMachine<DefaultChangeset>,
134137
enricher?: ChangeEnricherReadonlyCheckout<DefaultChangeset>,
135138
editor?: () => DefaultEditBuilder,
136139
): [SharedTreeCore<DefaultEditBuilder, DefaultChangeset>, DefaultChangeFamily] {
137-
assert(runtime.idCompressor !== undefined, "The runtime must provide an ID compressor");
138-
139140
const codec = makeModularChangeCodecFamily(
140141
fieldKindConfigurations,
141-
new RevisionTagCodec(runtime.idCompressor),
142+
new RevisionTagCodec(idCompressor),
142143
makeFieldBatchCodec(codecOptions, formatVersions.fieldBatch),
143144
codecOptions,
144145
chunkCompressionStrategy,
@@ -156,7 +157,7 @@ function createTreeInner(
156157
changeFamily,
157158
codecOptions,
158159
formatVersions,
159-
runtime,
160+
idCompressor,
160161
schema,
161162
defaultSchemaPolicy,
162163
resubmitMachine,
@@ -208,14 +209,15 @@ export class TestSharedTreeCore extends SharedObject {
208209
enricher?: ChangeEnricherReadonlyCheckout<DefaultChangeset>,
209210
) {
210211
super(id, runtime, TestSharedTreeCore.attributes, id);
212+
assert(runtime.idCompressor !== undefined, "The runtime must provide an ID compressor");
211213
[this.kernel, this.changeFamily] = createTreeInner(
212214
this,
213215
this.serializer,
214216
(content, localOpMetadata) => this.submitLocalMessage(content, localOpMetadata),
215217
this.logger,
216218
summarizables,
217219
chunkCompressionStrategy,
218-
runtime,
220+
runtime.idCompressor,
219221
schema,
220222
resubmitMachine,
221223
enricher,

0 commit comments

Comments
 (0)