@fluidframework/container-runtime 2.0.0-internal.2.0.2 → 2.0.0-internal.2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dist/containerRuntime.d.ts +2 -1
  2. package/dist/containerRuntime.d.ts.map +1 -1
  3. package/dist/containerRuntime.js +63 -23
  4. package/dist/containerRuntime.js.map +1 -1
  5. package/dist/dataStore.d.ts.map +1 -1
  6. package/dist/dataStore.js +6 -0
  7. package/dist/dataStore.js.map +1 -1
  8. package/dist/dataStoreContext.d.ts +7 -0
  9. package/dist/dataStoreContext.d.ts.map +1 -1
  10. package/dist/dataStoreContext.js +34 -8
  11. package/dist/dataStoreContext.js.map +1 -1
  12. package/dist/dataStoreContexts.js +1 -1
  13. package/dist/dataStoreContexts.js.map +1 -1
  14. package/dist/dataStores.d.ts +3 -2
  15. package/dist/dataStores.d.ts.map +1 -1
  16. package/dist/dataStores.js +29 -3
  17. package/dist/dataStores.js.map +1 -1
  18. package/dist/garbageCollection.d.ts +19 -5
  19. package/dist/garbageCollection.d.ts.map +1 -1
  20. package/dist/garbageCollection.js +120 -37
  21. package/dist/garbageCollection.js.map +1 -1
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +2 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/packageVersion.d.ts +1 -1
  27. package/dist/packageVersion.js +1 -1
  28. package/dist/packageVersion.js.map +1 -1
  29. package/dist/summarizerClientElection.js +1 -1
  30. package/dist/summarizerClientElection.js.map +1 -1
  31. package/dist/summaryGenerator.d.ts.map +1 -1
  32. package/dist/summaryGenerator.js +3 -2
  33. package/dist/summaryGenerator.js.map +1 -1
  34. package/garbageCollection.md +27 -22
  35. package/lib/containerRuntime.d.ts +2 -1
  36. package/lib/containerRuntime.d.ts.map +1 -1
  37. package/lib/containerRuntime.js +64 -24
  38. package/lib/containerRuntime.js.map +1 -1
  39. package/lib/dataStore.d.ts.map +1 -1
  40. package/lib/dataStore.js +6 -0
  41. package/lib/dataStore.js.map +1 -1
  42. package/lib/dataStoreContext.d.ts +7 -0
  43. package/lib/dataStoreContext.d.ts.map +1 -1
  44. package/lib/dataStoreContext.js +35 -9
  45. package/lib/dataStoreContext.js.map +1 -1
  46. package/lib/dataStoreContexts.js +1 -1
  47. package/lib/dataStoreContexts.js.map +1 -1
  48. package/lib/dataStores.d.ts +3 -2
  49. package/lib/dataStores.d.ts.map +1 -1
  50. package/lib/dataStores.js +30 -4
  51. package/lib/dataStores.js.map +1 -1
  52. package/lib/garbageCollection.d.ts +19 -5
  53. package/lib/garbageCollection.d.ts.map +1 -1
  54. package/lib/garbageCollection.js +119 -36
  55. package/lib/garbageCollection.js.map +1 -1
  56. package/lib/index.d.ts +1 -1
  57. package/lib/index.d.ts.map +1 -1
  58. package/lib/index.js +1 -1
  59. package/lib/index.js.map +1 -1
  60. package/lib/packageVersion.d.ts +1 -1
  61. package/lib/packageVersion.js +1 -1
  62. package/lib/packageVersion.js.map +1 -1
  63. package/lib/summarizerClientElection.js +1 -1
  64. package/lib/summarizerClientElection.js.map +1 -1
  65. package/lib/summaryGenerator.d.ts.map +1 -1
  66. package/lib/summaryGenerator.js +3 -2
  67. package/lib/summaryGenerator.js.map +1 -1
  68. package/package.json +26 -23
  69. package/src/containerRuntime.ts +77 -26
  70. package/src/dataStore.ts +13 -1
  71. package/src/dataStoreContext.ts +48 -10
  72. package/src/dataStoreContexts.ts +1 -1
  73. package/src/dataStores.ts +34 -3
  74. package/src/garbageCollection.ts +144 -44
  75. package/src/index.ts +1 -1
  76. package/src/packageVersion.ts +1 -1
  77. package/src/summarizerClientElection.ts +1 -1
  78. package/src/summaryGenerator.ts +3 -2
