@fluidframework/container-loader 2.0.0-internal.1.1.2 → 2.0.0-internal.1.2.0

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.
Files changed (92) hide show
  1. package/dist/catchUpMonitor.d.ts +6 -17
  2. package/dist/catchUpMonitor.d.ts.map +1 -1
  3. package/dist/catchUpMonitor.js +5 -36
  4. package/dist/catchUpMonitor.js.map +1 -1
  5. package/dist/collabWindowTracker.d.ts +1 -1
  6. package/dist/collabWindowTracker.d.ts.map +1 -1
  7. package/dist/collabWindowTracker.js +2 -1
  8. package/dist/collabWindowTracker.js.map +1 -1
  9. package/dist/connectionManager.d.ts +1 -1
  10. package/dist/connectionManager.d.ts.map +1 -1
  11. package/dist/connectionManager.js +8 -11
  12. package/dist/connectionManager.js.map +1 -1
  13. package/dist/connectionStateHandler.d.ts +80 -26
  14. package/dist/connectionStateHandler.d.ts.map +1 -1
  15. package/dist/connectionStateHandler.js +170 -89
  16. package/dist/connectionStateHandler.js.map +1 -1
  17. package/dist/container.d.ts +22 -11
  18. package/dist/container.d.ts.map +1 -1
  19. package/dist/container.js +130 -142
  20. package/dist/container.js.map +1 -1
  21. package/dist/containerContext.d.ts +18 -7
  22. package/dist/containerContext.d.ts.map +1 -1
  23. package/dist/containerContext.js +18 -8
  24. package/dist/containerContext.js.map +1 -1
  25. package/dist/containerStorageAdapter.d.ts +10 -24
  26. package/dist/containerStorageAdapter.d.ts.map +1 -1
  27. package/dist/containerStorageAdapter.js +50 -16
  28. package/dist/containerStorageAdapter.js.map +1 -1
  29. package/dist/deltaManager.d.ts +1 -1
  30. package/dist/deltaManager.d.ts.map +1 -1
  31. package/dist/deltaManager.js +18 -6
  32. package/dist/deltaManager.js.map +1 -1
  33. package/dist/loader.d.ts +1 -1
  34. package/dist/loader.js.map +1 -1
  35. package/dist/packageVersion.d.ts +1 -1
  36. package/dist/packageVersion.js +1 -1
  37. package/dist/packageVersion.js.map +1 -1
  38. package/dist/protocol.d.ts.map +1 -1
  39. package/dist/protocol.js +2 -1
  40. package/dist/protocol.js.map +1 -1
  41. package/lib/catchUpMonitor.d.ts +6 -17
  42. package/lib/catchUpMonitor.d.ts.map +1 -1
  43. package/lib/catchUpMonitor.js +5 -35
  44. package/lib/catchUpMonitor.js.map +1 -1
  45. package/lib/collabWindowTracker.d.ts +1 -1
  46. package/lib/collabWindowTracker.d.ts.map +1 -1
  47. package/lib/collabWindowTracker.js +3 -2
  48. package/lib/collabWindowTracker.js.map +1 -1
  49. package/lib/connectionManager.d.ts +1 -1
  50. package/lib/connectionManager.d.ts.map +1 -1
  51. package/lib/connectionManager.js +9 -14
  52. package/lib/connectionManager.js.map +1 -1
  53. package/lib/connectionStateHandler.d.ts +80 -26
  54. package/lib/connectionStateHandler.d.ts.map +1 -1
  55. package/lib/connectionStateHandler.js +170 -90
  56. package/lib/connectionStateHandler.js.map +1 -1
  57. package/lib/container.d.ts +22 -11
  58. package/lib/container.d.ts.map +1 -1
  59. package/lib/container.js +133 -145
  60. package/lib/container.js.map +1 -1
  61. package/lib/containerContext.d.ts +18 -7
  62. package/lib/containerContext.d.ts.map +1 -1
  63. package/lib/containerContext.js +19 -9
  64. package/lib/containerContext.js.map +1 -1
  65. package/lib/containerStorageAdapter.d.ts +10 -24
  66. package/lib/containerStorageAdapter.d.ts.map +1 -1
  67. package/lib/containerStorageAdapter.js +50 -15
  68. package/lib/containerStorageAdapter.js.map +1 -1
  69. package/lib/deltaManager.d.ts +1 -1
  70. package/lib/deltaManager.d.ts.map +1 -1
  71. package/lib/deltaManager.js +18 -6
  72. package/lib/deltaManager.js.map +1 -1
  73. package/lib/loader.d.ts +1 -1
  74. package/lib/loader.js.map +1 -1
  75. package/lib/packageVersion.d.ts +1 -1
  76. package/lib/packageVersion.js +1 -1
  77. package/lib/packageVersion.js.map +1 -1
  78. package/lib/protocol.d.ts.map +1 -1
  79. package/lib/protocol.js +2 -1
  80. package/lib/protocol.js.map +1 -1
  81. package/package.json +13 -13
  82. package/src/catchUpMonitor.ts +7 -47
  83. package/src/collabWindowTracker.ts +4 -3
  84. package/src/connectionManager.ts +9 -11
  85. package/src/connectionStateHandler.ts +231 -106
  86. package/src/container.ts +156 -168
  87. package/src/containerContext.ts +22 -8
  88. package/src/containerStorageAdapter.ts +64 -15
  89. package/src/deltaManager.ts +20 -7
  90. package/src/loader.ts +1 -1
  91. package/src/packageVersion.ts +1 -1
  92. package/src/protocol.ts +2 -1
