@fluidframework/driver-utils 2.0.0-internal.3.0.2 → 2.0.0-internal.3.2.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/.eslintrc.js +17 -19
- package/.mocharc.js +2 -2
- package/api-extractor.json +2 -2
- package/dist/blobAggregationStorage.d.ts +15 -2
- package/dist/blobAggregationStorage.d.ts.map +1 -1
- package/dist/blobAggregationStorage.js +22 -13
- package/dist/blobAggregationStorage.js.map +1 -1
- package/dist/blobCacheStorageService.d.ts.map +1 -1
- package/dist/blobCacheStorageService.js.map +1 -1
- package/dist/buildSnapshotTree.d.ts.map +1 -1
- package/dist/buildSnapshotTree.js.map +1 -1
- package/dist/documentStorageServiceProxy.d.ts.map +1 -1
- package/dist/documentStorageServiceProxy.js.map +1 -1
- package/dist/emptyDocumentDeltaStorageService.d.ts.map +1 -1
- package/dist/emptyDocumentDeltaStorageService.js.map +1 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js.map +1 -1
- package/dist/fluidResolvedUrl.d.ts.map +1 -1
- package/dist/fluidResolvedUrl.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/insecureUrlResolver.d.ts.map +1 -1
- package/dist/insecureUrlResolver.js +2 -1
- package/dist/insecureUrlResolver.js.map +1 -1
- package/dist/mapWithExpiration.d.ts.map +1 -1
- package/dist/mapWithExpiration.js +5 -3
- package/dist/mapWithExpiration.js.map +1 -1
- package/dist/messageRecognition.d.ts.map +1 -1
- package/dist/messageRecognition.js.map +1 -1
- package/dist/multiDocumentServiceFactory.d.ts.map +1 -1
- package/dist/multiDocumentServiceFactory.js.map +1 -1
- package/dist/multiUrlResolver.d.ts.map +1 -1
- package/dist/multiUrlResolver.js.map +1 -1
- package/dist/network.d.ts +1 -1
- package/dist/network.d.ts.map +1 -1
- package/dist/network.js +4 -3
- package/dist/network.js.map +1 -1
- package/dist/networkUtils.d.ts.map +1 -1
- package/dist/networkUtils.js +2 -3
- package/dist/networkUtils.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/parallelRequests.d.ts.map +1 -1
- package/dist/parallelRequests.js +19 -9
- package/dist/parallelRequests.js.map +1 -1
- package/dist/prefetchDocumentStorageService.d.ts.map +1 -1
- package/dist/prefetchDocumentStorageService.js.map +1 -1
- package/dist/rateLimiter.d.ts.map +1 -1
- package/dist/rateLimiter.js.map +1 -1
- package/dist/readAndParse.d.ts.map +1 -1
- package/dist/readAndParse.js.map +1 -1
- package/dist/runWithRetry.d.ts.map +1 -1
- package/dist/runWithRetry.js.map +1 -1
- package/dist/summaryForCreateNew.d.ts.map +1 -1
- package/dist/summaryForCreateNew.js.map +1 -1
- package/dist/treeConversions.d.ts.map +1 -1
- package/dist/treeConversions.js +1 -4
- package/dist/treeConversions.js.map +1 -1
- package/dist/treeUtils.d.ts +10 -10
- package/dist/treeUtils.d.ts.map +1 -1
- package/dist/treeUtils.js +10 -10
- package/dist/treeUtils.js.map +1 -1
- package/lib/blobAggregationStorage.d.ts +15 -2
- package/lib/blobAggregationStorage.d.ts.map +1 -1
- package/lib/blobAggregationStorage.js +22 -13
- package/lib/blobAggregationStorage.js.map +1 -1
- package/lib/blobCacheStorageService.d.ts.map +1 -1
- package/lib/blobCacheStorageService.js.map +1 -1
- package/lib/buildSnapshotTree.d.ts.map +1 -1
- package/lib/buildSnapshotTree.js.map +1 -1
- package/lib/documentStorageServiceProxy.d.ts.map +1 -1
- package/lib/documentStorageServiceProxy.js.map +1 -1
- package/lib/emptyDocumentDeltaStorageService.d.ts.map +1 -1
- package/lib/emptyDocumentDeltaStorageService.js.map +1 -1
- package/lib/error.d.ts.map +1 -1
- package/lib/error.js.map +1 -1
- package/lib/fluidResolvedUrl.d.ts.map +1 -1
- package/lib/fluidResolvedUrl.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/insecureUrlResolver.d.ts.map +1 -1
- package/lib/insecureUrlResolver.js +2 -1
- package/lib/insecureUrlResolver.js.map +1 -1
- package/lib/mapWithExpiration.d.ts.map +1 -1
- package/lib/mapWithExpiration.js +5 -3
- package/lib/mapWithExpiration.js.map +1 -1
- package/lib/messageRecognition.d.ts.map +1 -1
- package/lib/messageRecognition.js +1 -1
- package/lib/messageRecognition.js.map +1 -1
- package/lib/multiDocumentServiceFactory.d.ts.map +1 -1
- package/lib/multiDocumentServiceFactory.js.map +1 -1
- package/lib/multiUrlResolver.d.ts.map +1 -1
- package/lib/multiUrlResolver.js.map +1 -1
- package/lib/network.d.ts +1 -1
- package/lib/network.d.ts.map +1 -1
- package/lib/network.js +4 -3
- package/lib/network.js.map +1 -1
- package/lib/networkUtils.d.ts.map +1 -1
- package/lib/networkUtils.js +2 -3
- package/lib/networkUtils.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/parallelRequests.d.ts.map +1 -1
- package/lib/parallelRequests.js +19 -9
- package/lib/parallelRequests.js.map +1 -1
- package/lib/prefetchDocumentStorageService.d.ts.map +1 -1
- package/lib/prefetchDocumentStorageService.js.map +1 -1
- package/lib/rateLimiter.d.ts.map +1 -1
- package/lib/rateLimiter.js.map +1 -1
- package/lib/readAndParse.d.ts.map +1 -1
- package/lib/readAndParse.js.map +1 -1
- package/lib/runWithRetry.d.ts.map +1 -1
- package/lib/runWithRetry.js.map +1 -1
- package/lib/summaryForCreateNew.d.ts.map +1 -1
- package/lib/summaryForCreateNew.js.map +1 -1
- package/lib/treeConversions.d.ts.map +1 -1
- package/lib/treeConversions.js +4 -7
- package/lib/treeConversions.js.map +1 -1
- package/lib/treeUtils.d.ts +10 -10
- package/lib/treeUtils.d.ts.map +1 -1
- package/lib/treeUtils.js +11 -11
- package/lib/treeUtils.js.map +1 -1
- package/package.json +43 -64
- package/prettier.config.cjs +1 -1
- package/src/blobAggregationStorage.ts +380 -324
- package/src/blobCacheStorageService.ts +20 -17
- package/src/buildSnapshotTree.ts +54 -51
- package/src/documentStorageServiceProxy.ts +49 -43
- package/src/emptyDocumentDeltaStorageService.ts +11 -10
- package/src/error.ts +5 -7
- package/src/fluidResolvedUrl.ts +9 -6
- package/src/index.ts +5 -1
- package/src/insecureUrlResolver.ts +127 -116
- package/src/mapWithExpiration.ts +111 -104
- package/src/messageRecognition.ts +25 -19
- package/src/multiDocumentServiceFactory.ts +73 -62
- package/src/multiUrlResolver.ts +26 -29
- package/src/network.ts +114 -112
- package/src/networkUtils.ts +37 -34
- package/src/packageVersion.ts +1 -1
- package/src/parallelRequests.ts +571 -509
- package/src/prefetchDocumentStorageService.ts +76 -74
- package/src/rateLimiter.ts +29 -29
- package/src/readAndParse.ts +7 -4
- package/src/runWithRetry.ts +105 -94
- package/src/summaryForCreateNew.ts +27 -24
- package/src/treeConversions.ts +48 -70
- package/src/treeUtils.ts +70 -74
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +8 -12
|
@@ -4,113 +4,122 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
FetchSource,
|
|
8
|
+
IDocumentStorageService,
|
|
9
|
+
IDocumentStorageServicePolicies,
|
|
10
|
+
ISummaryContext,
|
|
10
11
|
} from "@fluidframework/driver-definitions";
|
|
11
12
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
ICreateBlobResponse,
|
|
14
|
+
ISnapshotTree,
|
|
15
|
+
ISummaryHandle,
|
|
16
|
+
ISummaryTree,
|
|
17
|
+
IVersion,
|
|
18
|
+
SummaryType,
|
|
18
19
|
} from "@fluidframework/protocol-definitions";
|
|
19
20
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
assert,
|
|
22
|
+
bufferToString,
|
|
23
|
+
stringToBuffer,
|
|
24
|
+
unreachableCase,
|
|
25
|
+
fromUtf8ToBase64,
|
|
26
|
+
Uint8ArrayToString,
|
|
27
|
+
} from "@fluidframework/common-utils";
|
|
27
28
|
import { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
28
29
|
import { loggerToMonitoringContext } from "@fluidframework/telemetry-utils";
|
|
29
30
|
|
|
30
31
|
/*
|
|
31
32
|
* Work around for bufferToString having a bug - it can't consume IsoBuffer!
|
|
32
33
|
* To be removed once bufferToString is fixed!
|
|
33
|
-
*/
|
|
34
|
+
*/
|
|
34
35
|
function bufferToString2(blob: ArrayBufferLike, encoding: "utf-8" | "base64"): string {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
if (blob instanceof Uint8Array) {
|
|
37
|
+
// IsoBuffer does not have ctor, so it's not in proto chain :(
|
|
38
|
+
return Uint8ArrayToString(blob, encoding);
|
|
39
|
+
}
|
|
40
|
+
return bufferToString(blob, encoding);
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Class responsible for aggregating smaller blobs into one and unpacking it later on.
|
|
45
|
+
*/
|
|
44
46
|
class BlobAggregator {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
47
|
+
private readonly content: [string, string][] = [];
|
|
48
|
+
|
|
49
|
+
public addBlob(key: string, content: string) {
|
|
50
|
+
this.content.push([key, content]);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public getAggregatedBlobContent() {
|
|
54
|
+
if (this.content.length === 0) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
return JSON.stringify(this.content);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static load(input: ArrayBufferLike) {
|
|
61
|
+
const data = bufferToString2(input, "utf-8");
|
|
62
|
+
return JSON.parse(data) as [string, string][];
|
|
63
|
+
}
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
|
|
66
|
+
/**
|
|
65
67
|
* Base class that deals with unpacking snapshots (in place) containing aggregated blobs
|
|
66
68
|
* It relies on abstract methods for reads and storing unpacked blobs.
|
|
69
|
+
*
|
|
70
|
+
* @deprecated This class was introduced experimentally and is no longer used.
|
|
67
71
|
*/
|
|
68
72
|
export abstract class SnapshotExtractor {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
73
|
+
protected readonly aggregatedBlobName = "__big";
|
|
74
|
+
protected readonly virtualIdPrefix = "__";
|
|
75
|
+
|
|
76
|
+
// counter for generation of virtual storage IDs
|
|
77
|
+
protected virtualIdCounter = 0;
|
|
78
|
+
protected getNextVirtualId() {
|
|
79
|
+
return `${this.virtualIdPrefix}${++this.virtualIdCounter}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
abstract getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike>;
|
|
83
|
+
abstract setBlob(id: string, tree: ISnapshotTree, content: string);
|
|
84
|
+
|
|
85
|
+
public async unpackSnapshotCore(snapshot: ISnapshotTree, level = 0): Promise<void> {
|
|
86
|
+
for (const key of Object.keys(snapshot.trees)) {
|
|
87
|
+
const obj = snapshot.trees[key];
|
|
88
|
+
await this.unpackSnapshotCore(obj, level + 1);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// For future proof, we will support multiple aggregated blobs with any name
|
|
92
|
+
// that starts with this.aggregatedBlobName
|
|
93
|
+
for (const key of Object.keys(snapshot.blobs)) {
|
|
94
|
+
if (!key.startsWith(this.aggregatedBlobName)) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const blobId = snapshot.blobs[key];
|
|
98
|
+
if (blobId !== undefined) {
|
|
99
|
+
const blob = await this.getBlob(blobId, snapshot);
|
|
100
|
+
for (const [path, value] of BlobAggregator.load(blob)) {
|
|
101
|
+
const id = this.getNextVirtualId();
|
|
102
|
+
this.setBlob(id, snapshot, value);
|
|
103
|
+
const pathSplit = path.split("/");
|
|
104
|
+
let subTree = snapshot;
|
|
105
|
+
for (const subPath of pathSplit.slice(0, pathSplit.length - 1)) {
|
|
106
|
+
if (subTree.trees[subPath] === undefined) {
|
|
107
|
+
subTree.trees[subPath] = { blobs: {}, trees: {} };
|
|
108
|
+
}
|
|
109
|
+
subTree = subTree.trees[subPath];
|
|
110
|
+
}
|
|
111
|
+
const blobName = pathSplit[pathSplit.length - 1];
|
|
112
|
+
assert(
|
|
113
|
+
subTree.blobs[blobName] === undefined,
|
|
114
|
+
0x0f6 /* "real blob ID exists" */,
|
|
115
|
+
);
|
|
116
|
+
subTree.blobs[blobName] = id;
|
|
117
|
+
}
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
119
|
+
delete snapshot.blobs[this.aggregatedBlobName];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
114
123
|
}
|
|
115
124
|
|
|
116
125
|
/*
|
|
@@ -127,248 +136,295 @@ export abstract class SnapshotExtractor {
|
|
|
127
136
|
* fixing existing flows to allow switching of storage.
|
|
128
137
|
*/
|
|
129
138
|
class SnapshotExtractorInPlace extends SnapshotExtractor {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
139
|
+
public async getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike> {
|
|
140
|
+
const blob = tree.blobs[id];
|
|
141
|
+
assert(blob !== undefined, 0x0f7 /* "aggregate blob missing" */);
|
|
142
|
+
return stringToBuffer(blob, "base64");
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public setBlob(id: string, tree: ISnapshotTree, content: string) {
|
|
146
|
+
assert(
|
|
147
|
+
tree.blobs[id] === undefined,
|
|
148
|
+
0x0f8 /* "blob from aggregate blob exists on its own" */,
|
|
149
|
+
);
|
|
150
|
+
tree.blobs[id] = fromUtf8ToBase64(content);
|
|
151
|
+
}
|
|
140
152
|
}
|
|
141
153
|
|
|
142
|
-
|
|
154
|
+
/**
|
|
143
155
|
* Snapshot packer and extractor.
|
|
144
156
|
* When summary is written it will find and aggregate small blobs into bigger blobs
|
|
145
157
|
* When snapshot is read, it will unpack aggregated blobs and provide them transparently to caller.
|
|
158
|
+
*
|
|
159
|
+
* @deprecated This class was introduced experimentally and is no longer used.
|
|
146
160
|
*/
|
|
147
161
|
export class BlobAggregationStorage extends SnapshotExtractor implements IDocumentStorageService {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
162
|
+
// Tells data store if it can use incremental summary (i.e. reuse DDSes from previous summary
|
|
163
|
+
// when only one DDS changed).
|
|
164
|
+
// The answer has to be know long before we enable actual packing. The reason for the is the following:
|
|
165
|
+
// A the moment when we enable packing, we should assume that all clients out there wil already have bits
|
|
166
|
+
// that can unpack properly (i.e. enough time passed since we deployed bits that can unpack)
|
|
167
|
+
// But we can still have clients where some of them already pack, and some do not. If one summary was
|
|
168
|
+
// using packing, then it relies on non-incremental summaries going forward, even if next client who
|
|
169
|
+
// produced summary is not packing!
|
|
170
|
+
// This can have slight improvement by enabling it per file (based on "did summary we loaded from contain
|
|
171
|
+
// aggregated blobs"), but that's harder to make reliable, so going for simplicity.
|
|
172
|
+
static readonly fullDataStoreSummaries = true;
|
|
173
|
+
|
|
174
|
+
protected loadedFromSummary = false;
|
|
175
|
+
|
|
176
|
+
protected virtualBlobs = new Map<string, ArrayBufferLike>();
|
|
177
|
+
|
|
178
|
+
static wrap(
|
|
179
|
+
storage: IDocumentStorageService,
|
|
180
|
+
logger: ITelemetryLogger,
|
|
181
|
+
allowPacking?: boolean,
|
|
182
|
+
packingLevel = 2,
|
|
183
|
+
) {
|
|
184
|
+
if (storage instanceof BlobAggregationStorage) {
|
|
185
|
+
return storage;
|
|
186
|
+
}
|
|
187
|
+
const mc = loggerToMonitoringContext(logger);
|
|
188
|
+
const realAllowPackaging =
|
|
189
|
+
mc.config.getBoolean("FluidAggregateBlobs") ?? allowPacking ?? false;
|
|
190
|
+
|
|
191
|
+
// Always create BlobAggregationStorage even if storage is not asking for packing.
|
|
192
|
+
// This is mostly to avoid cases where future changes in policy would result in inability to
|
|
193
|
+
// load old files that were created with aggregation on.
|
|
194
|
+
const minBlobSize = storage.policies?.minBlobSize;
|
|
195
|
+
return new BlobAggregationStorage(
|
|
196
|
+
storage,
|
|
197
|
+
logger,
|
|
198
|
+
realAllowPackaging,
|
|
199
|
+
packingLevel,
|
|
200
|
+
minBlobSize,
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
static async unpackSnapshot(snapshot: ISnapshotTree) {
|
|
205
|
+
const converter = new SnapshotExtractorInPlace();
|
|
206
|
+
await converter.unpackSnapshotCore(snapshot);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
public get policies(): IDocumentStorageServicePolicies | undefined {
|
|
210
|
+
const policies = this.storage.policies;
|
|
211
|
+
if (policies) {
|
|
212
|
+
return { ...policies, minBlobSize: undefined };
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
public async unpackSnapshot(snapshot: ISnapshotTree) {
|
|
217
|
+
// SummarizerNodeWithGC.refreshLatestSummary can call it when this.loadedFromSummary === false
|
|
218
|
+
// (I assumed after file was created)
|
|
219
|
+
// assert(!this.loadedFromSummary, "unpack without summary");
|
|
220
|
+
|
|
221
|
+
this.loadedFromSummary = true;
|
|
222
|
+
await this.unpackSnapshotCore(snapshot);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
protected constructor(
|
|
226
|
+
private readonly storage: IDocumentStorageService,
|
|
227
|
+
private readonly logger: ITelemetryLogger,
|
|
228
|
+
private readonly allowPacking: boolean,
|
|
229
|
+
private readonly packingLevel: number,
|
|
230
|
+
private readonly blobCutOffSize?: number,
|
|
231
|
+
) {
|
|
232
|
+
super();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
public setBlob(id: string, tree: ISnapshotTree, content: string) {
|
|
236
|
+
this.virtualBlobs.set(id, stringToBuffer(content, "utf-8"));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
public async getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike> {
|
|
240
|
+
return this.readBlob(id).catch((error) => {
|
|
241
|
+
this.logger.sendErrorEvent({ eventName: "BlobDedupNoAggregateBlob" }, error);
|
|
242
|
+
throw error;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
public get repositoryUrl() {
|
|
247
|
+
return this.storage.repositoryUrl;
|
|
248
|
+
}
|
|
249
|
+
public async getVersions(
|
|
250
|
+
versionId: string | null,
|
|
251
|
+
count: number,
|
|
252
|
+
scenarioName?: string,
|
|
253
|
+
fetchSource?: FetchSource,
|
|
254
|
+
) {
|
|
255
|
+
return this.storage.getVersions(versionId, count, scenarioName, fetchSource);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {
|
|
259
|
+
throw new Error("NYI");
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// for now we are not optimizing these blobs, with assumption that this API is used only
|
|
263
|
+
// for big blobs (images)
|
|
264
|
+
public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {
|
|
265
|
+
return this.storage.createBlob(file);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
public async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {
|
|
269
|
+
const tree = await this.storage.getSnapshotTree(version);
|
|
270
|
+
if (tree) {
|
|
271
|
+
await this.unpackSnapshot(tree);
|
|
272
|
+
}
|
|
273
|
+
return tree;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
public async readBlob(id: string): Promise<ArrayBufferLike> {
|
|
277
|
+
if (this.isRealStorageId(id)) {
|
|
278
|
+
return this.storage.readBlob(id);
|
|
279
|
+
}
|
|
280
|
+
// We support only reading blobs from the summary we loaded from.
|
|
281
|
+
// This may need to be extended to any general summary in the future as runtime usage pattern
|
|
282
|
+
// of storage changes (for example, data stores start to load from recent summary, not from original
|
|
283
|
+
// summary whole container loaded from)
|
|
284
|
+
|
|
285
|
+
// are there other ways we can get here? createFile is one flow, but we should not be reading blobs
|
|
286
|
+
// in such flow
|
|
287
|
+
assert(this.loadedFromSummary, 0x0f9 /* "never read summary" */);
|
|
288
|
+
const blob = this.virtualBlobs.get(id);
|
|
289
|
+
assert(blob !== undefined, 0x0fa /* "virtual blob not found" */);
|
|
290
|
+
return blob;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
public async uploadSummaryWithContext(
|
|
294
|
+
summary: ISummaryTree,
|
|
295
|
+
context: ISummaryContext,
|
|
296
|
+
): Promise<string> {
|
|
297
|
+
const summaryNew = this.allowPacking ? await this.compressSmallBlobs(summary) : summary;
|
|
298
|
+
return this.storage.uploadSummaryWithContext(summaryNew, context);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// For simplification, we assume that
|
|
302
|
+
// - blob aggregation is done at data store level only for now
|
|
303
|
+
// - data store either reuses previous summary, or generates full summary, i.e. there is no partial (some DDS)
|
|
304
|
+
// summary produced by data stores.
|
|
305
|
+
// These simplifications allow us not to touch handles, as they are self-contained (either do not use aggregated
|
|
306
|
+
// blob or contain aggregated blob that stays relevant for that sub-tree)
|
|
307
|
+
// Note:
|
|
308
|
+
// From perf perspective, it makes sense to place aggregated blobs one level up in the tree to not create extra
|
|
309
|
+
// tree nodes (i.e. have shallow tree with less edges). But that creates problems with reusability of trees at
|
|
310
|
+
// incremental summary time - we would need to understand handles and parse them. In current design we can skip
|
|
311
|
+
// that step because if data store is reused, the whole sub-tree is reused including aggregated blob embedded into it
|
|
312
|
+
// and that means we can do nothing and be correct!
|
|
313
|
+
private async compressSmallBlobs(
|
|
314
|
+
summary: ISummaryTree,
|
|
315
|
+
path = "",
|
|
316
|
+
level = 0,
|
|
317
|
+
aggregatorArg?: BlobAggregator,
|
|
318
|
+
): Promise<ISummaryTree> {
|
|
319
|
+
if (this.blobCutOffSize === undefined || this.blobCutOffSize < 0) {
|
|
320
|
+
return summary;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
let shouldCompress: boolean = false;
|
|
324
|
+
|
|
325
|
+
let aggregator = aggregatorArg;
|
|
326
|
+
// checking if this is a dataStore tree, since we only pack at data store level
|
|
327
|
+
if (Object.keys(summary.tree).includes(".component")) {
|
|
328
|
+
assert(aggregator === undefined, 0x0fb /* "logic err with aggregator" */);
|
|
329
|
+
assert(
|
|
330
|
+
level === this.packingLevel,
|
|
331
|
+
0x23b /* "we are not packing at the right level" */,
|
|
332
|
+
);
|
|
333
|
+
aggregator = new BlobAggregator();
|
|
334
|
+
shouldCompress = true;
|
|
335
|
+
} else {
|
|
336
|
+
assert(
|
|
337
|
+
level !== this.packingLevel,
|
|
338
|
+
0x23c /* "we are not packing at the right level" */,
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const newSummary: ISummaryTree = { ...summary };
|
|
343
|
+
newSummary.tree = { ...newSummary.tree };
|
|
344
|
+
for (const key of Object.keys(summary.tree)) {
|
|
345
|
+
const obj = summary.tree[key];
|
|
346
|
+
// Get path relative to root of data store (where we do aggregation)
|
|
347
|
+
const newPath = shouldCompress ? key : `${path}/${key}`;
|
|
348
|
+
switch (obj.type) {
|
|
349
|
+
case SummaryType.Tree:
|
|
350
|
+
// If client created empty tree, keep it as is
|
|
351
|
+
// Also do not package search blobs - they are part of storage contract
|
|
352
|
+
if (Object.keys(obj).length !== 0 && key !== "__search") {
|
|
353
|
+
const tree = await this.compressSmallBlobs(
|
|
354
|
+
obj,
|
|
355
|
+
newPath,
|
|
356
|
+
level + 1,
|
|
357
|
+
aggregator,
|
|
358
|
+
);
|
|
359
|
+
newSummary.tree[key] = tree;
|
|
360
|
+
if (Object.keys(obj).length === 0) {
|
|
361
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
362
|
+
delete newSummary.tree[key];
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
break;
|
|
366
|
+
case SummaryType.Blob:
|
|
367
|
+
if (
|
|
368
|
+
aggregator &&
|
|
369
|
+
typeof obj.content == "string" &&
|
|
370
|
+
obj.content.length < this.blobCutOffSize
|
|
371
|
+
) {
|
|
372
|
+
aggregator.addBlob(newPath, obj.content);
|
|
373
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
374
|
+
delete newSummary.tree[key];
|
|
375
|
+
}
|
|
376
|
+
break;
|
|
377
|
+
case SummaryType.Handle: {
|
|
378
|
+
// Would be nice to:
|
|
379
|
+
// Trees: expand the tree
|
|
380
|
+
// Blobs: parse handle and ensure it points to real blob, not virtual blob.
|
|
381
|
+
// We can avoid it for now given data store is the granularity of incremental summaries.
|
|
382
|
+
let handlePath = obj.handle;
|
|
383
|
+
if (handlePath.startsWith("/")) {
|
|
384
|
+
handlePath = handlePath.substr(1);
|
|
385
|
+
}
|
|
386
|
+
// Ensure only whole data stores can be reused, no reusing at deeper level!
|
|
387
|
+
assert(level === 0, 0x0fc /* "tree reuse at lower level" */);
|
|
388
|
+
assert(
|
|
389
|
+
!handlePath.includes("/"),
|
|
390
|
+
0x0fd /* "data stores are writing incremental summaries!" */,
|
|
391
|
+
);
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
case SummaryType.Attachment:
|
|
395
|
+
assert(
|
|
396
|
+
this.isRealStorageId(obj.id),
|
|
397
|
+
0x0fe /* "attachment is aggregate blob" */,
|
|
398
|
+
);
|
|
399
|
+
break;
|
|
400
|
+
default:
|
|
401
|
+
unreachableCase(obj, `Unknown type: ${(obj as any).type}`);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
assert(
|
|
406
|
+
newSummary.tree[this.aggregatedBlobName] === undefined,
|
|
407
|
+
0x0ff /* "duplicate aggregate blob" */,
|
|
408
|
+
);
|
|
409
|
+
if (shouldCompress) {
|
|
410
|
+
// Note: It would be great to add code here to unpack aggregate blob back to normal blobs
|
|
411
|
+
// If only one blob made it into aggregate. Currently that does not happen as we always have
|
|
412
|
+
// at least one .component blob and at least one DDS that has .attributes blob, so it's not an issue.
|
|
413
|
+
// But it's possible that in future that would be great addition!
|
|
414
|
+
// Good news - it's backward compatible change.
|
|
415
|
+
assert(aggregator !== undefined, 0x100 /* "logic error" */);
|
|
416
|
+
const content = aggregator.getAggregatedBlobContent();
|
|
417
|
+
if (content !== undefined) {
|
|
418
|
+
newSummary.tree[this.aggregatedBlobName] = {
|
|
419
|
+
type: SummaryType.Blob,
|
|
420
|
+
content,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return newSummary;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
protected isRealStorageId(id: string): boolean {
|
|
428
|
+
return !id.startsWith(this.virtualIdPrefix);
|
|
429
|
+
}
|
|
374
430
|
}
|