@@ -1 +1 @@
1
- {"version":3,"file":"summarizerClientElection.js","sourceRoot":"","sources":["../src/summarizerClientElection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,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CAAC,2BAA2B,CAAC,OAAO,CAAC,CAAC;IACzE,CAAC;;AAEsB,oDAA2B,GAAG,CAAC,OAAuB,EAAW,EAAE,CACtF,OAAO,CAAC,YAAY,CAAC,WAAW,IAAI,OAAO,CAAC,IAAI,KAAK,oBAAoB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IEvent, IEventProvider, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport { IClientDetails, MessageType } from \"@fluidframework/protocol-definitions\";\nimport { IOrderedClientElection, ISerializedElection, ITrackedClient } from \"./orderedClientElection\";\nimport { ISummaryCollectionOpEvents } from \"./summaryCollection\";\n\nexport const summarizerClientType = \"summarizer\";\n\nexport interface ISummarizerClientElectionEvents extends IEvent {\n (event: \"electedSummarizerChanged\", handler: () => void): void;\n}\n\nexport interface ISummarizerClientElection extends IEventProvider<ISummarizerClientElectionEvents> {\n readonly electedClientId: string | undefined;\n readonly electedParentId: string | undefined;\n}\n\n/**\n * This class encapsulates logic around tracking the elected summarizer client.\n * It will handle updating the elected client when a summary ack hasn't been seen\n * for some configured number of ops.\n */\nexport class SummarizerClientElection\n extends TypedEventEmitter<ISummarizerClientElectionEvents>\n implements ISummarizerClientElection {\n /**\n * Used to calculate number of ops since last summary ack for the current elected client.\n * This will be undefined if there is no elected summarizer, or no summary ack has been\n * observed since this client was elected.\n * When a summary ack comes in, this will be set to the sequence number of the summary ack.\n */\n private lastSummaryAckSeqForClient: number | undefined;\n /**\n * Used to prevent excess logging by recording the sequence number that we last reported at,\n * and making sure we don't report another event to telemetry. If things work as intended,\n * this is not needed, otherwise it could report an event on every op in worst case scenario.\n */\n private lastReportedSeq = 0;\n\n public get electedClientId() {\n return this.clientElection.electedClient?.clientId;\n }\n public get electedParentId() {\n return this.clientElection.electedParent?.clientId;\n }\n\n constructor(\n private readonly logger: ITelemetryLogger,\n private readonly summaryCollection: IEventProvider<ISummaryCollectionOpEvents>,\n public readonly clientElection: IOrderedClientElection,\n private readonly maxOpsSinceLastSummary: number,\n private readonly electionEnabled: boolean,\n ) {\n super();\n // On every inbound op, if enough ops pass without seeing a summary ack (per elected client),\n // elect a new client and log to telemetry.\n this.summaryCollection.on(\"default\", ({ sequenceNumber }) => {\n const electedClientId = this.electedClientId;\n if (electedClientId === undefined) {\n // Reset election if no elected client, but eligible clients are connected.\n // This should be uncommon, but is possible if the initial state of the\n // ordered client election contains an undefined client id or one not found\n // in the quorum (the latter would already log an error).\n if (this.clientElection.eligibleCount > 0) {\n this.clientElection.resetElectedClient(sequenceNumber);\n }\n return;\n }\n let electionSequenceNumber = this.clientElection.electionSequenceNumber;\n const opsWithoutSummary = sequenceNumber - (this.lastSummaryAckSeqForClient ?? electionSequenceNumber);\n if (opsWithoutSummary > this.maxOpsSinceLastSummary) {\n // Log and elect a new summarizer client.\n const opsSinceLastReport = sequenceNumber - this.lastReportedSeq;\n if (opsSinceLastReport > this.maxOpsSinceLastSummary) {\n this.logger.sendErrorEvent({\n eventName: \"ElectedClientNotSummarizing\",\n electedClientId,\n lastSummaryAckSeqForClient: this.lastSummaryAckSeqForClient,\n electionSequenceNumber,\n nextElectedClientId: this.clientElection.peekNextElectedClient()?.clientId,\n electionEnabled: this.electionEnabled,\n });\n this.lastReportedSeq = sequenceNumber;\n }\n\n if (this.electionEnabled) {\n const previousParentId = this.electedParentId;\n this.clientElection.incrementElectedClient(sequenceNumber);\n\n // Verify that state incremented as expected. This should be reliable,\n // since all of OrderedClientElection is synchronous.\n electionSequenceNumber = this.clientElection.electionSequenceNumber;\n if (sequenceNumber > (this.lastSummaryAckSeqForClient ?? electionSequenceNumber)) {\n if (opsSinceLastReport > this.maxOpsSinceLastSummary) {\n this.logger.sendErrorEvent({\n eventName: \"UnexpectedElectionSequenceNumber\",\n // Expected to be undefined\n lastSummaryAckSeqForClient: this.lastSummaryAckSeqForClient,\n // Expected to be same as op sequenceNumber\n electionSequenceNumber,\n sequenceNumber,\n previousClientId: electedClientId,\n previousParentId,\n electedParentId: this.electedParentId,\n electedClientId: this.electedClientId,\n opsSinceLastReport,\n maxOpsSinceLastSummary,\n });\n }\n }\n }\n }\n });\n\n // When a summary ack comes in, reset our op seq counter.\n this.summaryCollection.on(MessageType.SummaryAck, (op) => {\n this.lastSummaryAckSeqForClient = op.sequenceNumber;\n });\n\n // Use oldest client election for unanimously and deterministically deciding\n // which client should summarize.\n this.clientElection.on(\"election\", (client, sequenceNumber) => {\n this.lastSummaryAckSeqForClient = undefined;\n if (client === undefined && this.clientElection.eligibleCount > 0) {\n // If no client is valid for election, reset to the oldest again.\n // Also make extra sure not to get stuck in an infinite loop here:\n // If there are no eligible clients, just wait until a client joins\n // and will be auto-elected.\n this.clientElection.resetElectedClient(sequenceNumber);\n }\n // Election can trigger a change in SummaryManager state.\n this.emit(\"electedSummarizerChanged\");\n });\n }\n\n public serialize(): ISerializedElection {\n const { electedClientId, electedParentId, electionSequenceNumber } = this.clientElection.serialize();\n return {\n electedClientId,\n electedParentId,\n electionSequenceNumber: this.lastSummaryAckSeqForClient ?? electionSequenceNumber,\n };\n }\n\n public static isClientEligible(client: ITrackedClient): boolean {\n const details = client.client.details;\n if (details === undefined) {\n // Very old clients back-compat\n return true;\n }\n return SummarizerClientElection.clientDetailsPermitElection(details);\n }\n\n public static readonly clientDetailsPermitElection = (details: IClientDetails): boolean =>\n details.capabilities.interactive || details.type === summarizerClientType;\n}\n"]}
1
+ {"version":3,"file":"summarizerClientElection.js","sourceRoot":"","sources":["../src/summarizerClientElection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAkB,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAInF,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAC;AAWjD;;;;GAIG;AACH,MAAM,OAAO,wBACT,SAAQ,iBAAkD;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AoB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IEvent, IEventProvider, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport { IClientDetails, MessageType } from \"@fluidframework/protocol-definitions\";\nimport { IOrderedClientElection, ISerializedElection, ITrackedClient } from \"./orderedClientElection\";\nimport { ISummaryCollectionOpEvents } from \"./summaryCollection\";\n\nexport const summarizerClientType = \"summarizer\";\n\nexport interface ISummarizerClientElectionEvents extends IEvent {\n (event: \"electedSummarizerChanged\", handler: () => void): void;\n}\n\nexport interface ISummarizerClientElection extends IEventProvider<ISummarizerClientElectionEvents> {\n readonly electedClientId: string | undefined;\n readonly electedParentId: string | undefined;\n}\n\n/**\n * This class encapsulates logic around tracking the elected summarizer client.\n * It will handle updating the elected client when a summary ack hasn't been seen\n * for some configured number of ops.\n */\nexport class SummarizerClientElection\n extends TypedEventEmitter<ISummarizerClientElectionEvents>\n implements ISummarizerClientElection {\n /**\n * Used to calculate number of ops since last summary ack for the current elected client.\n * This will be undefined if there is no elected summarizer, or no summary ack has been\n * observed since this client was elected.\n * When a summary ack comes in, this will be set to the sequence number of the summary ack.\n */\n private lastSummaryAckSeqForClient: number | undefined;\n /**\n * Used to prevent excess logging by recording the sequence number that we last reported at,\n * and making sure we don't report another event to telemetry. If things work as intended,\n * this is not needed, otherwise it could report an event on every op in worst case scenario.\n */\n private lastReportedSeq = 0;\n\n public get electedClientId() {\n return this.clientElection.electedClient?.clientId;\n }\n public get electedParentId() {\n return this.clientElection.electedParent?.clientId;\n }\n\n constructor(\n private readonly logger: ITelemetryLogger,\n private readonly summaryCollection: IEventProvider<ISummaryCollectionOpEvents>,\n public readonly clientElection: IOrderedClientElection,\n private readonly maxOpsSinceLastSummary: number,\n private readonly electionEnabled: boolean,\n ) {\n super();\n // On every inbound op, if enough ops pass without seeing a summary ack (per elected client),\n // elect a new client and log to telemetry.\n this.summaryCollection.on(\"default\", ({ sequenceNumber }) => {\n const electedClientId = this.electedClientId;\n if (electedClientId === undefined) {\n // Reset election if no elected client, but eligible clients are connected.\n // This should be uncommon, but is possible if the initial state of the\n // ordered client election contains an undefined client id or one not found\n // in the quorum (the latter would already log an error).\n if (this.clientElection.eligibleCount > 0) {\n this.clientElection.resetElectedClient(sequenceNumber);\n }\n return;\n }\n let electionSequenceNumber = this.clientElection.electionSequenceNumber;\n const opsWithoutSummary = sequenceNumber - (this.lastSummaryAckSeqForClient ?? electionSequenceNumber);\n if (opsWithoutSummary > this.maxOpsSinceLastSummary) {\n // Log and elect a new summarizer client.\n const opsSinceLastReport = sequenceNumber - this.lastReportedSeq;\n if (opsSinceLastReport > this.maxOpsSinceLastSummary) {\n this.logger.sendTelemetryEvent({\n eventName: \"ElectedClientNotSummarizing\",\n electedClientId,\n lastSummaryAckSeqForClient: this.lastSummaryAckSeqForClient,\n electionSequenceNumber,\n nextElectedClientId: this.clientElection.peekNextElectedClient()?.clientId,\n electionEnabled: this.electionEnabled,\n });\n this.lastReportedSeq = sequenceNumber;\n }\n\n if (this.electionEnabled) {\n const previousParentId = this.electedParentId;\n this.clientElection.incrementElectedClient(sequenceNumber);\n\n // Verify that state incremented as expected. This should be reliable,\n // since all of OrderedClientElection is synchronous.\n electionSequenceNumber = this.clientElection.electionSequenceNumber;\n if (sequenceNumber > (this.lastSummaryAckSeqForClient ?? electionSequenceNumber)) {\n if (opsSinceLastReport > this.maxOpsSinceLastSummary) {\n this.logger.sendErrorEvent({\n eventName: \"UnexpectedElectionSequenceNumber\",\n // Expected to be undefined\n lastSummaryAckSeqForClient: this.lastSummaryAckSeqForClient,\n // Expected to be same as op sequenceNumber\n electionSequenceNumber,\n sequenceNumber,\n previousClientId: electedClientId,\n previousParentId,\n electedParentId: this.electedParentId,\n electedClientId: this.electedClientId,\n opsSinceLastReport,\n maxOpsSinceLastSummary,\n });\n }\n }\n }\n }\n });\n\n // When a summary ack comes in, reset our op seq counter.\n this.summaryCollection.on(MessageType.SummaryAck, (op) => {\n this.lastSummaryAckSeqForClient = op.sequenceNumber;\n });\n\n // Use oldest client election for unanimously and deterministically deciding\n // which client should summarize.\n this.clientElection.on(\"election\", (client, sequenceNumber) => {\n this.lastSummaryAckSeqForClient = undefined;\n if (client === undefined && this.clientElection.eligibleCount > 0) {\n // If no client is valid for election, reset to the oldest again.\n // Also make extra sure not to get stuck in an infinite loop here:\n // If there are no eligible clients, just wait until a client joins\n // and will be auto-elected.\n this.clientElection.resetElectedClient(sequenceNumber);\n }\n // Election can trigger a change in SummaryManager state.\n this.emit(\"electedSummarizerChanged\");\n });\n }\n\n public serialize(): ISerializedElection {\n const { electedClientId, electedParentId, electionSequenceNumber } = this.clientElection.serialize();\n return {\n electedClientId,\n electedParentId,\n electionSequenceNumber: this.lastSummaryAckSeqForClient ?? electionSequenceNumber,\n };\n }\n\n public static isClientEligible(client: ITrackedClient): boolean {\n const details = client.client.details;\n if (details === undefined) {\n // Very old clients back-compat\n return true;\n }\n return SummarizerClientElection.clientDetailsPermitElection(details);\n }\n\n public static readonly clientDetailsPermitElection = (details: IClientDetails): boolean =>\n details.capabilities.interactive || details.type === summarizerClientType;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"summaryGenerator.d.ts","sourceRoot":"","sources":["../src/summaryGenerator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAEH,QAAQ,EACR,aAAa,EACb,mBAAmB,EAEtB,MAAM,8BAA8B,CAAC;AAKtC,OAAO,EACH,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,yBAAyB,EACzB,6BAA6B,EAEhC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,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OAAO,EAAE,qBAAqB,KAAK,OAAO,CAAC,mBAAmB,CAAC,EACvF,qBAAqB,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,EACrD,yBAAyB,EAAE,MAAM,IAAI,EACrC,cAAc,EAAE,IAAI,CAAC,qBAAqB,EAAE,cAAc,CAAC,EAC3D,MAAM,EAAE,gBAAgB;IAQ7C;;;;;;OAMG;IACI,SAAS,CACZ,cAAc,EAAE,6BAA6B,EAC7C,OAAO,EAAE,iBAAiB,EAC1B,iBAAiB,EAAE,yBAAyB,EAC5C,cAAc,yBAA+B,GAC9C,iBAAiB;YAWN,aAAa;IA0M3B,OAAO,CAAC,8BAA8B;IAuCtC,OAAO,CAAC,qBAAqB;IAatB,OAAO;CAGjB"}
@@ -122,9 +122,10 @@ export class SummaryGenerator {
122
122
  // offlineError too.
123
123
  const category = cancellationToken.cancelled || (error === null || error === void 0 ? void 0 : error.errorType) === DriverErrorType.offlineError ?
124
124
  "generic" : "error";
125
+ const message = getFailMessage(errorCode);
125
126
  summarizeEvent.cancel(Object.assign(Object.assign({}, properties), { reason: errorCode, category,
126
- retryAfterSeconds }), error);
127
- resultsBuilder.fail(getFailMessage(errorCode), error, nackSummaryResult, retryAfterSeconds);
127
+ retryAfterSeconds }), error !== null && error !== void 0 ? error : message); // disconnect & summaryAckTimeout do not have proper error.
128
+ resultsBuilder.fail(message, error, nackSummaryResult, retryAfterSeconds);
128
129
  };