@@ -4,23 +4,74 @@
4
4
  */
5
5
  import { ITelemetryLogger, ITelemetryProperties } from "@fluidframework/common-definitions";
6
6
  import { IConnectionDetails, IDeltaManager } from "@fluidframework/container-definitions";
7
- import { IProtocolHandler } from "@fluidframework/protocol-base";
8
- import { ConnectionMode, IQuorumClients } from "@fluidframework/protocol-definitions";
7
+ import { ConnectionMode } from "@fluidframework/protocol-definitions";
9
8
  import { ConnectionState } from "./connectionState";
9
+ import { IProtocolHandler } from "./protocol";
10
10
  /** Constructor parameter type for passing in dependencies needed by the ConnectionStateHandler */
11
11
  export interface IConnectionStateHandlerInputs {
12
- /** Provides access to the clients currently in the quorum */
13
- quorumClients: () => IQuorumClients | undefined;
12
+ logger: ITelemetryLogger;
14
13
  /** Log to telemetry any change in state, included to Connecting */
15
- logConnectionStateChangeTelemetry: (value: ConnectionState, oldState: ConnectionState, reason?: string | undefined) => void;
14
+ connectionStateChanged: (value: ConnectionState, oldState: ConnectionState, reason?: string | undefined) => void;
16
15
  /** Whether to expect the client to join in write mode on next connection */
17
16
  shouldClientJoinWrite: () => boolean;
18
17
  /** (Optional) How long should we wait on our previous client's Leave op before transitioning to Connected again */
19
18
  maxClientLeaveWaitTime: number | undefined;
20
19
  /** Log an issue encountered while in the Connecting state. details will be logged as a JSON string */
21
20
  logConnectionIssue: (eventName: string, details?: ITelemetryProperties) => void;
22
- /** Callback whenever the ConnectionState changes between Disconnected and Connected */
23
- connectionStateChanged: () => void;
21
+ }
22
+ /**
23
+ * interface that connection state handler implements
24
+ */
25
+ export interface IConnectionStateHandler {
26
+ readonly connectionState: ConnectionState;
27
+ readonly pendingClientId: string | undefined;
28
+ containerSaved(): void;
29
+ dispose(): void;
30
+ initProtocol(protocol: IProtocolHandler): void;
31
+ receivedConnectEvent(connectionMode: ConnectionMode, details: IConnectionDetails): void;
32
+ receivedDisconnectEvent(reason: string): void;
33
+ }
34
+ export declare function createConnectionStateHandler(inputs: IConnectionStateHandlerInputs, deltaManager: IDeltaManager<any, any>, clientId?: string): ConnectionStateHandler | ConnectionStateCatchup;
35
+ export declare function createConnectionStateHandlerCore(wait: boolean, inputs: IConnectionStateHandlerInputs, deltaManager: IDeltaManager<any, any>, clientId?: string): ConnectionStateHandler | ConnectionStateCatchup;
36
+ /**
37
+ * Class that can be used as a base class for building IConnectionStateHandler adapters / pipeline.
38
+ * It implements both ends of communication interfaces and passes data back and forward
39
+ */
40
+ declare class ConnectionStateHandlerPassThrough implements IConnectionStateHandler, IConnectionStateHandlerInputs {
41
+ protected readonly inputs: IConnectionStateHandlerInputs;
42
+ protected readonly pimpl: IConnectionStateHandler;
43
+ constructor(inputs: IConnectionStateHandlerInputs, pimplFactory: (handler: IConnectionStateHandlerInputs) => IConnectionStateHandler);
44
+ /**
45
+ * IConnectionStateHandler
46
+ */
47
+ get connectionState(): ConnectionState;
48
+ get pendingClientId(): string | undefined;
49
+ containerSaved(): void;
50
+ dispose(): void;
51
+ initProtocol(protocol: IProtocolHandler): void;
52
+ receivedDisconnectEvent(reason: string): void;
53
+ receivedConnectEvent(connectionMode: ConnectionMode, details: IConnectionDetails): void;
54
+ /**
55
+ * IConnectionStateHandlerInputs
56
+ */
57
+ get logger(): ITelemetryLogger;
58
+ connectionStateChanged(value: ConnectionState, oldState: ConnectionState, reason?: string | undefined): void;
59
+ shouldClientJoinWrite(): boolean;
60
+ get maxClientLeaveWaitTime(): number | undefined;
61
+ logConnectionIssue(eventName: string, details?: ITelemetryProperties): void;
62
+ }
63
+ /**
64
+ * Implementation of IConnectionStateHandler pass-through adapter that waits for specific sequence number
65
+ * before raising connected event
66
+ */
67
+ declare class ConnectionStateCatchup extends ConnectionStateHandlerPassThrough {
68
+ private readonly deltaManager;
69
+ private catchUpMonitor;
70
+ constructor(inputs: IConnectionStateHandlerInputs, pimplFactory: (handler: IConnectionStateHandlerInputs) => IConnectionStateHandler, deltaManager: IDeltaManager<any, any>);
71
+ private _connectionState;
72
+ get connectionState(): ConnectionState;
73
+ connectionStateChanged(value: ConnectionState, oldState: ConnectionState, reason?: string | undefined): void;
74
+ private readonly transitionToConnectedState;
24
75
  }
