@fluidframework/routerlicious-driver 2.0.0-internal.4.3.0 → 2.0.0-internal.5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/deltaStorageService.d.ts +3 -3
- package/dist/deltaStorageService.d.ts.map +1 -1
- package/dist/deltaStorageService.js.map +1 -1
- package/dist/documentDeltaConnection.d.ts +2 -2
- package/dist/documentDeltaConnection.d.ts.map +1 -1
- package/dist/documentDeltaConnection.js.map +1 -1
- package/dist/documentService.d.ts +7 -4
- package/dist/documentService.d.ts.map +1 -1
- package/dist/documentService.js +11 -6
- package/dist/documentService.js.map +1 -1
- package/dist/documentServiceFactory.d.ts.map +1 -1
- package/dist/documentServiceFactory.js +9 -5
- package/dist/documentServiceFactory.js.map +1 -1
- package/dist/documentStorageService.d.ts +2 -2
- package/dist/documentStorageService.d.ts.map +1 -1
- package/dist/documentStorageService.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/restWrapper.d.ts +9 -5
- package/dist/restWrapper.d.ts.map +1 -1
- package/dist/restWrapper.js +42 -31
- package/dist/restWrapper.js.map +1 -1
- package/dist/retriableGitManager.d.ts +2 -2
- package/dist/retriableGitManager.d.ts.map +1 -1
- package/dist/retriableGitManager.js.map +1 -1
- package/dist/shreddedSummaryDocumentStorageService.d.ts +3 -3
- package/dist/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
- package/dist/shreddedSummaryDocumentStorageService.js +1 -1
- package/dist/shreddedSummaryDocumentStorageService.js.map +1 -1
- package/dist/urlUtils.d.ts +2 -2
- package/dist/urlUtils.d.ts.map +1 -1
- package/dist/urlUtils.js.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.d.ts +4 -4
- package/dist/wholeSummaryDocumentStorageService.d.ts.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.js +10 -6
- package/dist/wholeSummaryDocumentStorageService.js.map +1 -1
- package/lib/deltaStorageService.d.ts +3 -3
- package/lib/deltaStorageService.d.ts.map +1 -1
- package/lib/deltaStorageService.js +1 -1
- package/lib/deltaStorageService.js.map +1 -1
- package/lib/documentDeltaConnection.d.ts +2 -2
- package/lib/documentDeltaConnection.d.ts.map +1 -1
- package/lib/documentDeltaConnection.js.map +1 -1
- package/lib/documentService.d.ts +7 -4
- package/lib/documentService.d.ts.map +1 -1
- package/lib/documentService.js +12 -7
- package/lib/documentService.js.map +1 -1
- package/lib/documentServiceFactory.d.ts.map +1 -1
- package/lib/documentServiceFactory.js +11 -7
- package/lib/documentServiceFactory.js.map +1 -1
- package/lib/documentStorageService.d.ts +2 -2
- package/lib/documentStorageService.d.ts.map +1 -1
- package/lib/documentStorageService.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/restWrapper.d.ts +9 -5
- package/lib/restWrapper.d.ts.map +1 -1
- package/lib/restWrapper.js +39 -30
- package/lib/restWrapper.js.map +1 -1
- package/lib/retriableGitManager.d.ts +2 -2
- package/lib/retriableGitManager.d.ts.map +1 -1
- package/lib/retriableGitManager.js.map +1 -1
- package/lib/shreddedSummaryDocumentStorageService.d.ts +3 -3
- package/lib/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
- package/lib/shreddedSummaryDocumentStorageService.js +1 -1
- package/lib/shreddedSummaryDocumentStorageService.js.map +1 -1
- package/lib/urlUtils.d.ts +2 -2
- package/lib/urlUtils.d.ts.map +1 -1
- package/lib/urlUtils.js.map +1 -1
- package/lib/wholeSummaryDocumentStorageService.d.ts +4 -4
- package/lib/wholeSummaryDocumentStorageService.d.ts.map +1 -1
- package/lib/wholeSummaryDocumentStorageService.js +10 -6
- package/lib/wholeSummaryDocumentStorageService.js.map +1 -1
- package/package.json +7 -7
- package/src/deltaStorageService.ts +7 -4
- package/src/documentDeltaConnection.ts +2 -2
- package/src/documentService.ts +27 -22
- package/src/documentServiceFactory.ts +45 -12
- package/src/documentStorageService.ts +3 -3
- package/src/packageVersion.ts +1 -1
- package/src/restWrapper.ts +82 -55
- package/src/retriableGitManager.ts +2 -2
- package/src/shreddedSummaryDocumentStorageService.ts +2 -3
- package/src/urlUtils.ts +4 -4
- package/src/wholeSummaryDocumentStorageService.ts +18 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shreddedSummaryDocumentStorageService.js","sourceRoot":"","sources":["../src/shreddedSummaryDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAMlF,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAQ/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE,OAAO,EAAU,aAAa,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAI5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,MAAM,MAAM,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;AAE7C;;;;GAIG;AACH,MAAM,OAAO,qCAAqC;IAoBjD,YACoB,EAAU,EACV,OAAmB,EACnB,MAAwB,EAC3B,QAAyC,EACzD,cAA6C,EAC7C,SAAmC,EACnC,iBAAgD,EAC/B,oBAEU,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,OAAO;QAThC,OAAE,GAAF,EAAE,CAAQ;QACV,YAAO,GAAP,OAAO,CAAY;QACnB,WAAM,GAAN,MAAM,CAAkB;QAC3B,aAAQ,GAAR,QAAQ,CAAiC;QAIxC,sBAAiB,GAAjB,iBAAiB,CAEiB;QA7BpD,uFAAuF;QACvF,2BAA2B;QACR,kBAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;QA6B5D,IAAI,CAAA,cAAc,aAAd,cAA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,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAC3D,KAAK,CAAC,GAAG,CAAC;gBACT,MAAM,EAAE,QAAQ,CAAC,EAAE;aACnB,CAAC,CAAC;YACH,OAAO,QAAQ,CAAC;QACjB,CAAC,CACD,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,uBAAuB,CACpC,YAAoB;QAEpB,OAAO,YAAY;YAClB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;gBAC1D,mEAAmE;gBACnE,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;gBAC3B,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YACzC,CAAC,CAAC;YACJ,CAAC,CAAC,SAAS,CAAC;IACd,CAAC;IAEO,WAAW,CAAC,MAAc;QACjC,OAAO,GAAG,IAAI,CAAC,EAAE,IAAI,MAAM,EAAE,CAAC;IAC/B,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { stringToBuffer, Uint8ArrayToString } from \"@fluidframework/common-utils\";\nimport {\n\tIDocumentStorageService,\n\tISummaryContext,\n\tIDocumentStorageServicePolicies,\n} from \"@fluidframework/driver-definitions\";\nimport { buildHierarchy } from \"@fluidframework/protocol-base\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTreeEx,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { IRouterliciousDriverPolicies } from \"./policies\";\nimport { ICache, InMemoryCache } from \"./cache\";\nimport { RetriableGitManager } from \"./retriableGitManager\";\nimport { ISnapshotTreeVersion } from \"./definitions\";\nimport { GitManager } from \"./gitManager\";\nimport { ISummaryUploadManager } from \"./storageContracts\";\nimport { SummaryTreeUploadManager } from \"./summaryTreeUploadManager\";\n\nconst isNode = typeof window === \"undefined\";\n\n/**\n * Document access to underlying storage for routerlicious driver.\n * Uploads summaries piece-by-piece traversing the tree recursively.\n * Downloads summaries piece-by-piece on-demand, or up-front when prefetch is enabled.\n */\nexport class ShreddedSummaryDocumentStorageService implements IDocumentStorageService {\n\t// The values of this cache is useless. We only need the keys. So we are always putting\n\t// empty strings as values.\n\tprotected readonly blobsShaCache = new Map<string, string>();\n\tprivate readonly blobCache: ICache<ArrayBufferLike> | undefined;\n\tprivate readonly snapshotTreeCache: ICache<ISnapshotTreeVersion> | undefined;\n\n\tpublic get repositoryUrl(): string {\n\t\treturn \"\";\n\t}\n\n\tprivate async getSummaryUploadManager(): Promise<ISummaryUploadManager> {\n\t\tconst manager = await this.getStorageManager();\n\t\treturn new SummaryTreeUploadManager(\n\t\t\tnew RetriableGitManager(manager, this.logger),\n\t\t\tthis.blobsShaCache,\n\t\t\tthis.getPreviousFullSnapshot.bind(this),\n\t\t);\n\t}\n\n\tconstructor(\n\t\tprotected readonly id: string,\n\t\tprotected readonly manager: GitManager,\n\t\tprotected readonly logger: ITelemetryLogger,\n\t\tpublic readonly policies: IDocumentStorageServicePolicies,\n\t\tdriverPolicies?: IRouterliciousDriverPolicies,\n\t\tblobCache?: ICache<ArrayBufferLike>,\n\t\tsnapshotTreeCache?: ICache<ISnapshotTreeVersion>,\n\t\tprivate readonly getStorageManager: (\n\t\t\tdisableCache?: boolean,\n\t\t) => Promise<GitManager> = async () => this.manager,\n\t) {\n\t\tif (driverPolicies?.enableRestLess === true || isNode) {\n\t\t\tthis.blobCache = blobCache ?? new InMemoryCache();\n\t\t\tthis.snapshotTreeCache = snapshotTreeCache ?? new InMemoryCache();\n\t\t}\n\t}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\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\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | 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\tconst cachedSnapshotTree = await this.snapshotTreeCache?.get(\n\t\t\tthis.getCacheKey(requestVersion.treeId),\n\t\t);\n\t\tif (cachedSnapshotTree) {\n\t\t\treturn cachedSnapshotTree.snapshotTree as ISnapshotTreeEx;\n\t\t}\n\n\t\tconst rawTree = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"getSnapshotTree\",\n\t\t\t\ttreeId: requestVersion.treeId,\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.getTree(requestVersion!.treeId)).content;\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.tree.length,\n\t\t\t\t});\n\t\t\t\treturn response;\n\t\t\t},\n\t\t);\n\t\tconst tree = buildHierarchy(rawTree, this.blobsShaCache, true);\n\t\tawait this.snapshotTreeCache?.put(this.getCacheKey(tree.id), {\n\t\t\tid: requestVersion.id,\n\t\t\tsnapshotTree: tree,\n\t\t});\n\t\treturn tree;\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) {\n\t\t\treturn cachedBlob;\n\t\t}\n\n\t\tconst value = 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);\n\t\tthis.blobsShaCache.set(value.sha, \"\");\n\t\tconst bufferContent = stringToBuffer(value.content, value.encoding);\n\t\tawait this.blobCache?.put(this.getCacheKey(value.sha), bufferContent);\n\t\treturn bufferContent;\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(handle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tthrow new Error(\"NOT IMPLEMENTED!\");\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 getPreviousFullSnapshot(\n\t\tparentHandle: string,\n\t): Promise<ISnapshotTreeEx | null | undefined> {\n\t\treturn parentHandle\n\t\t\t? this.getVersions(parentHandle, 1).then(async (versions) => {\n\t\t\t\t\t// Clear the cache as the getSnapshotTree call will fill the cache.\n\t\t\t\t\tthis.blobsShaCache.clear();\n\t\t\t\t\treturn this.getSnapshotTree(versions[0]);\n\t\t\t })\n\t\t\t: undefined;\n\t}\n\n\tprivate getCacheKey(blobId: string): string {\n\t\treturn `${this.id}:${blobId}`;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shreddedSummaryDocumentStorageService.js","sourceRoot":"","sources":["../src/shreddedSummaryDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAuB,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAMlF,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAS/D,OAAO,EAAU,aAAa,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAI5D,OAAO,EAAE,w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AAI,CAAC,EAAE,IAAI,MAAM,EAAE,CAAC;IAC/B,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLoggerExt, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { stringToBuffer, Uint8ArrayToString } from \"@fluidframework/common-utils\";\nimport {\n\tIDocumentStorageService,\n\tISummaryContext,\n\tIDocumentStorageServicePolicies,\n} from \"@fluidframework/driver-definitions\";\nimport { buildHierarchy } from \"@fluidframework/protocol-base\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTreeEx,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport { IRouterliciousDriverPolicies } from \"./policies\";\nimport { ICache, InMemoryCache } from \"./cache\";\nimport { RetriableGitManager } from \"./retriableGitManager\";\nimport { ISnapshotTreeVersion } from \"./definitions\";\nimport { GitManager } from \"./gitManager\";\nimport { ISummaryUploadManager } from \"./storageContracts\";\nimport { SummaryTreeUploadManager } from \"./summaryTreeUploadManager\";\n\nconst isNode = typeof window === \"undefined\";\n\n/**\n * Document access to underlying storage for routerlicious driver.\n * Uploads summaries piece-by-piece traversing the tree recursively.\n * Downloads summaries piece-by-piece on-demand, or up-front when prefetch is enabled.\n */\nexport class ShreddedSummaryDocumentStorageService implements IDocumentStorageService {\n\t// The values of this cache is useless. We only need the keys. So we are always putting\n\t// empty strings as values.\n\tprotected readonly blobsShaCache = new Map<string, string>();\n\tprivate readonly blobCache: ICache<ArrayBufferLike> | undefined;\n\tprivate readonly snapshotTreeCache: ICache<ISnapshotTreeVersion> | undefined;\n\n\tpublic get repositoryUrl(): string {\n\t\treturn \"\";\n\t}\n\n\tprivate async getSummaryUploadManager(): Promise<ISummaryUploadManager> {\n\t\tconst manager = await this.getStorageManager();\n\t\treturn new SummaryTreeUploadManager(\n\t\t\tnew RetriableGitManager(manager, this.logger),\n\t\t\tthis.blobsShaCache,\n\t\t\tthis.getPreviousFullSnapshot.bind(this),\n\t\t);\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\tdriverPolicies?: IRouterliciousDriverPolicies,\n\t\tblobCache?: ICache<ArrayBufferLike>,\n\t\tsnapshotTreeCache?: ICache<ISnapshotTreeVersion>,\n\t\tprivate readonly getStorageManager: (\n\t\t\tdisableCache?: boolean,\n\t\t) => Promise<GitManager> = async () => this.manager,\n\t) {\n\t\tif (driverPolicies?.enableRestLess === true || isNode) {\n\t\t\tthis.blobCache = blobCache ?? new InMemoryCache();\n\t\t\tthis.snapshotTreeCache = snapshotTreeCache ?? new InMemoryCache();\n\t\t}\n\t}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\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\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | 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\tconst cachedSnapshotTree = await this.snapshotTreeCache?.get(\n\t\t\tthis.getCacheKey(requestVersion.treeId),\n\t\t);\n\t\tif (cachedSnapshotTree) {\n\t\t\treturn cachedSnapshotTree.snapshotTree as ISnapshotTreeEx;\n\t\t}\n\n\t\tconst rawTree = await PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"getSnapshotTree\",\n\t\t\t\ttreeId: requestVersion.treeId,\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.getTree(requestVersion!.treeId)).content;\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.tree.length,\n\t\t\t\t});\n\t\t\t\treturn response;\n\t\t\t},\n\t\t);\n\t\tconst tree = buildHierarchy(rawTree, this.blobsShaCache, true);\n\t\tawait this.snapshotTreeCache?.put(this.getCacheKey(tree.id), {\n\t\t\tid: requestVersion.id,\n\t\t\tsnapshotTree: tree,\n\t\t});\n\t\treturn tree;\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) {\n\t\t\treturn cachedBlob;\n\t\t}\n\n\t\tconst value = 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);\n\t\tthis.blobsShaCache.set(value.sha, \"\");\n\t\tconst bufferContent = stringToBuffer(value.content, value.encoding);\n\t\tawait this.blobCache?.put(this.getCacheKey(value.sha), bufferContent);\n\t\treturn bufferContent;\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(handle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tthrow new Error(\"NOT IMPLEMENTED!\");\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 getPreviousFullSnapshot(\n\t\tparentHandle: string,\n\t): Promise<ISnapshotTreeEx | null | undefined> {\n\t\treturn parentHandle\n\t\t\t? this.getVersions(parentHandle, 1).then(async (versions) => {\n\t\t\t\t\t// Clear the cache as the getSnapshotTree call will fill the cache.\n\t\t\t\t\tthis.blobsShaCache.clear();\n\t\t\t\t\treturn this.getSnapshotTree(versions[0]);\n\t\t\t })\n\t\t\t: undefined;\n\t}\n\n\tprivate getCacheKey(blobId: string): string {\n\t\treturn `${this.id}:${blobId}`;\n\t}\n}\n"]}
|
package/lib/urlUtils.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { IResolvedUrl } from "@fluidframework/driver-definitions";
|
|
6
6
|
import URLParse from "url-parse";
|
|
7
7
|
import { ISession } from "@fluidframework/server-services-client";
|
|
8
8
|
export declare const parseFluidUrl: (fluidUrl: string) => URLParse;
|
|
@@ -13,5 +13,5 @@ export declare const parseFluidUrl: (fluidUrl: string) => URLParse;
|
|
|
13
13
|
* TODO: Ideally we would be able to regenerate the resolvedUrl, rather than patching the current one.
|
|
14
14
|
*/
|
|
15
15
|
export declare const replaceDocumentIdInPath: (urlPath: string, documentId: string) => string;
|
|
16
|
-
export declare const getDiscoveredFluidResolvedUrl: (resolvedUrl:
|
|
16
|
+
export declare const getDiscoveredFluidResolvedUrl: (resolvedUrl: IResolvedUrl, session: ISession) => IResolvedUrl;
|
|
17
17
|
//# sourceMappingURL=urlUtils.d.ts.map
|
package/lib/urlUtils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlUtils.d.ts","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"urlUtils.d.ts","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,wCAAwC,CAAC;AAElE,eAAO,MAAM,aAAa,aAAc,MAAM,KAAG,QAEhD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,YAAa,MAAM,cAAc,MAAM,KAAG,MACf,CAAC;AAEhE,eAAO,MAAM,6BAA6B,gBAC5B,YAAY,WAChB,QAAQ,KACf,YAuBF,CAAC"}
|
package/lib/urlUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlUtils.js","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,QAAQ,MAAM,WAAW,CAAC;AAGjC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAAgB,EAAY,EAAE;IAC3D,OAAO,IAAI,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,OAAe,EAAE,UAAkB,EAAU,EAAE,CACtF,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEhE,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC5C,
|
|
1
|
+
{"version":3,"file":"urlUtils.js","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,QAAQ,MAAM,WAAW,CAAC;AAGjC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAAgB,EAAY,EAAE;IAC3D,OAAO,IAAI,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,OAAe,EAAE,UAAkB,EAAU,EAAE,CACtF,OAAO,CAAC,KAAK,CAAC,GAAG,CAA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B,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IResolvedUrl } from \"@fluidframework/driver-definitions\";\nimport URLParse from \"url-parse\";\nimport { ISession } from \"@fluidframework/server-services-client\";\n\nexport const parseFluidUrl = (fluidUrl: string): URLParse => {\n\treturn new URLParse(fluidUrl, true);\n};\n\n/**\n * Assume documentId is at end of url path.\n * This is true for Routerlicious' and Tinylicious' documentUrl and deltaStorageUrl.\n * Routerlicious and Tinylicious do not use documentId in storageUrl nor ordererUrl.\n * TODO: Ideally we would be able to regenerate the resolvedUrl, rather than patching the current one.\n */\nexport const replaceDocumentIdInPath = (urlPath: string, documentId: string): string =>\n\turlPath.split(\"/\").slice(0, -1).concat([documentId]).join(\"/\");\n\nexport const getDiscoveredFluidResolvedUrl = (\n\tresolvedUrl: IResolvedUrl,\n\tsession: ISession,\n): IResolvedUrl => {\n\tconst discoveredOrdererUrl = new URLParse(session.ordererUrl);\n\tconst deltaStorageUrl = new URLParse(resolvedUrl.endpoints.deltaStorageUrl);\n\tdeltaStorageUrl.set(\"host\", discoveredOrdererUrl.host);\n\n\tconst discoveredStorageUrl = new URLParse(session.historianUrl);\n\tconst storageUrl = new URLParse(resolvedUrl.endpoints.storageUrl);\n\tstorageUrl.set(\"host\", discoveredStorageUrl.host);\n\n\tconst parsedUrl = parseFluidUrl(resolvedUrl.url);\n\tconst discoveredResolvedUrl: IResolvedUrl = {\n\t\tendpoints: {\n\t\t\tdeltaStorageUrl: deltaStorageUrl.toString(),\n\t\t\tordererUrl: session.ordererUrl,\n\t\t\tdeltaStreamUrl: session.deltaStreamUrl,\n\t\t\tstorageUrl: storageUrl.toString(),\n\t\t},\n\t\tid: resolvedUrl.id,\n\t\ttokens: resolvedUrl.tokens,\n\t\ttype: resolvedUrl.type,\n\t\turl: new URLParse(`fluid://${discoveredOrdererUrl.host}${parsedUrl.pathname}`).toString(),\n\t};\n\treturn discoveredResolvedUrl;\n};\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
5
|
+
import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils";
|
|
6
6
|
import { IDocumentStorageService, ISummaryContext, IDocumentStorageServicePolicies } from "@fluidframework/driver-definitions";
|
|
7
7
|
import { ICreateBlobResponse, ISnapshotTree, ISummaryHandle, ISummaryTree, IVersion } from "@fluidframework/protocol-definitions";
|
|
8
8
|
import { ICache } from "./cache";
|
|
@@ -12,7 +12,7 @@ import { INormalizedWholeSummary } from "./contracts";
|
|
|
12
12
|
export declare class WholeSummaryDocumentStorageService implements IDocumentStorageService {
|
|
13
13
|
protected readonly id: string;
|
|
14
14
|
protected readonly manager: GitManager;
|
|
15
|
-
protected readonly logger:
|
|
15
|
+
protected readonly logger: ITelemetryLoggerExt;
|
|
16
16
|
readonly policies: IDocumentStorageServicePolicies;
|
|
17
17
|
private readonly driverPolicies?;
|
|
18
18
|
private readonly blobCache;
|
|
@@ -22,7 +22,7 @@ export declare class WholeSummaryDocumentStorageService implements IDocumentStor
|
|
|
22
22
|
private firstVersionsCall;
|
|
23
23
|
get repositoryUrl(): string;
|
|
24
24
|
private getSummaryUploadManager;
|
|
25
|
-
constructor(id: string, manager: GitManager, logger:
|
|
25
|
+
constructor(id: string, manager: GitManager, logger: ITelemetryLoggerExt, policies: IDocumentStorageServicePolicies, driverPolicies?: IRouterliciousDriverPolicies | undefined, blobCache?: ICache<ArrayBufferLike>, snapshotTreeCache?: ICache<INormalizedWholeSummary>, noCacheGitManager?: GitManager | undefined, getStorageManager?: (disableCache?: boolean) => Promise<GitManager>);
|
|
26
26
|
getVersions(versionId: string | null, count: number): Promise<IVersion[]>;
|
|
27
27
|
getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null>;
|
|
28
28
|
readBlob(blobId: string): Promise<ArrayBufferLike>;
|
|
@@ -31,7 +31,7 @@ export declare class WholeSummaryDocumentStorageService implements IDocumentStor
|
|
|
31
31
|
createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse>;
|
|
32
32
|
private fetchSnapshotTree;
|
|
33
33
|
private initializeFromSnapshot;
|
|
34
|
-
private
|
|
34
|
+
private updateBlobsCache;
|
|
35
35
|
private getCacheKey;
|
|
36
36
|
}
|
|
37
37
|
//# sourceMappingURL=wholeSummaryDocumentStorageService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wholeSummaryDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/wholeSummaryDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"wholeSummaryDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/wholeSummaryDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAoB,MAAM,iCAAiC,CAAC;AAQxF,OAAO,EACN,uBAAuB,EACvB,eAAe,EACf,+BAA+B,EAC/B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACN,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAiB,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAM1D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAKtD,qBAAa,kCAAmC,YAAW,uBAAuB;IAahF,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM;IAC7B,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,UAAU;IACtC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,mBAAmB;aAC9B,QAAQ,EAAE,+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9 +2,9 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
+
import { PerformanceEvent } from "@fluidframework/telemetry-utils";
|
|
5
6
|
import { assert, performance, stringToBuffer, Uint8ArrayToString, } from "@fluidframework/common-utils";
|
|
6
7
|
import { getW3CData, promiseRaceWithWinner } from "@fluidframework/driver-base";
|
|
7
|
-
import { PerformanceEvent } from "@fluidframework/telemetry-utils";
|
|
8
8
|
import { InMemoryCache } from "./cache";
|
|
9
9
|
import { convertSnapshotAndBlobsToSummaryTree, evalBlobsAndTrees, validateBlobsAndTrees, } from "./treeUtils";
|
|
10
10
|
import { WholeSummaryUploadManager } from "./wholeSummaryUploadManager";
|
|
@@ -115,18 +115,22 @@ export class WholeSummaryDocumentStorageService {
|
|
|
115
115
|
}
|
|
116
116
|
requestVersion = versions[0];
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
let normalizedWholeSnapshot = await this.snapshotTreeCache.get(this.getCacheKey(requestVersion.id));
|
|
119
119
|
if (normalizedWholeSnapshot !== undefined) {
|
|
120
120
|
return normalizedWholeSnapshot.snapshotTree;
|
|
121
121
|
}
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
normalizedWholeSnapshot = await this.fetchSnapshotTree(requestVersion.id, undefined, "getSnapshotTree");
|
|
123
|
+
// Currently retrieving blobs from network is not supported by AFR for WholeSummaryDocumentStorageService
|
|
124
|
+
// Blobs are expected to be put in the cache
|
|
125
|
+
await this.updateBlobsCache(normalizedWholeSnapshot.blobs);
|
|
126
|
+
return normalizedWholeSnapshot.snapshotTree;
|
|
124
127
|
}
|
|
125
128
|
async readBlob(blobId) {
|
|
126
129
|
const cachedBlob = await this.blobCache.get(this.getCacheKey(blobId));
|
|
127
130
|
if (cachedBlob !== undefined) {
|
|
128
131
|
return cachedBlob;
|
|
129
132
|
}
|
|
133
|
+
// Note: AFR does not support readBlobs, but potentially other r11s like servers do
|
|
130
134
|
const blob = await PerformanceEvent.timedExecAsync(this.logger, {
|
|
131
135
|
eventName: "readBlob",
|
|
132
136
|
blobId,
|
|
@@ -215,12 +219,12 @@ export class WholeSummaryDocumentStorageService {
|
|
|
215
219
|
assert(snapshotId !== undefined, 0x275 /* "Root tree should contain the id" */);
|
|
216
220
|
const cachePs = [
|
|
217
221
|
this.snapshotTreeCache.put(this.getCacheKey(snapshotId), normalizedWholeSummary),
|
|
218
|
-
this.
|
|
222
|
+
this.updateBlobsCache(normalizedWholeSummary.blobs),
|
|
219
223
|
];
|
|
220
224
|
await Promise.all(cachePs);
|
|
221
225
|
return snapshotId;
|
|
222
226
|
}
|
|
223
|
-
async
|
|
227
|
+
async updateBlobsCache(blobs) {
|
|
224
228
|
const blobCachePutPs = [];
|
|
225
229
|
blobs.forEach((value, id) => {
|
|
226
230
|
const cacheKey = this.getCacheKey(id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wholeSummaryDocumentStorageService.js","sourceRoot":"","sources":["../src/wholeSummaryDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,MAAM,EACN,WAAW,EACX,cAAc,EACd,kBAAkB,GAClB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAchF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAU,aAAa,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,EACN,oCAAoC,EACpC,iBAAiB,EACjB,qBAAqB,GACrB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAIxE,OAAO,EAAE,6CAA6C,EAAE,MAAM,sBAAsB,CAAC;AAErF,MAAM,gBAAgB,GAAW,QAAQ,CAAC;AAE1C,MAAM,OAAO,kCAAkC;IAY9C,YACoB,EAAU,EACV,OAAmB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EAAE,CAAC;QAC7C,MAAM,CAAC,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,aAAa,CAAC,sBAAsB,CAAC,KAAK,CAAC;SAChD,CAAC;QAEF,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAE3B,OAAO,UAAU,CAAC;IACnB,CAAC;IAEO,KAAK,CAAC,aAAa,CAAC,KAA+B;QAC1D,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","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport {\n\tassert,\n\tperformance,\n\tstringToBuffer,\n\tUint8ArrayToString,\n} from \"@fluidframework/common-utils\";\nimport { getW3CData, promiseRaceWithWinner } from \"@fluidframework/driver-base\";\nimport {\n\tIDocumentStorageService,\n\tISummaryContext,\n\tIDocumentStorageServicePolicies,\n} from \"@fluidframework/driver-definitions\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTree,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport { IWholeFlatSummary } from \"@fluidframework/server-services-client\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { ICache, InMemoryCache } from \"./cache\";\nimport { IRouterliciousDriverPolicies } from \"./policies\";\nimport {\n\tconvertSnapshotAndBlobsToSummaryTree,\n\tevalBlobsAndTrees,\n\tvalidateBlobsAndTrees,\n} from \"./treeUtils\";\nimport { GitManager } from \"./gitManager\";\nimport { WholeSummaryUploadManager } from \"./wholeSummaryUploadManager\";\nimport { ISummaryUploadManager } from \"./storageContracts\";\nimport { IR11sResponse } from \"./restWrapper\";\nimport { INormalizedWholeSummary } from \"./contracts\";\nimport { convertWholeFlatSummaryToSnapshotTreeAndBlobs } from \"./r11sSnapshotParser\";\n\nconst latestSnapshotId: string = \"latest\";\n\nexport class WholeSummaryDocumentStorageService implements IDocumentStorageService {\n\tprivate firstVersionsCall: boolean = true;\n\n\tpublic get repositoryUrl(): string {\n\t\treturn \"\";\n\t}\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: ITelemetryLogger,\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<INormalizedWholeSummary> = 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\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\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\tconst 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\t\treturn (await this.fetchSnapshotTree(requestVersion.id, undefined, \"getSnapshotTree\"))\n\t\t\t.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\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);\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 wholeFlatSummary = 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.getSummary(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 } = convertWholeFlatSummaryToSnapshotTreeAndBlobs(\n\t\t\twholeFlatSummary,\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<INormalizedWholeSummary> {\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<IWholeFlatSummary> = await manager.getSummary(\n\t\t\t\t\tversionId,\n\t\t\t\t);\n\t\t\t\tconst start = performance.now();\n\t\t\t\tconst snapshot: INormalizedWholeSummary =\n\t\t\t\t\tconvertWholeFlatSummaryToSnapshotTreeAndBlobs(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\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: INormalizedWholeSummary,\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.initBlobCache(normalizedWholeSummary.blobs),\n\t\t];\n\n\t\tawait Promise.all(cachePs);\n\n\t\treturn snapshotId;\n\t}\n\n\tprivate async initBlobCache(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;;;GAGG;AAEH,OAAO,EAAuB,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxF,OAAO,EACN,MAAM,EACN,WAAW,EACX,cAAc,EACd,kBAAkB,GAClB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAchF,OAAO,EAAU,aAAa,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,EACN,oCAAoC,EACpC,iBAAiB,EACjB,qBAAqB,GACrB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAIxE,OAAO,EAAE,6CAA6C,EAAE,MAAM,sBAAsB,CAAC;AAErF,MAAM,gBAAgB,GAAW,QAAQ,CAAC;AAE1C,MAAM,OAAO,kCAAkC;IAY9C,YACoB,EAAU,EACV,OAAmB,EACnB,MAA2B,EAC9B,QAAyC,EACxC,cAA6C,EAC7C,YAAqC,IAAI,aAAa,EAAE,EACxD,oBAAqD,IAAI,aAAa,EAAE,EACxE,iBAA8B,EAC9B,oBAEU,KAAK,EAAE,YAAY,EAAE,EAAE,CACjD,YAAY,IAAI,IAAI,CAAC,iBAAiB,KAAK,SAAS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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","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLoggerExt, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport {\n\tassert,\n\tperformance,\n\tstringToBuffer,\n\tUint8ArrayToString,\n} from \"@fluidframework/common-utils\";\nimport { getW3CData, promiseRaceWithWinner } from \"@fluidframework/driver-base\";\nimport {\n\tIDocumentStorageService,\n\tISummaryContext,\n\tIDocumentStorageServicePolicies,\n} from \"@fluidframework/driver-definitions\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTree,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport { IWholeFlatSummary } from \"@fluidframework/server-services-client\";\nimport { ICache, InMemoryCache } from \"./cache\";\nimport { IRouterliciousDriverPolicies } from \"./policies\";\nimport {\n\tconvertSnapshotAndBlobsToSummaryTree,\n\tevalBlobsAndTrees,\n\tvalidateBlobsAndTrees,\n} from \"./treeUtils\";\nimport { GitManager } from \"./gitManager\";\nimport { WholeSummaryUploadManager } from \"./wholeSummaryUploadManager\";\nimport { ISummaryUploadManager } from \"./storageContracts\";\nimport { IR11sResponse } from \"./restWrapper\";\nimport { INormalizedWholeSummary } from \"./contracts\";\nimport { convertWholeFlatSummaryToSnapshotTreeAndBlobs } from \"./r11sSnapshotParser\";\n\nconst latestSnapshotId: string = \"latest\";\n\nexport class WholeSummaryDocumentStorageService implements IDocumentStorageService {\n\tprivate firstVersionsCall: boolean = true;\n\n\tpublic get repositoryUrl(): string {\n\t\treturn \"\";\n\t}\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<INormalizedWholeSummary> = 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\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\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);\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 wholeFlatSummary = 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.getSummary(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 } = convertWholeFlatSummaryToSnapshotTreeAndBlobs(\n\t\t\twholeFlatSummary,\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<INormalizedWholeSummary> {\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<IWholeFlatSummary> = await manager.getSummary(\n\t\t\t\t\tversionId,\n\t\t\t\t);\n\t\t\t\tconst start = performance.now();\n\t\t\t\tconst snapshot: INormalizedWholeSummary =\n\t\t\t\t\tconvertWholeFlatSummaryToSnapshotTreeAndBlobs(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\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: INormalizedWholeSummary,\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/routerlicious-driver",
|
|
3
|
-
"version": "2.0.0-internal.
|
|
3
|
+
"version": "2.0.0-internal.5.0.0",
|
|
4
4
|
"description": "Socket.IO + Git implementation of Fluid service API",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -37,17 +37,17 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@fluidframework/common-definitions": "^0.20.1",
|
|
39
39
|
"@fluidframework/common-utils": "^1.1.1",
|
|
40
|
-
"@fluidframework/driver-base": ">=2.0.0-internal.
|
|
41
|
-
"@fluidframework/driver-definitions": ">=2.0.0-internal.
|
|
42
|
-
"@fluidframework/driver-utils": ">=2.0.0-internal.
|
|
40
|
+
"@fluidframework/driver-base": ">=2.0.0-internal.5.0.0 <2.0.0-internal.5.1.0",
|
|
41
|
+
"@fluidframework/driver-definitions": ">=2.0.0-internal.5.0.0 <2.0.0-internal.5.1.0",
|
|
42
|
+
"@fluidframework/driver-utils": ">=2.0.0-internal.5.0.0 <2.0.0-internal.5.1.0",
|
|
43
43
|
"@fluidframework/gitresources": "^0.1039.1000",
|
|
44
44
|
"@fluidframework/protocol-base": "^0.1039.1000",
|
|
45
45
|
"@fluidframework/protocol-definitions": "^1.1.0",
|
|
46
46
|
"@fluidframework/server-services-client": "^0.1039.1000",
|
|
47
|
-
"@fluidframework/telemetry-utils": ">=2.0.0-internal.
|
|
47
|
+
"@fluidframework/telemetry-utils": ">=2.0.0-internal.5.0.0 <2.0.0-internal.5.1.0",
|
|
48
48
|
"cross-fetch": "^3.1.5",
|
|
49
49
|
"json-stringify-safe": "5.0.1",
|
|
50
|
-
"socket.io-client": "^4.
|
|
50
|
+
"socket.io-client": "^4.6.1",
|
|
51
51
|
"url-parse": "^1.5.8",
|
|
52
52
|
"uuid": "^8.3.1"
|
|
53
53
|
},
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@fluidframework/build-common": "^1.1.0",
|
|
57
57
|
"@fluidframework/build-tools": "^0.17.0",
|
|
58
58
|
"@fluidframework/eslint-config-fluid": "^2.0.0",
|
|
59
|
-
"@fluidframework/mocha-test-setup": ">=2.0.0-internal.
|
|
59
|
+
"@fluidframework/mocha-test-setup": ">=2.0.0-internal.5.0.0 <2.0.0-internal.5.1.0",
|
|
60
60
|
"@fluidframework/routerlicious-driver-previous": "npm:@fluidframework/routerlicious-driver@2.0.0-internal.4.1.0",
|
|
61
61
|
"@microsoft/api-extractor": "^7.34.4",
|
|
62
62
|
"@types/mocha": "^9.1.1",
|
|
@@ -12,8 +12,11 @@ import {
|
|
|
12
12
|
} from "@fluidframework/driver-definitions";
|
|
13
13
|
import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
14
14
|
import { readAndParse, requestOps, emptyMessageStream } from "@fluidframework/driver-utils";
|
|
15
|
-
import {
|
|
16
|
-
|
|
15
|
+
import {
|
|
16
|
+
ITelemetryLoggerExt,
|
|
17
|
+
PerformanceEvent,
|
|
18
|
+
TelemetryNullLogger,
|
|
19
|
+
} from "@fluidframework/telemetry-utils";
|
|
17
20
|
import { DocumentStorageService } from "./documentStorageService";
|
|
18
21
|
import { RestWrapper } from "./restWrapperBase";
|
|
19
22
|
|
|
@@ -28,7 +31,7 @@ export class DocumentDeltaStorageService implements IDocumentDeltaStorageService
|
|
|
28
31
|
private readonly id: string,
|
|
29
32
|
private readonly deltaStorageService: IDeltaStorageService,
|
|
30
33
|
private readonly documentStorageService: DocumentStorageService,
|
|
31
|
-
private readonly logger:
|
|
34
|
+
private readonly logger: ITelemetryLoggerExt,
|
|
32
35
|
) {}
|
|
33
36
|
|
|
34
37
|
private logtailSha: string | undefined = this.documentStorageService.logTailSha;
|
|
@@ -95,7 +98,7 @@ export class DeltaStorageService implements IDeltaStorageService {
|
|
|
95
98
|
constructor(
|
|
96
99
|
private readonly url: string,
|
|
97
100
|
private readonly restWrapper: RestWrapper,
|
|
98
|
-
private readonly logger:
|
|
101
|
+
private readonly logger: ITelemetryLoggerExt,
|
|
99
102
|
private readonly getRestWrapper: () => Promise<RestWrapper> = async () => this.restWrapper,
|
|
100
103
|
private readonly getDeltaStorageUrl: () => string = () => this.url,
|
|
101
104
|
) {}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils";
|
|
7
7
|
import { DocumentDeltaConnection } from "@fluidframework/driver-base";
|
|
8
8
|
import { IAnyDriverError, IDocumentDeltaConnection } from "@fluidframework/driver-definitions";
|
|
9
9
|
import { IClient, IConnect } from "@fluidframework/protocol-definitions";
|
|
@@ -24,7 +24,7 @@ export class R11sDocumentDeltaConnection extends DocumentDeltaConnection {
|
|
|
24
24
|
io: typeof SocketIOClientStatic,
|
|
25
25
|
client: IClient,
|
|
26
26
|
url: string,
|
|
27
|
-
logger:
|
|
27
|
+
logger: ITelemetryLoggerExt,
|
|
28
28
|
timeoutMs = 20000,
|
|
29
29
|
): Promise<IDocumentDeltaConnection> {
|
|
30
30
|
const socket = io(url, {
|
package/src/documentService.ts
CHANGED
|
@@ -9,14 +9,17 @@ import { DriverErrorType } from "@fluidframework/driver-definitions";
|
|
|
9
9
|
import { RateLimiter, NetworkErrorBasic, canRetryOnError } from "@fluidframework/driver-utils";
|
|
10
10
|
import { IClient } from "@fluidframework/protocol-definitions";
|
|
11
11
|
import io from "socket.io-client";
|
|
12
|
-
import { PerformanceEvent, wrapError } from "@fluidframework/telemetry-utils";
|
|
13
|
-
import { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
12
|
+
import { PerformanceEvent, wrapError, ITelemetryLoggerExt } from "@fluidframework/telemetry-utils";
|
|
14
13
|
import { DeltaStorageService, DocumentDeltaStorageService } from "./deltaStorageService";
|
|
15
14
|
import { DocumentStorageService } from "./documentStorageService";
|
|
16
15
|
import { R11sDocumentDeltaConnection } from "./documentDeltaConnection";
|
|
17
16
|
import { NullBlobStorageService } from "./nullBlobStorageService";
|
|
18
17
|
import { ITokenProvider } from "./tokens";
|
|
19
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
RouterliciousOrdererRestWrapper,
|
|
20
|
+
RouterliciousStorageRestWrapper,
|
|
21
|
+
TokenFetcher,
|
|
22
|
+
} from "./restWrapper";
|
|
20
23
|
import { IRouterliciousDriverPolicies } from "./policies";
|
|
21
24
|
import { ICache } from "./cache";
|
|
22
25
|
import { ISnapshotTreeVersion } from "./definitions";
|
|
@@ -56,7 +59,7 @@ export class DocumentService implements api.IDocumentService {
|
|
|
56
59
|
private deltaStorageUrl: string,
|
|
57
60
|
private deltaStreamUrl: string,
|
|
58
61
|
private storageUrl: string,
|
|
59
|
-
private readonly logger:
|
|
62
|
+
private readonly logger: ITelemetryLoggerExt,
|
|
60
63
|
protected tokenProvider: ITokenProvider,
|
|
61
64
|
protected tenantId: string,
|
|
62
65
|
protected documentId: string,
|
|
@@ -66,7 +69,10 @@ export class DocumentService implements api.IDocumentService {
|
|
|
66
69
|
private readonly blobCache: ICache<ArrayBufferLike>,
|
|
67
70
|
private readonly wholeSnapshotTreeCache: ICache<INormalizedWholeSummary>,
|
|
68
71
|
private readonly shreddedSummaryTreeCache: ICache<ISnapshotTreeVersion>,
|
|
69
|
-
private readonly discoverFluidResolvedUrl: () => Promise<api.
|
|
72
|
+
private readonly discoverFluidResolvedUrl: () => Promise<api.IResolvedUrl>,
|
|
73
|
+
private storageRestWrapper: RouterliciousStorageRestWrapper,
|
|
74
|
+
private readonly storageTokenFetcher: TokenFetcher,
|
|
75
|
+
private readonly ordererTokenFetcher: TokenFetcher,
|
|
70
76
|
) {}
|
|
71
77
|
|
|
72
78
|
private documentStorageService: DocumentStorageService | undefined;
|
|
@@ -97,21 +103,22 @@ export class DocumentService implements api.IDocumentService {
|
|
|
97
103
|
!this.noCacheStorageManager ||
|
|
98
104
|
shouldUpdateDiscoveredSessionInfo
|
|
99
105
|
) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
106
|
+
if (shouldUpdateDiscoveredSessionInfo) {
|
|
107
|
+
const rateLimiter = new RateLimiter(
|
|
108
|
+
this.driverPolicies.maxConcurrentStorageRequests,
|
|
109
|
+
);
|
|
110
|
+
this.storageRestWrapper = await RouterliciousStorageRestWrapper.load(
|
|
111
|
+
this.tenantId,
|
|
112
|
+
this.storageTokenFetcher,
|
|
113
|
+
this.logger,
|
|
114
|
+
rateLimiter,
|
|
115
|
+
this.driverPolicies.enableRestLess,
|
|
116
|
+
this.storageUrl,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
const historian = new Historian(true, false, this.storageRestWrapper);
|
|
113
120
|
this.storageManager = new GitManager(historian);
|
|
114
|
-
const noCacheHistorian = new Historian(true, true, storageRestWrapper);
|
|
121
|
+
const noCacheHistorian = new Historian(true, true, this.storageRestWrapper);
|
|
115
122
|
this.noCacheStorageManager = new GitManager(noCacheHistorian);
|
|
116
123
|
}
|
|
117
124
|
|
|
@@ -153,9 +160,7 @@ export class DocumentService implements api.IDocumentService {
|
|
|
153
160
|
this.driverPolicies.maxConcurrentOrdererRequests,
|
|
154
161
|
);
|
|
155
162
|
this.ordererRestWrapper = await RouterliciousOrdererRestWrapper.load(
|
|
156
|
-
this.
|
|
157
|
-
this.documentId,
|
|
158
|
-
this.tokenProvider,
|
|
163
|
+
this.ordererTokenFetcher,
|
|
159
164
|
this.logger,
|
|
160
165
|
rateLimiter,
|
|
161
166
|
this.driverPolicies.enableRestLess,
|
|
@@ -10,14 +10,12 @@ import {
|
|
|
10
10
|
IDocumentService,
|
|
11
11
|
IDocumentServiceFactory,
|
|
12
12
|
IDocumentStorageServicePolicies,
|
|
13
|
-
IFluidResolvedUrl,
|
|
14
13
|
IResolvedUrl,
|
|
15
14
|
LoaderCachingPolicy,
|
|
16
15
|
} from "@fluidframework/driver-definitions";
|
|
17
16
|
import { ITelemetryBaseLogger } from "@fluidframework/common-definitions";
|
|
18
17
|
import { ISummaryTree } from "@fluidframework/protocol-definitions";
|
|
19
18
|
import {
|
|
20
|
-
ensureFluidResolvedUrl,
|
|
21
19
|
getDocAttributesFromProtocolSummary,
|
|
22
20
|
getQuorumValuesFromProtocolSummary,
|
|
23
21
|
isCombinedAppAndProtocolSummary,
|
|
@@ -28,7 +26,12 @@ import { ISession } from "@fluidframework/server-services-client";
|
|
|
28
26
|
import { DocumentService } from "./documentService";
|
|
29
27
|
import { IRouterliciousDriverPolicies } from "./policies";
|
|
30
28
|
import { ITokenProvider } from "./tokens";
|
|
31
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
RouterliciousOrdererRestWrapper,
|
|
31
|
+
RouterliciousStorageRestWrapper,
|
|
32
|
+
toInstrumentedR11sOrdererTokenFetcher,
|
|
33
|
+
toInstrumentedR11sStorageTokenFetcher,
|
|
34
|
+
} from "./restWrapper";
|
|
32
35
|
import { convertSummaryToCreateNewSummary } from "./createNewUtils";
|
|
33
36
|
import { parseFluidUrl, replaceDocumentIdInPath, getDiscoveredFluidResolvedUrl } from "./urlUtils";
|
|
34
37
|
import { ICache, InMemoryCache, NullCache } from "./cache";
|
|
@@ -96,7 +99,6 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
|
|
|
96
99
|
logger?: ITelemetryBaseLogger,
|
|
97
100
|
clientIsSummarizer?: boolean,
|
|
98
101
|
): Promise<IDocumentService> {
|
|
99
|
-
ensureFluidResolvedUrl(resolvedUrl);
|
|
100
102
|
if (createNewSummary === undefined) {
|
|
101
103
|
throw new Error("Empty file summary creation isn't supported in this driver.");
|
|
102
104
|
}
|
|
@@ -117,12 +119,16 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
|
|
|
117
119
|
const quorumValues = getQuorumValuesFromProtocolSummary(protocolSummary);
|
|
118
120
|
|
|
119
121
|
const logger2 = ChildLogger.create(logger, "RouterliciousDriver");
|
|
120
|
-
const
|
|
121
|
-
const ordererRestWrapper = await RouterliciousOrdererRestWrapper.load(
|
|
122
|
+
const ordererTokenFetcher = toInstrumentedR11sOrdererTokenFetcher(
|
|
122
123
|
tenantId,
|
|
123
|
-
undefined
|
|
124
|
+
undefined /* documentId */,
|
|
124
125
|
this.tokenProvider,
|
|
125
126
|
logger2,
|
|
127
|
+
);
|
|
128
|
+
const rateLimiter = new RateLimiter(this.driverPolicies.maxConcurrentOrdererRequests);
|
|
129
|
+
const ordererRestWrapper = await RouterliciousOrdererRestWrapper.load(
|
|
130
|
+
ordererTokenFetcher,
|
|
131
|
+
logger2,
|
|
126
132
|
rateLimiter,
|
|
127
133
|
this.driverPolicies.enableRestLess,
|
|
128
134
|
resolvedUrl.endpoints.ordererUrl,
|
|
@@ -233,7 +239,6 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
|
|
|
233
239
|
clientIsSummarizer?: boolean,
|
|
234
240
|
session?: ISession,
|
|
235
241
|
): Promise<IDocumentService> {
|
|
236
|
-
ensureFluidResolvedUrl(resolvedUrl);
|
|
237
242
|
const parsedUrl = parseFluidUrl(resolvedUrl.url);
|
|
238
243
|
const [, tenantId, documentId] = parsedUrl.pathname.split("/");
|
|
239
244
|
if (!documentId || !tenantId) {
|
|
@@ -245,17 +250,32 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
|
|
|
245
250
|
all: { driverVersion },
|
|
246
251
|
});
|
|
247
252
|
|
|
248
|
-
const
|
|
249
|
-
const ordererRestWrapper = await RouterliciousOrdererRestWrapper.load(
|
|
253
|
+
const ordererTokenFetcher = toInstrumentedR11sOrdererTokenFetcher(
|
|
250
254
|
tenantId,
|
|
251
255
|
documentId,
|
|
252
256
|
this.tokenProvider,
|
|
253
257
|
logger2,
|
|
258
|
+
);
|
|
259
|
+
const storageTokenFetcher = toInstrumentedR11sStorageTokenFetcher(
|
|
260
|
+
tenantId,
|
|
261
|
+
documentId,
|
|
262
|
+
this.tokenProvider,
|
|
263
|
+
logger2,
|
|
264
|
+
);
|
|
265
|
+
const ordererTokenP = ordererTokenFetcher();
|
|
266
|
+
const storageTokenP = storageTokenFetcher();
|
|
267
|
+
|
|
268
|
+
const rateLimiter = new RateLimiter(this.driverPolicies.maxConcurrentOrdererRequests);
|
|
269
|
+
const ordererRestWrapper = await RouterliciousOrdererRestWrapper.load(
|
|
270
|
+
ordererTokenFetcher,
|
|
271
|
+
logger2,
|
|
254
272
|
rateLimiter,
|
|
255
273
|
this.driverPolicies.enableRestLess,
|
|
274
|
+
undefined /* baseUrl */,
|
|
275
|
+
ordererTokenP,
|
|
256
276
|
);
|
|
257
277
|
|
|
258
|
-
const discoverFluidResolvedUrl = async (): Promise<
|
|
278
|
+
const discoverFluidResolvedUrl = async (): Promise<IResolvedUrl> => {
|
|
259
279
|
if (!this.driverPolicies.enableDiscovery) {
|
|
260
280
|
return resolvedUrl;
|
|
261
281
|
}
|
|
@@ -280,7 +300,7 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
|
|
|
280
300
|
);
|
|
281
301
|
return getDiscoveredFluidResolvedUrl(resolvedUrl, discoveredSession);
|
|
282
302
|
};
|
|
283
|
-
const fluidResolvedUrl:
|
|
303
|
+
const fluidResolvedUrl: IResolvedUrl =
|
|
284
304
|
session !== undefined
|
|
285
305
|
? getDiscoveredFluidResolvedUrl(resolvedUrl, session)
|
|
286
306
|
: await discoverFluidResolvedUrl();
|
|
@@ -295,6 +315,16 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
|
|
|
295
315
|
);
|
|
296
316
|
}
|
|
297
317
|
|
|
318
|
+
const storageRestWrapper = await RouterliciousStorageRestWrapper.load(
|
|
319
|
+
tenantId,
|
|
320
|
+
storageTokenFetcher,
|
|
321
|
+
logger2,
|
|
322
|
+
new RateLimiter(this.driverPolicies.maxConcurrentStorageRequests),
|
|
323
|
+
this.driverPolicies.enableRestLess,
|
|
324
|
+
storageUrl,
|
|
325
|
+
storageTokenP,
|
|
326
|
+
);
|
|
327
|
+
|
|
298
328
|
const documentStorageServicePolicies: IDocumentStorageServicePolicies = {
|
|
299
329
|
caching: this.driverPolicies.enablePrefetch
|
|
300
330
|
? LoaderCachingPolicy.Prefetch
|
|
@@ -320,6 +350,9 @@ export class RouterliciousDocumentServiceFactory implements IDocumentServiceFact
|
|
|
320
350
|
this.wholeSnapshotTreeCache,
|
|
321
351
|
this.shreddedSummaryTreeCache,
|
|
322
352
|
discoverFluidResolvedUrl,
|
|
353
|
+
storageRestWrapper,
|
|
354
|
+
storageTokenFetcher,
|
|
355
|
+
ordererTokenFetcher,
|
|
323
356
|
);
|
|
324
357
|
}
|
|
325
358
|
}
|