129
130
  // Wait to generate and send summary
130
131
  this.summarizeTimer.start();
@@ -1 +1 @@
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,CAA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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,KAAK,CAAC,8BAA8B,CAAC,CAAC;SAC/D;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, 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
+ {"version":3,"file":"summaryGenerator.js","sourceRoot":"","sources":["../src/summaryGenerator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACH,MAAM,E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.\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 const message = getFailMessage(errorCode);\n summarizeEvent.cancel({\n ...properties,\n reason: errorCode,\n category,\n retryAfterSeconds,\n }, error ?? message); // disconnect & summaryAckTimeout do not have proper error.\n resultsBuilder.fail(message, 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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/container-runtime",
3
- "version": "2.0.0-internal.2.0.2",
3
+ "version": "2.0.0-internal.2.1.0",
4
4
  "description": "Fluid container runtime",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -36,8 +36,6 @@
36
36
  "test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
37
37
  "tsc": "tsc",
38
38
  "tsc:watch": "tsc --watch",
39
- "tsfmt": "tsfmt --verify",
40
- "tsfmt:fix": "tsfmt --replace",
41
39
  "typetests:gen": "fluid-type-validator -g -d ."
42
40
  },
43
41
  "nyc": {
@@ -63,30 +61,31 @@
63
61
  "dependencies": {
64
62
  "@fluidframework/common-definitions": "^0.20.1",
65
63
  "@fluidframework/common-utils": "^1.0.0",
66
- "@fluidframework/container-definitions": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
67
- "@fluidframework/container-runtime-definitions": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
68
- "@fluidframework/container-utils": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
69
- "@fluidframework/core-interfaces": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
70
- "@fluidframework/datastore": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
71
- "@fluidframework/driver-definitions": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
72
- "@fluidframework/driver-utils": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
73
- "@fluidframework/garbage-collector": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
64
+ "@fluidframework/container-definitions": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
65
+ "@fluidframework/container-runtime-definitions": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
66
+ "@fluidframework/container-utils": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
67
+ "@fluidframework/core-interfaces": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
68
+ "@fluidframework/datastore": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
69
+ "@fluidframework/driver-definitions": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
70
+ "@fluidframework/driver-utils": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
71
+ "@fluidframework/garbage-collector": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
74
72
  "@fluidframework/protocol-base": "^0.1038.2000",
75
73
  "@fluidframework/protocol-definitions": "^1.1.0",
76
- "@fluidframework/runtime-definitions": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
77
- "@fluidframework/runtime-utils": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
78
- "@fluidframework/telemetry-utils": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
74
+ "@fluidframework/runtime-definitions": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
75
+ "@fluidframework/runtime-utils": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
76
+ "@fluidframework/telemetry-utils": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
79
77
  "double-ended-queue": "^2.1.0-0",
80
78
  "lz4js": "^0.2.0",
81
79
  "uuid": "^8.3.1"
82
80
  },
83
81
  "devDependencies": {
84
- "@fluidframework/build-common": "^1.0.0",
85
- "@fluidframework/build-tools": "^0.4.6000",
82
+ "@fluid-tools/build-cli": "^0.5.0",
83
+ "@fluidframework/build-common": "^1.1.0",
84
+ "@fluidframework/build-tools": "^0.5.0",
86
85
  "@fluidframework/container-runtime-previous": "npm:@fluidframework/container-runtime@2.0.0-internal.2.0.0",
87
- "@fluidframework/eslint-config-fluid": "^1.0.0",
88
- "@fluidframework/mocha-test-setup": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
89
- "@fluidframework/test-runtime-utils": ">=2.0.0-internal.2.0.2 <2.0.0-internal.3.0.0",
86
+ "@fluidframework/eslint-config-fluid": "^1.1.0",
87
+ "@fluidframework/mocha-test-setup": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
88
+ "@fluidframework/test-runtime-utils": ">=2.0.0-internal.2.1.0 <2.0.0-internal.3.0.0",
90
89
  "@microsoft/api-extractor": "^7.22.2",
91
90
  "@rushstack/eslint-config": "^2.5.1",
92
91
  "@types/double-ended-queue": "^2.1.0",
@@ -102,11 +101,15 @@
102
101
  "nyc": "^15.0.0",
103
102
  "rimraf": "^2.6.2",
104
103
  "sinon": "^7.4.2",
105
- "typescript": "~4.5.5",
106
- "typescript-formatter": "7.1.0"
104
+ "typescript": "~4.5.5"
107
105
  },
108
106
  "typeValidation": {
109
- "version": "2.0.0-internal.2.0.1",
110
- "broken": {}
107
+ "version": "2.0.0-internal.2.1.0",
108
+ "broken": {
109
+ "RemovedInterfaceDeclaration_IGarbageCollectionRuntime": {
110
+ "forwardCompat": false,
111
+ "backCompat": false
112
+ }
113
+ }
111
114
  }
112
115
  }
@@ -160,6 +160,7 @@ import {
160
160
  IGarbageCollectionRuntime,
161
161
  IGarbageCollector,
162
162
  IGCStats,
163
+ testTombstoneKey,
163
164
  } from "./garbageCollection";
164
165
  import {
165
166
  channelToDataStore,
@@ -1411,10 +1412,13 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
1411
1412
  const wait = typeof request.headers?.[RuntimeHeaders.wait] === "boolean"
1412
1413
  ? request.headers?.[RuntimeHeaders.wait]
1413
1414
  : true;
1415
+ const viaHandle = typeof request.headers?.[RuntimeHeaders.viaHandle] === "boolean"
1416
+ ? request.headers?.[RuntimeHeaders.viaHandle]
1417
+ : false;
1414
1418
 
1415
1419
  await this.dataStores.waitIfPendingAlias(id);
1416
1420
  const internalId = this.internalId(id);
1417
- const dataStoreContext = await this.dataStores.getDataStore(internalId, wait);
1421
+ const dataStoreContext = await this.dataStores.getDataStore(internalId, wait, viaHandle);
1418
1422
 
1419
1423
  /**
1420
1424
  * If GC should run and this an external app request with "externalRequest" header, we need to return
@@ -1817,7 +1821,7 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
1817
1821
  private async getRootDataStoreChannel(id: string, wait = true): Promise<IFluidDataStoreChannel> {
1818
1822
  await this.dataStores.waitIfPendingAlias(id);
1819
1823
  const internalId = this.internalId(id);
1820
- const context = await this.dataStores.getDataStore(internalId, wait);
1824
+ const context = await this.dataStores.getDataStore(internalId, wait, false /* viaHandle */);
1821
1825
  assert(await context.isRoot(), 0x12b /* "did not get root data store" */);
1822
1826
  return context.realize();
1823
1827
  }
