@fluidframework/container-runtime 2.0.0-internal.1.0.0.83139 → 2.0.0-internal.1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/.mocharc.js +12 -0
  2. package/dist/batchTracker.js +1 -1
  3. package/dist/batchTracker.js.map +1 -1
  4. package/dist/blobManager.d.ts +7 -1
  5. package/dist/blobManager.d.ts.map +1 -1
  6. package/dist/blobManager.js +34 -17
  7. package/dist/blobManager.js.map +1 -1
  8. package/dist/containerRuntime.d.ts +3 -104
  9. package/dist/containerRuntime.d.ts.map +1 -1
  10. package/dist/containerRuntime.js +83 -395
  11. package/dist/containerRuntime.js.map +1 -1
  12. package/dist/dataStore.d.ts +1 -1
  13. package/dist/dataStore.d.ts.map +1 -1
  14. package/dist/dataStore.js +2 -3
  15. package/dist/dataStore.js.map +1 -1
  16. package/dist/dataStoreContext.d.ts +3 -5
  17. package/dist/dataStoreContext.d.ts.map +1 -1
  18. package/dist/dataStoreContext.js +13 -23
  19. package/dist/dataStoreContext.js.map +1 -1
  20. package/dist/dataStores.d.ts +1 -1
  21. package/dist/dataStores.d.ts.map +1 -1
  22. package/dist/dataStores.js +3 -8
  23. package/dist/dataStores.js.map +1 -1
  24. package/dist/garbageCollection.d.ts +37 -6
  25. package/dist/garbageCollection.d.ts.map +1 -1
  26. package/dist/garbageCollection.js +61 -65
  27. package/dist/garbageCollection.js.map +1 -1
  28. package/dist/index.d.ts +2 -1
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +3 -2
  31. package/dist/index.js.map +1 -1
  32. package/dist/packageVersion.d.ts +1 -1
  33. package/dist/packageVersion.d.ts.map +1 -1
  34. package/dist/packageVersion.js +1 -1
  35. package/dist/packageVersion.js.map +1 -1
  36. package/dist/pendingStateManager.d.ts.map +1 -1
  37. package/dist/pendingStateManager.js +15 -2
  38. package/dist/pendingStateManager.js.map +1 -1
  39. package/dist/runningSummarizer.js +1 -1
  40. package/dist/runningSummarizer.js.map +1 -1
  41. package/dist/scheduleManager.d.ts +28 -0
  42. package/dist/scheduleManager.d.ts.map +1 -0
  43. package/dist/scheduleManager.js +235 -0
  44. package/dist/scheduleManager.js.map +1 -0
  45. package/dist/summarizer.d.ts.map +1 -1
  46. package/dist/summarizer.js +20 -1
  47. package/dist/summarizer.js.map +1 -1
  48. package/dist/summaryCollection.js +1 -1
  49. package/dist/summaryCollection.js.map +1 -1
  50. package/dist/summaryGenerator.js +1 -1
  51. package/dist/summaryGenerator.js.map +1 -1
  52. package/dist/summaryManager.d.ts.map +1 -1
  53. package/dist/summaryManager.js +20 -5
  54. package/dist/summaryManager.js.map +1 -1
  55. package/lib/batchTracker.js +1 -1
  56. package/lib/batchTracker.js.map +1 -1
  57. package/lib/blobManager.d.ts +7 -1
  58. package/lib/blobManager.d.ts.map +1 -1
  59. package/lib/blobManager.js +35 -18
  60. package/lib/blobManager.js.map +1 -1
  61. package/lib/containerRuntime.d.ts +3 -104
  62. package/lib/containerRuntime.d.ts.map +1 -1
  63. package/lib/containerRuntime.js +84 -395
  64. package/lib/containerRuntime.js.map +1 -1
  65. package/lib/dataStore.d.ts +1 -1
  66. package/lib/dataStore.d.ts.map +1 -1
  67. package/lib/dataStore.js +2 -3
  68. package/lib/dataStore.js.map +1 -1
  69. package/lib/dataStoreContext.d.ts +3 -5
  70. package/lib/dataStoreContext.d.ts.map +1 -1
  71. package/lib/dataStoreContext.js +13 -23
  72. package/lib/dataStoreContext.js.map +1 -1
  73. package/lib/dataStores.d.ts +1 -1
  74. package/lib/dataStores.d.ts.map +1 -1
  75. package/lib/dataStores.js +3 -8
  76. package/lib/dataStores.js.map +1 -1
  77. package/lib/garbageCollection.d.ts +37 -6
  78. package/lib/garbageCollection.d.ts.map +1 -1
  79. package/lib/garbageCollection.js +47 -52
  80. package/lib/garbageCollection.js.map +1 -1
  81. package/lib/index.d.ts +2 -1
  82. package/lib/index.d.ts.map +1 -1
  83. package/lib/index.js +2 -1
  84. package/lib/index.js.map +1 -1
  85. package/lib/packageVersion.d.ts +1 -1
  86. package/lib/packageVersion.d.ts.map +1 -1
  87. package/lib/packageVersion.js +1 -1
  88. package/lib/packageVersion.js.map +1 -1
  89. package/lib/pendingStateManager.d.ts.map +1 -1
  90. package/lib/pendingStateManager.js +15 -2
  91. package/lib/pendingStateManager.js.map +1 -1
  92. package/lib/runningSummarizer.js +1 -1
  93. package/lib/runningSummarizer.js.map +1 -1
  94. package/lib/scheduleManager.d.ts +28 -0
  95. package/lib/scheduleManager.d.ts.map +1 -0
  96. package/lib/scheduleManager.js +231 -0
  97. package/lib/scheduleManager.js.map +1 -0
  98. package/lib/summarizer.d.ts.map +1 -1
  99. package/lib/summarizer.js +22 -3
  100. package/lib/summarizer.js.map +1 -1
  101. package/lib/summaryCollection.js +1 -1
  102. package/lib/summaryCollection.js.map +1 -1
  103. package/lib/summaryGenerator.js +1 -1
  104. package/lib/summaryGenerator.js.map +1 -1
  105. package/lib/summaryManager.d.ts.map +1 -1
  106. package/lib/summaryManager.js +20 -5
  107. package/lib/summaryManager.js.map +1 -1
  108. package/package.json +32 -19
  109. package/src/batchTracker.ts +1 -1
  110. package/src/blobManager.ts +43 -17
  111. package/src/containerRuntime.ts +113 -547
  112. package/src/dataStore.ts +1 -4
  113. package/src/dataStoreContext.ts +10 -25
  114. package/src/dataStores.ts +13 -19
  115. package/src/garbageCollection.ts +64 -69
  116. package/src/index.ts +1 -2
  117. package/src/packageVersion.ts +1 -1
  118. package/src/pendingStateManager.ts +18 -2
  119. package/src/runningSummarizer.ts +1 -1
  120. package/src/scheduleManager.ts +294 -0
  121. package/src/summarizer.ts +28 -3
  122. package/src/summaryCollection.ts +1 -1
  123. package/src/summaryGenerator.ts +1 -1
  124. package/src/summaryManager.ts +20 -5
