@fluidframework/container-runtime 2.74.0 → 2.81.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 +8 -0
- package/container-runtime.test-files.tar +0 -0
- package/dist/blobManager/blobManager.d.ts +0 -2
- package/dist/blobManager/blobManager.d.ts.map +1 -1
- package/dist/blobManager/blobManager.js +4 -5
- package/dist/blobManager/blobManager.js.map +1 -1
- package/dist/channelCollection.d.ts +3 -3
- package/dist/channelCollection.d.ts.map +1 -1
- package/dist/channelCollection.js.map +1 -1
- package/dist/containerRuntime.d.ts +5 -0
- package/dist/containerRuntime.d.ts.map +1 -1
- package/dist/containerRuntime.js +13 -7
- package/dist/containerRuntime.js.map +1 -1
- package/dist/dataStoreContext.d.ts +1 -1
- package/dist/dataStoreContext.d.ts.map +1 -1
- package/dist/dataStoreContext.js +2 -1
- package/dist/dataStoreContext.js.map +1 -1
- package/dist/deltaScheduler.d.ts.map +1 -1
- package/dist/deltaScheduler.js +1 -0
- package/dist/deltaScheduler.js.map +1 -1
- package/dist/gc/gcHelpers.d.ts.map +1 -1
- package/dist/gc/gcHelpers.js +1 -0
- package/dist/gc/gcHelpers.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/runtimeLayerCompatState.d.ts +10 -6
- package/dist/runtimeLayerCompatState.d.ts.map +1 -1
- package/dist/runtimeLayerCompatState.js +16 -6
- package/dist/runtimeLayerCompatState.js.map +1 -1
- package/dist/summary/summarizerClientElection.d.ts.map +1 -1
- package/dist/summary/summarizerClientElection.js +1 -0
- package/dist/summary/summarizerClientElection.js.map +1 -1
- package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
- package/dist/summary/summarizerNode/summarizerNodeWithGc.js +1 -0
- package/dist/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -1
- package/dist/summary/summarizerTypes.d.ts +5 -0
- package/dist/summary/summarizerTypes.d.ts.map +1 -1
- package/dist/summary/summarizerTypes.js.map +1 -1
- package/dist/summary/summaryDelayLoadedModule/runningSummarizer.d.ts +3 -1
- package/dist/summary/summaryDelayLoadedModule/runningSummarizer.d.ts.map +1 -1
- package/dist/summary/summaryDelayLoadedModule/runningSummarizer.js +39 -18
- package/dist/summary/summaryDelayLoadedModule/runningSummarizer.js.map +1 -1
- package/dist/summary/summaryDelayLoadedModule/summarizer.d.ts +1 -1
- package/dist/summary/summaryDelayLoadedModule/summarizer.d.ts.map +1 -1
- package/dist/summary/summaryDelayLoadedModule/summarizer.js +13 -11
- package/dist/summary/summaryDelayLoadedModule/summarizer.js.map +1 -1
- package/dist/summary/summaryDelayLoadedModule/summaryGenerator.d.ts +4 -1
- package/dist/summary/summaryDelayLoadedModule/summaryGenerator.d.ts.map +1 -1
- package/dist/summary/summaryDelayLoadedModule/summaryGenerator.js +37 -16
- package/dist/summary/summaryDelayLoadedModule/summaryGenerator.js.map +1 -1
- package/dist/summary/summaryManager.d.ts +1 -1
- package/dist/summary/summaryManager.d.ts.map +1 -1
- package/dist/summary/summaryManager.js +10 -9
- package/dist/summary/summaryManager.js.map +1 -1
- package/eslint.config.mts +4 -4
- package/lib/blobManager/blobManager.d.ts +0 -2
- package/lib/blobManager/blobManager.d.ts.map +1 -1
- package/lib/blobManager/blobManager.js +4 -5
- package/lib/blobManager/blobManager.js.map +1 -1
- package/lib/channelCollection.d.ts +3 -3
- package/lib/channelCollection.d.ts.map +1 -1
- package/lib/channelCollection.js.map +1 -1
- package/lib/containerRuntime.d.ts +5 -0
- package/lib/containerRuntime.d.ts.map +1 -1
- package/lib/containerRuntime.js +13 -7
- package/lib/containerRuntime.js.map +1 -1
- package/lib/dataStoreContext.d.ts +1 -1
- package/lib/dataStoreContext.d.ts.map +1 -1
- package/lib/dataStoreContext.js +2 -1
- package/lib/dataStoreContext.js.map +1 -1
- package/lib/deltaScheduler.d.ts.map +1 -1
- package/lib/deltaScheduler.js +1 -0
- package/lib/deltaScheduler.js.map +1 -1
- package/lib/gc/gcHelpers.d.ts.map +1 -1
- package/lib/gc/gcHelpers.js +1 -0
- package/lib/gc/gcHelpers.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/runtimeLayerCompatState.d.ts +10 -6
- package/lib/runtimeLayerCompatState.d.ts.map +1 -1
- package/lib/runtimeLayerCompatState.js +15 -5
- package/lib/runtimeLayerCompatState.js.map +1 -1
- package/lib/summary/summarizerClientElection.d.ts.map +1 -1
- package/lib/summary/summarizerClientElection.js +1 -0
- package/lib/summary/summarizerClientElection.js.map +1 -1
- package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
- package/lib/summary/summarizerNode/summarizerNodeWithGc.js +1 -0
- package/lib/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -1
- package/lib/summary/summarizerTypes.d.ts +5 -0
- package/lib/summary/summarizerTypes.d.ts.map +1 -1
- package/lib/summary/summarizerTypes.js.map +1 -1
- package/lib/summary/summaryDelayLoadedModule/runningSummarizer.d.ts +3 -1
- package/lib/summary/summaryDelayLoadedModule/runningSummarizer.d.ts.map +1 -1
- package/lib/summary/summaryDelayLoadedModule/runningSummarizer.js +39 -18
- package/lib/summary/summaryDelayLoadedModule/runningSummarizer.js.map +1 -1
- package/lib/summary/summaryDelayLoadedModule/summarizer.d.ts +1 -1
- package/lib/summary/summaryDelayLoadedModule/summarizer.d.ts.map +1 -1
- package/lib/summary/summaryDelayLoadedModule/summarizer.js +13 -11
- package/lib/summary/summaryDelayLoadedModule/summarizer.js.map +1 -1
- package/lib/summary/summaryDelayLoadedModule/summaryGenerator.d.ts +4 -1
- package/lib/summary/summaryDelayLoadedModule/summaryGenerator.d.ts.map +1 -1
- package/lib/summary/summaryDelayLoadedModule/summaryGenerator.js +34 -13
- package/lib/summary/summaryDelayLoadedModule/summaryGenerator.js.map +1 -1
- package/lib/summary/summaryManager.d.ts +1 -1
- package/lib/summary/summaryManager.d.ts.map +1 -1
- package/lib/summary/summaryManager.js +10 -9
- package/lib/summary/summaryManager.js.map +1 -1
- package/package.json +27 -27
- package/src/blobManager/blobManager.ts +3 -7
- package/src/channelCollection.ts +3 -3
- package/src/containerRuntime.ts +19 -6
- package/src/dataStoreContext.ts +3 -2
- package/src/deltaScheduler.ts +1 -0
- package/src/gc/gcHelpers.ts +1 -0
- package/src/packageVersion.ts +1 -1
- package/src/runtimeLayerCompatState.ts +25 -9
- package/src/summary/summarizerClientElection.ts +1 -0
- package/src/summary/summarizerNode/summarizerNodeWithGc.ts +1 -0
- package/src/summary/summarizerTypes.ts +5 -0
- package/src/summary/summaryDelayLoadedModule/runningSummarizer.ts +54 -26
- package/src/summary/summaryDelayLoadedModule/summarizer.ts +13 -11
- package/src/summary/summaryDelayLoadedModule/summaryGenerator.ts +43 -13
- package/src/summary/summaryManager.ts +11 -10
- package/.eslintrc.cjs +0 -30
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summarizerTypes.js","sourceRoot":"","sources":["../../src/summary/summarizerTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgCH,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tIDeltaManager,\n\tContainerWarning,\n} from \"@fluidframework/container-definitions/internal\";\nimport type {\n\tISummarizerEvents,\n\tSummarizerStopReason,\n} from \"@fluidframework/container-runtime-definitions/internal\";\nimport type {\n\tIEventProvider,\n\tITelemetryBaseProperties,\n\tITelemetryBaseLogger,\n} from \"@fluidframework/core-interfaces\";\nimport type { ISummaryTree } from \"@fluidframework/driver-definitions\";\nimport type {\n\tIDocumentMessage,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport type { ISummaryStats } from \"@fluidframework/runtime-definitions/internal\";\nimport type {\n\tITelemetryLoggerExt,\n\tITelemetryLoggerPropertyBag,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { SummarizeReason } from \"./summarizerUtils.js\";\nimport type {\n\tEnqueueSummarizeResult,\n\tISummarizeResults,\n} from \"./summaryDelayLoadedModule/index.js\";\n\nexport const summarizerClientType = \"summarizer\";\n\n/**\n * Similar to AbortSignal, but using promise instead of events\n * @param T - cancellation reason type\n * @internal\n */\nexport interface ICancellationToken<T> {\n\t/**\n\t * Tells if this cancellable token is cancelled\n\t */\n\treadonly cancelled: boolean;\n\t/**\n\t * Promise that gets fulfilled when this cancellable token is cancelled\n\t * @returns reason of cancellation\n\t */\n\treadonly waitCancelled: Promise<T>;\n}\n\n/**\n * Similar to AbortSignal, but using promise instead of events\n * @internal\n */\nexport type ISummaryCancellationToken = ICancellationToken<SummarizerStopReason>;\n\n/**\n * Data required to update internal tracking state after receiving a Summary Ack.\n * @internal\n */\nexport interface IRefreshSummaryAckOptions {\n\t/**\n\t * Handle from the ack's summary op.\n\t */\n\treadonly proposalHandle: string | undefined;\n\t/**\n\t * Handle from the summary ack just received\n\t */\n\treadonly ackHandle: string;\n\t/**\n\t * Reference sequence number from the ack's summary op\n\t */\n\treadonly summaryRefSeq: number;\n\t/**\n\t * Telemetry logger to which telemetry events will be forwarded.\n\t */\n\treadonly summaryLogger: ITelemetryLoggerExt;\n}\n\n/**\n * @internal\n */\nexport interface ISummarizerInternalsProvider {\n\t/**\n\t * Encapsulates the work to walk the internals of the running container to generate a summary\n\t */\n\tsubmitSummary(options: ISubmitSummaryOptions): Promise<SubmitSummaryResult>;\n\n\t/**\n\t * Callback whenever a new SummaryAck is received, to update internal tracking state\n\t */\n\trefreshLatestSummaryAck(options: IRefreshSummaryAckOptions): Promise<void>;\n}\n\n/**\n * @internal\n */\nexport interface ISummarizingWarning extends ContainerWarning {\n\treadonly errorType: \"summarizingError\";\n\treadonly logged: boolean;\n}\n\n/**\n * @internal\n */\nexport interface IConnectableRuntime {\n\treadonly disposed: boolean;\n\treadonly connected: boolean;\n\treadonly clientId: string | undefined;\n\tonce(event: \"connected\" | \"disconnected\" | \"dispose\", listener: () => void): this;\n}\n\n/**\n * @internal\n */\nexport interface ISummarizerRuntime extends IConnectableRuntime {\n\treadonly baseLogger: ITelemetryBaseLogger;\n\t/**\n\t * clientId of parent (non-summarizing) container that owns summarizer container\n\t */\n\treadonly summarizerClientId: string | undefined;\n\treadonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>;\n\tdisposeFn(): void;\n\tcloseFn(): void;\n\ton(\n\t\tevent: \"op\",\n\t\tlistener: (op: ISequencedDocumentMessage, runtimeMessage?: boolean) => void,\n\t): this;\n\toff(\n\t\tevent: \"op\",\n\t\tlistener: (op: ISequencedDocumentMessage, runtimeMessage?: boolean) => void,\n\t): this;\n}\n\n/**\n * Options affecting summarize behavior.\n * @legacy @beta\n */\nexport interface ISummarizeOptions {\n\t/**\n\t * True to generate the full tree with no handle reuse optimizations; defaults to false\n\t */\n\treadonly fullTree?: boolean;\n}\n\n/**\n * @internal\n */\nexport interface ISubmitSummaryOptions extends ISummarizeOptions {\n\t/**\n\t * Logger to use for correlated summary events\n\t */\n\treadonly summaryLogger: ITelemetryLoggerExt;\n\t/**\n\t * Tells when summary process should be cancelled\n\t */\n\treadonly cancellationToken: ISummaryCancellationToken;\n\t/**\n\t * Summarization may be attempted multiple times. This tells whether this is the final summarization attempt.\n\t */\n\treadonly finalAttempt?: boolean;\n\t/**\n\t * The sequence number of the latest summary used to validate if summary state is correct before summarizing\n\t */\n\treadonly latestSummaryRefSeqNum: number;\n}\n\n/**\n * @legacy @beta\n */\nexport interface IOnDemandSummarizeOptions extends ISummarizeOptions {\n\t/**\n\t * Reason for generating summary.\n\t */\n\treadonly reason: string;\n\t/**\n\t * In case of a failure, will attempt to retry based on if the failure is retriable.\n\t */\n\treadonly retryOnFailure?: boolean;\n}\n\n/**\n * Options to use when enqueueing a summarize attempt.\n * @legacy @beta\n */\nexport interface IEnqueueSummarizeOptions extends IOnDemandSummarizeOptions {\n\t/**\n\t * If specified, The summarize attempt will not occur until after this sequence number.\n\t */\n\treadonly afterSequenceNumber?: number;\n\n\t/**\n\t * True to override the existing enqueued summarize attempt if there is one.\n\t * This will guarantee that this attempt gets enqueued. If override is false,\n\t * than an existing enqueued summarize attempt will block a new one from being\n\t * enqueued. There can only be one enqueued at a time. Defaults to false.\n\t */\n\treadonly override?: boolean;\n}\n\n/**\n * In addition to the normal summary tree + stats, this contains additional stats\n * only relevant at the root of the tree.\n * @legacy @beta\n */\nexport interface IGeneratedSummaryStats extends ISummaryStats {\n\t/**\n\t * The total number of data stores in the container.\n\t */\n\treadonly dataStoreCount: number;\n\t/**\n\t * The number of data stores that were summarized in this summary.\n\t */\n\treadonly summarizedDataStoreCount: number;\n\t/**\n\t * The number of data stores whose GC reference state was updated in this summary.\n\t */\n\treadonly gcStateUpdatedDataStoreCount?: number;\n\t/**\n\t * The size of the gc blobs in this summary.\n\t */\n\treadonly gcTotalBlobsSize?: number;\n\t/**\n\t * The number of gc blobs in this summary.\n\t */\n\treadonly gcBlobNodeCount?: number;\n\t/**\n\t * The summary number for a container's summary. Incremented on summaries throughout its lifetime.\n\t */\n\treadonly summaryNumber: number;\n}\n\n/**\n * Type for summarization failures that are retriable.\n * @legacy @beta\n */\nexport interface IRetriableFailureError extends Error {\n\treadonly retryAfterSeconds?: number;\n}\n\n/**\n * Base results for all submitSummary attempts.\n * @legacy @beta\n */\nexport interface IBaseSummarizeResult {\n\treadonly stage: \"base\";\n\t/**\n\t * Retriable error object related to failed summarize attempt.\n\t */\n\treadonly error: IRetriableFailureError | undefined;\n\t/**\n\t * Reference sequence number as of the generate summary attempt.\n\t */\n\treadonly referenceSequenceNumber: number;\n\treadonly minimumSequenceNumber: number;\n}\n\n/**\n * Results of submitSummary after generating the summary tree.\n * @legacy @beta\n */\nexport interface IGenerateSummaryTreeResult extends Omit<IBaseSummarizeResult, \"stage\"> {\n\treadonly stage: \"generate\";\n\t/**\n\t * Generated summary tree.\n\t */\n\treadonly summaryTree: ISummaryTree;\n\t/**\n\t * Stats for generated summary tree.\n\t */\n\treadonly summaryStats: IGeneratedSummaryStats;\n\t/**\n\t * Time it took to generate the summary tree and stats.\n\t */\n\treadonly generateDuration: number;\n}\n\n/**\n * Results of submitSummary after uploading the tree to storage.\n * @legacy @beta\n */\nexport interface IUploadSummaryResult extends Omit<IGenerateSummaryTreeResult, \"stage\"> {\n\treadonly stage: \"upload\";\n\t/**\n\t * The handle returned by storage pointing to the uploaded summary tree.\n\t */\n\treadonly handle: string;\n\t/**\n\t * Time it took to upload the summary tree to storage.\n\t */\n\treadonly uploadDuration: number;\n}\n\n/**\n * Results of submitSummary after submitting the summarize op.\n * @legacy @beta\n */\nexport interface ISubmitSummaryOpResult extends Omit<IUploadSummaryResult, \"stage\" | \"error\"> {\n\treadonly stage: \"submit\";\n\t/**\n\t * The client sequence number of the summarize op submitted for the summary.\n\t */\n\treadonly clientSequenceNumber: number;\n\t/**\n\t * Time it took to submit the summarize op to the broadcasting service.\n\t */\n\treadonly submitOpDuration: number;\n}\n\n/**\n * Strict type representing result of a submitSummary attempt.\n * The result consists of 4 possible stages, each with its own data.\n * The data is cumulative, so each stage will contain the data from the previous stages.\n * If the final \"submitted\" stage is not reached, the result may contain the error object.\n *\n * Stages:\n *\n * 1. \"base\" - stopped before the summary tree was even generated, and the result only contains the base data\n *\n * 2. \"generate\" - the summary tree was generated, and the result will contain that tree + stats\n *\n * 3. \"upload\" - the summary was uploaded to storage, and the result contains the server-provided handle\n *\n * 4. \"submit\" - the summarize op was submitted, and the result contains the op client sequence number.\n * @legacy @beta\n */\nexport type SubmitSummaryResult =\n\t| IBaseSummarizeResult\n\t| IGenerateSummaryTreeResult\n\t| IUploadSummaryResult\n\t| ISubmitSummaryOpResult;\n\n/**\n * The stages of Summarize, used to describe how far progress succeeded in case of a failure at a later stage.\n * @legacy @beta\n */\nexport type SummaryStage = SubmitSummaryResult[\"stage\"] | \"unknown\";\n\n/**\n * The data in summarizer result when submit summary stage fails.\n * @legacy @beta\n */\nexport interface SubmitSummaryFailureData {\n\tstage: SummaryStage;\n}\n\n/**\n * @legacy @beta\n */\nexport type SummarizeResultPart<TSuccess, TFailure = undefined> =\n\t| {\n\t\t\tsuccess: true;\n\t\t\tdata: TSuccess;\n\t }\n\t| {\n\t\t\tsuccess: false;\n\t\t\tdata: TFailure | undefined;\n\t\t\tmessage: string;\n\t\t\terror: IRetriableFailureError;\n\t };\n\n/**\n * @legacy @beta\n */\nexport interface ISummarizer extends IEventProvider<ISummarizerEvents> {\n\t/**\n\t * Allows {@link ISummarizer} to be used with our {@link @fluidframework/core-interfaces#FluidObject} pattern.\n\t */\n\treadonly ISummarizer?: ISummarizer;\n\n\t/*\n\t * Asks summarizer to move to exit.\n\t * Summarizer will finish current processes, which may take a while.\n\t * For example, summarizer may complete last summary before exiting.\n\t */\n\tstop(reason: SummarizerStopReason): void;\n\n\t/* Closes summarizer. Any pending processes (summary in flight) are abandoned. */\n\tclose(): void;\n\n\trun(onBehalfOf: string): Promise<SummarizerStopReason>;\n\n\t/**\n\t * Attempts to generate a summary on demand. If already running, takes no action.\n\t * @param options - options controlling the summarize attempt\n\t * @returns an alreadyRunning promise if a summarize attempt is already in progress,\n\t * which will resolve when the current attempt completes. At that point caller can\n\t * decide to try again or not. Otherwise, it will return an object containing promises\n\t * that resolve as the summarize attempt progresses. They will resolve with success\n\t * false if a failure is encountered.\n\t */\n\tsummarizeOnDemand(options: IOnDemandSummarizeOptions): ISummarizeResults;\n\t/**\n\t * Enqueue an attempt to summarize after the specified sequence number.\n\t * If afterSequenceNumber is provided, the summarize attempt is \"enqueued\"\n\t * to run once an eligible op comes in with sequenceNumber \\>= afterSequenceNumber.\n\t * @param options - options controlling the summarize attempt\n\t * @returns an object containing an alreadyEnqueued flag to indicate if another\n\t * summarize attempt has already been enqueued. It also may contain an overridden flag\n\t * when alreadyEnqueued is true, that indicates whether this attempt forced the\n\t * previous attempt to abort. If this attempt becomes enqueued, it returns an object\n\t * containing promises that resolve as the summarize attempt progresses. They will\n\t * resolve with success false if a failure is encountered.\n\t */\n\tenqueueSummarize(options: IEnqueueSummarizeOptions): EnqueueSummarizeResult;\n}\n\n/**\n * Data about an attempt to summarize used for heuristics.\n */\nexport interface ISummarizeAttempt {\n\t/**\n\t * Reference sequence number when summary was generated or attempted\n\t */\n\treadonly refSequenceNumber: number;\n\n\t/**\n\t * Time of summary attempt after it was sent or attempted\n\t */\n\treadonly summaryTime: number;\n\n\t/**\n\t * Sequence number of summary op\n\t */\n\tsummarySequenceNumber?: number;\n}\n\n/**\n * Data relevant for summary heuristics.\n */\nexport interface ISummarizeHeuristicData {\n\t/**\n\t * Latest received op sequence number\n\t */\n\tlastOpSequenceNumber: number;\n\n\t/**\n\t * Most recent summary attempt from this client\n\t */\n\treadonly lastAttempt: ISummarizeAttempt;\n\n\t/**\n\t * Most recent summary that received an ack\n\t */\n\treadonly lastSuccessfulSummary: Readonly<ISummarizeAttempt>;\n\n\t/**\n\t * Number of runtime ops since last summary\n\t */\n\tnumRuntimeOps: number;\n\n\t/**\n\t * Number of non-runtime ops since last summary\n\t */\n\tnumNonRuntimeOps: number;\n\n\t/**\n\t * Cumulative size in bytes of all the ops since the last summary\n\t */\n\ttotalOpsSize: number;\n\n\t/**\n\t * Wether or not this instance contains adjusted metrics due to missing op data\n\t */\n\thasMissingOpData: boolean;\n\n\t/**\n\t * Updates lastAttempt and lastSuccessfulAttempt based on the last summary.\n\t * @param lastSummary - last ack summary\n\t */\n\tupdateWithLastSummaryAckInfo(lastSummary: ISummarizeAttempt): void;\n\n\t/**\n\t * Records a summary attempt. If the attempt was successfully sent,\n\t * provide the reference sequence number, otherwise it will be set\n\t * to the last seen op sequence number.\n\t * @param referenceSequenceNumber - reference sequence number of sent summary\n\t */\n\trecordAttempt(referenceSequenceNumber?: number): void;\n\n\t/**\n\t * Mark that the last sent summary attempt has received an ack\n\t */\n\tmarkLastAttemptAsSuccessful(): void;\n\n\topsSinceLastSummary: number;\n}\n\n/**\n * Responsible for running heuristics determining when to summarize.\n */\nexport interface ISummarizeHeuristicRunner {\n\t/**\n\t * Start specific heuristic trackers (ex: idle timer)\n\t */\n\tstart(): void;\n\n\t/**\n\t * Runs the heuristics to determine if it should try to summarize\n\t */\n\trun(): void;\n\n\t/**\n\t * Runs a different heuristic to check if it should summarize before closing\n\t */\n\tshouldRunLastSummary(): boolean;\n\n\t/**\n\t * Disposes of resources\n\t */\n\tdispose(): void;\n}\n\ntype ISummarizeTelemetryRequiredProperties =\n\t/**\n\t * Reason code for attempting to summarize\n\t */\n\t\"summarizeReason\";\n\ntype ISummarizeTelemetryOptionalProperties =\n\t/**\n\t * Number of attempts within the last time window, used for calculating the throttle delay.\n\t */\n\t| \"summaryAttempts\"\n\t/**\n\t * Summarization may be attempted multiple times. This tells whether this is the final summarization attempt\n\t */\n\t| \"finalAttempt\"\n\t| keyof ISummarizeOptions;\n\nexport type ISummarizeTelemetryProperties = Pick<\n\tITelemetryBaseProperties,\n\tISummarizeTelemetryRequiredProperties\n> &\n\tPartial<Pick<ITelemetryBaseProperties, ISummarizeTelemetryOptionalProperties>>;\n\n/**\n * Strategy used to heuristically determine when we should run a summary\n */\nexport interface ISummaryHeuristicStrategy {\n\t/**\n\t * Summarize reason for this summarize heuristic strategy (ex: \"maxTime\")\n\t */\n\tsummarizeReason: Readonly<SummarizeReason>;\n\n\t/**\n\t * Determines if this strategy's summarize criteria been met\n\t * @param configuration - summary configuration we are to check against\n\t * @param heuristicData - heuristic data used to confirm conditions are met\n\t */\n\tshouldRunSummary(\n\t\tconfiguration: ISummaryConfigurationHeuristics,\n\t\theuristicData: ISummarizeHeuristicData,\n\t): boolean;\n}\n\ntype SummaryGeneratorRequiredTelemetryProperties =\n\t/**\n\t * True to generate the full tree with no handle reuse optimizations\n\t */\n\t| \"fullTree\"\n\t/**\n\t * Time since we last attempted to generate a summary\n\t */\n\t| \"timeSinceLastAttempt\"\n\t/**\n\t * Time since we last successfully generated a summary\n\t */\n\t| \"timeSinceLastSummary\";\n\ntype SummaryGeneratorOptionalTelemetryProperties =\n\t/**\n\t * Reference sequence number as of the generate summary attempt.\n\t */\n\t| \"referenceSequenceNumber\"\n\t/**\n\t * minimum sequence number (at the reference sequence number)\n\t */\n\t| \"minimumSequenceNumber\"\n\t/**\n\t * Delta between the current reference sequence number and the reference sequence number of the last attempt\n\t */\n\t| \"opsSinceLastAttempt\"\n\t/**\n\t * Delta between the current reference sequence number and the reference sequence number of the last summary\n\t */\n\t| \"opsSinceLastSummary\"\n\t/**\n\t * Delta in sum of op sizes between the current reference sequence number and the reference\n\t * sequence number of the last summary\n\t */\n\t| \"opsSizesSinceLastSummary\"\n\t/**\n\t * Delta between the number of non-runtime ops since the last summary\n\t */\n\t| \"nonRuntimeOpsSinceLastSummary\"\n\t/**\n\t * Delta between the number of runtime ops since the last summary\n\t */\n\t| \"runtimeOpsSinceLastSummary\"\n\t/**\n\t * Wether or not this instance contains adjusted metrics due to missing op data\n\t */\n\t| \"hasMissingOpData\"\n\t/**\n\t * Time it took to generate the summary tree and stats.\n\t */\n\t| \"generateDuration\"\n\t/**\n\t * The handle returned by storage pointing to the uploaded summary tree.\n\t */\n\t| \"handle\"\n\t/**\n\t * Time it took to upload the summary tree to storage.\n\t */\n\t| \"uploadDuration\"\n\t/**\n\t * The client sequence number of the summarize op submitted for the summary.\n\t */\n\t| \"clientSequenceNumber\"\n\t/**\n\t * Time it took for this summary to be acked after it was generated\n\t */\n\t| \"ackWaitDuration\"\n\t/**\n\t * Reference sequence number of the ack/nack message\n\t */\n\t| \"ackNackSequenceNumber\"\n\t/**\n\t * Actual sequence number of the summary op proposal.\n\t */\n\t| \"summarySequenceNumber\"\n\t/**\n\t * Optional Retry-After time in seconds. If specified, the client should wait this many seconds before retrying.\n\t */\n\t| \"nackRetryAfter\"\n\t/**\n\t * The stage at which the submit summary method failed at. This can help determine what type of failure we have\n\t */\n\t| \"stage\";\n\nexport type SummaryGeneratorTelemetry = Pick<\n\tITelemetryBaseProperties,\n\tSummaryGeneratorRequiredTelemetryProperties\n> &\n\tPartial<Pick<ITelemetryBaseProperties, SummaryGeneratorOptionalTelemetryProperties>>;\n\nexport interface ISummarizeRunnerTelemetry extends ITelemetryLoggerPropertyBag {\n\t/**\n\t * Number of times the summarizer run.\n\t */\n\tsummarizeCount: () => number;\n\t/**\n\t * Number of successful attempts to summarize.\n\t */\n\tsummarizerSuccessfulAttempts: () => number;\n}\n\n/**\n * @legacy @beta\n */\nexport interface ISummaryBaseConfiguration {\n\t/**\n\t * Delay before first attempt to spawn summarizing container.\n\t */\n\tinitialSummarizerDelayMs: number;\n\n\t/**\n\t * Defines the maximum allowed time to wait for a pending summary ack.\n\t * The maximum amount of time client will wait for a summarize is the minimum of\n\t * maxSummarizeAckWaitTime (currently 3 * 60 * 1000) and maxAckWaitTime.\n\t */\n\tmaxAckWaitTime: number;\n\t/**\n\t * Defines the maximum number of Ops in between Summaries that can be\n\t * allowed before forcibly electing a new summarizer client.\n\t */\n\tmaxOpsSinceLastSummary: number;\n}\n\n/**\n * @legacy @beta\n */\nexport interface ISummaryConfigurationHeuristics extends ISummaryBaseConfiguration {\n\tstate: \"enabled\";\n\t/**\n\t * Defines the maximum allowed time, since the last received Ack, before running the summary\n\t * with reason maxTime.\n\t * For example, say we receive ops one by one just before the idle time is triggered.\n\t * In this case, we still want to run a summary since it's been a while since the last summary.\n\t */\n\tmaxTime: number;\n\t/**\n\t * Defines the maximum number of Ops, since the last received Ack, that can be allowed\n\t * before running the summary with reason maxOps.\n\t */\n\tmaxOps: number;\n\t/**\n\t * Defines the minimum number of Ops, since the last received Ack, that can be allowed\n\t * before running the last summary.\n\t */\n\tminOpsForLastSummaryAttempt: number;\n\t/**\n\t * Defines the lower boundary for the allowed time in between summarizations.\n\t * Pairs with maxIdleTime to form a range.\n\t * For example, if we only receive 1 op, we don't want to have the same idle time as say 100 ops.\n\t * Based on the boundaries we set in minIdleTime and maxIdleTime, the idle time will change\n\t * linearly depending on the number of ops we receive.\n\t */\n\tminIdleTime: number;\n\t/**\n\t * Defines the upper boundary for the allowed time in between summarizations.\n\t * Pairs with minIdleTime to form a range.\n\t * For example, if we only receive 1 op, we don't want to have the same idle time as say 100 ops.\n\t * Based on the boundaries we set in minIdleTime and maxIdleTime, the idle time will change\n\t * linearly depending on the number of ops we receive.\n\t */\n\tmaxIdleTime: number;\n\t/**\n\t * Runtime op weight to use in heuristic summarizing.\n\t * This number is a multiplier on the number of runtime ops we process when running summarize heuristics.\n\t * For example: (multiplier) * (number of runtime ops) = weighted number of runtime ops\n\t */\n\truntimeOpWeight: number;\n\t/**\n\t * Non-runtime op weight to use in heuristic summarizing\n\t * This number is a multiplier on the number of non-runtime ops we process when running summarize heuristics.\n\t * For example: (multiplier) * (number of non-runtime ops) = weighted number of non-runtime ops\n\t */\n\tnonRuntimeOpWeight: number;\n\n\t/**\n\t * Number of ops since last summary needed before a non-runtime op can trigger running summary heuristics.\n\t *\n\t * Note: Any runtime ops sent before the threshold is reached will trigger heuristics normally.\n\t * This threshold ONLY applies to non-runtime ops triggering summaries.\n\t *\n\t * For example: Say the threshold is 20. Sending 19 non-runtime ops will not trigger any heuristic checks.\n\t * Sending the 20th non-runtime op will trigger the heuristic checks for summarizing.\n\t */\n\tnonRuntimeHeuristicThreshold?: number;\n}\n\n/**\n * @legacy @beta\n */\nexport interface ISummaryConfigurationDisableSummarizer {\n\tstate: \"disabled\";\n}\n\n/**\n * @legacy @beta\n */\nexport interface ISummaryConfigurationDisableHeuristics extends ISummaryBaseConfiguration {\n\tstate: \"disableHeuristics\";\n}\n\n/**\n * Configuration used internally to indicate on-demand summaries only (no election/heuristics).\n * @legacy @beta\n */\nexport interface ISummaryConfigurationWithSummaryOnRequest extends ISummaryBaseConfiguration {\n\tstate: \"summaryOnRequest\";\n}\n\n/**\n * @legacy @beta\n */\nexport type ISummaryConfiguration =\n\t| ISummaryConfigurationDisableSummarizer\n\t| ISummaryConfigurationDisableHeuristics\n\t| ISummaryConfigurationHeuristics\n\t| ISummaryConfigurationWithSummaryOnRequest;\n"]}
|
|
1
|
+
{"version":3,"file":"summarizerTypes.js","sourceRoot":"","sources":["../../src/summary/summarizerTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiCH,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tIDeltaManager,\n\tContainerWarning,\n} from \"@fluidframework/container-definitions/internal\";\nimport type {\n\tISummarizerEvents,\n\tSummarizerStopReason,\n} from \"@fluidframework/container-runtime-definitions/internal\";\nimport type {\n\tIEventProvider,\n\tITelemetryBaseProperties,\n\tITelemetryBaseLogger,\n} from \"@fluidframework/core-interfaces\";\nimport type { ISummaryTree } from \"@fluidframework/driver-definitions\";\nimport type {\n\tIDocumentMessage,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport type { ISummaryStats } from \"@fluidframework/runtime-definitions/internal\";\nimport type { TelemetryContext } from \"@fluidframework/runtime-utils/internal\";\nimport type {\n\tITelemetryLoggerExt,\n\tITelemetryLoggerPropertyBag,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { SummarizeReason } from \"./summarizerUtils.js\";\nimport type {\n\tEnqueueSummarizeResult,\n\tISummarizeResults,\n} from \"./summaryDelayLoadedModule/index.js\";\n\nexport const summarizerClientType = \"summarizer\";\n\n/**\n * Similar to AbortSignal, but using promise instead of events\n * @param T - cancellation reason type\n * @internal\n */\nexport interface ICancellationToken<T> {\n\t/**\n\t * Tells if this cancellable token is cancelled\n\t */\n\treadonly cancelled: boolean;\n\t/**\n\t * Promise that gets fulfilled when this cancellable token is cancelled\n\t * @returns reason of cancellation\n\t */\n\treadonly waitCancelled: Promise<T>;\n}\n\n/**\n * Similar to AbortSignal, but using promise instead of events\n * @internal\n */\nexport type ISummaryCancellationToken = ICancellationToken<SummarizerStopReason>;\n\n/**\n * Data required to update internal tracking state after receiving a Summary Ack.\n * @internal\n */\nexport interface IRefreshSummaryAckOptions {\n\t/**\n\t * Handle from the ack's summary op.\n\t */\n\treadonly proposalHandle: string | undefined;\n\t/**\n\t * Handle from the summary ack just received\n\t */\n\treadonly ackHandle: string;\n\t/**\n\t * Reference sequence number from the ack's summary op\n\t */\n\treadonly summaryRefSeq: number;\n\t/**\n\t * Telemetry logger to which telemetry events will be forwarded.\n\t */\n\treadonly summaryLogger: ITelemetryLoggerExt;\n}\n\n/**\n * @internal\n */\nexport interface ISummarizerInternalsProvider {\n\t/**\n\t * Encapsulates the work to walk the internals of the running container to generate a summary\n\t */\n\tsubmitSummary(options: ISubmitSummaryOptions): Promise<SubmitSummaryResult>;\n\n\t/**\n\t * Callback whenever a new SummaryAck is received, to update internal tracking state\n\t */\n\trefreshLatestSummaryAck(options: IRefreshSummaryAckOptions): Promise<void>;\n}\n\n/**\n * @internal\n */\nexport interface ISummarizingWarning extends ContainerWarning {\n\treadonly errorType: \"summarizingError\";\n\treadonly logged: boolean;\n}\n\n/**\n * @internal\n */\nexport interface IConnectableRuntime {\n\treadonly disposed: boolean;\n\treadonly connected: boolean;\n\treadonly clientId: string | undefined;\n\tonce(event: \"connected\" | \"disconnected\" | \"dispose\", listener: () => void): this;\n}\n\n/**\n * @internal\n */\nexport interface ISummarizerRuntime extends IConnectableRuntime {\n\treadonly baseLogger: ITelemetryBaseLogger;\n\t/**\n\t * clientId of parent (non-summarizing) container that owns summarizer container\n\t */\n\treadonly summarizerClientId: string | undefined;\n\treadonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>;\n\tdisposeFn(): void;\n\tcloseFn(): void;\n\ton(\n\t\tevent: \"op\",\n\t\tlistener: (op: ISequencedDocumentMessage, runtimeMessage?: boolean) => void,\n\t): this;\n\toff(\n\t\tevent: \"op\",\n\t\tlistener: (op: ISequencedDocumentMessage, runtimeMessage?: boolean) => void,\n\t): this;\n}\n\n/**\n * Options affecting summarize behavior.\n * @legacy @beta\n */\nexport interface ISummarizeOptions {\n\t/**\n\t * True to generate the full tree with no handle reuse optimizations; defaults to false\n\t */\n\treadonly fullTree?: boolean;\n}\n\n/**\n * @internal\n */\nexport interface ISubmitSummaryOptions extends ISummarizeOptions {\n\t/**\n\t * Logger to use for correlated summary events\n\t */\n\treadonly summaryLogger: ITelemetryLoggerExt;\n\t/**\n\t * Tells when summary process should be cancelled\n\t */\n\treadonly cancellationToken: ISummaryCancellationToken;\n\t/**\n\t * Summarization may be attempted multiple times. This tells whether this is the final summarization attempt.\n\t */\n\treadonly finalAttempt?: boolean;\n\t/**\n\t * The sequence number of the latest summary used to validate if summary state is correct before summarizing\n\t */\n\treadonly latestSummaryRefSeqNum: number;\n\t/**\n\t * Shared telemetry context for the current summarize attempt.\n\t */\n\ttelemetryContext?: TelemetryContext;\n}\n\n/**\n * @legacy @beta\n */\nexport interface IOnDemandSummarizeOptions extends ISummarizeOptions {\n\t/**\n\t * Reason for generating summary.\n\t */\n\treadonly reason: string;\n\t/**\n\t * In case of a failure, will attempt to retry based on if the failure is retriable.\n\t */\n\treadonly retryOnFailure?: boolean;\n}\n\n/**\n * Options to use when enqueueing a summarize attempt.\n * @legacy @beta\n */\nexport interface IEnqueueSummarizeOptions extends IOnDemandSummarizeOptions {\n\t/**\n\t * If specified, The summarize attempt will not occur until after this sequence number.\n\t */\n\treadonly afterSequenceNumber?: number;\n\n\t/**\n\t * True to override the existing enqueued summarize attempt if there is one.\n\t * This will guarantee that this attempt gets enqueued. If override is false,\n\t * than an existing enqueued summarize attempt will block a new one from being\n\t * enqueued. There can only be one enqueued at a time. Defaults to false.\n\t */\n\treadonly override?: boolean;\n}\n\n/**\n * In addition to the normal summary tree + stats, this contains additional stats\n * only relevant at the root of the tree.\n * @legacy @beta\n */\nexport interface IGeneratedSummaryStats extends ISummaryStats {\n\t/**\n\t * The total number of data stores in the container.\n\t */\n\treadonly dataStoreCount: number;\n\t/**\n\t * The number of data stores that were summarized in this summary.\n\t */\n\treadonly summarizedDataStoreCount: number;\n\t/**\n\t * The number of data stores whose GC reference state was updated in this summary.\n\t */\n\treadonly gcStateUpdatedDataStoreCount?: number;\n\t/**\n\t * The size of the gc blobs in this summary.\n\t */\n\treadonly gcTotalBlobsSize?: number;\n\t/**\n\t * The number of gc blobs in this summary.\n\t */\n\treadonly gcBlobNodeCount?: number;\n\t/**\n\t * The summary number for a container's summary. Incremented on summaries throughout its lifetime.\n\t */\n\treadonly summaryNumber: number;\n}\n\n/**\n * Type for summarization failures that are retriable.\n * @legacy @beta\n */\nexport interface IRetriableFailureError extends Error {\n\treadonly retryAfterSeconds?: number;\n}\n\n/**\n * Base results for all submitSummary attempts.\n * @legacy @beta\n */\nexport interface IBaseSummarizeResult {\n\treadonly stage: \"base\";\n\t/**\n\t * Retriable error object related to failed summarize attempt.\n\t */\n\treadonly error: IRetriableFailureError | undefined;\n\t/**\n\t * Reference sequence number as of the generate summary attempt.\n\t */\n\treadonly referenceSequenceNumber: number;\n\treadonly minimumSequenceNumber: number;\n}\n\n/**\n * Results of submitSummary after generating the summary tree.\n * @legacy @beta\n */\nexport interface IGenerateSummaryTreeResult extends Omit<IBaseSummarizeResult, \"stage\"> {\n\treadonly stage: \"generate\";\n\t/**\n\t * Generated summary tree.\n\t */\n\treadonly summaryTree: ISummaryTree;\n\t/**\n\t * Stats for generated summary tree.\n\t */\n\treadonly summaryStats: IGeneratedSummaryStats;\n\t/**\n\t * Time it took to generate the summary tree and stats.\n\t */\n\treadonly generateDuration: number;\n}\n\n/**\n * Results of submitSummary after uploading the tree to storage.\n * @legacy @beta\n */\nexport interface IUploadSummaryResult extends Omit<IGenerateSummaryTreeResult, \"stage\"> {\n\treadonly stage: \"upload\";\n\t/**\n\t * The handle returned by storage pointing to the uploaded summary tree.\n\t */\n\treadonly handle: string;\n\t/**\n\t * Time it took to upload the summary tree to storage.\n\t */\n\treadonly uploadDuration: number;\n}\n\n/**\n * Results of submitSummary after submitting the summarize op.\n * @legacy @beta\n */\nexport interface ISubmitSummaryOpResult extends Omit<IUploadSummaryResult, \"stage\" | \"error\"> {\n\treadonly stage: \"submit\";\n\t/**\n\t * The client sequence number of the summarize op submitted for the summary.\n\t */\n\treadonly clientSequenceNumber: number;\n\t/**\n\t * Time it took to submit the summarize op to the broadcasting service.\n\t */\n\treadonly submitOpDuration: number;\n}\n\n/**\n * Strict type representing result of a submitSummary attempt.\n * The result consists of 4 possible stages, each with its own data.\n * The data is cumulative, so each stage will contain the data from the previous stages.\n * If the final \"submitted\" stage is not reached, the result may contain the error object.\n *\n * Stages:\n *\n * 1. \"base\" - stopped before the summary tree was even generated, and the result only contains the base data\n *\n * 2. \"generate\" - the summary tree was generated, and the result will contain that tree + stats\n *\n * 3. \"upload\" - the summary was uploaded to storage, and the result contains the server-provided handle\n *\n * 4. \"submit\" - the summarize op was submitted, and the result contains the op client sequence number.\n * @legacy @beta\n */\nexport type SubmitSummaryResult =\n\t| IBaseSummarizeResult\n\t| IGenerateSummaryTreeResult\n\t| IUploadSummaryResult\n\t| ISubmitSummaryOpResult;\n\n/**\n * The stages of Summarize, used to describe how far progress succeeded in case of a failure at a later stage.\n * @legacy @beta\n */\nexport type SummaryStage = SubmitSummaryResult[\"stage\"] | \"unknown\";\n\n/**\n * The data in summarizer result when submit summary stage fails.\n * @legacy @beta\n */\nexport interface SubmitSummaryFailureData {\n\tstage: SummaryStage;\n}\n\n/**\n * @legacy @beta\n */\nexport type SummarizeResultPart<TSuccess, TFailure = undefined> =\n\t| {\n\t\t\tsuccess: true;\n\t\t\tdata: TSuccess;\n\t }\n\t| {\n\t\t\tsuccess: false;\n\t\t\tdata: TFailure | undefined;\n\t\t\tmessage: string;\n\t\t\terror: IRetriableFailureError;\n\t };\n\n/**\n * @legacy @beta\n */\nexport interface ISummarizer extends IEventProvider<ISummarizerEvents> {\n\t/**\n\t * Allows {@link ISummarizer} to be used with our {@link @fluidframework/core-interfaces#FluidObject} pattern.\n\t */\n\treadonly ISummarizer?: ISummarizer;\n\n\t/*\n\t * Asks summarizer to move to exit.\n\t * Summarizer will finish current processes, which may take a while.\n\t * For example, summarizer may complete last summary before exiting.\n\t */\n\tstop(reason: SummarizerStopReason): void;\n\n\t/* Closes summarizer. Any pending processes (summary in flight) are abandoned. */\n\tclose(): void;\n\n\trun(onBehalfOf: string): Promise<SummarizerStopReason>;\n\n\t/**\n\t * Attempts to generate a summary on demand. If already running, takes no action.\n\t * @param options - options controlling the summarize attempt\n\t * @returns an alreadyRunning promise if a summarize attempt is already in progress,\n\t * which will resolve when the current attempt completes. At that point caller can\n\t * decide to try again or not. Otherwise, it will return an object containing promises\n\t * that resolve as the summarize attempt progresses. They will resolve with success\n\t * false if a failure is encountered.\n\t */\n\tsummarizeOnDemand(options: IOnDemandSummarizeOptions): ISummarizeResults;\n\t/**\n\t * Enqueue an attempt to summarize after the specified sequence number.\n\t * If afterSequenceNumber is provided, the summarize attempt is \"enqueued\"\n\t * to run once an eligible op comes in with sequenceNumber \\>= afterSequenceNumber.\n\t * @param options - options controlling the summarize attempt\n\t * @returns an object containing an alreadyEnqueued flag to indicate if another\n\t * summarize attempt has already been enqueued. It also may contain an overridden flag\n\t * when alreadyEnqueued is true, that indicates whether this attempt forced the\n\t * previous attempt to abort. If this attempt becomes enqueued, it returns an object\n\t * containing promises that resolve as the summarize attempt progresses. They will\n\t * resolve with success false if a failure is encountered.\n\t */\n\tenqueueSummarize(options: IEnqueueSummarizeOptions): EnqueueSummarizeResult;\n}\n\n/**\n * Data about an attempt to summarize used for heuristics.\n */\nexport interface ISummarizeAttempt {\n\t/**\n\t * Reference sequence number when summary was generated or attempted\n\t */\n\treadonly refSequenceNumber: number;\n\n\t/**\n\t * Time of summary attempt after it was sent or attempted\n\t */\n\treadonly summaryTime: number;\n\n\t/**\n\t * Sequence number of summary op\n\t */\n\tsummarySequenceNumber?: number;\n}\n\n/**\n * Data relevant for summary heuristics.\n */\nexport interface ISummarizeHeuristicData {\n\t/**\n\t * Latest received op sequence number\n\t */\n\tlastOpSequenceNumber: number;\n\n\t/**\n\t * Most recent summary attempt from this client\n\t */\n\treadonly lastAttempt: ISummarizeAttempt;\n\n\t/**\n\t * Most recent summary that received an ack\n\t */\n\treadonly lastSuccessfulSummary: Readonly<ISummarizeAttempt>;\n\n\t/**\n\t * Number of runtime ops since last summary\n\t */\n\tnumRuntimeOps: number;\n\n\t/**\n\t * Number of non-runtime ops since last summary\n\t */\n\tnumNonRuntimeOps: number;\n\n\t/**\n\t * Cumulative size in bytes of all the ops since the last summary\n\t */\n\ttotalOpsSize: number;\n\n\t/**\n\t * Wether or not this instance contains adjusted metrics due to missing op data\n\t */\n\thasMissingOpData: boolean;\n\n\t/**\n\t * Updates lastAttempt and lastSuccessfulAttempt based on the last summary.\n\t * @param lastSummary - last ack summary\n\t */\n\tupdateWithLastSummaryAckInfo(lastSummary: ISummarizeAttempt): void;\n\n\t/**\n\t * Records a summary attempt. If the attempt was successfully sent,\n\t * provide the reference sequence number, otherwise it will be set\n\t * to the last seen op sequence number.\n\t * @param referenceSequenceNumber - reference sequence number of sent summary\n\t */\n\trecordAttempt(referenceSequenceNumber?: number): void;\n\n\t/**\n\t * Mark that the last sent summary attempt has received an ack\n\t */\n\tmarkLastAttemptAsSuccessful(): void;\n\n\topsSinceLastSummary: number;\n}\n\n/**\n * Responsible for running heuristics determining when to summarize.\n */\nexport interface ISummarizeHeuristicRunner {\n\t/**\n\t * Start specific heuristic trackers (ex: idle timer)\n\t */\n\tstart(): void;\n\n\t/**\n\t * Runs the heuristics to determine if it should try to summarize\n\t */\n\trun(): void;\n\n\t/**\n\t * Runs a different heuristic to check if it should summarize before closing\n\t */\n\tshouldRunLastSummary(): boolean;\n\n\t/**\n\t * Disposes of resources\n\t */\n\tdispose(): void;\n}\n\ntype ISummarizeTelemetryRequiredProperties =\n\t/**\n\t * Reason code for attempting to summarize\n\t */\n\t\"summarizeReason\";\n\ntype ISummarizeTelemetryOptionalProperties =\n\t/**\n\t * Number of attempts within the last time window, used for calculating the throttle delay.\n\t */\n\t| \"summaryAttempts\"\n\t/**\n\t * Summarization may be attempted multiple times. This tells whether this is the final summarization attempt\n\t */\n\t| \"finalAttempt\"\n\t| keyof ISummarizeOptions;\n\nexport type ISummarizeTelemetryProperties = Pick<\n\tITelemetryBaseProperties,\n\tISummarizeTelemetryRequiredProperties\n> &\n\tPartial<Pick<ITelemetryBaseProperties, ISummarizeTelemetryOptionalProperties>>;\n\n/**\n * Strategy used to heuristically determine when we should run a summary\n */\nexport interface ISummaryHeuristicStrategy {\n\t/**\n\t * Summarize reason for this summarize heuristic strategy (ex: \"maxTime\")\n\t */\n\tsummarizeReason: Readonly<SummarizeReason>;\n\n\t/**\n\t * Determines if this strategy's summarize criteria been met\n\t * @param configuration - summary configuration we are to check against\n\t * @param heuristicData - heuristic data used to confirm conditions are met\n\t */\n\tshouldRunSummary(\n\t\tconfiguration: ISummaryConfigurationHeuristics,\n\t\theuristicData: ISummarizeHeuristicData,\n\t): boolean;\n}\n\ntype SummaryGeneratorRequiredTelemetryProperties =\n\t/**\n\t * True to generate the full tree with no handle reuse optimizations\n\t */\n\t| \"fullTree\"\n\t/**\n\t * Time since we last attempted to generate a summary\n\t */\n\t| \"timeSinceLastAttempt\"\n\t/**\n\t * Time since we last successfully generated a summary\n\t */\n\t| \"timeSinceLastSummary\";\n\ntype SummaryGeneratorOptionalTelemetryProperties =\n\t/**\n\t * Reference sequence number as of the generate summary attempt.\n\t */\n\t| \"referenceSequenceNumber\"\n\t/**\n\t * minimum sequence number (at the reference sequence number)\n\t */\n\t| \"minimumSequenceNumber\"\n\t/**\n\t * Delta between the current reference sequence number and the reference sequence number of the last attempt\n\t */\n\t| \"opsSinceLastAttempt\"\n\t/**\n\t * Delta between the current reference sequence number and the reference sequence number of the last summary\n\t */\n\t| \"opsSinceLastSummary\"\n\t/**\n\t * Delta in sum of op sizes between the current reference sequence number and the reference\n\t * sequence number of the last summary\n\t */\n\t| \"opsSizesSinceLastSummary\"\n\t/**\n\t * Delta between the number of non-runtime ops since the last summary\n\t */\n\t| \"nonRuntimeOpsSinceLastSummary\"\n\t/**\n\t * Delta between the number of runtime ops since the last summary\n\t */\n\t| \"runtimeOpsSinceLastSummary\"\n\t/**\n\t * Wether or not this instance contains adjusted metrics due to missing op data\n\t */\n\t| \"hasMissingOpData\"\n\t/**\n\t * Time it took to generate the summary tree and stats.\n\t */\n\t| \"generateDuration\"\n\t/**\n\t * The handle returned by storage pointing to the uploaded summary tree.\n\t */\n\t| \"handle\"\n\t/**\n\t * Time it took to upload the summary tree to storage.\n\t */\n\t| \"uploadDuration\"\n\t/**\n\t * The client sequence number of the summarize op submitted for the summary.\n\t */\n\t| \"clientSequenceNumber\"\n\t/**\n\t * Time it took for this summary to be acked after it was generated\n\t */\n\t| \"ackWaitDuration\"\n\t/**\n\t * Reference sequence number of the ack/nack message\n\t */\n\t| \"ackNackSequenceNumber\"\n\t/**\n\t * Actual sequence number of the summary op proposal.\n\t */\n\t| \"summarySequenceNumber\"\n\t/**\n\t * Optional Retry-After time in seconds. If specified, the client should wait this many seconds before retrying.\n\t */\n\t| \"nackRetryAfter\"\n\t/**\n\t * The stage at which the submit summary method failed at. This can help determine what type of failure we have\n\t */\n\t| \"stage\";\n\nexport type SummaryGeneratorTelemetry = Pick<\n\tITelemetryBaseProperties,\n\tSummaryGeneratorRequiredTelemetryProperties\n> &\n\tPartial<Pick<ITelemetryBaseProperties, SummaryGeneratorOptionalTelemetryProperties>>;\n\nexport interface ISummarizeRunnerTelemetry extends ITelemetryLoggerPropertyBag {\n\t/**\n\t * Number of times the summarizer run.\n\t */\n\tsummarizeCount: () => number;\n\t/**\n\t * Number of successful attempts to summarize.\n\t */\n\tsummarizerSuccessfulAttempts: () => number;\n}\n\n/**\n * @legacy @beta\n */\nexport interface ISummaryBaseConfiguration {\n\t/**\n\t * Delay before first attempt to spawn summarizing container.\n\t */\n\tinitialSummarizerDelayMs: number;\n\n\t/**\n\t * Defines the maximum allowed time to wait for a pending summary ack.\n\t * The maximum amount of time client will wait for a summarize is the minimum of\n\t * maxSummarizeAckWaitTime (currently 3 * 60 * 1000) and maxAckWaitTime.\n\t */\n\tmaxAckWaitTime: number;\n\t/**\n\t * Defines the maximum number of Ops in between Summaries that can be\n\t * allowed before forcibly electing a new summarizer client.\n\t */\n\tmaxOpsSinceLastSummary: number;\n}\n\n/**\n * @legacy @beta\n */\nexport interface ISummaryConfigurationHeuristics extends ISummaryBaseConfiguration {\n\tstate: \"enabled\";\n\t/**\n\t * Defines the maximum allowed time, since the last received Ack, before running the summary\n\t * with reason maxTime.\n\t * For example, say we receive ops one by one just before the idle time is triggered.\n\t * In this case, we still want to run a summary since it's been a while since the last summary.\n\t */\n\tmaxTime: number;\n\t/**\n\t * Defines the maximum number of Ops, since the last received Ack, that can be allowed\n\t * before running the summary with reason maxOps.\n\t */\n\tmaxOps: number;\n\t/**\n\t * Defines the minimum number of Ops, since the last received Ack, that can be allowed\n\t * before running the last summary.\n\t */\n\tminOpsForLastSummaryAttempt: number;\n\t/**\n\t * Defines the lower boundary for the allowed time in between summarizations.\n\t * Pairs with maxIdleTime to form a range.\n\t * For example, if we only receive 1 op, we don't want to have the same idle time as say 100 ops.\n\t * Based on the boundaries we set in minIdleTime and maxIdleTime, the idle time will change\n\t * linearly depending on the number of ops we receive.\n\t */\n\tminIdleTime: number;\n\t/**\n\t * Defines the upper boundary for the allowed time in between summarizations.\n\t * Pairs with minIdleTime to form a range.\n\t * For example, if we only receive 1 op, we don't want to have the same idle time as say 100 ops.\n\t * Based on the boundaries we set in minIdleTime and maxIdleTime, the idle time will change\n\t * linearly depending on the number of ops we receive.\n\t */\n\tmaxIdleTime: number;\n\t/**\n\t * Runtime op weight to use in heuristic summarizing.\n\t * This number is a multiplier on the number of runtime ops we process when running summarize heuristics.\n\t * For example: (multiplier) * (number of runtime ops) = weighted number of runtime ops\n\t */\n\truntimeOpWeight: number;\n\t/**\n\t * Non-runtime op weight to use in heuristic summarizing\n\t * This number is a multiplier on the number of non-runtime ops we process when running summarize heuristics.\n\t * For example: (multiplier) * (number of non-runtime ops) = weighted number of non-runtime ops\n\t */\n\tnonRuntimeOpWeight: number;\n\n\t/**\n\t * Number of ops since last summary needed before a non-runtime op can trigger running summary heuristics.\n\t *\n\t * Note: Any runtime ops sent before the threshold is reached will trigger heuristics normally.\n\t * This threshold ONLY applies to non-runtime ops triggering summaries.\n\t *\n\t * For example: Say the threshold is 20. Sending 19 non-runtime ops will not trigger any heuristic checks.\n\t * Sending the 20th non-runtime op will trigger the heuristic checks for summarizing.\n\t */\n\tnonRuntimeHeuristicThreshold?: number;\n}\n\n/**\n * @legacy @beta\n */\nexport interface ISummaryConfigurationDisableSummarizer {\n\tstate: \"disabled\";\n}\n\n/**\n * @legacy @beta\n */\nexport interface ISummaryConfigurationDisableHeuristics extends ISummaryBaseConfiguration {\n\tstate: \"disableHeuristics\";\n}\n\n/**\n * Configuration used internally to indicate on-demand summaries only (no election/heuristics).\n * @legacy @beta\n */\nexport interface ISummaryConfigurationWithSummaryOnRequest extends ISummaryBaseConfiguration {\n\tstate: \"summaryOnRequest\";\n}\n\n/**\n * @legacy @beta\n */\nexport type ISummaryConfiguration =\n\t| ISummaryConfigurationDisableSummarizer\n\t| ISummaryConfigurationDisableHeuristics\n\t| ISummaryConfigurationHeuristics\n\t| ISummaryConfigurationWithSummaryOnRequest;\n"]}
|
|
@@ -42,7 +42,6 @@ export declare class RunningSummarizer extends TypedEventEmitter<ISummarizerEven
|
|
|
42
42
|
private summarizeCount;
|
|
43
43
|
private totalSuccessfulAttempts;
|
|
44
44
|
private initialized;
|
|
45
|
-
private readonly runtimeListener;
|
|
46
45
|
/**
|
|
47
46
|
* The maximum number of summary attempts to do when submit summary fails.
|
|
48
47
|
*/
|
|
@@ -65,6 +64,9 @@ export declare class RunningSummarizer extends TypedEventEmitter<ISummarizerEven
|
|
|
65
64
|
*/
|
|
66
65
|
private processIncomingSummaryAcks;
|
|
67
66
|
dispose(): void;
|
|
67
|
+
private readonly eventsCleanup;
|
|
68
|
+
private setupEventListeners;
|
|
69
|
+
private cleanupEventListeners;
|
|
68
70
|
/**
|
|
69
71
|
* RunningSummarizer's logger includes the sequenced index of the current summary on each event.
|
|
70
72
|
* If some other Summarizer code wants that event on their logs they can get it here,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runningSummarizer.d.ts","sourceRoot":"","sources":["../../../src/summary/summaryDelayLoadedModule/runningSummarizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAEX,iBAAiB,EAEjB,oBAAoB,EACpB,MAAM,wDAAwD,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEzF,OAAO,EAGN,KAAK,yBAAyB,EAC9B,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAMN,KAAK,mBAAmB,EACxB,MAAM,0CAA0C,CAAC;AAGlD,OAAO,KAAK,EACX,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EAEzB,qBAAqB,EACrB,uBAAuB,EAGvB,kBAAkB,EAGlB,yBAAyB,EACzB,qBAAqB,EACrB,mBAAmB,EACnB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAEX,qBAAqB,EACrB,iBAAiB,EACjB,MAAM,yBAAyB,CAAC;AAKjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAIzF;;;;;;GAMG;AACH,qBAAa,iBACZ,SAAQ,iBAAiB,CAAC,iBAAiB,CAC3C,YAAW,WAAW;
|
|
1
|
+
{"version":3,"file":"runningSummarizer.d.ts","sourceRoot":"","sources":["../../../src/summary/summaryDelayLoadedModule/runningSummarizer.ts"],"names":[],"mappings":"AAA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KACrB,mBAAmB,GAAG,SAAS,CAGpB;IAEd;;OAEG;IACH,OAAO,CAAC,8BAA8B,CAAS;IAExC,QAAQ,CAAC,EAAE,EAAE,yBAAyB,EAAE,cAAc,EAAE,OAAO,GAAG,IAAI;IA8B7E;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB;IAgB3B,OAAO,CAAC,6BAA6B;IAWxB,QAAQ,CAAC,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;YAyCjD,SAAS;IAuBvB,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,kBAAkB;IAW1B;;;;;;;;OAQG;YACW,mBAAmB;IAsBjC;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;IA+ExB;;OAEG;IACH,OAAO,CAAC,YAAY;IA0BpB;;;OAGG;YACW,uBAAuB;IA6KrC;;;OAGG;YACW,4BAA4B;IAsB1C;;OAEG;IACI,iBAAiB,CACvB,OAAO,EAAE,yBAAyB,EAClC,cAAc,GAAE,sBAAqD,GACnE,iBAAiB;IAkCpB;;OAEG;IACI,gBAAgB,CAAC,OAAO,EAAE,wBAAwB,GAAG,sBAAsB;IAmClF,OAAO,CAAC,qBAAqB;IAwB7B,OAAO,CAAC,sBAAsB;CAS9B"}
|
|
@@ -110,6 +110,7 @@ export class RunningSummarizer extends TypedEventEmitter {
|
|
|
110
110
|
}, error);
|
|
111
111
|
});
|
|
112
112
|
};
|
|
113
|
+
this.eventsCleanup = [];
|
|
113
114
|
/**
|
|
114
115
|
* RunningSummarizer's logger includes the sequenced index of the current summary on each event.
|
|
115
116
|
* If some other Summarizer code wants that event on their logs they can get it here,
|
|
@@ -175,11 +176,6 @@ export class RunningSummarizer extends TypedEventEmitter {
|
|
|
175
176
|
await this.refreshLatestSummaryAckAndHandleError(options);
|
|
176
177
|
}
|
|
177
178
|
}, this.summaryWatcher, this.mc.logger);
|
|
178
|
-
// Listen to runtime for ops
|
|
179
|
-
this.runtimeListener = (op, runtimeMessage) => {
|
|
180
|
-
this.handleOp(op, runtimeMessage === true);
|
|
181
|
-
};
|
|
182
|
-
this.runtime.on("op", this.runtimeListener);
|
|
183
179
|
// The max attempts for submit failures can be overridden via a feature flag. This allows us to
|
|
184
180
|
// tweak this as per telemetry data until we arrive at a stable number.
|
|
185
181
|
// If its set to a number higher than `defaultMaxAttemptsForSubmitFailures`, it will be ignored.
|
|
@@ -189,6 +185,7 @@ export class RunningSummarizer extends TypedEventEmitter {
|
|
|
189
185
|
overrideMaxAttempts < defaultMaxAttemptsForSubmitFailures
|
|
190
186
|
? overrideMaxAttempts
|
|
191
187
|
: defaultMaxAttemptsForSubmitFailures;
|
|
188
|
+
this.setupEventListeners();
|
|
192
189
|
}
|
|
193
190
|
async handleSummaryAck(ack) {
|
|
194
191
|
const refSequenceNumber = ack.summaryOp.referenceSequenceNumber;
|
|
@@ -235,7 +232,7 @@ export class RunningSummarizer extends TypedEventEmitter {
|
|
|
235
232
|
}
|
|
236
233
|
}
|
|
237
234
|
dispose() {
|
|
238
|
-
this.
|
|
235
|
+
this.cleanupEventListeners();
|
|
239
236
|
this.summaryWatcher.dispose();
|
|
240
237
|
this.heuristicRunner?.dispose();
|
|
241
238
|
this.heuristicRunner = undefined;
|
|
@@ -245,6 +242,27 @@ export class RunningSummarizer extends TypedEventEmitter {
|
|
|
245
242
|
this._disposed = true;
|
|
246
243
|
this.stopping = true;
|
|
247
244
|
}
|
|
245
|
+
setupEventListeners() {
|
|
246
|
+
const runtimeListener = (op, runtimeMessage) => {
|
|
247
|
+
this.handleOp(op, runtimeMessage === true);
|
|
248
|
+
};
|
|
249
|
+
this.runtime.on("op", runtimeListener);
|
|
250
|
+
this.eventsCleanup.push(() => this.runtime.off("op", runtimeListener));
|
|
251
|
+
// Forward events
|
|
252
|
+
for (const event of ["summarizeTimeout"]) {
|
|
253
|
+
const listener = (...args) => {
|
|
254
|
+
this.emit(event, ...args);
|
|
255
|
+
};
|
|
256
|
+
this.generator.on(event, listener);
|
|
257
|
+
this.eventsCleanup.push(() => this.generator.off(event, listener));
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
cleanupEventListeners() {
|
|
261
|
+
for (const cleanup of this.eventsCleanup) {
|
|
262
|
+
cleanup();
|
|
263
|
+
}
|
|
264
|
+
this.eventsCleanup.length = 0;
|
|
265
|
+
}
|
|
248
266
|
handleOp(op, runtimeMessage) {
|
|
249
267
|
this.heuristicData.lastOpSequenceNumber = op.sequenceNumber;
|
|
250
268
|
if (runtimeMessage) {
|
|
@@ -421,10 +439,11 @@ export class RunningSummarizer extends TypedEventEmitter {
|
|
|
421
439
|
numUnsummarizedNonRuntimeOps: this.heuristicData.numNonRuntimeOps,
|
|
422
440
|
isLastSummary,
|
|
423
441
|
});
|
|
424
|
-
|
|
442
|
+
summaryLogger.sendErrorEvent({
|
|
425
443
|
eventName: "SummarizeFailed",
|
|
426
444
|
maxAttempts: 1,
|
|
427
445
|
summaryAttempts: 1,
|
|
446
|
+
isLastSummary,
|
|
428
447
|
}, result.error);
|
|
429
448
|
if (isLastSummary) {
|
|
430
449
|
this.lastSummarizeFailureEventProps = {
|
|
@@ -462,23 +481,23 @@ export class RunningSummarizer extends TypedEventEmitter {
|
|
|
462
481
|
}, () => {
|
|
463
482
|
this.afterSummaryAction();
|
|
464
483
|
}).catch((error) => {
|
|
465
|
-
this.mc.logger.sendErrorEvent({ eventName: "UnexpectedSummarizeError" }, error);
|
|
484
|
+
this.mc.logger.sendErrorEvent({ eventName: "UnexpectedSummarizeError", summarizeReason: reason }, error);
|
|
466
485
|
});
|
|
467
486
|
}
|
|
468
487
|
/**
|
|
469
488
|
* Tries to summarize with retries where retry is based on the failure params.
|
|
470
489
|
* For example, summarization may be retried for failures with "retryAfterSeconds" param.
|
|
471
490
|
*/
|
|
472
|
-
async trySummarizeWithRetries(reason) {
|
|
491
|
+
async trySummarizeWithRetries(reason, summarizeOptions = {}) {
|
|
473
492
|
// Helper to set summarize options, telemetry properties and call summarize.
|
|
474
493
|
const attemptSummarize = (attemptNumber, finalAttempt) => {
|
|
475
|
-
const
|
|
476
|
-
fullTree: false,
|
|
494
|
+
const attemptSummarizeOptions = {
|
|
495
|
+
fullTree: summarizeOptions.fullTree ?? false,
|
|
477
496
|
};
|
|
478
497
|
const summarizeProps = {
|
|
479
498
|
summarizeReason: reason,
|
|
480
499
|
summaryAttempts: attemptNumber,
|
|
481
|
-
...
|
|
500
|
+
...attemptSummarizeOptions,
|
|
482
501
|
finalAttempt,
|
|
483
502
|
};
|
|
484
503
|
const summaryLogger = createChildLogger({
|
|
@@ -486,7 +505,7 @@ export class RunningSummarizer extends TypedEventEmitter {
|
|
|
486
505
|
properties: { all: summarizeProps },
|
|
487
506
|
});
|
|
488
507
|
const summaryOptions = {
|
|
489
|
-
...
|
|
508
|
+
...attemptSummarizeOptions,
|
|
490
509
|
summaryLogger,
|
|
491
510
|
cancellationToken: this.cancellationToken,
|
|
492
511
|
finalAttempt,
|
|
@@ -605,6 +624,8 @@ export class RunningSummarizer extends TypedEventEmitter {
|
|
|
605
624
|
eventName: "SummarizeFailed",
|
|
606
625
|
maxAttempts,
|
|
607
626
|
summaryAttempts: currentAttempt,
|
|
627
|
+
summarizeReason: reason,
|
|
628
|
+
isLastSummary: reason === "lastSummary",
|
|
608
629
|
}, error);
|
|
609
630
|
this.lastSummarizeFailureEventProps = {
|
|
610
631
|
currentAttempt,
|
|
@@ -620,8 +641,8 @@ export class RunningSummarizer extends TypedEventEmitter {
|
|
|
620
641
|
* Attempts to generate a summary on demand with retries in case of failures. The retry logic is the same
|
|
621
642
|
* as heuristics based summaries.
|
|
622
643
|
*/
|
|
623
|
-
async summarizeOnDemandWithRetries(reason, resultsBuilder) {
|
|
624
|
-
const results = await this.trySummarizeWithRetries(reason);
|
|
644
|
+
async summarizeOnDemandWithRetries(reason, resultsBuilder, summarizeOptions = {}) {
|
|
645
|
+
const results = await this.trySummarizeWithRetries(reason, summarizeOptions);
|
|
625
646
|
if (results === undefined) {
|
|
626
647
|
resultsBuilder.fail("Summarization was canceled", new RetriableSummaryError("Summarization was canceled"));
|
|
627
648
|
return resultsBuilder.build();
|
|
@@ -648,9 +669,9 @@ export class RunningSummarizer extends TypedEventEmitter {
|
|
|
648
669
|
// The heuristics are blocking concurrent summarize attempts.
|
|
649
670
|
throw new UsageError("Attempted to run an already-running summarizer on demand");
|
|
650
671
|
}
|
|
651
|
-
const { reason, ...summarizeOptions } = options;
|
|
652
|
-
if (
|
|
653
|
-
this.summarizeOnDemandWithRetries(`onDemand;${reason}`, resultsBuilder).catch((error) => {
|
|
672
|
+
const { reason, retryOnFailure, ...summarizeOptions } = options;
|
|
673
|
+
if (retryOnFailure === true) {
|
|
674
|
+
this.summarizeOnDemandWithRetries(`onDemand;${reason}`, resultsBuilder, summarizeOptions).catch((error) => {
|
|
654
675
|
resultsBuilder.fail("summarize failed", error);
|
|
655
676
|
});
|
|
656
677
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runningSummarizer.js","sourceRoot":"","sources":["../../../src/summary/summaryDelayLoadedModule/runningSummarizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAQjE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,qCAAqC,CAAC;AAC5F,OAAO,EACN,gBAAgB,EAChB,WAAW,GAEX,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAEN,UAAU,EACV,iBAAiB,EACjB,4BAA4B,EAC5B,YAAY,GAEZ,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAiB/C,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAwB,MAAM,uBAAuB,CAAC;AAO/F,OAAO,EAAE,kBAAkB,EAAE,mCAAmC,EAAE,MAAM,iBAAiB,CAAC;AAC1F,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CA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d,CAAC;QACF,OAAO,IAAI,CAAC;IACb,CAAC;IAEO,sBAAsB;QAC7B,IAAI,IAAI,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;YACxC,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,IAAI,CACvC,uCAAuC,EACvC,IAAI,qBAAqB,CAAC,uCAAuC,CAAC,CAClE,CAAC;YACF,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QAClC,CAAC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport type {\n\tISummarizeEventProps,\n\tISummarizerEvents,\n\tISummarizerObservabilityProps,\n\tSummarizerStopReason,\n} from \"@fluidframework/container-runtime-definitions/internal\";\nimport type { IDisposable, ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert, Deferred, PromiseTimer, delay } from \"@fluidframework/core-utils/internal\";\nimport {\n\tDriverErrorTypes,\n\tMessageType,\n\ttype ISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\ttype MonitoringContext,\n\tUsageError,\n\tcreateChildLogger,\n\tcreateChildMonitoringContext,\n\tisFluidError,\n\ttype ITelemetryLoggerExt,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { opSize } from \"../../opProperties.js\";\nimport type {\n\tIEnqueueSummarizeOptions,\n\tIOnDemandSummarizeOptions,\n\tIRefreshSummaryAckOptions,\n\tIRetriableFailureError,\n\tISubmitSummaryOptions,\n\tISummarizeHeuristicData,\n\tISummarizeHeuristicRunner,\n\tISummarizeOptions,\n\tISummarizerRuntime,\n\tISummarizeRunnerTelemetry,\n\tISummarizeTelemetryProperties,\n\tISummaryCancellationToken,\n\tISummaryConfiguration,\n\tSubmitSummaryResult,\n} from \"../summarizerTypes.js\";\nimport { raceTimer, RetriableSummaryError, type SummarizeReason } from \"../summarizerUtils.js\";\nimport type {\n\tIAckedSummary,\n\tIClientSummaryWatcher,\n\tSummaryCollection,\n} from \"../summaryCollection.js\";\n\nimport { defaultMaxAttempts, defaultMaxAttemptsForSubmitFailures } from \"./summarizer.js\";\nimport { SummarizeHeuristicRunner } from \"./summarizerHeuristics.js\";\nimport { SummaryGenerator } from \"./summaryGenerator.js\";\nimport { SummarizeResultBuilder } from \"./summaryResultBuilder.js\";\nimport type { EnqueueSummarizeResult, ISummarizeResults } from \"./summaryResultTypes.js\";\n\nconst maxSummarizeAckWaitTime = 10 * 60 * 1000; // 10 minutes\n\n/**\n * An instance of RunningSummarizer manages the heuristics for summarizing.\n * Until disposed, the instance of RunningSummarizer can assume that it is\n * in a state of running, meaning it is connected and initialized. It keeps\n * track of summaries that it is generating as they are broadcast and acked/nacked.\n * This object is created and controlled by Summarizer object.\n */\nexport class RunningSummarizer\n\textends TypedEventEmitter<ISummarizerEvents>\n\timplements IDisposable\n{\n\tpublic static async start(\n\t\tlogger: ITelemetryBaseLogger,\n\t\tsummaryWatcher: IClientSummaryWatcher,\n\t\tconfiguration: ISummaryConfiguration,\n\n\t\tsubmitSummaryCallback: (options: ISubmitSummaryOptions) => Promise<SubmitSummaryResult>,\n\n\t\trefreshLatestSummaryAckCallback: (options: IRefreshSummaryAckOptions) => Promise<void>,\n\t\theuristicData: ISummarizeHeuristicData,\n\t\tsummaryCollection: SummaryCollection,\n\n\t\tcancellationToken: ISummaryCancellationToken,\n\t\tstopSummarizerCallback: (reason: SummarizerStopReason) => void,\n\n\t\truntime: ISummarizerRuntime,\n\t): Promise<RunningSummarizer> {\n\t\tconst summarizer = new RunningSummarizer(\n\t\t\tlogger,\n\t\t\tsummaryWatcher,\n\t\t\tconfiguration,\n\t\t\tsubmitSummaryCallback,\n\t\t\trefreshLatestSummaryAckCallback,\n\t\t\theuristicData,\n\t\t\tsummaryCollection,\n\t\t\tcancellationToken,\n\t\t\tstopSummarizerCallback,\n\t\t\truntime,\n\t\t);\n\n\t\t// If there have been any acks newer that the one this client loaded from until now, process them before\n\t\t// starting the running summarizer which will trigger summary heuristics.\n\t\t// This is done primarily to handle scenarios where the summarizer loads from a cached snapshot and there\n\t\t// is newer one available. The ack for the newer summary is processed before summarizing because otherwise\n\t\t// that summary would fail as it has an older parent.\n\t\tlet nextReferenceSequenceNumber = runtime.deltaManager.initialSequenceNumber + 1;\n\t\tconst latestAck = summaryCollection.latestAck;\n\t\tif (\n\t\t\tlatestAck !== undefined &&\n\t\t\tlatestAck.summaryOp.referenceSequenceNumber >= nextReferenceSequenceNumber\n\t\t) {\n\t\t\tawait summarizer.handleSummaryAck(latestAck);\n\t\t\tnextReferenceSequenceNumber = latestAck.summaryOp.referenceSequenceNumber + 1;\n\t\t}\n\n\t\tawait summarizer.waitStart();\n\n\t\t// Process summary acks asynchronously\n\t\t// Note: no exceptions are thrown from processIncomingSummaryAcks handler as it handles all exceptions\n\t\tsummarizer.processIncomingSummaryAcks(nextReferenceSequenceNumber).catch((error) => {\n\t\t\tcreateChildLogger({ logger }).sendErrorEvent(\n\t\t\t\t{ eventName: \"HandleSummaryAckFatalError\" },\n\t\t\t\terror,\n\t\t\t);\n\t\t});\n\n\t\t// Update heuristic counts\n\t\t// By the time we get here, there are potentially ops missing from the heuristic summary counts\n\t\t// Examples of where this could happen:\n\t\t// 1. Op is processed during the time that we are initiating the RunningSummarizer instance but before we\n\t\t// listen for the op events (will get missed by the handlers in the current workflow)\n\t\t// 2. Op was sequenced after the last time we summarized (op sequence number > summarize ref sequence number)\n\t\tconst diff =\n\t\t\truntime.deltaManager.lastSequenceNumber -\n\t\t\t(heuristicData.lastSuccessfulSummary.refSequenceNumber +\n\t\t\t\theuristicData.numNonRuntimeOps +\n\t\t\t\theuristicData.numRuntimeOps);\n\t\theuristicData.hasMissingOpData = diff > 0;\n\n\t\tif (heuristicData.hasMissingOpData) {\n\t\t\t// Split the diff 50-50 and increment the counts appropriately\n\t\t\theuristicData.numNonRuntimeOps += Math.ceil(diff / 2);\n\t\t\theuristicData.numRuntimeOps += Math.floor(diff / 2);\n\t\t}\n\n\t\t// Update last seq number (in case the handlers haven't processed anything yet)\n\t\theuristicData.lastOpSequenceNumber = runtime.deltaManager.lastSequenceNumber;\n\n\t\t// Start heuristics\n\t\tsummarizer.heuristicRunner?.start();\n\t\tsummarizer.heuristicRunner?.run();\n\n\t\treturn summarizer;\n\t}\n\n\tpublic get disposed(): boolean {\n\t\treturn this._disposed;\n\t}\n\tprivate stopping = false;\n\tprivate _disposed = false;\n\tprivate summarizingLock: Promise<void> | undefined;\n\tprivate tryWhileSummarizing = false;\n\tprivate readonly pendingAckTimer: PromiseTimer;\n\tprivate heuristicRunner?: ISummarizeHeuristicRunner;\n\tprivate readonly generator: SummaryGenerator;\n\tprivate readonly mc: MonitoringContext;\n\n\tprivate enqueuedSummary:\n\t\t| {\n\t\t\t\treason: SummarizeReason;\n\t\t\t\tafterSequenceNumber: number;\n\t\t\t\tsummarizeOptions: ISummarizeOptions;\n\t\t\t\treadonly resultsBuilder: SummarizeResultBuilder;\n\t\t }\n\t\t| undefined;\n\tprivate summarizeCount = 0;\n\tprivate totalSuccessfulAttempts = 0;\n\tprivate initialized = false;\n\n\tprivate readonly runtimeListener: (\n\t\top: ISequencedDocumentMessage,\n\t\truntimeMessage?: boolean,\n\t) => void;\n\n\t/**\n\t * The maximum number of summary attempts to do when submit summary fails.\n\t */\n\tprivate readonly maxAttemptsForSubmitFailures: number;\n\n\t/**\n\t * These are necessary to store outside of methods because of the logic around runnning a lastSummary.\n\t * We want the lastSummary to also be captured as \"all attempts failed\".\n\t */\n\tprivate lastSummarizeFailureEventProps: Omit<ISummarizeEventProps, \"result\"> | undefined =\n\t\tundefined;\n\n\tprivate constructor(\n\t\tbaseLogger: ITelemetryBaseLogger,\n\t\tprivate readonly summaryWatcher: IClientSummaryWatcher,\n\t\tprivate readonly configuration: ISummaryConfiguration,\n\t\tprivate readonly submitSummaryCallback: (\n\t\t\toptions: ISubmitSummaryOptions,\n\t\t) => Promise<SubmitSummaryResult>,\n\t\tprivate readonly refreshLatestSummaryAckCallback: (\n\t\t\toptions: IRefreshSummaryAckOptions,\n\t\t) => Promise<void>,\n\t\tprivate readonly heuristicData: ISummarizeHeuristicData,\n\t\tprivate readonly summaryCollection: SummaryCollection,\n\n\t\tprivate readonly cancellationToken: ISummaryCancellationToken,\n\t\tprivate readonly stopSummarizerCallback: (reason: SummarizerStopReason) => void,\n\n\t\tprivate readonly runtime: ISummarizerRuntime,\n\t) {\n\t\tsuper();\n\n\t\tconst telemetryProps: ISummarizeRunnerTelemetry = {\n\t\t\tsummarizeCount: () => this.summarizeCount,\n\t\t\tsummarizerSuccessfulAttempts: () => this.totalSuccessfulAttempts,\n\t\t};\n\n\t\tthis.mc = createChildMonitoringContext({\n\t\t\tlogger: baseLogger,\n\t\t\tnamespace: \"Running\",\n\t\t\tproperties: {\n\t\t\t\tall: telemetryProps,\n\t\t\t},\n\t\t});\n\n\t\t// Only create heuristics when in 'enabled' mode.\n\t\t// This bypasses heuristics for 'disableHeuristics' and 'summaryOnRequest' configurations.\n\t\tif (configuration.state === \"enabled\") {\n\t\t\tthis.heuristicRunner = new SummarizeHeuristicRunner(\n\t\t\t\theuristicData,\n\t\t\t\tconfiguration,\n\t\t\t\t(reason) => this.trySummarize(reason),\n\t\t\t\tthis.mc.logger,\n\t\t\t);\n\t\t}\n\n\t\tassert(\n\t\t\tthis.configuration.state !== \"disabled\",\n\t\t\t0x2eb /* \"Summary not supported with configuration disabled\" */,\n\t\t);\n\n\t\t// Cap the maximum amount of time client will wait for a summarize op ack to maxSummarizeAckWaitTime\n\t\t// configuration.maxAckWaitTime is composed from defaults, server values, and runtime overrides\n\n\t\tconst maxAckWaitTime = Math.min(\n\t\t\tthis.configuration.maxAckWaitTime,\n\t\t\tmaxSummarizeAckWaitTime,\n\t\t);\n\n\t\tthis.pendingAckTimer = new PromiseTimer(maxAckWaitTime, () => {\n\t\t\t// Note: summarizeCount (from ChildLogger definition) may be 0,\n\t\t\t// since this code path is hit when RunningSummarizer first starts up,\n\t\t\t// before this instance has kicked off a new summarize run.\n\t\t\tthis.mc.logger.sendErrorEvent({\n\t\t\t\teventName: \"SummaryAckWaitTimeout\",\n\t\t\t\tmessage: \"Pending summary ack not received in time\",\n\t\t\t\tmaxAckWaitTime,\n\t\t\t\treferenceSequenceNumber: this.heuristicData.lastAttempt.refSequenceNumber,\n\t\t\t\tsummarySequenceNumber: this.heuristicData.lastAttempt.summarySequenceNumber,\n\t\t\t\ttimePending: Date.now() - this.heuristicData.lastAttempt.summaryTime,\n\t\t\t});\n\t\t});\n\t\t// Set up pending ack timeout by op timestamp differences for previous summaries.\n\t\tsummaryCollection.setPendingAckTimerTimeoutCallback(maxAckWaitTime, () => {\n\t\t\tif (this.pendingAckTimer.hasTimer) {\n\t\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"MissingSummaryAckFoundByOps\",\n\t\t\t\t\treferenceSequenceNumber: this.heuristicData.lastAttempt.refSequenceNumber,\n\t\t\t\t\tsummarySequenceNumber: this.heuristicData.lastAttempt.summarySequenceNumber,\n\t\t\t\t});\n\t\t\t\tthis.pendingAckTimer.clear();\n\t\t\t}\n\t\t});\n\n\t\tconst immediatelyRefreshLatestSummaryAck =\n\t\t\tthis.mc.config.getBoolean(\"Fluid.Summarizer.immediatelyRefreshLatestSummaryAck\") ?? true;\n\t\tthis.generator = new SummaryGenerator(\n\t\t\tthis.pendingAckTimer,\n\t\t\tthis.heuristicData,\n\t\t\tthis.submitSummaryCallback,\n\t\t\t() => {\n\t\t\t\tthis.totalSuccessfulAttempts++;\n\t\t\t},\n\n\t\t\tasync (options: IRefreshSummaryAckOptions) => {\n\t\t\t\tif (immediatelyRefreshLatestSummaryAck) {\n\t\t\t\t\tawait this.refreshLatestSummaryAckAndHandleError(options);\n\t\t\t\t}\n\t\t\t},\n\t\t\tthis.summaryWatcher,\n\t\t\tthis.mc.logger,\n\t\t);\n\n\t\t// Listen to runtime for ops\n\t\tthis.runtimeListener = (op: ISequencedDocumentMessage, runtimeMessage?: boolean) => {\n\t\t\tthis.handleOp(op, runtimeMessage === true);\n\t\t};\n\t\tthis.runtime.on(\"op\", this.runtimeListener);\n\n\t\t// The max attempts for submit failures can be overridden via a feature flag. This allows us to\n\t\t// tweak this as per telemetry data until we arrive at a stable number.\n\t\t// If its set to a number higher than `defaultMaxAttemptsForSubmitFailures`, it will be ignored.\n\t\tconst overrideMaxAttempts = this.mc.config.getNumber(\n\t\t\t\"Fluid.Summarizer.AttemptsForSubmitFailures\",\n\t\t);\n\t\tthis.maxAttemptsForSubmitFailures =\n\t\t\toverrideMaxAttempts !== undefined &&\n\t\t\toverrideMaxAttempts < defaultMaxAttemptsForSubmitFailures\n\t\t\t\t? overrideMaxAttempts\n\t\t\t\t: defaultMaxAttemptsForSubmitFailures;\n\t}\n\n\tprivate async handleSummaryAck(ack: IAckedSummary): Promise<void> {\n\t\tconst refSequenceNumber = ack.summaryOp.referenceSequenceNumber;\n\t\tconst summaryLogger = this.tryGetCorrelatedLogger(refSequenceNumber) ?? this.mc.logger;\n\t\tconst summaryOpHandle = ack.summaryOp.contents.handle;\n\t\tconst summaryAckHandle = ack.summaryAck.contents.handle;\n\t\twhile (this.summarizingLock !== undefined) {\n\t\t\tsummaryLogger.sendTelemetryEvent({\n\t\t\t\teventName: \"RefreshAttemptWithSummarizerRunning\",\n\t\t\t\treferenceSequenceNumber: refSequenceNumber,\n\t\t\t\tproposalHandle: summaryOpHandle,\n\t\t\t\tackHandle: summaryAckHandle,\n\t\t\t});\n\t\t\tawait this.summarizingLock;\n\t\t}\n\n\t\t// Make sure we block any summarizer from being executed/enqueued while\n\t\t// executing the refreshLatestSummaryAck.\n\t\t// https://dev.azure.com/fluidframework/internal/_workitems/edit/779\n\t\tawait this.lockedSummaryAction(\n\t\t\t() => {},\n\t\t\tasync () => {\n\t\t\t\tconst options: IRefreshSummaryAckOptions = {\n\t\t\t\t\tproposalHandle: summaryOpHandle,\n\t\t\t\t\tackHandle: summaryAckHandle,\n\t\t\t\t\tsummaryRefSeq: refSequenceNumber,\n\t\t\t\t\tsummaryLogger,\n\t\t\t\t};\n\t\t\t\tawait this.refreshLatestSummaryAckAndHandleError(options);\n\t\t\t},\n\t\t\t() => {},\n\t\t);\n\t}\n\n\tprivate readonly refreshLatestSummaryAckAndHandleError = async (\n\t\toptions: IRefreshSummaryAckOptions,\n\t): Promise<void> => {\n\t\treturn this.refreshLatestSummaryAckCallback(options).catch(async (error) => {\n\t\t\t// If the error is 404, so maybe the fetched version no longer exists on server. We just\n\t\t\t// ignore this error in that case, as that means we will have another summaryAck for the\n\t\t\t// latest version with which we will refresh the state. However in case of single commit\n\t\t\t// summary, we might be missing a summary ack, so in that case we are still fine as the\n\t\t\t// code in `submitSummary` function in container runtime, will refresh the latest state\n\t\t\t// by calling `prefetchLatestSummaryThenClose`. We will load the next summarizer from the\n\t\t\t// updated state and be fine.\n\t\t\tconst isIgnoredError =\n\t\t\t\tisFluidError(error) &&\n\t\t\t\terror.errorType === DriverErrorTypes.fileNotFoundOrAccessDeniedError;\n\n\t\t\toptions.summaryLogger.sendTelemetryEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: isIgnoredError\n\t\t\t\t\t\t? \"HandleSummaryAckErrorIgnored\"\n\t\t\t\t\t\t: \"HandleLastSummaryAckError\",\n\t\t\t\t\treferenceSequenceNumber: options.summaryRefSeq,\n\t\t\t\t\tproposalHandle: options.proposalHandle,\n\t\t\t\t\tackHandle: options.ackHandle,\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\t\t});\n\t};\n\n\t/**\n\t * Responsible for receiving and processing all the summary acks.\n\t * It starts processing ACKs after the one for the summary this client loaded from (initialSequenceNumber). Any\n\t * ACK before that is not interesting as it will simply be ignored.\n\t *\n\t * @param referenceSequenceNumber - The referenceSequenceNumber of the summary from which to start processing\n\t * acks.\n\t */\n\tprivate async processIncomingSummaryAcks(referenceSequenceNumber: number): Promise<void> {\n\t\t// Start waiting for acks that are for summaries newer that the one this client loaded from.\n\t\tlet nextReferenceSequenceNumber = referenceSequenceNumber;\n\t\twhile (!this.disposed) {\n\t\t\tconst ackedSummary = await this.summaryCollection.waitSummaryAck(\n\t\t\t\tnextReferenceSequenceNumber,\n\t\t\t);\n\t\t\tawait this.handleSummaryAck(ackedSummary);\n\t\t\tnextReferenceSequenceNumber = ackedSummary.summaryOp.referenceSequenceNumber + 1;\n\t\t}\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.runtime.off(\"op\", this.runtimeListener);\n\t\tthis.summaryWatcher.dispose();\n\t\tthis.heuristicRunner?.dispose();\n\t\tthis.heuristicRunner = undefined;\n\t\tthis.generator.dispose();\n\t\tthis.pendingAckTimer.clear();\n\t\tthis.disposeEnqueuedSummary();\n\t\tthis._disposed = true;\n\t\tthis.stopping = true;\n\t}\n\n\t/**\n\t * RunningSummarizer's logger includes the sequenced index of the current summary on each event.\n\t * If some other Summarizer code wants that event on their logs they can get it here,\n\t * but only if they're logging about that same summary.\n\t * @param summaryOpRefSeq - RefSeq number of the summary op, to ensure the log correlation will be correct\n\t */\n\tpublic tryGetCorrelatedLogger = (\n\t\tsummaryOpRefSeq: number,\n\t): ITelemetryLoggerExt | undefined =>\n\t\tthis.heuristicData.lastAttempt.refSequenceNumber === summaryOpRefSeq\n\t\t\t? this.mc.logger\n\t\t\t: undefined;\n\n\t/**\n\t * We only want a single heuristic runner micro-task (will provide better optimized grouping of ops)\n\t */\n\tprivate heuristicRunnerMicroTaskExists = false;\n\n\tpublic handleOp(op: ISequencedDocumentMessage, runtimeMessage: boolean): void {\n\t\tthis.heuristicData.lastOpSequenceNumber = op.sequenceNumber;\n\n\t\tif (runtimeMessage) {\n\t\t\tthis.heuristicData.numRuntimeOps++;\n\t\t} else {\n\t\t\tthis.heuristicData.numNonRuntimeOps++;\n\t\t}\n\n\t\tthis.heuristicData.totalOpsSize += opSize(op);\n\n\t\t// Check for enqueued on-demand summaries; Intentionally do nothing otherwise\n\t\tif (\n\t\t\tthis.initialized &&\n\t\t\tthis.opCanTriggerSummary(op, runtimeMessage) &&\n\t\t\t!this.tryRunEnqueuedSummary() &&\n\t\t\t!this.heuristicRunnerMicroTaskExists\n\t\t) {\n\t\t\tthis.heuristicRunnerMicroTaskExists = true;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-floating-promises\n\t\t\tPromise.resolve()\n\t\t\t\t.then(() => {\n\t\t\t\t\tthis.heuristicRunner?.run();\n\t\t\t\t})\n\t\t\t\t.finally(() => {\n\t\t\t\t\tthis.heuristicRunnerMicroTaskExists = false;\n\t\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Can the given op trigger a summary?\n\t * # Currently always prevents summaries for Summarize and SummaryAck/Nack ops\n\t * @param op - op to check\n\t * @returns true if this op can trigger a summary\n\t */\n\tprivate opCanTriggerSummary(\n\t\top: ISequencedDocumentMessage,\n\t\truntimeMessage: boolean,\n\t): boolean {\n\t\tswitch (op.type) {\n\t\t\tcase MessageType.Summarize:\n\t\t\tcase MessageType.SummaryAck:\n\t\t\tcase MessageType.SummaryNack: {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn runtimeMessage || this.nonRuntimeOpCanTriggerSummary();\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate nonRuntimeOpCanTriggerSummary(): boolean {\n\t\tconst opsSinceLastAck =\n\t\t\tthis.heuristicData.lastOpSequenceNumber -\n\t\t\tthis.heuristicData.lastSuccessfulSummary.refSequenceNumber;\n\t\treturn (\n\t\t\tthis.configuration.state === \"enabled\" &&\n\t\t\t(this.configuration.nonRuntimeHeuristicThreshold === undefined ||\n\t\t\t\tthis.configuration.nonRuntimeHeuristicThreshold <= opsSinceLastAck)\n\t\t);\n\t}\n\n\tpublic async waitStop(allowLastSummary: boolean): Promise<void> {\n\t\tif (this.stopping) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.stopping = true;\n\n\t\tthis.disposeEnqueuedSummary();\n\n\t\t// This will try to run lastSummary if needed.\n\t\tif (\n\t\t\tallowLastSummary &&\n\t\t\tthis.heuristicRunner?.shouldRunLastSummary() === true &&\n\t\t\tthis.summarizingLock === undefined\n\t\t) {\n\t\t\tthis.trySummarizeOnce(\n\t\t\t\t// summarizeProps\n\t\t\t\t{ summarizeReason: \"lastSummary\" },\n\t\t\t\t{},\n\t\t\t\tundefined,\n\t\t\t\ttrue /* isLastSummary */,\n\t\t\t);\n\t\t}\n\n\t\t// Note that trySummarizeOnce() call above returns right away, without waiting.\n\t\t// So we need to wait for its completion, otherwise it would be destroyed right away.\n\t\t// That said, if summary lock was taken upfront, this wait might wait on multiple retries to\n\t\t// submit summary. We should reconsider this flow and make summarizer move to exit faster.\n\t\t// This resolves when the current pending summary gets an ack or fails.\n\t\tawait this.summarizingLock;\n\n\t\tif (this.lastSummarizeFailureEventProps !== undefined) {\n\t\t\tthis.emit(\"summarizeAllAttemptsFailed\", {\n\t\t\t\t...this.lastSummarizeFailureEventProps,\n\t\t\t\tnumUnsummarizedRuntimeOps: this.heuristicData.numRuntimeOps,\n\t\t\t\tnumUnsummarizedNonRuntimeOps: this.heuristicData.numNonRuntimeOps,\n\t\t\t});\n\t\t}\n\t\tthis.lastSummarizeFailureEventProps = undefined;\n\t}\n\n\tprivate async waitStart(): Promise<void> {\n\t\t// Wait no longer than ack timeout for all pending\n\t\tconst waitStartResult = await raceTimer(\n\t\t\tthis.summaryWatcher.waitFlushed(),\n\t\t\tthis.pendingAckTimer.start(),\n\t\t);\n\t\tthis.pendingAckTimer.clear();\n\n\t\t// Remove pending ack wait timeout by op timestamp comparison, because\n\t\t// it has race conditions with summaries submitted by this same client.\n\t\tthis.summaryCollection.unsetPendingAckTimerTimeoutCallback();\n\n\t\tif (waitStartResult.result === \"done\" && waitStartResult.value !== undefined) {\n\t\t\tthis.heuristicData.updateWithLastSummaryAckInfo({\n\t\t\t\trefSequenceNumber: waitStartResult.value.summaryOp.referenceSequenceNumber,\n\t\t\t\t// This will be the Summarizer starting point so only use timestamps from client's machine.\n\t\t\t\tsummaryTime: Date.now(),\n\t\t\t\tsummarySequenceNumber: waitStartResult.value.summaryOp.sequenceNumber,\n\t\t\t});\n\t\t}\n\t\tthis.initialized = true;\n\t}\n\n\tprivate beforeSummaryAction(): void {\n\t\tthis.summarizeCount++;\n\t}\n\n\tprivate afterSummaryAction(): void {\n\t\tconst retry = this.tryWhileSummarizing;\n\t\tthis.tryWhileSummarizing = false;\n\n\t\t// After summarizing, we should check to see if we need to summarize again.\n\t\t// Rerun the heuristics and check for enqueued summaries.\n\t\tif (!this.stopping && !this.tryRunEnqueuedSummary() && retry) {\n\t\t\tthis.heuristicRunner?.run();\n\t\t}\n\t}\n\n\t/**\n\t * Runs single summary action that prevents any other concurrent actions.\n\t * Assumes that caller checked upfront for lack of concurrent action (this.summarizingLock)\n\t * before calling this API. I.e. caller is responsible for either erroring out or waiting on this promise.\n\t * @param before - set of instructions to run before running the action.\n\t * @param action - action to perform.\n\t * @param after - set of instructions to run after running the action.\n\t * @returns The result of the action.\n\t */\n\tprivate async lockedSummaryAction<T>(\n\t\tbefore: () => void,\n\t\taction: () => Promise<T>,\n\t\tafter: () => void,\n\t): Promise<T> {\n\t\tassert(\n\t\t\tthis.summarizingLock === undefined,\n\t\t\t0x25b /* \"Caller is responsible for checking lock\" */,\n\t\t);\n\n\t\tconst summarizingLock = new Deferred<void>();\n\t\tthis.summarizingLock = summarizingLock.promise;\n\n\t\tbefore();\n\n\t\treturn action().finally(() => {\n\t\t\tsummarizingLock.resolve();\n\t\t\tthis.summarizingLock = undefined;\n\t\t\tafter();\n\t\t});\n\t}\n\n\t/**\n\t * Runs single summarize attempt\n\t * @param summarizeProps - props to log with each telemetry event associated with this attempt\n\t * @param options - summary options\n\t * @param cancellationToken - cancellation token to use to be able to cancel this summary, if needed\n\t * @param resultsBuilder - optional, result builder to use.\n\t * @param isLastSummary - optional, is the call to this method for a last summary when shutting down the summarizer?\n\t * @returns ISummarizeResult - result of running a summary.\n\t */\n\tprivate trySummarizeOnce(\n\t\tsummarizeProps: ISummarizeTelemetryProperties,\n\t\toptions: ISummarizeOptions,\n\t\tresultsBuilder = new SummarizeResultBuilder(),\n\t\tisLastSummary = false,\n\t): ISummarizeResults {\n\t\tthis.lockedSummaryAction(\n\t\t\t() => {\n\t\t\t\tthis.beforeSummaryAction();\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tconst summaryLogger = createChildLogger({\n\t\t\t\t\tlogger: this.mc.logger,\n\t\t\t\t\tproperties: { all: summarizeProps },\n\t\t\t\t});\n\n\t\t\t\tconst summaryOptions: ISubmitSummaryOptions = {\n\t\t\t\t\t...options,\n\t\t\t\t\tsummaryLogger,\n\t\t\t\t\tcancellationToken: this.cancellationToken,\n\t\t\t\t\tlatestSummaryRefSeqNum: this.heuristicData.lastSuccessfulSummary.refSequenceNumber,\n\t\t\t\t};\n\t\t\t\tconst summarizeResult = this.generator.summarize(summaryOptions, resultsBuilder);\n\t\t\t\t// ensure we wait till the end of the process\n\t\t\t\tconst result = await summarizeResult.receivedSummaryAckOrNack;\n\n\t\t\t\tif (result.success) {\n\t\t\t\t\tthis.emit(\"summarize\", {\n\t\t\t\t\t\tresult: \"success\",\n\t\t\t\t\t\tcurrentAttempt: 1,\n\t\t\t\t\t\tmaxAttempts: 1,\n\t\t\t\t\t\tnumUnsummarizedRuntimeOps: this.heuristicData.numRuntimeOps,\n\t\t\t\t\t\tnumUnsummarizedNonRuntimeOps: this.heuristicData.numNonRuntimeOps,\n\t\t\t\t\t\tisLastSummary,\n\t\t\t\t\t});\n\t\t\t\t\tthis.lastSummarizeFailureEventProps = undefined;\n\t\t\t\t} else {\n\t\t\t\t\tthis.emit(\"summarize\", {\n\t\t\t\t\t\tresult: \"failure\",\n\t\t\t\t\t\tcurrentAttempt: 1,\n\t\t\t\t\t\tmaxAttempts: 1,\n\t\t\t\t\t\terror: result.error,\n\t\t\t\t\t\tfailureMessage: result.message,\n\t\t\t\t\t\tnumUnsummarizedRuntimeOps: this.heuristicData.numRuntimeOps,\n\t\t\t\t\t\tnumUnsummarizedNonRuntimeOps: this.heuristicData.numNonRuntimeOps,\n\t\t\t\t\t\tisLastSummary,\n\t\t\t\t\t});\n\t\t\t\t\tthis.mc.logger.sendErrorEvent(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\teventName: \"SummarizeFailed\",\n\t\t\t\t\t\t\tmaxAttempts: 1,\n\t\t\t\t\t\t\tsummaryAttempts: 1,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tresult.error,\n\t\t\t\t\t);\n\t\t\t\t\tif (isLastSummary) {\n\t\t\t\t\t\tthis.lastSummarizeFailureEventProps = {\n\t\t\t\t\t\t\tcurrentAttempt: (this.lastSummarizeFailureEventProps?.currentAttempt ?? 0) + 1,\n\t\t\t\t\t\t\tmaxAttempts: (this.lastSummarizeFailureEventProps?.currentAttempt ?? 0) + 1,\n\t\t\t\t\t\t\terror: result.error,\n\t\t\t\t\t\t\tfailureMessage: result.message,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tthis.afterSummaryAction();\n\t\t\t},\n\t\t).catch((error) => {\n\t\t\t// SummaryGenerator.summarize() does not throw exceptions - it converts them to failed result\n\t\t\t// on resultsBuilder\n\t\t\t// We do not care about exceptions on receivedSummaryAckOrNack - caller should check results\n\t\t\t// and take a appropriate action.\n\t\t});\n\n\t\treturn resultsBuilder.build();\n\t}\n\n\t/**\n\t * Heuristics summarize attempt.\n\t */\n\tprivate trySummarize(reason: SummarizeReason): void {\n\t\tif (this.summarizingLock !== undefined) {\n\t\t\t// lockedSummaryAction() will retry heuristic-based summary at the end of current attempt\n\t\t\t// if it's still needed\n\t\t\tthis.tryWhileSummarizing = true;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.lockedSummaryAction(\n\t\t\t() => {\n\t\t\t\tthis.beforeSummaryAction();\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\treturn this.trySummarizeWithRetries(reason);\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tthis.afterSummaryAction();\n\t\t\t},\n\t\t).catch((error) => {\n\t\t\tthis.mc.logger.sendErrorEvent({ eventName: \"UnexpectedSummarizeError\" }, error);\n\t\t});\n\t}\n\n\t/**\n\t * Tries to summarize with retries where retry is based on the failure params.\n\t * For example, summarization may be retried for failures with \"retryAfterSeconds\" param.\n\t */\n\tprivate async trySummarizeWithRetries(\n\t\treason: SummarizeReason,\n\t): Promise<ISummarizeResults | undefined> {\n\t\t// Helper to set summarize options, telemetry properties and call summarize.\n\t\tconst attemptSummarize = (\n\t\t\tattemptNumber: number,\n\t\t\tfinalAttempt: boolean,\n\t\t): {\n\t\t\tsummarizeProps: ISummarizeTelemetryProperties;\n\t\t\tsummarizeResult: ISummarizeResults;\n\t\t} => {\n\t\t\tconst summarizeOptions: ISummarizeOptions = {\n\t\t\t\tfullTree: false,\n\t\t\t};\n\t\t\tconst summarizeProps: ISummarizeTelemetryProperties = {\n\t\t\t\tsummarizeReason: reason,\n\t\t\t\tsummaryAttempts: attemptNumber,\n\t\t\t\t...summarizeOptions,\n\t\t\t\tfinalAttempt,\n\t\t\t};\n\t\t\tconst summaryLogger = createChildLogger({\n\t\t\t\tlogger: this.mc.logger,\n\t\t\t\tproperties: { all: summarizeProps },\n\t\t\t});\n\n\t\t\tconst summaryOptions: ISubmitSummaryOptions = {\n\t\t\t\t...summarizeOptions,\n\t\t\t\tsummaryLogger,\n\t\t\t\tcancellationToken: this.cancellationToken,\n\t\t\t\tfinalAttempt,\n\t\t\t\tlatestSummaryRefSeqNum: this.heuristicData.lastSuccessfulSummary.refSequenceNumber,\n\t\t\t};\n\t\t\tconst summarizeResult = this.generator.summarize(summaryOptions);\n\t\t\treturn { summarizeProps, summarizeResult };\n\t\t};\n\n\t\t// The max number of attempts are based on the stage at which summarization failed. If it fails before it is\n\t\t// submitted, a different value is used compared to if it fails after submission. Usually, in the former case,\n\t\t// we would retry more often as its cheaper and retries are likely to succeed.\n\t\t// This makes it harder to predict how many attempts would actually happen as that depends on how far an attempt\n\t\t// made. To keep things simple, the max attempts is reset after every attempt based on where it failed. This may\n\t\t// result in some failures not being retried depending on what happened before this attempt. That's fine because\n\t\t// such scenarios are very unlikely and even if it happens, it would resolve when a new summarizer starts over.\n\t\t// For example - When failure switches from one the submit failures to nack failure, only one more retry will\n\t\t// happen irrespective of the value of `defaultMaxAttempts`.\n\t\tlet maxAttempts = defaultMaxAttempts;\n\t\tlet currentAttempt = 0;\n\t\tlet retryAfterSeconds: number | undefined;\n\t\tlet done = false;\n\t\tlet status: \"success\" | \"failure\" | \"canceled\" = \"success\";\n\t\tlet results: ISummarizeResults | undefined;\n\t\tlet error: IRetriableFailureError | undefined;\n\t\tlet failureMessage: string | undefined;\n\t\tdo {\n\t\t\tcurrentAttempt++;\n\t\t\tif (this.cancellationToken.cancelled) {\n\t\t\t\tstatus = \"canceled\";\n\t\t\t\tdone = true;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst attemptResult = attemptSummarize(currentAttempt, false /* finalAttempt */);\n\t\t\tresults = attemptResult.summarizeResult;\n\n\t\t\t// Ack / nack is the final step, so if it succeeds we're done.\n\t\t\tconst ackNackResult = await results.receivedSummaryAckOrNack;\n\t\t\tif (ackNackResult.success) {\n\t\t\t\tstatus = \"success\";\n\t\t\t\tdone = true;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Update max attempts from the failure result.\n\t\t\t// If submit summary failed, use maxAttemptsForSubmitFailures. Else use the defaultMaxAttempts.\n\t\t\t// Note: Check \"summarySubmitted\" result first because if it fails, ack nack would fail as well.\n\t\t\tconst submitSummaryResult = await results.summarySubmitted;\n\t\t\tmaxAttempts = submitSummaryResult.success\n\t\t\t\t? defaultMaxAttempts\n\t\t\t\t: this.maxAttemptsForSubmitFailures;\n\n\t\t\t// Emit \"summarize\" event for this failed attempt.\n\t\t\tstatus = \"failure\";\n\t\t\terror = ackNackResult.error;\n\t\t\tfailureMessage = ackNackResult.message;\n\t\t\tretryAfterSeconds = error.retryAfterSeconds;\n\t\t\tconst eventProps: ISummarizeEventProps & ISummarizerObservabilityProps = {\n\t\t\t\tresult: status,\n\t\t\t\tcurrentAttempt,\n\t\t\t\tmaxAttempts,\n\t\t\t\terror,\n\t\t\t\tfailureMessage,\n\t\t\t\tnumUnsummarizedRuntimeOps: this.heuristicData.numRuntimeOps,\n\t\t\t\tnumUnsummarizedNonRuntimeOps: this.heuristicData.numNonRuntimeOps,\n\t\t\t};\n\t\t\tthis.emit(\"summarize\", eventProps);\n\n\t\t\t// Break if the failure doesn't have \"retryAfterSeconds\" or we are one less from max number of attempts.\n\t\t\t// Note that the final attempt if \"retryAfterSeconds\" does exist happens outside of the do..while loop.\n\t\t\tif (retryAfterSeconds === undefined || currentAttempt >= maxAttempts - 1) {\n\t\t\t\tdone = true;\n\t\t\t}\n\n\t\t\t// If the failure has \"retryAfterSeconds\", add a delay of that time before starting the next attempt.\n\t\t\tif (retryAfterSeconds !== undefined && retryAfterSeconds > 0) {\n\t\t\t\tthis.mc.logger.sendPerformanceEvent({\n\t\t\t\t\teventName: \"SummarizeAttemptDelay\",\n\t\t\t\t\tduration: retryAfterSeconds * 1000,\n\t\t\t\t\tsummaryNackDelay: ackNackResult.data !== undefined, // This will only be defined only for nack failures.\n\t\t\t\t\tstage: submitSummaryResult.data?.stage,\n\t\t\t\t\t...attemptResult.summarizeProps,\n\t\t\t\t});\n\t\t\t\tawait delay(retryAfterSeconds * 1000);\n\t\t\t}\n\t\t} while (!done);\n\n\t\t// If the attempt was successful, emit \"summarize\" event and return. A failed attempt may be retried below.\n\t\tif (status !== \"failure\") {\n\t\t\tthis.emit(\"summarize\", {\n\t\t\t\tresult: status,\n\t\t\t\tcurrentAttempt,\n\t\t\t\tmaxAttempts,\n\t\t\t\tnumUnsummarizedRuntimeOps: this.heuristicData.numRuntimeOps,\n\t\t\t\tnumUnsummarizedNonRuntimeOps: this.heuristicData.numNonRuntimeOps,\n\t\t\t});\n\t\t\treturn results;\n\t\t}\n\n\t\t// If summarization wasn't successful above and the failure contains \"retryAfterSeconds\", perform one last\n\t\t// attempt. This gives a chance to the runtime to perform additional steps in the last attempt.\n\t\tif (retryAfterSeconds !== undefined) {\n\t\t\tconst { summarizeResult } = attemptSummarize(++currentAttempt, true /* finalAttempt */);\n\t\t\t// Ack / nack is the final step, so if it succeeds we're done.\n\t\t\tconst ackNackResult = await summarizeResult.receivedSummaryAckOrNack;\n\t\t\tstatus = ackNackResult.success ? \"success\" : \"failure\";\n\t\t\terror = ackNackResult.success ? undefined : ackNackResult.error;\n\t\t\tfailureMessage = ackNackResult.success ? undefined : ackNackResult.message;\n\t\t\tconst eventProps: ISummarizeEventProps & ISummarizerObservabilityProps = {\n\t\t\t\tresult: status,\n\t\t\t\tcurrentAttempt,\n\t\t\t\tmaxAttempts,\n\t\t\t\terror,\n\t\t\t\tfailureMessage,\n\t\t\t\tnumUnsummarizedRuntimeOps: this.heuristicData.numRuntimeOps,\n\t\t\t\tnumUnsummarizedNonRuntimeOps: this.heuristicData.numNonRuntimeOps,\n\t\t\t};\n\t\t\tthis.emit(\"summarize\", eventProps);\n\t\t\tresults = summarizeResult;\n\t\t}\n\n\t\t// If summarization is still unsuccessful, stop the summarizer.\n\t\tif (status === \"failure\") {\n\t\t\tthis.mc.logger.sendErrorEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: \"SummarizeFailed\",\n\t\t\t\t\tmaxAttempts,\n\t\t\t\t\tsummaryAttempts: currentAttempt,\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\t\t\tthis.lastSummarizeFailureEventProps = {\n\t\t\t\tcurrentAttempt,\n\t\t\t\tmaxAttempts,\n\t\t\t\terror,\n\t\t\t\tfailureMessage,\n\t\t\t};\n\t\t\tthis.stopSummarizerCallback(\"failToSummarize\");\n\t\t}\n\t\treturn results;\n\t}\n\n\t/**\n\t * Attempts to generate a summary on demand with retries in case of failures. The retry logic is the same\n\t * as heuristics based summaries.\n\t */\n\tprivate async summarizeOnDemandWithRetries(\n\t\treason: SummarizeReason,\n\t\tresultsBuilder: SummarizeResultBuilder,\n\t): Promise<ISummarizeResults> {\n\t\tconst results = await this.trySummarizeWithRetries(reason);\n\t\tif (results === undefined) {\n\t\t\tresultsBuilder.fail(\n\t\t\t\t\"Summarization was canceled\",\n\t\t\t\tnew RetriableSummaryError(\"Summarization was canceled\"),\n\t\t\t);\n\t\t\treturn resultsBuilder.build();\n\t\t}\n\t\tconst submitResult = await results.summarySubmitted;\n\t\tconst summaryOpBroadcastedResult = await results.summaryOpBroadcasted;\n\t\tconst ackNackResult = await results.receivedSummaryAckOrNack;\n\t\tresultsBuilder.summarySubmitted.resolve(submitResult);\n\t\tresultsBuilder.summaryOpBroadcasted.resolve(summaryOpBroadcastedResult);\n\t\tresultsBuilder.receivedSummaryAckOrNack.resolve(ackNackResult);\n\t\treturn resultsBuilder.build();\n\t}\n\n\t/**\n\t *{@inheritdoc (ISummarizer:interface).summarizeOnDemand}\n\t */\n\tpublic summarizeOnDemand(\n\t\toptions: IOnDemandSummarizeOptions,\n\t\tresultsBuilder: SummarizeResultBuilder = new SummarizeResultBuilder(),\n\t): ISummarizeResults {\n\t\tif (this.stopping) {\n\t\t\tresultsBuilder.fail(\n\t\t\t\t\"RunningSummarizer stopped or disposed\",\n\t\t\t\tnew RetriableSummaryError(\"RunningSummarizer stopped or disposed\"),\n\t\t\t);\n\t\t\treturn resultsBuilder.build();\n\t\t}\n\t\t// Check for concurrent summary attempts. If one is found,\n\t\t// return a promise that caller can await before trying again.\n\t\tif (this.summarizingLock !== undefined) {\n\t\t\t// The heuristics are blocking concurrent summarize attempts.\n\t\t\tthrow new UsageError(\"Attempted to run an already-running summarizer on demand\");\n\t\t}\n\n\t\tconst { reason, ...summarizeOptions } = options;\n\t\tif (options.retryOnFailure === true) {\n\t\t\tthis.summarizeOnDemandWithRetries(`onDemand;${reason}`, resultsBuilder).catch(\n\t\t\t\t(error: IRetriableFailureError) => {\n\t\t\t\t\tresultsBuilder.fail(\"summarize failed\", error);\n\t\t\t\t},\n\t\t\t);\n\t\t} else {\n\t\t\tthis.trySummarizeOnce(\n\t\t\t\t{ summarizeReason: `onDemand/${reason}` },\n\t\t\t\tsummarizeOptions,\n\t\t\t\tresultsBuilder,\n\t\t\t);\n\t\t}\n\t\treturn resultsBuilder.build();\n\t}\n\n\t/**\n\t *{@inheritdoc (ISummarizer:interface).enqueueSummarize}\n\t */\n\tpublic enqueueSummarize(options: IEnqueueSummarizeOptions): EnqueueSummarizeResult {\n\t\tconst { reason, afterSequenceNumber = 0, override = false, ...summarizeOptions } = options;\n\t\tlet overridden = false;\n\t\tif (this.enqueuedSummary !== undefined) {\n\t\t\tif (!override) {\n\t\t\t\treturn { alreadyEnqueued: true };\n\t\t\t}\n\t\t\t// Override existing enqueued summarize attempt.\n\t\t\tthis.enqueuedSummary.resultsBuilder.fail(\n\t\t\t\t\"Aborted; overridden by another enqueue summarize attempt\",\n\t\t\t\tnew RetriableSummaryError(\n\t\t\t\t\t\"Summary was overridden by another enqueue summarize attempt\",\n\t\t\t\t),\n\t\t\t);\n\t\t\tthis.enqueuedSummary = undefined;\n\t\t\toverridden = true;\n\t\t}\n\n\t\tthis.enqueuedSummary = {\n\t\t\treason: `enqueue;${reason}`,\n\t\t\tafterSequenceNumber,\n\t\t\tsummarizeOptions,\n\t\t\tresultsBuilder: new SummarizeResultBuilder(),\n\t\t};\n\t\tconst results = this.enqueuedSummary.resultsBuilder.build();\n\t\tthis.tryRunEnqueuedSummary();\n\t\treturn overridden\n\t\t\t? {\n\t\t\t\t\t...results,\n\t\t\t\t\talreadyEnqueued: true,\n\t\t\t\t\toverridden: true,\n\t\t\t\t}\n\t\t\t: results;\n\t}\n\n\tprivate tryRunEnqueuedSummary(): boolean {\n\t\tif (this.stopping) {\n\t\t\tthis.disposeEnqueuedSummary();\n\t\t\treturn false;\n\t\t}\n\t\tif (\n\t\t\tthis.enqueuedSummary === undefined ||\n\t\t\tthis.heuristicData.lastOpSequenceNumber < this.enqueuedSummary.afterSequenceNumber ||\n\t\t\tthis.summarizingLock !== undefined\n\t\t) {\n\t\t\t// If no enqueued summary is ready or a summary is already in progress, take no action.\n\t\t\treturn false;\n\t\t}\n\t\tconst { reason, resultsBuilder, summarizeOptions } = this.enqueuedSummary;\n\t\t// Set to undefined first, so that subsequent enqueue attempt while summarize will occur later.\n\t\tthis.enqueuedSummary = undefined;\n\t\tthis.trySummarizeOnce(\n\t\t\t{ summarizeReason: `enqueuedSummary/${reason}` },\n\t\t\tsummarizeOptions,\n\t\t\tresultsBuilder,\n\t\t);\n\t\treturn true;\n\t}\n\n\tprivate disposeEnqueuedSummary(): void {\n\t\tif (this.enqueuedSummary !== undefined) {\n\t\t\tthis.enqueuedSummary.resultsBuilder.fail(\n\t\t\t\t\"RunningSummarizer stopped or disposed\",\n\t\t\t\tnew RetriableSummaryError(\"RunningSummarizer stopped or disposed\"),\n\t\t\t);\n\t\t\tthis.enqueuedSummary = undefined;\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"runningSummarizer.js","sourceRoot":"","sources":["../../../src/summary/summaryDelayLoadedModule/runningSummarizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAQjE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,qCAAqC,CAAC;AAC5F,OAAO,EACN,gBAAgB,EAChB,WAAW,GAEX,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAEN,UAAU,EACV,iBAAiB,EACjB,4BAA4B,EAC5B,YAAY,GAEZ,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAiB/C,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAwB,MAAM,uBAAuB,CAAC;AAO/F,OAAO,EAAE,kBAAkB,EAAE,mCAAmC,EAAE,MAAM,i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AAC;YACF,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QAClC,CAAC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport type {\n\tISummarizeEventProps,\n\tISummarizerEvents,\n\tISummarizerObservabilityProps,\n\tSummarizerStopReason,\n} from \"@fluidframework/container-runtime-definitions/internal\";\nimport type { IDisposable, ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert, Deferred, PromiseTimer, delay } from \"@fluidframework/core-utils/internal\";\nimport {\n\tDriverErrorTypes,\n\tMessageType,\n\ttype ISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\ttype MonitoringContext,\n\tUsageError,\n\tcreateChildLogger,\n\tcreateChildMonitoringContext,\n\tisFluidError,\n\ttype ITelemetryLoggerExt,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { opSize } from \"../../opProperties.js\";\nimport type {\n\tIEnqueueSummarizeOptions,\n\tIOnDemandSummarizeOptions,\n\tIRefreshSummaryAckOptions,\n\tIRetriableFailureError,\n\tISubmitSummaryOptions,\n\tISummarizeHeuristicData,\n\tISummarizeHeuristicRunner,\n\tISummarizeOptions,\n\tISummarizerRuntime,\n\tISummarizeRunnerTelemetry,\n\tISummarizeTelemetryProperties,\n\tISummaryCancellationToken,\n\tISummaryConfiguration,\n\tSubmitSummaryResult,\n} from \"../summarizerTypes.js\";\nimport { raceTimer, RetriableSummaryError, type SummarizeReason } from \"../summarizerUtils.js\";\nimport type {\n\tIAckedSummary,\n\tIClientSummaryWatcher,\n\tSummaryCollection,\n} from \"../summaryCollection.js\";\n\nimport { defaultMaxAttempts, defaultMaxAttemptsForSubmitFailures } from \"./summarizer.js\";\nimport { SummarizeHeuristicRunner } from \"./summarizerHeuristics.js\";\nimport { SummaryGenerator } from \"./summaryGenerator.js\";\nimport { SummarizeResultBuilder } from \"./summaryResultBuilder.js\";\nimport type { EnqueueSummarizeResult, ISummarizeResults } from \"./summaryResultTypes.js\";\n\nconst maxSummarizeAckWaitTime = 10 * 60 * 1000; // 10 minutes\n\n/**\n * An instance of RunningSummarizer manages the heuristics for summarizing.\n * Until disposed, the instance of RunningSummarizer can assume that it is\n * in a state of running, meaning it is connected and initialized. It keeps\n * track of summaries that it is generating as they are broadcast and acked/nacked.\n * This object is created and controlled by Summarizer object.\n */\nexport class RunningSummarizer\n\textends TypedEventEmitter<ISummarizerEvents>\n\timplements IDisposable\n{\n\tpublic static async start(\n\t\tlogger: ITelemetryBaseLogger,\n\t\tsummaryWatcher: IClientSummaryWatcher,\n\t\tconfiguration: ISummaryConfiguration,\n\n\t\tsubmitSummaryCallback: (options: ISubmitSummaryOptions) => Promise<SubmitSummaryResult>,\n\n\t\trefreshLatestSummaryAckCallback: (options: IRefreshSummaryAckOptions) => Promise<void>,\n\t\theuristicData: ISummarizeHeuristicData,\n\t\tsummaryCollection: SummaryCollection,\n\n\t\tcancellationToken: ISummaryCancellationToken,\n\t\tstopSummarizerCallback: (reason: SummarizerStopReason) => void,\n\n\t\truntime: ISummarizerRuntime,\n\t): Promise<RunningSummarizer> {\n\t\tconst summarizer = new RunningSummarizer(\n\t\t\tlogger,\n\t\t\tsummaryWatcher,\n\t\t\tconfiguration,\n\t\t\tsubmitSummaryCallback,\n\t\t\trefreshLatestSummaryAckCallback,\n\t\t\theuristicData,\n\t\t\tsummaryCollection,\n\t\t\tcancellationToken,\n\t\t\tstopSummarizerCallback,\n\t\t\truntime,\n\t\t);\n\n\t\t// If there have been any acks newer that the one this client loaded from until now, process them before\n\t\t// starting the running summarizer which will trigger summary heuristics.\n\t\t// This is done primarily to handle scenarios where the summarizer loads from a cached snapshot and there\n\t\t// is newer one available. The ack for the newer summary is processed before summarizing because otherwise\n\t\t// that summary would fail as it has an older parent.\n\t\tlet nextReferenceSequenceNumber = runtime.deltaManager.initialSequenceNumber + 1;\n\t\tconst latestAck = summaryCollection.latestAck;\n\t\tif (\n\t\t\tlatestAck !== undefined &&\n\t\t\tlatestAck.summaryOp.referenceSequenceNumber >= nextReferenceSequenceNumber\n\t\t) {\n\t\t\tawait summarizer.handleSummaryAck(latestAck);\n\t\t\tnextReferenceSequenceNumber = latestAck.summaryOp.referenceSequenceNumber + 1;\n\t\t}\n\n\t\tawait summarizer.waitStart();\n\n\t\t// Process summary acks asynchronously\n\t\t// Note: no exceptions are thrown from processIncomingSummaryAcks handler as it handles all exceptions\n\t\tsummarizer.processIncomingSummaryAcks(nextReferenceSequenceNumber).catch((error) => {\n\t\t\tcreateChildLogger({ logger }).sendErrorEvent(\n\t\t\t\t{ eventName: \"HandleSummaryAckFatalError\" },\n\t\t\t\terror,\n\t\t\t);\n\t\t});\n\n\t\t// Update heuristic counts\n\t\t// By the time we get here, there are potentially ops missing from the heuristic summary counts\n\t\t// Examples of where this could happen:\n\t\t// 1. Op is processed during the time that we are initiating the RunningSummarizer instance but before we\n\t\t// listen for the op events (will get missed by the handlers in the current workflow)\n\t\t// 2. Op was sequenced after the last time we summarized (op sequence number > summarize ref sequence number)\n\t\tconst diff =\n\t\t\truntime.deltaManager.lastSequenceNumber -\n\t\t\t(heuristicData.lastSuccessfulSummary.refSequenceNumber +\n\t\t\t\theuristicData.numNonRuntimeOps +\n\t\t\t\theuristicData.numRuntimeOps);\n\t\theuristicData.hasMissingOpData = diff > 0;\n\n\t\tif (heuristicData.hasMissingOpData) {\n\t\t\t// Split the diff 50-50 and increment the counts appropriately\n\t\t\theuristicData.numNonRuntimeOps += Math.ceil(diff / 2);\n\t\t\theuristicData.numRuntimeOps += Math.floor(diff / 2);\n\t\t}\n\n\t\t// Update last seq number (in case the handlers haven't processed anything yet)\n\t\theuristicData.lastOpSequenceNumber = runtime.deltaManager.lastSequenceNumber;\n\n\t\t// Start heuristics\n\t\tsummarizer.heuristicRunner?.start();\n\t\tsummarizer.heuristicRunner?.run();\n\n\t\treturn summarizer;\n\t}\n\n\tpublic get disposed(): boolean {\n\t\treturn this._disposed;\n\t}\n\tprivate stopping = false;\n\tprivate _disposed = false;\n\tprivate summarizingLock: Promise<void> | undefined;\n\tprivate tryWhileSummarizing = false;\n\tprivate readonly pendingAckTimer: PromiseTimer;\n\tprivate heuristicRunner?: ISummarizeHeuristicRunner;\n\tprivate readonly generator: SummaryGenerator;\n\tprivate readonly mc: MonitoringContext;\n\n\tprivate enqueuedSummary:\n\t\t| {\n\t\t\t\treason: SummarizeReason;\n\t\t\t\tafterSequenceNumber: number;\n\t\t\t\tsummarizeOptions: ISummarizeOptions;\n\t\t\t\treadonly resultsBuilder: SummarizeResultBuilder;\n\t\t }\n\t\t| undefined;\n\tprivate summarizeCount = 0;\n\tprivate totalSuccessfulAttempts = 0;\n\tprivate initialized = false;\n\n\t/**\n\t * The maximum number of summary attempts to do when submit summary fails.\n\t */\n\tprivate readonly maxAttemptsForSubmitFailures: number;\n\n\t/**\n\t * These are necessary to store outside of methods because of the logic around runnning a lastSummary.\n\t * We want the lastSummary to also be captured as \"all attempts failed\".\n\t */\n\tprivate lastSummarizeFailureEventProps: Omit<ISummarizeEventProps, \"result\"> | undefined =\n\t\tundefined;\n\n\tprivate constructor(\n\t\tbaseLogger: ITelemetryBaseLogger,\n\t\tprivate readonly summaryWatcher: IClientSummaryWatcher,\n\t\tprivate readonly configuration: ISummaryConfiguration,\n\t\tprivate readonly submitSummaryCallback: (\n\t\t\toptions: ISubmitSummaryOptions,\n\t\t) => Promise<SubmitSummaryResult>,\n\t\tprivate readonly refreshLatestSummaryAckCallback: (\n\t\t\toptions: IRefreshSummaryAckOptions,\n\t\t) => Promise<void>,\n\t\tprivate readonly heuristicData: ISummarizeHeuristicData,\n\t\tprivate readonly summaryCollection: SummaryCollection,\n\n\t\tprivate readonly cancellationToken: ISummaryCancellationToken,\n\t\tprivate readonly stopSummarizerCallback: (reason: SummarizerStopReason) => void,\n\n\t\tprivate readonly runtime: ISummarizerRuntime,\n\t) {\n\t\tsuper();\n\n\t\tconst telemetryProps: ISummarizeRunnerTelemetry = {\n\t\t\tsummarizeCount: () => this.summarizeCount,\n\t\t\tsummarizerSuccessfulAttempts: () => this.totalSuccessfulAttempts,\n\t\t};\n\n\t\tthis.mc = createChildMonitoringContext({\n\t\t\tlogger: baseLogger,\n\t\t\tnamespace: \"Running\",\n\t\t\tproperties: {\n\t\t\t\tall: telemetryProps,\n\t\t\t},\n\t\t});\n\n\t\t// Only create heuristics when in 'enabled' mode.\n\t\t// This bypasses heuristics for 'disableHeuristics' and 'summaryOnRequest' configurations.\n\t\tif (configuration.state === \"enabled\") {\n\t\t\tthis.heuristicRunner = new SummarizeHeuristicRunner(\n\t\t\t\theuristicData,\n\t\t\t\tconfiguration,\n\t\t\t\t(reason) => this.trySummarize(reason),\n\t\t\t\tthis.mc.logger,\n\t\t\t);\n\t\t}\n\n\t\tassert(\n\t\t\tthis.configuration.state !== \"disabled\",\n\t\t\t0x2eb /* \"Summary not supported with configuration disabled\" */,\n\t\t);\n\n\t\t// Cap the maximum amount of time client will wait for a summarize op ack to maxSummarizeAckWaitTime\n\t\t// configuration.maxAckWaitTime is composed from defaults, server values, and runtime overrides\n\n\t\tconst maxAckWaitTime = Math.min(\n\t\t\tthis.configuration.maxAckWaitTime,\n\t\t\tmaxSummarizeAckWaitTime,\n\t\t);\n\n\t\tthis.pendingAckTimer = new PromiseTimer(maxAckWaitTime, () => {\n\t\t\t// Note: summarizeCount (from ChildLogger definition) may be 0,\n\t\t\t// since this code path is hit when RunningSummarizer first starts up,\n\t\t\t// before this instance has kicked off a new summarize run.\n\t\t\tthis.mc.logger.sendErrorEvent({\n\t\t\t\teventName: \"SummaryAckWaitTimeout\",\n\t\t\t\tmessage: \"Pending summary ack not received in time\",\n\t\t\t\tmaxAckWaitTime,\n\t\t\t\treferenceSequenceNumber: this.heuristicData.lastAttempt.refSequenceNumber,\n\t\t\t\tsummarySequenceNumber: this.heuristicData.lastAttempt.summarySequenceNumber,\n\t\t\t\ttimePending: Date.now() - this.heuristicData.lastAttempt.summaryTime,\n\t\t\t});\n\t\t});\n\t\t// Set up pending ack timeout by op timestamp differences for previous summaries.\n\t\tsummaryCollection.setPendingAckTimerTimeoutCallback(maxAckWaitTime, () => {\n\t\t\tif (this.pendingAckTimer.hasTimer) {\n\t\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"MissingSummaryAckFoundByOps\",\n\t\t\t\t\treferenceSequenceNumber: this.heuristicData.lastAttempt.refSequenceNumber,\n\t\t\t\t\tsummarySequenceNumber: this.heuristicData.lastAttempt.summarySequenceNumber,\n\t\t\t\t});\n\t\t\t\tthis.pendingAckTimer.clear();\n\t\t\t}\n\t\t});\n\n\t\tconst immediatelyRefreshLatestSummaryAck =\n\t\t\tthis.mc.config.getBoolean(\"Fluid.Summarizer.immediatelyRefreshLatestSummaryAck\") ?? true;\n\t\tthis.generator = new SummaryGenerator(\n\t\t\tthis.pendingAckTimer,\n\t\t\tthis.heuristicData,\n\t\t\tthis.submitSummaryCallback,\n\t\t\t() => {\n\t\t\t\tthis.totalSuccessfulAttempts++;\n\t\t\t},\n\n\t\t\tasync (options: IRefreshSummaryAckOptions) => {\n\t\t\t\tif (immediatelyRefreshLatestSummaryAck) {\n\t\t\t\t\tawait this.refreshLatestSummaryAckAndHandleError(options);\n\t\t\t\t}\n\t\t\t},\n\t\t\tthis.summaryWatcher,\n\t\t\tthis.mc.logger,\n\t\t);\n\n\t\t// The max attempts for submit failures can be overridden via a feature flag. This allows us to\n\t\t// tweak this as per telemetry data until we arrive at a stable number.\n\t\t// If its set to a number higher than `defaultMaxAttemptsForSubmitFailures`, it will be ignored.\n\t\tconst overrideMaxAttempts = this.mc.config.getNumber(\n\t\t\t\"Fluid.Summarizer.AttemptsForSubmitFailures\",\n\t\t);\n\t\tthis.maxAttemptsForSubmitFailures =\n\t\t\toverrideMaxAttempts !== undefined &&\n\t\t\toverrideMaxAttempts < defaultMaxAttemptsForSubmitFailures\n\t\t\t\t? overrideMaxAttempts\n\t\t\t\t: defaultMaxAttemptsForSubmitFailures;\n\n\t\tthis.setupEventListeners();\n\t}\n\n\tprivate async handleSummaryAck(ack: IAckedSummary): Promise<void> {\n\t\tconst refSequenceNumber = ack.summaryOp.referenceSequenceNumber;\n\t\tconst summaryLogger = this.tryGetCorrelatedLogger(refSequenceNumber) ?? this.mc.logger;\n\t\tconst summaryOpHandle = ack.summaryOp.contents.handle;\n\t\tconst summaryAckHandle = ack.summaryAck.contents.handle;\n\t\twhile (this.summarizingLock !== undefined) {\n\t\t\tsummaryLogger.sendTelemetryEvent({\n\t\t\t\teventName: \"RefreshAttemptWithSummarizerRunning\",\n\t\t\t\treferenceSequenceNumber: refSequenceNumber,\n\t\t\t\tproposalHandle: summaryOpHandle,\n\t\t\t\tackHandle: summaryAckHandle,\n\t\t\t});\n\t\t\tawait this.summarizingLock;\n\t\t}\n\n\t\t// Make sure we block any summarizer from being executed/enqueued while\n\t\t// executing the refreshLatestSummaryAck.\n\t\t// https://dev.azure.com/fluidframework/internal/_workitems/edit/779\n\t\tawait this.lockedSummaryAction(\n\t\t\t() => {},\n\t\t\tasync () => {\n\t\t\t\tconst options: IRefreshSummaryAckOptions = {\n\t\t\t\t\tproposalHandle: summaryOpHandle,\n\t\t\t\t\tackHandle: summaryAckHandle,\n\t\t\t\t\tsummaryRefSeq: refSequenceNumber,\n\t\t\t\t\tsummaryLogger,\n\t\t\t\t};\n\t\t\t\tawait this.refreshLatestSummaryAckAndHandleError(options);\n\t\t\t},\n\t\t\t() => {},\n\t\t);\n\t}\n\n\tprivate readonly refreshLatestSummaryAckAndHandleError = async (\n\t\toptions: IRefreshSummaryAckOptions,\n\t): Promise<void> => {\n\t\treturn this.refreshLatestSummaryAckCallback(options).catch(async (error) => {\n\t\t\t// If the error is 404, so maybe the fetched version no longer exists on server. We just\n\t\t\t// ignore this error in that case, as that means we will have another summaryAck for the\n\t\t\t// latest version with which we will refresh the state. However in case of single commit\n\t\t\t// summary, we might be missing a summary ack, so in that case we are still fine as the\n\t\t\t// code in `submitSummary` function in container runtime, will refresh the latest state\n\t\t\t// by calling `prefetchLatestSummaryThenClose`. We will load the next summarizer from the\n\t\t\t// updated state and be fine.\n\t\t\tconst isIgnoredError =\n\t\t\t\tisFluidError(error) &&\n\t\t\t\terror.errorType === DriverErrorTypes.fileNotFoundOrAccessDeniedError;\n\n\t\t\toptions.summaryLogger.sendTelemetryEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: isIgnoredError\n\t\t\t\t\t\t? \"HandleSummaryAckErrorIgnored\"\n\t\t\t\t\t\t: \"HandleLastSummaryAckError\",\n\t\t\t\t\treferenceSequenceNumber: options.summaryRefSeq,\n\t\t\t\t\tproposalHandle: options.proposalHandle,\n\t\t\t\t\tackHandle: options.ackHandle,\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\t\t});\n\t};\n\n\t/**\n\t * Responsible for receiving and processing all the summary acks.\n\t * It starts processing ACKs after the one for the summary this client loaded from (initialSequenceNumber). Any\n\t * ACK before that is not interesting as it will simply be ignored.\n\t *\n\t * @param referenceSequenceNumber - The referenceSequenceNumber of the summary from which to start processing\n\t * acks.\n\t */\n\tprivate async processIncomingSummaryAcks(referenceSequenceNumber: number): Promise<void> {\n\t\t// Start waiting for acks that are for summaries newer that the one this client loaded from.\n\t\tlet nextReferenceSequenceNumber = referenceSequenceNumber;\n\t\twhile (!this.disposed) {\n\t\t\tconst ackedSummary = await this.summaryCollection.waitSummaryAck(\n\t\t\t\tnextReferenceSequenceNumber,\n\t\t\t);\n\t\t\tawait this.handleSummaryAck(ackedSummary);\n\t\t\tnextReferenceSequenceNumber = ackedSummary.summaryOp.referenceSequenceNumber + 1;\n\t\t}\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.cleanupEventListeners();\n\t\tthis.summaryWatcher.dispose();\n\t\tthis.heuristicRunner?.dispose();\n\t\tthis.heuristicRunner = undefined;\n\t\tthis.generator.dispose();\n\t\tthis.pendingAckTimer.clear();\n\t\tthis.disposeEnqueuedSummary();\n\t\tthis._disposed = true;\n\t\tthis.stopping = true;\n\t}\n\n\tprivate readonly eventsCleanup: (() => void)[] = [];\n\n\tprivate setupEventListeners(): void {\n\t\tconst runtimeListener: (op: ISequencedDocumentMessage, runtimeMessage?: boolean) => void =\n\t\t\t(op: ISequencedDocumentMessage, runtimeMessage?: boolean) => {\n\t\t\t\tthis.handleOp(op, runtimeMessage === true);\n\t\t\t};\n\t\tthis.runtime.on(\"op\", runtimeListener);\n\t\tthis.eventsCleanup.push(() => this.runtime.off(\"op\", runtimeListener));\n\n\t\t// Forward events\n\t\tfor (const event of [\"summarizeTimeout\"] as const) {\n\t\t\tconst listener = (...args: unknown[]): void => {\n\t\t\t\tthis.emit(event, ...args);\n\t\t\t};\n\t\t\tthis.generator.on(event, listener);\n\t\t\tthis.eventsCleanup.push(() => this.generator.off(event, listener));\n\t\t}\n\t}\n\n\tprivate cleanupEventListeners(): void {\n\t\tfor (const cleanup of this.eventsCleanup) {\n\t\t\tcleanup();\n\t\t}\n\t\tthis.eventsCleanup.length = 0;\n\t}\n\n\t/**\n\t * RunningSummarizer's logger includes the sequenced index of the current summary on each event.\n\t * If some other Summarizer code wants that event on their logs they can get it here,\n\t * but only if they're logging about that same summary.\n\t * @param summaryOpRefSeq - RefSeq number of the summary op, to ensure the log correlation will be correct\n\t */\n\tpublic tryGetCorrelatedLogger = (\n\t\tsummaryOpRefSeq: number,\n\t): ITelemetryLoggerExt | undefined =>\n\t\tthis.heuristicData.lastAttempt.refSequenceNumber === summaryOpRefSeq\n\t\t\t? this.mc.logger\n\t\t\t: undefined;\n\n\t/**\n\t * We only want a single heuristic runner micro-task (will provide better optimized grouping of ops)\n\t */\n\tprivate heuristicRunnerMicroTaskExists = false;\n\n\tpublic handleOp(op: ISequencedDocumentMessage, runtimeMessage: boolean): void {\n\t\tthis.heuristicData.lastOpSequenceNumber = op.sequenceNumber;\n\n\t\tif (runtimeMessage) {\n\t\t\tthis.heuristicData.numRuntimeOps++;\n\t\t} else {\n\t\t\tthis.heuristicData.numNonRuntimeOps++;\n\t\t}\n\n\t\tthis.heuristicData.totalOpsSize += opSize(op);\n\n\t\t// Check for enqueued on-demand summaries; Intentionally do nothing otherwise\n\t\tif (\n\t\t\tthis.initialized &&\n\t\t\tthis.opCanTriggerSummary(op, runtimeMessage) &&\n\t\t\t!this.tryRunEnqueuedSummary() &&\n\t\t\t!this.heuristicRunnerMicroTaskExists\n\t\t) {\n\t\t\tthis.heuristicRunnerMicroTaskExists = true;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-floating-promises\n\t\t\tPromise.resolve()\n\t\t\t\t.then(() => {\n\t\t\t\t\tthis.heuristicRunner?.run();\n\t\t\t\t})\n\t\t\t\t.finally(() => {\n\t\t\t\t\tthis.heuristicRunnerMicroTaskExists = false;\n\t\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Can the given op trigger a summary?\n\t * # Currently always prevents summaries for Summarize and SummaryAck/Nack ops\n\t * @param op - op to check\n\t * @returns true if this op can trigger a summary\n\t */\n\tprivate opCanTriggerSummary(\n\t\top: ISequencedDocumentMessage,\n\t\truntimeMessage: boolean,\n\t): boolean {\n\t\tswitch (op.type) {\n\t\t\tcase MessageType.Summarize:\n\t\t\tcase MessageType.SummaryAck:\n\t\t\tcase MessageType.SummaryNack: {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn runtimeMessage || this.nonRuntimeOpCanTriggerSummary();\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate nonRuntimeOpCanTriggerSummary(): boolean {\n\t\tconst opsSinceLastAck =\n\t\t\tthis.heuristicData.lastOpSequenceNumber -\n\t\t\tthis.heuristicData.lastSuccessfulSummary.refSequenceNumber;\n\t\treturn (\n\t\t\tthis.configuration.state === \"enabled\" &&\n\t\t\t(this.configuration.nonRuntimeHeuristicThreshold === undefined ||\n\t\t\t\tthis.configuration.nonRuntimeHeuristicThreshold <= opsSinceLastAck)\n\t\t);\n\t}\n\n\tpublic async waitStop(allowLastSummary: boolean): Promise<void> {\n\t\tif (this.stopping) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.stopping = true;\n\n\t\tthis.disposeEnqueuedSummary();\n\n\t\t// This will try to run lastSummary if needed.\n\t\tif (\n\t\t\tallowLastSummary &&\n\t\t\tthis.heuristicRunner?.shouldRunLastSummary() === true &&\n\t\t\tthis.summarizingLock === undefined\n\t\t) {\n\t\t\tthis.trySummarizeOnce(\n\t\t\t\t// summarizeProps\n\t\t\t\t{ summarizeReason: \"lastSummary\" },\n\t\t\t\t{},\n\t\t\t\tundefined,\n\t\t\t\ttrue /* isLastSummary */,\n\t\t\t);\n\t\t}\n\n\t\t// Note that trySummarizeOnce() call above returns right away, without waiting.\n\t\t// So we need to wait for its completion, otherwise it would be destroyed right away.\n\t\t// That said, if summary lock was taken upfront, this wait might wait on multiple retries to\n\t\t// submit summary. We should reconsider this flow and make summarizer move to exit faster.\n\t\t// This resolves when the current pending summary gets an ack or fails.\n\t\tawait this.summarizingLock;\n\n\t\tif (this.lastSummarizeFailureEventProps !== undefined) {\n\t\t\tthis.emit(\"summarizeAllAttemptsFailed\", {\n\t\t\t\t...this.lastSummarizeFailureEventProps,\n\t\t\t\tnumUnsummarizedRuntimeOps: this.heuristicData.numRuntimeOps,\n\t\t\t\tnumUnsummarizedNonRuntimeOps: this.heuristicData.numNonRuntimeOps,\n\t\t\t});\n\t\t}\n\t\tthis.lastSummarizeFailureEventProps = undefined;\n\t}\n\n\tprivate async waitStart(): Promise<void> {\n\t\t// Wait no longer than ack timeout for all pending\n\t\tconst waitStartResult = await raceTimer(\n\t\t\tthis.summaryWatcher.waitFlushed(),\n\t\t\tthis.pendingAckTimer.start(),\n\t\t);\n\t\tthis.pendingAckTimer.clear();\n\n\t\t// Remove pending ack wait timeout by op timestamp comparison, because\n\t\t// it has race conditions with summaries submitted by this same client.\n\t\tthis.summaryCollection.unsetPendingAckTimerTimeoutCallback();\n\n\t\tif (waitStartResult.result === \"done\" && waitStartResult.value !== undefined) {\n\t\t\tthis.heuristicData.updateWithLastSummaryAckInfo({\n\t\t\t\trefSequenceNumber: waitStartResult.value.summaryOp.referenceSequenceNumber,\n\t\t\t\t// This will be the Summarizer starting point so only use timestamps from client's machine.\n\t\t\t\tsummaryTime: Date.now(),\n\t\t\t\tsummarySequenceNumber: waitStartResult.value.summaryOp.sequenceNumber,\n\t\t\t});\n\t\t}\n\t\tthis.initialized = true;\n\t}\n\n\tprivate beforeSummaryAction(): void {\n\t\tthis.summarizeCount++;\n\t}\n\n\tprivate afterSummaryAction(): void {\n\t\tconst retry = this.tryWhileSummarizing;\n\t\tthis.tryWhileSummarizing = false;\n\n\t\t// After summarizing, we should check to see if we need to summarize again.\n\t\t// Rerun the heuristics and check for enqueued summaries.\n\t\tif (!this.stopping && !this.tryRunEnqueuedSummary() && retry) {\n\t\t\tthis.heuristicRunner?.run();\n\t\t}\n\t}\n\n\t/**\n\t * Runs single summary action that prevents any other concurrent actions.\n\t * Assumes that caller checked upfront for lack of concurrent action (this.summarizingLock)\n\t * before calling this API. I.e. caller is responsible for either erroring out or waiting on this promise.\n\t * @param before - set of instructions to run before running the action.\n\t * @param action - action to perform.\n\t * @param after - set of instructions to run after running the action.\n\t * @returns The result of the action.\n\t */\n\tprivate async lockedSummaryAction<T>(\n\t\tbefore: () => void,\n\t\taction: () => Promise<T>,\n\t\tafter: () => void,\n\t): Promise<T> {\n\t\tassert(\n\t\t\tthis.summarizingLock === undefined,\n\t\t\t0x25b /* \"Caller is responsible for checking lock\" */,\n\t\t);\n\n\t\tconst summarizingLock = new Deferred<void>();\n\t\tthis.summarizingLock = summarizingLock.promise;\n\n\t\tbefore();\n\n\t\treturn action().finally(() => {\n\t\t\tsummarizingLock.resolve();\n\t\t\tthis.summarizingLock = undefined;\n\t\t\tafter();\n\t\t});\n\t}\n\n\t/**\n\t * Runs single summarize attempt\n\t * @param summarizeProps - props to log with each telemetry event associated with this attempt\n\t * @param options - summary options\n\t * @param cancellationToken - cancellation token to use to be able to cancel this summary, if needed\n\t * @param resultsBuilder - optional, result builder to use.\n\t * @param isLastSummary - optional, is the call to this method for a last summary when shutting down the summarizer?\n\t * @returns ISummarizeResult - result of running a summary.\n\t */\n\tprivate trySummarizeOnce(\n\t\tsummarizeProps: ISummarizeTelemetryProperties,\n\t\toptions: ISummarizeOptions,\n\t\tresultsBuilder = new SummarizeResultBuilder(),\n\t\tisLastSummary = false,\n\t): ISummarizeResults {\n\t\tthis.lockedSummaryAction(\n\t\t\t() => {\n\t\t\t\tthis.beforeSummaryAction();\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tconst summaryLogger = createChildLogger({\n\t\t\t\t\tlogger: this.mc.logger,\n\t\t\t\t\tproperties: { all: summarizeProps },\n\t\t\t\t});\n\n\t\t\t\tconst summaryOptions: ISubmitSummaryOptions = {\n\t\t\t\t\t...options,\n\t\t\t\t\tsummaryLogger,\n\t\t\t\t\tcancellationToken: this.cancellationToken,\n\t\t\t\t\tlatestSummaryRefSeqNum: this.heuristicData.lastSuccessfulSummary.refSequenceNumber,\n\t\t\t\t};\n\t\t\t\tconst summarizeResult = this.generator.summarize(summaryOptions, resultsBuilder);\n\t\t\t\t// ensure we wait till the end of the process\n\t\t\t\tconst result = await summarizeResult.receivedSummaryAckOrNack;\n\n\t\t\t\tif (result.success) {\n\t\t\t\t\tthis.emit(\"summarize\", {\n\t\t\t\t\t\tresult: \"success\",\n\t\t\t\t\t\tcurrentAttempt: 1,\n\t\t\t\t\t\tmaxAttempts: 1,\n\t\t\t\t\t\tnumUnsummarizedRuntimeOps: this.heuristicData.numRuntimeOps,\n\t\t\t\t\t\tnumUnsummarizedNonRuntimeOps: this.heuristicData.numNonRuntimeOps,\n\t\t\t\t\t\tisLastSummary,\n\t\t\t\t\t});\n\t\t\t\t\tthis.lastSummarizeFailureEventProps = undefined;\n\t\t\t\t} else {\n\t\t\t\t\tthis.emit(\"summarize\", {\n\t\t\t\t\t\tresult: \"failure\",\n\t\t\t\t\t\tcurrentAttempt: 1,\n\t\t\t\t\t\tmaxAttempts: 1,\n\t\t\t\t\t\terror: result.error,\n\t\t\t\t\t\tfailureMessage: result.message,\n\t\t\t\t\t\tnumUnsummarizedRuntimeOps: this.heuristicData.numRuntimeOps,\n\t\t\t\t\t\tnumUnsummarizedNonRuntimeOps: this.heuristicData.numNonRuntimeOps,\n\t\t\t\t\t\tisLastSummary,\n\t\t\t\t\t});\n\t\t\t\t\tsummaryLogger.sendErrorEvent(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\teventName: \"SummarizeFailed\",\n\t\t\t\t\t\t\tmaxAttempts: 1,\n\t\t\t\t\t\t\tsummaryAttempts: 1,\n\t\t\t\t\t\t\tisLastSummary,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tresult.error,\n\t\t\t\t\t);\n\t\t\t\t\tif (isLastSummary) {\n\t\t\t\t\t\tthis.lastSummarizeFailureEventProps = {\n\t\t\t\t\t\t\tcurrentAttempt: (this.lastSummarizeFailureEventProps?.currentAttempt ?? 0) + 1,\n\t\t\t\t\t\t\tmaxAttempts: (this.lastSummarizeFailureEventProps?.currentAttempt ?? 0) + 1,\n\t\t\t\t\t\t\terror: result.error,\n\t\t\t\t\t\t\tfailureMessage: result.message,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tthis.afterSummaryAction();\n\t\t\t},\n\t\t).catch((error) => {\n\t\t\t// SummaryGenerator.summarize() does not throw exceptions - it converts them to failed result\n\t\t\t// on resultsBuilder\n\t\t\t// We do not care about exceptions on receivedSummaryAckOrNack - caller should check results\n\t\t\t// and take a appropriate action.\n\t\t});\n\n\t\treturn resultsBuilder.build();\n\t}\n\n\t/**\n\t * Heuristics summarize attempt.\n\t */\n\tprivate trySummarize(reason: SummarizeReason): void {\n\t\tif (this.summarizingLock !== undefined) {\n\t\t\t// lockedSummaryAction() will retry heuristic-based summary at the end of current attempt\n\t\t\t// if it's still needed\n\t\t\tthis.tryWhileSummarizing = true;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.lockedSummaryAction(\n\t\t\t() => {\n\t\t\t\tthis.beforeSummaryAction();\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\treturn this.trySummarizeWithRetries(reason);\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tthis.afterSummaryAction();\n\t\t\t},\n\t\t).catch((error) => {\n\t\t\tthis.mc.logger.sendErrorEvent(\n\t\t\t\t{ eventName: \"UnexpectedSummarizeError\", summarizeReason: reason },\n\t\t\t\terror,\n\t\t\t);\n\t\t});\n\t}\n\n\t/**\n\t * Tries to summarize with retries where retry is based on the failure params.\n\t * For example, summarization may be retried for failures with \"retryAfterSeconds\" param.\n\t */\n\tprivate async trySummarizeWithRetries(\n\t\treason: SummarizeReason,\n\t\tsummarizeOptions: ISummarizeOptions = {},\n\t): Promise<ISummarizeResults | undefined> {\n\t\t// Helper to set summarize options, telemetry properties and call summarize.\n\t\tconst attemptSummarize = (\n\t\t\tattemptNumber: number,\n\t\t\tfinalAttempt: boolean,\n\t\t): {\n\t\t\tsummarizeProps: ISummarizeTelemetryProperties;\n\t\t\tsummarizeResult: ISummarizeResults;\n\t\t} => {\n\t\t\tconst attemptSummarizeOptions: ISummarizeOptions = {\n\t\t\t\tfullTree: summarizeOptions.fullTree ?? false,\n\t\t\t};\n\t\t\tconst summarizeProps: ISummarizeTelemetryProperties = {\n\t\t\t\tsummarizeReason: reason,\n\t\t\t\tsummaryAttempts: attemptNumber,\n\t\t\t\t...attemptSummarizeOptions,\n\t\t\t\tfinalAttempt,\n\t\t\t};\n\t\t\tconst summaryLogger = createChildLogger({\n\t\t\t\tlogger: this.mc.logger,\n\t\t\t\tproperties: { all: summarizeProps },\n\t\t\t});\n\n\t\t\tconst summaryOptions: ISubmitSummaryOptions = {\n\t\t\t\t...attemptSummarizeOptions,\n\t\t\t\tsummaryLogger,\n\t\t\t\tcancellationToken: this.cancellationToken,\n\t\t\t\tfinalAttempt,\n\t\t\t\tlatestSummaryRefSeqNum: this.heuristicData.lastSuccessfulSummary.refSequenceNumber,\n\t\t\t};\n\t\t\tconst summarizeResult = this.generator.summarize(summaryOptions);\n\t\t\treturn { summarizeProps, summarizeResult };\n\t\t};\n\n\t\t// The max number of attempts are based on the stage at which summarization failed. If it fails before it is\n\t\t// submitted, a different value is used compared to if it fails after submission. Usually, in the former case,\n\t\t// we would retry more often as its cheaper and retries are likely to succeed.\n\t\t// This makes it harder to predict how many attempts would actually happen as that depends on how far an attempt\n\t\t// made. To keep things simple, the max attempts is reset after every attempt based on where it failed. This may\n\t\t// result in some failures not being retried depending on what happened before this attempt. That's fine because\n\t\t// such scenarios are very unlikely and even if it happens, it would resolve when a new summarizer starts over.\n\t\t// For example - When failure switches from one the submit failures to nack failure, only one more retry will\n\t\t// happen irrespective of the value of `defaultMaxAttempts`.\n\t\tlet maxAttempts = defaultMaxAttempts;\n\t\tlet currentAttempt = 0;\n\t\tlet retryAfterSeconds: number | undefined;\n\t\tlet done = false;\n\t\tlet status: \"success\" | \"failure\" | \"canceled\" = \"success\";\n\t\tlet results: ISummarizeResults | undefined;\n\t\tlet error: IRetriableFailureError | undefined;\n\t\tlet failureMessage: string | undefined;\n\t\tdo {\n\t\t\tcurrentAttempt++;\n\t\t\tif (this.cancellationToken.cancelled) {\n\t\t\t\tstatus = \"canceled\";\n\t\t\t\tdone = true;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst attemptResult = attemptSummarize(currentAttempt, false /* finalAttempt */);\n\t\t\tresults = attemptResult.summarizeResult;\n\n\t\t\t// Ack / nack is the final step, so if it succeeds we're done.\n\t\t\tconst ackNackResult = await results.receivedSummaryAckOrNack;\n\t\t\tif (ackNackResult.success) {\n\t\t\t\tstatus = \"success\";\n\t\t\t\tdone = true;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Update max attempts from the failure result.\n\t\t\t// If submit summary failed, use maxAttemptsForSubmitFailures. Else use the defaultMaxAttempts.\n\t\t\t// Note: Check \"summarySubmitted\" result first because if it fails, ack nack would fail as well.\n\t\t\tconst submitSummaryResult = await results.summarySubmitted;\n\t\t\tmaxAttempts = submitSummaryResult.success\n\t\t\t\t? defaultMaxAttempts\n\t\t\t\t: this.maxAttemptsForSubmitFailures;\n\n\t\t\t// Emit \"summarize\" event for this failed attempt.\n\t\t\tstatus = \"failure\";\n\t\t\terror = ackNackResult.error;\n\t\t\tfailureMessage = ackNackResult.message;\n\t\t\tretryAfterSeconds = error.retryAfterSeconds;\n\t\t\tconst eventProps: ISummarizeEventProps & ISummarizerObservabilityProps = {\n\t\t\t\tresult: status,\n\t\t\t\tcurrentAttempt,\n\t\t\t\tmaxAttempts,\n\t\t\t\terror,\n\t\t\t\tfailureMessage,\n\t\t\t\tnumUnsummarizedRuntimeOps: this.heuristicData.numRuntimeOps,\n\t\t\t\tnumUnsummarizedNonRuntimeOps: this.heuristicData.numNonRuntimeOps,\n\t\t\t};\n\t\t\tthis.emit(\"summarize\", eventProps);\n\n\t\t\t// Break if the failure doesn't have \"retryAfterSeconds\" or we are one less from max number of attempts.\n\t\t\t// Note that the final attempt if \"retryAfterSeconds\" does exist happens outside of the do..while loop.\n\t\t\tif (retryAfterSeconds === undefined || currentAttempt >= maxAttempts - 1) {\n\t\t\t\tdone = true;\n\t\t\t}\n\n\t\t\t// If the failure has \"retryAfterSeconds\", add a delay of that time before starting the next attempt.\n\t\t\tif (retryAfterSeconds !== undefined && retryAfterSeconds > 0) {\n\t\t\t\tthis.mc.logger.sendPerformanceEvent({\n\t\t\t\t\teventName: \"SummarizeAttemptDelay\",\n\t\t\t\t\tduration: retryAfterSeconds * 1000,\n\t\t\t\t\tsummaryNackDelay: ackNackResult.data !== undefined, // This will only be defined only for nack failures.\n\t\t\t\t\tstage: submitSummaryResult.data?.stage,\n\t\t\t\t\t...attemptResult.summarizeProps,\n\t\t\t\t});\n\t\t\t\tawait delay(retryAfterSeconds * 1000);\n\t\t\t}\n\t\t} while (!done);\n\n\t\t// If the attempt was successful, emit \"summarize\" event and return. A failed attempt may be retried below.\n\t\tif (status !== \"failure\") {\n\t\t\tthis.emit(\"summarize\", {\n\t\t\t\tresult: status,\n\t\t\t\tcurrentAttempt,\n\t\t\t\tmaxAttempts,\n\t\t\t\tnumUnsummarizedRuntimeOps: this.heuristicData.numRuntimeOps,\n\t\t\t\tnumUnsummarizedNonRuntimeOps: this.heuristicData.numNonRuntimeOps,\n\t\t\t});\n\t\t\treturn results;\n\t\t}\n\n\t\t// If summarization wasn't successful above and the failure contains \"retryAfterSeconds\", perform one last\n\t\t// attempt. This gives a chance to the runtime to perform additional steps in the last attempt.\n\t\tif (retryAfterSeconds !== undefined) {\n\t\t\tconst { summarizeResult } = attemptSummarize(++currentAttempt, true /* finalAttempt */);\n\t\t\t// Ack / nack is the final step, so if it succeeds we're done.\n\t\t\tconst ackNackResult = await summarizeResult.receivedSummaryAckOrNack;\n\t\t\tstatus = ackNackResult.success ? \"success\" : \"failure\";\n\t\t\terror = ackNackResult.success ? undefined : ackNackResult.error;\n\t\t\tfailureMessage = ackNackResult.success ? undefined : ackNackResult.message;\n\t\t\tconst eventProps: ISummarizeEventProps & ISummarizerObservabilityProps = {\n\t\t\t\tresult: status,\n\t\t\t\tcurrentAttempt,\n\t\t\t\tmaxAttempts,\n\t\t\t\terror,\n\t\t\t\tfailureMessage,\n\t\t\t\tnumUnsummarizedRuntimeOps: this.heuristicData.numRuntimeOps,\n\t\t\t\tnumUnsummarizedNonRuntimeOps: this.heuristicData.numNonRuntimeOps,\n\t\t\t};\n\t\t\tthis.emit(\"summarize\", eventProps);\n\t\t\tresults = summarizeResult;\n\t\t}\n\n\t\t// If summarization is still unsuccessful, stop the summarizer.\n\t\tif (status === \"failure\") {\n\t\t\tthis.mc.logger.sendErrorEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: \"SummarizeFailed\",\n\t\t\t\t\tmaxAttempts,\n\t\t\t\t\tsummaryAttempts: currentAttempt,\n\t\t\t\t\tsummarizeReason: reason,\n\t\t\t\t\tisLastSummary: reason === \"lastSummary\",\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t);\n\t\t\tthis.lastSummarizeFailureEventProps = {\n\t\t\t\tcurrentAttempt,\n\t\t\t\tmaxAttempts,\n\t\t\t\terror,\n\t\t\t\tfailureMessage,\n\t\t\t};\n\t\t\tthis.stopSummarizerCallback(\"failToSummarize\");\n\t\t}\n\t\treturn results;\n\t}\n\n\t/**\n\t * Attempts to generate a summary on demand with retries in case of failures. The retry logic is the same\n\t * as heuristics based summaries.\n\t */\n\tprivate async summarizeOnDemandWithRetries(\n\t\treason: SummarizeReason,\n\t\tresultsBuilder: SummarizeResultBuilder,\n\t\tsummarizeOptions: ISummarizeOptions = {},\n\t): Promise<ISummarizeResults> {\n\t\tconst results = await this.trySummarizeWithRetries(reason, summarizeOptions);\n\t\tif (results === undefined) {\n\t\t\tresultsBuilder.fail(\n\t\t\t\t\"Summarization was canceled\",\n\t\t\t\tnew RetriableSummaryError(\"Summarization was canceled\"),\n\t\t\t);\n\t\t\treturn resultsBuilder.build();\n\t\t}\n\t\tconst submitResult = await results.summarySubmitted;\n\t\tconst summaryOpBroadcastedResult = await results.summaryOpBroadcasted;\n\t\tconst ackNackResult = await results.receivedSummaryAckOrNack;\n\t\tresultsBuilder.summarySubmitted.resolve(submitResult);\n\t\tresultsBuilder.summaryOpBroadcasted.resolve(summaryOpBroadcastedResult);\n\t\tresultsBuilder.receivedSummaryAckOrNack.resolve(ackNackResult);\n\t\treturn resultsBuilder.build();\n\t}\n\n\t/**\n\t *{@inheritdoc (ISummarizer:interface).summarizeOnDemand}\n\t */\n\tpublic summarizeOnDemand(\n\t\toptions: IOnDemandSummarizeOptions,\n\t\tresultsBuilder: SummarizeResultBuilder = new SummarizeResultBuilder(),\n\t): ISummarizeResults {\n\t\tif (this.stopping) {\n\t\t\tresultsBuilder.fail(\n\t\t\t\t\"RunningSummarizer stopped or disposed\",\n\t\t\t\tnew RetriableSummaryError(\"RunningSummarizer stopped or disposed\"),\n\t\t\t);\n\t\t\treturn resultsBuilder.build();\n\t\t}\n\t\t// Check for concurrent summary attempts. If one is found,\n\t\t// return a promise that caller can await before trying again.\n\t\tif (this.summarizingLock !== undefined) {\n\t\t\t// The heuristics are blocking concurrent summarize attempts.\n\t\t\tthrow new UsageError(\"Attempted to run an already-running summarizer on demand\");\n\t\t}\n\n\t\tconst { reason, retryOnFailure, ...summarizeOptions } = options;\n\t\tif (retryOnFailure === true) {\n\t\t\tthis.summarizeOnDemandWithRetries(\n\t\t\t\t`onDemand;${reason}`,\n\t\t\t\tresultsBuilder,\n\t\t\t\tsummarizeOptions,\n\t\t\t).catch((error: IRetriableFailureError) => {\n\t\t\t\tresultsBuilder.fail(\"summarize failed\", error);\n\t\t\t});\n\t\t} else {\n\t\t\tthis.trySummarizeOnce(\n\t\t\t\t{ summarizeReason: `onDemand/${reason}` },\n\t\t\t\tsummarizeOptions,\n\t\t\t\tresultsBuilder,\n\t\t\t);\n\t\t}\n\t\treturn resultsBuilder.build();\n\t}\n\n\t/**\n\t *{@inheritdoc (ISummarizer:interface).enqueueSummarize}\n\t */\n\tpublic enqueueSummarize(options: IEnqueueSummarizeOptions): EnqueueSummarizeResult {\n\t\tconst { reason, afterSequenceNumber = 0, override = false, ...summarizeOptions } = options;\n\t\tlet overridden = false;\n\t\tif (this.enqueuedSummary !== undefined) {\n\t\t\tif (!override) {\n\t\t\t\treturn { alreadyEnqueued: true };\n\t\t\t}\n\t\t\t// Override existing enqueued summarize attempt.\n\t\t\tthis.enqueuedSummary.resultsBuilder.fail(\n\t\t\t\t\"Aborted; overridden by another enqueue summarize attempt\",\n\t\t\t\tnew RetriableSummaryError(\n\t\t\t\t\t\"Summary was overridden by another enqueue summarize attempt\",\n\t\t\t\t),\n\t\t\t);\n\t\t\tthis.enqueuedSummary = undefined;\n\t\t\toverridden = true;\n\t\t}\n\n\t\tthis.enqueuedSummary = {\n\t\t\treason: `enqueue;${reason}`,\n\t\t\tafterSequenceNumber,\n\t\t\tsummarizeOptions,\n\t\t\tresultsBuilder: new SummarizeResultBuilder(),\n\t\t};\n\t\tconst results = this.enqueuedSummary.resultsBuilder.build();\n\t\tthis.tryRunEnqueuedSummary();\n\t\treturn overridden\n\t\t\t? {\n\t\t\t\t\t...results,\n\t\t\t\t\talreadyEnqueued: true,\n\t\t\t\t\toverridden: true,\n\t\t\t\t}\n\t\t\t: results;\n\t}\n\n\tprivate tryRunEnqueuedSummary(): boolean {\n\t\tif (this.stopping) {\n\t\t\tthis.disposeEnqueuedSummary();\n\t\t\treturn false;\n\t\t}\n\t\tif (\n\t\t\tthis.enqueuedSummary === undefined ||\n\t\t\tthis.heuristicData.lastOpSequenceNumber < this.enqueuedSummary.afterSequenceNumber ||\n\t\t\tthis.summarizingLock !== undefined\n\t\t) {\n\t\t\t// If no enqueued summary is ready or a summary is already in progress, take no action.\n\t\t\treturn false;\n\t\t}\n\t\tconst { reason, resultsBuilder, summarizeOptions } = this.enqueuedSummary;\n\t\t// Set to undefined first, so that subsequent enqueue attempt while summarize will occur later.\n\t\tthis.enqueuedSummary = undefined;\n\t\tthis.trySummarizeOnce(\n\t\t\t{ summarizeReason: `enqueuedSummary/${reason}` },\n\t\t\tsummarizeOptions,\n\t\t\tresultsBuilder,\n\t\t);\n\t\treturn true;\n\t}\n\n\tprivate disposeEnqueuedSummary(): void {\n\t\tif (this.enqueuedSummary !== undefined) {\n\t\t\tthis.enqueuedSummary.resultsBuilder.fail(\n\t\t\t\t\"RunningSummarizer stopped or disposed\",\n\t\t\t\tnew RetriableSummaryError(\"RunningSummarizer stopped or disposed\"),\n\t\t\t);\n\t\t\tthis.enqueuedSummary = undefined;\n\t\t}\n\t}\n}\n"]}
|
|
@@ -102,7 +102,7 @@ export declare class Summarizer extends TypedEventEmitter<ISummarizerEvents> imp
|
|
|
102
102
|
summarizeOnDemand(options: IOnDemandSummarizeOptions): ISummarizeResults;
|
|
103
103
|
enqueueSummarize(options: IEnqueueSummarizeOptions): EnqueueSummarizeResult;
|
|
104
104
|
recordSummaryAttempt?(summaryRefSeqNum?: number): void;
|
|
105
|
-
private readonly
|
|
105
|
+
private readonly forwardedEventsCleanup;
|
|
106
106
|
private setupForwardedEvents;
|
|
107
107
|
private cleanupForwardedEvents;
|
|
108
108
|
}
|