@fluidframework/container-loader 0.59.3002 → 0.59.4000-71130
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/dist/collabWindowTracker.d.ts +1 -2
- package/dist/collabWindowTracker.d.ts.map +1 -1
- package/dist/collabWindowTracker.js +22 -23
- package/dist/collabWindowTracker.js.map +1 -1
- package/dist/connectionManager.d.ts.map +1 -1
- package/dist/connectionManager.js.map +1 -1
- package/dist/connectionState.d.ts +19 -0
- package/dist/connectionState.d.ts.map +1 -0
- package/dist/connectionState.js +23 -0
- package/dist/connectionState.js.map +1 -0
- package/dist/connectionStateHandler.d.ts +1 -1
- package/dist/connectionStateHandler.d.ts.map +1 -1
- package/dist/connectionStateHandler.js +12 -12
- package/dist/connectionStateHandler.js.map +1 -1
- package/dist/container.d.ts +9 -15
- package/dist/container.d.ts.map +1 -1
- package/dist/container.js +58 -39
- package/dist/container.js.map +1 -1
- package/dist/contracts.d.ts +1 -0
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/loader.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/lib/collabWindowTracker.d.ts +1 -2
- package/lib/collabWindowTracker.d.ts.map +1 -1
- package/lib/collabWindowTracker.js +22 -23
- package/lib/collabWindowTracker.js.map +1 -1
- package/lib/connectionManager.d.ts.map +1 -1
- package/lib/connectionManager.js.map +1 -1
- package/lib/connectionState.d.ts +19 -0
- package/lib/connectionState.d.ts.map +1 -0
- package/lib/connectionState.js +20 -0
- package/lib/connectionState.js.map +1 -0
- package/lib/connectionStateHandler.d.ts +1 -1
- package/lib/connectionStateHandler.d.ts.map +1 -1
- package/lib/connectionStateHandler.js +1 -1
- package/lib/connectionStateHandler.js.map +1 -1
- package/lib/container.d.ts +9 -15
- package/lib/container.d.ts.map +1 -1
- package/lib/container.js +40 -21
- package/lib/container.js.map +1 -1
- package/lib/contracts.d.ts +1 -0
- package/lib/contracts.d.ts.map +1 -1
- package/lib/contracts.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/loader.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/package.json +16 -14
- package/src/collabWindowTracker.ts +27 -27
- package/src/connectionManager.ts +1 -1
- package/src/connectionState.ts +21 -0
- package/src/connectionStateHandler.ts +1 -1
- package/src/container.ts +47 -26
- package/src/contracts.ts +2 -0
- package/src/index.ts +1 -1
- package/src/loader.ts +1 -1
- package/src/packageVersion.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectionStateHandler.js","sourceRoot":"","sources":["../src/connectionStateHandler.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,qEAAmE;AACnE,+DAA6D;AAC7D,2CAA8C;AAmB9C,MAAM,WAAW,GAAG,KAAK,CAAC;AAE1B,MAAa,sBAAsB;IAyB/B,YACqB,OAAgC,EAChC,MAAwB;;QADxB,YAAO,GAAP,OAAO,CAAyB;QAChC,WAAM,GAAN,MAAM,CAAkB;QA1BrC,qBAAgB,GAAG,2BAAe,CAAC,YAAY,CAAC;QA4BpD,IAAI,CAAC,mBAAmB,GAAG,IAAI,oBAAK;QAChC,+FAA+F;QAC/F,uDAAuD;QACvD,MAAA,IAAI,CAAC,OAAO,CAAC,sBAAsB,mCAAI,MAAM,EAC7C,GAAG,EAAE;YACD,IAAA,qBAAM,EAAC,CAAC,IAAI,CAAC,SAAS,EAClB,KAAK,CAAC,6EAA6E,CAAC,CAAC;YACzF,I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AQ,EAAE,MAAM,CAAC,CAAC;QAExF,gCAAgC;QAChC,IAAI,CAAC,OAAO,CAAC,sBAAsB,EAAE,CAAC;IAC1C,CAAC;CACJ;AAzOD,wDAyOC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { IConnectionDetails } from \"@fluidframework/container-definitions\";\nimport { ConnectionMode, IQuorumClients, ISequencedClient } from \"@fluidframework/protocol-definitions\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { assert, Timer } from \"@fluidframework/common-utils\";\nimport { ConnectionState } from \"./container\";\n\nexport interface IConnectionStateHandler {\n quorumClients: () => IQuorumClients | undefined;\n logConnectionStateChangeTelemetry: (\n value: ConnectionState,\n oldState: ConnectionState,\n reason?: string | undefined\n ) => void;\n shouldClientJoinWrite: () => boolean;\n maxClientLeaveWaitTime: number | undefined;\n logConnectionIssue: (eventName: string) => void;\n connectionStateChanged: () => void;\n}\n\nexport interface ILocalSequencedClient extends ISequencedClient {\n shouldHaveLeft?: boolean;\n}\n\nconst JoinOpTimer = 45000;\n\nexport class ConnectionStateHandler {\n private _connectionState = ConnectionState.Disconnected;\n private _pendingClientId: string | undefined;\n private _clientId: string | undefined;\n private readonly prevClientLeftTimer: Timer;\n private readonly joinOpTimer: Timer;\n\n private waitEvent: PerformanceEvent | undefined;\n\n public get connectionState(): ConnectionState {\n return this._connectionState;\n }\n\n public get connected(): boolean {\n return this.connectionState === ConnectionState.Connected;\n }\n\n public get clientId(): string | undefined {\n return this._clientId;\n }\n\n public get pendingClientId(): string | undefined {\n return this._pendingClientId;\n }\n\n constructor(\n private readonly handler: IConnectionStateHandler,\n private readonly logger: ITelemetryLogger,\n ) {\n this.prevClientLeftTimer = new Timer(\n // Default is 5 min for which we are going to wait for its own \"leave\" message. This is same as\n // the max time on server after which leave op is sent.\n this.handler.maxClientLeaveWaitTime ?? 300000,\n () => {\n assert(!this.connected,\n 0x2ac /* \"Connected when timeout waiting for leave from previous session fired!\" */);\n this.applyForConnectedState(\"timeout\");\n },\n );\n\n // Based on recent data, it looks like majority of cases where we get stuck are due to really slow or\n // timing out ops fetches. So attempt recovery infrequently. Also fetch uses 30 second timeout, so\n // if retrying fixes the problem, we should not see these events.\n this.joinOpTimer = new Timer(\n JoinOpTimer,\n () => {\n // I've observed timer firing within couple ms from disconnect event, looks like\n // queued timer callback is not cancelled if timer is cancelled while callback sits in the queue.\n if (this.connectionState === ConnectionState.Connecting) {\n this.handler.logConnectionIssue(\"NoJoinOp\");\n }\n },\n );\n }\n\n private startJoinOpTimer() {\n assert(!this.joinOpTimer.hasTimer, 0x234 /* \"has joinOpTimer\" */);\n this.joinOpTimer.start();\n }\n\n private stopJoinOpTimer() {\n assert(this.joinOpTimer.hasTimer, 0x235 /* \"no joinOpTimer\" */);\n this.joinOpTimer.clear();\n }\n\n public dispose() {\n assert(!this.joinOpTimer.hasTimer, 0x2a5 /* \"join timer\" */);\n this.prevClientLeftTimer.clear();\n }\n\n public containerSaved() {\n // If we were waiting for moving to Connected state, then only apply for state change. Since the container\n // is now saved and we don't have any ops to roundtrip, we can clear the timer and apply for connected state.\n if (this.prevClientLeftTimer.hasTimer) {\n this.prevClientLeftTimer.clear();\n this.applyForConnectedState(\"containerSaved\");\n }\n }\n\n public receivedAddMemberEvent(clientId: string) {\n // This is the only one that requires the pending client ID\n if (clientId === this.pendingClientId) {\n if (this.joinOpTimer.hasTimer) {\n this.stopJoinOpTimer();\n } else {\n // timer has already fired, meaning it took too long to get join on.\n // Record how long it actually took to recover.\n this.handler.logConnectionIssue(\"ReceivedJoinOp\");\n }\n // Start the event in case we are waiting for leave or timeout.\n if (this.prevClientLeftTimer.hasTimer) {\n this.waitEvent = PerformanceEvent.start(this.logger, {\n eventName: \"WaitBeforeClientLeave\",\n waitOnClientId: this._clientId,\n hadOutstandingOps: this.handler.shouldClientJoinWrite(),\n });\n }\n this.applyForConnectedState(\"addMemberEvent\");\n }\n }\n\n private applyForConnectedState(source: \"removeMemberEvent\" | \"addMemberEvent\" | \"timeout\" | \"containerSaved\") {\n const quorumClients = this.handler.quorumClients();\n assert(quorumClients !== undefined, 0x236 /* \"In all cases it should be already installed\" */);\n // Move to connected state only if we are in Connecting state, we have seen our join op\n // and there is no timer running which means we are not waiting for previous client to leave\n // or timeout has occured while doing so.\n if (this.pendingClientId !== this.clientId\n && this.pendingClientId !== undefined\n && quorumClients.getMember(this.pendingClientId) !== undefined\n && !this.prevClientLeftTimer.hasTimer\n ) {\n this.waitEvent?.end({ source });\n this.setConnectionState(ConnectionState.Connected);\n } else {\n // Adding this event temporarily so that we can get help debugging if something goes wrong.\n this.logger.sendTelemetryEvent({\n eventName: \"connectedStateRejected\",\n category: source === \"timeout\" ? \"error\" : \"generic\",\n source,\n pendingClientId: this.pendingClientId,\n clientId: this.clientId,\n hasTimer: this.prevClientLeftTimer.hasTimer,\n inQuorum: quorumClients !== undefined && this.pendingClientId !== undefined\n && quorumClients.getMember(this.pendingClientId) !== undefined,\n });\n }\n }\n\n public receivedRemoveMemberEvent(clientId: string) {\n // If the client which has left was us, then finish the timer.\n if (this.clientId === clientId) {\n this.prevClientLeftTimer.clear();\n this.applyForConnectedState(\"removeMemberEvent\");\n }\n }\n\n public receivedDisconnectEvent(reason: string) {\n if (this.joinOpTimer.hasTimer) {\n this.stopJoinOpTimer();\n }\n this.setConnectionState(ConnectionState.Disconnected, reason);\n }\n\n public receivedConnectEvent(\n connectionMode: ConnectionMode,\n details: IConnectionDetails,\n ) {\n const oldState = this._connectionState;\n this._connectionState = ConnectionState.Connecting;\n\n // Stash the clientID to detect when transitioning from connecting (socket.io channel open) to connected\n // (have received the join message for the client ID)\n // This is especially important in the reconnect case. It's possible there could be outstanding\n // ops sent by this client, so we should keep the old client id until we see our own client's\n // join message. after we see the join message for out new connection with our new client id,\n // we know there can no longer be outstanding ops that we sent with the previous client id.\n this._pendingClientId = details.clientId;\n\n // Report telemetry after we set client id, but before transitioning to Connected state below!\n this.handler.logConnectionStateChangeTelemetry(ConnectionState.Connecting, oldState);\n\n const quorumClients = this.handler.quorumClients();\n // Check if we already processed our own join op through delta storage!\n // we are fetching ops from storage in parallel to connecting to ordering service\n // Given async processes, it's possible that we have already processed our own join message before\n // connection was fully established.\n // Note that we might be still initializing quorum - connection is established proactively on load!\n if (quorumClients?.getMember(details.clientId) !== undefined\n || connectionMode === \"read\"\n ) {\n assert(!this.prevClientLeftTimer.hasTimer, 0x2a6 /* \"there should be no timer for 'read' connections\" */);\n this.setConnectionState(ConnectionState.Connected);\n } else if (connectionMode === \"write\") {\n this.startJoinOpTimer();\n }\n }\n\n private setConnectionState(value: ConnectionState.Disconnected, reason: string);\n private setConnectionState(value: ConnectionState.Connected);\n private setConnectionState(value: ConnectionState, reason?: string) {\n if (this.connectionState === value) {\n // Already in the desired state - exit early\n this.logger.sendErrorEvent({ eventName: \"setConnectionStateSame\", value });\n return;\n }\n\n const oldState = this._connectionState;\n this._connectionState = value;\n const quorumClients = this.handler.quorumClients();\n let client: ILocalSequencedClient | undefined;\n if (this._clientId !== undefined) {\n client = quorumClients?.getMember(this._clientId);\n }\n if (value === ConnectionState.Connected) {\n assert(oldState === ConnectionState.Connecting,\n 0x1d8 /* \"Should only transition from Connecting state\" */);\n // Mark our old client should have left in the quorum if it's still there\n if (client !== undefined) {\n client.shouldHaveLeft = true;\n }\n this._clientId = this.pendingClientId;\n } else if (value === ConnectionState.Disconnected) {\n // Important as we process our own joinSession message through delta request\n this._pendingClientId = undefined;\n // Only wait for \"leave\" message if the connected client exists in the quorum because only the write\n // client will exist in the quorum and only for those clients we will receive \"removeMember\" event and\n // the client has some unacked ops.\n // Also server would not accept ops from read client. Also check if the timer is not already running as\n // we could receive \"Disconnected\" event multiple times without getting connected and in that case we\n // don't want to reset the timer as we still want to wait on original client which started this timer.\n if (client !== undefined\n && this.handler.shouldClientJoinWrite()\n && this.prevClientLeftTimer.hasTimer === false\n ) {\n this.prevClientLeftTimer.restart();\n } else {\n // Adding this event temporarily so that we can get help debugging if something goes wrong.\n this.logger.sendTelemetryEvent({\n eventName: \"noWaitOnDisconnected\",\n inQuorum: client !== undefined,\n hasTimer: this.prevClientLeftTimer.hasTimer,\n shouldClientJoinWrite: this.handler.shouldClientJoinWrite(),\n });\n }\n }\n\n // Report transition before we propagate event across layers\n this.handler.logConnectionStateChangeTelemetry(this._connectionState, oldState, reason);\n\n // Propagate event across layers\n this.handler.connectionStateChanged();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"connectionStateHandler.js","sourceRoot":"","sources":["../src/connectionStateHandler.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,qEAAmE;AACnE,+DAA6D;AAC7D,uDAAoD;AAmBpD,MAAM,WAAW,GAAG,KAAK,CAAC;AAE1B,MAAa,sBAAsB;IAyB/B,YACqB,OAAgC,EAChC,MAAwB;;QADxB,YAAO,GAAP,OAAO,CAAyB;QAChC,WAAM,GAAN,MAAM,CAAkB;QA1BrC,qBAAgB,GAAG,iCAAe,CAAC,YAAY,CAAC;QA4BpD,IAAI,CAAC,mBAAmB,GAAG,IAAI,oBAAK;QAChC,+FAA+F;QAC/F,uDAAuD;QACvD,MAAA,IAAI,CAAC,OAAO,CAAC,sBAAsB,mCAAI,MAAM,EAC7C,GAAG,EAAE;YACD,IAAA,qBAAM,EAAC,CAAC,IAAI,CAAC,SAAS,EAClB,KAAK,CAAC,6EAA6E,CAAC,CAAC;YACzF,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;QAC3C,CAAC,CACJ,CAAC;QAEF,qGAAqG;QACrG,kGAAkG;QAClG,iEAAiE;QACjE,IAAI,CAAC,WAAW,GAAG,IAAI,oBAAK,CACxB,WAAW,EACX,GAAG,EAAE;YACD,gFAAgF;YAChF,iGAAiG;YACjG,IAAI,IAAI,CAAC,eAAe,KAAK,iCAAe,CAAC,UAAU,EAAE;gBACrD,IAAI,CAAC,OAAO,C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,CAAC,CAAC;YAChE,yEAAyE;YACzE,IAAI,MAAM,KAAK,SAAS,EAAE;gBACtB,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;aAChC;YACD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,eAAe,CAAC;SACzC;aAAM,IAAI,KAAK,KAAK,iCAAe,CAAC,YAAY,EAAE;YAC/C,4EAA4E;YAC5E,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;YAClC,oGAAoG;YACpG,sGAAsG;YACtG,mCAAmC;YACnC,uGAAuG;YACvG,qGAAqG;YACrG,sGAAsG;YACtG,IAAI,MAAM,KAAK,SAAS;mBACjB,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE;mBACpC,IAAI,CAAC,mBAAmB,CAAC,QAAQ,KAAK,KAAK,EAChD;gBACE,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC;aACtC;iBAAM;gBACH,2FAA2F;gBAC3F,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC;oBAC3B,SAAS,EAAE,sBAAsB;oBACjC,QAAQ,EAAE,MAAM,KAAK,SAAS;oBAC9B,QAAQ,EAAE,IAAI,CAAC,mBAAmB,CAAC,QAAQ;oBAC3C,qBAAqB,EAAE,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE;iBAC9D,CAAC,CAAC;aACN;SACJ;QAED,4DAA4D;QAC5D,IAAI,CAAC,OAAO,CAAC,iCAAiC,CAAC,IAAI,CAAC,gBAAgB,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QAExF,gCAAgC;QAChC,IAAI,CAAC,OAAO,CAAC,sBAAsB,EAAE,CAAC;IAC1C,CAAC;CACJ;AAzOD,wDAyOC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { IConnectionDetails } from \"@fluidframework/container-definitions\";\nimport { ConnectionMode, IQuorumClients, ISequencedClient } from \"@fluidframework/protocol-definitions\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { assert, Timer } from \"@fluidframework/common-utils\";\nimport { ConnectionState } from \"./connectionState\";\n\nexport interface IConnectionStateHandler {\n quorumClients: () => IQuorumClients | undefined;\n logConnectionStateChangeTelemetry: (\n value: ConnectionState,\n oldState: ConnectionState,\n reason?: string | undefined\n ) => void;\n shouldClientJoinWrite: () => boolean;\n maxClientLeaveWaitTime: number | undefined;\n logConnectionIssue: (eventName: string) => void;\n connectionStateChanged: () => void;\n}\n\nexport interface ILocalSequencedClient extends ISequencedClient {\n shouldHaveLeft?: boolean;\n}\n\nconst JoinOpTimer = 45000;\n\nexport class ConnectionStateHandler {\n private _connectionState = ConnectionState.Disconnected;\n private _pendingClientId: string | undefined;\n private _clientId: string | undefined;\n private readonly prevClientLeftTimer: Timer;\n private readonly joinOpTimer: Timer;\n\n private waitEvent: PerformanceEvent | undefined;\n\n public get connectionState(): ConnectionState {\n return this._connectionState;\n }\n\n public get connected(): boolean {\n return this.connectionState === ConnectionState.Connected;\n }\n\n public get clientId(): string | undefined {\n return this._clientId;\n }\n\n public get pendingClientId(): string | undefined {\n return this._pendingClientId;\n }\n\n constructor(\n private readonly handler: IConnectionStateHandler,\n private readonly logger: ITelemetryLogger,\n ) {\n this.prevClientLeftTimer = new Timer(\n // Default is 5 min for which we are going to wait for its own \"leave\" message. This is same as\n // the max time on server after which leave op is sent.\n this.handler.maxClientLeaveWaitTime ?? 300000,\n () => {\n assert(!this.connected,\n 0x2ac /* \"Connected when timeout waiting for leave from previous session fired!\" */);\n this.applyForConnectedState(\"timeout\");\n },\n );\n\n // Based on recent data, it looks like majority of cases where we get stuck are due to really slow or\n // timing out ops fetches. So attempt recovery infrequently. Also fetch uses 30 second timeout, so\n // if retrying fixes the problem, we should not see these events.\n this.joinOpTimer = new Timer(\n JoinOpTimer,\n () => {\n // I've observed timer firing within couple ms from disconnect event, looks like\n // queued timer callback is not cancelled if timer is cancelled while callback sits in the queue.\n if (this.connectionState === ConnectionState.Connecting) {\n this.handler.logConnectionIssue(\"NoJoinOp\");\n }\n },\n );\n }\n\n private startJoinOpTimer() {\n assert(!this.joinOpTimer.hasTimer, 0x234 /* \"has joinOpTimer\" */);\n this.joinOpTimer.start();\n }\n\n private stopJoinOpTimer() {\n assert(this.joinOpTimer.hasTimer, 0x235 /* \"no joinOpTimer\" */);\n this.joinOpTimer.clear();\n }\n\n public dispose() {\n assert(!this.joinOpTimer.hasTimer, 0x2a5 /* \"join timer\" */);\n this.prevClientLeftTimer.clear();\n }\n\n public containerSaved() {\n // If we were waiting for moving to Connected state, then only apply for state change. Since the container\n // is now saved and we don't have any ops to roundtrip, we can clear the timer and apply for connected state.\n if (this.prevClientLeftTimer.hasTimer) {\n this.prevClientLeftTimer.clear();\n this.applyForConnectedState(\"containerSaved\");\n }\n }\n\n public receivedAddMemberEvent(clientId: string) {\n // This is the only one that requires the pending client ID\n if (clientId === this.pendingClientId) {\n if (this.joinOpTimer.hasTimer) {\n this.stopJoinOpTimer();\n } else {\n // timer has already fired, meaning it took too long to get join on.\n // Record how long it actually took to recover.\n this.handler.logConnectionIssue(\"ReceivedJoinOp\");\n }\n // Start the event in case we are waiting for leave or timeout.\n if (this.prevClientLeftTimer.hasTimer) {\n this.waitEvent = PerformanceEvent.start(this.logger, {\n eventName: \"WaitBeforeClientLeave\",\n waitOnClientId: this._clientId,\n hadOutstandingOps: this.handler.shouldClientJoinWrite(),\n });\n }\n this.applyForConnectedState(\"addMemberEvent\");\n }\n }\n\n private applyForConnectedState(source: \"removeMemberEvent\" | \"addMemberEvent\" | \"timeout\" | \"containerSaved\") {\n const quorumClients = this.handler.quorumClients();\n assert(quorumClients !== undefined, 0x236 /* \"In all cases it should be already installed\" */);\n // Move to connected state only if we are in Connecting state, we have seen our join op\n // and there is no timer running which means we are not waiting for previous client to leave\n // or timeout has occured while doing so.\n if (this.pendingClientId !== this.clientId\n && this.pendingClientId !== undefined\n && quorumClients.getMember(this.pendingClientId) !== undefined\n && !this.prevClientLeftTimer.hasTimer\n ) {\n this.waitEvent?.end({ source });\n this.setConnectionState(ConnectionState.Connected);\n } else {\n // Adding this event temporarily so that we can get help debugging if something goes wrong.\n this.logger.sendTelemetryEvent({\n eventName: \"connectedStateRejected\",\n category: source === \"timeout\" ? \"error\" : \"generic\",\n source,\n pendingClientId: this.pendingClientId,\n clientId: this.clientId,\n hasTimer: this.prevClientLeftTimer.hasTimer,\n inQuorum: quorumClients !== undefined && this.pendingClientId !== undefined\n && quorumClients.getMember(this.pendingClientId) !== undefined,\n });\n }\n }\n\n public receivedRemoveMemberEvent(clientId: string) {\n // If the client which has left was us, then finish the timer.\n if (this.clientId === clientId) {\n this.prevClientLeftTimer.clear();\n this.applyForConnectedState(\"removeMemberEvent\");\n }\n }\n\n public receivedDisconnectEvent(reason: string) {\n if (this.joinOpTimer.hasTimer) {\n this.stopJoinOpTimer();\n }\n this.setConnectionState(ConnectionState.Disconnected, reason);\n }\n\n public receivedConnectEvent(\n connectionMode: ConnectionMode,\n details: IConnectionDetails,\n ) {\n const oldState = this._connectionState;\n this._connectionState = ConnectionState.Connecting;\n\n // Stash the clientID to detect when transitioning from connecting (socket.io channel open) to connected\n // (have received the join message for the client ID)\n // This is especially important in the reconnect case. It's possible there could be outstanding\n // ops sent by this client, so we should keep the old client id until we see our own client's\n // join message. after we see the join message for out new connection with our new client id,\n // we know there can no longer be outstanding ops that we sent with the previous client id.\n this._pendingClientId = details.clientId;\n\n // Report telemetry after we set client id, but before transitioning to Connected state below!\n this.handler.logConnectionStateChangeTelemetry(ConnectionState.Connecting, oldState);\n\n const quorumClients = this.handler.quorumClients();\n // Check if we already processed our own join op through delta storage!\n // we are fetching ops from storage in parallel to connecting to ordering service\n // Given async processes, it's possible that we have already processed our own join message before\n // connection was fully established.\n // Note that we might be still initializing quorum - connection is established proactively on load!\n if (quorumClients?.getMember(details.clientId) !== undefined\n || connectionMode === \"read\"\n ) {\n assert(!this.prevClientLeftTimer.hasTimer, 0x2a6 /* \"there should be no timer for 'read' connections\" */);\n this.setConnectionState(ConnectionState.Connected);\n } else if (connectionMode === \"write\") {\n this.startJoinOpTimer();\n }\n }\n\n private setConnectionState(value: ConnectionState.Disconnected, reason: string);\n private setConnectionState(value: ConnectionState.Connected);\n private setConnectionState(value: ConnectionState, reason?: string) {\n if (this.connectionState === value) {\n // Already in the desired state - exit early\n this.logger.sendErrorEvent({ eventName: \"setConnectionStateSame\", value });\n return;\n }\n\n const oldState = this._connectionState;\n this._connectionState = value;\n const quorumClients = this.handler.quorumClients();\n let client: ILocalSequencedClient | undefined;\n if (this._clientId !== undefined) {\n client = quorumClients?.getMember(this._clientId);\n }\n if (value === ConnectionState.Connected) {\n assert(oldState === ConnectionState.Connecting,\n 0x1d8 /* \"Should only transition from Connecting state\" */);\n // Mark our old client should have left in the quorum if it's still there\n if (client !== undefined) {\n client.shouldHaveLeft = true;\n }\n this._clientId = this.pendingClientId;\n } else if (value === ConnectionState.Disconnected) {\n // Important as we process our own joinSession message through delta request\n this._pendingClientId = undefined;\n // Only wait for \"leave\" message if the connected client exists in the quorum because only the write\n // client will exist in the quorum and only for those clients we will receive \"removeMember\" event and\n // the client has some unacked ops.\n // Also server would not accept ops from read client. Also check if the timer is not already running as\n // we could receive \"Disconnected\" event multiple times without getting connected and in that case we\n // don't want to reset the timer as we still want to wait on original client which started this timer.\n if (client !== undefined\n && this.handler.shouldClientJoinWrite()\n && this.prevClientLeftTimer.hasTimer === false\n ) {\n this.prevClientLeftTimer.restart();\n } else {\n // Adding this event temporarily so that we can get help debugging if something goes wrong.\n this.logger.sendTelemetryEvent({\n eventName: \"noWaitOnDisconnected\",\n inQuorum: client !== undefined,\n hasTimer: this.prevClientLeftTimer.hasTimer,\n shouldClientJoinWrite: this.handler.shouldClientJoinWrite(),\n });\n }\n }\n\n // Report transition before we propagate event across layers\n this.handler.logConnectionStateChangeTelemetry(this._connectionState, oldState, reason);\n\n // Propagate event across layers\n this.handler.connectionStateChanged();\n }\n}\n"]}
|
package/dist/container.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { IDocumentStorageService, IFluidResolvedUrl, IResolvedUrl } from "@fluid
|
|
|
8
8
|
import { IClientConfiguration, IClientDetails, IDocumentMessage, IQuorumClients, ISequencedDocumentMessage, IVersion } from "@fluidframework/protocol-definitions";
|
|
9
9
|
import { EventEmitterWithErrorHandling, TelemetryLogger } from "@fluidframework/telemetry-utils";
|
|
10
10
|
import { ILoaderOptions, Loader } from "./loader";
|
|
11
|
+
import { ConnectionState } from "./connectionState";
|
|
11
12
|
export interface IContainerLoadOptions {
|
|
12
13
|
/**
|
|
13
14
|
* Disables the Container from reconnecting if false, allows reconnect otherwise.
|
|
@@ -35,20 +36,6 @@ export interface IContainerConfig {
|
|
|
35
36
|
*/
|
|
36
37
|
clientDetailsOverride?: IClientDetails;
|
|
37
38
|
}
|
|
38
|
-
export declare enum ConnectionState {
|
|
39
|
-
/**
|
|
40
|
-
* The document is no longer connected to the delta server
|
|
41
|
-
*/
|
|
42
|
-
Disconnected = 0,
|
|
43
|
-
/**
|
|
44
|
-
* The document has an inbound connection but is still pending for outbound deltas
|
|
45
|
-
*/
|
|
46
|
-
Connecting = 1,
|
|
47
|
-
/**
|
|
48
|
-
* The document is fully connected
|
|
49
|
-
*/
|
|
50
|
-
Connected = 2
|
|
51
|
-
}
|
|
52
39
|
/**
|
|
53
40
|
* Waits until container connects to delta storage and gets up-to-date
|
|
54
41
|
* Useful when resolving URIs and hitting 404, due to container being loaded from (stale) snapshot and not being
|
|
@@ -109,7 +96,7 @@ export declare class Container extends EventEmitterWithErrorHandling<IContainerE
|
|
|
109
96
|
private readonly visibilityEventHandler;
|
|
110
97
|
private readonly connectionStateHandler;
|
|
111
98
|
private setAutoReconnectTime;
|
|
112
|
-
private
|
|
99
|
+
private collabWindowTracker;
|
|
113
100
|
private get connectionMode();
|
|
114
101
|
get IFluidRouter(): IFluidRouter;
|
|
115
102
|
get resolvedUrl(): IResolvedUrl | undefined;
|
|
@@ -235,6 +222,13 @@ export declare class Container extends EventEmitterWithErrorHandling<IContainerE
|
|
|
235
222
|
private submitContainerMessage;
|
|
236
223
|
private submitMessage;
|
|
237
224
|
private processRemoteMessage;
|
|
225
|
+
/**
|
|
226
|
+
* #260 (ADO)
|
|
227
|
+
* back-compat: noopTimeFrequency & noopCountFrequency properties were added to
|
|
228
|
+
* IClientConfiguration in 0.59.3000. During the integration, we must read the
|
|
229
|
+
* available configuration from the loader options.
|
|
230
|
+
*/
|
|
231
|
+
private getNoopConfig;
|
|
238
232
|
private submitSignal;
|
|
239
233
|
private processSignal;
|
|
240
234
|
/**
|
package/dist/container.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EACH,QAAQ,EACR,SAAS,EACT,YAAY,EACf,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACH,SAAS,EAET,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,uBAAuB,EAEvB,WAAW,EAGX,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EAEpB,MAAM,uCAAuC,CAAC;AAO/C,OAAO,EAEH,uBAAuB,EACvB,iBAAiB,EACjB,YAAY,EACf,MAAM,oCAAoC,CAAC;AAc5C,OAAO,EAEH,oBAAoB,EACpB,cAAc,EAGd,gBAAgB,EAEhB,cAAc,EAGd,yBAAyB,EAOzB,QAAQ,EAGX,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAEH,6BAA6B,EAG7B,eAAe,EAOlB,MAAM,iCAAiC,CAAC;AAMzC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAkB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EACH,QAAQ,EACR,SAAS,EACT,Y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O,CAAC,wBAAwB;IAuBhC,OAAO,CAAC,sBAAsB;IA4B9B,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,oBAAoB;IAyD5B;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,aAAa;IAiBrB;;;;OAIG;YACW,iBAAiB;YAiBjB,0BAA0B;YAkB1B,kBAAkB;IAgChC,OAAO,CAAC,yBAAyB;IAQjC,OAAO,CAAC,iBAAiB;CAG5B"}
|
package/dist/container.js
CHANGED
|
@@ -7,7 +7,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
7
7
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
8
|
};
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.Container = exports.waitContainerToCatchUp =
|
|
10
|
+
exports.Container = exports.waitContainerToCatchUp = void 0;
|
|
11
11
|
// eslint-disable-next-line import/no-internal-modules
|
|
12
12
|
const merge_1 = __importDefault(require("lodash/merge"));
|
|
13
13
|
const uuid_1 = require("uuid");
|
|
@@ -33,24 +33,10 @@ const utils_1 = require("./utils");
|
|
|
33
33
|
const quorum_1 = require("./quorum");
|
|
34
34
|
const collabWindowTracker_1 = require("./collabWindowTracker");
|
|
35
35
|
const connectionManager_1 = require("./connectionManager");
|
|
36
|
+
const connectionState_1 = require("./connectionState");
|
|
36
37
|
const detachedContainerRefSeqNumber = 0;
|
|
37
38
|
const dirtyContainerEvent = "dirty";
|
|
38
39
|
const savedContainerEvent = "saved";
|
|
39
|
-
var ConnectionState;
|
|
40
|
-
(function (ConnectionState) {
|
|
41
|
-
/**
|
|
42
|
-
* The document is no longer connected to the delta server
|
|
43
|
-
*/
|
|
44
|
-
ConnectionState[ConnectionState["Disconnected"] = 0] = "Disconnected";
|
|
45
|
-
/**
|
|
46
|
-
* The document has an inbound connection but is still pending for outbound deltas
|
|
47
|
-
*/
|
|
48
|
-
ConnectionState[ConnectionState["Connecting"] = 1] = "Connecting";
|
|
49
|
-
/**
|
|
50
|
-
* The document is fully connected
|
|
51
|
-
*/
|
|
52
|
-
ConnectionState[ConnectionState["Connected"] = 2] = "Connected";
|
|
53
|
-
})(ConnectionState = exports.ConnectionState || (exports.ConnectionState = {}));
|
|
54
40
|
/**
|
|
55
41
|
* Waits until container connects to delta storage and gets up-to-date
|
|
56
42
|
* Useful when resolving URIs and hitting 404, due to container being loaded from (stale) snapshot and not being
|
|
@@ -78,7 +64,7 @@ async function waitContainerToCatchUp(container) {
|
|
|
78
64
|
};
|
|
79
65
|
container.on("closed", closedCallback);
|
|
80
66
|
const waitForOps = () => {
|
|
81
|
-
(0, common_utils_1.assert)(container.connectionState !== ConnectionState.Disconnected, 0x0cd /* "Container disconnected while waiting for ops!" */);
|
|
67
|
+
(0, common_utils_1.assert)(container.connectionState !== connectionState_1.ConnectionState.Disconnected, 0x0cd /* "Container disconnected while waiting for ops!" */);
|
|
82
68
|
const hasCheckpointSequenceNumber = deltaManager.hasCheckpointSequenceNumber;
|
|
83
69
|
const connectionOpSeqNumber = deltaManager.lastKnownSeqNumber;
|
|
84
70
|
(0, common_utils_1.assert)(deltaManager.lastSequenceNumber <= connectionOpSeqNumber, 0x266 /* "lastKnownSeqNumber should never be below last processed sequence number" */);
|
|
@@ -100,7 +86,7 @@ async function waitContainerToCatchUp(container) {
|
|
|
100
86
|
// But that works only if service provides us checkPointSequenceNumber
|
|
101
87
|
// Our internal testing is based on R11S that does not, but almost all tests connect as "write" and
|
|
102
88
|
// use this function to catch up, so leveraging our own join op as a fence/barrier
|
|
103
|
-
if (container.connectionState === ConnectionState.Connected) {
|
|
89
|
+
if (container.connectionState === connectionState_1.ConnectionState.Connected) {
|
|
104
90
|
waitForOps();
|
|
105
91
|
return;
|
|
106
92
|
}
|
|
@@ -121,7 +107,7 @@ const getCodeProposal =
|
|
|
121
107
|
const summarizerClientType = "summarizer";
|
|
122
108
|
class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
123
109
|
constructor(loader, config) {
|
|
124
|
-
var _a
|
|
110
|
+
var _a;
|
|
125
111
|
super((name, error) => {
|
|
126
112
|
this.mc.logger.sendErrorEvent({
|
|
127
113
|
eventName: "ContainerEventHandlerException",
|
|
@@ -141,7 +127,6 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
141
127
|
this.attachStarted = false;
|
|
142
128
|
this._dirtyContainer = false;
|
|
143
129
|
this.setAutoReconnectTime = common_utils_1.performance.now();
|
|
144
|
-
this.collabWindowTracker = new collabWindowTracker_1.CollabWindowTracker((type, contents) => this.submitMessage(type, contents), () => this.activeConnection(), (_a = this.loader.services.options) === null || _a === void 0 ? void 0 : _a.noopTimeFrequency, (_b = this.loader.services.options) === null || _b === void 0 ? void 0 : _b.noopCountFrequency);
|
|
145
130
|
this._audience = new audience_1.Audience();
|
|
146
131
|
this.clientDetailsOverride = config.clientDetailsOverride;
|
|
147
132
|
this._resolvedUrl = config.resolvedUrl;
|
|
@@ -161,7 +146,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
161
146
|
docId: () => { var _a, _b; return (_b = (_a = this._resolvedUrl) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : undefined; },
|
|
162
147
|
containerAttachState: () => this._attachState,
|
|
163
148
|
containerLifecycleState: () => this._lifecycleState,
|
|
164
|
-
containerConnectionState: () => ConnectionState[this.connectionState],
|
|
149
|
+
containerConnectionState: () => connectionState_1.ConnectionState[this.connectionState],
|
|
165
150
|
},
|
|
166
151
|
// we need to be judicious with our logging here to avoid generating too much data
|
|
167
152
|
// all data logged here should be broadly applicable, and not specific to a
|
|
@@ -182,7 +167,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
182
167
|
});
|
|
183
168
|
// Prefix all events in this file with container-loader
|
|
184
169
|
this.mc = (0, telemetry_utils_1.loggerToMonitoringContext)(telemetry_utils_1.ChildLogger.create(this.subLogger, "Container"));
|
|
185
|
-
const summarizeProtocolTree = (
|
|
170
|
+
const summarizeProtocolTree = (_a = this.mc.config.getBoolean("Fluid.Container.summarizeProtocolTree")) !== null && _a !== void 0 ? _a : this.loader.services.options.summarizeProtocolTree;
|
|
186
171
|
this.options = Object.assign(Object.assign({}, this.loader.services.options), { summarizeProtocolTree });
|
|
187
172
|
this.connectionStateHandler = new connectionStateHandler_1.ConnectionStateHandler({
|
|
188
173
|
quorumClients: () => { var _a; return (_a = this._protocolHandler) === null || _a === void 0 ? void 0 : _a.quorum; },
|
|
@@ -194,7 +179,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
194
179
|
// its own join op. Attempt recovery option.
|
|
195
180
|
this._deltaManager.logConnectionIssue({
|
|
196
181
|
eventName,
|
|
197
|
-
duration: common_utils_1.performance.now() - this.connectionTransitionTimes[ConnectionState.Connecting],
|
|
182
|
+
duration: common_utils_1.performance.now() - this.connectionTransitionTimes[connectionState_1.ConnectionState.Connecting],
|
|
198
183
|
});
|
|
199
184
|
},
|
|
200
185
|
connectionStateChanged: () => {
|
|
@@ -478,7 +463,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
478
463
|
(_a = this._protocolHandler) === null || _a === void 0 ? void 0 : _a.close();
|
|
479
464
|
this.connectionStateHandler.dispose();
|
|
480
465
|
(_b = this._context) === null || _b === void 0 ? void 0 : _b.dispose(error !== undefined ? new Error(error.message) : undefined);
|
|
481
|
-
(0, common_utils_1.assert)(this.connectionState === ConnectionState.Disconnected, 0x0cf /* "disconnect event was not raised!" */);
|
|
466
|
+
(0, common_utils_1.assert)(this.connectionState === connectionState_1.ConnectionState.Disconnected, 0x0cf /* "disconnect event was not raised!" */);
|
|
482
467
|
(_c = this._storageService) === null || _c === void 0 ? void 0 : _c.dispose();
|
|
483
468
|
// Notify storage about critical errors. They may be due to disconnect between client & server knowledge
|
|
484
469
|
// about file, like file being overwritten in storage, but client having stale local cache.
|
|
@@ -651,7 +636,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
651
636
|
this.mc.logger.sendTelemetryEvent({
|
|
652
637
|
eventName: mode === contracts_1.ReconnectMode.Enabled ? "AutoReconnectEnabled" : "AutoReconnectDisabled",
|
|
653
638
|
connectionMode: this.connectionMode,
|
|
654
|
-
connectionState: ConnectionState[this.connectionState],
|
|
639
|
+
connectionState: connectionState_1.ConnectionState[this.connectionState],
|
|
655
640
|
duration,
|
|
656
641
|
});
|
|
657
642
|
this._deltaManager.connectionManager.setAutoReconnect(mode);
|
|
@@ -758,8 +743,8 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
758
743
|
return versions[0];
|
|
759
744
|
}
|
|
760
745
|
recordConnectStartTime() {
|
|
761
|
-
if (this.connectionTransitionTimes[ConnectionState.Disconnected] === undefined) {
|
|
762
|
-
this.connectionTransitionTimes[ConnectionState.Disconnected] = common_utils_1.performance.now();
|
|
746
|
+
if (this.connectionTransitionTimes[connectionState_1.ConnectionState.Disconnected] === undefined) {
|
|
747
|
+
this.connectionTransitionTimes[connectionState_1.ConnectionState.Disconnected] = common_utils_1.performance.now();
|
|
763
748
|
}
|
|
764
749
|
}
|
|
765
750
|
connectToDeltaStream(args) {
|
|
@@ -1055,7 +1040,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
1055
1040
|
* If it's not true, runtime is not in position to send ops.
|
|
1056
1041
|
*/
|
|
1057
1042
|
activeConnection() {
|
|
1058
|
-
return this.connectionState === ConnectionState.Connected &&
|
|
1043
|
+
return this.connectionState === connectionState_1.ConnectionState.Connected &&
|
|
1059
1044
|
this.connectionMode === "write";
|
|
1060
1045
|
}
|
|
1061
1046
|
createDeltaManager() {
|
|
@@ -1076,7 +1061,8 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
1076
1061
|
this.connectionStateHandler.receivedConnectEvent(this.connectionMode, details);
|
|
1077
1062
|
});
|
|
1078
1063
|
deltaManager.on("disconnect", (reason) => {
|
|
1079
|
-
|
|
1064
|
+
var _a;
|
|
1065
|
+
(_a = this.collabWindowTracker) === null || _a === void 0 ? void 0 : _a.stopSequenceNumberUpdate();
|
|
1080
1066
|
this.connectionStateHandler.receivedDisconnectEvent(reason);
|
|
1081
1067
|
});
|
|
1082
1068
|
deltaManager.on("throttled", (warning) => {
|
|
@@ -1115,12 +1101,12 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
1115
1101
|
let autoReconnect;
|
|
1116
1102
|
let checkpointSequenceNumber;
|
|
1117
1103
|
let opsBehind;
|
|
1118
|
-
if (value === ConnectionState.Disconnected) {
|
|
1104
|
+
if (value === connectionState_1.ConnectionState.Disconnected) {
|
|
1119
1105
|
autoReconnect = this._deltaManager.connectionManager.reconnectMode;
|
|
1120
1106
|
}
|
|
1121
1107
|
else {
|
|
1122
|
-
if (value === ConnectionState.Connected) {
|
|
1123
|
-
durationFromDisconnected = time - this.connectionTransitionTimes[ConnectionState.Disconnected];
|
|
1108
|
+
if (value === connectionState_1.ConnectionState.Connected) {
|
|
1109
|
+
durationFromDisconnected = time - this.connectionTransitionTimes[connectionState_1.ConnectionState.Disconnected];
|
|
1124
1110
|
durationFromDisconnected = telemetry_utils_1.TelemetryLogger.formatTick(durationFromDisconnected);
|
|
1125
1111
|
}
|
|
1126
1112
|
else {
|
|
@@ -1137,23 +1123,23 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
1137
1123
|
connectionInitiationReason = "AutoReconnect";
|
|
1138
1124
|
}
|
|
1139
1125
|
}
|
|
1140
|
-
this.mc.logger.sendPerformanceEvent(Object.assign({ eventName: `ConnectionStateChange_${ConnectionState[value]}`, from: ConnectionState[oldState], duration,
|
|
1126
|
+
this.mc.logger.sendPerformanceEvent(Object.assign({ eventName: `ConnectionStateChange_${connectionState_1.ConnectionState[value]}`, from: connectionState_1.ConnectionState[oldState], duration,
|
|
1141
1127
|
durationFromDisconnected,
|
|
1142
1128
|
reason,
|
|
1143
1129
|
connectionInitiationReason, pendingClientId: this.connectionStateHandler.pendingClientId, clientId: this.clientId, autoReconnect,
|
|
1144
1130
|
opsBehind, online: driver_utils_1.OnlineStatus[(0, driver_utils_1.isOnline)()], lastVisible: this.lastVisible !== undefined ? common_utils_1.performance.now() - this.lastVisible : undefined, checkpointSequenceNumber }, this._deltaManager.connectionProps));
|
|
1145
|
-
if (value === ConnectionState.Connected) {
|
|
1131
|
+
if (value === connectionState_1.ConnectionState.Connected) {
|
|
1146
1132
|
this.firstConnection = false;
|
|
1147
1133
|
}
|
|
1148
1134
|
}
|
|
1149
1135
|
propagateConnectionState() {
|
|
1150
|
-
const logOpsOnReconnect = this.connectionState === ConnectionState.Connected &&
|
|
1136
|
+
const logOpsOnReconnect = this.connectionState === connectionState_1.ConnectionState.Connected &&
|
|
1151
1137
|
!this.firstConnection &&
|
|
1152
1138
|
this.connectionMode === "write";
|
|
1153
1139
|
if (logOpsOnReconnect) {
|
|
1154
1140
|
this.messageCountAfterDisconnection = 0;
|
|
1155
1141
|
}
|
|
1156
|
-
const state = this.connectionState === ConnectionState.Connected;
|
|
1142
|
+
const state = this.connectionState === connectionState_1.ConnectionState.Connected;
|
|
1157
1143
|
if (!this.context.disposed) {
|
|
1158
1144
|
this.context.setConnectionState(state, this.clientId);
|
|
1159
1145
|
}
|
|
@@ -1190,12 +1176,13 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
1190
1176
|
return this.submitMessage(type, contents, batch, metadata);
|
|
1191
1177
|
}
|
|
1192
1178
|
submitMessage(type, contents, batch, metadata) {
|
|
1193
|
-
|
|
1179
|
+
var _a;
|
|
1180
|
+
if (this.connectionState !== connectionState_1.ConnectionState.Connected) {
|
|
1194
1181
|
this.mc.logger.sendErrorEvent({ eventName: "SubmitMessageWithNoConnection", type });
|
|
1195
1182
|
return -1;
|
|
1196
1183
|
}
|
|
1197
1184
|
this.messageCountAfterDisconnection += 1;
|
|
1198
|
-
this.collabWindowTracker.stopSequenceNumberUpdate();
|
|
1185
|
+
(_a = this.collabWindowTracker) === null || _a === void 0 ? void 0 : _a.stopSequenceNumberUpdate();
|
|
1199
1186
|
return this._deltaManager.submit(type, contents, batch, metadata);
|
|
1200
1187
|
}
|
|
1201
1188
|
processRemoteMessage(message) {
|
|
@@ -1224,10 +1211,42 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
1224
1211
|
}
|
|
1225
1212
|
// Allow the protocol handler to process the message
|
|
1226
1213
|
const result = this.protocolHandler.processMessage(message, local);
|
|
1227
|
-
|
|
1214
|
+
// Inactive (not in quorum or not writers) clients don't take part in the minimum sequence number calculation.
|
|
1215
|
+
if (this.activeConnection()) {
|
|
1216
|
+
if (this.collabWindowTracker === undefined) {
|
|
1217
|
+
// Note that config from first connection will be used for this container's lifetime.
|
|
1218
|
+
// That means that if relay service changes settings, such changes will impact only newly booted
|
|
1219
|
+
// clients.
|
|
1220
|
+
// All existing will continue to use settings they got earlier.
|
|
1221
|
+
const [noopTimeFrequency, noopCountFrequency] = this.getNoopConfig();
|
|
1222
|
+
this.collabWindowTracker = new collabWindowTracker_1.CollabWindowTracker((type, contents) => {
|
|
1223
|
+
(0, common_utils_1.assert)(this.activeConnection(), 0x241 /* "disconnect should result in stopSequenceNumberUpdate() call" */);
|
|
1224
|
+
this.submitMessage(type, contents);
|
|
1225
|
+
}, noopTimeFrequency, noopCountFrequency);
|
|
1226
|
+
}
|
|
1227
|
+
this.collabWindowTracker.scheduleSequenceNumberUpdate(message, result.immediateNoOp === true);
|
|
1228
|
+
}
|
|
1228
1229
|
this.emit("op", message);
|
|
1229
1230
|
return result;
|
|
1230
1231
|
}
|
|
1232
|
+
/**
|
|
1233
|
+
* #260 (ADO)
|
|
1234
|
+
* back-compat: noopTimeFrequency & noopCountFrequency properties were added to
|
|
1235
|
+
* IClientConfiguration in 0.59.3000. During the integration, we must read the
|
|
1236
|
+
* available configuration from the loader options.
|
|
1237
|
+
*/
|
|
1238
|
+
getNoopConfig() {
|
|
1239
|
+
var _a, _b;
|
|
1240
|
+
(0, common_utils_1.assert)(this.serviceConfiguration !== undefined, 0x2e2);
|
|
1241
|
+
if (this.serviceConfiguration.noopTimeFrequency !== undefined ||
|
|
1242
|
+
this.serviceConfiguration.noopCountFrequency !== undefined) {
|
|
1243
|
+
return [
|
|
1244
|
+
this.serviceConfiguration.noopTimeFrequency,
|
|
1245
|
+
this.serviceConfiguration.noopCountFrequency,
|
|
1246
|
+
];
|
|
1247
|
+
}
|
|
1248
|
+
return [(_a = this.loader.services.options) === null || _a === void 0 ? void 0 : _a.noopTimeFrequency, (_b = this.loader.services.options) === null || _b === void 0 ? void 0 : _b.noopCountFrequency];
|
|
1249
|
+
}
|
|
1231
1250
|
submitSignal(message) {
|
|
1232
1251
|
this._deltaManager.submitSignal(JSON.stringify(message));
|
|
1233
1252
|
}
|