@@ -2264,9 +2268,22 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
2264
2268
  /**
2265
2269
  * When running GC in test mode, this is called to delete objects whose routes are unused. This enables testing
2266
2270
  * scenarios with accessing deleted content.
2267
- * @param unusedRoutes - The routes that are unused in all data stores in this Container.
2271
+ * @param unusedRoutes - The routes that are unused in all data stores and blobs in this Container.
2268
2272
  */
2269
2273
  public deleteUnusedRoutes(unusedRoutes: string[]) {
2274
+ /**
2275
+ * When running GC in tombstone mode, this is called to tombstone datastore routes that are unused. This
2276
+ * enables testing scenarios without actually deleting content. The content acts as if it's deleted to the
2277
+ * external user, but the internal runtime does not delete it in summarizes, etc.
2278
+ */
2279
+ const tombstone = this.mc.config.getBoolean(testTombstoneKey) ?? false;
2280
+ // TODO: add blobs
2281
+ if (tombstone) {
2282
+ // If blob routes are passed in here, tombstone will fail and hit an assert
2283
+ this.dataStores.deleteUnusedRoutes(unusedRoutes, tombstone);
2284
+ return;
2285
+ }
2286
+
2270
2287
  const blobManagerUnusedRoutes: string[] = [];
2271
2288
  const dataStoreUnusedRoutes: string[] = [];
2272
2289
  for (const route of unusedRoutes) {
@@ -2385,20 +2402,9 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
2385
2402
  const latestSnapshotRefSeq = latestSnapshotInfo.latestSnapshotRefSeq;
2386
2403
  latestSnapshotVersionId = latestSnapshotInfo.latestSnapshotVersionId;
2387
2404
 
2388
- if (latestSnapshotRefSeq > this.deltaManager.lastSequenceNumber) {
2389
- // We need to catch up to the latest summary's reference sequence number before pausing.
2390
- await PerformanceEvent.timedExecAsync(
2391
- summaryNumberLogger,
2392
- {
2393
- eventName: "WaitingForSeq",
2394
- lastSequenceNumber: this.deltaManager.lastSequenceNumber,
2395
- targetSequenceNumber: latestSnapshotRefSeq,
2396
- lastKnownSeqNumber: this.deltaManager.lastKnownSeqNumber,
2397
- },
2398
- async () => waitForSeq(this.deltaManager, latestSnapshotRefSeq),
2399
- { start: true, end: true, cancel: "error" }, // definitely want start event
2400
- );
2401
- }
2405
+ // We might need to catch up to the latest summary's reference sequence number before pausing.
2406
+ await this.waitForDeltaManagerToCatchup(latestSnapshotRefSeq,
2407
+ summaryNumberLogger);
2402
2408
  }
2403
2409
 
2404
2410
  try {
@@ -2858,24 +2864,61 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
2858
2864
  }
2859
2865
  }
