@fluidframework/routerlicious-driver 2.0.0-dev.4.1.0.148229 → 2.0.0-dev.4.3.0.157531
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 +5 -0
- package/README.md +38 -0
- package/dist/contracts.d.ts +15 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +7 -0
- package/dist/contracts.js.map +1 -0
- package/dist/deltaStorageService.d.ts +1 -1
- package/dist/deltaStorageService.d.ts.map +1 -1
- package/dist/deltaStorageService.js +7 -4
- package/dist/deltaStorageService.js.map +1 -1
- package/dist/documentService.d.ts +4 -2
- package/dist/documentService.d.ts.map +1 -1
- package/dist/documentService.js +11 -9
- package/dist/documentService.js.map +1 -1
- package/dist/documentServiceFactory.d.ts +2 -1
- package/dist/documentServiceFactory.d.ts.map +1 -1
- package/dist/documentServiceFactory.js +18 -8
- package/dist/documentServiceFactory.js.map +1 -1
- package/dist/documentStorageService.d.ts +3 -2
- package/dist/documentStorageService.d.ts.map +1 -1
- package/dist/documentStorageService.js +4 -4
- package/dist/documentStorageService.js.map +1 -1
- package/dist/gitManager.d.ts +30 -0
- package/dist/gitManager.d.ts.map +1 -0
- package/dist/gitManager.js +89 -0
- package/dist/gitManager.js.map +1 -0
- package/dist/historian.d.ts +33 -0
- package/dist/historian.d.ts.map +1 -0
- package/dist/historian.js +65 -0
- package/dist/historian.js.map +1 -0
- 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 +15 -0
- package/dist/r11sSnapshotParser.d.ts.map +1 -0
- package/dist/r11sSnapshotParser.js +75 -0
- package/dist/r11sSnapshotParser.js.map +1 -0
- package/dist/restWrapper.d.ts +21 -8
- package/dist/restWrapper.d.ts.map +1 -1
- package/dist/restWrapper.js +93 -25
- package/dist/restWrapper.js.map +1 -1
- package/dist/restWrapperBase.d.ts +26 -0
- package/dist/restWrapperBase.d.ts.map +1 -0
- package/dist/restWrapperBase.js +55 -0
- package/dist/restWrapperBase.js.map +1 -0
- package/dist/retriableGitManager.d.ts +10 -21
- package/dist/retriableGitManager.d.ts.map +1 -1
- package/dist/retriableGitManager.js +0 -36
- package/dist/retriableGitManager.js.map +1 -1
- package/dist/shreddedSummaryDocumentStorageService.d.ts +1 -1
- package/dist/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
- package/dist/shreddedSummaryDocumentStorageService.js +6 -6
- package/dist/shreddedSummaryDocumentStorageService.js.map +1 -1
- package/dist/storageContracts.d.ts +44 -0
- package/dist/storageContracts.d.ts.map +1 -0
- package/dist/storageContracts.js +7 -0
- package/dist/storageContracts.js.map +1 -0
- package/dist/summaryTreeUploadManager.d.ts +23 -0
- package/dist/summaryTreeUploadManager.d.ts.map +1 -0
- package/dist/summaryTreeUploadManager.js +110 -0
- package/dist/summaryTreeUploadManager.js.map +1 -0
- package/dist/treeUtils.d.ts +7 -0
- package/dist/treeUtils.d.ts.map +1 -1
- package/dist/treeUtils.js +23 -1
- package/dist/treeUtils.js.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.d.ts +5 -4
- package/dist/wholeSummaryDocumentStorageService.d.ts.map +1 -1
- package/dist/wholeSummaryDocumentStorageService.js +74 -42
- package/dist/wholeSummaryDocumentStorageService.js.map +1 -1
- package/dist/wholeSummaryUploadManager.d.ts +16 -0
- package/dist/wholeSummaryUploadManager.d.ts.map +1 -0
- package/dist/wholeSummaryUploadManager.js +38 -0
- package/dist/wholeSummaryUploadManager.js.map +1 -0
- package/lib/contracts.d.ts +15 -0
- package/lib/contracts.d.ts.map +1 -0
- package/lib/contracts.js +6 -0
- package/lib/contracts.js.map +1 -0
- package/lib/deltaStorageService.d.ts +1 -1
- package/lib/deltaStorageService.d.ts.map +1 -1
- package/lib/deltaStorageService.js +7 -4
- package/lib/deltaStorageService.js.map +1 -1
- package/lib/documentService.d.ts +4 -2
- package/lib/documentService.d.ts.map +1 -1
- package/lib/documentService.js +9 -7
- package/lib/documentService.js.map +1 -1
- package/lib/documentServiceFactory.d.ts +2 -1
- package/lib/documentServiceFactory.d.ts.map +1 -1
- package/lib/documentServiceFactory.js +18 -8
- package/lib/documentServiceFactory.js.map +1 -1
- package/lib/documentStorageService.d.ts +3 -2
- package/lib/documentStorageService.d.ts.map +1 -1
- package/lib/documentStorageService.js +4 -4
- package/lib/documentStorageService.js.map +1 -1
- package/lib/gitManager.d.ts +30 -0
- package/lib/gitManager.d.ts.map +1 -0
- package/lib/gitManager.js +85 -0
- package/lib/gitManager.js.map +1 -0
- package/lib/historian.d.ts +33 -0
- package/lib/historian.d.ts.map +1 -0
- package/lib/historian.js +60 -0
- package/lib/historian.js.map +1 -0
- 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 +15 -0
- package/lib/r11sSnapshotParser.d.ts.map +1 -0
- package/lib/r11sSnapshotParser.js +71 -0
- package/lib/r11sSnapshotParser.js.map +1 -0
- package/lib/restWrapper.d.ts +21 -8
- package/lib/restWrapper.d.ts.map +1 -1
- package/lib/restWrapper.js +92 -26
- package/lib/restWrapper.js.map +1 -1
- package/lib/restWrapperBase.d.ts +26 -0
- package/lib/restWrapperBase.d.ts.map +1 -0
- package/lib/restWrapperBase.js +50 -0
- package/lib/restWrapperBase.js.map +1 -0
- package/lib/retriableGitManager.d.ts +10 -21
- package/lib/retriableGitManager.d.ts.map +1 -1
- package/lib/retriableGitManager.js +0 -36
- package/lib/retriableGitManager.js.map +1 -1
- package/lib/shreddedSummaryDocumentStorageService.d.ts +1 -1
- package/lib/shreddedSummaryDocumentStorageService.d.ts.map +1 -1
- package/lib/shreddedSummaryDocumentStorageService.js +5 -5
- package/lib/shreddedSummaryDocumentStorageService.js.map +1 -1
- package/lib/storageContracts.d.ts +44 -0
- package/lib/storageContracts.d.ts.map +1 -0
- package/lib/storageContracts.js +6 -0
- package/lib/storageContracts.js.map +1 -0
- package/lib/summaryTreeUploadManager.d.ts +23 -0
- package/lib/summaryTreeUploadManager.d.ts.map +1 -0
- package/lib/summaryTreeUploadManager.js +106 -0
- package/lib/summaryTreeUploadManager.js.map +1 -0
- package/lib/treeUtils.d.ts +7 -0
- package/lib/treeUtils.d.ts.map +1 -1
- package/lib/treeUtils.js +20 -0
- package/lib/treeUtils.js.map +1 -1
- package/lib/wholeSummaryDocumentStorageService.d.ts +5 -4
- package/lib/wholeSummaryDocumentStorageService.d.ts.map +1 -1
- package/lib/wholeSummaryDocumentStorageService.js +74 -42
- package/lib/wholeSummaryDocumentStorageService.js.map +1 -1
- package/lib/wholeSummaryUploadManager.d.ts +16 -0
- package/lib/wholeSummaryUploadManager.d.ts.map +1 -0
- package/lib/wholeSummaryUploadManager.js +34 -0
- package/lib/wholeSummaryUploadManager.js.map +1 -0
- package/package.json +9 -10
- package/src/contracts.ts +16 -0
- package/src/deltaStorageService.ts +11 -3
- package/src/documentService.ts +11 -11
- package/src/documentServiceFactory.ts +35 -16
- package/src/documentStorageService.ts +8 -4
- package/src/gitManager.ts +116 -0
- package/src/historian.ts +121 -0
- package/src/packageVersion.ts +1 -1
- package/src/r11sSnapshotParser.ts +83 -0
- package/src/restWrapper.ts +114 -38
- package/src/restWrapperBase.ts +146 -0
- package/src/retriableGitManager.ts +17 -95
- package/src/shreddedSummaryDocumentStorageService.ts +7 -9
- package/src/storageContracts.ts +63 -0
- package/src/summaryTreeUploadManager.ts +160 -0
- package/src/treeUtils.ts +30 -0
- package/src/wholeSummaryDocumentStorageService.ts +117 -58
- package/src/wholeSummaryUploadManager.ts +64 -0
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
import type { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
6
6
|
import { IDocumentStorageService, ISummaryContext, IDocumentStorageServicePolicies } from "@fluidframework/driver-definitions";
|
|
7
7
|
import { ICreateBlobResponse, ISnapshotTree, ISummaryHandle, ISummaryTree, IVersion } from "@fluidframework/protocol-definitions";
|
|
8
|
-
import { GitManager } from "@fluidframework/server-services-client";
|
|
9
8
|
import { ICache } from "./cache";
|
|
10
|
-
import { ISnapshotTreeVersion } from "./definitions";
|
|
11
9
|
import { IRouterliciousDriverPolicies } from "./policies";
|
|
10
|
+
import { GitManager } from "./gitManager";
|
|
11
|
+
import { INormalizedWholeSummary } from "./contracts";
|
|
12
12
|
export declare class WholeSummaryDocumentStorageService implements IDocumentStorageService {
|
|
13
13
|
protected readonly id: string;
|
|
14
14
|
protected readonly manager: GitManager;
|
|
@@ -22,14 +22,15 @@ 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: ITelemetryLogger, policies: IDocumentStorageServicePolicies, driverPolicies?: IRouterliciousDriverPolicies | undefined, blobCache?: ICache<ArrayBufferLike>, snapshotTreeCache?: ICache<
|
|
25
|
+
constructor(id: string, manager: GitManager, logger: ITelemetryLogger, 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>;
|
|
29
29
|
uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string>;
|
|
30
30
|
downloadSummary(summaryHandle: ISummaryHandle): Promise<ISummaryTree>;
|
|
31
31
|
createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse>;
|
|
32
|
-
private
|
|
32
|
+
private fetchSnapshotTree;
|
|
33
|
+
private initializeFromSnapshot;
|
|
33
34
|
private initBlobCache;
|
|
34
35
|
private getCacheKey;
|
|
35
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wholeSummaryDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/wholeSummaryDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"wholeSummaryDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/wholeSummaryDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAQ3E,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;AAG9C,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,gBAAgB;aAC3B,QAAQ,EAAE,+BAA+B;IACzD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC;IACnC,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IApBnC,OAAO,CAAC,iBAAiB,CAAiB;IAE1C,IAAW,aAAa,IAAI,MAAM,CAEjC;YAEa,uBAAuB;gBAMjB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,gBAAgB,EAC3B,QAAQ,EAAE,+BAA+B,EACxC,cAAc,CAAC,0CAA8B,EAC7C,SAAS,GAAE,MAAM,CAAC,eAAe,CAAuB,EACxD,iBAAiB,GAAE,MAAM,CAAC,uBAAuB,CAAuB,EACxE,iBAAiB,CAAC,wBAAY,EAC9B,iBAAiB,GAAE,CACnC,YAAY,CAAC,EAAE,OAAO,KAClB,OAAO,CAAC,UAAU,CAGP;IAGJ,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAyFzE,eAAe,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAqBlE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IA4BlD,wBAAwB,CACpC,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,eAAe,GACtB,OAAO,CAAC,MAAM,CAAC;IAqBL,eAAe,CAAC,aAAa,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAwBrE,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,mBAAmB,CAAC;YAqB9D,iBAAiB;YA4CjB,sBAAsB;YAetB,aAAa;IAS3B,OAAO,CAAC,WAAW;CAGnB"}
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { assert, stringToBuffer, Uint8ArrayToString } from "@fluidframework/common-utils";
|
|
6
|
-
import {
|
|
5
|
+
import { assert, performance, stringToBuffer, Uint8ArrayToString, } from "@fluidframework/common-utils";
|
|
6
|
+
import { getW3CData, promiseRaceWithWinner } from "@fluidframework/driver-base";
|
|
7
7
|
import { PerformanceEvent } from "@fluidframework/telemetry-utils";
|
|
8
8
|
import { InMemoryCache } from "./cache";
|
|
9
|
-
import { convertSnapshotAndBlobsToSummaryTree } from "./treeUtils";
|
|
9
|
+
import { convertSnapshotAndBlobsToSummaryTree, evalBlobsAndTrees, validateBlobsAndTrees, } from "./treeUtils";
|
|
10
|
+
import { WholeSummaryUploadManager } from "./wholeSummaryUploadManager";
|
|
11
|
+
import { convertWholeFlatSummaryToSnapshotTreeAndBlobs } from "./r11sSnapshotParser";
|
|
10
12
|
const latestSnapshotId = "latest";
|
|
11
13
|
export class WholeSummaryDocumentStorageService {
|
|
12
14
|
constructor(id, manager, logger, policies, driverPolicies, blobCache = new InMemoryCache(), snapshotTreeCache = new InMemoryCache(), noCacheGitManager, getStorageManager = async (disableCache) => disableCache && this.noCacheGitManager !== undefined
|
|
@@ -44,14 +46,47 @@ export class WholeSummaryDocumentStorageService {
|
|
|
44
46
|
// If this is the first versions call for the document, we know we will want the latest summary.
|
|
45
47
|
// Fetch latest summary, cache it, and return its id.
|
|
46
48
|
if (this.firstVersionsCall && count === 1) {
|
|
49
|
+
const normalizedSnapshotContents = await PerformanceEvent.timedExecAsync(this.logger, {
|
|
50
|
+
eventName: "ObtainSnapshot",
|
|
51
|
+
versionId: versionId !== null && versionId !== void 0 ? versionId : undefined,
|
|
52
|
+
count,
|
|
53
|
+
enableDiscovery: (_a = this.driverPolicies) === null || _a === void 0 ? void 0 : _a.enableDiscovery,
|
|
54
|
+
}, async (event) => {
|
|
55
|
+
var _a;
|
|
56
|
+
let method;
|
|
57
|
+
const cachedSnapshotP = this.snapshotTreeCache.get(this.getCacheKey(latestSnapshotId));
|
|
58
|
+
const networkSnapshotP = !((_a = this.driverPolicies) === null || _a === void 0 ? void 0 : _a.enableDiscovery)
|
|
59
|
+
? this.fetchSnapshotTree(latestSnapshotId, false, "getVersions")
|
|
60
|
+
: this.fetchSnapshotTree(latestSnapshotId, true, "getVersions");
|
|
61
|
+
const promiseRaceWinner = await promiseRaceWithWinner([
|
|
62
|
+
cachedSnapshotP.catch(() => undefined),
|
|
63
|
+
networkSnapshotP.catch(() => undefined),
|
|
64
|
+
]);
|
|
65
|
+
let retrievedSnapshot = promiseRaceWinner.value;
|
|
66
|
+
method = promiseRaceWinner.index === 0 ? "cache" : "network";
|
|
67
|
+
if (retrievedSnapshot === undefined) {
|
|
68
|
+
// if network failed -> wait for cache ( then return network failure)
|
|
69
|
+
// If cache returned empty or failed -> wait for network (success of failure)
|
|
70
|
+
if (promiseRaceWinner.index === 1) {
|
|
71
|
+
retrievedSnapshot = await cachedSnapshotP;
|
|
72
|
+
method = "cache";
|
|
73
|
+
}
|
|
74
|
+
if (retrievedSnapshot === undefined) {
|
|
75
|
+
retrievedSnapshot = await networkSnapshotP;
|
|
76
|
+
method = "network";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
event.end({
|
|
80
|
+
method,
|
|
81
|
+
});
|
|
82
|
+
return retrievedSnapshot;
|
|
83
|
+
});
|
|
84
|
+
const _id = await this.initializeFromSnapshot(normalizedSnapshotContents);
|
|
47
85
|
this.firstVersionsCall = false;
|
|
48
|
-
const { id: _id, snapshotTree } = !((_a = this.driverPolicies) === null || _a === void 0 ? void 0 : _a.enableDiscovery)
|
|
49
|
-
? await this.fetchAndCacheSnapshotTree(latestSnapshotId, false)
|
|
50
|
-
: await this.fetchAndCacheSnapshotTree(latestSnapshotId, true);
|
|
51
86
|
return [
|
|
52
87
|
{
|
|
53
88
|
id: _id,
|
|
54
|
-
treeId: snapshotTree.id,
|
|
89
|
+
treeId: normalizedSnapshotContents.snapshotTree.id,
|
|
55
90
|
},
|
|
56
91
|
];
|
|
57
92
|
}
|
|
@@ -63,7 +98,7 @@ export class WholeSummaryDocumentStorageService {
|
|
|
63
98
|
count,
|
|
64
99
|
}, async () => {
|
|
65
100
|
const manager = await this.getStorageManager();
|
|
66
|
-
return manager.getCommits(id, count);
|
|
101
|
+
return (await manager.getCommits(id, count)).content;
|
|
67
102
|
});
|
|
68
103
|
return commits.map((commit) => ({
|
|
69
104
|
date: commit.commit.author.date,
|
|
@@ -80,7 +115,12 @@ export class WholeSummaryDocumentStorageService {
|
|
|
80
115
|
}
|
|
81
116
|
requestVersion = versions[0];
|
|
82
117
|
}
|
|
83
|
-
|
|
118
|
+
const normalizedWholeSnapshot = await this.snapshotTreeCache.get(this.getCacheKey(requestVersion.id));
|
|
119
|
+
if (normalizedWholeSnapshot !== undefined) {
|
|
120
|
+
return normalizedWholeSnapshot.snapshotTree;
|
|
121
|
+
}
|
|
122
|
+
return (await this.fetchSnapshotTree(requestVersion.id, undefined, "getSnapshotTree"))
|
|
123
|
+
.snapshotTree;
|
|
84
124
|
}
|
|
85
125
|
async readBlob(blobId) {
|
|
86
126
|
const cachedBlob = await this.blobCache.get(this.getCacheKey(blobId));
|
|
@@ -92,7 +132,7 @@ export class WholeSummaryDocumentStorageService {
|
|
|
92
132
|
blobId,
|
|
93
133
|
}, async (event) => {
|
|
94
134
|
const manager = await this.getStorageManager();
|
|
95
|
-
const response = await manager.getBlob(blobId);
|
|
135
|
+
const response = (await manager.getBlob(blobId)).content;
|
|
96
136
|
event.end({
|
|
97
137
|
size: response.size,
|
|
98
138
|
});
|
|
@@ -124,9 +164,9 @@ export class WholeSummaryDocumentStorageService {
|
|
|
124
164
|
const manager = await this.getStorageManager();
|
|
125
165
|
const response = await manager.getSummary(summaryHandle.handle);
|
|
126
166
|
event.end({
|
|
127
|
-
size: (_a = response.trees[0]) === null || _a === void 0 ? void 0 : _a.entries.length,
|
|
167
|
+
size: (_a = response.content.trees[0]) === null || _a === void 0 ? void 0 : _a.entries.length,
|
|
128
168
|
});
|
|
129
|
-
return response;
|
|
169
|
+
return response.content;
|
|
130
170
|
});
|
|
131
171
|
const { blobs, snapshotTree } = convertWholeFlatSummaryToSnapshotTreeAndBlobs(wholeFlatSummary, "");
|
|
132
172
|
return convertSnapshotAndBlobsToSummaryTree(snapshotTree, blobs);
|
|
@@ -140,53 +180,45 @@ export class WholeSummaryDocumentStorageService {
|
|
|
140
180
|
const manager = await this.getStorageManager();
|
|
141
181
|
const response = await manager
|
|
142
182
|
.createBlob(Uint8ArrayToString(uint8ArrayFile, "base64"), "base64")
|
|
143
|
-
.then((r) => ({ id: r.sha, url: r.url }));
|
|
183
|
+
.then((r) => ({ id: r.content.sha, url: r.content.url }));
|
|
144
184
|
event.end({
|
|
145
185
|
blobId: response.id,
|
|
146
186
|
});
|
|
147
187
|
return response;
|
|
148
188
|
});
|
|
149
189
|
}
|
|
150
|
-
async
|
|
151
|
-
const
|
|
152
|
-
if (cachedSnapshotTreeVersion !== undefined) {
|
|
153
|
-
return {
|
|
154
|
-
id: cachedSnapshotTreeVersion.id,
|
|
155
|
-
snapshotTree: cachedSnapshotTreeVersion.snapshotTree,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
const wholeFlatSummary = await PerformanceEvent.timedExecAsync(this.logger, {
|
|
190
|
+
async fetchSnapshotTree(versionId, disableCache, scenarioName) {
|
|
191
|
+
const normalizedWholeSummary = await PerformanceEvent.timedExecAsync(this.logger, {
|
|
159
192
|
eventName: "getWholeFlatSummary",
|
|
160
193
|
treeId: versionId,
|
|
194
|
+
scenarioName,
|
|
161
195
|
}, async (event) => {
|
|
162
196
|
var _a;
|
|
163
197
|
const manager = await this.getStorageManager(disableCache);
|
|
164
198
|
const response = await manager.getSummary(versionId);
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
199
|
+
const start = performance.now();
|
|
200
|
+
const snapshot = convertWholeFlatSummaryToSnapshotTreeAndBlobs(response.content);
|
|
201
|
+
const snapshotConversionTime = performance.now() - start;
|
|
202
|
+
validateBlobsAndTrees(snapshot.snapshotTree);
|
|
203
|
+
const { trees, numBlobs, encodedBlobsSize } = evalBlobsAndTrees(snapshot);
|
|
204
|
+
event.end(Object.assign(Object.assign(Object.assign({ size: (_a = response.content.trees[0]) === null || _a === void 0 ? void 0 : _a.entries.length, trees, blobs: numBlobs, encodedBlobsSize }, response.propsToLog), { snapshotConversionTime }), getW3CData(response.requestUrl, "xmlhttprequest")));
|
|
205
|
+
return snapshot;
|
|
169
206
|
});
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
207
|
+
// Also add the result into the cache.
|
|
208
|
+
await this.snapshotTreeCache
|
|
209
|
+
.put(this.getCacheKey(versionId), normalizedWholeSummary)
|
|
210
|
+
.catch(() => undefined);
|
|
211
|
+
return normalizedWholeSummary;
|
|
212
|
+
}
|
|
213
|
+
async initializeFromSnapshot(normalizedWholeSummary) {
|
|
214
|
+
const snapshotId = normalizedWholeSummary.id;
|
|
215
|
+
assert(snapshotId !== undefined, 0x275 /* "Root tree should contain the id" */);
|
|
177
216
|
const cachePs = [
|
|
178
|
-
this.snapshotTreeCache.put(this.getCacheKey(
|
|
217
|
+
this.snapshotTreeCache.put(this.getCacheKey(snapshotId), normalizedWholeSummary),
|
|
179
218
|
this.initBlobCache(normalizedWholeSummary.blobs),
|
|
180
219
|
];
|
|
181
|
-
if (wholeFlatSummaryId !== versionId) {
|
|
182
|
-
// versionId could be "latest". When summarizer checks cache for "latest", we want it to be available.
|
|
183
|
-
// TODO: For in-memory cache, <latest,snapshotTree> will be a shared pointer with <snapshotId,snapshotTree>,
|
|
184
|
-
// However, for something like Redis, this will cache the same value twice. Alternatively, could we simply
|
|
185
|
-
// cache with versionId?
|
|
186
|
-
cachePs.push(this.snapshotTreeCache.put(this.getCacheKey(versionId), snapshotTreeVersion));
|
|
187
|
-
}
|
|
188
220
|
await Promise.all(cachePs);
|
|
189
|
-
return
|
|
221
|
+
return snapshotId;
|
|
190
222
|
}
|
|
191
223
|
async initBlobCache(blobs) {
|
|
192
224
|
const blobCach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,WAAW,CAAC,kBAAkB,CAAC,EAAE,mBAAmB,CAAC;YACrF,IAAI,CAAC,aAAa,CAAC,sBAAsB,CAAC,KAAK,CAAC;SAChD,CAAC;QACF,IAAI,kBAAkB,KAAK,SAAS,EAAE;YACrC,sGAAsG;YACtG,4GAA4G;YAC5G,0GAA0G;YAC1G,wBAAwB;YACxB,OAAO,CAAC,IAAI,CACX,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,mBAAmB,CAAC,CAC5E,CAAC;SACF;QAED,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAE3B,OAAO,mBAAmB,CAAC;IAC5B,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 { assert, stringToBuffer, Uint8ArrayToString } from \"@fluidframework/common-utils\";\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 {\n\tconvertWholeFlatSummaryToSnapshotTreeAndBlobs,\n\tGitManager,\n\tISummaryUploadManager,\n\tWholeSummaryUploadManager,\n} from \"@fluidframework/server-services-client\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { ICache, InMemoryCache } from \"./cache\";\nimport { ISnapshotTreeVersion } from \"./definitions\";\nimport { IRouterliciousDriverPolicies } from \"./policies\";\nimport { convertSnapshotAndBlobsToSummaryTree } from \"./treeUtils\";\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<ISnapshotTreeVersion> = 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\tthis.firstVersionsCall = false;\n\t\t\tconst { id: _id, snapshotTree } = !this.driverPolicies?.enableDiscovery\n\t\t\t\t? await this.fetchAndCacheSnapshotTree(latestSnapshotId, false)\n\t\t\t\t: await this.fetchAndCacheSnapshotTree(latestSnapshotId, true);\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: _id,\n\t\t\t\t\ttreeId: 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 manager.getCommits(id, count);\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\treturn (await this.fetchAndCacheSnapshotTree(requestVersion.id)).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);\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.trees[0]?.entries.length,\n\t\t\t\t});\n\t\t\t\treturn response;\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.sha, url: r.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 fetchAndCacheSnapshotTree(\n\t\tversionId: string,\n\t\tdisableCache?: boolean,\n\t): Promise<ISnapshotTreeVersion> {\n\t\tconst cachedSnapshotTreeVersion = await this.snapshotTreeCache.get(\n\t\t\tthis.getCacheKey(versionId),\n\t\t);\n\t\tif (cachedSnapshotTreeVersion !== undefined) {\n\t\t\treturn {\n\t\t\t\tid: cachedSnapshotTreeVersion.id,\n\t\t\t\tsnapshotTree: cachedSnapshotTreeVersion.snapshotTree,\n\t\t\t};\n\t\t}\n\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: versionId,\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 = await manager.getSummary(versionId);\n\t\t\t\tevent.end({\n\t\t\t\t\tsize: response.trees[0]?.entries.length,\n\t\t\t\t});\n\t\t\t\treturn response;\n\t\t\t},\n\t\t);\n\t\tconst normalizedWholeSummary =\n\t\t\tconvertWholeFlatSummaryToSnapshotTreeAndBlobs(wholeFlatSummary);\n\t\tassert(\n\t\t\tnormalizedWholeSummary.snapshotTree.id !== undefined,\n\t\t\t0x275 /* \"Root tree should contain the id\" */,\n\t\t);\n\t\tconst wholeFlatSummaryId: string = wholeFlatSummary.id;\n\t\tconst snapshotTreeVersion = {\n\t\t\tid: wholeFlatSummaryId,\n\t\t\tsnapshotTree: normalizedWholeSummary.snapshotTree,\n\t\t};\n\n\t\tconst cachePs: Promise<any>[] = [\n\t\t\tthis.snapshotTreeCache.put(this.getCacheKey(wholeFlatSummaryId), snapshotTreeVersion),\n\t\t\tthis.initBlobCache(normalizedWholeSummary.blobs),\n\t\t];\n\t\tif (wholeFlatSummaryId !== versionId) {\n\t\t\t// versionId could be \"latest\". When summarizer checks cache for \"latest\", we want it to be available.\n\t\t\t// TODO: For in-memory cache, <latest,snapshotTree> will be a shared pointer with <snapshotId,snapshotTree>,\n\t\t\t// However, for something like Redis, this will cache the same value twice. Alternatively, could we simply\n\t\t\t// cache with versionId?\n\t\t\tcachePs.push(\n\t\t\t\tthis.snapshotTreeCache.put(this.getCacheKey(versionId), snapshotTreeVersion),\n\t\t\t);\n\t\t}\n\n\t\tawait Promise.all(cachePs);\n\n\t\treturn snapshotTreeVersion;\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;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,EACnB,MAAwB,EAC3B,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;QACnD,CAAC,CAAC,IAAI,CAAC,iBAAiB;QACxB,CAAC,CAAC,IAAI,CAAC,OAAO;QAbG,OAAE,GAAF,EAAE,CAAQ;QACV,YAAO,GAAP,OAAO,CAAY;QACnB,WAAM,GAAN,MAAM,CAAkB;QAC3B,aAAQ,GAAR,QAAQ,CAAiC;QACxC,mBAAc,GAAd,cAAc,CAA+B;QAC7C,cAAS,GAAT,SAAS,CAA+C;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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"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { ISummaryTree, IWholeSummaryPayloadType } from "@fluidframework/server-services-client";
|
|
6
|
+
import { IGitManager, ISummaryUploadManager } from "./storageContracts";
|
|
7
|
+
/**
|
|
8
|
+
* Converts summary to snapshot tree and uploads with single snaphot tree payload.
|
|
9
|
+
*/
|
|
10
|
+
export declare class WholeSummaryUploadManager implements ISummaryUploadManager {
|
|
11
|
+
private readonly manager;
|
|
12
|
+
constructor(manager: IGitManager);
|
|
13
|
+
writeSummaryTree(summaryTree: ISummaryTree, parentHandle: string | undefined, summaryType: IWholeSummaryPayloadType, sequenceNumber?: number, initial?: boolean): Promise<string>;
|
|
14
|
+
private writeSummaryTreeCore;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=wholeSummaryUploadManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wholeSummaryUploadManager.d.ts","sourceRoot":"","sources":["../src/wholeSummaryUploadManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,YAAY,EAEZ,wBAAwB,EAExB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAExE;;GAEG;AACH,qBAAa,yBAA0B,YAAW,qBAAqB;IAC1D,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,WAAW;IAEpC,gBAAgB,CAC5B,WAAW,EAAE,YAAY,EACzB,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,WAAW,EAAE,wBAAwB,EACrC,cAAc,GAAE,MAAU,EAC1B,OAAO,GAAE,OAAe,GACtB,OAAO,CAAC,MAAM,CAAC;YAcJ,oBAAoB;CAwBlC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { convertSummaryTreeToWholeSummaryTree, } from "@fluidframework/server-services-client";
|
|
6
|
+
/**
|
|
7
|
+
* Converts summary to snapshot tree and uploads with single snaphot tree payload.
|
|
8
|
+
*/
|
|
9
|
+
export class WholeSummaryUploadManager {
|
|
10
|
+
constructor(manager) {
|
|
11
|
+
this.manager = manager;
|
|
12
|
+
}
|
|
13
|
+
async writeSummaryTree(summaryTree, parentHandle, summaryType, sequenceNumber = 0, initial = false) {
|
|
14
|
+
const id = await this.writeSummaryTreeCore(parentHandle, summaryTree, summaryType, sequenceNumber, initial);
|
|
15
|
+
if (!id) {
|
|
16
|
+
throw new Error(`Failed to write summary tree`);
|
|
17
|
+
}
|
|
18
|
+
return id;
|
|
19
|
+
}
|
|
20
|
+
async writeSummaryTreeCore(parentHandle, tree, type, sequenceNumber, initial) {
|
|
21
|
+
var _a;
|
|
22
|
+
const snapshotTree = convertSummaryTreeToWholeSummaryTree(parentHandle, tree, "", type === "channel" ? ".app" : "");
|
|
23
|
+
const snapshotPayload = {
|
|
24
|
+
entries: (_a = snapshotTree.entries) !== null && _a !== void 0 ? _a : [],
|
|
25
|
+
message: "",
|
|
26
|
+
sequenceNumber,
|
|
27
|
+
type,
|
|
28
|
+
};
|
|
29
|
+
return this.manager
|
|
30
|
+
.createSummary(snapshotPayload, initial)
|
|
31
|
+
.then((response) => response.content.id);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=wholeSummaryUploadManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wholeSummaryUploadManager.js","sourceRoot":"","sources":["../src/wholeSummaryUploadManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAIN,oCAAoC,GACpC,MAAM,wCAAwC,CAAC;AAGhD;;GAEG;AACH,MAAM,OAAO,yBAAyB;IACrC,YAA6B,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;IAAG,CAAC;IAE9C,KAAK,CAAC,gBAAgB,CAC5B,WAAyB,EACzB,YAAgC,EAChC,WAAqC,EACrC,iBAAyB,CAAC,EAC1B,UAAmB,KAAK;QAExB,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,oBAAoB,CACzC,YAAY,EACZ,WAAW,EACX,WAAW,EACX,cAAc,EACd,OAAO,CACP,CAAC;QACF,IAAI,CAAC,EAAE,EAAE;YACR,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SAChD;QACD,OAAO,EAAE,CAAC;IACX,CAAC;IAEO,KAAK,CAAC,oBAAoB,CACjC,YAAgC,EAChC,IAAkB,EAClB,IAA8B,EAC9B,cAAsB,EACtB,OAAgB;;QAEhB,MAAM,YAAY,GAAG,oCAAoC,CACxD,YAAY,EACZ,IAAI,EACJ,EAAE,EACF,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAChC,CAAC;QACF,MAAM,eAAe,GAAyB;YAC7C,OAAO,EAAE,MAAA,YAAY,CAAC,OAAO,mCAAI,EAAE;YACnC,OAAO,EAAE,EAAE;YACX,cAAc;YACd,IAAI;SACJ,CAAC;QAEF,OAAO,IAAI,CAAC,OAAO;aACjB,aAAa,CAAC,eAAe,EAAE,OAAO,CAAC;aACvC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC3C,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tISummaryTree,\n\tIWholeSummaryPayload,\n\tIWholeSummaryPayloadType,\n\tconvertSummaryTreeToWholeSummaryTree,\n} from \"@fluidframework/server-services-client\";\nimport { IGitManager, ISummaryUploadManager } from \"./storageContracts\";\n\n/**\n * Converts summary to snapshot tree and uploads with single snaphot tree payload.\n */\nexport class WholeSummaryUploadManager implements ISummaryUploadManager {\n\tconstructor(private readonly manager: IGitManager) {}\n\n\tpublic async writeSummaryTree(\n\t\tsummaryTree: ISummaryTree,\n\t\tparentHandle: string | undefined,\n\t\tsummaryType: IWholeSummaryPayloadType,\n\t\tsequenceNumber: number = 0,\n\t\tinitial: boolean = false,\n\t): Promise<string> {\n\t\tconst id = await this.writeSummaryTreeCore(\n\t\t\tparentHandle,\n\t\t\tsummaryTree,\n\t\t\tsummaryType,\n\t\t\tsequenceNumber,\n\t\t\tinitial,\n\t\t);\n\t\tif (!id) {\n\t\t\tthrow new Error(`Failed to write summary tree`);\n\t\t}\n\t\treturn id;\n\t}\n\n\tprivate async writeSummaryTreeCore(\n\t\tparentHandle: string | undefined,\n\t\ttree: ISummaryTree,\n\t\ttype: IWholeSummaryPayloadType,\n\t\tsequenceNumber: number,\n\t\tinitial: boolean,\n\t): Promise<string> {\n\t\tconst snapshotTree = convertSummaryTreeToWholeSummaryTree(\n\t\t\tparentHandle,\n\t\t\ttree,\n\t\t\t\"\",\n\t\t\ttype === \"channel\" ? \".app\" : \"\",\n\t\t);\n\t\tconst snapshotPayload: IWholeSummaryPayload = {\n\t\t\tentries: snapshotTree.entries ?? [],\n\t\t\tmessage: \"\",\n\t\t\tsequenceNumber,\n\t\t\ttype,\n\t\t};\n\n\t\treturn this.manager\n\t\t\t.createSummary(snapshotPayload, initial)\n\t\t\t.then((response) => response.content.id);\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-dev.4.
|
|
3
|
+
"version": "2.0.0-dev.4.3.0.157531",
|
|
4
4
|
"description": "Socket.IO + Git implementation of Fluid service API",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -37,28 +37,27 @@
|
|
|
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-dev.4.
|
|
41
|
-
"@fluidframework/driver-definitions": "2.0.0-dev.4.
|
|
42
|
-
"@fluidframework/driver-utils": "2.0.0-dev.4.
|
|
40
|
+
"@fluidframework/driver-base": "2.0.0-dev.4.3.0.157531",
|
|
41
|
+
"@fluidframework/driver-definitions": "2.0.0-dev.4.3.0.157531",
|
|
42
|
+
"@fluidframework/driver-utils": "2.0.0-dev.4.3.0.157531",
|
|
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-dev.4.
|
|
47
|
+
"@fluidframework/telemetry-utils": "2.0.0-dev.4.3.0.157531",
|
|
48
48
|
"cross-fetch": "^3.1.5",
|
|
49
49
|
"json-stringify-safe": "5.0.1",
|
|
50
|
-
"querystring": "^0.2.0",
|
|
51
50
|
"socket.io-client": "^4.4.1",
|
|
52
51
|
"url-parse": "^1.5.8",
|
|
53
52
|
"uuid": "^8.3.1"
|
|
54
53
|
},
|
|
55
54
|
"devDependencies": {
|
|
56
|
-
"@fluid-tools/build-cli": "^0.
|
|
55
|
+
"@fluid-tools/build-cli": "^0.17.0",
|
|
57
56
|
"@fluidframework/build-common": "^1.1.0",
|
|
58
|
-
"@fluidframework/build-tools": "^0.
|
|
57
|
+
"@fluidframework/build-tools": "^0.17.0",
|
|
59
58
|
"@fluidframework/eslint-config-fluid": "^2.0.0",
|
|
60
|
-
"@fluidframework/mocha-test-setup": "2.0.0-dev.4.
|
|
61
|
-
"@fluidframework/routerlicious-driver-previous": "npm:@fluidframework/routerlicious-driver@2.0.0-internal.4.
|
|
59
|
+
"@fluidframework/mocha-test-setup": "2.0.0-dev.4.3.0.157531",
|
|
60
|
+
"@fluidframework/routerlicious-driver-previous": "npm:@fluidframework/routerlicious-driver@2.0.0-internal.4.1.0",
|
|
62
61
|
"@microsoft/api-extractor": "^7.34.4",
|
|
63
62
|
"@types/mocha": "^9.1.1",
|
|
64
63
|
"@types/nock": "^9.3.0",
|
package/src/contracts.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ISnapshotTree } from "@fluidframework/protocol-definitions";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Normalized Whole Summary with decoded blobs and unflattened snapshot tree.
|
|
10
|
+
*/
|
|
11
|
+
export interface INormalizedWholeSummary {
|
|
12
|
+
blobs: Map<string, ArrayBuffer>;
|
|
13
|
+
snapshotTree: ISnapshotTree;
|
|
14
|
+
sequenceNumber: number | undefined;
|
|
15
|
+
id: string;
|
|
16
|
+
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { getW3CData } from "@fluidframework/driver-base";
|
|
6
7
|
import {
|
|
7
8
|
IDeltaStorageService,
|
|
8
9
|
IDocumentDeltaStorageService,
|
|
@@ -13,8 +14,8 @@ import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions"
|
|
|
13
14
|
import { readAndParse, requestOps, emptyMessageStream } from "@fluidframework/driver-utils";
|
|
14
15
|
import { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
15
16
|
import { PerformanceEvent, TelemetryNullLogger } from "@fluidframework/telemetry-utils";
|
|
16
|
-
import { RestWrapper } from "@fluidframework/server-services-client";
|
|
17
17
|
import { DocumentStorageService } from "./documentStorageService";
|
|
18
|
+
import { RestWrapper } from "./restWrapperBase";
|
|
18
19
|
|
|
19
20
|
const MaxBatchDeltas = 2000; // Maximum number of ops we can fetch at a time
|
|
20
21
|
|
|
@@ -120,9 +121,16 @@ export class DeltaStorageService implements IDeltaStorageService {
|
|
|
120
121
|
to,
|
|
121
122
|
});
|
|
122
123
|
event.end({
|
|
123
|
-
|
|
124
|
+
length: response.content.length,
|
|
125
|
+
details: JSON.stringify({
|
|
126
|
+
firstOpSeqNumber: response.content[0]?.sequenceNumber,
|
|
127
|
+
lastOpSeqNumber:
|
|
128
|
+
response.content[response.content.length - 1]?.sequenceNumber,
|
|
129
|
+
}),
|
|
130
|
+
...response.propsToLog,
|
|
131
|
+
...getW3CData(response.requestUrl, "xmlhttprequest"),
|
|
124
132
|
});
|
|
125
|
-
return response;
|
|
133
|
+
return response.content;
|
|
126
134
|
},
|
|
127
135
|
);
|
|
128
136
|
|
package/src/documentService.ts
CHANGED
|
@@ -8,7 +8,6 @@ import * as api from "@fluidframework/driver-definitions";
|
|
|
8
8
|
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
|
-
import { GitManager, Historian, RestWrapper } from "@fluidframework/server-services-client";
|
|
12
11
|
import io from "socket.io-client";
|
|
13
12
|
import { PerformanceEvent, wrapError } from "@fluidframework/telemetry-utils";
|
|
14
13
|
import { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
@@ -22,6 +21,10 @@ import { IRouterliciousDriverPolicies } from "./policies";
|
|
|
22
21
|
import { ICache } from "./cache";
|
|
23
22
|
import { ISnapshotTreeVersion } from "./definitions";
|
|
24
23
|
import { pkgVersion as driverVersion } from "./packageVersion";
|
|
24
|
+
import { GitManager } from "./gitManager";
|
|
25
|
+
import { Historian } from "./historian";
|
|
26
|
+
import { RestWrapper } from "./restWrapperBase";
|
|
27
|
+
import { INormalizedWholeSummary } from "./contracts";
|
|
25
28
|
|
|
26
29
|
/**
|
|
27
30
|
* Amount of time between discoveries within which we don't need to rediscover on re-connect.
|
|
@@ -61,7 +64,8 @@ export class DocumentService implements api.IDocumentService {
|
|
|
61
64
|
private readonly documentStorageServicePolicies: api.IDocumentStorageServicePolicies,
|
|
62
65
|
private readonly driverPolicies: IRouterliciousDriverPolicies,
|
|
63
66
|
private readonly blobCache: ICache<ArrayBufferLike>,
|
|
64
|
-
private readonly
|
|
67
|
+
private readonly wholeSnapshotTreeCache: ICache<INormalizedWholeSummary>,
|
|
68
|
+
private readonly shreddedSummaryTreeCache: ICache<ISnapshotTreeVersion>,
|
|
65
69
|
private readonly discoverFluidResolvedUrl: () => Promise<api.IFluidResolvedUrl>,
|
|
66
70
|
) {}
|
|
67
71
|
|
|
@@ -105,14 +109,9 @@ export class DocumentService implements api.IDocumentService {
|
|
|
105
109
|
this.driverPolicies.enableRestLess,
|
|
106
110
|
this.storageUrl,
|
|
107
111
|
);
|
|
108
|
-
const historian = new Historian(
|
|
112
|
+
const historian = new Historian(true, false, storageRestWrapper);
|
|
109
113
|
this.storageManager = new GitManager(historian);
|
|
110
|
-
const noCacheHistorian = new Historian(
|
|
111
|
-
this.storageUrl,
|
|
112
|
-
true,
|
|
113
|
-
true,
|
|
114
|
-
storageRestWrapper,
|
|
115
|
-
);
|
|
114
|
+
const noCacheHistorian = new Historian(true, true, storageRestWrapper);
|
|
116
115
|
this.noCacheStorageManager = new GitManager(noCacheHistorian);
|
|
117
116
|
}
|
|
118
117
|
|
|
@@ -128,7 +127,8 @@ export class DocumentService implements api.IDocumentService {
|
|
|
128
127
|
this.documentStorageServicePolicies,
|
|
129
128
|
this.driverPolicies,
|
|
130
129
|
this.blobCache,
|
|
131
|
-
this.
|
|
130
|
+
this.wholeSnapshotTreeCache,
|
|
131
|
+
this.shreddedSummaryTreeCache,
|
|
132
132
|
noCacheStorageManager,
|
|
133
133
|
getStorageManager,
|
|
134
134
|
);
|
|
@@ -187,7 +187,7 @@ export class DocumentService implements api.IDocumentService {
|
|
|
187
187
|
*/
|
|
188
188
|
public async connectToDeltaStream(client: IClient): Promise<api.IDocumentDeltaConnection> {
|
|
189
189
|
const connect = async (refreshToken?: boolean) => {
|
|
190
|
-
let ordererToken = this.ordererRestWrapper.getToken();
|
|
190
|
+
let ordererToken = await this.ordererRestWrapper.getToken();
|
|
191
191
|
if (this.shouldUpdateDiscoveredSessionInfo()) {
|
|
192
192
|
await this.refreshDiscovery();
|
|
193
193
|
}
|