@fluidframework/routerlicious-driver 2.3.0-288113 → 2.4.0-294316
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/createNewUtils.d.ts.map +1 -1
- package/dist/createNewUtils.js +3 -1
- package/dist/createNewUtils.js.map +1 -1
- package/dist/deltaStorageService.js +1 -1
- package/dist/deltaStorageService.js.map +1 -1
- package/dist/documentService.d.ts +6 -11
- package/dist/documentService.d.ts.map +1 -1
- package/dist/documentService.js +16 -61
- package/dist/documentService.js.map +1 -1
- package/dist/documentServiceFactory.d.ts +1 -0
- package/dist/documentServiceFactory.d.ts.map +1 -1
- package/dist/documentServiceFactory.js +33 -42
- package/dist/documentServiceFactory.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/r11sSnapshotParser.d.ts.map +1 -1
- package/dist/r11sSnapshotParser.js +2 -4
- package/dist/r11sSnapshotParser.js.map +1 -1
- package/dist/sessionInfoManager.d.ts +55 -0
- package/dist/sessionInfoManager.d.ts.map +1 -0
- package/dist/sessionInfoManager.js +100 -0
- package/dist/sessionInfoManager.js.map +1 -0
- package/dist/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
- package/dist/shreddedSummaryDocumentStorageService.js +3 -4
- package/dist/shreddedSummaryDocumentStorageService.js.map +1 -1
- package/dist/summaryTreeUploadManager.d.ts.map +1 -1
- package/dist/summaryTreeUploadManager.js +3 -3
- package/dist/summaryTreeUploadManager.js.map +1 -1
- package/dist/urlUtils.d.ts.map +1 -1
- package/dist/urlUtils.js +0 -2
- package/dist/urlUtils.js.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.d.ts.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.js +3 -4
- package/dist/wholeSummaryDocumentStorageService.js.map +1 -1
- package/lib/createNewUtils.d.ts.map +1 -1
- package/lib/createNewUtils.js +3 -1
- package/lib/createNewUtils.js.map +1 -1
- package/lib/deltaStorageService.js +1 -1
- package/lib/deltaStorageService.js.map +1 -1
- package/lib/documentService.d.ts +6 -11
- package/lib/documentService.d.ts.map +1 -1
- package/lib/documentService.js +16 -61
- package/lib/documentService.js.map +1 -1
- package/lib/documentServiceFactory.d.ts +1 -0
- package/lib/documentServiceFactory.d.ts.map +1 -1
- package/lib/documentServiceFactory.js +19 -28
- package/lib/documentServiceFactory.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/r11sSnapshotParser.d.ts.map +1 -1
- package/lib/r11sSnapshotParser.js +2 -4
- package/lib/r11sSnapshotParser.js.map +1 -1
- package/lib/sessionInfoManager.d.ts +55 -0
- package/lib/sessionInfoManager.d.ts.map +1 -0
- package/lib/sessionInfoManager.js +96 -0
- package/lib/sessionInfoManager.js.map +1 -0
- package/lib/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
- package/lib/shreddedSummaryDocumentStorageService.js +3 -4
- package/lib/shreddedSummaryDocumentStorageService.js.map +1 -1
- package/lib/summaryTreeUploadManager.d.ts.map +1 -1
- package/lib/summaryTreeUploadManager.js +3 -3
- package/lib/summaryTreeUploadManager.js.map +1 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/urlUtils.d.ts.map +1 -1
- package/lib/urlUtils.js +0 -2
- package/lib/urlUtils.js.map +1 -1
- package/lib/wholeSummaryDocumentStorageService.d.ts.map +1 -1
- package/lib/wholeSummaryDocumentStorageService.js +3 -4
- package/lib/wholeSummaryDocumentStorageService.js.map +1 -1
- package/package.json +17 -16
- package/src/createNewUtils.ts +4 -1
- package/src/deltaStorageService.ts +1 -1
- package/src/documentService.ts +19 -75
- package/src/documentServiceFactory.ts +25 -38
- package/src/packageVersion.ts +1 -1
- package/src/r11sSnapshotParser.ts +3 -5
- package/src/sessionInfoManager.ts +148 -0
- package/src/shreddedSummaryDocumentStorageService.ts +3 -4
- package/src/summaryTreeUploadManager.ts +4 -4
- package/src/urlUtils.ts +2 -4
- package/src/wholeSummaryDocumentStorageService.ts +3 -4
- package/tsconfig.json +1 -0
|
@@ -112,13 +112,12 @@ class WholeSummaryDocumentStorageService {
|
|
|
112
112
|
// eslint-disable-next-line @rushstack/no-new-null
|
|
113
113
|
async getSnapshotTree(version) {
|
|
114
114
|
let requestVersion = version;
|
|
115
|
-
if (requestVersion
|
|
115
|
+
if (!requestVersion) {
|
|
116
116
|
const versions = await this.getVersions(this.id, 1);
|
|
117
|
-
|
|
118
|
-
if (firstVersion === undefined) {
|
|
117
|
+
if (versions.length === 0) {
|
|
119
118
|
return null;
|
|
120
119
|
}
|
|
121
|
-
requestVersion =
|
|
120
|
+
requestVersion = versions[0];
|
|
122
121
|
}
|
|
123
122
|
let normalizedWholeSnapshot = await this.snapshotTreeCache.get(this.getCacheKey(requestVersion.id));
|
|
124
123
|
if (normalizedWholeSnapshot !== undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wholeSummaryDocumentStorageService.js","sourceRoot":"","sources":["../src/wholeSummaryDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA+F;AAC/F,kEAA6D;AAC7D,mEAAyF;AAUzF,uEAKkD;AAElD,yCAAmD;AAInD,mEAAyF;AAGzF,iDAIwB;AACxB,iFAA2E;AAE3E,MAAM,gBAAgB,GAAW,QAAQ,CAAC;AAE1C,MAAa,kCAAkC;IAItC,KAAK,CAAC,uBAAuB;QACpC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC/C,OAAO,IAAI,wDAAyB,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,YACoB,EAAU,EACV,OAAmB,EACnB,MAA2B,EAC9B,QAAyC,EACxC,cAA6C,EAC7C,YAAqC,IAAI,wBAAa,EAAE,EACxD,oBAAsD,IAAI,wBAAa,EAAE,EACzE,iB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AC,EAAE,sBAAsB,CAAC;aACxD,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACzB,OAAO,sBAAsB,CAAC;IAC/B,CAAC;IAEO,KAAK,CAAC,sBAAsB,CACnC,sBAAgD;QAEhD,MAAM,UAAU,GAAG,sBAAsB,CAAC,EAAE,CAAC;QAC7C,IAAA,iBAAM,EAAC,UAAU,KAAK,SAAS,EAAE,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAChF,MAAM,OAAO,GAAmB;YAC/B,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,sBAAsB,CAAC;YAChF,IAAI,CAAC,gBAAgB,CAAC,sBAAsB,CAAC,KAAK,CAAC;SACnD,CAAC;QAEF,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAE3B,OAAO,UAAU,CAAC;IACnB,CAAC;IAEO,KAAK,CAAC,gBAAgB,CAAC,KAA+B;QAC7D,MAAM,cAAc,GAAoB,EAAE,CAAC;QAC3C,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;YAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;YACtC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACnC,CAAC;IAEO,WAAW,CAAC,MAAc;QACjC,OAAO,GAAG,IAAI,CAAC,EAAE,IAAI,MAAM,EAAE,CAAC;IAC/B,CAAC;CACD;AApUD,gFAoUC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Uint8ArrayToString, performance, stringToBuffer } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { getW3CData, promiseRaceWithWinner } from \"@fluidframework/driver-base/internal\";\nimport { ISummaryHandle, ISummaryTree } from \"@fluidframework/driver-definitions\";\nimport {\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tISummaryContext,\n\tICreateBlobResponse,\n\tISnapshotTree,\n\tIVersion,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tMonitoringContext,\n\tPerformanceEvent,\n\tcreateChildMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { ICache, InMemoryCache } from \"./cache.js\";\nimport { INormalizedWholeSnapshot, IWholeFlatSnapshot } from \"./contracts.js\";\nimport { GitManager } from \"./gitManager.js\";\nimport { IRouterliciousDriverPolicies } from \"./policies.js\";\nimport { convertWholeFlatSnapshotToSnapshotTreeAndBlobs } from \"./r11sSnapshotParser.js\";\nimport { IR11sResponse } from \"./restWrapper.js\";\nimport { ISummaryUploadManager } from \"./storageContracts.js\";\nimport {\n\tconvertSnapshotAndBlobsToSummaryTree,\n\tevalBlobsAndTrees,\n\tvalidateBlobsAndTrees,\n} from \"./treeUtils.js\";\nimport { WholeSummaryUploadManager } from \"./wholeSummaryUploadManager.js\";\n\nconst latestSnapshotId: string = \"latest\";\n\nexport class WholeSummaryDocumentStorageService implements IDocumentStorageService {\n\tprivate readonly mc: MonitoringContext;\n\tprivate firstVersionsCall: boolean = true;\n\n\tprivate async getSummaryUploadManager(): Promise<ISummaryUploadManager> {\n\t\tconst manager = await this.getStorageManager();\n\t\treturn new WholeSummaryUploadManager(manager);\n\t}\n\n\tconstructor(\n\t\tprotected readonly id: string,\n\t\tprotected readonly manager: GitManager,\n\t\tprotected readonly logger: ITelemetryLoggerExt,\n\t\tpublic readonly policies: IDocumentStorageServicePolicies,\n\t\tprivate readonly driverPolicies?: IRouterliciousDriverPolicies,\n\t\tprivate readonly blobCache: ICache<ArrayBufferLike> = new InMemoryCache(),\n\t\tprivate readonly snapshotTreeCache: ICache<INormalizedWholeSnapshot> = new InMemoryCache(),\n\t\tprivate readonly noCacheGitManager?: GitManager,\n\t\tprivate readonly getStorageManager: (\n\t\t\tdisableCache?: boolean,\n\t\t) => Promise<GitManager> = async (disableCache) =>\n\t\t\tdisableCache && this.noCacheGitManager !== undefined\n\t\t\t\t? this.noCacheGitManager\n\t\t\t\t: this.manager,\n\t) {\n\t\tthis.mc = createChildMonitoringContext({\n\t\t\tlogger,\n\t\t});\n\t}\n\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\tif (versionId !== this.id && versionId !== null) {\n\t\t\t// Blobs/Trees in this scenario will never have multiple versions, so return versionId as is\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: versionId,\n\t\t\t\t\ttreeId: undefined!,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t\t// If this is the first versions call for the document, we know we will want the latest summary.\n\t\t// Fetch latest summary, cache it, and return its id.\n\t\tif (this.firstVersionsCall && count === 1) {\n\t\t\tconst normalizedSnapshotContents = await PerformanceEvent.timedExecAsync(\n\t\t\t\tthis.logger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"ObtainSnapshot\",\n\t\t\t\t\tversionId: versionId ?? undefined,\n\t\t\t\t\tcount,\n\t\t\t\t\tenableDiscovery: this.driverPolicies?.enableDiscovery,\n\t\t\t\t},\n\t\t\t\tasync (event) => {\n\t\t\t\t\tlet method: string;\n\t\t\t\t\tconst cachedSnapshotP = this.snapshotTreeCache.get(\n\t\t\t\t\t\tthis.getCacheKey(latestSnapshotId),\n\t\t\t\t\t);\n\n\t\t\t\t\tconst networkSnapshotP = !this.driverPolicies?.enableDiscovery\n\t\t\t\t\t\t? this.fetchSnapshotTree(latestSnapshotId, false, \"getVersions\")\n\t\t\t\t\t\t: this.fetchSnapshotTree(latestSnapshotId, true, \"getVersions\");\n\n\t\t\t\t\tconst promiseRaceWinner = await promiseRaceWithWinner([\n\t\t\t\t\t\tcachedSnapshotP.catch(() => undefined),\n\t\t\t\t\t\tnetworkSnapshotP.catch(() => undefined),\n\t\t\t\t\t]);\n\n\t\t\t\t\tlet retrievedSnapshot = promiseRaceWinner.value;\n\t\t\t\t\tmethod = promiseRaceWinner.index === 0 ? \"cache\" : \"network\";\n\n\t\t\t\t\tif (retrievedSnapshot === undefined) {\n\t\t\t\t\t\t// if network failed -> wait for cache ( then return network failure)\n\t\t\t\t\t\t// If cache returned empty or failed -> wait for network (success of failure)\n\t\t\t\t\t\tif (promiseRaceWinner.index === 1) {\n\t\t\t\t\t\t\tretrievedSnapshot = await cachedSnapshotP;\n\t\t\t\t\t\t\tmethod = \"cache\";\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (retrievedSnapshot === undefined) {\n\t\t\t\t\t\t\tretrievedSnapshot = await networkSnapshotP;\n\t\t\t\t\t\t\tmethod = \"network\";\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tevent.end({\n\t\t\t\t\t\tmethod,\n\t\t\t\t\t});\n\t\t\t\t\treturn retrievedSnapshot;\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tconst _id = await this.initializeFromSnapshot(normalizedSnapshotContents);\n\t\t\tthis.firstVersionsCall = false;\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: _id,\n\t\t\t\t\ttreeId: normalizedSnapshotContents.snapshotTree.id!,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\t// Otherwise, get the latest version of the document as normal.\n\t\tconst id = versionId ? versionId : this.id;\n\t\tconst commits = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"getVersions\",\n\t\t\t\tversionId: id,\n\t\t\t\tcount,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\treturn (await manager.getCommits(id, count)).content;\n\t\t\t},\n\t\t);\n\t\treturn commits.map((commit) => ({\n\t\t\tdate: commit.commit.author.date,\n\t\t\tid: commit.sha,\n\t\t\ttreeId: commit.commit.tree.sha,\n\t\t}));\n\t}\n\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\tlet requestVersion = version;\n\t\tif (requestVersion === undefined) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tconst firstVersion = versions[0];\n\t\t\tif (firstVersion === undefined) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\trequestVersion = firstVersion;\n\t\t}\n\n\t\tlet normalizedWholeSnapshot = await this.snapshotTreeCache.get(\n\t\t\tthis.getCacheKey(requestVersion.id),\n\t\t);\n\t\tif (normalizedWholeSnapshot !== undefined) {\n\t\t\treturn normalizedWholeSnapshot.snapshotTree;\n\t\t}\n\n\t\tnormalizedWholeSnapshot = await this.fetchSnapshotTree(\n\t\t\trequestVersion.id,\n\t\t\tundefined,\n\t\t\t\"getSnapshotTree\",\n\t\t);\n\n\t\t// Currently retrieving blobs from network is not supported by AFR for WholeSummaryDocumentStorageService\n\t\t// Blobs are expected to be put in the cache\n\t\tawait this.updateBlobsCache(normalizedWholeSnapshot.blobs);\n\n\t\treturn normalizedWholeSnapshot.snapshotTree;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tconst cachedBlob = await this.blobCache.get(this.getCacheKey(blobId));\n\t\tif (cachedBlob !== undefined) {\n\t\t\treturn cachedBlob;\n\t\t}\n\n\t\t// Note: AFR does not support readBlobs, but potentially other r11s like servers do\n\t\tconst blob = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"readBlob\",\n\t\t\t\tblobId,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\tconst response = (await manager.getBlob(blobId)).content;\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.size,\n\t\t\t\t});\n\t\t\t\treturn response;\n\t\t\t},\n\t\t\tundefined, // workers\n\t\t\tthis.mc.config.getNumber(\"Fluid.Driver.ReadBlobTelemetrySampling\"),\n\t\t);\n\t\tconst bufferValue = stringToBuffer(blob.content, blob.encoding);\n\n\t\tawait this.blobCache.put(this.getCacheKey(blob.sha), bufferValue);\n\n\t\treturn bufferValue;\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tconst summaryHandle = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"uploadSummaryWithContext\",\n\t\t\t\tproposalHandle: context.proposalHandle,\n\t\t\t\tackHandle: context.ackHandle,\n\t\t\t\treferenceSequenceNumber: context.referenceSequenceNumber,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tconst summaryUploadManager = await this.getSummaryUploadManager();\n\t\t\t\treturn summaryUploadManager.writeSummaryTree(\n\t\t\t\t\tsummary,\n\t\t\t\t\tcontext.ackHandle ?? \"\",\n\t\t\t\t\t\"channel\",\n\t\t\t\t);\n\t\t\t},\n\t\t);\n\t\treturn summaryHandle;\n\t}\n\n\tpublic async downloadSummary(summaryHandle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tconst wholeFlatSnapshot = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"getWholeFlatSummary\",\n\t\t\t\ttreeId: summaryHandle.handle,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\tconst response = await manager.getSnapshot(summaryHandle.handle);\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.content.trees[0]?.entries.length,\n\t\t\t\t});\n\t\t\t\treturn response.content;\n\t\t\t},\n\t\t);\n\n\t\tconst { blobs, snapshotTree } = convertWholeFlatSnapshotToSnapshotTreeAndBlobs(\n\t\t\twholeFlatSnapshot,\n\t\t\t\"\",\n\t\t);\n\t\treturn convertSnapshotAndBlobsToSummaryTree(snapshotTree, blobs);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\tconst uint8ArrayFile = new Uint8Array(file);\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"createBlob\",\n\t\t\t\tsize: uint8ArrayFile.length,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\tconst response = await manager\n\t\t\t\t\t.createBlob(Uint8ArrayToString(uint8ArrayFile, \"base64\"), \"base64\")\n\t\t\t\t\t.then((r) => ({ id: r.content.sha, url: r.content.url }));\n\t\t\t\tevent.end({\n\t\t\t\t\tblobId: response.id,\n\t\t\t\t});\n\t\t\t\treturn response;\n\t\t\t},\n\t\t);\n\t}\n\n\tprivate async fetchSnapshotTree(\n\t\tversionId: string,\n\t\tdisableCache?: boolean,\n\t\tscenarioName?: string,\n\t): Promise<INormalizedWholeSnapshot> {\n\t\tconst normalizedWholeSummary = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"getWholeFlatSummary\",\n\t\t\t\ttreeId: versionId,\n\t\t\t\tscenarioName,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager(disableCache);\n\t\t\t\tconst response: IR11sResponse<IWholeFlatSnapshot> =\n\t\t\t\t\tawait manager.getSnapshot(versionId);\n\t\t\t\tconst start = performance.now();\n\t\t\t\tconst snapshot: INormalizedWholeSnapshot =\n\t\t\t\t\tconvertWholeFlatSnapshotToSnapshotTreeAndBlobs(response.content);\n\t\t\t\tconst snapshotConversionTime = performance.now() - start;\n\t\t\t\tvalidateBlobsAndTrees(snapshot.snapshotTree);\n\t\t\t\tconst { trees, numBlobs, encodedBlobsSize } = evalBlobsAndTrees(snapshot);\n\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.content.trees[0]?.entries.length,\n\t\t\t\t\ttrees,\n\t\t\t\t\tblobs: numBlobs,\n\t\t\t\t\tencodedBlobsSize,\n\t\t\t\t\tsequenceNumber: snapshot.sequenceNumber,\n\t\t\t\t\t...response.propsToLog,\n\t\t\t\t\tsnapshotConversionTime,\n\t\t\t\t\t...getW3CData(response.requestUrl, \"xmlhttprequest\"),\n\t\t\t\t});\n\t\t\t\treturn snapshot;\n\t\t\t},\n\t\t);\n\n\t\t// Also add the result into the cache.\n\t\tawait this.snapshotTreeCache\n\t\t\t.put(this.getCacheKey(versionId), normalizedWholeSummary)\n\t\t\t.catch(() => undefined);\n\t\treturn normalizedWholeSummary;\n\t}\n\n\tprivate async initializeFromSnapshot(\n\t\tnormalizedWholeSummary: INormalizedWholeSnapshot,\n\t): Promise<string> {\n\t\tconst snapshotId = normalizedWholeSummary.id;\n\t\tassert(snapshotId !== undefined, 0x275 /* \"Root tree should contain the id\" */);\n\t\tconst cachePs: Promise<any>[] = [\n\t\t\tthis.snapshotTreeCache.put(this.getCacheKey(snapshotId), normalizedWholeSummary),\n\t\t\tthis.updateBlobsCache(normalizedWholeSummary.blobs),\n\t\t];\n\n\t\tawait Promise.all(cachePs);\n\n\t\treturn snapshotId;\n\t}\n\n\tprivate async updateBlobsCache(blobs: Map<string, ArrayBuffer>): Promise<void> {\n\t\tconst blobCachePutPs: Promise<void>[] = [];\n\t\tblobs.forEach((value, id) => {\n\t\t\tconst cacheKey = this.getCacheKey(id);\n\t\t\tblobCachePutPs.push(this.blobCache.put(cacheKey, value));\n\t\t});\n\t\tawait Promise.all(blobCachePutPs);\n\t}\n\n\tprivate getCacheKey(blobId: string): string {\n\t\treturn `${this.id}:${blobId}`;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"wholeSummaryDocumentStorageService.js","sourceRoot":"","sources":["../src/wholeSummaryDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;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AAW,CAAC,EAAE,CAAC,CAAC;YACtC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACnC,CAAC;IAEO,WAAW,CAAC,MAAc;QACjC,OAAO,GAAG,IAAI,CAAC,EAAE,IAAI,MAAM,EAAE,CAAC;IAC/B,CAAC;CACD;AAnUD,gFAmUC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Uint8ArrayToString, performance, stringToBuffer } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { getW3CData, promiseRaceWithWinner } from \"@fluidframework/driver-base/internal\";\nimport { ISummaryHandle, ISummaryTree } from \"@fluidframework/driver-definitions\";\nimport {\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tISummaryContext,\n\tICreateBlobResponse,\n\tISnapshotTree,\n\tIVersion,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tMonitoringContext,\n\tPerformanceEvent,\n\tcreateChildMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { ICache, InMemoryCache } from \"./cache.js\";\nimport { INormalizedWholeSnapshot, IWholeFlatSnapshot } from \"./contracts.js\";\nimport { GitManager } from \"./gitManager.js\";\nimport { IRouterliciousDriverPolicies } from \"./policies.js\";\nimport { convertWholeFlatSnapshotToSnapshotTreeAndBlobs } from \"./r11sSnapshotParser.js\";\nimport { IR11sResponse } from \"./restWrapper.js\";\nimport { ISummaryUploadManager } from \"./storageContracts.js\";\nimport {\n\tconvertSnapshotAndBlobsToSummaryTree,\n\tevalBlobsAndTrees,\n\tvalidateBlobsAndTrees,\n} from \"./treeUtils.js\";\nimport { WholeSummaryUploadManager } from \"./wholeSummaryUploadManager.js\";\n\nconst latestSnapshotId: string = \"latest\";\n\nexport class WholeSummaryDocumentStorageService implements IDocumentStorageService {\n\tprivate readonly mc: MonitoringContext;\n\tprivate firstVersionsCall: boolean = true;\n\n\tprivate async getSummaryUploadManager(): Promise<ISummaryUploadManager> {\n\t\tconst manager = await this.getStorageManager();\n\t\treturn new WholeSummaryUploadManager(manager);\n\t}\n\n\tconstructor(\n\t\tprotected readonly id: string,\n\t\tprotected readonly manager: GitManager,\n\t\tprotected readonly logger: ITelemetryLoggerExt,\n\t\tpublic readonly policies: IDocumentStorageServicePolicies,\n\t\tprivate readonly driverPolicies?: IRouterliciousDriverPolicies,\n\t\tprivate readonly blobCache: ICache<ArrayBufferLike> = new InMemoryCache(),\n\t\tprivate readonly snapshotTreeCache: ICache<INormalizedWholeSnapshot> = new InMemoryCache(),\n\t\tprivate readonly noCacheGitManager?: GitManager,\n\t\tprivate readonly getStorageManager: (\n\t\t\tdisableCache?: boolean,\n\t\t) => Promise<GitManager> = async (disableCache) =>\n\t\t\tdisableCache && this.noCacheGitManager !== undefined\n\t\t\t\t? this.noCacheGitManager\n\t\t\t\t: this.manager,\n\t) {\n\t\tthis.mc = createChildMonitoringContext({\n\t\t\tlogger,\n\t\t});\n\t}\n\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\tif (versionId !== this.id && versionId !== null) {\n\t\t\t// Blobs/Trees in this scenario will never have multiple versions, so return versionId as is\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: versionId,\n\t\t\t\t\ttreeId: undefined!,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t\t// If this is the first versions call for the document, we know we will want the latest summary.\n\t\t// Fetch latest summary, cache it, and return its id.\n\t\tif (this.firstVersionsCall && count === 1) {\n\t\t\tconst normalizedSnapshotContents = await PerformanceEvent.timedExecAsync(\n\t\t\t\tthis.logger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"ObtainSnapshot\",\n\t\t\t\t\tversionId: versionId ?? undefined,\n\t\t\t\t\tcount,\n\t\t\t\t\tenableDiscovery: this.driverPolicies?.enableDiscovery,\n\t\t\t\t},\n\t\t\t\tasync (event) => {\n\t\t\t\t\tlet method: string;\n\t\t\t\t\tconst cachedSnapshotP = this.snapshotTreeCache.get(\n\t\t\t\t\t\tthis.getCacheKey(latestSnapshotId),\n\t\t\t\t\t);\n\n\t\t\t\t\tconst networkSnapshotP = !this.driverPolicies?.enableDiscovery\n\t\t\t\t\t\t? this.fetchSnapshotTree(latestSnapshotId, false, \"getVersions\")\n\t\t\t\t\t\t: this.fetchSnapshotTree(latestSnapshotId, true, \"getVersions\");\n\n\t\t\t\t\tconst promiseRaceWinner = await promiseRaceWithWinner([\n\t\t\t\t\t\tcachedSnapshotP.catch(() => undefined),\n\t\t\t\t\t\tnetworkSnapshotP.catch(() => undefined),\n\t\t\t\t\t]);\n\n\t\t\t\t\tlet retrievedSnapshot = promiseRaceWinner.value;\n\t\t\t\t\tmethod = promiseRaceWinner.index === 0 ? \"cache\" : \"network\";\n\n\t\t\t\t\tif (retrievedSnapshot === undefined) {\n\t\t\t\t\t\t// if network failed -> wait for cache ( then return network failure)\n\t\t\t\t\t\t// If cache returned empty or failed -> wait for network (success of failure)\n\t\t\t\t\t\tif (promiseRaceWinner.index === 1) {\n\t\t\t\t\t\t\tretrievedSnapshot = await cachedSnapshotP;\n\t\t\t\t\t\t\tmethod = \"cache\";\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (retrievedSnapshot === undefined) {\n\t\t\t\t\t\t\tretrievedSnapshot = await networkSnapshotP;\n\t\t\t\t\t\t\tmethod = \"network\";\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tevent.end({\n\t\t\t\t\t\tmethod,\n\t\t\t\t\t});\n\t\t\t\t\treturn retrievedSnapshot;\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tconst _id = await this.initializeFromSnapshot(normalizedSnapshotContents);\n\t\t\tthis.firstVersionsCall = false;\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: _id,\n\t\t\t\t\ttreeId: normalizedSnapshotContents.snapshotTree.id!,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\t// Otherwise, get the latest version of the document as normal.\n\t\tconst id = versionId ? versionId : this.id;\n\t\tconst commits = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"getVersions\",\n\t\t\t\tversionId: id,\n\t\t\t\tcount,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\treturn (await manager.getCommits(id, count)).content;\n\t\t\t},\n\t\t);\n\t\treturn commits.map((commit) => ({\n\t\t\tdate: commit.commit.author.date,\n\t\t\tid: commit.sha,\n\t\t\ttreeId: commit.commit.tree.sha,\n\t\t}));\n\t}\n\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\tlet requestVersion = version;\n\t\tif (!requestVersion) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\trequestVersion = versions[0];\n\t\t}\n\n\t\tlet normalizedWholeSnapshot = await this.snapshotTreeCache.get(\n\t\t\tthis.getCacheKey(requestVersion.id),\n\t\t);\n\t\tif (normalizedWholeSnapshot !== undefined) {\n\t\t\treturn normalizedWholeSnapshot.snapshotTree;\n\t\t}\n\n\t\tnormalizedWholeSnapshot = await this.fetchSnapshotTree(\n\t\t\trequestVersion.id,\n\t\t\tundefined,\n\t\t\t\"getSnapshotTree\",\n\t\t);\n\n\t\t// Currently retrieving blobs from network is not supported by AFR for WholeSummaryDocumentStorageService\n\t\t// Blobs are expected to be put in the cache\n\t\tawait this.updateBlobsCache(normalizedWholeSnapshot.blobs);\n\n\t\treturn normalizedWholeSnapshot.snapshotTree;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tconst cachedBlob = await this.blobCache.get(this.getCacheKey(blobId));\n\t\tif (cachedBlob !== undefined) {\n\t\t\treturn cachedBlob;\n\t\t}\n\n\t\t// Note: AFR does not support readBlobs, but potentially other r11s like servers do\n\t\tconst blob = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"readBlob\",\n\t\t\t\tblobId,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\tconst response = (await manager.getBlob(blobId)).content;\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.size,\n\t\t\t\t});\n\t\t\t\treturn response;\n\t\t\t},\n\t\t\tundefined, // workers\n\t\t\tthis.mc.config.getNumber(\"Fluid.Driver.ReadBlobTelemetrySampling\"),\n\t\t);\n\t\tconst bufferValue = stringToBuffer(blob.content, blob.encoding);\n\n\t\tawait this.blobCache.put(this.getCacheKey(blob.sha), bufferValue);\n\n\t\treturn bufferValue;\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tconst summaryHandle = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"uploadSummaryWithContext\",\n\t\t\t\tproposalHandle: context.proposalHandle,\n\t\t\t\tackHandle: context.ackHandle,\n\t\t\t\treferenceSequenceNumber: context.referenceSequenceNumber,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tconst summaryUploadManager = await this.getSummaryUploadManager();\n\t\t\t\treturn summaryUploadManager.writeSummaryTree(\n\t\t\t\t\tsummary,\n\t\t\t\t\tcontext.ackHandle ?? \"\",\n\t\t\t\t\t\"channel\",\n\t\t\t\t);\n\t\t\t},\n\t\t);\n\t\treturn summaryHandle;\n\t}\n\n\tpublic async downloadSummary(summaryHandle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tconst wholeFlatSnapshot = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"getWholeFlatSummary\",\n\t\t\t\ttreeId: summaryHandle.handle,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\tconst response = await manager.getSnapshot(summaryHandle.handle);\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.content.trees[0]?.entries.length,\n\t\t\t\t});\n\t\t\t\treturn response.content;\n\t\t\t},\n\t\t);\n\n\t\tconst { blobs, snapshotTree } = convertWholeFlatSnapshotToSnapshotTreeAndBlobs(\n\t\t\twholeFlatSnapshot,\n\t\t\t\"\",\n\t\t);\n\t\treturn convertSnapshotAndBlobsToSummaryTree(snapshotTree, blobs);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\tconst uint8ArrayFile = new Uint8Array(file);\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"createBlob\",\n\t\t\t\tsize: uint8ArrayFile.length,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager();\n\t\t\t\tconst response = await manager\n\t\t\t\t\t.createBlob(Uint8ArrayToString(uint8ArrayFile, \"base64\"), \"base64\")\n\t\t\t\t\t.then((r) => ({ id: r.content.sha, url: r.content.url }));\n\t\t\t\tevent.end({\n\t\t\t\t\tblobId: response.id,\n\t\t\t\t});\n\t\t\t\treturn response;\n\t\t\t},\n\t\t);\n\t}\n\n\tprivate async fetchSnapshotTree(\n\t\tversionId: string,\n\t\tdisableCache?: boolean,\n\t\tscenarioName?: string,\n\t): Promise<INormalizedWholeSnapshot> {\n\t\tconst normalizedWholeSummary = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"getWholeFlatSummary\",\n\t\t\t\ttreeId: versionId,\n\t\t\t\tscenarioName,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst manager = await this.getStorageManager(disableCache);\n\t\t\t\tconst response: IR11sResponse<IWholeFlatSnapshot> =\n\t\t\t\t\tawait manager.getSnapshot(versionId);\n\t\t\t\tconst start = performance.now();\n\t\t\t\tconst snapshot: INormalizedWholeSnapshot =\n\t\t\t\t\tconvertWholeFlatSnapshotToSnapshotTreeAndBlobs(response.content);\n\t\t\t\tconst snapshotConversionTime = performance.now() - start;\n\t\t\t\tvalidateBlobsAndTrees(snapshot.snapshotTree);\n\t\t\t\tconst { trees, numBlobs, encodedBlobsSize } = evalBlobsAndTrees(snapshot);\n\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.content.trees[0]?.entries.length,\n\t\t\t\t\ttrees,\n\t\t\t\t\tblobs: numBlobs,\n\t\t\t\t\tencodedBlobsSize,\n\t\t\t\t\tsequenceNumber: snapshot.sequenceNumber,\n\t\t\t\t\t...response.propsToLog,\n\t\t\t\t\tsnapshotConversionTime,\n\t\t\t\t\t...getW3CData(response.requestUrl, \"xmlhttprequest\"),\n\t\t\t\t});\n\t\t\t\treturn snapshot;\n\t\t\t},\n\t\t);\n\n\t\t// Also add the result into the cache.\n\t\tawait this.snapshotTreeCache\n\t\t\t.put(this.getCacheKey(versionId), normalizedWholeSummary)\n\t\t\t.catch(() => undefined);\n\t\treturn normalizedWholeSummary;\n\t}\n\n\tprivate async initializeFromSnapshot(\n\t\tnormalizedWholeSummary: INormalizedWholeSnapshot,\n\t): Promise<string> {\n\t\tconst snapshotId = normalizedWholeSummary.id;\n\t\tassert(snapshotId !== undefined, 0x275 /* \"Root tree should contain the id\" */);\n\t\tconst cachePs: Promise<any>[] = [\n\t\t\tthis.snapshotTreeCache.put(this.getCacheKey(snapshotId), normalizedWholeSummary),\n\t\t\tthis.updateBlobsCache(normalizedWholeSummary.blobs),\n\t\t];\n\n\t\tawait Promise.all(cachePs);\n\n\t\treturn snapshotId;\n\t}\n\n\tprivate async updateBlobsCache(blobs: Map<string, ArrayBuffer>): Promise<void> {\n\t\tconst blobCachePutPs: Promise<void>[] = [];\n\t\tblobs.forEach((value, id) => {\n\t\t\tconst cacheKey = this.getCacheKey(id);\n\t\t\tblobCachePutPs.push(this.blobCache.put(cacheKey, value));\n\t\t});\n\t\tawait Promise.all(blobCachePutPs);\n\t}\n\n\tprivate getCacheKey(blobId: string): string {\n\t\treturn `${this.id}:${blobId}`;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createNewUtils.d.ts","sourceRoot":"","sources":["../src/createNewUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,YAAY,EAAe,MAAM,oCAAoC,CAAC;AAE/E;;;;GAIG;AACH,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,YAAY,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"createNewUtils.d.ts","sourceRoot":"","sources":["../src/createNewUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,YAAY,EAAe,MAAM,oCAAoC,CAAC;AAE/E;;;;GAIG;AACH,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,YAAY,GAAG,YAAY,CA2BpF"}
|
package/lib/createNewUtils.js
CHANGED
|
@@ -10,7 +10,9 @@ import { SummaryType } from "@fluidframework/driver-definitions";
|
|
|
10
10
|
* @returns Modified summary tree where the blob contents could be utf8 string only.
|
|
11
11
|
*/
|
|
12
12
|
export function convertSummaryToCreateNewSummary(summary) {
|
|
13
|
-
|
|
13
|
+
const keys = Object.keys(summary.tree);
|
|
14
|
+
for (const key of keys) {
|
|
15
|
+
const summaryObject = summary.tree[key];
|
|
14
16
|
switch (summaryObject.type) {
|
|
15
17
|
case SummaryType.Tree: {
|
|
16
18
|
summary.tree[key] = convertSummaryToCreateNewSummary(summaryObject);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createNewUtils.js","sourceRoot":"","sources":["../src/createNewUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAgB,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAE/E;;;;GAIG;AACH,MAAM,UAAU,gCAAgC,CAAC,OAAqB;IACrE,
|
|
1
|
+
{"version":3,"file":"createNewUtils.js","sourceRoot":"","sources":["../src/createNewUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAgB,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAE/E;;;;GAIG;AACH,MAAM,UAAU,gCAAgC,CAAC,OAAqB;IACrE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACxB,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAExC,QAAQ,aAAa,CAAC,IAAI,EAAE,CAAC;YAC5B,KAAK,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;gBACvB,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,gCAAgC,CAAC,aAAa,CAAC,CAAC;gBACpE,MAAM;YACP,CAAC;YACD,KAAK,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;gBACvB,aAAa,CAAC,OAAO;oBACpB,OAAO,aAAa,CAAC,OAAO,KAAK,QAAQ;wBACxC,CAAC,CAAC,aAAa,CAAC,OAAO;wBACvB,CAAC,CAAC,kBAAkB,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;gBACtD,MAAM;YACP,CAAC;YACD,KAAK,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;gBACzB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;YACpE,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACT,MAAM,IAAI,KAAK,CAAC,qBAAqB,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;YAC5D,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Uint8ArrayToString } from \"@fluid-internal/client-utils\";\nimport { ISummaryTree, SummaryType } from \"@fluidframework/driver-definitions\";\n\n/**\n * Utility api to convert ISummaryTree to a summary tree where blob contents are only utf8 strings.\n * @param summary - Summary supplied by the runtime to upload.\n * @returns Modified summary tree where the blob contents could be utf8 string only.\n */\nexport function convertSummaryToCreateNewSummary(summary: ISummaryTree): ISummaryTree {\n\tconst keys = Object.keys(summary.tree);\n\tfor (const key of keys) {\n\t\tconst summaryObject = summary.tree[key];\n\n\t\tswitch (summaryObject.type) {\n\t\t\tcase SummaryType.Tree: {\n\t\t\t\tsummary.tree[key] = convertSummaryToCreateNewSummary(summaryObject);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SummaryType.Blob: {\n\t\t\t\tsummaryObject.content =\n\t\t\t\t\ttypeof summaryObject.content === \"string\"\n\t\t\t\t\t\t? summaryObject.content\n\t\t\t\t\t\t: Uint8ArrayToString(summaryObject.content, \"utf8\");\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SummaryType.Handle: {\n\t\t\t\tthrow new Error(\"No handle should be present for first summary!!\");\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new Error(`Unknown tree type ${summaryObject.type}`);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn summary;\n}\n"]}
|
|
@@ -39,7 +39,7 @@ export class DocumentDeltaStorageService {
|
|
|
39
39
|
if (this.snapshotOps !== undefined && this.snapshotOps.length !== 0) {
|
|
40
40
|
const messages = this.snapshotOps.filter((op) => op.sequenceNumber >= from && op.sequenceNumber < to);
|
|
41
41
|
validateMessages("snapshotOps", messages, from, this.logger, false /* strict */);
|
|
42
|
-
if (messages.length > 0 && messages[0]
|
|
42
|
+
if (messages.length > 0 && messages[0].sequenceNumber === from) {
|
|
43
43
|
this.snapshotOps = this.snapshotOps.filter((op) => op.sequenceNumber >= to);
|
|
44
44
|
opsFromSnapshot += messages.length;
|
|
45
45
|
return { messages, partialResult: true };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deltaStorageService.js","sourceRoot":"","sources":["../src/deltaStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAQpF,OAAO,EACN,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,cAAc,GACd,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAEN,gBAAgB,GAChB,MAAM,0CAA0C,CAAC;AAKlD;;;;;;GAMG;AACH,MAAM,cAAc,GAAG,IAAI,CAAC;AAE5B;;GAEG;AACH,MAAM,OAAO,2BAA2B;IACvC,YACkB,QAAgB,EAChB,EAAU,EACV,mBAAyC,EACzC,sBAA8C,EAC9C,MAA2B;QAJ3B,aAAQ,GAAR,QAAQ,CAAQ;QAChB,OAAE,GAAF,EAAE,CAAQ;QACV,wBAAmB,GAAnB,mBAAmB,CAAsB;QACzC,2BAAsB,GAAtB,sBAAsB,CAAwB;QAC9C,WAAM,GAAN,MAAM,CAAqB;QAE5C,IAAI,CAAC,UAAU,GAAG,sBAAsB,CAAC,UAAU,CAAC;IACrD,CAAC;IAKD,aAAa,CACZ,SAAiB,EACjB,OAA2B,EAC3B,WAAyB,EACzB,UAAoB,EACpB,WAAoB;QAEpB,IAAI,UAAU,EAAE,CAAC;YAChB,OAAO,kBAAkB,CAAC;QAC3B,CAAC;QAED,IAAI,eAAe,GAAG,CAAC,CAAC;QACxB,IAAI,cAAc,GAAG,CAAC,CAAC;QACvB,MAAM,eAA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QAAQ,EAAE,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;IAChD,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseProperties } from \"@fluidframework/core-interfaces\";\nimport { getW3CData, validateMessages } from \"@fluidframework/driver-base/internal\";\nimport {\n\tIDeltaStorageService,\n\tIDeltasFetchResult,\n\tIDocumentDeltaStorageService,\n\tIStream,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\temptyMessageStream,\n\treadAndParse,\n\trequestOps,\n\tstreamObserver,\n} from \"@fluidframework/driver-utils/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tPerformanceEvent,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { DocumentStorageService } from \"./documentStorageService.js\";\nimport { RestWrapper } from \"./restWrapperBase.js\";\n\n/**\n * Maximum number of ops we can fetch at a time. This should be kept at 2k, as\n * server determines whether to try to fallback to long-term storage if the ops range requested is larger than\n * what they have locally available in short-term storage. So if we request 2k ops, they know it is not a\n * specific request and they don't fall to long term storage which takes time.\n * Please coordinate to AFR team if this value need to be changed.\n */\nconst MaxBatchDeltas = 2000;\n\n/**\n * Storage service limited to only being able to fetch documents for a specific document\n */\nexport class DocumentDeltaStorageService implements IDocumentDeltaStorageService {\n\tconstructor(\n\t\tprivate readonly tenantId: string,\n\t\tprivate readonly id: string,\n\t\tprivate readonly deltaStorageService: IDeltaStorageService,\n\t\tprivate readonly documentStorageService: DocumentStorageService,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t) {\n\t\tthis.logtailSha = documentStorageService.logTailSha;\n\t}\n\n\tprivate logtailSha: string | undefined;\n\tprivate snapshotOps: ISequencedDocumentMessage[] | undefined;\n\n\tfetchMessages(\n\t\tfromTotal: number,\n\t\ttoTotal: number | undefined,\n\t\tabortSignal?: AbortSignal,\n\t\tcachedOnly?: boolean,\n\t\tfetchReason?: string,\n\t): IStream<ISequencedDocumentMessage[]> {\n\t\tif (cachedOnly) {\n\t\t\treturn emptyMessageStream;\n\t\t}\n\n\t\tlet opsFromSnapshot = 0;\n\t\tlet opsFromStorage = 0;\n\t\tconst requestCallback = async (\n\t\t\tfrom: number,\n\t\t\tto: number,\n\t\t\ttelemetryProps: ITelemetryBaseProperties,\n\t\t) => {\n\t\t\tthis.snapshotOps = this.logtailSha\n\t\t\t\t? await readAndParse<ISequencedDocumentMessage[]>(\n\t\t\t\t\t\tthis.documentStorageService,\n\t\t\t\t\t\tthis.logtailSha,\n\t\t\t\t\t)\n\t\t\t\t: [];\n\t\t\tthis.logtailSha = undefined;\n\n\t\t\tif (this.snapshotOps !== undefined && this.snapshotOps.length !== 0) {\n\t\t\t\tconst messages = this.snapshotOps.filter(\n\t\t\t\t\t(op) => op.sequenceNumber >= from && op.sequenceNumber < to,\n\t\t\t\t);\n\t\t\t\tvalidateMessages(\"snapshotOps\", messages, from, this.logger, false /* strict */);\n\t\t\t\tif (messages.length > 0 && messages[0] && messages[0].sequenceNumber === from) {\n\t\t\t\t\tthis.snapshotOps = this.snapshotOps.filter((op) => op.sequenceNumber >= to);\n\t\t\t\t\topsFromSnapshot += messages.length;\n\t\t\t\t\treturn { messages, partialResult: true };\n\t\t\t\t}\n\t\t\t\tthis.snapshotOps = undefined;\n\t\t\t}\n\n\t\t\tconst ops = await this.deltaStorageService.get(this.tenantId, this.id, from, to);\n\t\t\tvalidateMessages(\"storage\", ops.messages, from, this.logger, false /* strict */);\n\t\t\topsFromStorage += ops.messages.length;\n\t\t\treturn ops;\n\t\t};\n\n\t\tconst stream = requestOps(\n\t\t\tasync (from: number, to: number, telemetryProps: ITelemetryBaseProperties) => {\n\t\t\t\tconst result = await requestCallback(from, to, telemetryProps);\n\t\t\t\t// Catch all case, just in case\n\t\t\t\tvalidateMessages(\"catch all\", result.messages, from, this.logger);\n\t\t\t\treturn result;\n\t\t\t},\n\t\t\t// Staging: starting with no concurrency, listening for feedback first.\n\t\t\t// In future releases we will switch to actual concurrency\n\t\t\t1, // concurrency\n\t\t\tfromTotal, // inclusive\n\t\t\ttoTotal, // exclusive\n\t\t\tMaxBatchDeltas,\n\t\t\tthis.logger,\n\t\t\tabortSignal,\n\t\t\tfetchReason,\n\t\t);\n\n\t\treturn streamObserver(stream, (result) => {\n\t\t\tif (result.done && opsFromSnapshot + opsFromStorage !== 0) {\n\t\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\t\teventName: \"CacheOpsRetrieved\",\n\t\t\t\t\topsFromSnapshot,\n\t\t\t\t\topsFromStorage,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n}\n\n/**\n * Provides access to the underlying delta storage on the server for routerlicious driver.\n */\nexport class DeltaStorageService implements IDeltaStorageService {\n\tconstructor(\n\t\tprivate readonly url: string,\n\t\tprivate readonly restWrapper: RestWrapper,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprivate readonly getRestWrapper: () => Promise<RestWrapper> = async () => this.restWrapper,\n\t\tprivate readonly getDeltaStorageUrl: () => string = () => this.url,\n\t) {}\n\n\tpublic async get(\n\t\ttenantId: string,\n\t\tid: string,\n\t\tfrom: number, // inclusive\n\t\tto: number, // exclusive\n\t): Promise<IDeltasFetchResult> {\n\t\tconst ops = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"OpsFetch\",\n\t\t\t\tfrom,\n\t\t\t\tto,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst restWrapper = await this.getRestWrapper();\n\t\t\t\tconst url = this.getDeltaStorageUrl();\n\t\t\t\tconst response = await restWrapper.get<ISequencedDocumentMessage[]>(url, {\n\t\t\t\t\tfrom: from - 1,\n\t\t\t\t\tto,\n\t\t\t\t});\n\t\t\t\tevent.end({\n\t\t\t\t\tlength: response.content.length,\n\t\t\t\t\tdetails: JSON.stringify({\n\t\t\t\t\t\tfirstOpSeqNumber: response.content[0]?.sequenceNumber,\n\t\t\t\t\t\tlastOpSeqNumber: response.content[response.content.length - 1]?.sequenceNumber,\n\t\t\t\t\t}),\n\t\t\t\t\t...response.propsToLog,\n\t\t\t\t\t...getW3CData(response.requestUrl, \"xmlhttprequest\"),\n\t\t\t\t});\n\t\t\t\treturn response.content;\n\t\t\t},\n\t\t);\n\n\t\t// It is assumed that server always returns all the ops that it has in the range that was requested.\n\t\t// This may change in the future, if so, we need to adjust and receive \"end\" value from server in such case.\n\t\treturn { messages: ops, partialResult: false };\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"deltaStorageService.js","sourceRoot":"","sources":["../src/deltaStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAQpF,OAAO,EACN,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,cAAc,GACd,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAEN,gBAAgB,GAChB,MAAM,0CAA0C,CAAC;AAKlD;;;;;;GAMG;AACH,MAAM,cAAc,GAAG,IAAI,CAAC;AAE5B;;GAEG;AACH,MAAM,OAAO,2BAA2B;IACvC,YACkB,QAAgB,EAChB,EAAU,EACV,mBAAyC,EACzC,sBAA8C,EAC9C,MAA2B;QAJ3B,aAAQ,GAAR,QAAQ,CAAQ;QAChB,OAAE,GAAF,EAAE,CAAQ;QACV,wBAAmB,GAAnB,mBAAmB,CAAsB;QACzC,2BAAsB,GAAtB,sBAAsB,CAAwB;QAC9C,WAAM,GAAN,MAAM,CAAqB;QAE5C,IAAI,CAAC,UAAU,GAAG,sBAAsB,CAAC,UAAU,CAAC;IACrD,CAAC;IAKD,aAAa,CACZ,SAAiB,EACjB,OAA2B,EAC3B,WAAyB,EACzB,UAAoB,EACpB,WAAoB;QAEpB,IAAI,UAAU,EAAE,CAAC;YAChB,OAAO,kBAAkB,CAAC;QAC3B,CAAC;QAED,IAAI,eAAe,GAAG,CAA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4GAA4G;QAC5G,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;IAChD,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseProperties } from \"@fluidframework/core-interfaces\";\nimport { getW3CData, validateMessages } from \"@fluidframework/driver-base/internal\";\nimport {\n\tIDeltaStorageService,\n\tIDeltasFetchResult,\n\tIDocumentDeltaStorageService,\n\tIStream,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\temptyMessageStream,\n\treadAndParse,\n\trequestOps,\n\tstreamObserver,\n} from \"@fluidframework/driver-utils/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tPerformanceEvent,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { DocumentStorageService } from \"./documentStorageService.js\";\nimport { RestWrapper } from \"./restWrapperBase.js\";\n\n/**\n * Maximum number of ops we can fetch at a time. This should be kept at 2k, as\n * server determines whether to try to fallback to long-term storage if the ops range requested is larger than\n * what they have locally available in short-term storage. So if we request 2k ops, they know it is not a\n * specific request and they don't fall to long term storage which takes time.\n * Please coordinate to AFR team if this value need to be changed.\n */\nconst MaxBatchDeltas = 2000;\n\n/**\n * Storage service limited to only being able to fetch documents for a specific document\n */\nexport class DocumentDeltaStorageService implements IDocumentDeltaStorageService {\n\tconstructor(\n\t\tprivate readonly tenantId: string,\n\t\tprivate readonly id: string,\n\t\tprivate readonly deltaStorageService: IDeltaStorageService,\n\t\tprivate readonly documentStorageService: DocumentStorageService,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t) {\n\t\tthis.logtailSha = documentStorageService.logTailSha;\n\t}\n\n\tprivate logtailSha: string | undefined;\n\tprivate snapshotOps: ISequencedDocumentMessage[] | undefined;\n\n\tfetchMessages(\n\t\tfromTotal: number,\n\t\ttoTotal: number | undefined,\n\t\tabortSignal?: AbortSignal,\n\t\tcachedOnly?: boolean,\n\t\tfetchReason?: string,\n\t): IStream<ISequencedDocumentMessage[]> {\n\t\tif (cachedOnly) {\n\t\t\treturn emptyMessageStream;\n\t\t}\n\n\t\tlet opsFromSnapshot = 0;\n\t\tlet opsFromStorage = 0;\n\t\tconst requestCallback = async (\n\t\t\tfrom: number,\n\t\t\tto: number,\n\t\t\ttelemetryProps: ITelemetryBaseProperties,\n\t\t) => {\n\t\t\tthis.snapshotOps = this.logtailSha\n\t\t\t\t? await readAndParse<ISequencedDocumentMessage[]>(\n\t\t\t\t\t\tthis.documentStorageService,\n\t\t\t\t\t\tthis.logtailSha,\n\t\t\t\t\t)\n\t\t\t\t: [];\n\t\t\tthis.logtailSha = undefined;\n\n\t\t\tif (this.snapshotOps !== undefined && this.snapshotOps.length !== 0) {\n\t\t\t\tconst messages = this.snapshotOps.filter(\n\t\t\t\t\t(op) => op.sequenceNumber >= from && op.sequenceNumber < to,\n\t\t\t\t);\n\t\t\t\tvalidateMessages(\"snapshotOps\", messages, from, this.logger, false /* strict */);\n\t\t\t\tif (messages.length > 0 && messages[0].sequenceNumber === from) {\n\t\t\t\t\tthis.snapshotOps = this.snapshotOps.filter((op) => op.sequenceNumber >= to);\n\t\t\t\t\topsFromSnapshot += messages.length;\n\t\t\t\t\treturn { messages, partialResult: true };\n\t\t\t\t}\n\t\t\t\tthis.snapshotOps = undefined;\n\t\t\t}\n\n\t\t\tconst ops = await this.deltaStorageService.get(this.tenantId, this.id, from, to);\n\t\t\tvalidateMessages(\"storage\", ops.messages, from, this.logger, false /* strict */);\n\t\t\topsFromStorage += ops.messages.length;\n\t\t\treturn ops;\n\t\t};\n\n\t\tconst stream = requestOps(\n\t\t\tasync (from: number, to: number, telemetryProps: ITelemetryBaseProperties) => {\n\t\t\t\tconst result = await requestCallback(from, to, telemetryProps);\n\t\t\t\t// Catch all case, just in case\n\t\t\t\tvalidateMessages(\"catch all\", result.messages, from, this.logger);\n\t\t\t\treturn result;\n\t\t\t},\n\t\t\t// Staging: starting with no concurrency, listening for feedback first.\n\t\t\t// In future releases we will switch to actual concurrency\n\t\t\t1, // concurrency\n\t\t\tfromTotal, // inclusive\n\t\t\ttoTotal, // exclusive\n\t\t\tMaxBatchDeltas,\n\t\t\tthis.logger,\n\t\t\tabortSignal,\n\t\t\tfetchReason,\n\t\t);\n\n\t\treturn streamObserver(stream, (result) => {\n\t\t\tif (result.done && opsFromSnapshot + opsFromStorage !== 0) {\n\t\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\t\teventName: \"CacheOpsRetrieved\",\n\t\t\t\t\topsFromSnapshot,\n\t\t\t\t\topsFromStorage,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n}\n\n/**\n * Provides access to the underlying delta storage on the server for routerlicious driver.\n */\nexport class DeltaStorageService implements IDeltaStorageService {\n\tconstructor(\n\t\tprivate readonly url: string,\n\t\tprivate readonly restWrapper: RestWrapper,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprivate readonly getRestWrapper: () => Promise<RestWrapper> = async () => this.restWrapper,\n\t\tprivate readonly getDeltaStorageUrl: () => string = () => this.url,\n\t) {}\n\n\tpublic async get(\n\t\ttenantId: string,\n\t\tid: string,\n\t\tfrom: number, // inclusive\n\t\tto: number, // exclusive\n\t): Promise<IDeltasFetchResult> {\n\t\tconst ops = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"OpsFetch\",\n\t\t\t\tfrom,\n\t\t\t\tto,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\tconst restWrapper = await this.getRestWrapper();\n\t\t\t\tconst url = this.getDeltaStorageUrl();\n\t\t\t\tconst response = await restWrapper.get<ISequencedDocumentMessage[]>(url, {\n\t\t\t\t\tfrom: from - 1,\n\t\t\t\t\tto,\n\t\t\t\t});\n\t\t\t\tevent.end({\n\t\t\t\t\tlength: response.content.length,\n\t\t\t\t\tdetails: JSON.stringify({\n\t\t\t\t\t\tfirstOpSeqNumber: response.content[0]?.sequenceNumber,\n\t\t\t\t\t\tlastOpSeqNumber: response.content[response.content.length - 1]?.sequenceNumber,\n\t\t\t\t\t}),\n\t\t\t\t\t...response.propsToLog,\n\t\t\t\t\t...getW3CData(response.requestUrl, \"xmlhttprequest\"),\n\t\t\t\t});\n\t\t\t\treturn response.content;\n\t\t\t},\n\t\t);\n\n\t\t// It is assumed that server always returns all the ops that it has in the range that was requested.\n\t\t// This may change in the future, if so, we need to adjust and receive \"end\" value from server in such case.\n\t\treturn { messages: ops, partialResult: false };\n\t}\n}\n"]}
|
package/lib/documentService.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { INormalizedWholeSnapshot } from "./contracts.js";
|
|
|
11
11
|
import { ISnapshotTreeVersion } from "./definitions.js";
|
|
12
12
|
import { IRouterliciousDriverPolicies } from "./policies.js";
|
|
13
13
|
import { RouterliciousOrdererRestWrapper, RouterliciousStorageRestWrapper, TokenFetcher } from "./restWrapper.js";
|
|
14
|
+
import type { IGetSessionInfoResponse } from "./sessionInfoManager.js";
|
|
14
15
|
import { ITokenProvider } from "./tokens.js";
|
|
15
16
|
/**
|
|
16
17
|
* The DocumentService manages the Socket.IO connection and manages routing requests to connected
|
|
@@ -32,17 +33,15 @@ export declare class DocumentService extends TypedEventEmitter<IDocumentServiceE
|
|
|
32
33
|
private readonly blobCache;
|
|
33
34
|
private readonly wholeSnapshotTreeCache;
|
|
34
35
|
private readonly shreddedSummaryTreeCache;
|
|
35
|
-
private readonly
|
|
36
|
+
private readonly getSessionInfo;
|
|
36
37
|
private storageRestWrapper;
|
|
37
38
|
private readonly storageTokenFetcher;
|
|
38
39
|
private readonly ordererTokenFetcher;
|
|
39
|
-
private lastDiscoveredAt;
|
|
40
|
-
private discoverP;
|
|
41
40
|
private storageManager;
|
|
42
41
|
private noCacheStorageManager;
|
|
43
42
|
private _policies;
|
|
44
43
|
get resolvedUrl(): IResolvedUrl;
|
|
45
|
-
constructor(_resolvedUrl: IResolvedUrl, ordererUrl: string, deltaStorageUrl: string, deltaStreamUrl: string, storageUrl: string, logger: ITelemetryLoggerExt, tokenProvider: ITokenProvider, tenantId: string, documentId: string, ordererRestWrapper: RouterliciousOrdererRestWrapper, documentStorageServicePolicies: IDocumentStorageServicePolicies, driverPolicies: IRouterliciousDriverPolicies, blobCache: ICache<ArrayBufferLike>, wholeSnapshotTreeCache: ICache<INormalizedWholeSnapshot>, shreddedSummaryTreeCache: ICache<ISnapshotTreeVersion>,
|
|
44
|
+
constructor(_resolvedUrl: IResolvedUrl, ordererUrl: string, deltaStorageUrl: string, deltaStreamUrl: string, storageUrl: string, logger: ITelemetryLoggerExt, tokenProvider: ITokenProvider, tenantId: string, documentId: string, ordererRestWrapper: RouterliciousOrdererRestWrapper, documentStorageServicePolicies: IDocumentStorageServicePolicies, driverPolicies: IRouterliciousDriverPolicies, blobCache: ICache<ArrayBufferLike>, wholeSnapshotTreeCache: ICache<INormalizedWholeSnapshot>, shreddedSummaryTreeCache: ICache<ISnapshotTreeVersion>, getSessionInfo: () => Promise<IGetSessionInfoResponse>, storageRestWrapper: RouterliciousStorageRestWrapper, storageTokenFetcher: TokenFetcher, ordererTokenFetcher: TokenFetcher);
|
|
46
45
|
private documentStorageService;
|
|
47
46
|
get policies(): IDocumentServicePolicies | undefined;
|
|
48
47
|
dispose(): void;
|
|
@@ -65,13 +64,9 @@ export declare class DocumentService extends TypedEventEmitter<IDocumentServiceE
|
|
|
65
64
|
*/
|
|
66
65
|
connectToDeltaStream(client: IClient): Promise<IDocumentDeltaConnection>;
|
|
67
66
|
/**
|
|
68
|
-
*
|
|
67
|
+
* Refresh session info URLs if necessary.
|
|
68
|
+
* @returns boolean - true if session info was refreshed
|
|
69
69
|
*/
|
|
70
|
-
private
|
|
71
|
-
private refreshDiscoveryCore;
|
|
72
|
-
/**
|
|
73
|
-
* Whether enough time has passed since last disconnect to warrant a new discovery call on reconnect.
|
|
74
|
-
*/
|
|
75
|
-
private shouldUpdateDiscoveredSessionInfo;
|
|
70
|
+
private refreshSessionInfoIfNeeded;
|
|
76
71
|
}
|
|
77
72
|
//# sourceMappingURL=documentService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentService.d.ts","sourceRoot":"","sources":["../src/documentService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAC7D,OAAO,EACN,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,4BAA4B,EAC5B,gBAAgB,EAChB,uBAAuB,EACvB,+BAA+B,EAC/B,YAAY,EACZ,MAAM,6CAA6C,CAAC;AAMrD,OAAO,EACN,mBAAmB,EAGnB,MAAM,0CAA0C,CAAC;AAGlD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AASxD,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EACN,+BAA+B,EAC/B,+BAA+B,EAC/B,YAAY,EACZ,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"documentService.d.ts","sourceRoot":"","sources":["../src/documentService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAC7D,OAAO,EACN,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,4BAA4B,EAC5B,gBAAgB,EAChB,uBAAuB,EACvB,+BAA+B,EAC/B,YAAY,EACZ,MAAM,6CAA6C,CAAC;AAMrD,OAAO,EACN,mBAAmB,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qBAAqB,CAAyB;IAEtD,OAAO,CAAC,SAAS,CAAuC;IAExD,IAAW,WAAW,iBAErB;gBAGQ,YAAY,EAAE,YAAY,EACxB,UAAU,EAAE,MAAM,EACpB,eAAe,EAAE,MAAM,EACvB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EACT,MAAM,EAAE,mBAAmB,EAClC,aAAa,EAAE,cAAc,EAC7B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,kBAAkB,EAAE,+BAA+B,EAC5C,8BAA8B,EAAE,+BAA+B,EAC/D,cAAc,EAAE,4BAA4B,EAC5C,SAAS,EAAE,MAAM,CAAC,eAAe,CAAC,EAClC,sBAAsB,EAAE,MAAM,CAAC,wBAAwB,CAAC,EACxD,wBAAwB,EAAE,MAAM,CAAC,oBAAoB,CAAC,EACtD,cAAc,EAAE,MAAM,OAAO,CAAC,uBAAuB,CAAC,EAC/D,kBAAkB,EAAE,+BAA+B,EAC1C,mBAAmB,EAAE,YAAY,EACjC,mBAAmB,EAAE,YAAY;IAKnD,OAAO,CAAC,sBAAsB,CAAqC;IAEnE,IAAW,QAAQ,IAAI,wBAAwB,GAAG,SAAS,CAE1D;IAEM,OAAO;IAEd;;;;OAIG;IACU,gBAAgB,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAmDjE;;;;OAIG;IACU,qBAAqB,IAAI,OAAO,CAAC,4BAA4B,CAAC;IAmC3E;;;;OAIG;IACU,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAwFrF;;;OAGG;YACW,0BAA0B;CAaxC"}
|
package/lib/documentService.js
CHANGED
|
@@ -16,13 +16,6 @@ import { Historian } from "./historian.js";
|
|
|
16
16
|
import { NullBlobStorageService } from "./nullBlobStorageService.js";
|
|
17
17
|
import { pkgVersion as driverVersion } from "./packageVersion.js";
|
|
18
18
|
import { RouterliciousOrdererRestWrapper, RouterliciousStorageRestWrapper, } from "./restWrapper.js";
|
|
19
|
-
/**
|
|
20
|
-
* Amount of time between discoveries within which we don't need to rediscover on re-connect.
|
|
21
|
-
* Currently, R11s defines session length at 10 minutes. To avoid any weird unknown edge-cases though,
|
|
22
|
-
* we set the limit to 5 minutes here.
|
|
23
|
-
* In the future, we likely want to retrieve this information from service's "inactive session" definition.
|
|
24
|
-
*/
|
|
25
|
-
const RediscoverAfterTimeSinceDiscoveryMs = 5 * 60000; // 5 minute
|
|
26
19
|
/**
|
|
27
20
|
* The DocumentService manages the Socket.IO connection and manages routing requests to connected
|
|
28
21
|
* clients.
|
|
@@ -31,7 +24,7 @@ export class DocumentService extends TypedEventEmitter {
|
|
|
31
24
|
get resolvedUrl() {
|
|
32
25
|
return this._resolvedUrl;
|
|
33
26
|
}
|
|
34
|
-
constructor(_resolvedUrl, ordererUrl, deltaStorageUrl, deltaStreamUrl, storageUrl, logger, tokenProvider, tenantId, documentId, ordererRestWrapper, documentStorageServicePolicies, driverPolicies, blobCache, wholeSnapshotTreeCache, shreddedSummaryTreeCache,
|
|
27
|
+
constructor(_resolvedUrl, ordererUrl, deltaStorageUrl, deltaStreamUrl, storageUrl, logger, tokenProvider, tenantId, documentId, ordererRestWrapper, documentStorageServicePolicies, driverPolicies, blobCache, wholeSnapshotTreeCache, shreddedSummaryTreeCache, getSessionInfo, storageRestWrapper, storageTokenFetcher, ordererTokenFetcher) {
|
|
35
28
|
super();
|
|
36
29
|
this._resolvedUrl = _resolvedUrl;
|
|
37
30
|
this.ordererUrl = ordererUrl;
|
|
@@ -48,11 +41,10 @@ export class DocumentService extends TypedEventEmitter {
|
|
|
48
41
|
this.blobCache = blobCache;
|
|
49
42
|
this.wholeSnapshotTreeCache = wholeSnapshotTreeCache;
|
|
50
43
|
this.shreddedSummaryTreeCache = shreddedSummaryTreeCache;
|
|
51
|
-
this.
|
|
44
|
+
this.getSessionInfo = getSessionInfo;
|
|
52
45
|
this.storageRestWrapper = storageRestWrapper;
|
|
53
46
|
this.storageTokenFetcher = storageTokenFetcher;
|
|
54
47
|
this.ordererTokenFetcher = ordererTokenFetcher;
|
|
55
|
-
this.lastDiscoveredAt = Date.now();
|
|
56
48
|
}
|
|
57
49
|
get policies() {
|
|
58
50
|
return this._policies;
|
|
@@ -71,14 +63,9 @@ export class DocumentService extends TypedEventEmitter {
|
|
|
71
63
|
return new NullBlobStorageService();
|
|
72
64
|
}
|
|
73
65
|
const getStorageManager = async (disableCache) => {
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
if (!this.storageManager ||
|
|
79
|
-
!this.noCacheStorageManager ||
|
|
80
|
-
shouldUpdateDiscoveredSessionInfo) {
|
|
81
|
-
if (shouldUpdateDiscoveredSessionInfo) {
|
|
66
|
+
const refreshed = await this.refreshSessionInfoIfNeeded();
|
|
67
|
+
if (!this.storageManager || !this.noCacheStorageManager || refreshed) {
|
|
68
|
+
if (refreshed) {
|
|
82
69
|
const rateLimiter = new RateLimiter(this.driverPolicies.maxConcurrentStorageRequests);
|
|
83
70
|
this.storageRestWrapper = RouterliciousStorageRestWrapper.load(this.tenantId, this.storageTokenFetcher, this.logger, rateLimiter, this.driverPolicies.enableRestLess, this.storageUrl /* baseUrl */);
|
|
84
71
|
}
|
|
@@ -104,9 +91,8 @@ export class DocumentService extends TypedEventEmitter {
|
|
|
104
91
|
await this.connectToStorage();
|
|
105
92
|
assert(!!this.documentStorageService, 0x0b1 /* "Storage service not initialized" */);
|
|
106
93
|
const getRestWrapper = async () => {
|
|
107
|
-
const
|
|
108
|
-
if (
|
|
109
|
-
await this.refreshDiscovery();
|
|
94
|
+
const refreshed = await this.refreshSessionInfoIfNeeded();
|
|
95
|
+
if (refreshed) {
|
|
110
96
|
const rateLimiter = new RateLimiter(this.driverPolicies.maxConcurrentOrdererRequests);
|
|
111
97
|
this.ordererRestWrapper = RouterliciousOrdererRestWrapper.load(this.ordererTokenFetcher, this.logger, rateLimiter, this.driverPolicies.enableRestLess);
|
|
112
98
|
}
|
|
@@ -124,9 +110,7 @@ export class DocumentService extends TypedEventEmitter {
|
|
|
124
110
|
async connectToDeltaStream(client) {
|
|
125
111
|
const connect = async (refreshToken) => {
|
|
126
112
|
let ordererToken = await this.ordererRestWrapper.getToken();
|
|
127
|
-
|
|
128
|
-
await this.refreshDiscovery();
|
|
129
|
-
}
|
|
113
|
+
await this.refreshSessionInfoIfNeeded();
|
|
130
114
|
if (refreshToken) {
|
|
131
115
|
ordererToken = await PerformanceEvent.timedExecAsync(this.logger, {
|
|
132
116
|
eventName: "GetDeltaStreamToken",
|
|
@@ -177,50 +161,21 @@ export class DocumentService extends TypedEventEmitter {
|
|
|
177
161
|
}
|
|
178
162
|
}
|
|
179
163
|
/**
|
|
180
|
-
*
|
|
164
|
+
* Refresh session info URLs if necessary.
|
|
165
|
+
* @returns boolean - true if session info was refreshed
|
|
181
166
|
*/
|
|
182
|
-
async
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}, async () => this.refreshDiscoveryCore());
|
|
167
|
+
async refreshSessionInfoIfNeeded() {
|
|
168
|
+
const response = await this.getSessionInfo();
|
|
169
|
+
if (!response.refreshed) {
|
|
170
|
+
return false;
|
|
187
171
|
}
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
async refreshDiscoveryCore() {
|
|
191
|
-
const fluidResolvedUrl = await this.discoverFluidResolvedUrl();
|
|
172
|
+
const fluidResolvedUrl = response.resolvedUrl;
|
|
192
173
|
this._resolvedUrl = fluidResolvedUrl;
|
|
193
|
-
// TODO why are we non null asserting here?
|
|
194
174
|
this.storageUrl = fluidResolvedUrl.endpoints.storageUrl;
|
|
195
|
-
// TODO why are we non null asserting here?
|
|
196
175
|
this.ordererUrl = fluidResolvedUrl.endpoints.ordererUrl;
|
|
197
|
-
// TODO why are we non null asserting here?
|
|
198
176
|
this.deltaStorageUrl = fluidResolvedUrl.endpoints.deltaStorageUrl;
|
|
199
177
|
this.deltaStreamUrl = fluidResolvedUrl.endpoints.deltaStreamUrl ?? this.ordererUrl;
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Whether enough time has passed since last disconnect to warrant a new discovery call on reconnect.
|
|
203
|
-
*/
|
|
204
|
-
shouldUpdateDiscoveredSessionInfo() {
|
|
205
|
-
if (!this.driverPolicies.enableDiscovery) {
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
const now = Date.now();
|
|
209
|
-
// When connection is disconnected, we cannot know if session has moved or document has been deleted
|
|
210
|
-
// without re-doing discovery on the next attempt to connect.
|
|
211
|
-
// Disconnect event is not so reliable in local testing. To ensure re-discovery when necessary,
|
|
212
|
-
// re-discover if enough time has passed since last discovery.
|
|
213
|
-
const pastLastDiscoveryTimeThreshold = now - this.lastDiscoveredAt > RediscoverAfterTimeSinceDiscoveryMs;
|
|
214
|
-
if (pastLastDiscoveryTimeThreshold) {
|
|
215
|
-
// Reset discover promise and refresh discovery.
|
|
216
|
-
this.lastDiscoveredAt = Date.now();
|
|
217
|
-
this.discoverP = undefined;
|
|
218
|
-
this.refreshDiscovery().catch(() => {
|
|
219
|
-
// Undo discovery time set on failure, so that next check refreshes.
|
|
220
|
-
this.lastDiscoveredAt = 0;
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
return pastLastDiscoveryTimeThreshold;
|
|
178
|
+
return true;
|
|
224
179
|
}
|
|
225
180
|
}
|
|
226
181
|
//# sourceMappingURL=documentService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentService.js","sourceRoot":"","sources":["../src/documentService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAY7D,OAAO,EACN,iBAAiB,EACjB,WAAW,EACX,eAAe,GACf,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAEN,gBAAgB,EAChB,SAAS,GACT,MAAM,0CAA0C,CAAC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AAY,GAAG,gBAAgB,CAAC;QACrC,2CAA2C;QAC3C,IAAI,CAAC,UAAU,GAAG,gBAAgB,CAAC,SAAS,CAAC,UAAW,CAAC;QACzD,2CAA2C;QAC3C,IAAI,CAAC,UAAU,GAAG,gBAAgB,CAAC,SAAS,CAAC,UAAW,CAAC;QACzD,2CAA2C;QAC3C,IAAI,CAAC,eAAe,GAAG,gBAAgB,CAAC,SAAS,CAAC,eAAgB,CAAC;QACnE,IAAI,CAAC,cAAc,GAAG,gBAAgB,CAAC,SAAS,CAAC,cAAc,IAAI,IAAI,CAAC,UAAU,CAAC;IACpF,CAAC;IAED;;OAEG;IACK,iCAAiC;QACxC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,eAAe,EAAE,CAAC;YAC1C,OAAO,KAAK,CAAC;QACd,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,oGAAoG;QACpG,6DAA6D;QAC7D,+FAA+F;QAC/F,8DAA8D;QAC9D,MAAM,8BAA8B,GACnC,GAAG,GAAG,IAAI,CAAC,gBAAgB,GAAG,mCAAmC,CAAC;QACnE,IAAI,8BAA8B,EAAE,CAAC;YACpC,gDAAgD;YAChD,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACnC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;YAC3B,IAAI,CAAC,gBAAgB,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;gBAClC,oEAAoE;gBACpE,IAAI,CAAC,gBAAgB,GAAG,CAAC,CAAC;YAC3B,CAAC,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,8BAA8B,CAAC;IACvC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { IClient } from \"@fluidframework/driver-definitions\";\nimport {\n\tIDocumentServiceEvents,\n\tIDocumentServicePolicies,\n\tIDocumentDeltaConnection,\n\tIDocumentDeltaStorageService,\n\tIDocumentService,\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tIResolvedUrl,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tNetworkErrorBasic,\n\tRateLimiter,\n\tcanRetryOnError,\n} from \"@fluidframework/driver-utils/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tPerformanceEvent,\n\twrapError,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport io from \"socket.io-client\";\n\nimport { ICache } from \"./cache.js\";\nimport { INormalizedWholeSnapshot } from \"./contracts.js\";\nimport { ISnapshotTreeVersion } from \"./definitions.js\";\nimport { DeltaStorageService, DocumentDeltaStorageService } from \"./deltaStorageService.js\";\nimport { R11sDocumentDeltaConnection } from \"./documentDeltaConnection.js\";\nimport { DocumentStorageService } from \"./documentStorageService.js\";\nimport { RouterliciousErrorTypes } from \"./errorUtils.js\";\nimport { GitManager } from \"./gitManager.js\";\nimport { Historian } from \"./historian.js\";\nimport { NullBlobStorageService } from \"./nullBlobStorageService.js\";\nimport { pkgVersion as driverVersion } from \"./packageVersion.js\";\nimport { IRouterliciousDriverPolicies } from \"./policies.js\";\nimport {\n\tRouterliciousOrdererRestWrapper,\n\tRouterliciousStorageRestWrapper,\n\tTokenFetcher,\n} from \"./restWrapper.js\";\nimport { RestWrapper } from \"./restWrapperBase.js\";\nimport { ITokenProvider } from \"./tokens.js\";\n\n/**\n * Amount of time between discoveries within which we don't need to rediscover on re-connect.\n * Currently, R11s defines session length at 10 minutes. To avoid any weird unknown edge-cases though,\n * we set the limit to 5 minutes here.\n * In the future, we likely want to retrieve this information from service's \"inactive session\" definition.\n */\nconst RediscoverAfterTimeSinceDiscoveryMs = 5 * 60000; // 5 minute\n\n/**\n * The DocumentService manages the Socket.IO connection and manages routing requests to connected\n * clients.\n */\nexport class DocumentService\n\textends TypedEventEmitter<IDocumentServiceEvents>\n\t// eslint-disable-next-line import/namespace\n\timplements IDocumentService\n{\n\tprivate lastDiscoveredAt: number = Date.now();\n\tprivate discoverP: Promise<void> | undefined;\n\n\tprivate storageManager: GitManager | undefined;\n\tprivate noCacheStorageManager: GitManager | undefined;\n\n\tprivate _policies: IDocumentServicePolicies | undefined;\n\n\tpublic get resolvedUrl() {\n\t\treturn this._resolvedUrl;\n\t}\n\n\tconstructor(\n\t\tprivate _resolvedUrl: IResolvedUrl,\n\t\tprotected ordererUrl: string,\n\t\tprivate deltaStorageUrl: string,\n\t\tprivate deltaStreamUrl: string,\n\t\tprivate storageUrl: string,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprotected tokenProvider: ITokenProvider,\n\t\tprotected tenantId: string,\n\t\tprotected documentId: string,\n\t\tprotected ordererRestWrapper: RouterliciousOrdererRestWrapper,\n\t\tprivate readonly documentStorageServicePolicies: IDocumentStorageServicePolicies,\n\t\tprivate readonly driverPolicies: IRouterliciousDriverPolicies,\n\t\tprivate readonly blobCache: ICache<ArrayBufferLike>,\n\t\tprivate readonly wholeSnapshotTreeCache: ICache<INormalizedWholeSnapshot>,\n\t\tprivate readonly shreddedSummaryTreeCache: ICache<ISnapshotTreeVersion>,\n\t\tprivate readonly discoverFluidResolvedUrl: () => Promise<IResolvedUrl>,\n\t\tprivate storageRestWrapper: RouterliciousStorageRestWrapper,\n\t\tprivate readonly storageTokenFetcher: TokenFetcher,\n\t\tprivate readonly ordererTokenFetcher: TokenFetcher,\n\t) {\n\t\tsuper();\n\t}\n\n\tprivate documentStorageService: DocumentStorageService | undefined;\n\n\tpublic get policies(): IDocumentServicePolicies | undefined {\n\t\treturn this._policies;\n\t}\n\n\tpublic dispose() {}\n\n\t/**\n\t * Connects to a storage endpoint for snapshot service.\n\t *\n\t * @returns returns the document storage service for routerlicious driver.\n\t */\n\tpublic async connectToStorage(): Promise<IDocumentStorageService> {\n\t\tif (this.documentStorageService !== undefined) {\n\t\t\treturn this.documentStorageService;\n\t\t}\n\n\t\tif (this.storageUrl === undefined) {\n\t\t\treturn new NullBlobStorageService();\n\t\t}\n\n\t\tconst getStorageManager = async (disableCache?: boolean): Promise<GitManager> => {\n\t\t\tconst shouldUpdateDiscoveredSessionInfo = this.shouldUpdateDiscoveredSessionInfo();\n\t\t\tif (shouldUpdateDiscoveredSessionInfo) {\n\t\t\t\tawait this.refreshDiscovery();\n\t\t\t}\n\t\t\tif (\n\t\t\t\t!this.storageManager ||\n\t\t\t\t!this.noCacheStorageManager ||\n\t\t\t\tshouldUpdateDiscoveredSessionInfo\n\t\t\t) {\n\t\t\t\tif (shouldUpdateDiscoveredSessionInfo) {\n\t\t\t\t\tconst rateLimiter = new RateLimiter(\n\t\t\t\t\t\tthis.driverPolicies.maxConcurrentStorageRequests,\n\t\t\t\t\t);\n\t\t\t\t\tthis.storageRestWrapper = RouterliciousStorageRestWrapper.load(\n\t\t\t\t\t\tthis.tenantId,\n\t\t\t\t\t\tthis.storageTokenFetcher,\n\t\t\t\t\t\tthis.logger,\n\t\t\t\t\t\trateLimiter,\n\t\t\t\t\t\tthis.driverPolicies.enableRestLess,\n\t\t\t\t\t\tthis.storageUrl /* baseUrl */,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst historian = new Historian(true, false, this.storageRestWrapper);\n\t\t\t\tthis.storageManager = new GitManager(historian);\n\t\t\t\tconst noCacheHistorian = new Historian(true, true, this.storageRestWrapper);\n\t\t\t\tthis.noCacheStorageManager = new GitManager(noCacheHistorian);\n\t\t\t}\n\n\t\t\treturn disableCache ? this.noCacheStorageManager : this.storageManager;\n\t\t};\n\t\t// Initialize storageManager and noCacheStorageManager\n\t\tconst storageManager = await getStorageManager();\n\t\tconst noCacheStorageManager = await getStorageManager(true);\n\t\tthis.documentStorageService = new DocumentStorageService(\n\t\t\tthis.documentId,\n\t\t\tstorageManager,\n\t\t\tthis.logger,\n\t\t\tthis.documentStorageServicePolicies,\n\t\t\tthis.driverPolicies,\n\t\t\tthis.blobCache,\n\t\t\tthis.wholeSnapshotTreeCache,\n\t\t\tthis.shreddedSummaryTreeCache,\n\t\t\tnoCacheStorageManager,\n\t\t\tgetStorageManager,\n\t\t);\n\t\treturn this.documentStorageService;\n\t}\n\n\t/**\n\t * Connects to a delta storage endpoint for getting ops between a range.\n\t *\n\t * @returns returns the document delta storage service for routerlicious driver.\n\t */\n\tpublic async connectToDeltaStorage(): Promise<IDocumentDeltaStorageService> {\n\t\tawait this.connectToStorage();\n\t\tassert(!!this.documentStorageService, 0x0b1 /* \"Storage service not initialized\" */);\n\n\t\tconst getRestWrapper = async (): Promise<RestWrapper> => {\n\t\t\tconst shouldUpdateDiscoveredSessionInfo = this.shouldUpdateDiscoveredSessionInfo();\n\n\t\t\tif (shouldUpdateDiscoveredSessionInfo) {\n\t\t\t\tawait this.refreshDiscovery();\n\t\t\t\tconst rateLimiter = new RateLimiter(this.driverPolicies.maxConcurrentOrdererRequests);\n\t\t\t\tthis.ordererRestWrapper = RouterliciousOrdererRestWrapper.load(\n\t\t\t\t\tthis.ordererTokenFetcher,\n\t\t\t\t\tthis.logger,\n\t\t\t\t\trateLimiter,\n\t\t\t\t\tthis.driverPolicies.enableRestLess,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn this.ordererRestWrapper;\n\t\t};\n\t\tconst restWrapper = await getRestWrapper();\n\t\tconst deltaStorageService = new DeltaStorageService(\n\t\t\tthis.deltaStorageUrl,\n\t\t\trestWrapper,\n\t\t\tthis.logger,\n\t\t\tgetRestWrapper,\n\t\t\t() => this.deltaStorageUrl,\n\t\t);\n\t\treturn new DocumentDeltaStorageService(\n\t\t\tthis.tenantId,\n\t\t\tthis.documentId,\n\t\t\tdeltaStorageService,\n\t\t\tthis.documentStorageService,\n\t\t\tthis.logger,\n\t\t);\n\t}\n\n\t/**\n\t * Connects to a delta stream endpoint for emitting ops.\n\t *\n\t * @returns returns the document delta stream service for routerlicious driver.\n\t */\n\tpublic async connectToDeltaStream(client: IClient): Promise<IDocumentDeltaConnection> {\n\t\tconst connect = async (refreshToken?: boolean) => {\n\t\t\tlet ordererToken = await this.ordererRestWrapper.getToken();\n\t\t\tif (this.shouldUpdateDiscoveredSessionInfo()) {\n\t\t\t\tawait this.refreshDiscovery();\n\t\t\t}\n\n\t\t\tif (refreshToken) {\n\t\t\t\tordererToken = await PerformanceEvent.timedExecAsync(\n\t\t\t\t\tthis.logger,\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: \"GetDeltaStreamToken\",\n\t\t\t\t\t\tdocId: this.documentId,\n\t\t\t\t\t\tdetails: JSON.stringify({\n\t\t\t\t\t\t\trefreshToken,\n\t\t\t\t\t\t}),\n\t\t\t\t\t},\n\t\t\t\t\tasync () =>\n\t\t\t\t\t\tthis.tokenProvider\n\t\t\t\t\t\t\t.fetchOrdererToken(this.tenantId, this.documentId, refreshToken)\n\t\t\t\t\t\t\t.then(\n\t\t\t\t\t\t\t\t(newOrdererToken) => {\n\t\t\t\t\t\t\t\t\tthis.ordererRestWrapper.setToken(newOrdererToken);\n\t\t\t\t\t\t\t\t\treturn newOrdererToken;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t(error) => {\n\t\t\t\t\t\t\t\t\tconst tokenError = wrapError(\n\t\t\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t\t\t\t(errorMessage) =>\n\t\t\t\t\t\t\t\t\t\t\tnew NetworkErrorBasic(\n\t\t\t\t\t\t\t\t\t\t\t\t`The Host-provided token fetcher threw an error`,\n\t\t\t\t\t\t\t\t\t\t\t\tRouterliciousErrorTypes.fetchTokenError,\n\t\t\t\t\t\t\t\t\t\t\t\tcanRetryOnError(error),\n\t\t\t\t\t\t\t\t\t\t\t\t{ errorMessage, driverVersion },\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tthrow tokenError;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\t\tthis.logger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"ConnectToDeltaStream\",\n\t\t\t\t\tdocId: this.documentId,\n\t\t\t\t},\n\t\t\t\tasync () => {\n\t\t\t\t\treturn R11sDocumentDeltaConnection.create(\n\t\t\t\t\t\tthis.tenantId,\n\t\t\t\t\t\tthis.documentId,\n\t\t\t\t\t\tordererToken.jwt,\n\t\t\t\t\t\tio,\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tthis.deltaStreamUrl,\n\t\t\t\t\t\tthis.logger,\n\t\t\t\t\t\tundefined /* timeoutMs */,\n\t\t\t\t\t\tthis.driverPolicies.enableLongPollingDowngrade,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t);\n\t\t};\n\n\t\t// Attempt to establish connection.\n\t\t// Retry with new token on authorization error; otherwise, allow container layer to handle.\n\t\ttry {\n\t\t\tconst connection = await connect();\n\t\t\t// Enable single-commit summaries via driver policy based on the enable_single_commit_summary flag which maybe provided by the service during connection.\n\t\t\t// summarizeProtocolTree flag is used by the loader layer to attach protocol tree along with the summary required in the single-commit summaries.\n\t\t\tconst shouldSummarizeProtocolTree = (connection as R11sDocumentDeltaConnection).details\n\t\t\t\t?.supportedFeatures?.enable_single_commit_summary\n\t\t\t\t? true\n\t\t\t\t: false;\n\t\t\tthis._policies = {\n\t\t\t\t...this._policies,\n\t\t\t\tsummarizeProtocolTree: shouldSummarizeProtocolTree,\n\t\t\t};\n\n\t\t\treturn connection;\n\t\t} catch (error: any) {\n\t\t\tif (error?.statusCode === 401) {\n\t\t\t\t// Fetch new token and retry once,\n\t\t\t\t// otherwise 401 will be bubbled up as non-retriable AuthorizationError.\n\t\t\t\treturn connect(true /* refreshToken */);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Re-discover session URLs if necessary.\n\t */\n\tprivate async refreshDiscovery(): Promise<void> {\n\t\tif (!this.discoverP) {\n\t\t\tthis.discoverP = PerformanceEvent.timedExecAsync(\n\t\t\t\tthis.logger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"RefreshDiscovery\",\n\t\t\t\t},\n\t\t\t\tasync () => this.refreshDiscoveryCore(),\n\t\t\t);\n\t\t}\n\t\treturn this.discoverP;\n\t}\n\n\tprivate async refreshDiscoveryCore(): Promise<void> {\n\t\tconst fluidResolvedUrl = await this.discoverFluidResolvedUrl();\n\t\tthis._resolvedUrl = fluidResolvedUrl;\n\t\t// TODO why are we non null asserting here?\n\t\tthis.storageUrl = fluidResolvedUrl.endpoints.storageUrl!;\n\t\t// TODO why are we non null asserting here?\n\t\tthis.ordererUrl = fluidResolvedUrl.endpoints.ordererUrl!;\n\t\t// TODO why are we non null asserting here?\n\t\tthis.deltaStorageUrl = fluidResolvedUrl.endpoints.deltaStorageUrl!;\n\t\tthis.deltaStreamUrl = fluidResolvedUrl.endpoints.deltaStreamUrl ?? this.ordererUrl;\n\t}\n\n\t/**\n\t * Whether enough time has passed since last disconnect to warrant a new discovery call on reconnect.\n\t */\n\tprivate shouldUpdateDiscoveredSessionInfo(): boolean {\n\t\tif (!this.driverPolicies.enableDiscovery) {\n\t\t\treturn false;\n\t\t}\n\t\tconst now = Date.now();\n\t\t// When connection is disconnected, we cannot know if session has moved or document has been deleted\n\t\t// without re-doing discovery on the next attempt to connect.\n\t\t// Disconnect event is not so reliable in local testing. To ensure re-discovery when necessary,\n\t\t// re-discover if enough time has passed since last discovery.\n\t\tconst pastLastDiscoveryTimeThreshold =\n\t\t\tnow - this.lastDiscoveredAt > RediscoverAfterTimeSinceDiscoveryMs;\n\t\tif (pastLastDiscoveryTimeThreshold) {\n\t\t\t// Reset discover promise and refresh discovery.\n\t\t\tthis.lastDiscoveredAt = Date.now();\n\t\t\tthis.discoverP = undefined;\n\t\t\tthis.refreshDiscovery().catch(() => {\n\t\t\t\t// Undo discovery time set on failure, so that next check refreshes.\n\t\t\t\tthis.lastDiscoveredAt = 0;\n\t\t\t});\n\t\t}\n\t\treturn pastLastDiscoveryTimeThreshold;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"documentService.js","sourceRoot":"","sources":["../src/documentService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAY7D,OAAO,EACN,iBAAiB,EACjB,WAAW,EACX,eAAe,GACf,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAEN,gBAAgB,EAChB,SAAS,GACT,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAKlC,OAAO,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAC5F,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAElE,OAAO,EACN,+BAA+B,EAC/B,+BAA+B,GAE/B,MAAM,kBAAkB,CAAC;AAK1B;;;GAGG;AACH,MAAM,OAAO,eACZ,SAAQ,iBAAyC;IASjD,IAAW,WAAW;QACrB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IAED,YACS,YAA0B,EACxB,UAAkB,EACpB,eAAuB,EACvB,cAAsB,EACtB,UAAkB,EACT,MAA2B,EAClC,aAA6B,EAC7B,QAAgB,EAChB,UAAkB,EAClB,kBAAmD,EAC5C,8BAA+D,EAC/D,c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AC,SAAS,CAAC,UAAU,CAAC;QACxD,IAAI,CAAC,eAAe,GAAG,gBAAgB,CAAC,SAAS,CAAC,eAAe,CAAC;QAClE,IAAI,CAAC,cAAc,GAAG,gBAAgB,CAAC,SAAS,CAAC,cAAc,IAAI,IAAI,CAAC,UAAU,CAAC;QACnF,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { IClient } from \"@fluidframework/driver-definitions\";\nimport {\n\tIDocumentServiceEvents,\n\tIDocumentServicePolicies,\n\tIDocumentDeltaConnection,\n\tIDocumentDeltaStorageService,\n\tIDocumentService,\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tIResolvedUrl,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tNetworkErrorBasic,\n\tRateLimiter,\n\tcanRetryOnError,\n} from \"@fluidframework/driver-utils/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tPerformanceEvent,\n\twrapError,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport io from \"socket.io-client\";\n\nimport { ICache } from \"./cache.js\";\nimport { INormalizedWholeSnapshot } from \"./contracts.js\";\nimport { ISnapshotTreeVersion } from \"./definitions.js\";\nimport { DeltaStorageService, DocumentDeltaStorageService } from \"./deltaStorageService.js\";\nimport { R11sDocumentDeltaConnection } from \"./documentDeltaConnection.js\";\nimport { DocumentStorageService } from \"./documentStorageService.js\";\nimport { RouterliciousErrorTypes } from \"./errorUtils.js\";\nimport { GitManager } from \"./gitManager.js\";\nimport { Historian } from \"./historian.js\";\nimport { NullBlobStorageService } from \"./nullBlobStorageService.js\";\nimport { pkgVersion as driverVersion } from \"./packageVersion.js\";\nimport { IRouterliciousDriverPolicies } from \"./policies.js\";\nimport {\n\tRouterliciousOrdererRestWrapper,\n\tRouterliciousStorageRestWrapper,\n\tTokenFetcher,\n} from \"./restWrapper.js\";\nimport { RestWrapper } from \"./restWrapperBase.js\";\nimport type { IGetSessionInfoResponse } from \"./sessionInfoManager.js\";\nimport { ITokenProvider } from \"./tokens.js\";\n\n/**\n * The DocumentService manages the Socket.IO connection and manages routing requests to connected\n * clients.\n */\nexport class DocumentService\n\textends TypedEventEmitter<IDocumentServiceEvents>\n\t// eslint-disable-next-line import/namespace\n\timplements IDocumentService\n{\n\tprivate storageManager: GitManager | undefined;\n\tprivate noCacheStorageManager: GitManager | undefined;\n\n\tprivate _policies: IDocumentServicePolicies | undefined;\n\n\tpublic get resolvedUrl() {\n\t\treturn this._resolvedUrl;\n\t}\n\n\tconstructor(\n\t\tprivate _resolvedUrl: IResolvedUrl,\n\t\tprotected ordererUrl: string,\n\t\tprivate deltaStorageUrl: string,\n\t\tprivate deltaStreamUrl: string,\n\t\tprivate storageUrl: string,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprotected tokenProvider: ITokenProvider,\n\t\tprotected tenantId: string,\n\t\tprotected documentId: string,\n\t\tprotected ordererRestWrapper: RouterliciousOrdererRestWrapper,\n\t\tprivate readonly documentStorageServicePolicies: IDocumentStorageServicePolicies,\n\t\tprivate readonly driverPolicies: IRouterliciousDriverPolicies,\n\t\tprivate readonly blobCache: ICache<ArrayBufferLike>,\n\t\tprivate readonly wholeSnapshotTreeCache: ICache<INormalizedWholeSnapshot>,\n\t\tprivate readonly shreddedSummaryTreeCache: ICache<ISnapshotTreeVersion>,\n\t\tprivate readonly getSessionInfo: () => Promise<IGetSessionInfoResponse>,\n\t\tprivate storageRestWrapper: RouterliciousStorageRestWrapper,\n\t\tprivate readonly storageTokenFetcher: TokenFetcher,\n\t\tprivate readonly ordererTokenFetcher: TokenFetcher,\n\t) {\n\t\tsuper();\n\t}\n\n\tprivate documentStorageService: DocumentStorageService | undefined;\n\n\tpublic get policies(): IDocumentServicePolicies | undefined {\n\t\treturn this._policies;\n\t}\n\n\tpublic dispose() {}\n\n\t/**\n\t * Connects to a storage endpoint for snapshot service.\n\t *\n\t * @returns returns the document storage service for routerlicious driver.\n\t */\n\tpublic async connectToStorage(): Promise<IDocumentStorageService> {\n\t\tif (this.documentStorageService !== undefined) {\n\t\t\treturn this.documentStorageService;\n\t\t}\n\n\t\tif (this.storageUrl === undefined) {\n\t\t\treturn new NullBlobStorageService();\n\t\t}\n\n\t\tconst getStorageManager = async (disableCache?: boolean): Promise<GitManager> => {\n\t\t\tconst refreshed = await this.refreshSessionInfoIfNeeded();\n\t\t\tif (!this.storageManager || !this.noCacheStorageManager || refreshed) {\n\t\t\t\tif (refreshed) {\n\t\t\t\t\tconst rateLimiter = new RateLimiter(\n\t\t\t\t\t\tthis.driverPolicies.maxConcurrentStorageRequests,\n\t\t\t\t\t);\n\t\t\t\t\tthis.storageRestWrapper = RouterliciousStorageRestWrapper.load(\n\t\t\t\t\t\tthis.tenantId,\n\t\t\t\t\t\tthis.storageTokenFetcher,\n\t\t\t\t\t\tthis.logger,\n\t\t\t\t\t\trateLimiter,\n\t\t\t\t\t\tthis.driverPolicies.enableRestLess,\n\t\t\t\t\t\tthis.storageUrl /* baseUrl */,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst historian = new Historian(true, false, this.storageRestWrapper);\n\t\t\t\tthis.storageManager = new GitManager(historian);\n\t\t\t\tconst noCacheHistorian = new Historian(true, true, this.storageRestWrapper);\n\t\t\t\tthis.noCacheStorageManager = new GitManager(noCacheHistorian);\n\t\t\t}\n\n\t\t\treturn disableCache ? this.noCacheStorageManager : this.storageManager;\n\t\t};\n\t\t// Initialize storageManager and noCacheStorageManager\n\t\tconst storageManager = await getStorageManager();\n\t\tconst noCacheStorageManager = await getStorageManager(true);\n\t\tthis.documentStorageService = new DocumentStorageService(\n\t\t\tthis.documentId,\n\t\t\tstorageManager,\n\t\t\tthis.logger,\n\t\t\tthis.documentStorageServicePolicies,\n\t\t\tthis.driverPolicies,\n\t\t\tthis.blobCache,\n\t\t\tthis.wholeSnapshotTreeCache,\n\t\t\tthis.shreddedSummaryTreeCache,\n\t\t\tnoCacheStorageManager,\n\t\t\tgetStorageManager,\n\t\t);\n\t\treturn this.documentStorageService;\n\t}\n\n\t/**\n\t * Connects to a delta storage endpoint for getting ops between a range.\n\t *\n\t * @returns returns the document delta storage service for routerlicious driver.\n\t */\n\tpublic async connectToDeltaStorage(): Promise<IDocumentDeltaStorageService> {\n\t\tawait this.connectToStorage();\n\t\tassert(!!this.documentStorageService, 0x0b1 /* \"Storage service not initialized\" */);\n\n\t\tconst getRestWrapper = async (): Promise<RestWrapper> => {\n\t\t\tconst refreshed = await this.refreshSessionInfoIfNeeded();\n\n\t\t\tif (refreshed) {\n\t\t\t\tconst rateLimiter = new RateLimiter(this.driverPolicies.maxConcurrentOrdererRequests);\n\t\t\t\tthis.ordererRestWrapper = RouterliciousOrdererRestWrapper.load(\n\t\t\t\t\tthis.ordererTokenFetcher,\n\t\t\t\t\tthis.logger,\n\t\t\t\t\trateLimiter,\n\t\t\t\t\tthis.driverPolicies.enableRestLess,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn this.ordererRestWrapper;\n\t\t};\n\t\tconst restWrapper = await getRestWrapper();\n\t\tconst deltaStorageService = new DeltaStorageService(\n\t\t\tthis.deltaStorageUrl,\n\t\t\trestWrapper,\n\t\t\tthis.logger,\n\t\t\tgetRestWrapper,\n\t\t\t() => this.deltaStorageUrl,\n\t\t);\n\t\treturn new DocumentDeltaStorageService(\n\t\t\tthis.tenantId,\n\t\t\tthis.documentId,\n\t\t\tdeltaStorageService,\n\t\t\tthis.documentStorageService,\n\t\t\tthis.logger,\n\t\t);\n\t}\n\n\t/**\n\t * Connects to a delta stream endpoint for emitting ops.\n\t *\n\t * @returns returns the document delta stream service for routerlicious driver.\n\t */\n\tpublic async connectToDeltaStream(client: IClient): Promise<IDocumentDeltaConnection> {\n\t\tconst connect = async (refreshToken?: boolean) => {\n\t\t\tlet ordererToken = await this.ordererRestWrapper.getToken();\n\t\t\tawait this.refreshSessionInfoIfNeeded();\n\n\t\t\tif (refreshToken) {\n\t\t\t\tordererToken = await PerformanceEvent.timedExecAsync(\n\t\t\t\t\tthis.logger,\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: \"GetDeltaStreamToken\",\n\t\t\t\t\t\tdocId: this.documentId,\n\t\t\t\t\t\tdetails: JSON.stringify({\n\t\t\t\t\t\t\trefreshToken,\n\t\t\t\t\t\t}),\n\t\t\t\t\t},\n\t\t\t\t\tasync () =>\n\t\t\t\t\t\tthis.tokenProvider\n\t\t\t\t\t\t\t.fetchOrdererToken(this.tenantId, this.documentId, refreshToken)\n\t\t\t\t\t\t\t.then(\n\t\t\t\t\t\t\t\t(newOrdererToken) => {\n\t\t\t\t\t\t\t\t\tthis.ordererRestWrapper.setToken(newOrdererToken);\n\t\t\t\t\t\t\t\t\treturn newOrdererToken;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t(error) => {\n\t\t\t\t\t\t\t\t\tconst tokenError = wrapError(\n\t\t\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t\t\t\t(errorMessage) =>\n\t\t\t\t\t\t\t\t\t\t\tnew NetworkErrorBasic(\n\t\t\t\t\t\t\t\t\t\t\t\t`The Host-provided token fetcher threw an error`,\n\t\t\t\t\t\t\t\t\t\t\t\tRouterliciousErrorTypes.fetchTokenError,\n\t\t\t\t\t\t\t\t\t\t\t\tcanRetryOnError(error),\n\t\t\t\t\t\t\t\t\t\t\t\t{ errorMessage, driverVersion },\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tthrow tokenError;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\t\tthis.logger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"ConnectToDeltaStream\",\n\t\t\t\t\tdocId: this.documentId,\n\t\t\t\t},\n\t\t\t\tasync () => {\n\t\t\t\t\treturn R11sDocumentDeltaConnection.create(\n\t\t\t\t\t\tthis.tenantId,\n\t\t\t\t\t\tthis.documentId,\n\t\t\t\t\t\tordererToken.jwt,\n\t\t\t\t\t\tio,\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tthis.deltaStreamUrl,\n\t\t\t\t\t\tthis.logger,\n\t\t\t\t\t\tundefined /* timeoutMs */,\n\t\t\t\t\t\tthis.driverPolicies.enableLongPollingDowngrade,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t);\n\t\t};\n\n\t\t// Attempt to establish connection.\n\t\t// Retry with new token on authorization error; otherwise, allow container layer to handle.\n\t\ttry {\n\t\t\tconst connection = await connect();\n\t\t\t// Enable single-commit summaries via driver policy based on the enable_single_commit_summary flag which maybe provided by the service during connection.\n\t\t\t// summarizeProtocolTree flag is used by the loader layer to attach protocol tree along with the summary required in the single-commit summaries.\n\t\t\tconst shouldSummarizeProtocolTree = (connection as R11sDocumentDeltaConnection).details\n\t\t\t\t?.supportedFeatures?.enable_single_commit_summary\n\t\t\t\t? true\n\t\t\t\t: false;\n\t\t\tthis._policies = {\n\t\t\t\t...this._policies,\n\t\t\t\tsummarizeProtocolTree: shouldSummarizeProtocolTree,\n\t\t\t};\n\n\t\t\treturn connection;\n\t\t} catch (error: any) {\n\t\t\tif (error?.statusCode === 401) {\n\t\t\t\t// Fetch new token and retry once,\n\t\t\t\t// otherwise 401 will be bubbled up as non-retriable AuthorizationError.\n\t\t\t\treturn connect(true /* refreshToken */);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Refresh session info URLs if necessary.\n\t * @returns boolean - true if session info was refreshed\n\t */\n\tprivate async refreshSessionInfoIfNeeded(): Promise<boolean> {\n\t\tconst response = await this.getSessionInfo();\n\t\tif (!response.refreshed) {\n\t\t\treturn false;\n\t\t}\n\t\tconst fluidResolvedUrl = response.resolvedUrl;\n\t\tthis._resolvedUrl = fluidResolvedUrl;\n\t\tthis.storageUrl = fluidResolvedUrl.endpoints.storageUrl;\n\t\tthis.ordererUrl = fluidResolvedUrl.endpoints.ordererUrl;\n\t\tthis.deltaStorageUrl = fluidResolvedUrl.endpoints.deltaStorageUrl;\n\t\tthis.deltaStreamUrl = fluidResolvedUrl.endpoints.deltaStreamUrl ?? this.ordererUrl;\n\t\treturn true;\n\t}\n}\n"]}
|
|
@@ -19,6 +19,7 @@ export declare class RouterliciousDocumentServiceFactory implements IDocumentSer
|
|
|
19
19
|
private readonly blobCache;
|
|
20
20
|
private readonly wholeSnapshotTreeCache;
|
|
21
21
|
private readonly shreddedSummaryTreeCache;
|
|
22
|
+
private readonly sessionInfoManager;
|
|
22
23
|
constructor(tokenProvider: ITokenProvider, driverPolicies?: Partial<IRouterliciousDriverPolicies>);
|
|
23
24
|
/**
|
|
24
25
|
* {@inheritDoc @fluidframework/driver-definitions#IDocumentServiceFactory.createContainer}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentServiceFactory.d.ts","sourceRoot":"","sources":["../src/documentServiceFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"documentServiceFactory.d.ts","sourceRoot":"","sources":["../src/documentServiceFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAEN,gBAAgB,EAChB,uBAAuB,EAEvB,YAAY,EAEZ,MAAM,6CAA6C,CAAC;AAOrD,OAAO,EACN,QAAQ,EAER,MAAM,wCAAwC,CAAC;AAQhD,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAS7D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC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