@@ -1 +1 @@
1
- {"version":3,"file":"summaryGenerator.js","sourceRoot":"","sources":["../src/summaryGenerator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAC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AM,EAC1B,cAAc,EAAE,WAAW,CAAC,cAAc,IAC5C;YAEF,KAAK,QAAQ,CAAC,CAAC,qDACR,YAAY,GACZ,WAAW,CAAC,YAAY,KAC3B,gBAAgB,EAAE,WAAW,CAAC,gBAAgB,EAC9C,MAAM,EAAE,WAAW,CAAC,MAAM,EAC1B,cAAc,EAAE,WAAW,CAAC,cAAc,EAC1C,oBAAoB,EAAE,WAAW,CAAC,oBAAoB,EACtD,gBAAgB,EAAE,IAAI,CAAC,aAAa,CAAC,gBAAgB,EACrD,wBAAwB,EAAE,IAAI,CAAC,aAAa,CAAC,YAAY,EACzD,6BAA6B,EAAE,IAAI,CAAC,aAAa,CAAC,gBAAgB,IACpE;YAEF,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,0BAA0B,CAAC,CAAC;SACrD;QAED,OAAO,YAAY,CAAC;IACxB,CAAC;IAEO,qBAAqB,CAAC,IAAY,EAAE,KAAa;QACrD,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC;YAC7B,SAAS,EAAE,kBAAkB;YAC7B,WAAW,EAAE,IAAI;YACjB,YAAY,EAAE,KAAK;SACtB,CAAC,CAAC;QACH,IAAI,KAAK,GAAG,wBAAwB,EAAE;YAClC,+BAA+B;YAC/B,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC;YAC1B,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,qBAAqB,CAAC,QAAQ,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;SAC9F;IACL,CAAC;IAEM,OAAO;QACV,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport {\n assert,\n Deferred,\n IPromiseTimer,\n IPromiseTimerResult,\n Timer,\n} from \"@fluidframework/common-utils\";\nimport { MessageType } from \"@fluidframework/protocol-definitions\";\nimport { PerformanceEvent, LoggingError, ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { getRetryDelaySecondsFromError } from \"@fluidframework/driver-utils\";\nimport { DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport {\n IAckSummaryResult,\n INackSummaryResult,\n ISummarizeOptions,\n IBroadcastSummaryResult,\n ISummarizeResults,\n ISummarizeHeuristicData,\n ISubmitSummaryOptions,\n SubmitSummaryResult,\n SummarizeResultPart,\n ISummaryCancellationToken,\n ISummarizeTelemetryProperties,\n SummaryGeneratorTelemetry,\n} from \"./summarizerTypes\";\nimport { IClientSummaryWatcher } from \"./summaryCollection\";\n\nexport type raceTimerResult<T> =\n { result: \"done\"; value: T; } |\n { result: IPromiseTimerResult[\"timerResult\"]; } |\n { result: \"cancelled\"; };\n\n/** Helper function to wait for a promise or PromiseTimer to elapse. */\nexport async function raceTimer<T>(\n promise: Promise<T>,\n timer: Promise<IPromiseTimerResult>,\n cancellationToken?: ISummaryCancellationToken,\n): Promise<raceTimerResult<T>> {\n const promises: Promise<raceTimerResult<T>>[] = [\n promise.then((value) => ({ result: \"done\", value } as const)),\n timer.then(({ timerResult: result }) => ({ result } as const)),\n ];\n if (cancellationToken !== undefined) {\n promises.push(cancellationToken.waitCancelled.then(() => ({ result: \"cancelled\" } as const)));\n }\n return Promise.race(promises);\n}\n\n// Send some telemetry if generate summary takes too long\nconst maxSummarizeTimeoutTime = 20000; // 20 sec\nconst maxSummarizeTimeoutCount = 5; // Double and resend 5 times\n\nexport type SummarizeReason =\n /**\n * Attempt to summarize after idle timeout has elapsed.\n * Idle timer restarts whenever an op is received. So this\n * triggers only after some amount of time has passed with\n * no ops being received.\n */\n | \"idle\"\n /**\n * Attempt to summarize after a maximum time since last\n * successful summary has passed. This measures time since\n * last summary ack op was processed.\n */\n | \"maxTime\"\n /**\n * Attempt to summarize after a maximum number of ops have\n * passed since the last successful summary. This compares\n * op sequence numbers with the reference sequence number\n * of the summarize op corresponding to the last summary\n * ack op.\n */\n | \"maxOps\"\n /**\n * Special case to attempt to summarize one last time before the\n * summarizer client closes itself. This is to prevent cases where\n * the summarizer client never gets a chance to summarize, because\n * there are too many outstanding ops and/or parent client cannot\n * stay connected long enough for summarizer client to catch up.\n */\n | \"lastSummary\"\n /** On-demand summary requested with specified reason. */\n | `onDemand;${string}`\n /** Enqueue summarize attempt with specified reason. */\n | `enqueue;${string}`;\n\nconst summarizeErrors = {\n /**\n * Error encountered while generating the summary tree, uploading\n * it to storage, or submitting the op. It could be a result of\n * the client becoming disconnected while generating or an actual error.\n */\n submitSummaryFailure: \"Error while generating, uploading, or submitting summary\",\n /**\n * The summaryAckWaitTimeout time has elapsed before receiving the summarize op\n * sent by this summarize attempt. It is expected to be broadcast quickly.\n */\n summaryOpWaitTimeout: \"Timeout while waiting for summarize op broadcast\",\n /**\n * The summaryAckWaitTimeout time has elapsed before receiving either a\n * summaryAck or summaryNack op from the server in response to this\n * summarize attempt. It is expected that the server should respond.\n */\n summaryAckWaitTimeout: \"Timeout while waiting for summaryAck/summaryNack op\",\n /**\n * The server responded with a summaryNack op, thus rejecting this\n * summarize attempt.\n */\n summaryNack: \"Server rejected summary via summaryNack op\",\n\n disconnect: \"Summary cancelled due to summarizer or main client disconnect\",\n} as const;\n\nexport class SummarizeResultBuilder {\n public readonly summarySubmitted = new Deferred<SummarizeResultPart<SubmitSummaryResult>>();\n public readonly summaryOpBroadcasted = new Deferred<SummarizeResultPart<IBroadcastSummaryResult>>();\n public readonly receivedSummaryAckOrNack =\n new Deferred<SummarizeResultPart<IAckSummaryResult, INackSummaryResult>>();\n\n public fail(message: string, error: any, nackSummaryResult?: INackSummaryResult, retryAfterSeconds?: number) {\n assert(!this.receivedSummaryAckOrNack.isCompleted,\n 0x25e /* \"no reason to call fail if all promises have been completed\" */);\n\n const result: SummarizeResultPart<undefined> =\n { success: false, message, data: undefined, error, retryAfterSeconds } as const;\n this.summarySubmitted.resolve(result);\n this.summaryOpBroadcasted.resolve(result);\n this.receivedSummaryAckOrNack.resolve({ ...result, data: nackSummaryResult });\n }\n public build(): ISummarizeResults {\n return {\n summarySubmitted: this.summarySubmitted.promise,\n summaryOpBroadcasted: this.summaryOpBroadcasted.promise,\n receivedSummaryAckOrNack: this.receivedSummaryAckOrNack.promise,\n } as const;\n }\n}\n\n/**\n * This class generates and tracks a summary attempt.\n */\nexport class SummaryGenerator {\n private readonly summarizeTimer: Timer;\n constructor(\n private readonly pendingAckTimer: IPromiseTimer,\n private readonly heuristicData: ISummarizeHeuristicData,\n private readonly submitSummaryCallback: (options: ISubmitSummaryOptions) => Promise<SubmitSummaryResult>,\n private readonly raiseSummarizingError: (errorMessage: string) => void,\n private readonly successfulSummaryCallback: () => void,\n private readonly summaryWatcher: Pick<IClientSummaryWatcher, \"watchSummary\">,\n private readonly logger: ITelemetryLogger,\n ) {\n this.summarizeTimer = new Timer(\n maxSummarizeTimeoutTime,\n () => this.summarizeTimerHandler(maxSummarizeTimeoutTime, 1),\n );\n }\n\n /**\n * Generates summary and listens for broadcast and ack/nack.\n * Returns true for ack, false for nack, and undefined for failure or timeout.\n * @param reason - reason for summarizing\n * @param options - refreshLatestAck to fetch summary ack info from server,\n * fullTree to generate tree without any summary handles even if unchanged\n */\n public summarize(\n summarizeProps: ISummarizeTelemetryProperties,\n options: ISummarizeOptions,\n cancellationToken: ISummaryCancellationToken,\n resultsBuilder = new SummarizeResultBuilder(),\n ): ISummarizeResults {\n this.summarizeCore(summarizeProps, options, resultsBuilder, cancellationToken)\n .catch((error) => {\n const message = \"UnexpectedSummarizeError\";\n this.logger.sendErrorEvent({ eventName: message, ...summarizeProps }, error);\n resultsBuilder.fail(message, error);\n });\n\n return resultsBuilder.build();\n }\n\n private async summarizeCore(\n summarizeProps: ISummarizeTelemetryProperties,\n options: ISummarizeOptions,\n resultsBuilder: SummarizeResultBuilder,\n cancellationToken: ISummaryCancellationToken,\n ): Promise<void> {\n const { refreshLatestAck, fullTree } = options;\n const logger = ChildLogger.create(this.logger, undefined, { all: summarizeProps });\n\n // Note: timeSinceLastAttempt and timeSinceLastSummary for the\n // first summary are basically the time since the summarizer was loaded.\n const timeSinceLastAttempt = Date.now() - this.heuristicData.lastAttempt.summaryTime;\n const timeSinceLastSummary = Date.now() - this.heuristicData.lastSuccessfulSummary.summaryTime;\n let summarizeTelemetryProps: SummaryGeneratorTelemetry = {\n fullTree,\n timeSinceLastAttempt,\n timeSinceLastSummary,\n };\n\n const summarizeEvent = PerformanceEvent.start(logger, {\n eventName: \"Summarize\",\n refreshLatestAck,\n ...summarizeTelemetryProps,\n });\n\n // Helper functions to report failures and return.\n const getFailMessage =\n (errorCode: keyof typeof summarizeErrors) => `${errorCode}: ${summarizeErrors[errorCode]}`;\n const fail = (\n errorCode: keyof typeof summarizeErrors,\n error?: any,\n properties?: SummaryGeneratorTelemetry,\n nackSummaryResult?: INackSummaryResult,\n ) => {\n this.raiseSummarizingError(summarizeErrors[errorCode]);\n // UploadSummary may fail with 429 and retryAfter - respect that\n // Summary Nack also can have retryAfter, it's parsed below and comes as a property.\n const retryAfterSeconds = getRetryDelaySecondsFromError(error);\n\n // Report any failure as an error unless it was due to cancellation (like \"disconnected\" error)\n // If failure happened on upload, we may not yet realized that socket disconnected, so check\n // offlineError too.\n const category = cancellationToken.cancelled || error?.errorType === DriverErrorType.offlineError ?\n \"generic\" : \"error\";\n\n summarizeEvent.cancel({\n ...properties,\n reason: errorCode,\n category,\n retryAfterSeconds,\n }, error);\n resultsBuilder.fail(getFailMessage(errorCode), error, nackSummaryResult, retryAfterSeconds);\n };\n\n // Wait to generate and send summary\n this.summarizeTimer.start();\n\n // Use record type to prevent unexpected value types\n let summaryData: SubmitSummaryResult | undefined;\n try {\n summaryData = await this.submitSummaryCallback({\n fullTree,\n refreshLatestAck,\n summaryLogger: logger,\n cancellationToken,\n });\n\n // Cumulatively add telemetry properties based on how far generateSummary went.\n const referenceSequenceNumber = summaryData.referenceSequenceNumber;\n const opsSinceLastSummary =\n referenceSequenceNumber - this.heuristicData.lastSuccessfulSummary.refSequenceNumber;\n summarizeTelemetryProps = {\n ...summarizeTelemetryProps,\n referenceSequenceNumber,\n minimumSequenceNumber: summaryData.minimumSequenceNumber,\n opsSinceLastAttempt: referenceSequenceNumber - this.heuristicData.lastAttempt.refSequenceNumber,\n opsSinceLastSummary,\n };\n summarizeTelemetryProps = this.addSummaryDataToTelemetryProps(summaryData, summarizeTelemetryProps);\n\n if (summaryData.stage !== \"submit\") {\n return fail(\"submitSummaryFailure\", summaryData.error, summarizeTelemetryProps);\n }\n\n /**\n * With incremental summaries, if the full tree was not summarized, only data stores that changed should\n * be summarized. A data store is considered changed if either or both of the following is true:\n * - It has received an op.\n * - Its reference state changed, i.e., it went from referenced to unreferenced or vice-versa.\n *\n * In the extreme case, every op can be for a different data store and each op can result in the reference\n * state change of multiple data stores. So, the total number of data stores that are summarized should not\n * exceed the number of ops since last summary + number of data store whose reference state changed.\n */\n if (!fullTree && !summaryData.forcedFullTree) {\n const { summarizedDataStoreCount, gcStateUpdatedDataStoreCount = 0 } = summaryData.summaryStats;\n if (summarizedDataStoreCount > gcStateUpdatedDataStoreCount + opsSinceLastSummary) {\n logger.sendErrorEvent({\n eventName: \"IncrementalSummaryViolation\",\n summarizedDataStoreCount,\n gcStateUpdatedDataStoreCount,\n opsSinceLastSummary,\n });\n }\n }\n\n // Log event here on summary success only, as Summarize_cancel duplicates failure logging.\n summarizeEvent.reportEvent(\"generate\", { ...summarizeTelemetryProps });\n resultsBuilder.summarySubmitted.resolve({ success: true, data: summaryData });\n } catch (error) {\n return fail(\"submitSummaryFailure\", error);\n } finally {\n this.heuristicData.recordAttempt(summaryData?.referenceSequenceNumber);\n this.summarizeTimer.clear();\n }\n\n try {\n const pendingTimeoutP = this.pendingAckTimer.start();\n const summary = this.summaryWatcher.watchSummary(summaryData.clientSequenceNumber);\n\n // Wait for broadcast\n const waitBroadcastResult = await raceTimer(summary.waitBroadcast(), pendingTimeoutP, cancellationToken);\n if (waitBroadcastResult.result === \"cancelled\") {\n return fail(\"disconnect\");\n }\n if (waitBroadcastResult.result !== \"done\") {\n return fail(\"summaryOpWaitTimeout\");\n }\n const summarizeOp = waitBroadcastResult.value;\n\n const broadcastDuration = Date.now() - this.heuristicData.lastAttempt.summaryTime;\n resultsBuilder.summaryOpBroadcasted.resolve({\n success: true,\n data: { summarizeOp, broadcastDuration },\n });\n\n this.heuristicData.lastAttempt.summarySequenceNumber = summarizeOp.sequenceNumber;\n logger.sendTelemetryEvent({\n eventName: \"Summarize_Op\",\n duration: broadcastDuration,\n referenceSequenceNumber: summarizeOp.referenceSequenceNumber,\n summarySequenceNumber: summarizeOp.sequenceNumber,\n handle: summarizeOp.contents.handle,\n });\n\n // Wait for ack/nack\n const waitAckNackResult = await raceTimer(summary.waitAckNack(), pendingTimeoutP, cancellationToken);\n if (waitAckNackResult.result === \"cancelled\") {\n return fail(\"disconnect\");\n }\n if (waitAckNackResult.result !== \"done\") {\n return fail(\"summaryAckWaitTimeout\");\n }\n const ackNackOp = waitAckNackResult.value;\n this.pendingAckTimer.clear();\n\n // Update for success/failure\n const ackNackDuration = Date.now() - this.heuristicData.lastAttempt.summaryTime;\n\n // adding new properties\n summarizeTelemetryProps = {\n ackWaitDuration: ackNackDuration,\n ackNackSequenceNumber: ackNackOp.sequenceNumber,\n summarySequenceNumber: ackNackOp.contents.summaryProposal.summarySequenceNumber,\n ...summarizeTelemetryProps,\n };\n if (ackNackOp.type === MessageType.SummaryAck) {\n this.heuristicData.markLastAttemptAsSuccessful();\n this.successfulSummaryCallback();\n summarizeEvent.end({\n ...summarizeTelemetryProps,\n handle: ackNackOp.contents.handle,\n });\n resultsBuilder.receivedSummaryAckOrNack.resolve({ success: true, data: {\n summaryAckOp: ackNackOp,\n ackNackDuration,\n } });\n } else {\n // Check for retryDelay in summaryNack response.\n assert(ackNackOp.type === MessageType.SummaryNack, 0x274 /* \"type check\" */);\n const summaryNack = ackNackOp.contents;\n const message = summaryNack?.message;\n const retryAfterSeconds = summaryNack?.retryAfter;\n\n // pre-0.58 error message prefix: summaryNack\n const error = new LoggingError(`Received summaryNack: ${message}`, { retryAfterSeconds });\n\n assert(getRetryDelaySecondsFromError(error) === retryAfterSeconds, 0x25f /* \"retryAfterSeconds\" */);\n // This will only set resultsBuilder.receivedSummaryAckOrNack, as other promises are already set.\n return fail(\n \"summaryNack\",\n error,\n { ...summarizeTelemetryProps, nackRetryAfter: retryAfterSeconds },\n { summaryNackOp: ackNackOp, ackNackDuration },\n );\n }\n } finally {\n this.pendingAckTimer.clear();\n }\n }\n\n private addSummaryDataToTelemetryProps(\n summaryData: SubmitSummaryResult,\n initialProps: SummaryGeneratorTelemetry,\n ): SummaryGeneratorTelemetry {\n switch (summaryData.stage) {\n case \"base\": return initialProps;\n\n case \"generate\": return {\n ...initialProps,\n ...summaryData.summaryStats,\n generateDuration: summaryData.generateDuration,\n };\n\n case \"upload\": return {\n ...initialProps,\n ...summaryData.summaryStats,\n generateDuration: summaryData.generateDuration,\n handle: summaryData.handle,\n uploadDuration: summaryData.uploadDuration,\n };\n\n case \"submit\": return {\n ...initialProps,\n ...summaryData.summaryStats,\n generateDuration: summaryData.generateDuration,\n handle: summaryData.handle,\n uploadDuration: summaryData.uploadDuration,\n clientSequenceNumber: summaryData.clientSequenceNumber,\n hasMissingOpData: this.heuristicData.hasMissingOpData,\n opsSizesSinceLastSummary: this.heuristicData.totalOpsSize,\n nonRuntimeOpsSinceLastSummary: this.heuristicData.numNonRuntimeOps,\n };\n\n default: assert(true, \"Unexpected summary stage\");\n }\n\n return initialProps;\n }\n\n private summarizeTimerHandler(time: number, count: number) {\n this.logger.sendPerformanceEvent({\n eventName: \"SummarizeTimeout\",\n timeoutTime: time,\n timeoutCount: count,\n });\n if (count < maxSummarizeTimeoutCount) {\n // Double and start a new timer\n const nextTime = time * 2;\n this.summarizeTimer.start(nextTime, () => this.summarizeTimerHandler(nextTime, count + 1));\n }\n }\n\n public dispose() {\n this.summarizeTimer.clear();\n }\n}\n"]}
1
+ {"version":3,"file":"summaryGenerator.js","sourceRoot":"","sources":["../src/summaryGenerator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACH,MAAM,EACN,QAAQ,EAGR,KAAK,GACR,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9F,OAAO,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAsBrE,uEAAuE;AACvE,MAAM,CAAC,KAAK,UAAU,SAAS,CAC3B,OAAmB,EACnB,KAAmC,EACnC,iBAA6C;IAE7C,MAAM,QAAQ,GAAkC;QAC5C,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAY,CAAA,CAAC;QAC7D,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAY,CAAA,CAAC;KACjE,CAAC;IACF,IAAI,iBAAiB,KAAK,SAAS,EAAE;QACjC,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,EAAY,CAAA,CAAC,CAAC,CAAC;KACjG;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAClC,CAAC;AAED,yDAAyD;AACzD,MAAM,uBAAuB,GAAG,KAAK,CAAC,CAAC,SAAS;AAChD,MAAM,wBAAwB,GAAG,CAAC,CAAC,CAAC,4BAA4B;AAqChE,MAAM,eAAe,GAAG;IACpB;;;;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;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport {\n assert,\n Deferred,\n IPromiseTimer,\n IPromiseTimerResult,\n Timer,\n} from \"@fluidframework/common-utils\";\nimport { MessageType } from \"@fluidframework/protocol-definitions\";\nimport { PerformanceEvent, LoggingError, ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { getRetryDelaySecondsFromError } from \"@fluidframework/driver-utils\";\nimport { DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport {\n IAckSummaryResult,\n INackSummaryResult,\n ISummarizeOptions,\n IBroadcastSummaryResult,\n ISummarizeResults,\n ISummarizeHeuristicData,\n ISubmitSummaryOptions,\n SubmitSummaryResult,\n SummarizeResultPart,\n ISummaryCancellationToken,\n ISummarizeTelemetryProperties,\n SummaryGeneratorTelemetry,\n} from \"./summarizerTypes\";\nimport { IClientSummaryWatcher } from \"./summaryCollection\";\n\nexport type raceTimerResult<T> =\n { result: \"done\"; value: T; } |\n { result: IPromiseTimerResult[\"timerResult\"]; } |\n { result: \"cancelled\"; };\n\n/** Helper function to wait for a promise or PromiseTimer to elapse. */\nexport async function raceTimer<T>(\n promise: Promise<T>,\n timer: Promise<IPromiseTimerResult>,\n cancellationToken?: ISummaryCancellationToken,\n): Promise<raceTimerResult<T>> {\n const promises: Promise<raceTimerResult<T>>[] = [\n promise.then((value) => ({ result: \"done\", value } as const)),\n timer.then(({ timerResult: result }) => ({ result } as const)),\n ];\n if (cancellationToken !== undefined) {\n promises.push(cancellationToken.waitCancelled.then(() => ({ result: \"cancelled\" } as const)));\n }\n return Promise.race(promises);\n}\n\n// Send some telemetry if generate summary takes too long\nconst maxSummarizeTimeoutTime = 20000; // 20 sec\nconst maxSummarizeTimeoutCount = 5; // Double and resend 5 times\n\nexport type SummarizeReason =\n /**\n * Attempt to summarize after idle timeout has elapsed.\n * Idle timer restarts whenever an op is received. So this\n * triggers only after some amount of time has passed with\n * no ops being received.\n */\n | \"idle\"\n /**\n * Attempt to summarize after a maximum time since last\n * successful summary has passed. This measures time since\n * last summary ack op was processed.\n */\n | \"maxTime\"\n /**\n * Attempt to summarize after a maximum number of ops have\n * passed since the last successful summary. This compares\n * op sequence numbers with the reference sequence number\n * of the summarize op corresponding to the last summary\n * ack op.\n */\n | \"maxOps\"\n /**\n * Special case to attempt to summarize one last time before the\n * summarizer client closes itself. This is to prevent cases where\n * the summarizer client never gets a chance to summarize, because\n * there are too many outstanding ops and/or parent client cannot\n * stay connected long enough for summarizer client to catch up.\n */\n | \"lastSummary\"\n /** On-demand summary requested with specified reason. */\n | `onDemand;${string}`\n /** Enqueue summarize attempt with specified reason. */\n | `enqueue;${string}`;\n\nconst summarizeErrors = {\n /**\n * Error encountered while generating the summary tree, uploading\n * it to storage, or submitting the op. It could be a result of\n * the client becoming disconnected while generating or an actual error.\n */\n submitSummaryFailure: \"Error while generating, uploading, or submitting summary\",\n /**\n * The summaryAckWaitTimeout time has elapsed before receiving the summarize op\n * sent by this summarize attempt. It is expected to be broadcast quickly.\n */\n summaryOpWaitTimeout: \"Timeout while waiting for summarize op broadcast\",\n /**\n * The summaryAckWaitTimeout time has elapsed before receiving either a\n * summaryAck or summaryNack op from the server in response to this\n * summarize attempt. It is expected that the server should respond.\n */\n summaryAckWaitTimeout: \"Timeout while waiting for summaryAck/summaryNack op\",\n /**\n * The server responded with a summaryNack op, thus rejecting this\n * summarize attempt.\n */\n summaryNack: \"Server rejected summary via summaryNack op\",\n\n disconnect: \"Summary cancelled due to summarizer or main client disconnect\",\n} as const;\n\nexport class SummarizeResultBuilder {\n public readonly summarySubmitted = new Deferred<SummarizeResultPart<SubmitSummaryResult>>();\n public readonly summaryOpBroadcasted = new Deferred<SummarizeResultPart<IBroadcastSummaryResult>>();\n public readonly receivedSummaryAckOrNack =\n new Deferred<SummarizeResultPart<IAckSummaryResult, INackSummaryResult>>();\n\n public fail(message: string, error: any, nackSummaryResult?: INackSummaryResult, retryAfterSeconds?: number) {\n assert(!this.receivedSummaryAckOrNack.isCompleted,\n 0x25e /* \"no reason to call fail if all promises have been completed\" */);\n\n const result: SummarizeResultPart<undefined> =\n { success: false, message, data: undefined, error, retryAfterSeconds } as const;\n this.summarySubmitted.resolve(result);\n this.summaryOpBroadcasted.resolve(result);\n this.receivedSummaryAckOrNack.resolve({ ...result, data: nackSummaryResult });\n }\n public build(): ISummarizeResults {\n return {\n summarySubmitted: this.summarySubmitted.promise,\n summaryOpBroadcasted: this.summaryOpBroadcasted.promise,\n receivedSummaryAckOrNack: this.receivedSummaryAckOrNack.promise,\n } as const;\n }\n}\n\n/**\n * This class generates and tracks a summary attempt.\n */\nexport class SummaryGenerator {\n private readonly summarizeTimer: Timer;\n constructor(\n private readonly pendingAckTimer: IPromiseTimer,\n private readonly heuristicData: ISummarizeHeuristicData,\n private readonly submitSummaryCallback: (options: ISubmitSummaryOptions) => Promise<SubmitSummaryResult>,\n private readonly raiseSummarizingError: (errorMessage: string) => void,\n private readonly successfulSummaryCallback: () => void,\n private readonly summaryWatcher: Pick<IClientSummaryWatcher, \"watchSummary\">,\n private readonly logger: ITelemetryLogger,\n ) {\n this.summarizeTimer = new Timer(\n maxSummarizeTimeoutTime,\n () => this.summarizeTimerHandler(maxSummarizeTimeoutTime, 1),\n );\n }\n\n /**\n * Generates summary and listens for broadcast and ack/nack.\n * Returns true for ack, false for nack, and undefined for failure or timeout.\n * @param reason - reason for summarizing\n * @param options - refreshLatestAck to fetch summary ack info from server,\n * fullTree to generate tree without any summary handles even if unchanged\n */\n public summarize(\n summarizeProps: ISummarizeTelemetryProperties,\n options: ISummarizeOptions,\n cancellationToken: ISummaryCancellationToken,\n resultsBuilder = new SummarizeResultBuilder(),\n ): ISummarizeResults {\n this.summarizeCore(summarizeProps, options, resultsBuilder, cancellationToken)\n .catch((error) => {\n const message = \"UnexpectedSummarizeError\";\n this.logger.sendErrorEvent({ eventName: message, ...summarizeProps }, error);\n resultsBuilder.fail(message, error);\n });\n\n return resultsBuilder.build();\n }\n\n private async summarizeCore(\n summarizeProps: ISummarizeTelemetryProperties,\n options: ISummarizeOptions,\n resultsBuilder: SummarizeResultBuilder,\n cancellationToken: ISummaryCancellationToken,\n ): Promise<void> {\n const { refreshLatestAck, fullTree } = options;\n const logger = ChildLogger.create(this.logger, undefined, { all: summarizeProps });\n\n // Note: timeSinceLastAttempt and timeSinceLastSummary for the\n // first summary are basically the time since the summarizer was loaded.\n const timeSinceLastAttempt = Date.now() - this.heuristicData.lastAttempt.summaryTime;\n const timeSinceLastSummary = Date.now() - this.heuristicData.lastSuccessfulSummary.summaryTime;\n let summarizeTelemetryProps: SummaryGeneratorTelemetry = {\n fullTree,\n timeSinceLastAttempt,\n timeSinceLastSummary,\n };\n\n const summarizeEvent = PerformanceEvent.start(logger, {\n eventName: \"Summarize\",\n refreshLatestAck,\n ...summarizeTelemetryProps,\n });\n\n // Helper functions to report failures and return.\n const getFailMessage =\n (errorCode: keyof typeof summarizeErrors) => `${errorCode}: ${summarizeErrors[errorCode]}`;\n const fail = (\n errorCode: keyof typeof summarizeErrors,\n error?: any,\n properties?: SummaryGeneratorTelemetry,\n nackSummaryResult?: INackSummaryResult,\n ) => {\n this.raiseSummarizingError(summarizeErrors[errorCode]);\n // UploadSummary may fail with 429 and retryAfter - respect that\n // Summary Nack also can have retryAfter, it's parsed below and comes as a property.\n const retryAfterSeconds = getRetryDelaySecondsFromError(error);\n\n // Report any failure as an error unless it was due to cancellation (like \"disconnected\" error)\n // If failure happened on upload, we may not yet realized that socket disconnected, so check\n // offlineError too.\n const category = cancellationToken.cancelled || error?.errorType === DriverErrorType.offlineError ?\n \"generic\" : \"error\";\n\n summarizeEvent.cancel({\n ...properties,\n reason: errorCode,\n category,\n retryAfterSeconds,\n }, error);\n resultsBuilder.fail(getFailMessage(errorCode), error, nackSummaryResult, retryAfterSeconds);\n };\n\n // Wait to generate and send summary\n this.summarizeTimer.start();\n\n // Use record type to prevent unexpected value types\n let summaryData: SubmitSummaryResult | undefined;\n try {\n summaryData = await this.submitSummaryCallback({\n fullTree,\n refreshLatestAck,\n summaryLogger: logger,\n cancellationToken,\n });\n\n // Cumulatively add telemetry properties based on how far generateSummary went.\n const referenceSequenceNumber = summaryData.referenceSequenceNumber;\n const opsSinceLastSummary =\n referenceSequenceNumber - this.heuristicData.lastSuccessfulSummary.refSequenceNumber;\n summarizeTelemetryProps = {\n ...summarizeTelemetryProps,\n referenceSequenceNumber,\n minimumSequenceNumber: summaryData.minimumSequenceNumber,\n opsSinceLastAttempt: referenceSequenceNumber - this.heuristicData.lastAttempt.refSequenceNumber,\n opsSinceLastSummary,\n };\n summarizeTelemetryProps = this.addSummaryDataToTelemetryProps(summaryData, summarizeTelemetryProps);\n\n if (summaryData.stage !== \"submit\") {\n return fail(\"submitSummaryFailure\", summaryData.error, summarizeTelemetryProps);\n }\n\n /**\n * With incremental summaries, if the full tree was not summarized, only data stores that changed should\n * be summarized. A data store is considered changed if either or both of the following is true:\n * - It has received an op.\n * - Its reference state changed, i.e., it went from referenced to unreferenced or vice-versa.\n *\n * In the extreme case, every op can be for a different data store and each op can result in the reference\n * state change of multiple data stores. So, the total number of data stores that are summarized should not\n * exceed the number of ops since last summary + number of data store whose reference state changed.\n */\n if (!fullTree && !summaryData.forcedFullTree) {\n const { summarizedDataStoreCount, gcStateUpdatedDataStoreCount = 0 } = summaryData.summaryStats;\n if (summarizedDataStoreCount > gcStateUpdatedDataStoreCount + opsSinceLastSummary) {\n logger.sendErrorEvent({\n eventName: \"IncrementalSummaryViolation\",\n summarizedDataStoreCount,\n gcStateUpdatedDataStoreCount,\n opsSinceLastSummary,\n });\n }\n }\n\n // Log event here on summary success only, as Summarize_cancel duplicates failure logging.\n summarizeEvent.reportEvent(\"generate\", { ...summarizeTelemetryProps });\n resultsBuilder.summarySubmitted.resolve({ success: true, data: summaryData });\n } catch (error) {\n return fail(\"submitSummaryFailure\", error);\n } finally {\n this.heuristicData.recordAttempt(summaryData?.referenceSequenceNumber);\n this.summarizeTimer.clear();\n }\n\n try {\n const pendingTimeoutP = this.pendingAckTimer.start();\n const summary = this.summaryWatcher.watchSummary(summaryData.clientSequenceNumber);\n\n // Wait for broadcast\n const waitBroadcastResult = await raceTimer(summary.waitBroadcast(), pendingTimeoutP, cancellationToken);\n if (waitBroadcastResult.result === \"cancelled\") {\n return fail(\"disconnect\");\n }\n if (waitBroadcastResult.result !== \"done\") {\n return fail(\"summaryOpWaitTimeout\");\n }\n const summarizeOp = waitBroadcastResult.value;\n\n const broadcastDuration = Date.now() - this.heuristicData.lastAttempt.summaryTime;\n resultsBuilder.summaryOpBroadcasted.resolve({\n success: true,\n data: { summarizeOp, broadcastDuration },\n });\n\n this.heuristicData.lastAttempt.summarySequenceNumber = summarizeOp.sequenceNumber;\n logger.sendTelemetryEvent({\n eventName: \"Summarize_Op\",\n duration: broadcastDuration,\n referenceSequenceNumber: summarizeOp.referenceSequenceNumber,\n summarySequenceNumber: summarizeOp.sequenceNumber,\n handle: summarizeOp.contents.handle,\n });\n\n // Wait for ack/nack\n const waitAckNackResult = await raceTimer(summary.waitAckNack(), pendingTimeoutP, cancellationToken);\n if (waitAckNackResult.result === \"cancelled\") {\n return fail(\"disconnect\");\n }\n if (waitAckNackResult.result !== \"done\") {\n return fail(\"summaryAckWaitTimeout\");\n }\n const ackNackOp = waitAckNackResult.value;\n this.pendingAckTimer.clear();\n\n // Update for success/failure\n const ackNackDuration = Date.now() - this.heuristicData.lastAttempt.summaryTime;\n\n // adding new properties\n summarizeTelemetryProps = {\n ackWaitDuration: ackNackDuration,\n ackNackSequenceNumber: ackNackOp.sequenceNumber,\n summarySequenceNumber: ackNackOp.contents.summaryProposal.summarySequenceNumber,\n ...summarizeTelemetryProps,\n };\n if (ackNackOp.type === MessageType.SummaryAck) {\n this.heuristicData.markLastAttemptAsSuccessful();\n this.successfulSummaryCallback();\n summarizeEvent.end({\n ...summarizeTelemetryProps,\n handle: ackNackOp.contents.handle,\n });\n resultsBuilder.receivedSummaryAckOrNack.resolve({ success: true, data: {\n summaryAckOp: ackNackOp,\n ackNackDuration,\n } });\n } else {\n // Check for retryDelay in summaryNack response.\n assert(ackNackOp.type === MessageType.SummaryNack, 0x274 /* \"type check\" */);\n const summaryNack = ackNackOp.contents;\n const message = summaryNack?.message;\n const retryAfterSeconds = summaryNack?.retryAfter;\n\n // pre-0.58 error message prefix: summaryNack\n const error = new LoggingError(`Received summaryNack: ${message}`, { retryAfterSeconds });\n\n assert(getRetryDelaySecondsFromError(error) === retryAfterSeconds, 0x25f /* \"retryAfterSeconds\" */);\n // This will only set resultsBuilder.receivedSummaryAckOrNack, as other promises are already set.\n return fail(\n \"summaryNack\",\n error,\n { ...summarizeTelemetryProps, nackRetryAfter: retryAfterSeconds },\n { summaryNackOp: ackNackOp, ackNackDuration },\n );\n }\n } finally {\n this.pendingAckTimer.clear();\n }\n }\n\n private addSummaryDataToTelemetryProps(\n summaryData: SubmitSummaryResult,\n initialProps: SummaryGeneratorTelemetry,\n ): SummaryGeneratorTelemetry {\n switch (summaryData.stage) {\n case \"base\": return initialProps;\n\n case \"generate\": return {\n ...initialProps,\n ...summaryData.summaryStats,\n generateDuration: summaryData.generateDuration,\n };\n\n case \"upload\": return {\n ...initialProps,\n ...summaryData.summaryStats,\n generateDuration: summaryData.generateDuration,\n handle: summaryData.handle,\n uploadDuration: summaryData.uploadDuration,\n };\n\n case \"submit\": return {\n ...initialProps,\n ...summaryData.summaryStats,\n generateDuration: summaryData.generateDuration,\n handle: summaryData.handle,\n uploadDuration: summaryData.uploadDuration,\n clientSequenceNumber: summaryData.clientSequenceNumber,\n hasMissingOpData: this.heuristicData.hasMissingOpData,\n opsSizesSinceLastSummary: this.heuristicData.totalOpsSize,\n nonRuntimeOpsSinceLastSummary: this.heuristicData.numNonRuntimeOps,\n };\n\n default: assert(true, 0x397 /* Unexpected summary stage */);\n }\n\n return initialProps;\n }\n\n private summarizeTimerHandler(time: number, count: number) {\n this.logger.sendPerformanceEvent({\n eventName: \"SummarizeTimeout\",\n timeoutTime: time,\n timeoutCount: count,\n });\n if (count < maxSummarizeTimeoutCount) {\n // Double and start a new timer\n const nextTime = time * 2;\n this.summarizeTimer.start(nextTime, () => this.summarizeTimerHandler(nextTime, count + 1));\n }\n }\n\n public dispose() {\n this.summarizeTimer.clear();\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"summaryManager.d.ts","sourceRoot":"","sources":["../src/summaryManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAI3G,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACH,WAAW,EAEd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAKxD,oBAAY,mBAAmB;IAC3B,GAAG,IAAI;IACP,QAAQ,IAAI;IACZ,OAAO,IAAI;IACX,QAAQ,IAAI;CACf;AAUD,MAAM,WAAW,gBAAiB,SAAQ,MAAM;IAC5C,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,OAAE;IAC3D,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,IAAI,OAAE;CACjD;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAgB,SAAQ,cAAc,CAAC,gBAAgB,CAAC;IACrE,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAE5B;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CACzC;AAED,MAAM,WAAW,qBAAqB;IAClC,cAAc,EAAE,MAAM,CAAC;IACvB,uBAAuB,EAAE,MAAM,CAAC;CACnC;AAED;;;;GAI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OAAO,CAAC,QAAQ,CAAC,iBAAiB,CA+BhC;IAEF,OAAO,CAAC,kBAAkB;IAsG1B,OAAO,CAAC,IAAI;IAWZ;;;;OAIG;YACW,6BAA6B;IAqD3C,SAAgB,iBAAiB,EAAE,WAAW,CAAC,mBAAmB,CAAC,CAMjE;IAEF,SAAgB,gBAAgB,EAAE,WAAW,CAAC,kBAAkB,CAAC,CAM/D;IAEK,OAAO;CAMjB"}
@@ -5,6 +5,7 @@
5
5
  import { assert } from "@fluidframework/common-utils";
6
6
  import { ChildLogger, PerformanceEvent } from "@fluidframework/telemetry-utils";
7
7
  import { DriverErrorType } from "@fluidframework/driver-definitions";
8
+ import { Summarizer } from "./summarizer";
8
9
  const defaultInitialDelayMs = 5000;
9
10
  const defaultOpsToBypassInitialDelay = 4000;
10
11
  export var SummaryManagerState;
@@ -137,8 +138,12 @@ export class SummaryManager {
137
138
  // a summarizer to kick off lastSummary. Without that, we would not be able to summarize and get
138
139
  // document out of broken state if it has too many ops and ordering service keeps nacking main
139
140
  // container (and thus it goes into cycle of reconnects)
140
- if (startWithInitialDelay && this.getShouldSummarizeState().shouldSummarize === false) {
141
- return "early exit";
141
+ // If we can't run the LastSummary, simply return as to avoid paying the cost of launching
142
+ // the summarizer at all.
143
+ const shouldSummarizeStateEarlyStage = this.getShouldSummarizeState();
144
+ if (startWithInitialDelay &&
145
+ shouldSummarizeStateEarlyStage.shouldSummarize === false) {
146
+ return `early exit ${shouldSummarizeStateEarlyStage.stopReason}`;
142
147
  }
143
148
  // We transition to Running before requesting the summarizer, because after requesting we can't predict
144
149
  // when the electedClient will be replaced with the new summarizer client.
@@ -149,11 +154,21 @@ export class SummaryManager {
149
154
  const summarizer = await this.requestSummarizerFn();
150
155
  this.summarizer = summarizer;
151
156
  // Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore
157
+ // If we can't run the LastSummary, simply return as to avoid paying the cost of launching
158
+ // the summarizer at all.
152
159
  const shouldSummarizeState = this.getShouldSummarizeState();
153
160
  if (shouldSummarizeState.shouldSummarize === false) {
154
- this.state = SummaryManagerState.Starting;
155
- summarizer.stop(shouldSummarizeState.stopReason);
156
- return "early exit after starting summarizer";
161
+ // In order to allow the last summary to run, we not only need a stop reason that would
162
+ // allow it but also, startWithInitialDelay to be false (start the summarization immediately),
163
+ // which would happen when we have a high enough number of unsummarized ops.
164
+ if (startWithInitialDelay || !Summarizer.stopReasonCanRunLastSummary(shouldSummarizeState.stopReason)) {
165
+ this.state = SummaryManagerState.Starting;
166
+ summarizer.stop(shouldSummarizeState.stopReason);
167
+ return `early exit after starting summarizer ${shouldSummarizeState.stopReason}`;
168
+ }
169
+ this.logger.sendTelemetryEvent({
170
+ eventName: "LastAttemptToSummarize",
171
+ });
157
172
  }
158
173
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
159
174
  const clientId = this.latestClientId;
@@ -1 +1 @@
1
- {"version":3,"file":"summaryManager.js","sourceRoot":"","sources":["../src/summaryManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AASrE,MAAM,qBAAqB,GAAG,IAAI,CAAC;AACnC,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAE5C,MAAM,CAAN,IAAY,mBAKX;AALD,WAAY,mBAAmB;IAC3B,2DAAO,CAAA;IACP,qEAAY,CAAA;IACZ,mEAAW,CAAA;IACX,qEAAY,CAAA;AAChB,CAAC,EALW,mBAAmB,KAAnB,mBAAmB,QAK9B;AAuCD;;;;GAIG;AACH,MAAM,OAAO,cAAc;IAevB,YACqB,cAAyC,EACzC,cAA+B,EAC/B,iBACoE,EACrF,YAA8B;IAC9B;2CACuC;IACtB,mBAA+C,EAC/C,cAA0B,EAC3C,EACI,cAAc,GAAG,qBAAqB,EACtC,uBAA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AAK,KAAK,mBAAmB,CAAC,OAAO,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDisposable, IEvent, IEventProvider, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ChildLogger, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport { ISummarizerClientElection } from \"./summarizerClientElection\";\nimport { IThrottler } from \"./throttler\";\nimport {\n ISummarizer,\n SummarizerStopReason,\n} from \"./summarizerTypes\";\nimport { SummaryCollection } from \"./summaryCollection\";\n\nconst defaultInitialDelayMs = 5000;\nconst defaultOpsToBypassInitialDelay = 4000;\n\nexport enum SummaryManagerState {\n Off = 0,\n Starting = 1,\n Running = 2,\n Stopping = 3,\n}\n\n// Please note that all reasons in this list are not errors,\n// and thus they are not raised today to parent container as error.\n// If this needs to be changed in future, we should re-evaluate what and how we raise to summarizer\ntype StopReason = Extract<SummarizerStopReason, \"parentNotConnected\" | \"parentShouldNotSummarize\">;\ntype ShouldSummarizeState =\n | { shouldSummarize: true; }\n | { shouldSummarize: false; stopReason: StopReason; };\n\nexport interface IConnectedEvents extends IEvent {\n (event: \"connected\", listener: (clientId: string) => void);\n (event: \"disconnected\", listener: () => void);\n}\n\n/**\n * IConnectedState describes an object that SummaryManager can watch to observe connection/disconnection.\n *\n * Under current implementation, its role will be fulfilled by the ContainerRuntime, but this could be replaced\n * with anything else that fulfills the contract if we want to shift the layer that the SummaryManager lives at.\n */\nexport interface IConnectedState extends IEventProvider<IConnectedEvents> {\n readonly connected: boolean;\n\n /**\n * Under current implementation this is undefined if we've never connected, otherwise it's the clientId from our\n * latest connection (even if we've since disconnected!). Although this happens to be the behavior we want in\n * SummaryManager, I suspect that globally we may eventually want to modify this behavior (e.g. make clientId\n * undefined while disconnected). To protect against this, let's assume this field can't be trusted while\n * disconnected and instead separately track \"latest clientId\" in SummaryManager.\n */\n readonly clientId: string | undefined;\n}\n\nexport interface ISummaryManagerConfig {\n initialDelayMs: number;\n opsToBypassInitialDelay: number;\n}\n\n/**\n * SummaryManager is created by parent container (i.e. interactive container with clientType !== \"summarizer\") only.\n * It observes changes in calculated summarizer and reacts to changes by either creating summarizer client or\n * stopping existing summarizer client.\n */\nexport class SummaryManager implements IDisposable {\n private readonly logger: ITelemetryLogger;\n private readonly opsToBypassInitialDelay: number;\n private readonly initialDelayMs: number;\n private latestClientId: string | undefined;\n private state = SummaryManagerState.Off;\n private summarizer?: ISummarizer;\n private _disposed = false;\n\n public get disposed() {\n return this._disposed;\n }\n\n public get currentState() { return this.state; }\n\n constructor(\n private readonly clientElection: ISummarizerClientElection,\n private readonly connectedState: IConnectedState,\n private readonly summaryCollection:\n Pick<SummaryCollection, \"opsSinceLastAck\" | \"addOpListener\" | \"removeOpListener\">,\n parentLogger: ITelemetryLogger,\n /** Creates summarizer by asking interactive container to spawn summarizing container and\n * get back its Summarizer instance. */\n private readonly requestSummarizerFn: () => Promise<ISummarizer>,\n private readonly startThrottler: IThrottler,\n {\n initialDelayMs = defaultInitialDelayMs,\n opsToBypassInitialDelay = defaultOpsToBypassInitialDelay,\n }: Readonly<Partial<ISummaryManagerConfig>> = {},\n private readonly disableHeuristics?: boolean,\n ) {\n this.logger = ChildLogger.create(\n parentLogger,\n \"SummaryManager\",\n { all: { clientId: () => this.latestClientId } });\n\n this.connectedState.on(\"connected\", this.handleConnected);\n this.connectedState.on(\"disconnected\", this.handleDisconnected);\n this.latestClientId = this.connectedState.clientId;\n\n this.opsToBypassInitialDelay = opsToBypassInitialDelay;\n this.initialDelayMs = initialDelayMs;\n }\n\n /**\n * Until start is called, the SummaryManager won't begin attempting to start summarization. This ensures there's\n * a window between construction and starting where the caller can attach listeners.\n */\n public start(): void {\n this.clientElection.on(\"electedSummarizerChanged\", this.refreshSummarizer);\n this.refreshSummarizer();\n }\n\n private readonly handleConnected = (clientId: string) => {\n this.latestClientId = clientId;\n // If we have a summarizer, it should have been either cancelled on disconnected by now.\n // But because of lastSummary process, it can still hang around, so there is not much we can\n // check or assert.\n this.refreshSummarizer();\n };\n\n private readonly handleDisconnected = () => {\n this.refreshSummarizer();\n };\n\n private static readonly isStartingOrRunning = (state: SummaryManagerState) =>\n state === SummaryManagerState.Starting || state === SummaryManagerState.Running;\n\n private getShouldSummarizeState(): ShouldSummarizeState {\n // Note that if we're in the Running state, the electedClient may be a summarizer client, so we can't\n // enforce connectedState.clientId === clientElection.electedClientId. But once we're Running, we should\n // only transition to Stopping when the electedParentId changes. Stopping the summarizer without\n // changing the electedParent will just cause us to transition to Starting again.\n if (this.connectedState.clientId !== this.clientElection.electedParentId ||\n (this.state !== SummaryManagerState.Running &&\n this.connectedState.clientId !== this.clientElection.electedClientId)) {\n return { shouldSummarize: false, stopReason: \"parentShouldNotSummarize\" };\n } else if (!this.connectedState.connected) {\n return { shouldSummarize: false, stopReason: \"parentNotConnected\" };\n } else if (this.disposed) {\n assert(false, 0x260 /* \"Disposed should mean disconnected!\" */);\n } else {\n return { shouldSummarize: true };\n }\n }\n\n private readonly refreshSummarizer = () => {\n // Transition states depending on shouldSummarize, which is a calculated property\n // that is only true if this client is connected and is the elected summarizer.\n const shouldSummarizeState = this.getShouldSummarizeState();\n switch (this.state) {\n case SummaryManagerState.Off: {\n if (shouldSummarizeState.shouldSummarize) {\n this.startSummarization();\n }\n return;\n }\n case SummaryManagerState.Starting: {\n // Cannot take any action until summarizer is created\n // state transition will occur after creation\n return;\n }\n case SummaryManagerState.Running: {\n if (shouldSummarizeState.shouldSummarize === false) {\n this.stop(shouldSummarizeState.stopReason);\n }\n return;\n }\n case SummaryManagerState.Stopping: {\n // Cannot take any action until running summarizer finishes\n // state transition will occur after it stops\n return;\n }\n default: {\n return;\n }\n }\n };\n\n private startSummarization() {\n assert(this.state === SummaryManagerState.Off, 0x261 /* \"Expected: off\" */);\n this.state = SummaryManagerState.Starting;\n\n assert(this.summarizer === undefined, 0x262 /* \"Old summarizer is still working!\" */);\n\n this.delayBeforeCreatingSummarizer().then(async (startWithInitialDelay: boolean) => {\n // Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore\n // but only if creation was delayed. If it was not, then we want to ensure we always create\n // a summarizer to kick off lastSummary. Without that, we would not be able to summarize and get\n // document out of broken state if it has too many ops and ordering service keeps nacking main\n // container (and thus it goes into cycle of reconnects)\n if (startWithInitialDelay && this.getShouldSummarizeState().shouldSummarize === false) {\n return \"early exit\";\n }\n\n // We transition to Running before requesting the summarizer, because after requesting we can't predict\n // when the electedClient will be replaced with the new summarizer client.\n // The alternative would be to let connectedState.clientId !== clientElection.electedClientId when\n // state === Starting || state === Running.\n assert(this.state === SummaryManagerState.Starting, 0x263 /* \"Expected: starting\" */);\n this.state = SummaryManagerState.Running;\n\n const summarizer = await this.requestSummarizerFn();\n this.summarizer = summarizer;\n\n // Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore\n const shouldSummarizeState = this.getShouldSummarizeState();\n if (shouldSummarizeState.shouldSummarize === false) {\n this.state = SummaryManagerState.Starting;\n summarizer.stop(shouldSummarizeState.stopReason);\n return \"early exit after starting summarizer\";\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const clientId = this.latestClientId!;\n\n return PerformanceEvent.timedExecAsync(\n this.logger,\n { eventName: \"RunningSummarizer\", attempt: this.startThrottler.numAttempts },\n async () => summarizer.run(clientId, this.disableHeuristics),\n );\n }).then((reason: string) => {\n this.logger.sendTelemetryEvent({\n eventName: \"EndingSummarizer\",\n reason,\n });\n }).catch((error) => {\n this.logger.sendTelemetryEvent(\n {\n eventName: \"EndingSummarizer\",\n reason: \"exception\",\n },\n error);\n\n // Most of exceptions happen due to container being closed while loading it, due to\n // summarizer container loosing connection while load.\n // Not worth reporting such errors as errors. That said, we might miss some real errors if\n // we ignore blindly, so try to narrow signature we are looking for - skip logging\n // error only if this client should no longer be a summarizer (which in practice\n // means it also lost connection), and error happened on load (we do not have summarizer).\n // We could annotate the error raised in Container.load where the container closed during load with no error\n // and check for that case here, but that does not seem to be necessary.\n if (this.getShouldSummarizeState().shouldSummarize || this.summarizer !== undefined) {\n // Report any failure as an error unless it was due to cancellation (like \"disconnected\" error)\n // If failure happened on container load, we may not yet realized that socket disconnected, so check\n // offlineError.\n const category = error?.errorType === DriverErrorType.offlineError ? \"generic\" : \"error\";\n this.logger.sendTelemetryEvent(\n {\n eventName: \"SummarizerException\",\n category,\n },\n error);\n }\n }).finally(() => {\n assert(this.state !== SummaryManagerState.Off, 0x264 /* \"Expected: Not Off\" */);\n this.state = SummaryManagerState.Off;\n\n this.summarizer?.close();\n this.summarizer = undefined;\n\n if (this.getShouldSummarizeState().shouldSummarize) {\n this.startSummarization();\n }\n });\n }\n\n private stop(reason: SummarizerStopReason) {\n if (!SummaryManager.isStartingOrRunning(this.state)) {\n return;\n }\n this.state = SummaryManagerState.Stopping;\n\n // Stopping the running summarizer client should trigger a change\n // in states when the running summarizer closes\n this.summarizer?.stop(reason);\n }\n\n /**\n * Implements initial delay before creating summarizer\n * @returns true, if creation is delayed due to heuristics (not many ops to summarize).\n * False if summarizer should start immediately due to too many unsummarized ops.\n */\n private async delayBeforeCreatingSummarizer(): Promise<boolean> {\n // throttle creation of new summarizer containers to prevent spamming the server with websocket connections\n let delayMs = this.startThrottler.getDelay();\n\n // We have been elected the summarizer. Some day we may be able to summarize with a live document but for\n // now we play it safe and launch a second copy.\n this.logger.sendTelemetryEvent({\n eventName: \"CreatingSummarizer\",\n throttlerDelay: delayMs,\n initialDelay: this.initialDelayMs,\n startThrottlerMaxDelayMs: this.startThrottler.maxDelayMs,\n opsSinceLastAck: this.summaryCollection.opsSinceLastAck,\n opsToBypassInitialDelay: this.opsToBypassInitialDelay,\n });\n\n // This delay helps ensure that last summarizer that might be left from previous client\n // has enough time to complete its last summary and thus new summarizer not conflict with previous one.\n // If, however, there are too many unsummarized ops, try to resolve it as quickly as possible, with\n // understanding that we may see nacks because of such quick action.\n // A better design would be for summarizer election logic to always select current summarizer as\n // summarizing client (i.e. clientType === \"summarizer\" can be elected) to ensure that nobody else can\n // summarizer while it finishes its work and moves to exit.\n // It also helps with pure boot scenario (single client) to offset expensive work a bit out from\n // critical boot sequence.\n let startWithInitialDelay = false;\n if (this.summaryCollection.opsSinceLastAck < this.opsToBypassInitialDelay) {\n startWithInitialDelay = true;\n delayMs = Math.max(delayMs, this.initialDelayMs);\n }\n\n if (delayMs > 0) {\n let timer;\n let resolveOpPromiseFn;\n // Create a listener that will break the delay if we've exceeded the initial delay ops count.\n const opsListenerFn = () => {\n if (this.summaryCollection.opsSinceLastAck >= this.opsToBypassInitialDelay) {\n clearTimeout(timer);\n resolveOpPromiseFn();\n }\n };\n // Create a Promise that will resolve when the delay expires.\n const delayPromise = new Promise<void>((resolve) => {\n timer = setTimeout(() => resolve(), delayMs);\n });\n // Create a Promise that will resolve if the ops count passes the threshold.\n const opPromise = new Promise<void>((resolve) => { resolveOpPromiseFn = resolve; });\n this.summaryCollection.addOpListener(opsListenerFn);\n await Promise.race([delayPromise, opPromise]);\n this.summaryCollection.removeOpListener(opsListenerFn);\n }\n return startWithInitialDelay;\n }\n\n public readonly summarizeOnDemand: ISummarizer[\"summarizeOnDemand\"] = (...args) => {\n if (this.summarizer === undefined) {\n throw Error(\"No running summarizer client\");\n // TODO: could spawn a summarizer client temporarily.\n }\n return this.summarizer.summarizeOnDemand(...args);\n };\n\n public readonly enqueueSummarize: ISummarizer[\"enqueueSummarize\"] = (...args) => {\n if (this.summarizer === undefined) {\n throw Error(\"No running summarizer client\");\n // TODO: could spawn a summarizer client temporarily.\n }\n return this.summarizer.enqueueSummarize(...args);\n };\n\n public dispose() {\n this.clientElection.off(\"electedSummarizerChanged\", this.refreshSummarizer);\n this.connectedState.off(\"connected\", this.handleConnected);\n this.connectedState.off(\"disconnected\", this.handleDisconnected);\n this._disposed = true;\n }\n}\n"]}
1
+ {"version":3,"file":"summaryManager.js","sourceRoot":"","sources":["../src/summ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E,YAAY,CAAC,KAAK,CAAC,CAAC;oBACpB,kBAAkB,EAAE,CAAC;iBACxB;YACL,CAAC,CAAC;YACF,6DAA6D;YAC7D,MAAM,YAAY,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;gBAC/C,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;YACjD,CAAC,CAAC,CAAC;YACH,4EAA4E;YAC5E,MAAM,SAAS,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,GAAG,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YACpF,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;YACpD,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC;YAC9C,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;SAC1D;QACD,OAAO,qBAAqB,CAAC;IACjC,CAAC;IAkBM,OAAO;QACV,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,0BAA0B,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAC5E,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAC3D,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACjE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IAC1B,CAAC;;AAtPuB,kCAAmB,GAAG,CAAC,KAA0B,EAAE,EAAE,CACzE,KAAK,KAAK,mBAAmB,CAAC,QAAQ,IAAI,KAAK,KAAK,mBAAmB,CAAC,OAAO,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDisposable, IEvent, IEventProvider, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ChildLogger, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport { ISummarizerClientElection } from \"./summarizerClientElection\";\nimport { IThrottler } from \"./throttler\";\nimport {\n ISummarizer,\n SummarizerStopReason,\n} from \"./summarizerTypes\";\nimport { SummaryCollection } from \"./summaryCollection\";\nimport { Summarizer } from \"./summarizer\";\n\nconst defaultInitialDelayMs = 5000;\nconst defaultOpsToBypassInitialDelay = 4000;\n\nexport enum SummaryManagerState {\n Off = 0,\n Starting = 1,\n Running = 2,\n Stopping = 3,\n}\n\n// Please note that all reasons in this list are not errors,\n// and thus they are not raised today to parent container as error.\n// If this needs to be changed in future, we should re-evaluate what and how we raise to summarizer\ntype StopReason = Extract<SummarizerStopReason, \"parentNotConnected\" | \"parentShouldNotSummarize\">;\ntype ShouldSummarizeState =\n | { shouldSummarize: true; }\n | { shouldSummarize: false; stopReason: StopReason; };\n\nexport interface IConnectedEvents extends IEvent {\n (event: \"connected\", listener: (clientId: string) => void);\n (event: \"disconnected\", listener: () => void);\n}\n\n/**\n * IConnectedState describes an object that SummaryManager can watch to observe connection/disconnection.\n *\n * Under current implementation, its role will be fulfilled by the ContainerRuntime, but this could be replaced\n * with anything else that fulfills the contract if we want to shift the layer that the SummaryManager lives at.\n */\nexport interface IConnectedState extends IEventProvider<IConnectedEvents> {\n readonly connected: boolean;\n\n /**\n * Under current implementation this is undefined if we've never connected, otherwise it's the clientId from our\n * latest connection (even if we've since disconnected!). Although this happens to be the behavior we want in\n * SummaryManager, I suspect that globally we may eventually want to modify this behavior (e.g. make clientId\n * undefined while disconnected). To protect against this, let's assume this field can't be trusted while\n * disconnected and instead separately track \"latest clientId\" in SummaryManager.\n */\n readonly clientId: string | undefined;\n}\n\nexport interface ISummaryManagerConfig {\n initialDelayMs: number;\n opsToBypassInitialDelay: number;\n}\n\n/**\n * SummaryManager is created by parent container (i.e. interactive container with clientType !== \"summarizer\") only.\n * It observes changes in calculated summarizer and reacts to changes by either creating summarizer client or\n * stopping existing summarizer client.\n */\nexport class SummaryManager implements IDisposable {\n private readonly logger: ITelemetryLogger;\n private readonly opsToBypassInitialDelay: number;\n private readonly initialDelayMs: number;\n private latestClientId: string | undefined;\n private state = SummaryManagerState.Off;\n private summarizer?: ISummarizer;\n private _disposed = false;\n\n public get disposed() {\n return this._disposed;\n }\n\n public get currentState() { return this.state; }\n\n constructor(\n private readonly clientElection: ISummarizerClientElection,\n private readonly connectedState: IConnectedState,\n private readonly summaryCollection:\n Pick<SummaryCollection, \"opsSinceLastAck\" | \"addOpListener\" | \"removeOpListener\">,\n parentLogger: ITelemetryLogger,\n /** Creates summarizer by asking interactive container to spawn summarizing container and\n * get back its Summarizer instance. */\n private readonly requestSummarizerFn: () => Promise<ISummarizer>,\n private readonly startThrottler: IThrottler,\n {\n initialDelayMs = defaultInitialDelayMs,\n opsToBypassInitialDelay = defaultOpsToBypassInitialDelay,\n }: Readonly<Partial<ISummaryManagerConfig>> = {},\n private readonly disableHeuristics?: boolean,\n ) {\n this.logger = ChildLogger.create(\n parentLogger,\n \"SummaryManager\",\n { all: { clientId: () => this.latestClientId } });\n\n this.connectedState.on(\"connected\", this.handleConnected);\n this.connectedState.on(\"disconnected\", this.handleDisconnected);\n this.latestClientId = this.connectedState.clientId;\n\n this.opsToBypassInitialDelay = opsToBypassInitialDelay;\n this.initialDelayMs = initialDelayMs;\n }\n\n /**\n * Until start is called, the SummaryManager won't begin attempting to start summarization. This ensures there's\n * a window between construction and starting where the caller can attach listeners.\n */\n public start(): void {\n this.clientElection.on(\"electedSummarizerChanged\", this.refreshSummarizer);\n this.refreshSummarizer();\n }\n\n private readonly handleConnected = (clientId: string) => {\n this.latestClientId = clientId;\n // If we have a summarizer, it should have been either cancelled on disconnected by now.\n // But because of lastSummary process, it can still hang around, so there is not much we can\n // check or assert.\n this.refreshSummarizer();\n };\n\n private readonly handleDisconnected = () => {\n this.refreshSummarizer();\n };\n\n private static readonly isStartingOrRunning = (state: SummaryManagerState) =>\n state === SummaryManagerState.Starting || state === SummaryManagerState.Running;\n\n private getShouldSummarizeState(): ShouldSummarizeState {\n // Note that if we're in the Running state, the electedClient may be a summarizer client, so we can't\n // enforce connectedState.clientId === clientElection.electedClientId. But once we're Running, we should\n // only transition to Stopping when the electedParentId changes. Stopping the summarizer without\n // changing the electedParent will just cause us to transition to Starting again.\n if (this.connectedState.clientId !== this.clientElection.electedParentId ||\n (this.state !== SummaryManagerState.Running &&\n this.connectedState.clientId !== this.clientElection.electedClientId)) {\n return { shouldSummarize: false, stopReason: \"parentShouldNotSummarize\" };\n } else if (!this.connectedState.connected) {\n return { shouldSummarize: false, stopReason: \"parentNotConnected\" };\n } else if (this.disposed) {\n assert(false, 0x260 /* \"Disposed should mean disconnected!\" */);\n } else {\n return { shouldSummarize: true };\n }\n }\n\n private readonly refreshSummarizer = () => {\n // Transition states depending on shouldSummarize, which is a calculated property\n // that is only true if this client is connected and is the elected summarizer.\n const shouldSummarizeState = this.getShouldSummarizeState();\n switch (this.state) {\n case SummaryManagerState.Off: {\n if (shouldSummarizeState.shouldSummarize) {\n this.startSummarization();\n }\n return;\n }\n case SummaryManagerState.Starting: {\n // Cannot take any action until summarizer is created\n // state transition will occur after creation\n return;\n }\n case SummaryManagerState.Running: {\n if (shouldSummarizeState.shouldSummarize === false) {\n this.stop(shouldSummarizeState.stopReason);\n }\n return;\n }\n case SummaryManagerState.Stopping: {\n // Cannot take any action until running summarizer finishes\n // state transition will occur after it stops\n return;\n }\n default: {\n return;\n }\n }\n };\n\n private startSummarization() {\n assert(this.state === SummaryManagerState.Off, 0x261 /* \"Expected: off\" */);\n this.state = SummaryManagerState.Starting;\n\n assert(this.summarizer === undefined, 0x262 /* \"Old summarizer is still working!\" */);\n\n this.delayBeforeCreatingSummarizer().then(async (startWithInitialDelay: boolean) => {\n // Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore\n // but only if creation was delayed. If it was not, then we want to ensure we always create\n // a summarizer to kick off lastSummary. Without that, we would not be able to summarize and get\n // document out of broken state if it has too many ops and ordering service keeps nacking main\n // container (and thus it goes into cycle of reconnects)\n // If we can't run the LastSummary, simply return as to avoid paying the cost of launching\n // the summarizer at all.\n const shouldSummarizeStateEarlyStage = this.getShouldSummarizeState();\n if (startWithInitialDelay &&\n shouldSummarizeStateEarlyStage.shouldSummarize === false) {\n return `early exit ${shouldSummarizeStateEarlyStage.stopReason}`;\n }\n\n // We transition to Running before requesting the summarizer, because after requesting we can't predict\n // when the electedClient will be replaced with the new summarizer client.\n // The alternative would be to let connectedState.clientId !== clientElection.electedClientId when\n // state === Starting || state === Running.\n assert(this.state === SummaryManagerState.Starting, 0x263 /* \"Expected: starting\" */);\n this.state = SummaryManagerState.Running;\n\n const summarizer = await this.requestSummarizerFn();\n this.summarizer = summarizer;\n\n // Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore\n // If we can't run the LastSummary, simply return as to avoid paying the cost of launching\n // the summarizer at all.\n const shouldSummarizeState = this.getShouldSummarizeState();\n if (shouldSummarizeState.shouldSummarize === false) {\n // In order to allow the last summary to run, we not only need a stop reason that would\n // allow it but also, startWithInitialDelay to be false (start the summarization immediately),\n // which would happen when we have a high enough number of unsummarized ops.\n if (startWithInitialDelay || !Summarizer.stopReasonCanRunLastSummary(shouldSummarizeState.stopReason)) {\n this.state = SummaryManagerState.Starting;\n summarizer.stop(shouldSummarizeState.stopReason);\n return `early exit after starting summarizer ${shouldSummarizeState.stopReason}`;\n }\n this.logger.sendTelemetryEvent({\n eventName: \"LastAttemptToSummarize\",\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const clientId = this.latestClientId!;\n\n return PerformanceEvent.timedExecAsync(\n this.logger,\n { eventName: \"RunningSummarizer\", attempt: this.startThrottler.numAttempts },\n async () => summarizer.run(clientId, this.disableHeuristics),\n );\n }).then((reason: string) => {\n this.logger.sendTelemetryEvent({\n eventName: \"EndingSummarizer\",\n reason,\n });\n }).catch((error) => {\n this.logger.sendTelemetryEvent(\n {\n eventName: \"EndingSummarizer\",\n reason: \"exception\",\n },\n error);\n\n // Most of exceptions happen due to container being closed while loading it, due to\n // summarizer container loosing connection while load.\n // Not worth reporting such errors as errors. That said, we might miss some real errors if\n // we ignore blindly, so try to narrow signature we are looking for - skip logging\n // error only if this client should no longer be a summarizer (which in practice\n // means it also lost connection), and error happened on load (we do not have summarizer).\n // We could annotate the error raised in Container.load where the container closed during load with no error\n // and check for that case here, but that does not seem to be necessary.\n if (this.getShouldSummarizeState().shouldSummarize || this.summarizer !== undefined) {\n // Report any failure as an error unless it was due to cancellation (like \"disconnected\" error)\n // If failure happened on container load, we may not yet realized that socket disconnected, so check\n // offlineError.\n const category = error?.errorType === DriverErrorType.offlineError ? \"generic\" : \"error\";\n this.logger.sendTelemetryEvent(\n {\n eventName: \"SummarizerException\",\n category,\n },\n error);\n }\n }).finally(() => {\n assert(this.state !== SummaryManagerState.Off, 0x264 /* \"Expected: Not Off\" */);\n this.state = SummaryManagerState.Off;\n\n this.summarizer?.close();\n this.summarizer = undefined;\n\n if (this.getShouldSummarizeState().shouldSummarize) {\n this.startSummarization();\n }\n });\n }\n\n private stop(reason: SummarizerStopReason) {\n if (!SummaryManager.isStartingOrRunning(this.state)) {\n return;\n }\n this.state = SummaryManagerState.Stopping;\n\n // Stopping the running summarizer client should trigger a change\n // in states when the running summarizer closes\n this.summarizer?.stop(reason);\n }\n\n /**\n * Implements initial delay before creating summarizer\n * @returns true, if creation is delayed due to heuristics (not many ops to summarize).\n * False if summarizer should start immediately due to too many unsummarized ops.\n */\n private async delayBeforeCreatingSummarizer(): Promise<boolean> {\n // throttle creation of new summarizer containers to prevent spamming the server with websocket connections\n let delayMs = this.startThrottler.getDelay();\n\n // We have been elected the summarizer. Some day we may be able to summarize with a live document but for\n // now we play it safe and launch a second copy.\n this.logger.sendTelemetryEvent({\n eventName: \"CreatingSummarizer\",\n throttlerDelay: delayMs,\n initialDelay: this.initialDelayMs,\n startThrottlerMaxDelayMs: this.startThrottler.maxDelayMs,\n opsSinceLastAck: this.summaryCollection.opsSinceLastAck,\n opsToBypassInitialDelay: this.opsToBypassInitialDelay,\n });\n\n // This delay helps ensure that last summarizer that might be left from previous client\n // has enough time to complete its last summary and thus new summarizer not conflict with previous one.\n // If, however, there are too many unsummarized ops, try to resolve it as quickly as possible, with\n // understanding that we may see nacks because of such quick action.\n // A better design would be for summarizer election logic to always select current summarizer as\n // summarizing client (i.e. clientType === \"summarizer\" can be elected) to ensure that nobody else can\n // summarizer while it finishes its work and moves to exit.\n // It also helps with pure boot scenario (single client) to offset expensive work a bit out from\n // critical boot sequence.\n let startWithInitialDelay = false;\n if (this.summaryCollection.opsSinceLastAck < this.opsToBypassInitialDelay) {\n startWithInitialDelay = true;\n delayMs = Math.max(delayMs, this.initialDelayMs);\n }\n\n if (delayMs > 0) {\n let timer;\n let resolveOpPromiseFn;\n // Create a listener that will break the delay if we've exceeded the initial delay ops count.\n const opsListenerFn = () => {\n if (this.summaryCollection.opsSinceLastAck >= this.opsToBypassInitialDelay) {\n clearTimeout(timer);\n resolveOpPromiseFn();\n }\n };\n // Create a Promise that will resolve when the delay expires.\n const delayPromise = new Promise<void>((resolve) => {\n timer = setTimeout(() => resolve(), delayMs);\n });\n // Create a Promise that will resolve if the ops count passes the threshold.\n const opPromise = new Promise<void>((resolve) => { resolveOpPromiseFn = resolve; });\n this.summaryCollection.addOpListener(opsListenerFn);\n await Promise.race([delayPromise, opPromise]);\n this.summaryCollection.removeOpListener(opsListenerFn);\n }\n return startWithInitialDelay;\n }\n\n public readonly summarizeOnDemand: ISummarizer[\"summarizeOnDemand\"] = (...args) => {\n if (this.summarizer === undefined) {\n throw Error(\"No running summarizer client\");\n // TODO: could spawn a summarizer client temporarily.\n }\n return this.summarizer.summarizeOnDemand(...args);\n };\n\n public readonly enqueueSummarize: ISummarizer[\"enqueueSummarize\"] = (...args) => {\n if (this.summarizer === undefined) {\n throw Error(\"No running summarizer client\");\n // TODO: could spawn a summarizer client temporarily.\n }\n return this.summarizer.enqueueSummarize(...args);\n };\n\n public dispose() {\n this.clientElection.off(\"electedSummarizerChanged\", this.refreshSummarizer);\n this.connectedState.off(\"connected\", this.handleConnected);\n this.connectedState.off(\"disconnected\", this.handleDisconnected);\n this._disposed = true;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/container-runtime",
3
- "version": "2.0.0-internal.1.0.0.83139",
3
+ "version": "2.0.0-internal.1.1.1",
4
4
  "description": "Fluid container runtime",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -62,30 +62,30 @@
62
62
  },
63
63
  "dependencies": {
64
64
  "@fluidframework/common-definitions": "^0.20.1",
65
- "@fluidframework/common-utils": "^0.32.1",
66
- "@fluidframework/container-definitions": "2.0.0-internal.1.0.0.83139",
67
- "@fluidframework/container-runtime-definitions": "2.0.0-internal.1.0.0.83139",
68
- "@fluidframework/container-utils": "2.0.0-internal.1.0.0.83139",
69
- "@fluidframework/core-interfaces": "2.0.0-internal.1.0.0.83139",
70
- "@fluidframework/datastore": "2.0.0-internal.1.0.0.83139",
71
- "@fluidframework/driver-definitions": "2.0.0-internal.1.0.0.83139",
72
- "@fluidframework/driver-utils": "2.0.0-internal.1.0.0.83139",
73
- "@fluidframework/garbage-collector": "2.0.0-internal.1.0.0.83139",
74
- "@fluidframework/protocol-base": "^0.1037.1000-0",
75
- "@fluidframework/protocol-definitions": "^0.1029.1000-0",
76
- "@fluidframework/runtime-definitions": "2.0.0-internal.1.0.0.83139",
77
- "@fluidframework/runtime-utils": "2.0.0-internal.1.0.0.83139",
78
- "@fluidframework/telemetry-utils": "2.0.0-internal.1.0.0.83139",
65
+ "@fluidframework/common-utils": "^1.0.0",
66
+ "@fluidframework/container-definitions": "^2.0.0-internal.1.1.1",
67
+ "@fluidframework/container-runtime-definitions": "^2.0.0-internal.1.1.1",
68
+ "@fluidframework/container-utils": "^2.0.0-internal.1.1.1",
69
+ "@fluidframework/core-interfaces": "^2.0.0-internal.1.1.1",
70
+ "@fluidframework/datastore": "^2.0.0-internal.1.1.1",
71
+ "@fluidframework/driver-definitions": "^2.0.0-internal.1.1.1",
72
+ "@fluidframework/driver-utils": "^2.0.0-internal.1.1.1",
73
+ "@fluidframework/garbage-collector": "^2.0.0-internal.1.1.1",
74
+ "@fluidframework/protocol-base": "^0.1037.1000",
75
+ "@fluidframework/protocol-definitions": "^1.0.0",
76
+ "@fluidframework/runtime-definitions": "^2.0.0-internal.1.1.1",
77
+ "@fluidframework/runtime-utils": "^2.0.0-internal.1.1.1",
78
+ "@fluidframework/telemetry-utils": "^2.0.0-internal.1.1.1",
79
79
  "double-ended-queue": "^2.1.0-0",
80
80
  "uuid": "^8.3.1"
81
81
  },
82
82
  "devDependencies": {
83
83
  "@fluidframework/build-common": "^0.24.0",
84
- "@fluidframework/build-tools": "^0.3.0-0",
84
+ "@fluidframework/build-tools": "^0.3.1000",
85
85
  "@fluidframework/container-runtime-previous": "npm:@fluidframework/container-runtime@^1.0.0",
86
86
  "@fluidframework/eslint-config-fluid": "^0.28.2000",
87
- "@fluidframework/mocha-test-setup": "2.0.0-internal.1.0.0.83139",
88
- "@fluidframework/test-runtime-utils": "2.0.0-internal.1.0.0.83139",
87
+ "@fluidframework/mocha-test-setup": "^2.0.0-internal.1.1.1",
88
+ "@fluidframework/test-runtime-utils": "^2.0.0-internal.1.1.1",
89
89
  "@microsoft/api-extractor": "^7.22.2",
90
90
  "@rushstack/eslint-config": "^2.5.1",
91
91
  "@types/double-ended-queue": "^2.1.0",
@@ -94,7 +94,7 @@
94
94
  "@types/sinon": "^7.0.13",
95
95
  "@types/uuid": "^8.3.0",
96
96
  "concurrently": "^6.2.0",
97
- "copyfiles": "^2.1.0",
97
+ "copyfiles": "^2.4.1",
98
98
  "cross-env": "^7.0.2",
99
99
  "eslint": "~8.6.0",
100
100
  "mocha": "^10.0.0",
@@ -130,6 +130,19 @@
130
130
  },
131
131
  "TypeAliasDeclaration_SubmitSummaryResult": {
132
132
  "backCompat": false
133
+ },
134
+ "ClassDeclaration_ContainerRuntime": {
135
+ "backCompat": false
136
+ },
137
+ "InterfaceDeclaration_IConnectableRuntime": {
138
+ "backCompat": false
139
+ },
140
+ "InterfaceDeclaration_ISummarizerRuntime": {
141
+ "backCompat": false
142
+ },
143
+ "RemovedInterfaceDeclaration_IPendingRuntimeState": {
144
+ "forwardCompat": false,
145
+ "backCompat": false
133
146
  }
134
147
  }
135
148
  }
@@ -37,7 +37,7 @@ export class BatchTracker {
37
37
 
38
38
  const length = message.sequenceNumber - this.startBatchSequenceNumber + 1;
39
39
  if (length >= batchLengthThreshold) {
40
- this.logger.sendErrorEvent({
40
+ this.logger.sendPerformanceEvent({
41
41
  eventName: "LengthTooBig",
42
42
  length,
43
43
  threshold: batchLengthThreshold,
@@ -9,7 +9,7 @@ import { IDocumentStorageService } from "@fluidframework/driver-definitions";
9
9
  import { ICreateBlobResponse, ISequencedDocumentMessage, ISnapshotTree } from "@fluidframework/protocol-definitions";
10
10
  import { generateHandleContextPath, SummaryTreeBuilder } from "@fluidframework/runtime-utils";
11
11
  import { ITelemetryLogger } from "@fluidframework/common-definitions";
12
- import { assert, Deferred, TypedEventEmitter } from "@fluidframework/common-utils";
12
+ import { assert, bufferToString, Deferred, stringToBuffer, TypedEventEmitter } from "@fluidframework/common-utils";
13
13
  import { IContainerRuntime, IContainerRuntimeEvents } from "@fluidframework/container-runtime-definitions";
14
14
  import { AttachState } from "@fluidframework/container-definitions";
15
15
  import { ChildLogger, PerformanceEvent } from "@fluidframework/telemetry-utils";
@@ -102,6 +102,8 @@ interface PendingBlob {
102
102
  uploadP: Promise<ICreateBlobResponse>;
103
103
  }
104
104
 
105
+ export interface IPendingBlobs { [id: string]: { blob: string; }; }
106
+
105
107
  export class BlobManager {
106
108
  public static readonly basePath = "_blobs";
107
109
  private static readonly redirectTableBlobName = ".redirectTable";
@@ -154,10 +156,22 @@ export class BlobManager {
154
156
  // of the format `/<BlobManager.basePath>/<blobId>`.
155
157
  private readonly gcNodeUpdated: (blobPath: string) => void,
156
158
  private readonly runtime: IBlobManagerRuntime,
159
+ stashedBlobs: IPendingBlobs = {},
157
160
  ) {
158
161
  this.logger = ChildLogger.create(this.runtime.logger, "BlobManager");
159
162
  this.runtime.on("disconnected", () => this.onDisconnected());
160
163
  this.redirectTable = this.load(snapshot);
164
+
165
+ // Begin uploading stashed blobs from previous container instance
166
+ Object.entries(stashedBlobs).forEach(([localId, entry]) => {
167
+ const blob = stringToBuffer(entry.blob, "base64");
168
+ this.pendingBlobs.set(localId, {
169
+ blob,
170
+ status: PendingBlobStatus.OfflinePendingUpload,
171
+ handleP: new Deferred(),
172
+ uploadP: this.uploadBlob(localId, blob),
173
+ });
174
+ });
161
175
  }
162
176
 
163
177
  private get pendingOfflineUploads() {
@@ -219,7 +233,7 @@ export class BlobManager {
219
233
  // For a detached container, entries are inserted into the redirect table with an undefined storage ID.
220
234
  // For an attached container, entries are inserted w/storage ID after the BlobAttach op round-trips.
221
235
  assert(!undefinedValueInTable || this.runtime.attachState === AttachState.Detached && ids.size === 0,
222
- "'redirectTable' must contain only undefined while detached / defined values while attached");
236
+ 0x382 /* 'redirectTable' must contain only undefined while detached / defined values while attached */);
223
237
 
224
238
  return ids as Set<string>;
225
239
  }
@@ -231,7 +245,7 @@ export class BlobManager {
231
245
  }
232
246
  let storageId;
233
247
  if (this.runtime.attachState === AttachState.Detached) {
234
- assert(this.redirectTable.has(blobId), "requesting unknown blobs");
248
+ assert(this.redirectTable.has(blobId), 0x383 /* requesting unknown blobs */);
235
249
 
236
250
  // Blobs created while the container is detached are stored in IDetachedBlobStorage.
237
251
  // The 'IDocumentStorageService.readBlob()' call below will retrieve these via localId.
@@ -256,7 +270,7 @@ export class BlobManager {
256
270
 
257
271
  private getBlobHandle(id: string): IFluidHandle<ArrayBufferLike> {
258
272
  assert(this.redirectTable.has(id) || this.pendingBlobs.has(id),
259
- "requesting handle for unknown blob");
273
+ 0x384 /* requesting handle for unknown blob */);
260
274
  return new BlobHandle(
261
275
  `${BlobManager.basePath}/${id}`,
262
276
  this.routeContext,
@@ -282,7 +296,7 @@ export class BlobManager {
282
296
  await new Promise<void>((resolve) => this.runtime.once("attached", resolve));
283
297
  }
284
298
  assert(this.runtime.attachState === AttachState.Attached,
285
- "For clarity and paranoid defense against adding future attachment states");
299
+ 0x385 /* For clarity and paranoid defense against adding future attachment states */);
286
300
 
287
301
  // Create a local ID for each blob. This is used to support blobs if/when the client goes
288
302
  // offline since we don't have the ID from storage yet. If online flow succeeds this won't be used.
@@ -314,7 +328,7 @@ export class BlobManager {
314
328
  const entry = this.pendingBlobs.get(localId);
315
329
  assert(entry?.status === PendingBlobStatus.OnlinePendingUpload ||
316
330
  entry?.status === PendingBlobStatus.OfflinePendingUpload,
317
- "Must have pending blob entry for uploaded blob");
331
+ 0x386 /* Must have pending blob entry for uploaded blob */);
318
332
  entry.storageId = response.id;
319
333
  if (this.runtime.connected) {
320
334
  if (entry.status === PendingBlobStatus.OnlinePendingUpload) {
@@ -348,7 +362,7 @@ export class BlobManager {
348
362
 
349
363
  private async onUploadReject(localId: string, error) {
350
364
  const entry = this.pendingBlobs.get(localId);
351
- assert(!!entry, "Must have pending blob entry for blob which failed to upload");
365
+ assert(!!entry, 0x387 /* Must have pending blob entry for blob which failed to upload */);
352
366
  if (!this.runtime.connected) {
353
367
  if (entry.status === PendingBlobStatus.OnlinePendingUpload) {
354
368
  this.transitionToOffline(localId);
@@ -363,11 +377,11 @@ export class BlobManager {
363
377
  }
364
378
 
365
379
  private transitionToOffline(localId: string) {
366
- assert(!this.runtime.connected, "Must only transition to offline flow while runtime is disconnected");
380
+ assert(!this.runtime.connected, 0x388 /* Must only transition to offline flow while runtime is disconnected */);
367
381
  const entry = this.pendingBlobs.get(localId);
368
- assert(!!entry, "No pending blob entry");
382
+ assert(!!entry, 0x389 /* No pending blob entry */);
369
383
  assert([PendingBlobStatus.OnlinePendingUpload, PendingBlobStatus.OnlinePendingOp].includes(entry.status),
370
- "Blob must be in online flow to transition to offline flow");
384
+ 0x38a /* Blob must be in online flow to transition to offline flow */);
371
385
 
372
386
  entry.status = entry.status === PendingBlobStatus.OnlinePendingUpload
373
387
  ? PendingBlobStatus.OfflinePendingUpload
@@ -388,14 +402,14 @@ export class BlobManager {
388
402
  * @param metadata - op metadata containing storage and/or local IDs
389
403
  */
390
404
  public reSubmit(metadata: Record<string, unknown> | undefined) {
391
- assert(!!metadata, "Resubmitted ops must have metadata");
405
+ assert(!!metadata, 0x38b /* Resubmitted ops must have metadata */);
392
406
  const { blobId, localId }: { blobId?: string; localId?: string; } = metadata;
393
407
  if (!blobId) {
394
- assert(!!localId, "Submitted BlobAttach ops must have a blobId or localId");
408
+ assert(!!localId, 0x38c /* Submitted BlobAttach ops must have a blobId or localId */);
395
409
  // We submitted this op while offline. The blob should have been uploaded by now.
396
410
  const pendingEntry = this.pendingBlobs.get(localId);
397
411
  assert(pendingEntry?.status === PendingBlobStatus.OfflinePendingOp &&
398
- !!pendingEntry?.storageId, "blob must be uploaded before resubmitting BlobAttach op");
412
+ !!pendingEntry?.storageId, 0x38d /* blob must be uploaded before resubmitting BlobAttach op */);
399
413
  return this.sendBlobAttachOp(pendingEntry.storageId, localId);
400
414
  }
401
415
  return this.sendBlobAttachOp(blobId, localId);
@@ -413,10 +427,13 @@ export class BlobManager {
413
427
  if (message.metadata.localId === undefined) {
414
428
  // Since there is no local ID, we know this op was submitted while online.
415
429
  const waitingBlobs = this.opsInFlight.get(message.metadata.blobId);
416
- assert(!!waitingBlobs, "local online BlobAttach op with no pending blob");
430
+ assert(!!waitingBlobs, 0x38e /* local online BlobAttach op with no pending blob */);
417
431
  waitingBlobs.forEach((localId) => {
418
432
  const pendingBlobEntry = this.pendingBlobs.get(localId);
419
- assert(pendingBlobEntry !== undefined, "local online BlobAttach op with no pending blob entry");
433
+ assert(
434
+ pendingBlobEntry !== undefined,
435
+ 0x38f, /* local online BlobAttach op with no pending blob entry */
436
+ );
420
437
 
421
438
  // It's possible we transitioned to offline flow while waiting for this op.
422
439
  if (pendingBlobEntry.status === PendingBlobStatus.OnlinePendingOp) {
@@ -497,7 +514,7 @@ export class BlobManager {
497
514
  // Note that because of de-duping, there can be multiple localIds that all redirect to the same storageId or
498
515
  // a blob may be referenced via its storageId handle.
499
516
  for (const [localId, storageId] of this.redirectTable) {
500
- assert(!!storageId, "Must be attached to get GC data");
517
+ assert(!!storageId, 0x390 /* Must be attached to get GC data */);
501
518
  // Add node for the localId and add a route to the storageId node. The storageId node will have been
502
519
  // added above when adding nodes for this.blobIds.
503
520
  gcData.gcNodes[this.getBlobGCNodePath(localId)] = [this.getBlobGCNodePath(storageId)];
@@ -554,7 +571,8 @@ export class BlobManager {
554
571
  public setRedirectTable(table: Map<string, string>) {
555
572
  assert(this.runtime.attachState === AttachState.Detached,
556
573
  0x252 /* "redirect table can only be set in detached container" */);
557
- assert(this.redirectTable.size === table.size, "Redirect table size must match BlobManager's local ID count");
574
+ assert(this.redirectTable.size === table.size,
575
+ 0x391 /* Redirect table size must match BlobManager's local ID count */);
558
576
  for (const [localId, storageId] of table) {
559
577
  assert(this.redirectTable.has(localId), 0x254 /* "unrecognized id in redirect table" */);
560
578
  this.redirectTable.set(localId, storageId);
@@ -562,4 +580,12 @@ export class BlobManager {
562
580
  this.redirectTable.set(storageId, storageId);
563
581
  }
564
582
  }
583
+
584
+ public getPendingBlobs(): IPendingBlobs {
585
+ const blobs = {};
586
+ for (const [key, entry] of this.pendingBlobs) {
587
+ blobs[key] = { blob: bufferToString(entry.blob, "base64") };
588
+ }
589
+ return blobs;
590
+ }
565
591
  }