25
76
  /**
26
77
  * In the lifetime of a container, the connection will likely disconnect and reconnect periodically.
@@ -34,33 +85,36 @@ export interface IConnectionStateHandlerInputs {
34
85
  *
35
86
  * The job of this class is to encapsulate the transition period during reconnect, which is identified by
36
87
  * ConnectionState.CatchingUp. Specifically, before moving to Connected state with the new clientId, it ensures that:
37
- * (A) We process the Leave op for the previous clientId. This allows us to properly handle any acks from in-flight ops
38
- * that got sequenced with the old clientId (we'll recognize them as local ops). After the Leave op, any other
39
- * pending ops can safely be submitted with the new clientId without fear of duplication in the sequenced op stream.
40
- * (B) We process the Join op for the new clientId (identified when the underlying connection was first established),
41
- * indicating the service is ready to sequence ops sent with the new clientId.
42
- * (C) We process all ops known at the time the underlying connection was established (so we are "caught up")
43
88
  *
44
- * For (A) we give up waiting after some time (same timeout as server uses), and go ahead and transition to Connected.
45
- * For (B) we log telemetry if it takes too long, but still only transition to Connected when the Join op is processed
89
+ * a. We process the Leave op for the previous clientId. This allows us to properly handle any acks from in-flight ops
90
+ * that got sequenced with the old clientId (we'll recognize them as local ops). After the Leave op, any other
91
+ * pending ops can safely be submitted with the new clientId without fear of duplication in the sequenced op stream.
92
+ *
93
+ * b. We process the Join op for the new clientId (identified when the underlying connection was first established),
94
+ * indicating the service is ready to sequence ops sent with the new clientId.
95
+ *
96
+ * c. We process all ops known at the time the underlying connection was established (so we are "caught up")
97
+ *
98
+ * For (a) we give up waiting after some time (same timeout as server uses), and go ahead and transition to Connected.
99
+ *
100
+ * For (b) we log telemetry if it takes too long, but still only transition to Connected when the Join op is processed
46
101
  * and we are added to the Quorum.
47
- * For (C) this is optional behavior, controlled by the parameters of receivedConnectEvent
102
+ *
103
+ * For (c) this is optional behavior, controlled by the parameters of receivedConnectEvent
48
104
  */
