@fluidframework/container-runtime 2.52.0 → 2.53.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.
- package/CHANGELOG.md +4 -0
- package/container-runtime.test-files.tar +0 -0
- package/dist/containerRuntime.d.ts.map +1 -1
- package/dist/containerRuntime.js +4 -0
- package/dist/containerRuntime.js.map +1 -1
- package/dist/gc/garbageCollection.d.ts.map +1 -1
- package/dist/gc/garbageCollection.js +5 -0
- package/dist/gc/garbageCollection.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/pendingStateManager.d.ts.map +1 -1
- package/dist/pendingStateManager.js +4 -2
- package/dist/pendingStateManager.js.map +1 -1
- package/dist/summary/orderedClientElection.js +9 -9
- package/dist/summary/orderedClientElection.js.map +1 -1
- package/lib/containerRuntime.d.ts.map +1 -1
- package/lib/containerRuntime.js +4 -0
- package/lib/containerRuntime.js.map +1 -1
- package/lib/gc/garbageCollection.d.ts.map +1 -1
- package/lib/gc/garbageCollection.js +5 -0
- package/lib/gc/garbageCollection.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/pendingStateManager.d.ts.map +1 -1
- package/lib/pendingStateManager.js +4 -2
- package/lib/pendingStateManager.js.map +1 -1
- package/lib/summary/orderedClientElection.js +1 -1
- package/lib/summary/orderedClientElection.js.map +1 -1
- package/package.json +18 -18
- package/src/containerRuntime.ts +5 -0
- package/src/gc/garbageCollection.ts +6 -0
- package/src/packageVersion.ts +1 -1
- package/src/pendingStateManager.ts +4 -2
- package/src/summary/orderedClientElection.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pendingStateManager.js","sourceRoot":"","sources":["../src/pendingStateManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAA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AC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,KAAK,IAAI,CAAC,EACxE,KAAK,CAAC,2CAA2C,CACjD,CAAC;IACH,CAAC;CACD;AAED;;GAEG;AACH,SAAS,cAAc,CACtB,OAAiC;IAEjC,MAAM,SAAS,GAA0C,OAAO,CAAC,SAAS,CAAC;IAC3E,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC7B,gEAAgE;QAChE,OAAO,CAAC,SAAS,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,aAAa,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IACxF,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAS,mBAAmB,CAC3B,OAAwB;IAExB,OAAO,OAAO,CAAC,SAAS,KAAK,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,IAAI,KAAK,cAAc,CAAC;AACrF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDisposable, type ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert, Lazy } from \"@fluidframework/core-utils/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tDataProcessingError,\n\tLoggingError,\n\textractSafePropertiesFromMessage,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport Deque from \"double-ended-queue\";\nimport { v4 as uuid } from \"uuid\";\n\nimport { isContainerMessageDirtyable } from \"./containerRuntime.js\";\nimport {\n\ttype InboundContainerRuntimeMessage,\n\ttype InboundSequencedContainerRuntimeMessage,\n\ttype LocalContainerRuntimeMessage,\n} from \"./messageTypes.js\";\nimport { asBatchMetadata, asEmptyBatchLocalOpMetadata } from \"./metadata.js\";\nimport {\n\tEmptyGroupedBatch,\n\tLocalBatchMessage,\n\tgetEffectiveBatchId,\n\tBatchStartInfo,\n\tInboundMessageResult,\n\tserializeOp,\n\ttype LocalEmptyBatchPlaceholder,\n\ttype BatchResubmitInfo,\n} from \"./opLifecycle/index.js\";\n\n/**\n * This represents a message that has been submitted and is added to the pending queue when `submit` is called on the\n * ContainerRuntime. This message has either not been ack'd by the server or has not been submitted to the server yet.\n *\n * @remarks This is the current serialization format for pending local state when a Container is serialized.\n */\nexport interface IPendingMessage {\n\ttype: \"message\";\n\treferenceSequenceNumber: number;\n\t/**\n\t * Serialized copy of runtimeOp\n\t */\n\tcontent: string;\n\t/**\n\t * The original runtime op that was submitted to the ContainerRuntime\n\t * Unless this pending message came from stashed content, in which case this is undefined at first and then deserialized from the contents string\n\t */\n\truntimeOp: LocalContainerRuntimeMessage | EmptyGroupedBatch | undefined; // Undefined for initial messages before parsing\n\t/**\n\t * Local Op Metadata that was passed to the ContainerRuntime when the op was submitted.\n\t * This contains state needed when processing the ack, or to resubmit or rollback the op.\n\t */\n\tlocalOpMetadata: unknown;\n\t/**\n\t * Metadata that was passed to the ContainerRuntime when the op was submitted.\n\t * This is rarely used, and may be inspected by the service (as opposed to op contents which is opaque)\n\t */\n\topMetadata: Record<string, unknown> | undefined;\n\t/**\n\t * Populated upon processing the op's ack, before moving the pending message to savedOps.\n\t */\n\tsequenceNumber?: number;\n\t/**\n\t * Info about the batch this pending message belongs to, for validation and for computing the batchId on reconnect\n\t * We don't include batchId itself to avoid redundancy, because that's stamped on opMetadata above\n\t */\n\tbatchInfo: {\n\t\t/**\n\t\t * The Batch's original clientId, from when it was first flushed to be submitted.\n\t\t * Or, a random uuid if it was never submitted (and batchStartCsn will be -1)\n\t\t */\n\t\tclientId: string;\n\t\t/**\n\t\t * The Batch's original clientSequenceNumber, from when it was first flushed to be submitted\n\t\t * Or, -1 if it was never submitted (and clientId will be a random uuid)\n\t\t */\n\t\tbatchStartCsn: number;\n\t\t/**\n\t\t * length of the batch (how many runtime messages here)\n\t\t */\n\t\tlength: number;\n\t\t/**\n\t\t * If true, don't compare batchID of incoming batches to this. e.g. ID Allocation Batch IDs should be ignored\n\t\t */\n\t\tignoreBatchId?: boolean;\n\t\t/**\n\t\t * If true, this batch is staged and should not actually be submitted on replayPendingStates.\n\t\t */\n\t\tstaged: boolean;\n\t};\n}\n\ntype Patch<T, U> = U & Omit<T, keyof U>;\n\n/**\n * First version of the type (pre-dates batchInfo)\n */\ntype IPendingMessageV0 = Patch<IPendingMessage, { batchInfo?: undefined }>;\n\n/**\n * Union of all supported schemas for when applying stashed ops\n *\n * @remarks When the format changes, this type should update to reflect all possible schemas.\n */\ntype IPendingMessageFromStash = IPendingMessageV0 | IPendingMessage;\n\nexport interface IPendingLocalState {\n\t/**\n\t * list of pending states, including ops and batch information\n\t */\n\tpendingStates: IPendingMessage[];\n}\n\n/**\n * Info needed to replay/resubmit a pending message\n */\nexport type PendingMessageResubmitData = Pick<\n\tIPendingMessage,\n\t\"runtimeOp\" | \"localOpMetadata\" | \"opMetadata\"\n> & {\n\t// Required (it's only missing on IPendingMessage for empty batch, which will be resubmitted as an empty array)\n\truntimeOp: LocalContainerRuntimeMessage;\n};\n\nexport interface PendingBatchResubmitMetadata extends BatchResubmitInfo {\n\t/**\n\t * Whether changes in this batch should be squashed when resubmitting.\n\t */\n\tsquash: boolean;\n}\n\nexport interface IRuntimeStateHandler {\n\tconnected(): boolean;\n\tclientId(): string | undefined;\n\tapplyStashedOp(serializedOp: string): Promise<unknown>;\n\treSubmitBatch(\n\t\tbatch: PendingMessageResubmitData[],\n\t\tmetadata: PendingBatchResubmitMetadata,\n\t): void;\n\tisActiveConnection: () => boolean;\n\tisAttached: () => boolean;\n}\n\nfunction isEmptyBatchPendingMessage(message: IPendingMessageFromStash): boolean {\n\tconst content = JSON.parse(message.content) as Partial<EmptyGroupedBatch>;\n\treturn content.type === \"groupedBatch\" && content.contents?.length === 0;\n}\n\nfunction buildPendingMessageContent(message: InboundSequencedContainerRuntimeMessage): string {\n\t// IMPORTANT: Order matters here, this must match the order of the properties used\n\t// when submitting the message.\n\tconst { type, contents }: InboundContainerRuntimeMessage = message;\n\t// Any properties that are not defined, won't be emitted by stringify.\n\treturn JSON.stringify({ type, contents });\n}\n\nfunction typesOfKeys<T extends object>(obj: T): Record<keyof T, string> {\n\treturn Object.keys(obj).reduce((acc, key) => {\n\t\tacc[key] = typeof obj[key];\n\t\treturn acc;\n\t}, {}) as Record<keyof T, string>;\n}\n\nfunction scrubAndStringify(\n\tmessage: InboundContainerRuntimeMessage | LocalContainerRuntimeMessage,\n): string {\n\t// Scrub the whole object in case there are unexpected keys\n\tconst scrubbed: Record<string, unknown> = typesOfKeys(message);\n\n\t// For these known/expected keys, we can either drill into the object (for contents)\n\t// or just use the value as-is (since it's not personal info)\n\tscrubbed.contents = message.contents && typesOfKeys(message.contents);\n\tscrubbed.type = message.type;\n\n\treturn JSON.stringify(scrubbed);\n}\n\n/**\n * Finds and returns the index where the strings diverge, and the character at that index in each string (or undefined if not applicable)\n */\nfunction findFirstRawCharacterMismatched(\n\ta: string,\n\tb: string,\n): [index: number, charA?: string, charB?: string] {\n\tconst minLength = Math.min(a.length, b.length);\n\tfor (let i = 0; i < minLength; i++) {\n\t\tif (a[i] !== b[i]) {\n\t\t\treturn [i, a[i], b[i]];\n\t\t}\n\t}\n\n\t// Since we didn't return in the loop, the shorter string must be a prefix of the other.\n\t// If they're the same length, return -1 to indicate they're identical.\n\t// Otherwise, the next character of the longer one is where they differ. No need to return that next character.\n\treturn a.length === b.length\n\t\t? [-1, undefined, undefined]\n\t\t: [minLength, a[minLength], b[minLength]];\n}\n\n/**\n * Finds and returns the index where the strings diverge, and the character at that index in each string (or undefined if not applicable)\n * It scrubs non-ASCII characters since they convey more meaning (privacy consideration)\n */\nexport function findFirstCharacterMismatched(\n\ta: string,\n\tb: string,\n): [index: number, charA?: string, charB?: string] {\n\tconst [index, rawCharA, rawCharB] = findFirstRawCharacterMismatched(a, b);\n\n\tconst charA = (rawCharA?.codePointAt(0) ?? 0) <= 0x7f ? rawCharA : \"[non-ASCII]\";\n\tconst charB = (rawCharB?.codePointAt(0) ?? 0) <= 0x7f ? rawCharB : \"[non-ASCII]\";\n\n\treturn [index, charA, charB];\n}\n\n/**\n * Returns a shallow copy of the given message with the non-serializable properties removed.\n * Note that the runtimeOp's data has already been serialized in the content property.\n */\nfunction toSerializableForm(\n\tmessage: IPendingMessage,\n): IPendingMessage & { runtimeOp: undefined; localOpMetadata: undefined } {\n\treturn {\n\t\t...message,\n\t\tlocalOpMetadata: undefined,\n\t\truntimeOp: undefined,\n\t};\n}\n\ninterface ReplayPendingStateOptions {\n\t/**\n\t * If true, only replay staged batches, clearing the \"staged\" flag.\n\t * This is used when we are exiting staging mode and want to rebase and submit the staged batches without resubmitting pre-staged messages.\n\t * Default: false\n\t */\n\tcommittingStagedBatches: boolean;\n\t/**\n\t * @param squash - If true, edits should be squashed when resubmitting.\n\t * Default: false\n\t */\n\tsquash: boolean;\n}\n\nconst defaultReplayPendingStatesOptions: ReplayPendingStateOptions = {\n\tcommittingStagedBatches: false,\n\tsquash: false,\n};\n\n/**\n * PendingStateManager is responsible for maintaining the messages that have not been sent or have not yet been\n * acknowledged by the server. It also maintains the batch information for both automatically and manually flushed\n * batches along with the messages.\n * When the Container reconnects, it replays the pending states, which includes manual flushing\n * of messages and triggering resubmission of unacked ops.\n *\n * It verifies that all the ops are acked, are received in the right order and batch information is correct.\n */\nexport class PendingStateManager implements IDisposable {\n\t/**\n\t * Messages that will need to be resubmitted if not ack'd before the next reconnection\n\t */\n\tprivate readonly pendingMessages = new Deque<IPendingMessage>();\n\t/**\n\t * Messages stashed from a previous container, now being rehydrated. Need to be resubmitted.\n\t */\n\tprivate readonly initialMessages = new Deque<IPendingMessageFromStash>();\n\n\t/**\n\t * Sequenced local ops that are saved when stashing since pending ops may depend on them\n\t */\n\tprivate savedOps: IPendingMessage[] = [];\n\n\t// eslint-disable-next-line unicorn/consistent-function-scoping -- Property is defined once; no need to extract inner lambda\n\tprivate readonly disposeOnce = new Lazy<void>(() => {\n\t\tthis.initialMessages.clear();\n\t\tthis.pendingMessages.clear();\n\t});\n\n\t/**\n\t * Used to ensure we don't replay ops on the same connection twice\n\t */\n\tprivate clientIdFromLastReplay: string | undefined;\n\n\t/**\n\t * The pending messages count. Includes `pendingMessages` and `initialMessages` to keep in sync with\n\t * 'hasPendingMessages'.\n\t */\n\tpublic get pendingMessagesCount(): number {\n\t\treturn this.pendingMessages.length + this.initialMessages.length;\n\t}\n\n\t/**\n\t * Checks the pending messages to see if any of them represent user changes (aka \"dirtyable\" messages)\n\t */\n\tpublic hasPendingUserChanges(): boolean {\n\t\tfor (let i = 0; i < this.pendingMessages.length; i++) {\n\t\t\tconst element = this.pendingMessages.get(i);\n\t\t\tif (\n\t\t\t\telement !== undefined &&\n\t\t\t\thasTypicalRuntimeOp(element) && // Empty batches don't count towards user changes\n\t\t\t\tisContainerMessageDirtyable(element.runtimeOp)\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\t// Consider any initial messages to be user changes\n\t\t// (it's an approximation since we would have to parse them to know for sure)\n\t\treturn this.initialMessages.length > 0;\n\t}\n\n\t/**\n\t * The minimumPendingMessageSequenceNumber is the minimum of the first pending message and the first initial message.\n\t *\n\t * We need this so that we can properly keep local data and maintain the correct sequence window.\n\t */\n\tpublic get minimumPendingMessageSequenceNumber(): number | undefined {\n\t\treturn this.pendingMessages.peekFront()?.referenceSequenceNumber;\n\t}\n\n\t/**\n\t * Called to check if there are any pending messages in the pending message queue.\n\t * @returns A boolean indicating whether there are messages or not.\n\t */\n\tpublic hasPendingMessages(): boolean {\n\t\treturn this.pendingMessagesCount !== 0;\n\t}\n\n\tpublic getLocalState(snapshotSequenceNumber?: number): IPendingLocalState {\n\t\tassert(\n\t\t\tthis.initialMessages.isEmpty(),\n\t\t\t0x2e9 /* \"Must call getLocalState() after applying initial states\" */,\n\t\t);\n\t\t// Using snapshot sequence number to filter ops older than our latest snapshot.\n\t\t// Such ops should not be declared in pending/stashed state. Snapshot seq num will not\n\t\t// be available when the container is not attached. Therefore, no filtering is needed.\n\t\tconst newSavedOps = [...this.savedOps].filter((message) => {\n\t\t\tassert(\n\t\t\t\tmessage.sequenceNumber !== undefined,\n\t\t\t\t0x97c /* saved op should already have a sequence number */,\n\t\t\t);\n\t\t\treturn message.sequenceNumber > (snapshotSequenceNumber ?? 0);\n\t\t});\n\t\tfor (const message of this.pendingMessages.toArray()) {\n\t\t\tif (\n\t\t\t\tsnapshotSequenceNumber !== undefined &&\n\t\t\t\tmessage.referenceSequenceNumber < snapshotSequenceNumber\n\t\t\t) {\n\t\t\t\tthrow new LoggingError(\"trying to stash ops older than our latest snapshot\");\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tpendingStates: [\n\t\t\t\t...newSavedOps,\n\t\t\t\t...this.pendingMessages.toArray().map((message) => toSerializableForm(message)),\n\t\t\t],\n\t\t};\n\t}\n\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tconstructor(\n\t\tprivate readonly stateHandler: IRuntimeStateHandler,\n\t\tstashedLocalState: IPendingLocalState | undefined,\n\t\tlogger: ITelemetryBaseLogger,\n\t) {\n\t\tthis.logger = createChildLogger({ logger });\n\t\tif (stashedLocalState?.pendingStates) {\n\t\t\tthis.initialMessages.push(...stashedLocalState.pendingStates);\n\t\t}\n\t}\n\n\tpublic get disposed(): boolean {\n\t\treturn this.disposeOnce.evaluated;\n\t}\n\tpublic readonly dispose = (): void => this.disposeOnce.value;\n\n\t/**\n\t * We've flushed an empty batch, and need to track it locally until the corresponding\n\t * ack is processed, to properly track batch IDs\n\t */\n\tpublic onFlushEmptyBatch(\n\t\tplaceholder: LocalEmptyBatchPlaceholder,\n\t\tclientSequenceNumber: number | undefined,\n\t\tstaged: boolean,\n\t): void {\n\t\tthis.onFlushBatch([placeholder], clientSequenceNumber, staged);\n\t}\n\n\t/**\n\t * The given batch has been flushed, and needs to be tracked locally until the corresponding\n\t * acks are processed, to ensure it is successfully sent.\n\t * @param batch - The batch that was flushed\n\t * @param clientSequenceNumber - The CSN of the first message in the batch,\n\t * or undefined if the batch was not yet sent (e.g. by the time we flushed we lost the connection)\n\t * @param staged - Indicates whether batch is staged (not to be submitted while runtime is in Staging Mode)\n\t * @param ignoreBatchId - Whether to ignore the batchId in the batchStartInfo\n\t */\n\tpublic onFlushBatch(\n\t\tbatch: LocalBatchMessage[] | [LocalEmptyBatchPlaceholder],\n\t\tclientSequenceNumber: number | undefined,\n\t\tstaged: boolean,\n\t\tignoreBatchId?: boolean,\n\t): void {\n\t\t// clientId and batchStartCsn are used for generating the batchId so we can detect container forks\n\t\t// where this batch was submitted by two different clients rehydrating from the same local state.\n\t\t// In the typical case where the batch was actually sent, use the clientId and clientSequenceNumber.\n\t\t// In the case where the batch was not sent, use a random uuid for clientId, and -1 for clientSequenceNumber to indicate this case.\n\t\t// This will guarantee uniqueness of the batchId, and is a suitable fallback since clientId/CSN is only needed if the batch was actually sent/sequenced.\n\t\tconst batchWasSent = clientSequenceNumber !== undefined;\n\t\tif (batchWasSent) {\n\t\t\tassert(!staged, 0xb84 /* Staged batches should not have been submitted */);\n\t\t}\n\t\tconst [clientId, batchStartCsn] = batchWasSent\n\t\t\t? [this.stateHandler.clientId(), clientSequenceNumber]\n\t\t\t: [uuid(), -1]; // -1 will indicate not a real clientId/CSN pair\n\t\tassert(\n\t\t\tclientId !== undefined,\n\t\t\t0xa33 /* clientId (from stateHandler) could only be undefined if we've never connected, but we have a CSN so we know that's not the case */,\n\t\t);\n\n\t\tfor (const message of batch) {\n\t\t\tconst {\n\t\t\t\truntimeOp,\n\t\t\t\treferenceSequenceNumber,\n\t\t\t\tlocalOpMetadata,\n\t\t\t\tmetadata: opMetadata,\n\t\t\t} = message;\n\t\t\tconst pendingMessage: IPendingMessage = {\n\t\t\t\ttype: \"message\",\n\t\t\t\treferenceSequenceNumber,\n\t\t\t\tcontent: serializeOp(runtimeOp),\n\t\t\t\truntimeOp,\n\t\t\t\tlocalOpMetadata,\n\t\t\t\topMetadata,\n\t\t\t\t// Note: We only will read this off the first message, but put it on all for simplicity\n\t\t\t\tbatchInfo: { clientId, batchStartCsn, length: batch.length, ignoreBatchId, staged },\n\t\t\t};\n\t\t\tthis.pendingMessages.push(pendingMessage);\n\t\t}\n\t}\n\n\t/**\n\t * Applies stashed ops at their reference sequence number so they are ready to be ACKed or resubmitted\n\t * @param seqNum - Sequence number at which to apply ops. Will apply all ops if seqNum is undefined.\n\t */\n\tpublic async applyStashedOpsAt(seqNum?: number): Promise<void> {\n\t\t// apply stashed ops at sequence number\n\t\twhile (!this.initialMessages.isEmpty()) {\n\t\t\tif (seqNum !== undefined) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst peekMessage = this.initialMessages.peekFront()!;\n\t\t\t\tif (peekMessage.referenceSequenceNumber > seqNum) {\n\t\t\t\t\tbreak; // nothing left to do at this sequence number\n\t\t\t\t}\n\t\t\t\tif (peekMessage.referenceSequenceNumber < seqNum) {\n\t\t\t\t\tthrow new Error(\"loaded from snapshot too recent to apply stashed ops\");\n\t\t\t\t}\n\t\t\t}\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst nextMessage = this.initialMessages.shift()!;\n\t\t\t// Nothing to apply if the message is an empty batch.\n\t\t\t// We still need to track it for resubmission.\n\t\t\ttry {\n\t\t\t\tif (isEmptyBatchPendingMessage(nextMessage)) {\n\t\t\t\t\tnextMessage.localOpMetadata = {\n\t\t\t\t\t\temptyBatch: true,\n\t\t\t\t\t} satisfies LocalEmptyBatchPlaceholder[\"localOpMetadata\"]; // equivalent to applyStashedOp for empty batch\n\t\t\t\t\tpatchbatchInfo(nextMessage); // Back compat\n\t\t\t\t\tthis.pendingMessages.push(nextMessage);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// applyStashedOp will cause the DDS to behave as if it has sent the op but not actually send it\n\t\t\t\tconst localOpMetadata = await this.stateHandler.applyStashedOp(nextMessage.content);\n\t\t\t\tif (this.stateHandler.isAttached()) {\n\t\t\t\t\tnextMessage.localOpMetadata = localOpMetadata;\n\t\t\t\t\t// NOTE: This runtimeOp has been roundtripped through string, which is technically lossy.\n\t\t\t\t\t// e.g. At this point, handles are in their encoded form.\n\t\t\t\t\tnextMessage.runtimeOp = JSON.parse(\n\t\t\t\t\t\tnextMessage.content,\n\t\t\t\t\t) as LocalContainerRuntimeMessage;\n\t\t\t\t\t// then we push onto pendingMessages which will cause PendingStateManager to resubmit when we connect\n\t\t\t\t\tpatchbatchInfo(nextMessage); // Back compat\n\t\t\t\t\tthis.pendingMessages.push(nextMessage);\n\t\t\t\t} else {\n\t\t\t\t\tif (localOpMetadata !== undefined) {\n\t\t\t\t\t\tthrow new Error(\"Local Op Metadata must be undefined when not attached\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthrow DataProcessingError.wrapIfUnrecognized(error, \"applyStashedOp\", nextMessage);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Compares the batch ID of the incoming batch with the pending batch ID for this client.\n\t * They should not match, as that would indicate a forked container.\n\t * @param remoteBatchStart - BatchStartInfo for an incoming batch *NOT* submitted by this client\n\t * @returns whether the batch IDs match\n\t */\n\tprivate remoteBatchMatchesPendingBatch(remoteBatchStart: BatchStartInfo): boolean {\n\t\t// Find the first pending message that uses Batch ID, to compare to the incoming remote batch.\n\t\t// If there is no such message, then the incoming remote batch doesn't have a match here and we can return.\n\t\tconst firstIndexUsingBatchId = Array.from({\n\t\t\tlength: this.pendingMessages.length,\n\t\t}).findIndex((_, i) => this.pendingMessages.get(i)?.batchInfo.ignoreBatchId !== true);\n\t\tconst pendingMessageUsingBatchId =\n\t\t\tfirstIndexUsingBatchId === -1\n\t\t\t\t? undefined\n\t\t\t\t: this.pendingMessages.get(firstIndexUsingBatchId);\n\n\t\tif (pendingMessageUsingBatchId === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// We must compare the effective batch IDs, since one of these ops\n\t\t// may have been the original, not resubmitted, so wouldn't have its batch ID stamped yet.\n\t\tconst pendingBatchId = getEffectiveBatchId(pendingMessageUsingBatchId);\n\t\tconst inboundBatchId = getEffectiveBatchId(remoteBatchStart);\n\n\t\treturn pendingBatchId === inboundBatchId;\n\t}\n\n\t/**\n\t * Processes an inbound message or batch of messages - May be local or remote.\n\t *\n\t * @param inbound - The inbound message(s) to process, with extra info (e.g. about the start of a batch). Could be local or remote.\n\t * @param local - true if we submitted these messages and expect corresponding pending messages\n\t * @returns The inbound messages with localOpMetadata \"zipped\" in.\n\t *\n\t * @throws a DataProcessingError in either of these cases:\n\t * - The pending message content doesn't match the incoming message content for any message here\n\t * - The batch IDs *do match* but it's not local (indicates Container forking).\n\t */\n\tpublic processInboundMessages(\n\t\tinbound: InboundMessageResult,\n\t\tlocal: boolean,\n\t): {\n\t\tmessage: InboundSequencedContainerRuntimeMessage;\n\t\tlocalOpMetadata?: unknown;\n\t}[] {\n\t\tif (local) {\n\t\t\treturn this.processPendingLocalMessages(inbound);\n\t\t}\n\n\t\t// An inbound remote batch should not match the pending batch ID for this client.\n\t\t// That would indicate the container forked (two instances trying to submit the same local state)\n\t\tif (\"batchStart\" in inbound && this.remoteBatchMatchesPendingBatch(inbound.batchStart)) {\n\t\t\tthrow DataProcessingError.create(\n\t\t\t\t\"Forked Container Error! Matching batchIds but mismatched clientId\",\n\t\t\t\t\"PendingStateManager.processInboundMessages\",\n\t\t\t\tinbound.batchStart.keyMessage,\n\t\t\t);\n\t\t}\n\n\t\t// No localOpMetadata for remote messages\n\t\tconst messages = inbound.type === \"fullBatch\" ? inbound.messages : [inbound.nextMessage];\n\t\treturn messages.map((message) => ({ message }));\n\t}\n\n\t/**\n\t * Processes the incoming message(s) from the server that were submitted by this client.\n\t * It verifies that messages are received in the right order and that any batch information is correct.\n\t * @param inbound - The inbound message(s) (originating from this client) to correlate with the pending local state\n\t * @throws DataProcessingError if the pending message content doesn't match the incoming message content for any message here\n\t * @returns The inbound messages with localOpMetadata \"zipped\" in.\n\t */\n\tprivate processPendingLocalMessages(inbound: InboundMessageResult): {\n\t\tmessage: InboundSequencedContainerRuntimeMessage;\n\t\tlocalOpMetadata: unknown;\n\t}[] {\n\t\tif (\"batchStart\" in inbound) {\n\t\t\tthis.onLocalBatchBegin(inbound.batchStart, inbound.length);\n\t\t}\n\n\t\t// Empty batch\n\t\tif (inbound.length === 0) {\n\t\t\tconst localOpMetadata = this.processNextPendingMessage(\n\t\t\t\tinbound.batchStart.keyMessage.sequenceNumber,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\tasEmptyBatchLocalOpMetadata(localOpMetadata)?.emptyBatch === true,\n\t\t\t\t0xa20 /* Expected empty batch marker */,\n\t\t\t);\n\t\t\treturn [];\n\t\t}\n\n\t\tconst messages = inbound.type === \"fullBatch\" ? inbound.messages : [inbound.nextMessage];\n\n\t\treturn messages.map((message) => ({\n\t\t\tmessage,\n\t\t\tlocalOpMetadata: this.processNextPendingMessage(message.sequenceNumber, message),\n\t\t}));\n\t}\n\n\t/**\n\t * Processes the pending local copy of message that's been ack'd by the server.\n\t * @param sequenceNumber - The sequenceNumber from the server corresponding to the next pending message.\n\t * @param message - [optional] The entire incoming message, for comparing contents with the pending message for extra validation.\n\t * @throws DataProcessingError if the pending message content doesn't match the incoming message content.\n\t * @returns - The localOpMetadata of the next pending message, to be sent to whoever submitted the original message.\n\t */\n\tprivate processNextPendingMessage(\n\t\tsequenceNumber: number,\n\t\tmessage?: InboundSequencedContainerRuntimeMessage,\n\t): unknown {\n\t\tconst pendingMessage = this.pendingMessages.peekFront();\n\t\tassert(\n\t\t\tpendingMessage !== undefined,\n\t\t\t0x169 /* \"No pending message found for this remote message\" */,\n\t\t);\n\n\t\tpendingMessage.sequenceNumber = sequenceNumber;\n\t\tthis.savedOps.push(toSerializableForm(pendingMessage));\n\n\t\tthis.pendingMessages.shift();\n\n\t\t// message is undefined in the Empty Batch case,\n\t\t// because we don't have an incoming message to compare and pendingMessage is just a placeholder anyway.\n\t\tif (message !== undefined) {\n\t\t\tconst messageContent = buildPendingMessageContent(message);\n\n\t\t\t// Stringified content should match\n\t\t\t// If it doesn't, collect as much info about the difference as possible (privacy-wise) and log it\n\t\t\tif (pendingMessage.content !== messageContent) {\n\t\t\t\tconst [pendingLength, incomingLength] = [\n\t\t\t\t\tpendingMessage.content.length,\n\t\t\t\t\tmessageContent.length,\n\t\t\t\t];\n\t\t\t\tconst [mismatchStartIndex, pendingChar, incomingChar] = findFirstCharacterMismatched(\n\t\t\t\t\tpendingMessage.content,\n\t\t\t\t\tmessageContent,\n\t\t\t\t);\n\n\t\t\t\tconst pendingContentObj = JSON.parse(\n\t\t\t\t\tpendingMessage.content,\n\t\t\t\t) as LocalContainerRuntimeMessage;\n\t\t\t\tconst incomingContentObj = JSON.parse(\n\t\t\t\t\tmessageContent,\n\t\t\t\t) as InboundContainerRuntimeMessage;\n\n\t\t\t\t// Compare inner contents object, since that both should be { type, contents }\n\t\t\t\tconst contentsMatch =\n\t\t\t\t\tpendingContentObj.contents === incomingContentObj.contents ||\n\t\t\t\t\t(pendingContentObj.contents !== undefined &&\n\t\t\t\t\t\tincomingContentObj.contents !== undefined &&\n\t\t\t\t\t\tJSON.stringify(pendingContentObj.contents) ===\n\t\t\t\t\t\t\tJSON.stringify(incomingContentObj.contents));\n\n\t\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"unexpectedAckReceived\",\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tpendingContentScrubbed: scrubAndStringify(pendingContentObj),\n\t\t\t\t\t\tincomingContentScrubbed: scrubAndStringify(incomingContentObj),\n\t\t\t\t\t\tcontentsMatch,\n\t\t\t\t\t\tpendingLength,\n\t\t\t\t\t\tincomingLength,\n\t\t\t\t\t\tmismatchStartIndex,\n\t\t\t\t\t\tpendingChar,\n\t\t\t\t\t\tincomingChar,\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\tthrow DataProcessingError.create(\n\t\t\t\t\t\"pending local message content mismatch\",\n\t\t\t\t\t\"unexpectedAckReceived\",\n\t\t\t\t\tmessage,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn pendingMessage.localOpMetadata;\n\t}\n\n\t/**\n\t * Check if the incoming batch matches the batch info for the next pending message.\n\t */\n\tprivate onLocalBatchBegin(batchStart: BatchStartInfo, batchLength?: number): void {\n\t\t// Get the next message from the pending queue. Verify a message exists.\n\t\tconst pendingMessage = this.pendingMessages.peekFront();\n\t\tassert(\n\t\t\tpendingMessage !== undefined,\n\t\t\t0xa21 /* No pending message found as we start processing this remote batch */,\n\t\t);\n\t\tassert(\n\t\t\t!pendingMessage.batchInfo.staged,\n\t\t\t0xb85 /* Pending state mismatch, ack came in but next pending message is staged */,\n\t\t);\n\n\t\t// If this batch became empty on resubmit, batch.messages will be empty (but keyMessage is always set)\n\t\t// and the next pending message should be an empty batch marker.\n\t\t// More Info: We must submit empty batches and track them in case a different fork\n\t\t// of this container also submitted the same batch (and it may not be empty for that fork).\n\t\tconst firstMessage = batchStart.keyMessage;\n\t\t// -1 length is for back compat, undefined length means we actually don't know it\n\t\tconst skipLengthCheck =\n\t\t\tpendingMessage.batchInfo.length === -1 || batchLength === undefined;\n\t\tconst expectedPendingBatchLength =\n\t\t\tbatchLength === 0\n\t\t\t\t? 1 // For an empty batch, expect a singleton array with the empty batch marker\n\t\t\t\t: batchLength; // Otherwise, the lengths should actually match\n\n\t\t// Note: We don't need to use getEffectiveBatchId here, just check the explicit stamped batchID\n\t\t// That logic is needed only when comparing across potential container forks.\n\t\t// Furthermore, we also are comparing the batch IDs constituent data - clientId (it's local) and batchStartCsn.\n\t\tconst pendingBatchId = asBatchMetadata(pendingMessage.opMetadata)?.batchId;\n\t\tconst inboundBatchId = batchStart.batchId;\n\n\t\t// We expect the incoming batch to be of the same length, starting at the same clientSequenceNumber,\n\t\t// as the batch we originally submitted. The batchIds should match as well, if set (or neither should be set)\n\t\t// We have another later check to compare the message contents, which we'd expect to fail if this check does,\n\t\t// so we don't throw here, merely log. In a later release this check may replace that one since it's cheaper.\n\t\tif (\n\t\t\tpendingMessage.batchInfo.batchStartCsn !== batchStart.batchStartCsn ||\n\t\t\t(!skipLengthCheck && pendingMessage.batchInfo.length !== expectedPendingBatchLength) ||\n\t\t\tpendingBatchId !== inboundBatchId\n\t\t) {\n\t\t\tthis.logger?.sendErrorEvent({\n\t\t\t\teventName: \"BatchInfoMismatch\",\n\t\t\t\tdetails: {\n\t\t\t\t\tpendingBatchCsn: pendingMessage.batchInfo.batchStartCsn,\n\t\t\t\t\tbatchStartCsn: batchStart.batchStartCsn,\n\t\t\t\t\tpendingBatchLength: pendingMessage.batchInfo.length,\n\t\t\t\t\texpectedPendingBatchLength,\n\t\t\t\t\tbatchLength,\n\t\t\t\t\tpendingBatchId,\n\t\t\t\t\tinboundBatchId,\n\t\t\t\t\tpendingMessageBatchMetadata: asBatchMetadata(pendingMessage.opMetadata)?.batch,\n\t\t\t\t\tmessageBatchMetadata: asBatchMetadata(firstMessage?.metadata)?.batch,\n\t\t\t\t},\n\t\t\t\tmessageDetails: firstMessage && extractSafePropertiesFromMessage(firstMessage),\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Called when the Container's connection state changes. If the Container gets connected, it replays all the pending\n\t * states in its queue. This includes triggering resubmission of unacked ops.\n\t * ! Note: successfully resubmitting an op that has been successfully sequenced is not possible due to checks in the ConnectionStateHandler (Loader layer)\n\t */\n\tpublic replayPendingStates(options?: ReplayPendingStateOptions): void {\n\t\tconst { committingStagedBatches, squash } = {\n\t\t\t...defaultReplayPendingStatesOptions,\n\t\t\t...options,\n\t\t};\n\t\tassert(\n\t\t\tthis.stateHandler.connected() || committingStagedBatches === true,\n\t\t\t0x172 /* \"The connection state is not consistent with the runtime\" */,\n\t\t);\n\n\t\t// Staged batches have not yet been submitted so check doesn't apply\n\t\tif (!committingStagedBatches) {\n\t\t\t// This assert suggests we are about to send same ops twice, which will result in data loss.\n\t\t\tassert(\n\t\t\t\tthis.clientIdFromLastReplay !== this.stateHandler.clientId(),\n\t\t\t\t0x173 /* \"replayPendingStates called twice for same clientId!\" */,\n\t\t\t);\n\t\t}\n\t\tthis.clientIdFromLastReplay = this.stateHandler.clientId();\n\n\t\tassert(\n\t\t\tthis.initialMessages.isEmpty(),\n\t\t\t0x174 /* \"initial states should be empty before replaying pending\" */,\n\t\t);\n\n\t\tconst initialPendingMessagesCount = this.pendingMessages.length;\n\t\tlet remainingPendingMessagesCount = this.pendingMessages.length;\n\n\t\tlet seenStagedBatch = false;\n\n\t\t// Process exactly `pendingMessagesCount` items in the queue as it represents the number of messages that were\n\t\t// pending when we connected. This is important because the `reSubmitFn` might add more items in the queue\n\t\t// which must not be replayed.\n\t\twhile (remainingPendingMessagesCount > 0) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tlet pendingMessage = this.pendingMessages.shift()!;\n\t\t\tremainingPendingMessagesCount--;\n\n\t\t\t// Re-queue pre-staging messages - we are only to replay staged batches\n\t\t\tif (committingStagedBatches) {\n\t\t\t\tif (!pendingMessage.batchInfo.staged) {\n\t\t\t\t\tassert(!seenStagedBatch, 0xb86 /* Staged batch was followed by non-staged batch */);\n\t\t\t\t\tthis.pendingMessages.push(pendingMessage);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tseenStagedBatch = true;\n\t\t\t\tpendingMessage.batchInfo.staged = false; // Clear staged flag so we can submit\n\t\t\t}\n\n\t\t\tconst batchMetadataFlag = asBatchMetadata(pendingMessage.opMetadata)?.batch;\n\t\t\tassert(batchMetadataFlag !== false, 0x41b /* We cannot process batches in chunks */);\n\n\t\t\t// The next message starts a batch (possibly single-message), and we'll need its batchId.\n\t\t\tconst batchId = pendingMessage.batchInfo.ignoreBatchId\n\t\t\t\t? undefined\n\t\t\t\t: getEffectiveBatchId(pendingMessage);\n\n\t\t\tconst staged = pendingMessage.batchInfo.staged;\n\n\t\t\tif (asEmptyBatchLocalOpMetadata(pendingMessage.localOpMetadata)?.emptyBatch === true) {\n\t\t\t\t// Resubmit no messages, with the batchId. Will result in another empty batch marker.\n\t\t\t\tthis.stateHandler.reSubmitBatch([], { batchId, staged, squash });\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tassert(\n\t\t\t\thasTypicalRuntimeOp(pendingMessage),\n\t\t\t\t0xb87 /* runtimeOp is only undefined for empty batches */,\n\t\t\t);\n\n\t\t\t/**\n\t\t\t * We must preserve the distinct batches on resubmit.\n\t\t\t * Note: It is not possible for the PendingStateManager to receive a partially acked batch. It will\n\t\t\t * either receive the whole batch ack or nothing at all. See {@link InboundBatchAggregator} for how this works.\n\t\t\t */\n\t\t\tif (batchMetadataFlag === undefined) {\n\t\t\t\t// Single-message batch\n\n\t\t\t\tthis.stateHandler.reSubmitBatch(\n\t\t\t\t\t[\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\truntimeOp: pendingMessage.runtimeOp,\n\t\t\t\t\t\t\tlocalOpMetadata: pendingMessage.localOpMetadata,\n\t\t\t\t\t\t\topMetadata: pendingMessage.opMetadata,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\t{ batchId, staged, squash },\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// else: batchMetadataFlag === true (It's a typical multi-message batch)\n\n\t\t\tassert(\n\t\t\t\tremainingPendingMessagesCount > 0,\n\t\t\t\t0x554 /* Last pending message cannot be a batch begin */,\n\t\t\t);\n\n\t\t\tconst batch: PendingMessageResubmitData[] = [];\n\n\t\t\t// check is >= because batch end may be last pending message\n\t\t\twhile (remainingPendingMessagesCount >= 0) {\n\t\t\t\tassert(\n\t\t\t\t\thasTypicalRuntimeOp(pendingMessage),\n\t\t\t\t\t0xb88 /* runtimeOp is only undefined for empty batches */,\n\t\t\t\t);\n\t\t\t\tbatch.push({\n\t\t\t\t\truntimeOp: pendingMessage.runtimeOp,\n\t\t\t\t\tlocalOpMetadata: pendingMessage.localOpMetadata,\n\t\t\t\t\topMetadata: pendingMessage.opMetadata,\n\t\t\t\t});\n\n\t\t\t\t// End of the batch\n\t\t\t\tif (pendingMessage.opMetadata?.batch === false) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tassert(remainingPendingMessagesCount > 0, 0x555 /* No batch end found */);\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tpendingMessage = this.pendingMessages.shift()!;\n\t\t\t\tremainingPendingMessagesCount--;\n\t\t\t\tassert(\n\t\t\t\t\tpendingMessage.opMetadata?.batch !== true,\n\t\t\t\t\t0x556 /* Batch start needs a corresponding batch end */,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.stateHandler.reSubmitBatch(batch, { batchId, staged, squash });\n\t\t}\n\n\t\t// pending ops should no longer depend on previous sequenced local ops after resubmit\n\t\tthis.savedOps = [];\n\n\t\t// We replayPendingStates on read connections too - we expect these to get nack'd though, and to then reconnect\n\t\t// on a write connection and replay again. This filters out the replay that happens on the read connection so\n\t\t// we only see the replays on write connections (that have a chance to go through).\n\t\tif (this.stateHandler.isActiveConnection()) {\n\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\teventName: \"PendingStatesReplayed\",\n\t\t\t\tcount: initialPendingMessagesCount,\n\t\t\t\tclientId: this.stateHandler.clientId(),\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Pops all staged batches, invoking the callback on each constituent op in order (LIFO)\n\t */\n\tpublic popStagedBatches(\n\t\tcallback: (\n\t\t\t// callback will only be given staged messages with a valid runtime op (i.e. not empty batch and not an initial message with only serialized content)\n\t\t\tstagedMessage: IPendingMessage & { runtimeOp: LocalContainerRuntimeMessage },\n\t\t) => void,\n\t): void {\n\t\twhile (!this.pendingMessages.isEmpty()) {\n\t\t\tconst stagedMessage = this.pendingMessages.peekBack();\n\t\t\tif (stagedMessage?.batchInfo.staged === true) {\n\t\t\t\tthis.pendingMessages.pop();\n\n\t\t\t\tif (hasTypicalRuntimeOp(stagedMessage)) {\n\t\t\t\t\tcallback(stagedMessage);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tbreak; // no more staged messages\n\t\t\t}\n\t\t}\n\t\tassert(\n\t\t\tthis.pendingMessages.toArray().every((m) => m.batchInfo.staged !== true),\n\t\t\t0xb89 /* Shouldn't be any more staged messages */,\n\t\t);\n\t}\n}\n\n/**\n * For back-compat if trying to apply stashed ops that pre-date batchInfo\n */\nfunction patchbatchInfo(\n\tmessage: IPendingMessageFromStash,\n): asserts message is IPendingMessage {\n\tconst batchInfo: IPendingMessageFromStash[\"batchInfo\"] = message.batchInfo;\n\tif (batchInfo === undefined) {\n\t\t// Using uuid guarantees uniqueness, retaining existing behavior\n\t\tmessage.batchInfo = { clientId: uuid(), batchStartCsn: -1, length: -1, staged: false };\n\t}\n}\n\n/**\n * This filters out messages that are not \"typical\" runtime ops, i.e. empty batches or initial messages (which only have serialized content).\n */\nfunction hasTypicalRuntimeOp(\n\tmessage: IPendingMessage,\n): message is IPendingMessage & { runtimeOp: LocalContainerRuntimeMessage } {\n\treturn message.runtimeOp !== undefined && message.runtimeOp.type !== \"groupedBatch\";\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pendingStateManager.js","sourceRoot":"","sources":["../src/pendingStateManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAEN,mBAAmB,EACnB,YAAY,EACZ,gCAAgC,EAChC,iBAAiB,GACjB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,MAAM,oBAAoB,CAAC;AACvC,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAMpE,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAGN,mBAAmB,EAGnB,WAAW,GAGX,MAAM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a,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IACxF,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAS,mBAAmB,CAC3B,OAAwB;IAExB,OAAO,OAAO,CAAC,SAAS,KAAK,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,IAAI,KAAK,cAAc,CAAC;AACrF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDisposable, type ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert, Lazy } from \"@fluidframework/core-utils/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tDataProcessingError,\n\tLoggingError,\n\textractSafePropertiesFromMessage,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport Deque from \"double-ended-queue\";\nimport { v4 as uuid } from \"uuid\";\n\nimport { isContainerMessageDirtyable } from \"./containerRuntime.js\";\nimport {\n\ttype InboundContainerRuntimeMessage,\n\ttype InboundSequencedContainerRuntimeMessage,\n\ttype LocalContainerRuntimeMessage,\n} from \"./messageTypes.js\";\nimport { asBatchMetadata, asEmptyBatchLocalOpMetadata } from \"./metadata.js\";\nimport {\n\tEmptyGroupedBatch,\n\tLocalBatchMessage,\n\tgetEffectiveBatchId,\n\tBatchStartInfo,\n\tInboundMessageResult,\n\tserializeOp,\n\ttype LocalEmptyBatchPlaceholder,\n\ttype BatchResubmitInfo,\n} from \"./opLifecycle/index.js\";\n\n/**\n * This represents a message that has been submitted and is added to the pending queue when `submit` is called on the\n * ContainerRuntime. This message has either not been ack'd by the server or has not been submitted to the server yet.\n *\n * @remarks This is the current serialization format for pending local state when a Container is serialized.\n */\nexport interface IPendingMessage {\n\ttype: \"message\";\n\treferenceSequenceNumber: number;\n\t/**\n\t * Serialized copy of runtimeOp\n\t */\n\tcontent: string;\n\t/**\n\t * The original runtime op that was submitted to the ContainerRuntime\n\t * Unless this pending message came from stashed content, in which case this is undefined at first and then deserialized from the contents string\n\t */\n\truntimeOp: LocalContainerRuntimeMessage | EmptyGroupedBatch | undefined; // Undefined for initial messages before parsing\n\t/**\n\t * Local Op Metadata that was passed to the ContainerRuntime when the op was submitted.\n\t * This contains state needed when processing the ack, or to resubmit or rollback the op.\n\t */\n\tlocalOpMetadata: unknown;\n\t/**\n\t * Metadata that was passed to the ContainerRuntime when the op was submitted.\n\t * This is rarely used, and may be inspected by the service (as opposed to op contents which is opaque)\n\t */\n\topMetadata: Record<string, unknown> | undefined;\n\t/**\n\t * Populated upon processing the op's ack, before moving the pending message to savedOps.\n\t */\n\tsequenceNumber?: number;\n\t/**\n\t * Info about the batch this pending message belongs to, for validation and for computing the batchId on reconnect\n\t * We don't include batchId itself to avoid redundancy, because that's stamped on opMetadata above\n\t */\n\tbatchInfo: {\n\t\t/**\n\t\t * The Batch's original clientId, from when it was first flushed to be submitted.\n\t\t * Or, a random uuid if it was never submitted (and batchStartCsn will be -1)\n\t\t */\n\t\tclientId: string;\n\t\t/**\n\t\t * The Batch's original clientSequenceNumber, from when it was first flushed to be submitted\n\t\t * Or, -1 if it was never submitted (and clientId will be a random uuid)\n\t\t */\n\t\tbatchStartCsn: number;\n\t\t/**\n\t\t * length of the batch (how many runtime messages here)\n\t\t */\n\t\tlength: number;\n\t\t/**\n\t\t * If true, don't compare batchID of incoming batches to this. e.g. ID Allocation Batch IDs should be ignored\n\t\t */\n\t\tignoreBatchId?: boolean;\n\t\t/**\n\t\t * If true, this batch is staged and should not actually be submitted on replayPendingStates.\n\t\t */\n\t\tstaged: boolean;\n\t};\n}\n\ntype Patch<T, U> = U & Omit<T, keyof U>;\n\n/**\n * First version of the type (pre-dates batchInfo)\n */\ntype IPendingMessageV0 = Patch<IPendingMessage, { batchInfo?: undefined }>;\n\n/**\n * Union of all supported schemas for when applying stashed ops\n *\n * @remarks When the format changes, this type should update to reflect all possible schemas.\n */\ntype IPendingMessageFromStash = IPendingMessageV0 | IPendingMessage;\n\nexport interface IPendingLocalState {\n\t/**\n\t * list of pending states, including ops and batch information\n\t */\n\tpendingStates: IPendingMessage[];\n}\n\n/**\n * Info needed to replay/resubmit a pending message\n */\nexport type PendingMessageResubmitData = Pick<\n\tIPendingMessage,\n\t\"runtimeOp\" | \"localOpMetadata\" | \"opMetadata\"\n> & {\n\t// Required (it's only missing on IPendingMessage for empty batch, which will be resubmitted as an empty array)\n\truntimeOp: LocalContainerRuntimeMessage;\n};\n\nexport interface PendingBatchResubmitMetadata extends BatchResubmitInfo {\n\t/**\n\t * Whether changes in this batch should be squashed when resubmitting.\n\t */\n\tsquash: boolean;\n}\n\nexport interface IRuntimeStateHandler {\n\tconnected(): boolean;\n\tclientId(): string | undefined;\n\tapplyStashedOp(serializedOp: string): Promise<unknown>;\n\treSubmitBatch(\n\t\tbatch: PendingMessageResubmitData[],\n\t\tmetadata: PendingBatchResubmitMetadata,\n\t): void;\n\tisActiveConnection: () => boolean;\n\tisAttached: () => boolean;\n}\n\nfunction isEmptyBatchPendingMessage(message: IPendingMessageFromStash): boolean {\n\tconst content = JSON.parse(message.content) as Partial<EmptyGroupedBatch>;\n\treturn content.type === \"groupedBatch\" && content.contents?.length === 0;\n}\n\nfunction buildPendingMessageContent(message: InboundSequencedContainerRuntimeMessage): string {\n\t// IMPORTANT: Order matters here, this must match the order of the properties used\n\t// when submitting the message.\n\tconst { type, contents }: InboundContainerRuntimeMessage = message;\n\t// Any properties that are not defined, won't be emitted by stringify.\n\treturn JSON.stringify({ type, contents });\n}\n\nfunction typesOfKeys<T extends object>(obj: T): Record<keyof T, string> {\n\treturn Object.keys(obj).reduce((acc, key) => {\n\t\tacc[key] = typeof obj[key];\n\t\treturn acc;\n\t}, {}) as Record<keyof T, string>;\n}\n\nfunction scrubAndStringify(\n\tmessage: InboundContainerRuntimeMessage | LocalContainerRuntimeMessage,\n): string {\n\t// Scrub the whole object in case there are unexpected keys\n\tconst scrubbed: Record<string, unknown> = typesOfKeys(message);\n\n\t// For these known/expected keys, we can either drill into the object (for contents)\n\t// or just use the value as-is (since it's not personal info)\n\tscrubbed.contents = message.contents && typesOfKeys(message.contents);\n\tscrubbed.type = message.type;\n\n\treturn JSON.stringify(scrubbed);\n}\n\n/**\n * Finds and returns the index where the strings diverge, and the character at that index in each string (or undefined if not applicable)\n */\nfunction findFirstRawCharacterMismatched(\n\ta: string,\n\tb: string,\n): [index: number, charA?: string, charB?: string] {\n\tconst minLength = Math.min(a.length, b.length);\n\tfor (let i = 0; i < minLength; i++) {\n\t\tif (a[i] !== b[i]) {\n\t\t\treturn [i, a[i], b[i]];\n\t\t}\n\t}\n\n\t// Since we didn't return in the loop, the shorter string must be a prefix of the other.\n\t// If they're the same length, return -1 to indicate they're identical.\n\t// Otherwise, the next character of the longer one is where they differ. No need to return that next character.\n\treturn a.length === b.length\n\t\t? [-1, undefined, undefined]\n\t\t: [minLength, a[minLength], b[minLength]];\n}\n\n/**\n * Finds and returns the index where the strings diverge, and the character at that index in each string (or undefined if not applicable)\n * It scrubs non-ASCII characters since they convey more meaning (privacy consideration)\n */\nexport function findFirstCharacterMismatched(\n\ta: string,\n\tb: string,\n): [index: number, charA?: string, charB?: string] {\n\tconst [index, rawCharA, rawCharB] = findFirstRawCharacterMismatched(a, b);\n\n\tconst charA = (rawCharA?.codePointAt(0) ?? 0) <= 0x7f ? rawCharA : \"[non-ASCII]\";\n\tconst charB = (rawCharB?.codePointAt(0) ?? 0) <= 0x7f ? rawCharB : \"[non-ASCII]\";\n\n\treturn [index, charA, charB];\n}\n\n/**\n * Returns a shallow copy of the given message with the non-serializable properties removed.\n * Note that the runtimeOp's data has already been serialized in the content property.\n */\nfunction toSerializableForm(\n\tmessage: IPendingMessage,\n): IPendingMessage & { runtimeOp: undefined; localOpMetadata: undefined } {\n\treturn {\n\t\t...message,\n\t\tlocalOpMetadata: undefined,\n\t\truntimeOp: undefined,\n\t};\n}\n\ninterface ReplayPendingStateOptions {\n\t/**\n\t * If true, only replay staged batches, clearing the \"staged\" flag.\n\t * This is used when we are exiting staging mode and want to rebase and submit the staged batches without resubmitting pre-staged messages.\n\t * Default: false\n\t */\n\tcommittingStagedBatches: boolean;\n\t/**\n\t * @param squash - If true, edits should be squashed when resubmitting.\n\t * Default: false\n\t */\n\tsquash: boolean;\n}\n\nconst defaultReplayPendingStatesOptions: ReplayPendingStateOptions = {\n\tcommittingStagedBatches: false,\n\tsquash: false,\n};\n\n/**\n * PendingStateManager is responsible for maintaining the messages that have not been sent or have not yet been\n * acknowledged by the server. It also maintains the batch information for both automatically and manually flushed\n * batches along with the messages.\n * When the Container reconnects, it replays the pending states, which includes manual flushing\n * of messages and triggering resubmission of unacked ops.\n *\n * It verifies that all the ops are acked, are received in the right order and batch information is correct.\n */\nexport class PendingStateManager implements IDisposable {\n\t/**\n\t * Messages that will need to be resubmitted if not ack'd before the next reconnection\n\t */\n\tprivate readonly pendingMessages = new Deque<IPendingMessage>();\n\t/**\n\t * Messages stashed from a previous container, now being rehydrated. Need to be resubmitted.\n\t */\n\tprivate readonly initialMessages = new Deque<IPendingMessageFromStash>();\n\n\t/**\n\t * Sequenced local ops that are saved when stashing since pending ops may depend on them\n\t */\n\tprivate savedOps: IPendingMessage[] = [];\n\n\t// eslint-disable-next-line unicorn/consistent-function-scoping -- Property is defined once; no need to extract inner lambda\n\tprivate readonly disposeOnce = new Lazy<void>(() => {\n\t\tthis.initialMessages.clear();\n\t\tthis.pendingMessages.clear();\n\t});\n\n\t/**\n\t * Used to ensure we don't replay ops on the same connection twice\n\t */\n\tprivate clientIdFromLastReplay: string | undefined;\n\n\t/**\n\t * The pending messages count. Includes `pendingMessages` and `initialMessages` to keep in sync with\n\t * 'hasPendingMessages'.\n\t */\n\tpublic get pendingMessagesCount(): number {\n\t\treturn this.pendingMessages.length + this.initialMessages.length;\n\t}\n\n\t/**\n\t * Checks the pending messages to see if any of them represent user changes (aka \"dirtyable\" messages)\n\t */\n\tpublic hasPendingUserChanges(): boolean {\n\t\tfor (let i = 0; i < this.pendingMessages.length; i++) {\n\t\t\tconst element = this.pendingMessages.get(i);\n\t\t\tif (\n\t\t\t\telement !== undefined &&\n\t\t\t\thasTypicalRuntimeOp(element) && // Empty batches don't count towards user changes\n\t\t\t\tisContainerMessageDirtyable(element.runtimeOp)\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\t// Consider any initial messages to be user changes\n\t\t// (it's an approximation since we would have to parse them to know for sure)\n\t\treturn this.initialMessages.length > 0;\n\t}\n\n\t/**\n\t * The minimumPendingMessageSequenceNumber is the minimum of the first pending message and the first initial message.\n\t *\n\t * We need this so that we can properly keep local data and maintain the correct sequence window.\n\t */\n\tpublic get minimumPendingMessageSequenceNumber(): number | undefined {\n\t\treturn this.pendingMessages.peekFront()?.referenceSequenceNumber;\n\t}\n\n\t/**\n\t * Called to check if there are any pending messages in the pending message queue.\n\t * @returns A boolean indicating whether there are messages or not.\n\t */\n\tpublic hasPendingMessages(): boolean {\n\t\treturn this.pendingMessagesCount !== 0;\n\t}\n\n\tpublic getLocalState(snapshotSequenceNumber?: number): IPendingLocalState {\n\t\tassert(\n\t\t\tthis.initialMessages.isEmpty(),\n\t\t\t0x2e9 /* \"Must call getLocalState() after applying initial states\" */,\n\t\t);\n\t\t// Using snapshot sequence number to filter ops older than our latest snapshot.\n\t\t// Such ops should not be declared in pending/stashed state. Snapshot seq num will not\n\t\t// be available when the container is not attached. Therefore, no filtering is needed.\n\t\tconst newSavedOps = [...this.savedOps].filter((message) => {\n\t\t\tassert(\n\t\t\t\tmessage.sequenceNumber !== undefined,\n\t\t\t\t0x97c /* saved op should already have a sequence number */,\n\t\t\t);\n\t\t\treturn message.sequenceNumber > (snapshotSequenceNumber ?? 0);\n\t\t});\n\t\tfor (const message of this.pendingMessages.toArray()) {\n\t\t\tif (\n\t\t\t\tsnapshotSequenceNumber !== undefined &&\n\t\t\t\tmessage.referenceSequenceNumber < snapshotSequenceNumber\n\t\t\t) {\n\t\t\t\tthrow new LoggingError(\"trying to stash ops older than our latest snapshot\");\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tpendingStates: [\n\t\t\t\t...newSavedOps,\n\t\t\t\t...this.pendingMessages.toArray().map((message) => toSerializableForm(message)),\n\t\t\t],\n\t\t};\n\t}\n\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tconstructor(\n\t\tprivate readonly stateHandler: IRuntimeStateHandler,\n\t\tstashedLocalState: IPendingLocalState | undefined,\n\t\tlogger: ITelemetryBaseLogger,\n\t) {\n\t\tthis.logger = createChildLogger({ logger });\n\t\tif (stashedLocalState?.pendingStates) {\n\t\t\tthis.initialMessages.push(...stashedLocalState.pendingStates);\n\t\t}\n\t}\n\n\tpublic get disposed(): boolean {\n\t\treturn this.disposeOnce.evaluated;\n\t}\n\tpublic readonly dispose = (): void => this.disposeOnce.value;\n\n\t/**\n\t * We've flushed an empty batch, and need to track it locally until the corresponding\n\t * ack is processed, to properly track batch IDs\n\t */\n\tpublic onFlushEmptyBatch(\n\t\tplaceholder: LocalEmptyBatchPlaceholder,\n\t\tclientSequenceNumber: number | undefined,\n\t\tstaged: boolean,\n\t): void {\n\t\tthis.onFlushBatch([placeholder], clientSequenceNumber, staged);\n\t}\n\n\t/**\n\t * The given batch has been flushed, and needs to be tracked locally until the corresponding\n\t * acks are processed, to ensure it is successfully sent.\n\t * @param batch - The batch that was flushed\n\t * @param clientSequenceNumber - The CSN of the first message in the batch,\n\t * or undefined if the batch was not yet sent (e.g. by the time we flushed we lost the connection)\n\t * @param staged - Indicates whether batch is staged (not to be submitted while runtime is in Staging Mode)\n\t * @param ignoreBatchId - Whether to ignore the batchId in the batchStartInfo\n\t */\n\tpublic onFlushBatch(\n\t\tbatch: LocalBatchMessage[] | [LocalEmptyBatchPlaceholder],\n\t\tclientSequenceNumber: number | undefined,\n\t\tstaged: boolean,\n\t\tignoreBatchId?: boolean,\n\t): void {\n\t\t// clientId and batchStartCsn are used for generating the batchId so we can detect container forks\n\t\t// where this batch was submitted by two different clients rehydrating from the same local state.\n\t\t// In the typical case where the batch was actually sent, use the clientId and clientSequenceNumber.\n\t\t// In the case where the batch was not sent, use a random uuid for clientId, and -1 for clientSequenceNumber to indicate this case.\n\t\t// This will guarantee uniqueness of the batchId, and is a suitable fallback since clientId/CSN is only needed if the batch was actually sent/sequenced.\n\t\tconst batchWasSent = clientSequenceNumber !== undefined;\n\t\tif (batchWasSent) {\n\t\t\tassert(!staged, 0xb84 /* Staged batches should not have been submitted */);\n\t\t}\n\t\tconst [clientId, batchStartCsn] = batchWasSent\n\t\t\t? [this.stateHandler.clientId(), clientSequenceNumber]\n\t\t\t: [uuid(), -1]; // -1 will indicate not a real clientId/CSN pair\n\t\tassert(\n\t\t\tclientId !== undefined,\n\t\t\t0xa33 /* clientId (from stateHandler) could only be undefined if we've never connected, but we have a CSN so we know that's not the case */,\n\t\t);\n\n\t\tfor (const message of batch) {\n\t\t\tconst {\n\t\t\t\truntimeOp,\n\t\t\t\treferenceSequenceNumber,\n\t\t\t\tlocalOpMetadata,\n\t\t\t\tmetadata: opMetadata,\n\t\t\t} = message;\n\t\t\tconst pendingMessage: IPendingMessage = {\n\t\t\t\ttype: \"message\",\n\t\t\t\treferenceSequenceNumber,\n\t\t\t\tcontent: serializeOp(runtimeOp),\n\t\t\t\truntimeOp,\n\t\t\t\tlocalOpMetadata,\n\t\t\t\topMetadata,\n\t\t\t\t// Note: We only will read this off the first message, but put it on all for simplicity\n\t\t\t\tbatchInfo: { clientId, batchStartCsn, length: batch.length, ignoreBatchId, staged },\n\t\t\t};\n\t\t\tthis.pendingMessages.push(pendingMessage);\n\t\t}\n\t}\n\n\t/**\n\t * Applies stashed ops at their reference sequence number so they are ready to be ACKed or resubmitted\n\t * @param seqNum - Sequence number at which to apply ops. Will apply all ops if seqNum is undefined.\n\t */\n\tpublic async applyStashedOpsAt(seqNum?: number): Promise<void> {\n\t\t// apply stashed ops at sequence number\n\t\twhile (!this.initialMessages.isEmpty()) {\n\t\t\tif (seqNum !== undefined) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst peekMessage = this.initialMessages.peekFront()!;\n\t\t\t\tif (peekMessage.referenceSequenceNumber > seqNum) {\n\t\t\t\t\tbreak; // nothing left to do at this sequence number\n\t\t\t\t}\n\t\t\t\tif (peekMessage.referenceSequenceNumber < seqNum) {\n\t\t\t\t\tthrow new Error(\"loaded from snapshot too recent to apply stashed ops\");\n\t\t\t\t}\n\t\t\t}\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst nextMessage = this.initialMessages.shift()!;\n\t\t\t// Nothing to apply if the message is an empty batch.\n\t\t\t// We still need to track it for resubmission.\n\t\t\ttry {\n\t\t\t\tif (isEmptyBatchPendingMessage(nextMessage)) {\n\t\t\t\t\tnextMessage.localOpMetadata = {\n\t\t\t\t\t\temptyBatch: true,\n\t\t\t\t\t} satisfies LocalEmptyBatchPlaceholder[\"localOpMetadata\"]; // equivalent to applyStashedOp for empty batch\n\t\t\t\t\tpatchbatchInfo(nextMessage); // Back compat\n\t\t\t\t\tthis.pendingMessages.push(nextMessage);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// applyStashedOp will cause the DDS to behave as if it has sent the op but not actually send it\n\t\t\t\tconst localOpMetadata = await this.stateHandler.applyStashedOp(nextMessage.content);\n\t\t\t\tif (this.stateHandler.isAttached()) {\n\t\t\t\t\tnextMessage.localOpMetadata = localOpMetadata;\n\t\t\t\t\t// NOTE: This runtimeOp has been roundtripped through string, which is technically lossy.\n\t\t\t\t\t// e.g. At this point, handles are in their encoded form.\n\t\t\t\t\tnextMessage.runtimeOp = JSON.parse(\n\t\t\t\t\t\tnextMessage.content,\n\t\t\t\t\t) as LocalContainerRuntimeMessage;\n\t\t\t\t\t// then we push onto pendingMessages which will cause PendingStateManager to resubmit when we connect\n\t\t\t\t\tpatchbatchInfo(nextMessage); // Back compat\n\t\t\t\t\tthis.pendingMessages.push(nextMessage);\n\t\t\t\t} else {\n\t\t\t\t\tif (localOpMetadata !== undefined) {\n\t\t\t\t\t\tthrow new Error(\"Local Op Metadata must be undefined when not attached\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthrow DataProcessingError.wrapIfUnrecognized(error, \"applyStashedOp\", nextMessage);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Compares the batch ID of the incoming batch with the pending batch ID for this client.\n\t * They should not match, as that would indicate a forked container.\n\t * @param remoteBatchStart - BatchStartInfo for an incoming batch *NOT* submitted by this client\n\t * @returns whether the batch IDs match\n\t */\n\tprivate remoteBatchMatchesPendingBatch(remoteBatchStart: BatchStartInfo): boolean {\n\t\t// Find the first pending message that uses Batch ID, to compare to the incoming remote batch.\n\t\t// If there is no such message, then the incoming remote batch doesn't have a match here and we can return.\n\t\tconst firstIndexUsingBatchId = Array.from({\n\t\t\tlength: this.pendingMessages.length,\n\t\t}).findIndex((_, i) => this.pendingMessages.get(i)?.batchInfo.ignoreBatchId !== true);\n\t\tconst pendingMessageUsingBatchId =\n\t\t\tfirstIndexUsingBatchId === -1\n\t\t\t\t? undefined\n\t\t\t\t: this.pendingMessages.get(firstIndexUsingBatchId);\n\n\t\tif (pendingMessageUsingBatchId === undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// We must compare the effective batch IDs, since one of these ops\n\t\t// may have been the original, not resubmitted, so wouldn't have its batch ID stamped yet.\n\t\tconst pendingBatchId = getEffectiveBatchId(pendingMessageUsingBatchId);\n\t\tconst inboundBatchId = getEffectiveBatchId(remoteBatchStart);\n\n\t\treturn pendingBatchId === inboundBatchId;\n\t}\n\n\t/**\n\t * Processes an inbound message or batch of messages - May be local or remote.\n\t *\n\t * @param inbound - The inbound message(s) to process, with extra info (e.g. about the start of a batch). Could be local or remote.\n\t * @param local - true if we submitted these messages and expect corresponding pending messages\n\t * @returns The inbound messages with localOpMetadata \"zipped\" in.\n\t *\n\t * @throws a DataProcessingError in either of these cases:\n\t * - The pending message content doesn't match the incoming message content for any message here\n\t * - The batch IDs *do match* but it's not local (indicates Container forking).\n\t */\n\tpublic processInboundMessages(\n\t\tinbound: InboundMessageResult,\n\t\tlocal: boolean,\n\t): {\n\t\tmessage: InboundSequencedContainerRuntimeMessage;\n\t\tlocalOpMetadata?: unknown;\n\t}[] {\n\t\tif (local) {\n\t\t\treturn this.processPendingLocalMessages(inbound);\n\t\t}\n\n\t\t// An inbound remote batch should not match the pending batch ID for this client.\n\t\t// That would indicate the container forked (two instances trying to submit the same local state)\n\t\tif (\"batchStart\" in inbound && this.remoteBatchMatchesPendingBatch(inbound.batchStart)) {\n\t\t\tthrow DataProcessingError.create(\n\t\t\t\t\"Forked Container Error! Matching batchIds but mismatched clientId\",\n\t\t\t\t\"PendingStateManager.processInboundMessages\",\n\t\t\t\tinbound.batchStart.keyMessage,\n\t\t\t);\n\t\t}\n\n\t\t// No localOpMetadata for remote messages\n\t\tconst messages = inbound.type === \"fullBatch\" ? inbound.messages : [inbound.nextMessage];\n\t\treturn messages.map((message) => ({ message }));\n\t}\n\n\t/**\n\t * Processes the incoming message(s) from the server that were submitted by this client.\n\t * It verifies that messages are received in the right order and that any batch information is correct.\n\t * @param inbound - The inbound message(s) (originating from this client) to correlate with the pending local state\n\t * @throws DataProcessingError if the pending message content doesn't match the incoming message content for any message here\n\t * @returns The inbound messages with localOpMetadata \"zipped\" in.\n\t */\n\tprivate processPendingLocalMessages(inbound: InboundMessageResult): {\n\t\tmessage: InboundSequencedContainerRuntimeMessage;\n\t\tlocalOpMetadata: unknown;\n\t}[] {\n\t\tif (\"batchStart\" in inbound) {\n\t\t\tthis.onLocalBatchBegin(inbound.batchStart, inbound.length);\n\t\t}\n\n\t\t// Empty batch\n\t\tif (inbound.length === 0) {\n\t\t\tconst localOpMetadata = this.processNextPendingMessage(\n\t\t\t\tinbound.batchStart.keyMessage.sequenceNumber,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\tasEmptyBatchLocalOpMetadata(localOpMetadata)?.emptyBatch === true,\n\t\t\t\t0xa20 /* Expected empty batch marker */,\n\t\t\t);\n\t\t\treturn [];\n\t\t}\n\n\t\tconst messages = inbound.type === \"fullBatch\" ? inbound.messages : [inbound.nextMessage];\n\n\t\treturn messages.map((message) => ({\n\t\t\tmessage,\n\t\t\tlocalOpMetadata: this.processNextPendingMessage(message.sequenceNumber, message),\n\t\t}));\n\t}\n\n\t/**\n\t * Processes the pending local copy of message that's been ack'd by the server.\n\t * @param sequenceNumber - The sequenceNumber from the server corresponding to the next pending message.\n\t * @param message - [optional] The entire incoming message, for comparing contents with the pending message for extra validation.\n\t * @throws DataProcessingError if the pending message content doesn't match the incoming message content.\n\t * @returns - The localOpMetadata of the next pending message, to be sent to whoever submitted the original message.\n\t */\n\tprivate processNextPendingMessage(\n\t\tsequenceNumber: number,\n\t\tmessage?: InboundSequencedContainerRuntimeMessage,\n\t): unknown {\n\t\tconst pendingMessage = this.pendingMessages.peekFront();\n\t\tassert(\n\t\t\tpendingMessage !== undefined,\n\t\t\t0x169 /* \"No pending message found for this remote message\" */,\n\t\t);\n\n\t\tpendingMessage.sequenceNumber = sequenceNumber;\n\t\tthis.savedOps.push(toSerializableForm(pendingMessage));\n\n\t\tthis.pendingMessages.shift();\n\n\t\t// message is undefined in the Empty Batch case,\n\t\t// because we don't have an incoming message to compare and pendingMessage is just a placeholder anyway.\n\t\tif (message !== undefined) {\n\t\t\tconst messageContent = buildPendingMessageContent(message);\n\n\t\t\t// Stringified content should match\n\t\t\t// If it doesn't, collect as much info about the difference as possible (privacy-wise) and log it\n\t\t\tif (pendingMessage.content !== messageContent) {\n\t\t\t\tconst [pendingLength, incomingLength] = [\n\t\t\t\t\tpendingMessage.content.length,\n\t\t\t\t\tmessageContent.length,\n\t\t\t\t];\n\t\t\t\tconst [mismatchStartIndex, pendingChar, incomingChar] = findFirstCharacterMismatched(\n\t\t\t\t\tpendingMessage.content,\n\t\t\t\t\tmessageContent,\n\t\t\t\t);\n\n\t\t\t\tconst pendingContentObj = JSON.parse(\n\t\t\t\t\tpendingMessage.content,\n\t\t\t\t) as LocalContainerRuntimeMessage;\n\t\t\t\tconst incomingContentObj = JSON.parse(\n\t\t\t\t\tmessageContent,\n\t\t\t\t) as InboundContainerRuntimeMessage;\n\n\t\t\t\t// Compare inner contents object, since that both should be { type, contents }\n\t\t\t\tconst contentsMatch =\n\t\t\t\t\tpendingContentObj.contents === incomingContentObj.contents ||\n\t\t\t\t\t(pendingContentObj.contents !== undefined &&\n\t\t\t\t\t\tincomingContentObj.contents !== undefined &&\n\t\t\t\t\t\tJSON.stringify(pendingContentObj.contents) ===\n\t\t\t\t\t\t\tJSON.stringify(incomingContentObj.contents));\n\n\t\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"unexpectedAckReceived\",\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tpendingContentScrubbed: scrubAndStringify(pendingContentObj),\n\t\t\t\t\t\tincomingContentScrubbed: scrubAndStringify(incomingContentObj),\n\t\t\t\t\t\tcontentsMatch,\n\t\t\t\t\t\tpendingLength,\n\t\t\t\t\t\tincomingLength,\n\t\t\t\t\t\tmismatchStartIndex,\n\t\t\t\t\t\tpendingChar,\n\t\t\t\t\t\tincomingChar,\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\tthrow DataProcessingError.create(\n\t\t\t\t\t\"pending local message content mismatch\",\n\t\t\t\t\t\"unexpectedAckReceived\",\n\t\t\t\t\tmessage,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn pendingMessage.localOpMetadata;\n\t}\n\n\t/**\n\t * Check if the incoming batch matches the batch info for the next pending message.\n\t */\n\tprivate onLocalBatchBegin(batchStart: BatchStartInfo, batchLength?: number): void {\n\t\t// Get the next message from the pending queue. Verify a message exists.\n\t\tconst pendingMessage = this.pendingMessages.peekFront();\n\t\tassert(\n\t\t\tpendingMessage !== undefined,\n\t\t\t0xa21 /* No pending message found as we start processing this remote batch */,\n\t\t);\n\t\tassert(\n\t\t\t!pendingMessage.batchInfo.staged,\n\t\t\t0xb85 /* Pending state mismatch, ack came in but next pending message is staged */,\n\t\t);\n\n\t\t// If this batch became empty on resubmit, batch.messages will be empty (but keyMessage is always set)\n\t\t// and the next pending message should be an empty batch marker.\n\t\t// More Info: We must submit empty batches and track them in case a different fork\n\t\t// of this container also submitted the same batch (and it may not be empty for that fork).\n\t\tconst firstMessage = batchStart.keyMessage;\n\t\t// -1 length is for back compat, undefined length means we actually don't know it\n\t\tconst skipLengthCheck =\n\t\t\tpendingMessage.batchInfo.length === -1 || batchLength === undefined;\n\t\tconst expectedPendingBatchLength =\n\t\t\tbatchLength === 0\n\t\t\t\t? 1 // For an empty batch, expect a singleton array with the empty batch marker\n\t\t\t\t: batchLength; // Otherwise, the lengths should actually match\n\n\t\t// Note: We don't need to use getEffectiveBatchId here, just check the explicit stamped batchID\n\t\t// That logic is needed only when comparing across potential container forks.\n\t\t// Furthermore, we also are comparing the batch IDs constituent data - clientId (it's local) and batchStartCsn.\n\t\tconst pendingBatchId = asBatchMetadata(pendingMessage.opMetadata)?.batchId;\n\t\tconst inboundBatchId = batchStart.batchId;\n\n\t\t// We expect the incoming batch to be of the same length, starting at the same clientSequenceNumber,\n\t\t// as the batch we originally submitted. The batchIds should match as well, if set (or neither should be set)\n\t\t// We have another later check to compare the message contents, which we'd expect to fail if this check does,\n\t\t// so we don't throw here, merely log. In a later release this check may replace that one since it's cheaper.\n\t\tif (\n\t\t\tpendingMessage.batchInfo.batchStartCsn !== batchStart.batchStartCsn ||\n\t\t\t(!skipLengthCheck && pendingMessage.batchInfo.length !== expectedPendingBatchLength) ||\n\t\t\tpendingBatchId !== inboundBatchId\n\t\t) {\n\t\t\tthis.logger?.sendErrorEvent({\n\t\t\t\teventName: \"BatchInfoMismatch\",\n\t\t\t\tdetails: {\n\t\t\t\t\tpendingBatchCsn: pendingMessage.batchInfo.batchStartCsn,\n\t\t\t\t\tbatchStartCsn: batchStart.batchStartCsn,\n\t\t\t\t\tpendingBatchLength: pendingMessage.batchInfo.length,\n\t\t\t\t\texpectedPendingBatchLength,\n\t\t\t\t\tbatchLength,\n\t\t\t\t\tpendingBatchId,\n\t\t\t\t\tinboundBatchId,\n\t\t\t\t\tpendingMessageBatchMetadata: asBatchMetadata(pendingMessage.opMetadata)?.batch,\n\t\t\t\t\tmessageBatchMetadata: asBatchMetadata(firstMessage?.metadata)?.batch,\n\t\t\t\t},\n\t\t\t\tmessageDetails: firstMessage && extractSafePropertiesFromMessage(firstMessage),\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Called when the Container's connection state changes. If the Container gets connected, it replays all the pending\n\t * states in its queue. This includes triggering resubmission of unacked ops.\n\t * ! Note: successfully resubmitting an op that has been successfully sequenced is not possible due to checks in the ConnectionStateHandler (Loader layer)\n\t */\n\tpublic replayPendingStates(options?: ReplayPendingStateOptions): void {\n\t\tconst { committingStagedBatches, squash } = {\n\t\t\t...defaultReplayPendingStatesOptions,\n\t\t\t...options,\n\t\t};\n\t\tassert(\n\t\t\tthis.stateHandler.connected() || committingStagedBatches === true,\n\t\t\t0x172 /* \"The connection state is not consistent with the runtime\" */,\n\t\t);\n\n\t\t// Staged batches have not yet been submitted so check doesn't apply\n\t\tif (!committingStagedBatches) {\n\t\t\t// This assert suggests we are about to send same ops twice, which will result in data loss.\n\t\t\tassert(\n\t\t\t\tthis.clientIdFromLastReplay !== this.stateHandler.clientId(),\n\t\t\t\t0x173 /* \"replayPendingStates called twice for same clientId!\" */,\n\t\t\t);\n\t\t}\n\t\tthis.clientIdFromLastReplay = this.stateHandler.clientId();\n\n\t\tassert(\n\t\t\tthis.initialMessages.isEmpty(),\n\t\t\t0x174 /* \"initial states should be empty before replaying pending\" */,\n\t\t);\n\n\t\tconst initialPendingMessagesCount = this.pendingMessages.length;\n\t\tlet remainingPendingMessagesCount = this.pendingMessages.length;\n\n\t\tlet seenStagedBatch = false;\n\n\t\t// Process exactly `pendingMessagesCount` items in the queue as it represents the number of messages that were\n\t\t// pending when we connected. This is important because the `reSubmitFn` might add more items in the queue\n\t\t// which must not be replayed.\n\t\twhile (remainingPendingMessagesCount > 0) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tlet pendingMessage = this.pendingMessages.shift()!;\n\t\t\tremainingPendingMessagesCount--;\n\n\t\t\t// Re-queue pre-staging messages - we are only to replay staged batches\n\t\t\tif (committingStagedBatches) {\n\t\t\t\tif (!pendingMessage.batchInfo.staged) {\n\t\t\t\t\tassert(!seenStagedBatch, 0xb86 /* Staged batch was followed by non-staged batch */);\n\t\t\t\t\tthis.pendingMessages.push(pendingMessage);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tseenStagedBatch = true;\n\t\t\t\tpendingMessage.batchInfo.staged = false; // Clear staged flag so we can submit\n\t\t\t}\n\n\t\t\tconst batchMetadataFlag = asBatchMetadata(pendingMessage.opMetadata)?.batch;\n\t\t\tassert(batchMetadataFlag !== false, 0x41b /* We cannot process batches in chunks */);\n\n\t\t\t// The next message starts a batch (possibly single-message), and we'll need its batchId.\n\t\t\tconst batchId = pendingMessage.batchInfo.ignoreBatchId\n\t\t\t\t? undefined\n\t\t\t\t: getEffectiveBatchId(pendingMessage);\n\n\t\t\tconst staged = pendingMessage.batchInfo.staged;\n\n\t\t\tif (asEmptyBatchLocalOpMetadata(pendingMessage.localOpMetadata)?.emptyBatch === true) {\n\t\t\t\t// Resubmit no messages, with the batchId. Will result in another empty batch marker.\n\t\t\t\tthis.stateHandler.reSubmitBatch([], { batchId, staged, squash });\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tassert(\n\t\t\t\thasTypicalRuntimeOp(pendingMessage),\n\t\t\t\t0xb87 /* runtimeOp is only undefined for empty batches */,\n\t\t\t);\n\n\t\t\t/**\n\t\t\t * We must preserve the distinct batches on resubmit.\n\t\t\t * Note: It is not possible for the PendingStateManager to receive a partially acked batch. It will\n\t\t\t * either receive the whole batch ack or nothing at all. See {@link InboundBatchAggregator} for how this works.\n\t\t\t */\n\t\t\tif (batchMetadataFlag === undefined) {\n\t\t\t\t// Single-message batch\n\n\t\t\t\tthis.stateHandler.reSubmitBatch(\n\t\t\t\t\t[\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\truntimeOp: pendingMessage.runtimeOp,\n\t\t\t\t\t\t\tlocalOpMetadata: pendingMessage.localOpMetadata,\n\t\t\t\t\t\t\topMetadata: pendingMessage.opMetadata,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\t{ batchId, staged, squash },\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// else: batchMetadataFlag === true (It's a typical multi-message batch)\n\n\t\t\tassert(\n\t\t\t\tremainingPendingMessagesCount > 0,\n\t\t\t\t0x554 /* Last pending message cannot be a batch begin */,\n\t\t\t);\n\n\t\t\tconst batch: PendingMessageResubmitData[] = [];\n\n\t\t\t// check is >= because batch end may be last pending message\n\t\t\twhile (remainingPendingMessagesCount >= 0) {\n\t\t\t\tassert(\n\t\t\t\t\thasTypicalRuntimeOp(pendingMessage),\n\t\t\t\t\t0xb88 /* runtimeOp is only undefined for empty batches */,\n\t\t\t\t);\n\t\t\t\tbatch.push({\n\t\t\t\t\truntimeOp: pendingMessage.runtimeOp,\n\t\t\t\t\tlocalOpMetadata: pendingMessage.localOpMetadata,\n\t\t\t\t\topMetadata: pendingMessage.opMetadata,\n\t\t\t\t});\n\n\t\t\t\t// End of the batch\n\t\t\t\tif (pendingMessage.opMetadata?.batch === false) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tassert(remainingPendingMessagesCount > 0, 0x555 /* No batch end found */);\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tpendingMessage = this.pendingMessages.shift()!;\n\t\t\t\tremainingPendingMessagesCount--;\n\t\t\t\tassert(\n\t\t\t\t\tpendingMessage.opMetadata?.batch !== true,\n\t\t\t\t\t0x556 /* Batch start needs a corresponding batch end */,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.stateHandler.reSubmitBatch(batch, { batchId, staged, squash });\n\t\t}\n\n\t\tif (!committingStagedBatches) {\n\t\t\t// pending ops should no longer depend on previous sequenced local ops after resubmitting all pending messages (does not apply if only replaying the staged messages)\n\t\t\tthis.savedOps = [];\n\t\t}\n\n\t\t// We replayPendingStates on read connections too - we expect these to get nack'd though, and to then reconnect\n\t\t// on a write connection and replay again. This filters out the replay that happens on the read connection so\n\t\t// we only see the replays on write connections (that have a chance to go through).\n\t\tif (this.stateHandler.isActiveConnection()) {\n\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\teventName: \"PendingStatesReplayed\",\n\t\t\t\tcount: initialPendingMessagesCount,\n\t\t\t\tclientId: this.stateHandler.clientId(),\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Pops all staged batches, invoking the callback on each constituent op in order (LIFO)\n\t */\n\tpublic popStagedBatches(\n\t\tcallback: (\n\t\t\t// callback will only be given staged messages with a valid runtime op (i.e. not empty batch and not an initial message with only serialized content)\n\t\t\tstagedMessage: IPendingMessage & { runtimeOp: LocalContainerRuntimeMessage },\n\t\t) => void,\n\t): void {\n\t\twhile (!this.pendingMessages.isEmpty()) {\n\t\t\tconst stagedMessage = this.pendingMessages.peekBack();\n\t\t\tif (stagedMessage?.batchInfo.staged === true) {\n\t\t\t\tthis.pendingMessages.pop();\n\n\t\t\t\tif (hasTypicalRuntimeOp(stagedMessage)) {\n\t\t\t\t\tcallback(stagedMessage);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tbreak; // no more staged messages\n\t\t\t}\n\t\t}\n\t\tassert(\n\t\t\tthis.pendingMessages.toArray().every((m) => m.batchInfo.staged !== true),\n\t\t\t0xb89 /* Shouldn't be any more staged messages */,\n\t\t);\n\t}\n}\n\n/**\n * For back-compat if trying to apply stashed ops that pre-date batchInfo\n */\nfunction patchbatchInfo(\n\tmessage: IPendingMessageFromStash,\n): asserts message is IPendingMessage {\n\tconst batchInfo: IPendingMessageFromStash[\"batchInfo\"] = message.batchInfo;\n\tif (batchInfo === undefined) {\n\t\t// Using uuid guarantees uniqueness, retaining existing behavior\n\t\tmessage.batchInfo = { clientId: uuid(), batchStartCsn: -1, length: -1, staged: false };\n\t}\n}\n\n/**\n * This filters out messages that are not \"typical\" runtime ops, i.e. empty batches or initial messages (which only have serialized content).\n */\nfunction hasTypicalRuntimeOp(\n\tmessage: IPendingMessage,\n): message is IPendingMessage & { runtimeOp: LocalContainerRuntimeMessage } {\n\treturn message.runtimeOp !== undefined && message.runtimeOp.type !== \"groupedBatch\";\n}\n"]}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { TypedEventEmitter } from "@fluid-internal/client-utils";
|
|
7
7
|
import { assert } from "@fluidframework/core-utils/internal";
|
|
8
8
|
import { UsageError, createChildLogger, } from "@fluidframework/telemetry-utils/internal";
|
|
9
|
-
import { summarizerClientType } from "./
|
|
9
|
+
import { summarizerClientType } from "./summarizerTypes.js";
|
|
10
10
|
/**
|
|
11
11
|
* Tracks clients in the Quorum. It maintains their order using their join op
|
|
12
12
|
* sequence numbers.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orderedClientElection.js","sourceRoot":"","sources":["../../src/summary/orderedClientElection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,2CAA2C;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAGjE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EAEN,UAAU,EACV,iBAAiB,GACjB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAoFlD;;;;;;GAMG;AACH,MAAM,OAAO,uBACZ,SAAQ,iBAAiD;IAqBzD,IAAW,KAAK;QACf,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;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AAI,CAAC,uBAAuB,CAAC,YAAY,CAAC,CACvE,CAAC;IACH,CAAC;IAEM,SAAS;QACf,OAAO;YACN,sBAAsB,EAAE,IAAI,CAAC,sBAAsB;YACnD,eAAe,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ;YAC7C,eAAe,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ;SAC7C,CAAC;IACH,CAAC;IAEO,oBAAoB,CAC3B,SAAiB,EACjB,MAAiC,EACjC,cAAsB,EACtB,YAAqB,KAAK,EAC1B,MAAe;QAEf,IAAI,IAAI,CAAC,uBAAuB,IAAI,SAAS,EAAE,CAAC;YAC/C,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC;gBAChC,SAAS;gBACT,QAAQ,EAAE,MAAM,EAAE,QAAQ;gBAC1B,cAAc;gBACd,eAAe,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ;gBAC7C,eAAe,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ;gBAC7C,UAAU,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;gBACpE,kBAAkB,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,KAAK,oBAAoB;gBACxE,MAAM;aACN,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @rushstack/no-new-null */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { IDeltaManager } from \"@fluidframework/container-definitions/internal\";\nimport { IEvent, IEventProvider, ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { IClient, IQuorumClients, ISequencedClient } from \"@fluidframework/driver-definitions\";\nimport {\n\tITelemetryLoggerExt,\n\tUsageError,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { summarizerClientType } from \"./index.js\";\n\n// helper types for recursive readonly.\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport type ImmutablePrimitives = undefined | null | boolean | string | number | Function;\nexport type Immutable<T> = T extends ImmutablePrimitives\n\t? T\n\t: T extends (infer A)[]\n\t\t? readonly Immutable<A>[]\n\t\t: T extends Map<infer K, infer V>\n\t\t\t? ReadonlyMap<Immutable<K>, Immutable<V>>\n\t\t\t: T extends Set<infer V>\n\t\t\t\t? ReadonlySet<Immutable<V>>\n\t\t\t\t: { readonly [K in keyof T]: Immutable<T[K]> };\n\n/**\n * Minimum information for a client tracked for election consideration.\n */\nexport interface ITrackedClient {\n\treadonly clientId: string;\n\treadonly sequenceNumber: number;\n\treadonly client: Immutable<IClient>;\n}\n\n/**\n * Common contract for link nodes within an OrderedClientCollection.\n */\nexport interface ILinkNode {\n\treadonly sequenceNumber: number;\n\tyoungerClient: ILinkedClient | undefined;\n}\n\n/**\n * Placeholder root node within an OrderedClientCollection; does not represent a client.\n */\nexport interface IRootLinkNode extends ILinkNode {\n\treadonly sequenceNumber: -1;\n\treadonly olderClient: undefined;\n}\n\n/**\n * Additional information required to keep track of the client within the doubly-linked list.\n */\nexport interface ILinkedClient extends ILinkNode, ITrackedClient {\n\tolderClient: LinkNode;\n}\n\n/**\n * Any link node within OrderedClientCollection including the placeholder root node.\n */\nexport type LinkNode = IRootLinkNode | ILinkedClient;\n\n/**\n * Events raised by an OrderedClientCollection.\n */\nexport interface IOrderedClientCollectionEvents extends IEvent {\n\t/**\n\t * Event fires when client is being added.\n\t */\n\t(\n\t\tevent: \"addClient\" | \"removeClient\",\n\t\tlistener: (client: ILinkedClient, sequenceNumber: number) => void,\n\t);\n}\n\n/**\n * Contract for a sorted collection of all clients in the quorum.\n */\nexport interface IOrderedClientCollection\n\textends IEventProvider<IOrderedClientCollectionEvents> {\n\t/**\n\t * Count of clients in the collection.\n\t */\n\treadonly count: number;\n\t/**\n\t * Pointer to the oldest client in the collection.\n\t */\n\treadonly oldestClient: ILinkedClient | undefined;\n\t/**\n\t * Returns a sorted array of all the clients in the collection.\n\t */\n\tgetAllClients(): ILinkedClient[];\n}\n\n/**\n * Tracks clients in the Quorum. It maintains their order using their join op\n * sequence numbers.\n * Internally, the collection of clients is maintained in a doubly-linked list,\n * with pointers to both the first and last nodes.\n * The first (root) node is a placeholder to simplify logic and reduce null checking.\n */\nexport class OrderedClientCollection\n\textends TypedEventEmitter<IOrderedClientCollectionEvents>\n\timplements IOrderedClientCollection\n{\n\t/**\n\t * Collection of ALL clients currently in the quorum, with client ids as keys.\n\t */\n\tprivate readonly clientMap = new Map<string, ILinkedClient>();\n\t/**\n\t * Placeholder head node of linked list, for simplified null checking.\n\t */\n\tprivate readonly rootNode: IRootLinkNode = {\n\t\tsequenceNumber: -1,\n\t\tolderClient: undefined,\n\t\tyoungerClient: undefined,\n\t};\n\t/**\n\t * Pointer to end of linked list, for optimized client adds.\n\t */\n\tprivate _youngestClient: LinkNode = this.rootNode;\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tpublic get count(): number {\n\t\treturn this.clientMap.size;\n\t}\n\tpublic get oldestClient(): ILinkedClient | undefined {\n\t\treturn this.rootNode.youngerClient;\n\t}\n\n\tconstructor(\n\t\tlogger: ITelemetryBaseLogger,\n\t\tdeltaManager: Pick<IDeltaManager<unknown, unknown>, \"lastSequenceNumber\">,\n\t\tquorum: Pick<IQuorumClients, \"getMembers\" | \"on\">,\n\t) {\n\t\tsuper();\n\t\tthis.logger = createChildLogger({ logger, namespace: \"OrderedClientCollection\" });\n\t\tconst members = quorum.getMembers();\n\t\tfor (const [clientId, client] of members) {\n\t\t\tthis.addClient(clientId, client);\n\t\t}\n\n\t\tquorum.on(\"addMember\", (clientId, client) => {\n\t\t\tconst newClient = this.addClient(clientId, client);\n\t\t\tthis.emit(\"addClient\", newClient, deltaManager.lastSequenceNumber);\n\t\t});\n\t\tquorum.on(\"removeMember\", (clientId) => {\n\t\t\tconst sequenceNumber = deltaManager.lastSequenceNumber;\n\t\t\tconst removeClient = this.removeClient(clientId);\n\t\t\tif (removeClient === undefined) {\n\t\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"ClientNotFound\",\n\t\t\t\t\tclientId,\n\t\t\t\t\tsequenceNumber,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthis.emit(\"removeClient\", removeClient, sequenceNumber);\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate addClient(clientId: string, client: ISequencedClient): ITrackedClient {\n\t\t// Normal case is adding the latest client, which will bypass loop.\n\t\t// Find where it belongs otherwise (maybe possible during initial load?).\n\t\tassert(\n\t\t\tclient.sequenceNumber > -1,\n\t\t\t0x1f6 /* \"Negative client sequence number not allowed\" */,\n\t\t);\n\t\tlet currClient = this._youngestClient;\n\t\twhile (currClient.sequenceNumber > client.sequenceNumber) {\n\t\t\tassert(\n\t\t\t\tcurrClient.olderClient !== undefined,\n\t\t\t\t0x1f7 /* \"Previous client should always be defined\" */,\n\t\t\t);\n\t\t\t// Note: If adding a client older than the elected client, it will not be automatically elected.\n\t\t\tcurrClient = currClient.olderClient;\n\t\t}\n\n\t\t// Now currClient is the node right before where the new client node should be.\n\t\tconst newClient: ILinkedClient = {\n\t\t\tclientId,\n\t\t\tsequenceNumber: client.sequenceNumber,\n\t\t\tclient: { ...client.client }, // shallow clone\n\t\t\tolderClient: currClient,\n\t\t\tyoungerClient: currClient.youngerClient,\n\t\t};\n\n\t\t// Update prev node to point to this new node.\n\t\tnewClient.olderClient.youngerClient = newClient;\n\n\t\tif (newClient.youngerClient === undefined) {\n\t\t\t// Update linked list end pointer to youngest client.\n\t\t\tthis._youngestClient = newClient;\n\t\t} else {\n\t\t\t// Update next node to point back to this new node.\n\t\t\tnewClient.youngerClient.olderClient = newClient;\n\t\t}\n\n\t\tthis.clientMap.set(clientId, newClient);\n\t\treturn newClient;\n\t}\n\n\tprivate removeClient(clientId: string): ITrackedClient | undefined {\n\t\tconst removeClient = this.clientMap.get(clientId);\n\t\tif (removeClient === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Update prev node to point to next node.\n\t\tremoveClient.olderClient.youngerClient = removeClient.youngerClient;\n\n\t\tif (removeClient.youngerClient === undefined) {\n\t\t\t// Update linked list end pointer to youngest client.\n\t\t\tthis._youngestClient = removeClient.olderClient;\n\t\t} else {\n\t\t\t// Update next node to point back to previous node.\n\t\t\tremoveClient.youngerClient.olderClient = removeClient.olderClient;\n\t\t}\n\n\t\tthis.clientMap.delete(clientId);\n\t\treturn removeClient;\n\t}\n\n\t/**\n\t * Returns an array of all clients being tracked in order from oldest to newest.\n\t */\n\tpublic getAllClients(): ILinkedClient[] {\n\t\tconst result: ILinkedClient[] = [];\n\t\tlet currClient: LinkNode = this.rootNode;\n\t\twhile (currClient.youngerClient !== undefined) {\n\t\t\tresult.push(currClient.youngerClient);\n\t\t\tcurrClient = currClient.youngerClient;\n\t\t}\n\t\treturn result;\n\t}\n}\n\n/**\n * Events raised by an OrderedClientElection.\n */\nexport interface IOrderedClientElectionEvents extends IEvent {\n\t/**\n\t * Event fires when the currently elected client changes.\n\t */\n\t(\n\t\tevent: \"election\",\n\t\tlistener: (\n\t\t\t/**\n\t\t\t * Newly elected client.\n\t\t\t */\n\t\t\tclient: ITrackedClient | undefined,\n\t\t\t/**\n\t\t\t * Sequence number where election took place.\n\t\t\t */\n\t\t\tsequenceNumber: number,\n\t\t\t/**\n\t\t\t * Previously elected client.\n\t\t\t */\n\t\t\tprevClient: ITrackedClient | undefined,\n\t\t) => void,\n\t);\n}\n\n/**\n * Serialized state of IOrderedClientElection.\n * @internal\n */\nexport interface ISerializedElection {\n\t/**\n\t * Sequence number at the time of the latest election.\n\t */\n\treadonly electionSequenceNumber: number;\n\n\t/**\n\t * Most recently elected client id. This is either:\n\t *\n\t * 1. the interactive elected parent client, in which case electedClientId === electedParentId,\n\t * and the SummaryManager on the elected client will spawn a summarizer client, or\n\t *\n\t * 2. the non-interactive summarizer client itself.\n\t */\n\treadonly electedClientId: string | undefined;\n\n\t/**\n\t * Most recently elected parent client id. This is always an interactive client.\n\t */\n\treadonly electedParentId: string | undefined;\n}\n\n/**\n * Contract for maintaining a deterministic client election based on eligibility.\n */\nexport interface IOrderedClientElection extends IEventProvider<IOrderedClientElectionEvents> {\n\t/**\n\t * Count of eligible clients in the collection.\n\t */\n\treadonly eligibleCount: number;\n\n\t/**\n\t * Currently elected client. This is either:\n\t *\n\t * 1. the interactive elected parent client, in which case electedClientId === electedParentId,\n\t * and the SummaryManager on the elected client will spawn a summarizer client, or\n\t *\n\t * 2. the non-interactive summarizer client itself.\n\t */\n\treadonly electedClient: ITrackedClient | undefined;\n\t/**\n\t * Currently elected parent client. This is always an interactive client.\n\t */\n\treadonly electedParent: ITrackedClient | undefined;\n\t/**\n\t * Sequence number of most recent election.\n\t */\n\treadonly electionSequenceNumber: number;\n\t/**\n\t * Resets the currently elected client back to the oldest eligible client.\n\t */\n\tresetElectedClient(sequenceNumber: number): void;\n\t/**\n\t * Peeks at what the next elected client would be if incrementElectedClient were called.\n\t */\n\tpeekNextElectedClient(): ITrackedClient | undefined;\n\t/**\n\t * Returns a sorted array of all the eligible clients in the collection.\n\t */\n\tgetAllEligibleClients(): ITrackedClient[];\n\t/**\n\t * Serialize election data\n\t */\n\tserialize(): ISerializedElection;\n}\n\n/**\n * Adapter for OrderedClientCollection, with the purpose of deterministically maintaining\n * a currently elected client, excluding ineligible clients, in a distributed fashion.\n * This can be true as long as incrementElectedClient and resetElectedClient calls\n * are called under the same conditions for all clients.\n */\nexport class OrderedClientElection\n\textends TypedEventEmitter<IOrderedClientElectionEvents>\n\timplements IOrderedClientElection\n{\n\tprivate _eligibleCount: number = 0;\n\tprivate _electedClient: ILinkedClient | undefined;\n\tprivate _electedParent: ILinkedClient | undefined;\n\tprivate _electionSequenceNumber: number;\n\n\tpublic get eligibleCount(): number {\n\t\treturn this._eligibleCount;\n\t}\n\tpublic get electionSequenceNumber(): number {\n\t\treturn this._electionSequenceNumber;\n\t}\n\n\t/**\n\t * OrderedClientCollection tracks electedClient and electedParent separately. This allows us to handle the case\n\t * where a new interactive parent client has been elected, but the summarizer is still doing work, so\n\t * a new summarizer should not yet be spawned. In this case, changing electedParent will cause SummaryManager\n\t * to stop the current summarizer, but a new summarizer will not be spawned until the old summarizer client has\n\t * left the quorum.\n\t *\n\t * Details:\n\t *\n\t * electedParent is the interactive client that has been elected to spawn a summarizer. It is typically the oldest\n\t * eligible interactive client in the quorum. Only the electedParent is permitted to spawn a summarizer.\n\t * Once elected, this client will remain the electedParent until it leaves the quorum or the summarizer that\n\t * it spawned stops producing summaries, at which point a new electedParent will be chosen.\n\t *\n\t * electedClient is the non-interactive summarizer client if one exists. If not, then electedClient is equal to\n\t * electedParent. If electedParent === electedClient, this is the signal for electedParent to spawn a new\n\t * electedClient. Once a summarizer client becomes electedClient, a new summarizer will not be spawned until\n\t * electedClient leaves the quorum.\n\t *\n\t * A typical sequence looks like this:\n\t *\n\t * i. Begin by electing A. electedParent === A, electedClient === A.\n\t *\n\t * ii. SummaryManager running on A spawns a summarizer client, A'. electedParent === A, electedClient === A'\n\t *\n\t * iii. A' stops producing summaries. A new parent client, B, is elected. electedParent === B, electedClient === A'\n\t *\n\t * iv. SummaryManager running on A detects the change to electedParent and tells the summarizer to stop, but A'\n\t * is in mid-summarization. No new summarizer is spawned, as electedParent !== electedClient.\n\t *\n\t * v. A' completes its summary, and the summarizer and backing client are torn down.\n\t *\n\t * vi. A' leaves the quorum, and B takes its place as electedClient. electedParent === B, electedClient === B\n\t *\n\t * vii. SummaryManager running on B spawns a summarizer client, B'. electedParent === B, electedClient === B'\n\t */\n\tpublic get electedClient(): ILinkedClient | undefined {\n\t\treturn this._electedClient;\n\t}\n\tpublic get electedParent(): ILinkedClient | undefined {\n\t\treturn this._electedParent;\n\t}\n\n\tconstructor(\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprivate readonly orderedClientCollection: IOrderedClientCollection,\n\t\t/**\n\t\t * Serialized state from summary or current sequence number at time of load if new.\n\t\t */\n\t\tinitialState: ISerializedElection | number,\n\t\tprivate readonly isEligibleFn: (c: ITrackedClient) => boolean,\n\t\tprivate readonly recordPerformanceEvents: boolean = false,\n\t) {\n\t\tsuper();\n\t\tlet initialClient: ILinkedClient | undefined;\n\t\tlet initialParent: ILinkedClient | undefined;\n\t\tfor (const client of orderedClientCollection.getAllClients()) {\n\t\t\tthis.addClient(client, 0);\n\t\t\tif (typeof initialState !== \"number\") {\n\t\t\t\tif (client.clientId === initialState.electedClientId) {\n\t\t\t\t\tinitialClient = client;\n\t\t\t\t\tif (\n\t\t\t\t\t\tinitialState.electedParentId === undefined &&\n\t\t\t\t\t\tclient.client.details.type !== summarizerClientType\n\t\t\t\t\t) {\n\t\t\t\t\t\t// If there was no elected parent in the serialized data, use this one.\n\t\t\t\t\t\tinitialParent = client;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (client.clientId === initialState.electedParentId) {\n\t\t\t\t\tinitialParent = client;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\torderedClientCollection.on(\"addClient\", (client, seq) => this.addClient(client, seq));\n\t\torderedClientCollection.on(\"removeClient\", (client, seq) =>\n\t\t\tthis.removeClient(client, seq),\n\t\t);\n\n\t\tif (typeof initialState === \"number\") {\n\t\t\tthis._electionSequenceNumber = initialState;\n\t\t} else {\n\t\t\t// Override the initially elected client with the initial state.\n\t\t\tif (initialClient?.clientId !== initialState.electedClientId) {\n\t\t\t\t// Cannot find initially elected client, so elect undefined.\n\t\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"InitialElectedClientNotFound\",\n\t\t\t\t\telectionSequenceNumber: initialState.electionSequenceNumber,\n\t\t\t\t\texpectedClientId: initialState.electedClientId,\n\t\t\t\t\telectedClientId: initialClient?.clientId,\n\t\t\t\t\tclientCount: orderedClientCollection.count,\n\t\t\t\t});\n\t\t\t} else if (initialClient !== undefined && !isEligibleFn(initialClient)) {\n\t\t\t\t// Initially elected client is ineligible, so elect next eligible client.\n\t\t\t\tinitialClient = initialParent = this.findFirstEligibleParent(initialParent);\n\t\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"InitialElectedClientIneligible\",\n\t\t\t\t\telectionSequenceNumber: initialState.electionSequenceNumber,\n\t\t\t\t\texpectedClientId: initialState.electedClientId,\n\t\t\t\t\telectedClientId: initialClient?.clientId,\n\t\t\t\t});\n\t\t\t}\n\t\t\tthis._electedParent = initialParent;\n\t\t\tthis._electedClient = initialClient;\n\t\t\tthis._electionSequenceNumber = initialState.electionSequenceNumber;\n\t\t}\n\t}\n\n\t/**\n\t * Tries changing the elected client, raising an event if it is different.\n\t * Note that this function does no eligibility or suitability checks. If we get here, then\n\t * we will set _electedClient, and we will set _electedParent if this is an interactive client.\n\t */\n\tprivate tryElectingClient(\n\t\tclient: ILinkedClient | undefined,\n\t\tsequenceNumber: number,\n\t\treason: string,\n\t): void {\n\t\tthis.sendPerformanceEvent(\n\t\t\t\"TryElectingClient\",\n\t\t\tclient,\n\t\t\tsequenceNumber,\n\t\t\tfalse /* forceSend */,\n\t\t\treason,\n\t\t);\n\t\tlet change = false;\n\t\tconst isSummarizerClient = client?.client.details.type === summarizerClientType;\n\t\tconst prevClient = this._electedClient;\n\t\tif (this._electedClient !== client) {\n\t\t\tthis.sendPerformanceEvent(\n\t\t\t\t\"ClientElected\",\n\t\t\t\tclient,\n\t\t\t\tsequenceNumber,\n\t\t\t\ttrue /* forceSend */,\n\t\t\t\treason,\n\t\t\t);\n\t\t\t// Changing the elected client. Record the sequence number and note that we have to fire an event.\n\t\t\tthis._electionSequenceNumber = sequenceNumber;\n\t\t\tthis._electedClient = client;\n\t\t\tchange = true;\n\t\t}\n\t\tif (this._electedParent !== client && !isSummarizerClient) {\n\t\t\tthis.sendPerformanceEvent(\n\t\t\t\t\"InteractiveClientElected\",\n\t\t\t\tclient,\n\t\t\t\tsequenceNumber,\n\t\t\t\ttrue /* forceSend */,\n\t\t\t\treason,\n\t\t\t);\n\t\t\t// Changing the elected parent as well.\n\t\t\tthis._electedParent = client;\n\t\t\tchange = true;\n\t\t}\n\t\tif (change) {\n\t\t\tthis.emit(\"election\", client, sequenceNumber, prevClient);\n\t\t}\n\t}\n\n\tprivate tryElectingParent(\n\t\tclient: ILinkedClient | undefined,\n\t\tsequenceNumber: number,\n\t\treason: string,\n\t): void {\n\t\tthis.sendPerformanceEvent(\n\t\t\t\"TryElectingParent\",\n\t\t\tclient,\n\t\t\tsequenceNumber,\n\t\t\tfalse /* forceSend */,\n\t\t\treason,\n\t\t);\n\t\tif (this._electedParent !== client) {\n\t\t\tthis.sendPerformanceEvent(\n\t\t\t\t\"ParentElected\",\n\t\t\t\tclient,\n\t\t\t\tsequenceNumber,\n\t\t\t\ttrue /* forceSend */,\n\t\t\t\treason,\n\t\t\t);\n\t\t\tthis._electedParent = client;\n\t\t\tthis.emit(\"election\", this._electedClient, sequenceNumber, this._electedClient);\n\t\t}\n\t}\n\n\t/**\n\t * Helper function to find the first eligible parent client starting with the passed in client,\n\t * or undefined if none are eligible.\n\t * @param client - client to start checking\n\t * @returns oldest eligible client starting with passed in client or undefined if none.\n\t */\n\tprivate findFirstEligibleParent(\n\t\tclient: ILinkedClient | undefined,\n\t): ILinkedClient | undefined {\n\t\tlet candidateClient = client;\n\t\twhile (\n\t\t\tcandidateClient !== undefined &&\n\t\t\t(!this.isEligibleFn(candidateClient) ||\n\t\t\t\tcandidateClient.client.details.type === summarizerClientType)\n\t\t) {\n\t\t\tcandidateClient = candidateClient.youngerClient;\n\t\t}\n\t\treturn candidateClient;\n\t}\n\n\t/**\n\t * Updates tracking for when a new client is added to the collection.\n\t * Will automatically elect that new client if none is elected currently.\n\t * @param client - client added to the collection\n\t * @param sequenceNumber - sequence number when client was added\n\t */\n\tprivate addClient(client: ILinkedClient, sequenceNumber: number): void {\n\t\tthis.sendPerformanceEvent(\"AddClient\", client, sequenceNumber);\n\t\tif (this.isEligibleFn(client)) {\n\t\t\tthis._eligibleCount++;\n\t\t\tconst newClientIsSummarizer = client.client.details.type === summarizerClientType;\n\t\t\tconst electedClientIsSummarizer =\n\t\t\t\tthis._electedClient?.client.details.type === summarizerClientType;\n\t\t\t// Note that we allow a summarizer client to supersede an interactive client as elected client.\n\t\t\tif (\n\t\t\t\tthis._electedClient === undefined ||\n\t\t\t\t(!electedClientIsSummarizer && newClientIsSummarizer)\n\t\t\t) {\n\t\t\t\tthis.tryElectingClient(client, sequenceNumber, \"AddClient\");\n\t\t\t} else if (this._electedParent === undefined && !newClientIsSummarizer) {\n\t\t\t\t// This is an odd case. If the _electedClient is set, the _electedParent should be as well.\n\t\t\t\tthis.tryElectingParent(client, sequenceNumber, \"AddClient\");\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Updates tracking for when an existing client is removed from the collection.\n\t * Will automatically elect next oldest client if currently elected is removed.\n\t * @param client - client removed from the collection\n\t * @param sequenceNumber - sequence number when client was removed\n\t */\n\tprivate removeClient(client: ILinkedClient, sequenceNumber: number): void {\n\t\tthis.sendPerformanceEvent(\"RemoveClient\", client, sequenceNumber);\n\t\tif (this.isEligibleFn(client)) {\n\t\t\tthis._eligibleCount--;\n\t\t\tif (this._electedClient === client) {\n\t\t\t\t// Removing the _electedClient. There are 2 possible cases:\n\t\t\t\tif (this._electedParent === client) {\n\t\t\t\t\t// 1. The _electedClient is an interactive client that has left the quorum.\n\t\t\t\t\t// Automatically shift to next oldest client.\n\t\t\t\t\tconst nextClient =\n\t\t\t\t\t\tthis.findFirstEligibleParent(this._electedParent?.youngerClient) ??\n\t\t\t\t\t\tthis.findFirstEligibleParent(this.orderedClientCollection.oldestClient);\n\t\t\t\t\tthis.tryElectingClient(nextClient, sequenceNumber, \"RemoveClient\");\n\t\t\t\t} else {\n\t\t\t\t\t// 2. The _electedClient is a summarizer that we've been allowing to finish its work.\n\t\t\t\t\t// Let the _electedParent become the _electedClient so that it can start its own summarizer.\n\t\t\t\t\tif (this._electedClient.client.details.type !== summarizerClientType) {\n\t\t\t\t\t\tthrow new UsageError(\"Elected client should be a summarizer client 1\");\n\t\t\t\t\t}\n\t\t\t\t\tthis.tryElectingClient(\n\t\t\t\t\t\tthis._electedParent,\n\t\t\t\t\t\tsequenceNumber,\n\t\t\t\t\t\t\"RemoveSummarizerClient\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (this._electedParent === client) {\n\t\t\t\t// Removing the _electedParent (but not _electedClient).\n\t\t\t\t// Shift to the next oldest parent, but do not replace the _electedClient,\n\t\t\t\t// which is a summarizer that is still doing work.\n\t\t\t\tif (this._electedClient?.client.details.type !== summarizerClientType) {\n\t\t\t\t\tthrow new UsageError(\"Elected client should be a summarizer client 2\");\n\t\t\t\t}\n\t\t\t\tconst nextParent =\n\t\t\t\t\tthis.findFirstEligibleParent(this._electedParent?.youngerClient) ??\n\t\t\t\t\tthis.findFirstEligibleParent(this.orderedClientCollection.oldestClient);\n\t\t\t\tthis.tryElectingParent(nextParent, sequenceNumber, \"RemoveClient\");\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic getAllEligibleClients(): ITrackedClient[] {\n\t\treturn this.orderedClientCollection\n\t\t\t.getAllClients()\n\t\t\t.filter((client) => this.isEligibleFn(client));\n\t}\n\n\t/**\n\t * (Re-)start election with the oldest client in the quorum. This is called if we need to summarize\n\t * and no client has been elected.\n\t */\n\tpublic resetElectedClient(sequenceNumber: number): void {\n\t\tconst firstClient = this.findFirstEligibleParent(\n\t\t\tthis.orderedClientCollection.oldestClient,\n\t\t);\n\t\tif (this._electedClient === undefined || this._electedClient === this._electedParent) {\n\t\t\tthis.tryElectingClient(firstClient, sequenceNumber, \"ResetElectedClient\");\n\t\t} else {\n\t\t\t// The _electedClient is a summarizer and should not be replaced until it leaves the quorum.\n\t\t\t// Changing the _electedParent will stop the summarizer.\n\t\t\tthis.tryElectingParent(firstClient, sequenceNumber, \"ResetElectedClient\");\n\t\t}\n\t}\n\n\tpublic peekNextElectedClient(): ITrackedClient | undefined {\n\t\treturn (\n\t\t\tthis.findFirstEligibleParent(this._electedParent?.youngerClient) ??\n\t\t\tthis.findFirstEligibleParent(this.orderedClientCollection.oldestClient)\n\t\t);\n\t}\n\n\tpublic serialize(): ISerializedElection {\n\t\treturn {\n\t\t\telectionSequenceNumber: this.electionSequenceNumber,\n\t\t\telectedClientId: this.electedClient?.clientId,\n\t\t\telectedParentId: this.electedParent?.clientId,\n\t\t};\n\t}\n\n\tprivate sendPerformanceEvent(\n\t\teventName: string,\n\t\tclient: ILinkedClient | undefined,\n\t\tsequenceNumber: number,\n\t\tforceSend: boolean = false,\n\t\treason?: string,\n\t): void {\n\t\tif (this.recordPerformanceEvents || forceSend) {\n\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\teventName,\n\t\t\t\tclientId: client?.clientId,\n\t\t\t\tsequenceNumber,\n\t\t\t\telectedClientId: this.electedClient?.clientId,\n\t\t\t\telectedParentId: this.electedParent?.clientId,\n\t\t\t\tisEligible: client === undefined ? false : this.isEligibleFn(client),\n\t\t\t\tisSummarizerClient: client?.client.details.type === summarizerClientType,\n\t\t\t\treason,\n\t\t\t});\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"orderedClientElection.js","sourceRoot":"","sources":["../../src/summary/orderedClientElection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,2CAA2C;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAGjE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EAEN,UAAU,EACV,iBAAiB,GACjB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAoF5D;;;;;;GAMG;AACH,MAAM,OAAO,uBACZ,SAAQ,iBAAiD;IAqBzD,IAAW,KAAK;QACf,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;IAC5B,CAA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uBAAuB,CAAC,YAAY,CAAC,CACvE,CAAC;IACH,CAAC;IAEM,SAAS;QACf,OAAO;YACN,sBAAsB,EAAE,IAAI,CAAC,sBAAsB;YACnD,eAAe,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ;YAC7C,eAAe,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ;SAC7C,CAAC;IACH,CAAC;IAEO,oBAAoB,CAC3B,SAAiB,EACjB,MAAiC,EACjC,cAAsB,EACtB,YAAqB,KAAK,EAC1B,MAAe;QAEf,IAAI,IAAI,CAAC,uBAAuB,IAAI,SAAS,EAAE,CAAC;YAC/C,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC;gBAChC,SAAS;gBACT,QAAQ,EAAE,MAAM,EAAE,QAAQ;gBAC1B,cAAc;gBACd,eAAe,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ;gBAC7C,eAAe,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ;gBAC7C,UAAU,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;gBACpE,kBAAkB,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,KAAK,oBAAoB;gBACxE,MAAM;aACN,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @rushstack/no-new-null */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { IDeltaManager } from \"@fluidframework/container-definitions/internal\";\nimport { IEvent, IEventProvider, ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { IClient, IQuorumClients, ISequencedClient } from \"@fluidframework/driver-definitions\";\nimport {\n\tITelemetryLoggerExt,\n\tUsageError,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { summarizerClientType } from \"./summarizerTypes.js\";\n\n// helper types for recursive readonly.\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport type ImmutablePrimitives = undefined | null | boolean | string | number | Function;\nexport type Immutable<T> = T extends ImmutablePrimitives\n\t? T\n\t: T extends (infer A)[]\n\t\t? readonly Immutable<A>[]\n\t\t: T extends Map<infer K, infer V>\n\t\t\t? ReadonlyMap<Immutable<K>, Immutable<V>>\n\t\t\t: T extends Set<infer V>\n\t\t\t\t? ReadonlySet<Immutable<V>>\n\t\t\t\t: { readonly [K in keyof T]: Immutable<T[K]> };\n\n/**\n * Minimum information for a client tracked for election consideration.\n */\nexport interface ITrackedClient {\n\treadonly clientId: string;\n\treadonly sequenceNumber: number;\n\treadonly client: Immutable<IClient>;\n}\n\n/**\n * Common contract for link nodes within an OrderedClientCollection.\n */\nexport interface ILinkNode {\n\treadonly sequenceNumber: number;\n\tyoungerClient: ILinkedClient | undefined;\n}\n\n/**\n * Placeholder root node within an OrderedClientCollection; does not represent a client.\n */\nexport interface IRootLinkNode extends ILinkNode {\n\treadonly sequenceNumber: -1;\n\treadonly olderClient: undefined;\n}\n\n/**\n * Additional information required to keep track of the client within the doubly-linked list.\n */\nexport interface ILinkedClient extends ILinkNode, ITrackedClient {\n\tolderClient: LinkNode;\n}\n\n/**\n * Any link node within OrderedClientCollection including the placeholder root node.\n */\nexport type LinkNode = IRootLinkNode | ILinkedClient;\n\n/**\n * Events raised by an OrderedClientCollection.\n */\nexport interface IOrderedClientCollectionEvents extends IEvent {\n\t/**\n\t * Event fires when client is being added.\n\t */\n\t(\n\t\tevent: \"addClient\" | \"removeClient\",\n\t\tlistener: (client: ILinkedClient, sequenceNumber: number) => void,\n\t);\n}\n\n/**\n * Contract for a sorted collection of all clients in the quorum.\n */\nexport interface IOrderedClientCollection\n\textends IEventProvider<IOrderedClientCollectionEvents> {\n\t/**\n\t * Count of clients in the collection.\n\t */\n\treadonly count: number;\n\t/**\n\t * Pointer to the oldest client in the collection.\n\t */\n\treadonly oldestClient: ILinkedClient | undefined;\n\t/**\n\t * Returns a sorted array of all the clients in the collection.\n\t */\n\tgetAllClients(): ILinkedClient[];\n}\n\n/**\n * Tracks clients in the Quorum. It maintains their order using their join op\n * sequence numbers.\n * Internally, the collection of clients is maintained in a doubly-linked list,\n * with pointers to both the first and last nodes.\n * The first (root) node is a placeholder to simplify logic and reduce null checking.\n */\nexport class OrderedClientCollection\n\textends TypedEventEmitter<IOrderedClientCollectionEvents>\n\timplements IOrderedClientCollection\n{\n\t/**\n\t * Collection of ALL clients currently in the quorum, with client ids as keys.\n\t */\n\tprivate readonly clientMap = new Map<string, ILinkedClient>();\n\t/**\n\t * Placeholder head node of linked list, for simplified null checking.\n\t */\n\tprivate readonly rootNode: IRootLinkNode = {\n\t\tsequenceNumber: -1,\n\t\tolderClient: undefined,\n\t\tyoungerClient: undefined,\n\t};\n\t/**\n\t * Pointer to end of linked list, for optimized client adds.\n\t */\n\tprivate _youngestClient: LinkNode = this.rootNode;\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tpublic get count(): number {\n\t\treturn this.clientMap.size;\n\t}\n\tpublic get oldestClient(): ILinkedClient | undefined {\n\t\treturn this.rootNode.youngerClient;\n\t}\n\n\tconstructor(\n\t\tlogger: ITelemetryBaseLogger,\n\t\tdeltaManager: Pick<IDeltaManager<unknown, unknown>, \"lastSequenceNumber\">,\n\t\tquorum: Pick<IQuorumClients, \"getMembers\" | \"on\">,\n\t) {\n\t\tsuper();\n\t\tthis.logger = createChildLogger({ logger, namespace: \"OrderedClientCollection\" });\n\t\tconst members = quorum.getMembers();\n\t\tfor (const [clientId, client] of members) {\n\t\t\tthis.addClient(clientId, client);\n\t\t}\n\n\t\tquorum.on(\"addMember\", (clientId, client) => {\n\t\t\tconst newClient = this.addClient(clientId, client);\n\t\t\tthis.emit(\"addClient\", newClient, deltaManager.lastSequenceNumber);\n\t\t});\n\t\tquorum.on(\"removeMember\", (clientId) => {\n\t\t\tconst sequenceNumber = deltaManager.lastSequenceNumber;\n\t\t\tconst removeClient = this.removeClient(clientId);\n\t\t\tif (removeClient === undefined) {\n\t\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"ClientNotFound\",\n\t\t\t\t\tclientId,\n\t\t\t\t\tsequenceNumber,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthis.emit(\"removeClient\", removeClient, sequenceNumber);\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate addClient(clientId: string, client: ISequencedClient): ITrackedClient {\n\t\t// Normal case is adding the latest client, which will bypass loop.\n\t\t// Find where it belongs otherwise (maybe possible during initial load?).\n\t\tassert(\n\t\t\tclient.sequenceNumber > -1,\n\t\t\t0x1f6 /* \"Negative client sequence number not allowed\" */,\n\t\t);\n\t\tlet currClient = this._youngestClient;\n\t\twhile (currClient.sequenceNumber > client.sequenceNumber) {\n\t\t\tassert(\n\t\t\t\tcurrClient.olderClient !== undefined,\n\t\t\t\t0x1f7 /* \"Previous client should always be defined\" */,\n\t\t\t);\n\t\t\t// Note: If adding a client older than the elected client, it will not be automatically elected.\n\t\t\tcurrClient = currClient.olderClient;\n\t\t}\n\n\t\t// Now currClient is the node right before where the new client node should be.\n\t\tconst newClient: ILinkedClient = {\n\t\t\tclientId,\n\t\t\tsequenceNumber: client.sequenceNumber,\n\t\t\tclient: { ...client.client }, // shallow clone\n\t\t\tolderClient: currClient,\n\t\t\tyoungerClient: currClient.youngerClient,\n\t\t};\n\n\t\t// Update prev node to point to this new node.\n\t\tnewClient.olderClient.youngerClient = newClient;\n\n\t\tif (newClient.youngerClient === undefined) {\n\t\t\t// Update linked list end pointer to youngest client.\n\t\t\tthis._youngestClient = newClient;\n\t\t} else {\n\t\t\t// Update next node to point back to this new node.\n\t\t\tnewClient.youngerClient.olderClient = newClient;\n\t\t}\n\n\t\tthis.clientMap.set(clientId, newClient);\n\t\treturn newClient;\n\t}\n\n\tprivate removeClient(clientId: string): ITrackedClient | undefined {\n\t\tconst removeClient = this.clientMap.get(clientId);\n\t\tif (removeClient === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Update prev node to point to next node.\n\t\tremoveClient.olderClient.youngerClient = removeClient.youngerClient;\n\n\t\tif (removeClient.youngerClient === undefined) {\n\t\t\t// Update linked list end pointer to youngest client.\n\t\t\tthis._youngestClient = removeClient.olderClient;\n\t\t} else {\n\t\t\t// Update next node to point back to previous node.\n\t\t\tremoveClient.youngerClient.olderClient = removeClient.olderClient;\n\t\t}\n\n\t\tthis.clientMap.delete(clientId);\n\t\treturn removeClient;\n\t}\n\n\t/**\n\t * Returns an array of all clients being tracked in order from oldest to newest.\n\t */\n\tpublic getAllClients(): ILinkedClient[] {\n\t\tconst result: ILinkedClient[] = [];\n\t\tlet currClient: LinkNode = this.rootNode;\n\t\twhile (currClient.youngerClient !== undefined) {\n\t\t\tresult.push(currClient.youngerClient);\n\t\t\tcurrClient = currClient.youngerClient;\n\t\t}\n\t\treturn result;\n\t}\n}\n\n/**\n * Events raised by an OrderedClientElection.\n */\nexport interface IOrderedClientElectionEvents extends IEvent {\n\t/**\n\t * Event fires when the currently elected client changes.\n\t */\n\t(\n\t\tevent: \"election\",\n\t\tlistener: (\n\t\t\t/**\n\t\t\t * Newly elected client.\n\t\t\t */\n\t\t\tclient: ITrackedClient | undefined,\n\t\t\t/**\n\t\t\t * Sequence number where election took place.\n\t\t\t */\n\t\t\tsequenceNumber: number,\n\t\t\t/**\n\t\t\t * Previously elected client.\n\t\t\t */\n\t\t\tprevClient: ITrackedClient | undefined,\n\t\t) => void,\n\t);\n}\n\n/**\n * Serialized state of IOrderedClientElection.\n * @internal\n */\nexport interface ISerializedElection {\n\t/**\n\t * Sequence number at the time of the latest election.\n\t */\n\treadonly electionSequenceNumber: number;\n\n\t/**\n\t * Most recently elected client id. This is either:\n\t *\n\t * 1. the interactive elected parent client, in which case electedClientId === electedParentId,\n\t * and the SummaryManager on the elected client will spawn a summarizer client, or\n\t *\n\t * 2. the non-interactive summarizer client itself.\n\t */\n\treadonly electedClientId: string | undefined;\n\n\t/**\n\t * Most recently elected parent client id. This is always an interactive client.\n\t */\n\treadonly electedParentId: string | undefined;\n}\n\n/**\n * Contract for maintaining a deterministic client election based on eligibility.\n */\nexport interface IOrderedClientElection extends IEventProvider<IOrderedClientElectionEvents> {\n\t/**\n\t * Count of eligible clients in the collection.\n\t */\n\treadonly eligibleCount: number;\n\n\t/**\n\t * Currently elected client. This is either:\n\t *\n\t * 1. the interactive elected parent client, in which case electedClientId === electedParentId,\n\t * and the SummaryManager on the elected client will spawn a summarizer client, or\n\t *\n\t * 2. the non-interactive summarizer client itself.\n\t */\n\treadonly electedClient: ITrackedClient | undefined;\n\t/**\n\t * Currently elected parent client. This is always an interactive client.\n\t */\n\treadonly electedParent: ITrackedClient | undefined;\n\t/**\n\t * Sequence number of most recent election.\n\t */\n\treadonly electionSequenceNumber: number;\n\t/**\n\t * Resets the currently elected client back to the oldest eligible client.\n\t */\n\tresetElectedClient(sequenceNumber: number): void;\n\t/**\n\t * Peeks at what the next elected client would be if incrementElectedClient were called.\n\t */\n\tpeekNextElectedClient(): ITrackedClient | undefined;\n\t/**\n\t * Returns a sorted array of all the eligible clients in the collection.\n\t */\n\tgetAllEligibleClients(): ITrackedClient[];\n\t/**\n\t * Serialize election data\n\t */\n\tserialize(): ISerializedElection;\n}\n\n/**\n * Adapter for OrderedClientCollection, with the purpose of deterministically maintaining\n * a currently elected client, excluding ineligible clients, in a distributed fashion.\n * This can be true as long as incrementElectedClient and resetElectedClient calls\n * are called under the same conditions for all clients.\n */\nexport class OrderedClientElection\n\textends TypedEventEmitter<IOrderedClientElectionEvents>\n\timplements IOrderedClientElection\n{\n\tprivate _eligibleCount: number = 0;\n\tprivate _electedClient: ILinkedClient | undefined;\n\tprivate _electedParent: ILinkedClient | undefined;\n\tprivate _electionSequenceNumber: number;\n\n\tpublic get eligibleCount(): number {\n\t\treturn this._eligibleCount;\n\t}\n\tpublic get electionSequenceNumber(): number {\n\t\treturn this._electionSequenceNumber;\n\t}\n\n\t/**\n\t * OrderedClientCollection tracks electedClient and electedParent separately. This allows us to handle the case\n\t * where a new interactive parent client has been elected, but the summarizer is still doing work, so\n\t * a new summarizer should not yet be spawned. In this case, changing electedParent will cause SummaryManager\n\t * to stop the current summarizer, but a new summarizer will not be spawned until the old summarizer client has\n\t * left the quorum.\n\t *\n\t * Details:\n\t *\n\t * electedParent is the interactive client that has been elected to spawn a summarizer. It is typically the oldest\n\t * eligible interactive client in the quorum. Only the electedParent is permitted to spawn a summarizer.\n\t * Once elected, this client will remain the electedParent until it leaves the quorum or the summarizer that\n\t * it spawned stops producing summaries, at which point a new electedParent will be chosen.\n\t *\n\t * electedClient is the non-interactive summarizer client if one exists. If not, then electedClient is equal to\n\t * electedParent. If electedParent === electedClient, this is the signal for electedParent to spawn a new\n\t * electedClient. Once a summarizer client becomes electedClient, a new summarizer will not be spawned until\n\t * electedClient leaves the quorum.\n\t *\n\t * A typical sequence looks like this:\n\t *\n\t * i. Begin by electing A. electedParent === A, electedClient === A.\n\t *\n\t * ii. SummaryManager running on A spawns a summarizer client, A'. electedParent === A, electedClient === A'\n\t *\n\t * iii. A' stops producing summaries. A new parent client, B, is elected. electedParent === B, electedClient === A'\n\t *\n\t * iv. SummaryManager running on A detects the change to electedParent and tells the summarizer to stop, but A'\n\t * is in mid-summarization. No new summarizer is spawned, as electedParent !== electedClient.\n\t *\n\t * v. A' completes its summary, and the summarizer and backing client are torn down.\n\t *\n\t * vi. A' leaves the quorum, and B takes its place as electedClient. electedParent === B, electedClient === B\n\t *\n\t * vii. SummaryManager running on B spawns a summarizer client, B'. electedParent === B, electedClient === B'\n\t */\n\tpublic get electedClient(): ILinkedClient | undefined {\n\t\treturn this._electedClient;\n\t}\n\tpublic get electedParent(): ILinkedClient | undefined {\n\t\treturn this._electedParent;\n\t}\n\n\tconstructor(\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprivate readonly orderedClientCollection: IOrderedClientCollection,\n\t\t/**\n\t\t * Serialized state from summary or current sequence number at time of load if new.\n\t\t */\n\t\tinitialState: ISerializedElection | number,\n\t\tprivate readonly isEligibleFn: (c: ITrackedClient) => boolean,\n\t\tprivate readonly recordPerformanceEvents: boolean = false,\n\t) {\n\t\tsuper();\n\t\tlet initialClient: ILinkedClient | undefined;\n\t\tlet initialParent: ILinkedClient | undefined;\n\t\tfor (const client of orderedClientCollection.getAllClients()) {\n\t\t\tthis.addClient(client, 0);\n\t\t\tif (typeof initialState !== \"number\") {\n\t\t\t\tif (client.clientId === initialState.electedClientId) {\n\t\t\t\t\tinitialClient = client;\n\t\t\t\t\tif (\n\t\t\t\t\t\tinitialState.electedParentId === undefined &&\n\t\t\t\t\t\tclient.client.details.type !== summarizerClientType\n\t\t\t\t\t) {\n\t\t\t\t\t\t// If there was no elected parent in the serialized data, use this one.\n\t\t\t\t\t\tinitialParent = client;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (client.clientId === initialState.electedParentId) {\n\t\t\t\t\tinitialParent = client;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\torderedClientCollection.on(\"addClient\", (client, seq) => this.addClient(client, seq));\n\t\torderedClientCollection.on(\"removeClient\", (client, seq) =>\n\t\t\tthis.removeClient(client, seq),\n\t\t);\n\n\t\tif (typeof initialState === \"number\") {\n\t\t\tthis._electionSequenceNumber = initialState;\n\t\t} else {\n\t\t\t// Override the initially elected client with the initial state.\n\t\t\tif (initialClient?.clientId !== initialState.electedClientId) {\n\t\t\t\t// Cannot find initially elected client, so elect undefined.\n\t\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"InitialElectedClientNotFound\",\n\t\t\t\t\telectionSequenceNumber: initialState.electionSequenceNumber,\n\t\t\t\t\texpectedClientId: initialState.electedClientId,\n\t\t\t\t\telectedClientId: initialClient?.clientId,\n\t\t\t\t\tclientCount: orderedClientCollection.count,\n\t\t\t\t});\n\t\t\t} else if (initialClient !== undefined && !isEligibleFn(initialClient)) {\n\t\t\t\t// Initially elected client is ineligible, so elect next eligible client.\n\t\t\t\tinitialClient = initialParent = this.findFirstEligibleParent(initialParent);\n\t\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"InitialElectedClientIneligible\",\n\t\t\t\t\telectionSequenceNumber: initialState.electionSequenceNumber,\n\t\t\t\t\texpectedClientId: initialState.electedClientId,\n\t\t\t\t\telectedClientId: initialClient?.clientId,\n\t\t\t\t});\n\t\t\t}\n\t\t\tthis._electedParent = initialParent;\n\t\t\tthis._electedClient = initialClient;\n\t\t\tthis._electionSequenceNumber = initialState.electionSequenceNumber;\n\t\t}\n\t}\n\n\t/**\n\t * Tries changing the elected client, raising an event if it is different.\n\t * Note that this function does no eligibility or suitability checks. If we get here, then\n\t * we will set _electedClient, and we will set _electedParent if this is an interactive client.\n\t */\n\tprivate tryElectingClient(\n\t\tclient: ILinkedClient | undefined,\n\t\tsequenceNumber: number,\n\t\treason: string,\n\t): void {\n\t\tthis.sendPerformanceEvent(\n\t\t\t\"TryElectingClient\",\n\t\t\tclient,\n\t\t\tsequenceNumber,\n\t\t\tfalse /* forceSend */,\n\t\t\treason,\n\t\t);\n\t\tlet change = false;\n\t\tconst isSummarizerClient = client?.client.details.type === summarizerClientType;\n\t\tconst prevClient = this._electedClient;\n\t\tif (this._electedClient !== client) {\n\t\t\tthis.sendPerformanceEvent(\n\t\t\t\t\"ClientElected\",\n\t\t\t\tclient,\n\t\t\t\tsequenceNumber,\n\t\t\t\ttrue /* forceSend */,\n\t\t\t\treason,\n\t\t\t);\n\t\t\t// Changing the elected client. Record the sequence number and note that we have to fire an event.\n\t\t\tthis._electionSequenceNumber = sequenceNumber;\n\t\t\tthis._electedClient = client;\n\t\t\tchange = true;\n\t\t}\n\t\tif (this._electedParent !== client && !isSummarizerClient) {\n\t\t\tthis.sendPerformanceEvent(\n\t\t\t\t\"InteractiveClientElected\",\n\t\t\t\tclient,\n\t\t\t\tsequenceNumber,\n\t\t\t\ttrue /* forceSend */,\n\t\t\t\treason,\n\t\t\t);\n\t\t\t// Changing the elected parent as well.\n\t\t\tthis._electedParent = client;\n\t\t\tchange = true;\n\t\t}\n\t\tif (change) {\n\t\t\tthis.emit(\"election\", client, sequenceNumber, prevClient);\n\t\t}\n\t}\n\n\tprivate tryElectingParent(\n\t\tclient: ILinkedClient | undefined,\n\t\tsequenceNumber: number,\n\t\treason: string,\n\t): void {\n\t\tthis.sendPerformanceEvent(\n\t\t\t\"TryElectingParent\",\n\t\t\tclient,\n\t\t\tsequenceNumber,\n\t\t\tfalse /* forceSend */,\n\t\t\treason,\n\t\t);\n\t\tif (this._electedParent !== client) {\n\t\t\tthis.sendPerformanceEvent(\n\t\t\t\t\"ParentElected\",\n\t\t\t\tclient,\n\t\t\t\tsequenceNumber,\n\t\t\t\ttrue /* forceSend */,\n\t\t\t\treason,\n\t\t\t);\n\t\t\tthis._electedParent = client;\n\t\t\tthis.emit(\"election\", this._electedClient, sequenceNumber, this._electedClient);\n\t\t}\n\t}\n\n\t/**\n\t * Helper function to find the first eligible parent client starting with the passed in client,\n\t * or undefined if none are eligible.\n\t * @param client - client to start checking\n\t * @returns oldest eligible client starting with passed in client or undefined if none.\n\t */\n\tprivate findFirstEligibleParent(\n\t\tclient: ILinkedClient | undefined,\n\t): ILinkedClient | undefined {\n\t\tlet candidateClient = client;\n\t\twhile (\n\t\t\tcandidateClient !== undefined &&\n\t\t\t(!this.isEligibleFn(candidateClient) ||\n\t\t\t\tcandidateClient.client.details.type === summarizerClientType)\n\t\t) {\n\t\t\tcandidateClient = candidateClient.youngerClient;\n\t\t}\n\t\treturn candidateClient;\n\t}\n\n\t/**\n\t * Updates tracking for when a new client is added to the collection.\n\t * Will automatically elect that new client if none is elected currently.\n\t * @param client - client added to the collection\n\t * @param sequenceNumber - sequence number when client was added\n\t */\n\tprivate addClient(client: ILinkedClient, sequenceNumber: number): void {\n\t\tthis.sendPerformanceEvent(\"AddClient\", client, sequenceNumber);\n\t\tif (this.isEligibleFn(client)) {\n\t\t\tthis._eligibleCount++;\n\t\t\tconst newClientIsSummarizer = client.client.details.type === summarizerClientType;\n\t\t\tconst electedClientIsSummarizer =\n\t\t\t\tthis._electedClient?.client.details.type === summarizerClientType;\n\t\t\t// Note that we allow a summarizer client to supersede an interactive client as elected client.\n\t\t\tif (\n\t\t\t\tthis._electedClient === undefined ||\n\t\t\t\t(!electedClientIsSummarizer && newClientIsSummarizer)\n\t\t\t) {\n\t\t\t\tthis.tryElectingClient(client, sequenceNumber, \"AddClient\");\n\t\t\t} else if (this._electedParent === undefined && !newClientIsSummarizer) {\n\t\t\t\t// This is an odd case. If the _electedClient is set, the _electedParent should be as well.\n\t\t\t\tthis.tryElectingParent(client, sequenceNumber, \"AddClient\");\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Updates tracking for when an existing client is removed from the collection.\n\t * Will automatically elect next oldest client if currently elected is removed.\n\t * @param client - client removed from the collection\n\t * @param sequenceNumber - sequence number when client was removed\n\t */\n\tprivate removeClient(client: ILinkedClient, sequenceNumber: number): void {\n\t\tthis.sendPerformanceEvent(\"RemoveClient\", client, sequenceNumber);\n\t\tif (this.isEligibleFn(client)) {\n\t\t\tthis._eligibleCount--;\n\t\t\tif (this._electedClient === client) {\n\t\t\t\t// Removing the _electedClient. There are 2 possible cases:\n\t\t\t\tif (this._electedParent === client) {\n\t\t\t\t\t// 1. The _electedClient is an interactive client that has left the quorum.\n\t\t\t\t\t// Automatically shift to next oldest client.\n\t\t\t\t\tconst nextClient =\n\t\t\t\t\t\tthis.findFirstEligibleParent(this._electedParent?.youngerClient) ??\n\t\t\t\t\t\tthis.findFirstEligibleParent(this.orderedClientCollection.oldestClient);\n\t\t\t\t\tthis.tryElectingClient(nextClient, sequenceNumber, \"RemoveClient\");\n\t\t\t\t} else {\n\t\t\t\t\t// 2. The _electedClient is a summarizer that we've been allowing to finish its work.\n\t\t\t\t\t// Let the _electedParent become the _electedClient so that it can start its own summarizer.\n\t\t\t\t\tif (this._electedClient.client.details.type !== summarizerClientType) {\n\t\t\t\t\t\tthrow new UsageError(\"Elected client should be a summarizer client 1\");\n\t\t\t\t\t}\n\t\t\t\t\tthis.tryElectingClient(\n\t\t\t\t\t\tthis._electedParent,\n\t\t\t\t\t\tsequenceNumber,\n\t\t\t\t\t\t\"RemoveSummarizerClient\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (this._electedParent === client) {\n\t\t\t\t// Removing the _electedParent (but not _electedClient).\n\t\t\t\t// Shift to the next oldest parent, but do not replace the _electedClient,\n\t\t\t\t// which is a summarizer that is still doing work.\n\t\t\t\tif (this._electedClient?.client.details.type !== summarizerClientType) {\n\t\t\t\t\tthrow new UsageError(\"Elected client should be a summarizer client 2\");\n\t\t\t\t}\n\t\t\t\tconst nextParent =\n\t\t\t\t\tthis.findFirstEligibleParent(this._electedParent?.youngerClient) ??\n\t\t\t\t\tthis.findFirstEligibleParent(this.orderedClientCollection.oldestClient);\n\t\t\t\tthis.tryElectingParent(nextParent, sequenceNumber, \"RemoveClient\");\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic getAllEligibleClients(): ITrackedClient[] {\n\t\treturn this.orderedClientCollection\n\t\t\t.getAllClients()\n\t\t\t.filter((client) => this.isEligibleFn(client));\n\t}\n\n\t/**\n\t * (Re-)start election with the oldest client in the quorum. This is called if we need to summarize\n\t * and no client has been elected.\n\t */\n\tpublic resetElectedClient(sequenceNumber: number): void {\n\t\tconst firstClient = this.findFirstEligibleParent(\n\t\t\tthis.orderedClientCollection.oldestClient,\n\t\t);\n\t\tif (this._electedClient === undefined || this._electedClient === this._electedParent) {\n\t\t\tthis.tryElectingClient(firstClient, sequenceNumber, \"ResetElectedClient\");\n\t\t} else {\n\t\t\t// The _electedClient is a summarizer and should not be replaced until it leaves the quorum.\n\t\t\t// Changing the _electedParent will stop the summarizer.\n\t\t\tthis.tryElectingParent(firstClient, sequenceNumber, \"ResetElectedClient\");\n\t\t}\n\t}\n\n\tpublic peekNextElectedClient(): ITrackedClient | undefined {\n\t\treturn (\n\t\t\tthis.findFirstEligibleParent(this._electedParent?.youngerClient) ??\n\t\t\tthis.findFirstEligibleParent(this.orderedClientCollection.oldestClient)\n\t\t);\n\t}\n\n\tpublic serialize(): ISerializedElection {\n\t\treturn {\n\t\t\telectionSequenceNumber: this.electionSequenceNumber,\n\t\t\telectedClientId: this.electedClient?.clientId,\n\t\t\telectedParentId: this.electedParent?.clientId,\n\t\t};\n\t}\n\n\tprivate sendPerformanceEvent(\n\t\teventName: string,\n\t\tclient: ILinkedClient | undefined,\n\t\tsequenceNumber: number,\n\t\tforceSend: boolean = false,\n\t\treason?: string,\n\t): void {\n\t\tif (this.recordPerformanceEvents || forceSend) {\n\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\teventName,\n\t\t\t\tclientId: client?.clientId,\n\t\t\t\tsequenceNumber,\n\t\t\t\telectedClientId: this.electedClient?.clientId,\n\t\t\t\telectedParentId: this.electedParent?.clientId,\n\t\t\t\tisEligible: client === undefined ? false : this.isEligibleFn(client),\n\t\t\t\tisSummarizerClient: client?.client.details.type === summarizerClientType,\n\t\t\t\treason,\n\t\t\t});\n\t\t}\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/container-runtime",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.53.0",
|
|
4
4
|
"description": "Fluid container runtime",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -119,18 +119,18 @@
|
|
|
119
119
|
"temp-directory": "nyc/.nyc_output"
|
|
120
120
|
},
|
|
121
121
|
"dependencies": {
|
|
122
|
-
"@fluid-internal/client-utils": "~2.
|
|
123
|
-
"@fluidframework/container-definitions": "~2.
|
|
124
|
-
"@fluidframework/container-runtime-definitions": "~2.
|
|
125
|
-
"@fluidframework/core-interfaces": "~2.
|
|
126
|
-
"@fluidframework/core-utils": "~2.
|
|
127
|
-
"@fluidframework/datastore": "~2.
|
|
128
|
-
"@fluidframework/driver-definitions": "~2.
|
|
129
|
-
"@fluidframework/driver-utils": "~2.
|
|
130
|
-
"@fluidframework/id-compressor": "~2.
|
|
131
|
-
"@fluidframework/runtime-definitions": "~2.
|
|
132
|
-
"@fluidframework/runtime-utils": "~2.
|
|
133
|
-
"@fluidframework/telemetry-utils": "~2.
|
|
122
|
+
"@fluid-internal/client-utils": "~2.53.0",
|
|
123
|
+
"@fluidframework/container-definitions": "~2.53.0",
|
|
124
|
+
"@fluidframework/container-runtime-definitions": "~2.53.0",
|
|
125
|
+
"@fluidframework/core-interfaces": "~2.53.0",
|
|
126
|
+
"@fluidframework/core-utils": "~2.53.0",
|
|
127
|
+
"@fluidframework/datastore": "~2.53.0",
|
|
128
|
+
"@fluidframework/driver-definitions": "~2.53.0",
|
|
129
|
+
"@fluidframework/driver-utils": "~2.53.0",
|
|
130
|
+
"@fluidframework/id-compressor": "~2.53.0",
|
|
131
|
+
"@fluidframework/runtime-definitions": "~2.53.0",
|
|
132
|
+
"@fluidframework/runtime-utils": "~2.53.0",
|
|
133
|
+
"@fluidframework/telemetry-utils": "~2.53.0",
|
|
134
134
|
"@tylerbu/sorted-btree-es6": "^1.8.0",
|
|
135
135
|
"double-ended-queue": "^2.1.0-0",
|
|
136
136
|
"lz4js": "^0.2.0",
|
|
@@ -140,16 +140,16 @@
|
|
|
140
140
|
"devDependencies": {
|
|
141
141
|
"@arethetypeswrong/cli": "^0.17.1",
|
|
142
142
|
"@biomejs/biome": "~1.9.3",
|
|
143
|
-
"@fluid-internal/mocha-test-setup": "~2.
|
|
144
|
-
"@fluid-private/stochastic-test-utils": "~2.
|
|
145
|
-
"@fluid-private/test-pairwise-generator": "~2.
|
|
143
|
+
"@fluid-internal/mocha-test-setup": "~2.53.0",
|
|
144
|
+
"@fluid-private/stochastic-test-utils": "~2.53.0",
|
|
145
|
+
"@fluid-private/test-pairwise-generator": "~2.53.0",
|
|
146
146
|
"@fluid-tools/benchmark": "^0.51.0",
|
|
147
147
|
"@fluid-tools/build-cli": "^0.57.0",
|
|
148
148
|
"@fluidframework/build-common": "^2.0.3",
|
|
149
149
|
"@fluidframework/build-tools": "^0.57.0",
|
|
150
|
-
"@fluidframework/container-runtime-previous": "npm:@fluidframework/container-runtime@2.
|
|
150
|
+
"@fluidframework/container-runtime-previous": "npm:@fluidframework/container-runtime@2.52.0",
|
|
151
151
|
"@fluidframework/eslint-config-fluid": "^5.7.4",
|
|
152
|
-
"@fluidframework/test-runtime-utils": "~2.
|
|
152
|
+
"@fluidframework/test-runtime-utils": "~2.53.0",
|
|
153
153
|
"@microsoft/api-extractor": "7.52.8",
|
|
154
154
|
"@types/double-ended-queue": "^2.1.0",
|
|
155
155
|
"@types/lz4js": "^0.2.0",
|
package/src/containerRuntime.ts
CHANGED
|
@@ -5040,6 +5040,11 @@ export class ContainerRuntime
|
|
|
5040
5040
|
}
|
|
5041
5041
|
|
|
5042
5042
|
public getPendingLocalState(props?: IGetPendingLocalStateProps): unknown {
|
|
5043
|
+
// AB#46464 - Add support for serializing pending state while in staging mode
|
|
5044
|
+
if (this.inStagingMode) {
|
|
5045
|
+
throw new UsageError("getPendingLocalState is not yet supported in staging mode");
|
|
5046
|
+
}
|
|
5047
|
+
|
|
5043
5048
|
this.verifyNotClosed();
|
|
5044
5049
|
if (props?.notifyImminentClosure) {
|
|
5045
5050
|
throw new UsageError("notifyImminentClosure is no longer supported in ContainerRuntime");
|
|
@@ -1179,6 +1179,12 @@ export class GarbageCollector implements IGarbageCollector {
|
|
|
1179
1179
|
public dispose(): void {
|
|
1180
1180
|
this.sessionExpiryTimer?.clear();
|
|
1181
1181
|
this.sessionExpiryTimer = undefined;
|
|
1182
|
+
|
|
1183
|
+
// Clear all unreferenced node timers to prevent process hanging
|
|
1184
|
+
for (const tracker of this.unreferencedNodesState.values()) {
|
|
1185
|
+
tracker.stopTracking();
|
|
1186
|
+
}
|
|
1187
|
+
this.unreferencedNodesState.clear();
|
|
1182
1188
|
}
|
|
1183
1189
|
|
|
1184
1190
|
/**
|
package/src/packageVersion.ts
CHANGED
|
@@ -873,8 +873,10 @@ export class PendingStateManager implements IDisposable {
|
|
|
873
873
|
this.stateHandler.reSubmitBatch(batch, { batchId, staged, squash });
|
|
874
874
|
}
|
|
875
875
|
|
|
876
|
-
|
|
877
|
-
|
|
876
|
+
if (!committingStagedBatches) {
|
|
877
|
+
// pending ops should no longer depend on previous sequenced local ops after resubmitting all pending messages (does not apply if only replaying the staged messages)
|
|
878
|
+
this.savedOps = [];
|
|
879
|
+
}
|
|
878
880
|
|
|
879
881
|
// We replayPendingStates on read connections too - we expect these to get nack'd though, and to then reconnect
|
|
880
882
|
// on a write connection and replay again. This filters out the replay that happens on the read connection so
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
createChildLogger,
|
|
17
17
|
} from "@fluidframework/telemetry-utils/internal";
|
|
18
18
|
|
|
19
|
-
import { summarizerClientType } from "./
|
|
19
|
+
import { summarizerClientType } from "./summarizerTypes.js";
|
|
20
20
|
|
|
21
21
|
// helper types for recursive readonly.
|
|
22
22
|
// eslint-disable-next-line @typescript-eslint/ban-types
|