@fluidframework/container-loader 2.0.2 → 2.1.0-276326
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.cjs +2 -5
- package/api-extractor/api-extractor.legacy.json +4 -0
- package/api-report/container-loader.beta.api.md +0 -27
- package/api-report/{container-loader.alpha.api.md → container-loader.legacy.alpha.api.md} +0 -27
- package/api-report/container-loader.public.api.md +0 -27
- package/dist/attachment.d.ts +2 -1
- package/dist/attachment.d.ts.map +1 -1
- package/dist/attachment.js.map +1 -1
- package/dist/audience.d.ts.map +1 -1
- package/dist/audience.js +4 -4
- package/dist/audience.js.map +1 -1
- package/dist/catchUpMonitor.d.ts +15 -4
- package/dist/catchUpMonitor.d.ts.map +1 -1
- package/dist/catchUpMonitor.js +12 -3
- package/dist/catchUpMonitor.js.map +1 -1
- package/dist/connectionManager.d.ts +24 -8
- package/dist/connectionManager.d.ts.map +1 -1
- package/dist/connectionManager.js +36 -23
- package/dist/connectionManager.js.map +1 -1
- package/dist/connectionStateHandler.d.ts +30 -20
- package/dist/connectionStateHandler.d.ts.map +1 -1
- package/dist/connectionStateHandler.js +15 -11
- package/dist/connectionStateHandler.js.map +1 -1
- package/dist/container.d.ts +7 -2
- package/dist/container.d.ts.map +1 -1
- package/dist/container.js +45 -28
- package/dist/container.js.map +1 -1
- package/dist/containerContext.d.ts +8 -4
- package/dist/containerContext.d.ts.map +1 -1
- package/dist/containerContext.js +3 -1
- package/dist/containerContext.js.map +1 -1
- package/dist/containerStorageAdapter.d.ts +1 -1
- package/dist/containerStorageAdapter.d.ts.map +1 -1
- package/dist/containerStorageAdapter.js +12 -6
- package/dist/containerStorageAdapter.js.map +1 -1
- package/dist/contracts.d.ts +17 -8
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +4 -2
- package/dist/contracts.js.map +1 -1
- package/dist/debugLogger.js +3 -3
- package/dist/debugLogger.js.map +1 -1
- package/dist/deltaManager.d.ts +13 -9
- package/dist/deltaManager.d.ts.map +1 -1
- package/dist/deltaManager.js +32 -23
- package/dist/deltaManager.js.map +1 -1
- package/dist/deltaQueue.d.ts +1 -4
- package/dist/deltaQueue.d.ts.map +1 -1
- package/dist/deltaQueue.js +2 -2
- package/dist/deltaQueue.js.map +1 -1
- package/dist/disposal.d.ts +1 -1
- package/dist/disposal.d.ts.map +1 -1
- package/dist/disposal.js.map +1 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js.map +1 -1
- package/dist/legacy.d.ts +1 -1
- package/dist/loadPaused.d.ts +2 -2
- package/dist/loadPaused.d.ts.map +1 -1
- package/dist/loadPaused.js +7 -3
- package/dist/loadPaused.js.map +1 -1
- package/dist/loader.d.ts +10 -1
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +11 -1
- package/dist/loader.js.map +1 -1
- package/dist/location-redirection-utilities/resolveWithLocationRedirection.d.ts +2 -1
- package/dist/location-redirection-utilities/resolveWithLocationRedirection.d.ts.map +1 -1
- package/dist/location-redirection-utilities/resolveWithLocationRedirection.js +3 -1
- package/dist/location-redirection-utilities/resolveWithLocationRedirection.js.map +1 -1
- package/dist/memoryBlobStorage.d.ts.map +1 -1
- package/dist/memoryBlobStorage.js +4 -2
- package/dist/memoryBlobStorage.js.map +1 -1
- package/dist/noopHeuristic.js +1 -1
- package/dist/noopHeuristic.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/protocol/protocol.d.ts +4 -3
- package/dist/protocol/protocol.d.ts.map +1 -1
- package/dist/protocol/protocol.js +6 -5
- package/dist/protocol/protocol.js.map +1 -1
- package/dist/protocol/quorum.d.ts +11 -8
- package/dist/protocol/quorum.d.ts.map +1 -1
- package/dist/protocol/quorum.js +8 -8
- package/dist/protocol/quorum.js.map +1 -1
- package/dist/protocol.d.ts +2 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +7 -2
- package/dist/protocol.js.map +1 -1
- package/dist/protocolTreeDocumentStorageService.d.ts +2 -2
- package/dist/protocolTreeDocumentStorageService.d.ts.map +1 -1
- package/dist/protocolTreeDocumentStorageService.js.map +1 -1
- package/dist/retriableDocumentStorageService.d.ts.map +1 -1
- package/dist/retriableDocumentStorageService.js +4 -1
- package/dist/retriableDocumentStorageService.js.map +1 -1
- package/dist/serializedStateManager.d.ts +29 -12
- package/dist/serializedStateManager.d.ts.map +1 -1
- package/dist/serializedStateManager.js +55 -24
- package/dist/serializedStateManager.js.map +1 -1
- package/dist/utils.d.ts +4 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +15 -6
- package/dist/utils.js.map +1 -1
- package/lib/attachment.d.ts +2 -1
- package/lib/attachment.d.ts.map +1 -1
- package/lib/attachment.js.map +1 -1
- package/lib/audience.d.ts.map +1 -1
- package/lib/audience.js +4 -4
- package/lib/audience.js.map +1 -1
- package/lib/catchUpMonitor.d.ts +15 -4
- package/lib/catchUpMonitor.d.ts.map +1 -1
- package/lib/catchUpMonitor.js +12 -3
- package/lib/catchUpMonitor.js.map +1 -1
- package/lib/connectionManager.d.ts +24 -8
- package/lib/connectionManager.d.ts.map +1 -1
- package/lib/connectionManager.js +36 -23
- package/lib/connectionManager.js.map +1 -1
- package/lib/connectionStateHandler.d.ts +30 -20
- package/lib/connectionStateHandler.d.ts.map +1 -1
- package/lib/connectionStateHandler.js +14 -12
- package/lib/connectionStateHandler.js.map +1 -1
- package/lib/container.d.ts +7 -2
- package/lib/container.d.ts.map +1 -1
- package/lib/container.js +45 -28
- package/lib/container.js.map +1 -1
- package/lib/containerContext.d.ts +8 -4
- package/lib/containerContext.d.ts.map +1 -1
- package/lib/containerContext.js +3 -1
- package/lib/containerContext.js.map +1 -1
- package/lib/containerStorageAdapter.d.ts +1 -1
- package/lib/containerStorageAdapter.d.ts.map +1 -1
- package/lib/containerStorageAdapter.js +12 -6
- package/lib/containerStorageAdapter.js.map +1 -1
- package/lib/contracts.d.ts +17 -8
- package/lib/contracts.d.ts.map +1 -1
- package/lib/contracts.js +4 -2
- package/lib/contracts.js.map +1 -1
- package/lib/debugLogger.js +3 -3
- package/lib/debugLogger.js.map +1 -1
- package/lib/deltaManager.d.ts +13 -9
- package/lib/deltaManager.d.ts.map +1 -1
- package/lib/deltaManager.js +32 -23
- package/lib/deltaManager.js.map +1 -1
- package/lib/deltaQueue.d.ts +1 -4
- package/lib/deltaQueue.d.ts.map +1 -1
- package/lib/deltaQueue.js +2 -2
- package/lib/deltaQueue.js.map +1 -1
- package/lib/disposal.d.ts +1 -1
- package/lib/disposal.d.ts.map +1 -1
- package/lib/disposal.js.map +1 -1
- package/lib/error.d.ts.map +1 -1
- package/lib/error.js.map +1 -1
- package/lib/legacy.d.ts +1 -1
- package/lib/loadPaused.d.ts +2 -2
- package/lib/loadPaused.d.ts.map +1 -1
- package/lib/loadPaused.js +8 -4
- package/lib/loadPaused.js.map +1 -1
- package/lib/loader.d.ts +10 -1
- package/lib/loader.d.ts.map +1 -1
- package/lib/loader.js +11 -1
- package/lib/loader.js.map +1 -1
- package/lib/location-redirection-utilities/resolveWithLocationRedirection.d.ts +2 -1
- package/lib/location-redirection-utilities/resolveWithLocationRedirection.d.ts.map +1 -1
- package/lib/location-redirection-utilities/resolveWithLocationRedirection.js +3 -1
- package/lib/location-redirection-utilities/resolveWithLocationRedirection.js.map +1 -1
- package/lib/memoryBlobStorage.d.ts.map +1 -1
- package/lib/memoryBlobStorage.js +4 -2
- package/lib/memoryBlobStorage.js.map +1 -1
- package/lib/noopHeuristic.js +1 -1
- package/lib/noopHeuristic.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/protocol/protocol.d.ts +4 -3
- package/lib/protocol/protocol.d.ts.map +1 -1
- package/lib/protocol/protocol.js +6 -5
- package/lib/protocol/protocol.js.map +1 -1
- package/lib/protocol/quorum.d.ts +11 -8
- package/lib/protocol/quorum.d.ts.map +1 -1
- package/lib/protocol/quorum.js +8 -8
- package/lib/protocol/quorum.js.map +1 -1
- package/lib/protocol.d.ts +2 -0
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +7 -2
- package/lib/protocol.js.map +1 -1
- package/lib/protocolTreeDocumentStorageService.d.ts +2 -2
- package/lib/protocolTreeDocumentStorageService.d.ts.map +1 -1
- package/lib/protocolTreeDocumentStorageService.js.map +1 -1
- package/lib/retriableDocumentStorageService.d.ts.map +1 -1
- package/lib/retriableDocumentStorageService.js +4 -1
- package/lib/retriableDocumentStorageService.js.map +1 -1
- package/lib/serializedStateManager.d.ts +29 -12
- package/lib/serializedStateManager.d.ts.map +1 -1
- package/lib/serializedStateManager.js +56 -25
- package/lib/serializedStateManager.js.map +1 -1
- package/lib/utils.d.ts +4 -2
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +16 -7
- package/lib/utils.js.map +1 -1
- package/package.json +21 -17
- package/src/attachment.ts +2 -1
- package/src/audience.ts +4 -4
- package/src/catchUpMonitor.ts +23 -8
- package/src/connectionManager.ts +85 -60
- package/src/connectionStateHandler.ts +85 -63
- package/src/container.ts +118 -84
- package/src/containerContext.ts +5 -3
- package/src/containerStorageAdapter.ts +20 -13
- package/src/contracts.ts +21 -9
- package/src/debugLogger.ts +4 -4
- package/src/deltaManager.ts +75 -56
- package/src/deltaQueue.ts +16 -10
- package/src/disposal.ts +3 -3
- package/src/error.ts +2 -1
- package/src/loadPaused.ts +16 -8
- package/src/loader.ts +20 -2
- package/src/location-redirection-utilities/resolveWithLocationRedirection.ts +7 -3
- package/src/memoryBlobStorage.ts +5 -3
- package/src/noopHeuristic.ts +1 -1
- package/src/packageVersion.ts +1 -1
- package/src/protocol/protocol.ts +12 -11
- package/src/protocol/quorum.ts +49 -40
- package/src/protocol.ts +12 -4
- package/src/protocolTreeDocumentStorageService.ts +3 -2
- package/src/retriableDocumentStorageService.ts +6 -3
- package/src/serializedStateManager.ts +95 -39
- package/src/utils.ts +26 -10
|
@@ -28,30 +28,44 @@ const JoinOpTimeoutMs = 45000;
|
|
|
28
28
|
// Timeout waiting for "self" join signal, before giving up
|
|
29
29
|
const JoinSignalTimeoutMs = 10000;
|
|
30
30
|
|
|
31
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Constructor parameter type for passing in dependencies needed by the ConnectionStateHandler
|
|
33
|
+
*/
|
|
32
34
|
export interface IConnectionStateHandlerInputs {
|
|
33
35
|
logger: ITelemetryLoggerExt;
|
|
34
36
|
mc: MonitoringContext;
|
|
35
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Log to telemetry any change in state, included to Connecting
|
|
39
|
+
*/
|
|
36
40
|
connectionStateChanged: (
|
|
37
41
|
value: ConnectionState,
|
|
38
42
|
oldState: ConnectionState,
|
|
39
43
|
reason?: IConnectionStateChangeReason,
|
|
40
44
|
) => void;
|
|
41
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* Whether to expect the client to join in write mode on next connection
|
|
47
|
+
*/
|
|
42
48
|
shouldClientJoinWrite: () => boolean;
|
|
43
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* (Optional) How long should we wait on our previous client's Leave op before transitioning to Connected again
|
|
51
|
+
*/
|
|
44
52
|
maxClientLeaveWaitTime: number | undefined;
|
|
45
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Log an issue encountered while in the Connecting state. details will be logged as a JSON string
|
|
55
|
+
*/
|
|
46
56
|
logConnectionIssue: (
|
|
47
57
|
eventName: string,
|
|
48
58
|
category: TelemetryEventCategory,
|
|
49
59
|
details?: ITelemetryBaseProperties,
|
|
50
60
|
) => void;
|
|
51
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Callback to note that an old local client ID is still present in the Quorum that should have left and should now be considered invalid
|
|
63
|
+
*/
|
|
52
64
|
clientShouldHaveLeft: (clientId: string) => void;
|
|
53
65
|
|
|
54
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Some critical error was hit. Container should be closed and error logged.
|
|
68
|
+
*/
|
|
55
69
|
onCriticalError: (error: unknown) => void;
|
|
56
70
|
}
|
|
57
71
|
|
|
@@ -90,9 +104,9 @@ export interface IConnectionStateHandler {
|
|
|
90
104
|
|
|
91
105
|
export function createConnectionStateHandler(
|
|
92
106
|
inputs: IConnectionStateHandlerInputs,
|
|
93
|
-
deltaManager: IDeltaManager<
|
|
107
|
+
deltaManager: IDeltaManager<unknown, unknown>,
|
|
94
108
|
clientId?: string,
|
|
95
|
-
) {
|
|
109
|
+
): ConnectionStateHandler | ConnectionStateCatchup {
|
|
96
110
|
const config = inputs.mc.config;
|
|
97
111
|
return createConnectionStateHandlerCore(
|
|
98
112
|
config.getBoolean("Fluid.Container.DisableCatchUpBeforeDeclaringConnected") !== true, // connectedRaisedWhenCaughtUp
|
|
@@ -107,10 +121,10 @@ export function createConnectionStateHandlerCore(
|
|
|
107
121
|
connectedRaisedWhenCaughtUp: boolean,
|
|
108
122
|
readClientsWaitForJoinSignal: boolean,
|
|
109
123
|
inputs: IConnectionStateHandlerInputs,
|
|
110
|
-
deltaManager: IDeltaManager<
|
|
124
|
+
deltaManager: IDeltaManager<unknown, unknown>,
|
|
111
125
|
clientId?: string,
|
|
112
|
-
) {
|
|
113
|
-
const factory = (handler: IConnectionStateHandlerInputs) =>
|
|
126
|
+
): ConnectionStateCatchup | ConnectionStateHandler {
|
|
127
|
+
const factory = (handler: IConnectionStateHandlerInputs): ConnectionStateHandler =>
|
|
114
128
|
new ConnectionStateHandler(handler, readClientsWaitForJoinSignal, clientId);
|
|
115
129
|
|
|
116
130
|
return connectedRaisedWhenCaughtUp
|
|
@@ -145,101 +159,102 @@ class ConnectionStateHandlerPassThrough
|
|
|
145
159
|
this.pimpl = pimplFactory(this);
|
|
146
160
|
}
|
|
147
161
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
public get connectionState() {
|
|
162
|
+
// #region IConnectionStateHandler
|
|
163
|
+
|
|
164
|
+
public get connectionState(): ConnectionState {
|
|
152
165
|
return this.pimpl.connectionState;
|
|
153
166
|
}
|
|
154
|
-
public get pendingClientId() {
|
|
167
|
+
public get pendingClientId(): string | undefined {
|
|
155
168
|
return this.pimpl.pendingClientId;
|
|
156
169
|
}
|
|
157
|
-
public get clientId() {
|
|
170
|
+
public get clientId(): string | undefined {
|
|
158
171
|
return this.pimpl.clientId;
|
|
159
172
|
}
|
|
160
173
|
|
|
161
|
-
public containerSaved() {
|
|
174
|
+
public containerSaved(): void {
|
|
162
175
|
return this.pimpl.containerSaved();
|
|
163
176
|
}
|
|
164
|
-
public dispose() {
|
|
177
|
+
public dispose(): void {
|
|
165
178
|
return this.pimpl.dispose();
|
|
166
179
|
}
|
|
167
|
-
public initProtocol(protocol: IProtocolHandler) {
|
|
180
|
+
public initProtocol(protocol: IProtocolHandler): void {
|
|
168
181
|
return this.pimpl.initProtocol(protocol);
|
|
169
182
|
}
|
|
170
|
-
public receivedDisconnectEvent(reason: IConnectionStateChangeReason<IAnyDriverError>) {
|
|
183
|
+
public receivedDisconnectEvent(reason: IConnectionStateChangeReason<IAnyDriverError>): void {
|
|
171
184
|
return this.pimpl.receivedDisconnectEvent(reason);
|
|
172
185
|
}
|
|
173
186
|
|
|
174
|
-
public establishingConnection(reason: IConnectionStateChangeReason) {
|
|
187
|
+
public establishingConnection(reason: IConnectionStateChangeReason): void {
|
|
175
188
|
return this.pimpl.establishingConnection(reason);
|
|
176
189
|
}
|
|
177
190
|
|
|
178
|
-
public cancelEstablishingConnection(reason: IConnectionStateChangeReason) {
|
|
191
|
+
public cancelEstablishingConnection(reason: IConnectionStateChangeReason): void {
|
|
179
192
|
return this.pimpl.cancelEstablishingConnection(reason);
|
|
180
193
|
}
|
|
181
194
|
|
|
182
|
-
public receivedConnectEvent(details: IConnectionDetailsInternal) {
|
|
195
|
+
public receivedConnectEvent(details: IConnectionDetailsInternal): void {
|
|
183
196
|
return this.pimpl.receivedConnectEvent(details);
|
|
184
197
|
}
|
|
185
198
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
199
|
+
// #endregion
|
|
200
|
+
|
|
201
|
+
// #region IConnectionStateHandlerInputs
|
|
189
202
|
|
|
190
|
-
public get logger() {
|
|
203
|
+
public get logger(): ITelemetryLoggerExt {
|
|
191
204
|
return this.inputs.logger;
|
|
192
205
|
}
|
|
193
|
-
public get mc() {
|
|
206
|
+
public get mc(): MonitoringContext {
|
|
194
207
|
return this.inputs.mc;
|
|
195
208
|
}
|
|
196
209
|
public connectionStateChanged(
|
|
197
210
|
value: ConnectionState,
|
|
198
211
|
oldState: ConnectionState,
|
|
199
212
|
reason?: IConnectionStateChangeReason,
|
|
200
|
-
) {
|
|
213
|
+
): void {
|
|
201
214
|
return this.inputs.connectionStateChanged(value, oldState, reason);
|
|
202
215
|
}
|
|
203
|
-
public shouldClientJoinWrite() {
|
|
216
|
+
public shouldClientJoinWrite(): boolean {
|
|
204
217
|
return this.inputs.shouldClientJoinWrite();
|
|
205
218
|
}
|
|
206
|
-
public get maxClientLeaveWaitTime() {
|
|
219
|
+
public get maxClientLeaveWaitTime(): number | undefined {
|
|
207
220
|
return this.inputs.maxClientLeaveWaitTime;
|
|
208
221
|
}
|
|
209
222
|
public logConnectionIssue(
|
|
210
223
|
eventName: string,
|
|
211
224
|
category: TelemetryEventCategory,
|
|
212
225
|
details?: ITelemetryBaseProperties,
|
|
213
|
-
) {
|
|
226
|
+
): void {
|
|
214
227
|
return this.inputs.logConnectionIssue(eventName, category, details);
|
|
215
228
|
}
|
|
216
|
-
public clientShouldHaveLeft(clientId: string) {
|
|
229
|
+
public clientShouldHaveLeft(clientId: string): void {
|
|
217
230
|
return this.inputs.clientShouldHaveLeft(clientId);
|
|
218
231
|
}
|
|
219
232
|
|
|
220
|
-
public onCriticalError(error: unknown) {
|
|
233
|
+
public onCriticalError(error: unknown): void {
|
|
221
234
|
return this.inputs.onCriticalError(error);
|
|
222
235
|
}
|
|
236
|
+
|
|
237
|
+
// #endregion
|
|
223
238
|
}
|
|
224
239
|
|
|
225
240
|
/**
|
|
226
241
|
* Implementation of IConnectionStateHandler pass-through adapter that waits for specific sequence number
|
|
227
242
|
* before raising connected event
|
|
228
243
|
*/
|
|
229
|
-
class ConnectionStateCatchup extends ConnectionStateHandlerPassThrough {
|
|
244
|
+
export class ConnectionStateCatchup extends ConnectionStateHandlerPassThrough {
|
|
230
245
|
private catchUpMonitor: ICatchUpMonitor | undefined;
|
|
231
246
|
|
|
232
247
|
constructor(
|
|
233
248
|
inputs: IConnectionStateHandlerInputs,
|
|
234
249
|
pimplFactory: (handler: IConnectionStateHandlerInputs) => IConnectionStateHandler,
|
|
235
|
-
private readonly deltaManager: IDeltaManager<
|
|
250
|
+
private readonly deltaManager: IDeltaManager<unknown, unknown>,
|
|
236
251
|
) {
|
|
237
252
|
super(inputs, pimplFactory);
|
|
238
253
|
this._connectionState = this.pimpl.connectionState;
|
|
239
254
|
}
|
|
240
255
|
|
|
241
256
|
private _connectionState: ConnectionState;
|
|
242
|
-
public get connectionState() {
|
|
257
|
+
public get connectionState(): ConnectionState {
|
|
243
258
|
return this._connectionState;
|
|
244
259
|
}
|
|
245
260
|
|
|
@@ -247,9 +262,9 @@ class ConnectionStateCatchup extends ConnectionStateHandlerPassThrough {
|
|
|
247
262
|
value: ConnectionState,
|
|
248
263
|
oldState: ConnectionState,
|
|
249
264
|
reason?: IConnectionStateChangeReason<IAnyDriverError>,
|
|
250
|
-
) {
|
|
265
|
+
): void {
|
|
251
266
|
switch (value) {
|
|
252
|
-
case ConnectionState.Connected:
|
|
267
|
+
case ConnectionState.Connected: {
|
|
253
268
|
assert(
|
|
254
269
|
this._connectionState === ConnectionState.CatchingUp,
|
|
255
270
|
0x3e1 /* connectivity transitions */,
|
|
@@ -266,31 +281,35 @@ class ConnectionStateCatchup extends ConnectionStateHandlerPassThrough {
|
|
|
266
281
|
this.transitionToConnectedState,
|
|
267
282
|
);
|
|
268
283
|
return;
|
|
269
|
-
|
|
284
|
+
}
|
|
285
|
+
case ConnectionState.Disconnected: {
|
|
270
286
|
this.catchUpMonitor?.dispose();
|
|
271
287
|
this.catchUpMonitor = undefined;
|
|
272
288
|
break;
|
|
289
|
+
}
|
|
273
290
|
// ConnectionState.EstablishingConnection state would be set when we start establishing connection
|
|
274
291
|
// during container.connect() or reconnect because of an error.
|
|
275
|
-
case ConnectionState.EstablishingConnection:
|
|
292
|
+
case ConnectionState.EstablishingConnection: {
|
|
276
293
|
assert(
|
|
277
294
|
this._connectionState === ConnectionState.Disconnected,
|
|
278
295
|
0x6d2 /* connectivity transition to establishing connection */,
|
|
279
296
|
);
|
|
280
297
|
break;
|
|
281
|
-
|
|
298
|
+
}
|
|
299
|
+
case ConnectionState.CatchingUp: {
|
|
282
300
|
assert(
|
|
283
301
|
this._connectionState === ConnectionState.EstablishingConnection,
|
|
284
302
|
0x3e3 /* connectivity transitions */,
|
|
285
303
|
);
|
|
286
304
|
break;
|
|
305
|
+
}
|
|
287
306
|
default:
|
|
288
307
|
}
|
|
289
308
|
this._connectionState = value;
|
|
290
309
|
this.inputs.connectionStateChanged(value, oldState, reason);
|
|
291
310
|
}
|
|
292
311
|
|
|
293
|
-
private readonly transitionToConnectedState = () => {
|
|
312
|
+
private readonly transitionToConnectedState = (): void => {
|
|
294
313
|
// Defensive measure, we should always be in Connecting state when this is called.
|
|
295
314
|
const state = this.pimpl.connectionState;
|
|
296
315
|
assert(state === ConnectionState.Connected, 0x3e5 /* invariant broken */);
|
|
@@ -331,7 +350,7 @@ class ConnectionStateCatchup extends ConnectionStateHandlerPassThrough {
|
|
|
331
350
|
*
|
|
332
351
|
* For (c) this is optional behavior, controlled by the parameters of receivedConnectEvent
|
|
333
352
|
*/
|
|
334
|
-
class ConnectionStateHandler implements IConnectionStateHandler {
|
|
353
|
+
export class ConnectionStateHandler implements IConnectionStateHandler {
|
|
335
354
|
private _connectionState = ConnectionState.Disconnected;
|
|
336
355
|
private _pendingClientId: string | undefined;
|
|
337
356
|
|
|
@@ -352,7 +371,9 @@ class ConnectionStateHandler implements IConnectionStateHandler {
|
|
|
352
371
|
private connection?: IConnectionDetailsInternal;
|
|
353
372
|
private _clientId?: string;
|
|
354
373
|
|
|
355
|
-
/**
|
|
374
|
+
/**
|
|
375
|
+
* Track how long we waited to see "leave" op for previous clientId
|
|
376
|
+
*/
|
|
356
377
|
private waitEvent: PerformanceEvent | undefined;
|
|
357
378
|
|
|
358
379
|
public get connectionState(): ConnectionState {
|
|
@@ -373,7 +394,8 @@ class ConnectionStateHandler implements IConnectionStateHandler {
|
|
|
373
394
|
clientIdFromPausedSession?: string,
|
|
374
395
|
) {
|
|
375
396
|
this._clientId = clientIdFromPausedSession;
|
|
376
|
-
|
|
397
|
+
// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
398
|
+
const errorHandler = (error): void => this.handler.onCriticalError(error);
|
|
377
399
|
this.prevClientLeftTimer = new Timer(
|
|
378
400
|
// Default is 5 min for which we are going to wait for its own "leave" message. This is same as
|
|
379
401
|
// the max time on server after which leave op is sent.
|
|
@@ -412,7 +434,7 @@ class ConnectionStateHandler implements IConnectionStateHandler {
|
|
|
412
434
|
);
|
|
413
435
|
}
|
|
414
436
|
|
|
415
|
-
private startjoinTimer() {
|
|
437
|
+
private startjoinTimer(): void {
|
|
416
438
|
assert(!this.joinTimer.hasTimer, 0x234 /* "has joinTimer" */);
|
|
417
439
|
assert(this.connection !== undefined, 0x4b3 /* have connection */);
|
|
418
440
|
this.joinTimer.start(
|
|
@@ -420,21 +442,21 @@ class ConnectionStateHandler implements IConnectionStateHandler {
|
|
|
420
442
|
);
|
|
421
443
|
}
|
|
422
444
|
|
|
423
|
-
private stopjoinTimer() {
|
|
445
|
+
private stopjoinTimer(): void {
|
|
424
446
|
assert(this.joinTimer.hasTimer, 0x235 /* "no joinTimer" */);
|
|
425
447
|
this.joinTimer.clear();
|
|
426
448
|
}
|
|
427
449
|
|
|
428
|
-
private get waitingForLeaveOp() {
|
|
450
|
+
private get waitingForLeaveOp(): boolean {
|
|
429
451
|
return this.prevClientLeftTimer.hasTimer;
|
|
430
452
|
}
|
|
431
453
|
|
|
432
|
-
public dispose() {
|
|
454
|
+
public dispose(): void {
|
|
433
455
|
assert(!this.joinTimer.hasTimer, 0x2a5 /* "join timer" */);
|
|
434
456
|
this.prevClientLeftTimer.clear();
|
|
435
457
|
}
|
|
436
458
|
|
|
437
|
-
public containerSaved() {
|
|
459
|
+
public containerSaved(): void {
|
|
438
460
|
// If we were waiting for moving to Connected state, then only apply for state change. Since the container
|
|
439
461
|
// is now saved and we don't have any ops to roundtrip, we can clear the timer and apply for connected state.
|
|
440
462
|
if (this.waitingForLeaveOp) {
|
|
@@ -443,7 +465,7 @@ class ConnectionStateHandler implements IConnectionStateHandler {
|
|
|
443
465
|
}
|
|
444
466
|
}
|
|
445
467
|
|
|
446
|
-
private receivedAddMemberEvent(clientId: string) {
|
|
468
|
+
private receivedAddMemberEvent(clientId: string): void {
|
|
447
469
|
// This is the only one that requires the pending client ID
|
|
448
470
|
if (clientId === this.pendingClientId) {
|
|
449
471
|
if (this.joinTimer.hasTimer) {
|
|
@@ -475,7 +497,7 @@ class ConnectionStateHandler implements IConnectionStateHandler {
|
|
|
475
497
|
|
|
476
498
|
private applyForConnectedState(
|
|
477
499
|
source: "removeMemberEvent" | "addMemberEvent" | "timeout" | "containerSaved",
|
|
478
|
-
) {
|
|
500
|
+
): void {
|
|
479
501
|
assert(
|
|
480
502
|
this.protocol !== undefined,
|
|
481
503
|
0x236 /* "In all cases it should be already installed" */,
|
|
@@ -515,7 +537,7 @@ class ConnectionStateHandler implements IConnectionStateHandler {
|
|
|
515
537
|
}
|
|
516
538
|
}
|
|
517
539
|
|
|
518
|
-
private receivedRemoveMemberEvent(clientId: string) {
|
|
540
|
+
private receivedRemoveMemberEvent(clientId: string): void {
|
|
519
541
|
// If the client which has left was us, then finish the timer.
|
|
520
542
|
if (this.clientId === clientId && this.waitingForLeaveOp) {
|
|
521
543
|
this.prevClientLeftTimer.clear();
|
|
@@ -523,12 +545,12 @@ class ConnectionStateHandler implements IConnectionStateHandler {
|
|
|
523
545
|
}
|
|
524
546
|
}
|
|
525
547
|
|
|
526
|
-
public receivedDisconnectEvent(reason: IConnectionStateChangeReason<IAnyDriverError>) {
|
|
548
|
+
public receivedDisconnectEvent(reason: IConnectionStateChangeReason<IAnyDriverError>): void {
|
|
527
549
|
this.connection = undefined;
|
|
528
550
|
this.setConnectionState(ConnectionState.Disconnected, reason);
|
|
529
551
|
}
|
|
530
552
|
|
|
531
|
-
public cancelEstablishingConnection(reason: IConnectionStateChangeReason) {
|
|
553
|
+
public cancelEstablishingConnection(reason: IConnectionStateChangeReason): void {
|
|
532
554
|
assert(
|
|
533
555
|
this._connectionState === ConnectionState.EstablishingConnection,
|
|
534
556
|
0x6d3 /* Connection state should be EstablishingConnection */,
|
|
@@ -539,7 +561,7 @@ class ConnectionStateHandler implements IConnectionStateHandler {
|
|
|
539
561
|
this.handler.connectionStateChanged(ConnectionState.Disconnected, oldState, reason);
|
|
540
562
|
}
|
|
541
563
|
|
|
542
|
-
public establishingConnection(reason: IConnectionStateChangeReason) {
|
|
564
|
+
public establishingConnection(reason: IConnectionStateChangeReason): void {
|
|
543
565
|
const oldState = this._connectionState;
|
|
544
566
|
this._connectionState = ConnectionState.EstablishingConnection;
|
|
545
567
|
this.handler.connectionStateChanged(ConnectionState.EstablishingConnection, oldState, {
|
|
@@ -553,7 +575,7 @@ class ConnectionStateHandler implements IConnectionStateHandler {
|
|
|
553
575
|
* @returns - true if we should wait for "self" to appear in audience.
|
|
554
576
|
* false is returned only for "read" connections, and only if this.readClientsWaitForJoinSignal is false.
|
|
555
577
|
*/
|
|
556
|
-
private shouldWaitForSelf() {
|
|
578
|
+
private shouldWaitForSelf(): boolean {
|
|
557
579
|
assert(
|
|
558
580
|
this.connection !== undefined,
|
|
559
581
|
0x4b4 /* all callers call here with active connection */,
|
|
@@ -569,7 +591,7 @@ class ConnectionStateHandler implements IConnectionStateHandler {
|
|
|
569
591
|
* @param deltaManager - DeltaManager to be used for delaying Connected transition until caught up.
|
|
570
592
|
* If it's undefined, then don't delay and transition to Connected as soon as Leave/Join op are accounted for
|
|
571
593
|
*/
|
|
572
|
-
public receivedConnectEvent(details: IConnectionDetailsInternal) {
|
|
594
|
+
public receivedConnectEvent(details: IConnectionDetailsInternal): void {
|
|
573
595
|
this.connection = details;
|
|
574
596
|
|
|
575
597
|
const oldState = this._connectionState;
|
|
@@ -695,7 +717,7 @@ class ConnectionStateHandler implements IConnectionStateHandler {
|
|
|
695
717
|
return this.readClientsWaitForJoinSignal ? this.protocol?.audience : this.protocol?.quorum;
|
|
696
718
|
}
|
|
697
719
|
|
|
698
|
-
public initProtocol(protocol: IProtocolHandler) {
|
|
720
|
+
public initProtocol(protocol: IProtocolHandler): void {
|
|
699
721
|
this.protocol = protocol;
|
|
700
722
|
|
|
701
723
|
this.membership?.on("addMember", (clientId, details) => {
|
|
@@ -752,7 +774,7 @@ class ConnectionStateHandler implements IConnectionStateHandler {
|
|
|
752
774
|
}
|
|
753
775
|
}
|
|
754
776
|
|
|
755
|
-
protected hasMember(clientId?: string) {
|
|
777
|
+
protected hasMember(clientId?: string): boolean {
|
|
756
778
|
return this.membership?.getMember(clientId ?? "") !== undefined;
|
|
757
779
|
}
|
|
758
780
|
}
|