2860
2866
 
2867
+ private async waitForDeltaManagerToCatchup(
2868
+ latestSnapshotRefSeq: number,
2869
+ summaryLogger: ITelemetryLogger,
2870
+ ): Promise<void> {
2871
+ if (latestSnapshotRefSeq > this.deltaManager.lastSequenceNumber) {
2872
+ // We need to catch up to the latest summary's reference sequence number before proceeding.
2873
+ await PerformanceEvent.timedExecAsync(
2874
+ summaryLogger,
2875
+ {
2876
+ eventName: "WaitingForSeq",
2877
+ lastSequenceNumber: this.deltaManager.lastSequenceNumber,
2878
+ targetSequenceNumber: latestSnapshotRefSeq,
2879
+ lastKnownSeqNumber: this.deltaManager.lastKnownSeqNumber,
2880
+ },
2881
+ async () => waitForSeq(this.deltaManager, latestSnapshotRefSeq),
2882
+ { start: true, end: true, cancel: "error" }, // definitely want start event
2883
+ );
2884
+ }
2885
+ }
2886
+
2861
2887
  /** Implementation of ISummarizerInternalsProvider.refreshLatestSummaryAck */
2862
2888
  public async refreshLatestSummaryAck(options: IRefreshSummaryAckOptions) {
2863
2889
  const { proposalHandle, ackHandle, summaryRefSeq, summaryLogger } = options;
2864
2890
  const readAndParseBlob = async <T>(id: string) => readAndParse<T>(this.storage, id);
2865
2891
  // The call to fetch the snapshot is very expensive and not always needed.
2866
2892
  // It should only be done by the summarizerNode, if required.
2893
+ // When fetching from storage we will always get the latest version and do not use the ackHandle.
2867
2894
  const snapshotTreeFetcher = async () => {
2868
2895
  const fetchResult = await this.fetchSnapshotFromStorage(
2869
- ackHandle,
2896
+ null,
2870
2897
  summaryLogger,
2871
2898
  {
2872
2899
  eventName: "RefreshLatestSummaryGetSnapshot",
2873
2900
  ackHandle,
2874
2901
  summaryRefSeq,
2875
- fetchLatest: false,
2902
+ fetchLatest: true,
2876
2903
  });
2904
+
2905
+ const latestSnapshotRefSeq = await seqFromTree(fetchResult.snapshotTree, readAndParseBlob);
2906
+ summaryLogger.sendTelemetryEvent(
2907
+ {
2908
+ eventName: "LatestSummaryRetrieved",
2909
+ ackHandle,
2910
+ lastSequenceNumber: latestSnapshotRefSeq,
2911
+ targetSequenceNumber: summaryRefSeq,
2912
+ });
2913
+
2914
+ // In case we had to retrieve the latest snapshot and it is different than summaryRefSeq,
2915
+ // wait for the delta manager to catch up before refreshing the latest Summary.
2916
+ await this.waitForDeltaManagerToCatchup(latestSnapshotRefSeq,
2917
+ summaryLogger);
2918
+
2877
2919
  return fetchResult.snapshotTree;
2878
2920
  };
2921
+
2879
2922
  const result = await this.summarizerNode.refreshLatestSummary(
2880
2923
  proposalHandle,
2881
2924
  summaryRefSeq,
@@ -3085,6 +3128,9 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
3085
3128
  throw new UsageError(`Summary heuristic configuration property "${prop}" cannot be less than 0`);
3086
3129
  }
3087
3130
  }
