forked from microsoft/FluidFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntimeLayerCompatState.ts
More file actions
159 lines (148 loc) · 4.93 KB
/
runtimeLayerCompatState.ts
File metadata and controls
159 lines (148 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/
import {
generation,
LayerCompatibilityPolicyWindowMonths,
type ILayerCompatDetails,
type ILayerCompatSupportRequirements,
} from "@fluid-internal/client-utils";
import type { ICriticalContainerError } from "@fluidframework/container-definitions";
import {
encodeHandlesInContainerRuntime,
notifiesReadOnlyState,
} from "@fluidframework/runtime-definitions/internal";
import {
validateLayerCompatibility,
type MonitoringContext,
} from "@fluidframework/telemetry-utils/internal";
import { pkgVersion } from "./packageVersion.js";
/**
* The config key to disable strict loader layer compatibility check.
*/
export const disableStrictLoaderLayerCompatibilityCheckKey =
"Fluid.ContainerRuntime.DisableStrictLoaderLayerCompatibilityCheck";
/**
* The core compatibility details of the Runtime layer that is the same across all layer boundaries.
* @internal
*/
export const runtimeCoreCompatDetails = {
/**
* The package version of the Runtime layer.
*/
pkgVersion,
/**
* The current generation of the Runtime layer.
*/
generation,
} as const;
/**
* Runtime's compatibility details that is exposed to the Loader layer.
* @internal
*/
export const runtimeCompatDetailsForLoader: ILayerCompatDetails = {
...runtimeCoreCompatDetails,
/**
* The features supported by the Runtime layer across the Runtime / Loader boundary.
*/
supportedFeatures: new Set<string>(),
};
/**
* The requirements that the Loader layer must meet to be compatible with this Runtime.
* @internal
*/
export const loaderSupportRequirementsForRuntime: ILayerCompatSupportRequirements = {
/**
* Minimum generation that Loader must be at to be compatible with this Runtime. This is calculated
* based on the LayerCompatibilityPolicyWindowMonths.RuntimeLoader value which defines how many months old can
* the Loader layer be compared to the Runtime layer for them to still be considered compatible.
* The minimum valid generation value is 0.
*/
minSupportedGeneration: Math.max(
0,
runtimeCoreCompatDetails.generation - LayerCompatibilityPolicyWindowMonths.RuntimeLoader,
),
/**
* The features that the Loader must support to be compatible with Runtime.
*/
requiredFeatures: [],
};
/**
* Runtime's compatibility details that is exposed to the DataStore layer.
* @internal
*/
export const runtimeCompatDetailsForDataStore: ILayerCompatDetails = {
...runtimeCoreCompatDetails,
/**
* The features supported by the Runtime layer across the Runtime / DataStore boundary.
*/
supportedFeatures: new Set<string>([encodeHandlesInContainerRuntime, notifiesReadOnlyState]),
};
/**
* The requirements that the DataStore layer must meet to be compatible with this Runtime.
* @internal
*/
export const dataStoreSupportRequirementsForRuntime: ILayerCompatSupportRequirements = {
/**
* Minimum generation that DataStore must be at to be compatible with this Runtime. This is calculated
* based on the LayerCompatibilityPolicyWindowMonths.RuntimeDataStore value which defines how many months old can
* the DataStore layer be compared to the Runtime layer for them to still be considered compatible.
* The minimum valid generation value is 0.
*/
minSupportedGeneration: Math.max(
0,
runtimeCoreCompatDetails.generation -
LayerCompatibilityPolicyWindowMonths.RuntimeDataStore,
),
/**
* The features that the DataStore must support to be compatible with Runtime.
*/
requiredFeatures: [],
};
/**
* Validates that the Loader layer is compatible with this Runtime.
* @internal
*/
export function validateLoaderCompatibility(
maybeLoaderCompatDetailsForRuntime: ILayerCompatDetails | undefined,
disposeFn: (error?: ICriticalContainerError) => void,
mc: MonitoringContext,
): void {
// By default, use strictCompatibilityCheck here - If the Loader doesn't provide compatibility details,
// assume it's a very old version and should be considered incompatible,
// since Loader can drift far from the Runtime causing issues.
// Can be disabled via config `disableStrictLoaderLayerCompatibilityCheckKey`.
const disableStrictLoaderLayerCompatibilityCheck = mc.config.getBoolean(
disableStrictLoaderLayerCompatibilityCheckKey,
);
validateLayerCompatibility(
"runtime",
"loader",
runtimeCompatDetailsForLoader,
loaderSupportRequirementsForRuntime,
maybeLoaderCompatDetailsForRuntime,
disposeFn,
mc,
disableStrictLoaderLayerCompatibilityCheck !== true /* strictCompatibilityCheck */,
);
}
/**
* Validates that the DataStore layer is compatible with this Runtime.
* @internal
*/
export function validateDatastoreCompatibility(
maybeDataStoreCompatDetailsForRuntime: ILayerCompatDetails | undefined,
disposeFn: () => void,
mc: MonitoringContext,
): void {
validateLayerCompatibility(
"runtime",
"dataStore",
runtimeCompatDetailsForDataStore,
dataStoreSupportRequirementsForRuntime,
maybeDataStoreCompatDetailsForRuntime,
disposeFn,
mc,
);
}