49
- export declare class ConnectionStateHandler {
105
+ declare class ConnectionStateHandler implements IConnectionStateHandler {
50
106
  private readonly handler;
51
- private readonly logger;
52
107
  private _clientId?;
53
108
  private _connectionState;
54
109
  private _pendingClientId;
55
- private catchUpMonitor;
56
110
  private readonly prevClientLeftTimer;
57
111
  private readonly joinOpTimer;
112
+ private protocol?;
58
113
  private waitEvent;
59
114
  get connectionState(): ConnectionState;
60
- get connected(): boolean;
61
- get clientId(): string | undefined;
115
+ private get clientId();
62
116
  get pendingClientId(): string | undefined;
63
- constructor(handler: IConnectionStateHandlerInputs, logger: ITelemetryLogger, _clientId?: string | undefined);
117
+ constructor(handler: IConnectionStateHandlerInputs, _clientId?: string | undefined);
64
118
  private startJoinOpTimer;
65
119
  private stopJoinOpTimer;
66
120
  private get waitingForLeaveOp();
@@ -70,7 +124,6 @@ export declare class ConnectionStateHandler {
70
124
  private applyForConnectedState;
71
125
  private receivedRemoveMemberEvent;
72
126
  receivedDisconnectEvent(reason: string): void;
73
- private readonly transitionToConnectedState;
74
127
  /**
75
128
  * The "connect" event indicates the connection to the Relay Service is live.
76
129
  * However, some additional conditions must be met before we can fully transition to
@@ -80,10 +133,11 @@ export declare class ConnectionStateHandler {
80
133
  * @param deltaManager - DeltaManager to be used for delaying Connected transition until caught up.
81
134
  * If it's undefined, then don't delay and transition to Connected as soon as Leave/Join op are accounted for
82
135
  */
83
- receivedConnectEvent(connectionMode: ConnectionMode, details: IConnectionDetails, deltaManager?: IDeltaManager<any, any>): void;
84
- /** Clear all the state used during the Connecting phase (set in receivedConnectEvent) */
85
- private clearPendingConnectionState;
136
+ receivedConnectEvent(connectionMode: ConnectionMode, details: IConnectionDetails): void;
86
137
  private setConnectionState;
138
+ protected get membership(): import("@fluidframework/protocol-definitions").IQuorum | undefined;
87
139
  initProtocol(protocol: IProtocolHandler): void;
140
+ protected hasMember(clientId?: string): boolean;
88
141
  }
142
+ export {};
89
143
  //# sourceMappingURL=connectionStateHandler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connectionStateHandler.d.ts","sourceRoot":"","sources":["../src/connectionStateHandler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE5F,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAC1F,OAAO,EAAyB,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAEtF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,kGAAkG;AAClG,MAAM,WAAW,6BAA6B;IAC1C,6DAA6D;IAC7D,aAAa,EAAE,MAAM,cAAc,GAAG,SAAS,CAAC;IAChD,mEAAmE;IACnE,iCAAiC,EAC7B,CAAC,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;IAC7F,4EAA4E;IAC5E,qBAAqB,EAAE,MAAM,OAAO,CAAC;IACrC,mHAAmH;IACnH,sBAAsB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3C,sGAAsG;IACtG,kBAAkB,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAChF,uFAAuF;IACvF,sBAAsB,EAAE,MAAM,IAAI,CAAC;CACtC;AAID;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,sBAAsB;IA0B3B,OAAO,CAAC,QAAQ,CAAC,OAAO;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,EAAE,MAAM;CAGxC"}
@@ -3,10 +3,102 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { assert, Timer } from "@fluidframework/common-utils";
6
- import { PerformanceEvent } from "@fluidframework/telemetry-utils";
6
+ import { PerformanceEvent, loggerToMonitoringContext } from "@fluidframework/telemetry-utils";
7
7
  import { ConnectionState } from "./connectionState";
8
- import { CatchUpMonitor, ImmediateCatchUpMonitor } from "./catchUpMonitor";
8
+ import { CatchUpMonitor } from "./catchUpMonitor";
9
9
  const JoinOpTimeoutMs = 45000;
10
+ export function createConnectionStateHandler(inputs, deltaManager, clientId) {
11
+ const mc = loggerToMonitoringContext(inputs.logger);
12
+ return createConnectionStateHandlerCore(mc.config.getBoolean("Fluid.Container.CatchUpBeforeDeclaringConnected") === true, inputs, deltaManager, clientId);
13
+ }
14
+ export function createConnectionStateHandlerCore(wait, inputs, deltaManager, clientId) {
15
+ if (!wait) {
16
+ return new ConnectionStateHandler(inputs, clientId);
17
+ }
18
+ return new ConnectionStateCatchup(inputs, (handler) => new ConnectionStateHandler(handler, clientId), deltaManager);
19
+ }
20
+ /**
21
+ * Class that can be used as a base class for building IConnectionStateHandler adapters / pipeline.
22
+ * It implements both ends of communication interfaces and passes data back and forward
23
+ */
24
+ class ConnectionStateHandlerPassThrough {
25
+ constructor(inputs, pimplFactory) {
26
+ this.inputs = inputs;
27
+ this.pimpl = pimplFactory(this);
28
+ }
29
+ /**
30
+ * IConnectionStateHandler
31
+ */
32
+ get connectionState() { return this.pimpl.connectionState; }
33
+ get pendingClientId() { return this.pimpl.pendingClientId; }
34
+ containerSaved() { return this.pimpl.containerSaved(); }
35
+ dispose() { return this.pimpl.dispose(); }
36
+ initProtocol(protocol) { return this.pimpl.initProtocol(protocol); }
37
+ receivedDisconnectEvent(reason) { return this.pimpl.receivedDisconnectEvent(reason); }
38
+ receivedConnectEvent(connectionMode, details) {
39
+ return this.pimpl.receivedConnectEvent(connectionMode, details);
40
+ }
41
+ /**
42
+ * IConnectionStateHandlerInputs
43
+ */
44
+ get logger() { return this.inputs.logger; }
45
+ connectionStateChanged(value, oldState, reason) {
46
+ return this.inputs.connectionStateChanged(value, oldState, reason);
47
+ }
48
+ shouldClientJoinWrite() { return this.inputs.shouldClientJoinWrite(); }
49
+ get maxClientLeaveWaitTime() { return this.inputs.maxClientLeaveWaitTime; }
50
+ logConnectionIssue(eventName, details) {
51
+ return this.inputs.logConnectionIssue(eventName, details);
52
+ }
53
+ }
54
+ /**
55
+ * Implementation of IConnectionStateHandler pass-through adapter that waits for specific sequence number
56
+ * before raising connected event
57
+ */
58
+ class ConnectionStateCatchup extends ConnectionStateHandlerPassThrough {
59
+ constructor(inputs, pimplFactory, deltaManager) {
60
+ super(inputs, pimplFactory);
61
+ this.deltaManager = deltaManager;
62
+ this.transitionToConnectedState = () => {
63
+ // Defensive measure, we should always be in Connecting state when this is called.
64
+ const state = this.pimpl.connectionState;
65
+ assert(state === ConnectionState.Connected, 0x3e5 /* invariant broken */);
66
+ assert(this._connectionState === ConnectionState.CatchingUp, 0x3e6 /* invariant broken */);
67
+ this._connectionState = ConnectionState.Connected;
68
+ this.inputs.connectionStateChanged(ConnectionState.Connected, ConnectionState.CatchingUp, "caught up");
69
+ };
70
+ this._connectionState = this.pimpl.connectionState;
71
+ }
72
+ get connectionState() {
73
+ return this._connectionState;
74
+ }
75
+ connectionStateChanged(value, oldState, reason) {
76
+ var _a;
77
+ switch (value) {
78
+ case ConnectionState.Connected:
79
+ assert(this._connectionState === ConnectionState.CatchingUp, 0x3e1 /* connectivity transitions */);
80
+ // Create catch-up monitor here (not earlier), as we might get more exact info by now about how far
81
+ // client is behind through join signal. This is only true if base layer uses signals (i.e. audience,
82
+ // not quorum, including for "rea" connections) to make decisions about moving to "connected" state.
83
+ // In addition to that, in its current form, doing this in ConnectionState.CatchingUp is dangerous as
84
+ // we might get callback right away, and it will screw up state transition (as code outside of switch
85
+ // statement will overwrite current state).
86
+ assert(this.catchUpMonitor === undefined, 0x3eb /* catchUpMonitor should be gone */);
87
+ this.catchUpMonitor = new CatchUpMonitor(this.deltaManager, this.transitionToConnectedState);
88
+ return;
89
+ case ConnectionState.Disconnected:
90
+ (_a = this.catchUpMonitor) === null || _a === void 0 ? void 0 : _a.dispose();
91
+ this.catchUpMonitor = undefined;
92
+ break;
93
+ case ConnectionState.CatchingUp:
94
+ assert(this._connectionState === ConnectionState.Disconnected, 0x3e3 /* connectivity transitions */);
95
+ break;
96
+ default:
97
+ }
98
+ this._connectionState = value;
99
+ this.inputs.connectionStateChanged(value, oldState, reason);
100
+ }
101
+ }
10
102
  /**
11
103
  * In the lifetime of a container, the connection will likely disconnect and reconnect periodically.
12
104
  * This class ensures that any ops sent by this container instance on previous connection are either
@@ -19,59 +111,49 @@ const JoinOpTimeoutMs = 45000;
19
111
  *
20
112
  * The job of this class is to encapsulate the transition period during reconnect, which is identified by
21
113
  * ConnectionState.CatchingUp. Specifically, before moving to Connected state with the new clientId, it ensures that:
22
- * (A) We process the Leave op for the previous clientId. This allows us to properly handle any acks from in-flight ops
23
- * that got sequenced with the old clientId (we'll recognize them as local ops). After the Leave op, any other
24
- * pending ops can safely be submitted with the new clientId without fear of duplication in the sequenced op stream.
25
- * (B) We process the Join op for the new clientId (identified when the underlying connection was first established),
26
- * indicating the service is ready to sequence ops sent with the new clientId.
27
- * (C) We process all ops known at the time the underlying connection was established (so we are "caught up")
28
114
  *
29
- * For (A) we give up waiting after some time (same timeout as server uses), and go ahead and transition to Connected.
30
- * For (B) we log telemetry if it takes too long, but still only transition to Connected when the Join op is processed
115
+ * a. We process the Leave op for the previous clientId. This allows us to properly handle any acks from in-flight ops
116
+ * that got sequenced with the old clientId (we'll recognize them as local ops). After the Leave op, any other
117
+ * pending ops can safely be submitted with the new clientId without fear of duplication in the sequenced op stream.
118
+ *
119
+ * b. We process the Join op for the new clientId (identified when the underlying connection was first established),
120
+ * indicating the service is ready to sequence ops sent with the new clientId.
121
+ *
122
+ * c. We process all ops known at the time the underlying connection was established (so we are "caught up")
123
+ *
124
+ * For (a) we give up waiting after some time (same timeout as server uses), and go ahead and transition to Connected.
125
+ *
126
+ * For (b) we log telemetry if it takes too long, but still only transition to Connected when the Join op is processed
31
127
  * and we are added to the Quorum.
32
- * For (C) this is optional behavior, controlled by the parameters of receivedConnectEvent
128
+ *
129
+ * For (c) this is optional behavior, controlled by the parameters of receivedConnectEvent
33
130
  */
34
- export class ConnectionStateHandler {
35
- constructor(handler, logger, _clientId) {
131
+ class ConnectionStateHandler {
132
+ constructor(handler, _clientId) {
36
133
  var _a;
37
134
  this.handler = handler;
38
- this.logger = logger;
39
135
  this._clientId = _clientId;
40
136
  this._connectionState = ConnectionState.Disconnected;
41
- this.transitionToConnectedState = () => {
42
- // Defensive measure, we should always be in CatchingUp state when this is called.
43
- if (this._connectionState === ConnectionState.CatchingUp) {
44
- this.setConnectionState(ConnectionState.Connected);
45
- }
46
- else {
47
- this.logger.sendTelemetryEvent({
48
- eventName: "cannotTransitionToConnectedState",
49
- connectionState: ConnectionState[this._connectionState],
50
- });
51
- }
52
- };
53
137
  this.prevClientLeftTimer = new Timer(
54
138
  // Default is 5 min for which we are going to wait for its own "leave" message. This is same as
55
139
  // the max time on server after which leave op is sent.
56
140
  (_a = this.handler.maxClientLeaveWaitTime) !== null && _a !== void 0 ? _a : 300000, () => {
57
- assert(!this.connected, 0x2ac /* "Connected when timeout waiting for leave from previous session fired!" */);
141
+ assert(this.connectionState !== ConnectionState.Connected, 0x2ac /* "Connected when timeout waiting for leave from previous session fired!" */);
58
142
  this.applyForConnectedState("timeout");
59
143
  });
60
144
  // Based on recent data, it looks like majority of cases where we get stuck are due to really slow or
61
145
  // timing out ops fetches. So attempt recovery infrequently. Also fetch uses 30 second timeout, so
62
146
  // if retrying fixes the problem, we should not see these events.
63
147
  this.joinOpTimer = new Timer(JoinOpTimeoutMs, () => {
64
- var _a;
65
148
  // I've observed timer firing within couple ms from disconnect event, looks like
66
149
  // queued timer callback is not cancelled if timer is cancelled while callback sits in the queue.
67
150
  if (this.connectionState !== ConnectionState.CatchingUp) {
68
151
  return;
69
152
  }
70
- const quorumClients = this.handler.quorumClients();
71
153
  const details = {
72
- quorumInitialized: quorumClients !== undefined,
154
+ protocolInitialized: this.protocol !== undefined,
73
155
  pendingClientId: this.pendingClientId,
74
- inQuorum: (quorumClients === null || quorumClients === void 0 ? void 0 : quorumClients.getMember((_a = this.pendingClientId) !== null && _a !== void 0 ? _a : "")) !== undefined,
156
+ clientJoined: this.hasMember(this.pendingClientId),
75
157
  waitingForLeaveOp: this.waitingForLeaveOp,
76
158
  };
77
159
  this.handler.logConnectionIssue("NoJoinOp", details);
@@ -80,9 +162,6 @@ export class ConnectionStateHandler {
80
162
  get connectionState() {
81
163
  return this._connectionState;
82
164
  }
83
- get connected() {
84
- return this.connectionState === ConnectionState.Connected;
85
- }
86
165
  get clientId() {
87
166
  return this._clientId;
88
167
  }
@@ -125,7 +204,7 @@ export class ConnectionStateHandler {
125
204
  }
126
205
  // Start the event in case we are waiting for leave or timeout.
127
206
  if (this.waitingForLeaveOp) {
128
- this.waitEvent = PerformanceEvent.start(this.logger, {
207
+ this.waitEvent = PerformanceEvent.start(this.handler.logger, {
129
208
  eventName: "WaitBeforeClientLeave",
130
209
  details: JSON.stringify({
131
210
  waitOnClientId: this._clientId,
@@ -137,25 +216,21 @@ export class ConnectionStateHandler {
137
216
  }
138
217
  }
139
218
  applyForConnectedState(source) {
140
- var _a, _b;
141
- const quorumClients = this.handler.quorumClients();
142
- assert(quorumClients !== undefined, 0x236 /* "In all cases it should be already installed" */);
143
- assert(this.waitingForLeaveOp === false ||
144
- (this.clientId !== undefined && quorumClients.getMember(this.clientId) !== undefined), 0x2e2 /* "Must only wait for leave message when clientId in quorum" */);
219
+ var _a;
220
+ assert(this.protocol !== undefined, 0x236 /* "In all cases it should be already installed" */);
221
+ assert(!this.waitingForLeaveOp || this.hasMember(this.clientId), 0x2e2 /* "Must only wait for leave message when clientId in quorum" */);
145
222
  // Move to connected state only if we are in Connecting state, we have seen our join op
146
223
  // and there is no timer running which means we are not waiting for previous client to leave
147
224
  // or timeout has occurred while doing so.
148
225
  if (this.pendingClientId !== this.clientId
149
- && this.pendingClientId !== undefined
150
- && quorumClients.getMember(this.pendingClientId) !== undefined
226
+ && this.hasMember(this.pendingClientId)
151
227
  && !this.waitingForLeaveOp) {
152
228
  (_a = this.waitEvent) === null || _a === void 0 ? void 0 : _a.end({ source });
153
- assert(this.catchUpMonitor !== undefined, 0x37d /* catchUpMonitor should always be set if pendingClientId is set */);
154
- this.catchUpMonitor.on("caughtUp", this.transitionToConnectedState);
229
+ this.setConnectionState(ConnectionState.Connected);
155
230
  }
156
231
  else {
157
232
  // Adding this event temporarily so that we can get help debugging if something goes wrong.
158
- this.logger.sendTelemetryEvent({
233
+ this.handler.logger.sendTelemetryEvent({
159
234
  eventName: "connectedStateRejected",
160
235
  category: source === "timeout" ? "error" : "generic",
161
236
  details: JSON.stringify({
@@ -163,7 +238,7 @@ export class ConnectionStateHandler {
163
238
  pendingClientId: this.pendingClientId,
164
239
  clientId: this.clientId,
165
240
  waitingForLeaveOp: this.waitingForLeaveOp,
166
- inQuorum: (quorumClients === null || quorumClients === void 0 ? void 0 : quorumClients.getMember((_b = this.pendingClientId) !== null && _b !== void 0 ? _b : "")) !== undefined,
241
+ clientJoined: this.hasMember(this.pendingClientId),
167
242
  }),
168
243
  });
169
244
  }
@@ -187,18 +262,16 @@ export class ConnectionStateHandler {
187
262
  * @param deltaManager - DeltaManager to be used for delaying Connected transition until caught up.
188
263
  * If it's undefined, then don't delay and transition to Connected as soon as Leave/Join op are accounted for
189
264
  */
190
- receivedConnectEvent(connectionMode, details, deltaManager) {
191
- var _a;
265
+ receivedConnectEvent(connectionMode, details) {
192
266
  const oldState = this._connectionState;
193
267
  this._connectionState = ConnectionState.CatchingUp;
194
268
  const writeConnection = connectionMode === "write";
195
- assert(!this.handler.shouldClientJoinWrite() || writeConnection, 0x30a /* shouldClientJoinWrite should imply this is a writeConnection */);
196
- assert(!this.waitingForLeaveOp || writeConnection, 0x2a6 /* "waitingForLeaveOp should imply writeConnection (we need to be ready to flush pending ops)" */);
197
- // Defensive measure in case catchUpMonitor from previous connection attempt wasn't already cleared
198
- (_a = this.catchUpMonitor) === null || _a === void 0 ? void 0 : _a.dispose();
199
- // Note that this may be undefined since the connection is established proactively on load
200
- // and the quorum may still be under initialization.
201
- const quorumClients = this.handler.quorumClients();
269
+ // The following checks are wrong. They are only valid if user has write access to a file.
270
+ // If user lost such access mid-session, user will not be able to get "write" connection.
271
+ // assert(!this.handler.shouldClientJoinWrite() || writeConnection,
272
+ // 0x30a /* shouldClientJoinWrite should imply this is a writeConnection */);
273
+ // assert(!this.waitingForLeaveOp || writeConnection,
274
+ // 0x2a6 /* "waitingForLeaveOp should imply writeConnection (we need to be ready to flush pending ops)" */);
202
275
  // Stash the clientID to detect when transitioning from connecting (socket.io channel open) to connected
203
276
  // (have received the join message for the client ID)
204
277
  // This is especially important in the reconnect case. It's possible there could be outstanding
@@ -206,18 +279,14 @@ export class ConnectionStateHandler {
206
279
  // join message. after we see the join message for our new connection with our new client id,
207
280
  // we know there can no longer be outstanding ops that we sent with the previous client id.
208
281
  this._pendingClientId = details.clientId;
209
- // We may want to catch up to known ops as of now before transitioning to Connected state
210
- this.catchUpMonitor = deltaManager !== undefined
211
- ? new CatchUpMonitor(deltaManager)
212
- : new ImmediateCatchUpMonitor();
213
282
  // IMPORTANT: Report telemetry after we set _pendingClientId, but before transitioning to Connected state
214
- this.handler.logConnectionStateChangeTelemetry(ConnectionState.CatchingUp, oldState);
283
+ this.handler.connectionStateChanged(ConnectionState.CatchingUp, oldState);
215
284
  // For write connections, this pending clientId could be in the quorum already (i.e. join op already processed).
216
285
  // We are fetching ops from storage in parallel to connecting to Relay Service,
217
286
  // and given async processes, it's possible that we have already processed our own join message before
218
287
  // connection was fully established.
219
- // If quorumClients itself is undefined, we expect it will process the join op after it's initialized.
220
- const waitingForJoinOp = writeConnection && (quorumClients === null || quorumClients === void 0 ? void 0 : quorumClients.getMember(this._pendingClientId)) === undefined;
288
+ // If protocol is not initialized yet, we expect it will process the join op after it's initialized.
289
+ const waitingForJoinOp = writeConnection && !this.hasMember(this._pendingClientId);
221
290
  if (waitingForJoinOp) {
222
291
  // Previous client left, and we are waiting for our own join op. When it is processed we'll join the quorum
223
292
  // and attempt to transition to Connected state via receivedAddMemberEvent.
@@ -225,33 +294,24 @@ export class ConnectionStateHandler {
225
294
  }
226
295
  else if (!this.waitingForLeaveOp) {
227
296
  // We're not waiting for Join or Leave op (if read-only connection those don't even apply),
228
- // but we do need to wait until we are caught up (to now-known ops) before transitioning to Connected state.
229
- this.catchUpMonitor.on("caughtUp", this.transitionToConnectedState);
297
+ // go ahead and declare the state to be Connected!
298
+ // If we are waiting for Leave op still, do nothing for now, we will transition to Connected later.
299
+ this.setConnectionState(ConnectionState.Connected);
230
300
  }
231
301
  // else - We are waiting for Leave op still, do nothing for now, we will transition to Connected later
232
302
  }
233
- /** Clear all the state used during the Connecting phase (set in receivedConnectEvent) */
234
- clearPendingConnectionState() {
235
- var _a;
236
- this._pendingClientId = undefined;
237
- (_a = this.catchUpMonitor) === null || _a === void 0 ? void 0 : _a.dispose();
238
- this.catchUpMonitor = undefined;
239
- if (this.joinOpTimer.hasTimer) {
240
- this.stopJoinOpTimer();
241
- }
242
- }
243
303
  setConnectionState(value, reason) {
304
+ var _a, _b;
244
305
  if (this.connectionState === value) {
245
306
  // Already in the desired state - exit early
246
- this.logger.sendErrorEvent({ eventName: "setConnectionStateSame", value });
307
+ this.handler.logger.sendErrorEvent({ eventName: "setConnectionStateSame", value });
247
308
  return;
248
309
  }
249
310
  const oldState = this._connectionState;
250
311
  this._connectionState = value;
251
- const quorumClients = this.handler.quorumClients();
252
312
  let client;
253
313
  if (this._clientId !== undefined) {
254
- client = quorumClients === null || quorumClients === void 0 ? void 0 : quorumClients.getMember(this._clientId);
314
+ client = (_b = (_a = this.protocol) === null || _a === void 0 ? void 0 : _a.quorum) === null || _b === void 0 ? void 0 : _b.getMember(this._clientId);
255
315
  }
256
316
  if (value === ConnectionState.Connected) {
257
317
  assert(oldState === ConnectionState.CatchingUp, 0x1d8 /* "Should only transition from Connecting state" */);
@@ -263,23 +323,26 @@ export class ConnectionStateHandler {
263
323
  }
264
324
  else if (value === ConnectionState.Disconnected) {
265
325
  // Clear pending state immediately to prepare for reconnect
266
- this.clearPendingConnectionState();
267
- // Only wait for "leave" message if the connected client exists in the quorum because only the write
268
- // client will exist in the quorum and only for those clients we will receive "removeMember" event and
269
- // the client has some unacked ops.
270
- // Also server would not accept ops from read client. Also check if the timer is not already running as
326
+ this._pendingClientId = undefined;
327
+ if (this.joinOpTimer.hasTimer) {
328
+ this.stopJoinOpTimer();
329
+ }
330
+ // Only wait for "leave" message if the connected client exists in the quorum and had some non-acked ops
331
+ // Also check if the timer is not already running as
271
332
  // we could receive "Disconnected" event multiple times without getting connected and in that case we
272
333
  // don't want to reset the timer as we still want to wait on original client which started this timer.
273
334
  if (client !== undefined
274
335
  && this.handler.shouldClientJoinWrite()
275
- && this.prevClientLeftTimer.hasTimer === false) {
336
+ && !this.waitingForLeaveOp // same as !this.prevClientLeftTimer.hasTimer
337
+ ) {
276
338
  this.prevClientLeftTimer.restart();
277
339
  }
278
340
  else {
279
341
  // Adding this event temporarily so that we can get help debugging if something goes wrong.
280
- this.logger.sendTelemetryEvent({
342
+ this.handler.logger.sendTelemetryEvent({
281
343
  eventName: "noWaitOnDisconnected",
282
344
  details: JSON.stringify({
345
+ clientId: this._clientId,
283
346
  inQuorum: client !== undefined,
284
347
  waitingForLeaveOp: this.waitingForLeaveOp,
285
348
  hadOutstandingOps: this.handler.shouldClientJoinWrite(),
@@ -288,21 +351,38 @@ export class ConnectionStateHandler {
288
351
  }
289
352
  }
290
353
  // Report transition before we propagate event across layers
291
- this.handler.logConnectionStateChangeTelemetry(this._connectionState, oldState, reason);
292
- // Propagate event across layers
293
- this.handler.connectionStateChanged();
354
+ this.handler.connectionStateChanged(this._connectionState, oldState, reason);
355
+ }
356
+ // Helper method to switch between quorum and audience.
357
+ // Old design was checking only quorum for "write" clients.
358
+ // Latest change checks audience for all types of connections.
359
+ get membership() {
360
+ var _a;
361
+ return (_a = this.protocol) === null || _a === void 0 ? void 0 : _a.quorum;
294
362
  }
295
363
  initProtocol(protocol) {
296
- protocol.quorum.on("addMember", (clientId, _details) => {
364
+ var _a, _b;
365
+ this.protocol = protocol;
366
+ (_a = this.membership) === null || _a === void 0 ? void 0 : _a.on("addMember", (clientId) => {
297
367
  this.receivedAddMemberEvent(clientId);
298
368
  });
299
- protocol.quorum.on("removeMember", (clientId) => {
369
+ (_b = this.membership) === null || _b === void 0 ? void 0 : _b.on("removeMember", (clientId) => {
300
370
  this.receivedRemoveMemberEvent(clientId);
301
371
  });
372
+ // Very unlikely race condition, but theoretically can happen - our new connection is already
373
+ // summarized and we are loading from such summary.
374
+ if (this.hasMember(this.pendingClientId)) {
375
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
376
+ this.receivedAddMemberEvent(this.pendingClientId);
377
+ }
302
378
  // if we have a clientId from a previous container we need to wait for its leave message
303
- if (this.clientId !== undefined && protocol.quorum.getMember(this.clientId) !== undefined) {
379
+ if (this.clientId !== undefined && this.hasMember(this.clientId)) {
304
380
  this.prevClientLeftTimer.restart();
305
381
  }
306
382
  }
383
+ hasMember(clientId) {
384
+ var _a;
385
+ return ((_a = this.membership) === null || _a === void 0 ? void 0 : _a.getMember(clientId !== null && clientId !== void 0 ? clientId : "")) !== undefined;
386
+ }
307
387
  }
308
388
  //# sourceMappingURL=connectionStateHandler.js.map