3131
+ if (configuration.minIdleTime > configuration.maxIdleTime) {
3132
+ throw new UsageError(`"minIdleTime" [${configuration.minIdleTime}] cannot be greater than "maxIdleTime" [${configuration.maxIdleTime}]`);
3133
+ }
3088
3134
  }
3089
3135
  }
3090
3136
 
@@ -3099,11 +3145,16 @@ const waitForSeq = async (
3099
3145
  // TODO: remove cast to any when actual event is determined
3100
3146
  deltaManager.on("closed" as any, reject);
3101
3147
 
3102
- const handleOp = (message: Pick<ISequencedDocumentMessage, "sequenceNumber">) => {
3103
- if (message.sequenceNumber >= targetSeq) {
3104
- resolve();
3105
- deltaManager.off("op", handleOp);
3106
- }
3107
- };
3108
- deltaManager.on("op", handleOp);
3148
+ // If we already reached target sequence number, simply resolve the promise.
3149
+ if (deltaManager.lastSequenceNumber >= targetSeq) {
3150
+ resolve();
3151
+ } else {
3152
+ const handleOp = (message: Pick<ISequencedDocumentMessage, "sequenceNumber">) => {
3153
+ if (message.sequenceNumber >= targetSeq) {
3154
+ resolve();
3155
+ deltaManager.off("op", handleOp);
3156
+ }
3157
+ };
3158
+ deltaManager.on("op", handleOp);
3159
+ }
3109
3160
  });
