Skip to content

Commit df53390

Browse files
Update how shared tree codec versions are generated (#25752)
This change updates how the write version for the different codecs in tree are determined. Currently, there is a mapping of `SharedTreeFormatVersion` to a list of write versions for all codecs. The `SharedTreeFormatVersion` is one of the options that can be passed when creating a tree and the codecs version are selected from the mapping based on this value. With this change, `SharedTreeFormatVersion` will be removed. Instead, the write versions for the codecs will be selected based on the `minVersionForCollab` option that is also passed during tree creation. The `minVersionForCollab` will be passed down to each codec and it can decide what write version it wants based on this. This PR also standardizes how the various versions are maintained by the codecs (using an `as const` enum-like object and branded values, and a function that generates the right version based on the `minVersionForCollab`). The mapping from `SharedTreeFormatVersion` to `minVersionForCollab` is as follows: * `SharedTreeFormatVersion.v1`: no longer an option * `SharedTreeFormatVersion.v2`: no longer an option * `SharedTreeFormatVersion.v3`: `minVersionForCollab: FluidClientVersion.v2_0` * `SharedTreeFormatVersion.v4`: was never an option, still not an option * `SharedTreeFormatVersion.v5`: `minVersionForCollab: FluidClientVersion.v2_43` * `SharedTreeFormatVersion.vSharedBranches`: no longer an option. Use `SharedTreeOptions.enableSharedBranches` instead. Unchanged: specifying `minVersionForCollab: FluidClientVersion.v2_52` will enable `DetachedFieldIndexFormatVersion.v2`. [AB#51463](https://dev.azure.com/fluidframework/235294da-091d-4c29-84fc-cdfc3d90890b/_workitems/edit/51463). ## Breaking Changes `SharedTreeFormatOptions` (internal) no longer has a `formatVersion` field. --------- Co-authored-by: yann-achard-MS <97201204+yann-achard-MS@users.noreply.github.com>
1 parent 39cecea commit df53390

File tree

256 files changed

+1484
-28636
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

256 files changed

+1484
-28636
lines changed

.changeset/big-items-stop.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
"@fluidframework/tree": minor
3+
"fluid-framework": minor
4+
"__section": tree
5+
---
6+
`formatVersion` removed from the options passed to `configuredSharedTree`
7+
8+
Note: this change may break users of alpha APIs. See below for details.
9+
10+
`SharedTreeOptions` (which is passed to `configuredSharedTree`) no longer includes a `formatVersion: SharedTreeFormatVersion[keyof SharedTreeFormatVersion]` field.
11+
The concept of `SharedTreeFormatVersion` has been removed altogether.
12+
Instead, users are expected to leverage the already existing `minVersionForCollab` field.
13+
14+
For migration purposes, the mapping from `SharedTreeFormatVersion` to `minVersionForCollab` is as follows:
15+
* `SharedTreeFormatVersion.v1`: no supported equivalent
16+
* `SharedTreeFormatVersion.v2`: no supported equivalent
17+
* `SharedTreeFormatVersion.v3`: `minVersionForCollab: FluidClientVersion.v2_0`
18+
* `SharedTreeFormatVersion.v5`: `minVersionForCollab: FluidClientVersion.v2_43`
19+
* `SharedTreeFormatVersion.vSharedBranches`: `minVersionForCollab: FluidClientVersion.v2_43` + `SharedTreeOptions.enableSharedBranches`
20+
21+
The values for which there is no supported equivalent `minVersionForCollab` were never given official support.
22+
[Contact](https://github.com/microsoft/FluidFramework/issues) the Fluid Framework team if you need help migrating away from them.

packages/dds/tree/api-report/tree.alpha.api.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ type FlexListToUnion<TList extends FlexList> = ExtractItemType<TList[number]>;
320320
// @alpha
321321
export const FluidClientVersion: {
322322
readonly v2_0: "2.0.0";
323+
readonly v2_43: "2.43.0";
323324
readonly v2_52: "2.52.0";
324325
};
325326

@@ -998,7 +999,6 @@ type ScopedSchemaName<TScope extends string | undefined, TName extends number |
998999

9991000
// @alpha @input
10001001
export interface SharedTreeFormatOptions {
1001-
formatVersion: SharedTreeFormatVersion[keyof SharedTreeFormatVersion];
10021002
treeEncodeType: TreeCompressionStrategy;
10031003
}
10041004

@@ -1015,7 +1015,9 @@ export const SharedTreeFormatVersion: {
10151015
export type SharedTreeFormatVersion = typeof SharedTreeFormatVersion;
10161016

10171017
// @alpha @input
1018-
export type SharedTreeOptions = Partial<CodecWriteOptions> & Partial<SharedTreeFormatOptions> & SharedTreeOptionsBeta;
1018+
export interface SharedTreeOptions extends Partial<CodecWriteOptions>, Partial<SharedTreeFormatOptions>, SharedTreeOptionsBeta {
1019+
readonly enableSharedBranches?: boolean;
1020+
}
10191021

10201022
// @beta @input
10211023
export type SharedTreeOptionsBeta = ForestOptions;

packages/dds/tree/src/codec/codec.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,23 @@ export const FluidClientVersion = {
499499
// then update it to "2.001" once we actually have the opt in working.
500500
// v2_1 = v2_0,
501501

502-
/** Fluid Framework Client 2.52 and newer. */
503-
// New formats introduced in 2.52:
504-
// - DetachedFieldIndex FormatV2
502+
/**
503+
* Fluid Framework Client 2.43 and newer.
504+
*
505+
* New formats introduced in 2.43:
506+
* - SchemaFormatVersion.v2
507+
* - MessageFormatVersion.v4
508+
* - EditManagerFormatVersion.v4
509+
* - Sequence format version 3
510+
*/
511+
v2_43: "2.43.0",
512+
513+
/**
514+
* Fluid Framework Client 2.52 and newer.
515+
*
516+
* New formats introduced in 2.52:
517+
* - DetachedFieldIndexFormatVersion.v2
518+
*/
505519
v2_52: "2.52.0",
506520
} as const satisfies Record<string, MinimumVersionForCollab>;
507521

packages/dds/tree/src/core/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ export {
151151
type SchemaAndPolicy,
152152
Multiplicity,
153153
type SchemaPolicy,
154-
SchemaVersion,
155-
type SchemaFormatVersion,
154+
SchemaFormatVersion,
156155
} from "./schema-stored/index.js";
157156

158157
export {

packages/dds/tree/src/core/schema-stored/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ export {
2323
storedSchemaDecodeDispatcher,
2424
type SchemaAndPolicy,
2525
type SchemaPolicy,
26-
SchemaVersion,
27-
type SchemaFormatVersion,
26+
SchemaFormatVersion,
2827
} from "./schema.js";
2928
export {
3029
type TreeStoredSchemaSubscription,

packages/dds/tree/src/core/schema-stored/schema.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@ import type { Multiplicity } from "./multiplicity.js";
3333
/**
3434
* The format version for the schema.
3535
*/
36-
export enum SchemaVersion {
37-
v1 = 1,
36+
export const SchemaFormatVersion = {
37+
v1: 1,
3838
/**
3939
* Adds persisted metadata to the node schema and field schema.
4040
*/
41-
v2 = 2,
42-
}
43-
export type SchemaFormatVersion = Brand<SchemaVersion, "SchemaFormatVersion">;
41+
v2: 2,
42+
} as const;
43+
export type SchemaFormatVersion = Brand<
44+
(typeof SchemaFormatVersion)[keyof typeof SchemaFormatVersion],
45+
"SchemaFormatVersion"
46+
>;
4447

4548
type FieldSchemaFormat = FieldSchemaFormatV1 | FieldSchemaFormatV2;
4649

packages/dds/tree/src/core/tree/detachedFieldIndexCodecCommon.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { hasSingle } from "../../util/index.js";
1212

1313
import {
1414
Format,
15+
type DetachedFieldIndexFormatVersion,
1516
type EncodedRootsForRevision,
1617
type RootRanges,
1718
} from "./detachedFieldIndexFormatCommon.js";
@@ -27,7 +28,7 @@ import type { Static, TSchema } from "@sinclair/typebox";
2728
export function makeDetachedFieldIndexCodecFromMajorCodec<
2829
TEncodedRevisionTag,
2930
TEncodedRevisionTagSchema extends TSchema,
30-
TVersion extends number,
31+
TVersion extends DetachedFieldIndexFormatVersion,
3132
>(
3233
options: ICodecOptions,
3334
majorCodec: IJsonCodec<Major, TEncodedRevisionTag>,

packages/dds/tree/src/core/tree/detachedFieldIndexCodecV1.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ import {
1414
RevisionTagSchema,
1515
} from "../rebase/index.js";
1616

17-
import { type FormatV1, version1 } from "./detachedFieldIndexFormatV1.js";
17+
import type { FormatV1 } from "./detachedFieldIndexFormatV1.js";
1818
import type { DetachedFieldSummaryData, Major } from "./detachedFieldIndexTypes.js";
1919
import { makeDetachedFieldIndexCodecFromMajorCodec } from "./detachedFieldIndexCodecCommon.js";
20+
import { DetachedFieldIndexFormatVersion } from "./detachedFieldIndexFormatCommon.js";
21+
import { brand } from "../../util/index.js";
2022

2123
class MajorCodec implements IJsonCodec<Major, EncodedRevisionTag> {
2224
public constructor(
@@ -74,7 +76,7 @@ export function makeDetachedNodeToFieldCodecV1(
7476
return makeDetachedFieldIndexCodecFromMajorCodec(
7577
options,
7678
majorCodec,
77-
version1,
79+
brand(DetachedFieldIndexFormatVersion.v1),
7880
RevisionTagSchema,
7981
);
8082
}

packages/dds/tree/src/core/tree/detachedFieldIndexCodecV2.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ import type { IIdCompressor, StableId } from "@fluidframework/id-compressor";
99
import type { ICodecOptions, IJsonCodec } from "../../codec/index.js";
1010
import type { EncodedRevisionTag, RevisionTagCodec, RevisionTag } from "../rebase/index.js";
1111

12-
import {
13-
type FormatV2,
14-
StableOrFinalRevisionTag,
15-
version2,
16-
} from "./detachedFieldIndexFormatV2.js";
12+
import { type FormatV2, StableOrFinalRevisionTag } from "./detachedFieldIndexFormatV2.js";
1713
import type { DetachedFieldSummaryData, Major } from "./detachedFieldIndexTypes.js";
1814
import { makeDetachedFieldIndexCodecFromMajorCodec } from "./detachedFieldIndexCodecCommon.js";
1915
import { isStableId } from "@fluidframework/id-compressor/internal";
16+
import { DetachedFieldIndexFormatVersion } from "./detachedFieldIndexFormatCommon.js";
17+
import { brand } from "../../util/index.js";
2018

2119
class MajorCodec implements IJsonCodec<Major> {
2220
public constructor(
@@ -66,7 +64,7 @@ export function makeDetachedNodeToFieldCodecV2(
6664
return makeDetachedFieldIndexCodecFromMajorCodec(
6765
options,
6866
majorCodec,
69-
version2,
67+
brand(DetachedFieldIndexFormatVersion.v2),
7068
StableOrFinalRevisionTag,
7169
);
7270
}

packages/dds/tree/src/core/tree/detachedFieldIndexCodecs.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import type { IIdCompressor } from "@fluidframework/id-compressor";
7+
import type { MinimumVersionForCollab } from "@fluidframework/runtime-definitions/internal";
78

89
import {
910
type CodecTree,
@@ -16,22 +17,35 @@ import {
1617
} from "../../codec/index.js";
1718
import type { RevisionTagCodec } from "../rebase/index.js";
1819

19-
import { version1 } from "./detachedFieldIndexFormatV1.js";
20-
import { version2 } from "./detachedFieldIndexFormatV2.js";
2120
import { makeDetachedNodeToFieldCodecV1 } from "./detachedFieldIndexCodecV1.js";
2221
import { makeDetachedNodeToFieldCodecV2 } from "./detachedFieldIndexCodecV2.js";
2322
import type { DetachedFieldSummaryData } from "./detachedFieldIndexTypes.js";
24-
import type { Brand } from "../../util/index.js";
23+
import { DetachedFieldIndexFormatVersion } from "./detachedFieldIndexFormatCommon.js";
24+
import { brand } from "../../util/index.js";
25+
26+
/**
27+
* Convert a MinimumVersionForCollab to a version for detached field codecs.
28+
* @param clientVersion - The MinimumVersionForCollab to convert.
29+
* @returns The detached field codec version that corresponds to the provided MinimumVersionForCollab.
30+
*/
31+
function clientVersionToDetachedFieldVersion(
32+
clientVersion: MinimumVersionForCollab,
33+
): DetachedFieldIndexFormatVersion {
34+
return clientVersion < FluidClientVersion.v2_52
35+
? brand(DetachedFieldIndexFormatVersion.v1)
36+
: brand(DetachedFieldIndexFormatVersion.v2);
37+
}
2538

2639
export function makeDetachedFieldIndexCodec(
2740
revisionTagCodec: RevisionTagCodec,
2841
options: CodecWriteOptions,
2942
idCompressor: IIdCompressor,
3043
): IJsonCodec<DetachedFieldSummaryData> {
3144
const family = makeDetachedFieldIndexCodecFamily(revisionTagCodec, options, idCompressor);
32-
const writeVersion =
33-
options.minVersionForCollab < FluidClientVersion.v2_52 ? version1 : version2;
34-
return makeVersionDispatchingCodec(family, { ...options, writeVersion });
45+
return makeVersionDispatchingCodec(family, {
46+
...options,
47+
writeVersion: clientVersionToDetachedFieldVersion(options.minVersionForCollab),
48+
});
3549
}
3650

3751
export function makeDetachedFieldIndexCodecFamily(
@@ -40,14 +54,22 @@ export function makeDetachedFieldIndexCodecFamily(
4054
idCompressor: IIdCompressor,
4155
): ICodecFamily<DetachedFieldSummaryData> {
4256
return makeCodecFamily([
43-
[version1, makeDetachedNodeToFieldCodecV1(revisionTagCodec, options, idCompressor)],
44-
[version2, makeDetachedNodeToFieldCodecV2(revisionTagCodec, options, idCompressor)],
57+
[
58+
DetachedFieldIndexFormatVersion.v1,
59+
makeDetachedNodeToFieldCodecV1(revisionTagCodec, options, idCompressor),
60+
],
61+
[
62+
DetachedFieldIndexFormatVersion.v2,
63+
makeDetachedNodeToFieldCodecV2(revisionTagCodec, options, idCompressor),
64+
],
4565
]);
4666
}
4767

48-
export type DetachedFieldIndexFormatVersion = Brand<1 | 2, "DetachedFieldIndexFormatVersion">;
4968
export function getCodecTreeForDetachedFieldIndexFormat(
50-
version: DetachedFieldIndexFormatVersion,
69+
clientVersion: MinimumVersionForCollab,
5170
): CodecTree {
52-
return { name: "DetachedFieldIndex", version };
71+
return {
72+
name: "DetachedFieldIndex",
73+
version: clientVersionToDetachedFieldVersion(clientVersion),
74+
};
5375
}

0 commit comments

Comments
 (0)