package/src/dataStore.ts CHANGED
@@ -7,7 +7,12 @@ import { ITelemetryLogger } from "@fluidframework/common-definitions";
7
7
  import { assert, unreachableCase } from "@fluidframework/common-utils";
8
8
  import { AttachState } from "@fluidframework/container-definitions";
9
9
  import { UsageError } from "@fluidframework/container-utils";
10
- import { IRequest, IResponse } from "@fluidframework/core-interfaces";
10
+ import {
11
+ FluidObject,
12
+ IFluidHandle,
13
+ IRequest,
14
+ IResponse,
15
+ } from "@fluidframework/core-interfaces";
11
16
  import { AliasResult, IDataStore, IFluidDataStoreChannel } from "@fluidframework/runtime-definitions";
12
17
  import { TelemetryDataTag } from "@fluidframework/telemetry-utils";
13
18
  import { ContainerRuntime } from "./containerRuntime";
@@ -151,6 +156,13 @@ class DataStore implements IDataStore {
151
156
  return this.fluidDataStoreChannel.request(request);
152
157
  }
153
158
 
159
+ /**
160
+ * {@inheritDoc @fluidframework/runtime-definitions#IDataStore.entryPoint}
161
+ */
162
+ get entryPoint(): IFluidHandle<FluidObject> | undefined {
163
+ return this.fluidDataStoreChannel.entryPoint;
164
+ }
165
+
154
166
  constructor(
155
167
  private readonly fluidDataStoreChannel: IFluidDataStoreChannel,
156
168
  private readonly internalId: string,