@fluidframework/odsp-driver 1.1.0 → 1.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/dist/checkUrl.d.ts +1 -1
- package/dist/checkUrl.js +1 -1
- package/dist/checkUrl.js.map +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/contractsPublic.d.ts +1 -0
- package/dist/contractsPublic.d.ts.map +1 -1
- package/dist/contractsPublic.js.map +1 -1
- package/dist/getFileLink.js +0 -4
- package/dist/getFileLink.js.map +1 -1
- package/dist/localOdspDriver/localOdspDocumentService.d.ts +26 -0
- package/dist/localOdspDriver/localOdspDocumentService.d.ts.map +1 -0
- package/dist/localOdspDriver/localOdspDocumentService.js +39 -0
- package/dist/localOdspDriver/localOdspDocumentService.js.map +1 -0
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.d.ts +24 -0
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.d.ts.map +1 -0
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.js +45 -0
- package/dist/localOdspDriver/localOdspDocumentServiceFactory.js.map +1 -0
- package/dist/localOdspDriver/localOdspDocumentStorageManager.d.ts +27 -0
- package/dist/localOdspDriver/localOdspDocumentStorageManager.d.ts.map +1 -0
- package/dist/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
- package/dist/localOdspDriver/localOdspDocumentStorageManager.js.map +1 -0
- package/dist/odspDeltaStorageService.js.map +1 -1
- package/dist/odspDocumentService.d.ts.map +1 -1
- package/dist/odspDocumentService.js.map +1 -1
- package/dist/odspDocumentServiceFactory.d.ts +2 -1
- package/dist/odspDocumentServiceFactory.d.ts.map +1 -1
- package/dist/odspDocumentServiceFactory.js +7 -1
- package/dist/odspDocumentServiceFactory.js.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.d.ts +3 -1
- package/dist/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/dist/odspDocumentServiceFactoryCore.js.map +1 -1
- package/dist/odspDocumentStorageManager.d.ts +5 -23
- package/dist/odspDocumentStorageManager.d.ts.map +1 -1
- package/dist/odspDocumentStorageManager.js +52 -245
- package/dist/odspDocumentStorageManager.js.map +1 -1
- package/dist/odspDocumentStorageServiceBase.d.ts +58 -0
- package/dist/odspDocumentStorageServiceBase.d.ts.map +1 -0
- package/dist/odspDocumentStorageServiceBase.js +216 -0
- package/dist/odspDocumentStorageServiceBase.js.map +1 -0
- package/dist/odspDriverUrlResolver.js +1 -1
- package/dist/odspDriverUrlResolver.js.map +1 -1
- package/dist/odspDriverUrlResolverForShareLink.d.ts +8 -2
- package/dist/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
- package/dist/odspDriverUrlResolverForShareLink.js +11 -3
- package/dist/odspDriverUrlResolverForShareLink.js.map +1 -1
- package/dist/odspFluidFileLink.d.ts.map +1 -1
- package/dist/odspFluidFileLink.js +27 -21
- package/dist/odspFluidFileLink.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/lib/checkUrl.d.ts +1 -1
- package/lib/checkUrl.js +1 -1
- package/lib/checkUrl.js.map +1 -1
- package/lib/constants.d.ts +1 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +1 -1
- package/lib/constants.js.map +1 -1
- package/lib/contractsPublic.d.ts +1 -0
- package/lib/contractsPublic.d.ts.map +1 -1
- package/lib/contractsPublic.js.map +1 -1
- package/lib/getFileLink.js +0 -4
- package/lib/getFileLink.js.map +1 -1
- package/lib/localOdspDriver/localOdspDocumentService.d.ts +26 -0
- package/lib/localOdspDriver/localOdspDocumentService.d.ts.map +1 -0
- package/lib/localOdspDriver/localOdspDocumentService.js +35 -0
- package/lib/localOdspDriver/localOdspDocumentService.js.map +1 -0
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.d.ts +24 -0
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.d.ts.map +1 -0
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.js +41 -0
- package/lib/localOdspDriver/localOdspDocumentServiceFactory.js.map +1 -0
- package/lib/localOdspDriver/localOdspDocumentStorageManager.d.ts +27 -0
- package/lib/localOdspDriver/localOdspDocumentStorageManager.d.ts.map +1 -0
- package/lib/localOdspDriver/localOdspDocumentStorageManager.js +62 -0
- package/lib/localOdspDriver/localOdspDocumentStorageManager.js.map +1 -0
- package/lib/odspDeltaStorageService.js.map +1 -1
- package/lib/odspDocumentService.d.ts.map +1 -1
- package/lib/odspDocumentService.js +1 -1
- package/lib/odspDocumentService.js.map +1 -1
- package/lib/odspDocumentServiceFactory.d.ts +2 -1
- package/lib/odspDocumentServiceFactory.d.ts.map +1 -1
- package/lib/odspDocumentServiceFactory.js +5 -0
- package/lib/odspDocumentServiceFactory.js.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.d.ts +3 -1
- package/lib/odspDocumentServiceFactoryCore.d.ts.map +1 -1
- package/lib/odspDocumentServiceFactoryCore.js.map +1 -1
- package/lib/odspDocumentStorageManager.d.ts +5 -23
- package/lib/odspDocumentStorageManager.d.ts.map +1 -1
- package/lib/odspDocumentStorageManager.js +53 -246
- package/lib/odspDocumentStorageManager.js.map +1 -1
- package/lib/odspDocumentStorageServiceBase.d.ts +58 -0
- package/lib/odspDocumentStorageServiceBase.d.ts.map +1 -0
- package/lib/odspDocumentStorageServiceBase.js +212 -0
- package/lib/odspDocumentStorageServiceBase.js.map +1 -0
- package/lib/odspDriverUrlResolver.js +1 -1
- package/lib/odspDriverUrlResolver.js.map +1 -1
- package/lib/odspDriverUrlResolverForShareLink.d.ts +8 -2
- package/lib/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
- package/lib/odspDriverUrlResolverForShareLink.js +11 -3
- package/lib/odspDriverUrlResolverForShareLink.js.map +1 -1
- package/lib/odspFluidFileLink.d.ts.map +1 -1
- package/lib/odspFluidFileLink.js +27 -21
- package/lib/odspFluidFileLink.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/package.json +17 -12
- package/src/checkUrl.ts +1 -1
- package/src/constants.ts +1 -1
- package/src/contractsPublic.ts +1 -0
- package/src/getFileLink.ts +0 -5
- package/src/localOdspDriver/localOdspDocumentService.ts +54 -0
- package/src/localOdspDriver/localOdspDocumentServiceFactory.ts +67 -0
- package/src/localOdspDriver/localOdspDocumentStorageManager.ts +83 -0
- package/src/odspDeltaStorageService.ts +1 -1
- package/src/odspDocumentService.ts +5 -1
- package/src/odspDocumentServiceFactory.ts +7 -3
- package/src/odspDocumentServiceFactoryCore.ts +1 -1
- package/src/odspDocumentStorageManager.ts +81 -312
- package/src/odspDocumentStorageServiceBase.ts +268 -0
- package/src/odspDriverUrlResolver.ts +1 -1
- package/src/odspDriverUrlResolverForShareLink.ts +13 -1
- package/src/odspFluidFileLink.ts +26 -22
- package/src/packageVersion.ts +1 -1
|
@@ -13,9 +13,9 @@ const odsp_driver_definitions_1 = require("@fluidframework/odsp-driver-definitio
|
|
|
13
13
|
const fetchSnapshot_1 = require("./fetchSnapshot");
|
|
14
14
|
const getUrlAndHeadersWithAuth_1 = require("./getUrlAndHeadersWithAuth");
|
|
15
15
|
const odspUtils_1 = require("./odspUtils");
|
|
16
|
-
const epochTracker_1 = require("./epochTracker");
|
|
17
16
|
const odspSummaryUploadManager_1 = require("./odspSummaryUploadManager");
|
|
18
17
|
const packageVersion_1 = require("./packageVersion");
|
|
18
|
+
const odspDocumentStorageServiceBase_1 = require("./odspDocumentStorageServiceBase");
|
|
19
19
|
exports.defaultSummarizerCacheExpiryTimeout = 60 * 1000; // 60 seconds.
|
|
20
20
|
/* eslint-disable max-len */
|
|
21
21
|
// An implementation of Promise.race that gives you the winner of the promise race
|
|
@@ -26,98 +26,10 @@ async function promiseRaceWithWinner(promises) {
|
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
class
|
|
30
|
-
constructor() {
|
|
31
|
-
// If the defer flag is set when the timeout fires, we'll reschedule rather than clear immediately
|
|
32
|
-
// This deferral approach is used (rather than clearing/resetting the timer) as current calling patterns trigger
|
|
33
|
-
// too many calls to setTimeout/clearTimeout.
|
|
34
|
-
this.deferBlobCacheClear = false;
|
|
35
|
-
this._blobCache = new Map();
|
|
36
|
-
// Tracks all blob IDs evicted from cache
|
|
37
|
-
this.blobsEvicted = new Set();
|
|
38
|
-
// Initial time-out to purge data from cache
|
|
39
|
-
// If this time out is very small, then we purge blobs from cache too soon and that results in a lot of
|
|
40
|
-
// requests to storage, which brings down perf and may trip protection limits causing 429s
|
|
41
|
-
this.blobCacheTimeoutDuration = 2 * 60 * 1000;
|
|
42
|
-
// SPO does not keep old snapshots around for long, so we are running chances of not
|
|
43
|
-
// being able to rehydrate data store / DDS in the future if we purge anything (and with blob de-duping,
|
|
44
|
-
// even if blob read by runtime, it could be read again in the future)
|
|
45
|
-
// So for now, purging is disabled.
|
|
46
|
-
this.purgeEnabled = false;
|
|
47
|
-
}
|
|
48
|
-
get value() {
|
|
49
|
-
return this._blobCache;
|
|
50
|
-
}
|
|
51
|
-
addBlobs(blobs) {
|
|
52
|
-
blobs.forEach((value, blobId) => {
|
|
53
|
-
this._blobCache.set(blobId, value);
|
|
54
|
-
});
|
|
55
|
-
// Reset the timer on cache set
|
|
56
|
-
this.scheduleClearBlobsCache();
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Schedule a timer for clearing the blob cache or defer the current one.
|
|
60
|
-
*/
|
|
61
|
-
scheduleClearBlobsCache() {
|
|
62
|
-
if (this.blobCacheTimeout !== undefined) {
|
|
63
|
-
// If we already have an outstanding timer, just signal that we should defer the clear
|
|
64
|
-
this.deferBlobCacheClear = true;
|
|
65
|
-
}
|
|
66
|
-
else if (this.purgeEnabled) {
|
|
67
|
-
// If we don't have an outstanding timer, set a timer
|
|
68
|
-
// When the timer runs out, we'll decide whether to proceed with the cache clear or reset the timer
|
|
69
|
-
const clearCacheOrDefer = () => {
|
|
70
|
-
this.blobCacheTimeout = undefined;
|
|
71
|
-
if (this.deferBlobCacheClear) {
|
|
72
|
-
this.deferBlobCacheClear = false;
|
|
73
|
-
this.scheduleClearBlobsCache();
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
// NOTE: Slightly better algorithm here would be to purge either only big blobs,
|
|
77
|
-
// or sort them by size and purge enough big blobs to leave only 256Kb of small blobs in cache
|
|
78
|
-
// Purging is optimizing memory footprint. But count controls potential number of storage requests
|
|
79
|
-
// We want to optimize both - memory footprint and number of future requests to storage.
|
|
80
|
-
// Note that Container can realize data store or DDS on-demand at any point in time, so we do not
|
|
81
|
-
// control when blobs will be used.
|
|
82
|
-
this._blobCache.forEach((_, blobId) => this.blobsEvicted.add(blobId));
|
|
83
|
-
this._blobCache.clear();
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
this.blobCacheTimeout = setTimeout(clearCacheOrDefer, this.blobCacheTimeoutDuration);
|
|
87
|
-
// any future storage reads that get into the cache should be cleared from cache rather quickly -
|
|
88
|
-
// there is not much value in keeping them longer
|
|
89
|
-
this.blobCacheTimeoutDuration = 10 * 1000;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
getBlob(blobId) {
|
|
93
|
-
// Reset the timer on attempted cache read
|
|
94
|
-
this.scheduleClearBlobsCache();
|
|
95
|
-
const blobContent = this._blobCache.get(blobId);
|
|
96
|
-
const evicted = this.blobsEvicted.has(blobId);
|
|
97
|
-
return { blobContent, evicted };
|
|
98
|
-
}
|
|
99
|
-
setBlob(blobId, blob) {
|
|
100
|
-
// This API is called as result of cache miss and reading blob from storage.
|
|
101
|
-
// Runtime never reads same blob twice.
|
|
102
|
-
// The only reason we may get read request for same blob is blob de-duping in summaries.
|
|
103
|
-
// Note that the bigger the size, the less likely blobs are the same, so there is very little benefit of caching big blobs.
|
|
104
|
-
// Images are the only exception - user may insert same image twice. But we currently do not de-dup them - only snapshot
|
|
105
|
-
// blobs are de-duped.
|
|
106
|
-
const size = blob.byteLength;
|
|
107
|
-
if (size < 256 * 1024) {
|
|
108
|
-
// Reset the timer on cache set
|
|
109
|
-
this.scheduleClearBlobsCache();
|
|
110
|
-
return this._blobCache.set(blobId, blob);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
// we evicted it here by not caching.
|
|
114
|
-
this.blobsEvicted.add(blobId);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
class OdspDocumentStorageService {
|
|
29
|
+
class OdspDocumentStorageService extends odspDocumentStorageServiceBase_1.OdspDocumentStorageServiceBase {
|
|
119
30
|
constructor(odspResolvedUrl, getStorageToken, logger, fetchFullSnapshot, cache, hostPolicy, epochTracker, flushCallback, snapshotFormatFetchType) {
|
|
120
31
|
var _a;
|
|
32
|
+
super();
|
|
121
33
|
this.odspResolvedUrl = odspResolvedUrl;
|
|
122
34
|
this.getStorageToken = getStorageToken;
|
|
123
35
|
this.logger = logger;
|
|
@@ -127,24 +39,6 @@ class OdspDocumentStorageService {
|
|
|
127
39
|
this.epochTracker = epochTracker;
|
|
128
40
|
this.flushCallback = flushCallback;
|
|
129
41
|
this.snapshotFormatFetchType = snapshotFormatFetchType;
|
|
130
|
-
this.policies = {
|
|
131
|
-
// By default, ODSP tells the container not to prefetch/cache.
|
|
132
|
-
caching: driver_definitions_1.LoaderCachingPolicy.NoCaching,
|
|
133
|
-
// ODSP storage works better if it has less number of blobs / edges
|
|
134
|
-
// Runtime creating many small blobs results in sub-optimal perf.
|
|
135
|
-
// 2K seems like the sweat spot:
|
|
136
|
-
// The smaller the number, less blobs we aggregate. Most storages are very likely to have notion
|
|
137
|
-
// of minimal "cluster" size, so having small blobs is wasteful
|
|
138
|
-
// At the same time increasing the limit ensure that more blobs with user content are aggregated,
|
|
139
|
-
// reducing possibility for de-duping of same blobs (i.e. .attributes rolled into aggregate blob
|
|
140
|
-
// are not reused across data stores, or even within data store, resulting in duplication of content)
|
|
141
|
-
// Note that duplication of content should not have significant impact for bytes over wire as
|
|
142
|
-
// compression of http payload mostly takes care of it, but it does impact storage size and in-memory sizes.
|
|
143
|
-
minBlobSize: 2048,
|
|
144
|
-
maximumCacheDurationMs: epochTracker_1.defaultCacheExpiryTimeoutMs,
|
|
145
|
-
};
|
|
146
|
-
this.commitCache = new Map();
|
|
147
|
-
this.attributesBlobHandles = new Set();
|
|
148
42
|
this.firstVersionCall = true;
|
|
149
43
|
// Driver specified limits for snapshot size and time.
|
|
150
44
|
/**
|
|
@@ -156,26 +50,12 @@ class OdspDocumentStorageService {
|
|
|
156
50
|
this.maxSnapshotFetchTimeout = 120000; // 2 min
|
|
157
51
|
// limits the amount of parallel "attachment" blob uploads
|
|
158
52
|
this.createBlobRateLimiter = new driver_utils_1.RateLimiter(1);
|
|
159
|
-
this.blobCache = new BlobCache();
|
|
160
53
|
this.documentId = this.odspResolvedUrl.hashedDocumentId;
|
|
161
54
|
this.snapshotUrl = this.odspResolvedUrl.endpoints.snapshotStorageUrl;
|
|
162
55
|
this.attachmentPOSTUrl = this.odspResolvedUrl.endpoints.attachmentPOSTStorageUrl;
|
|
163
56
|
this.attachmentGETUrl = this.odspResolvedUrl.endpoints.attachmentGETStorageUrl;
|
|
164
57
|
this.odspSummaryUploadManager = new odspSummaryUploadManager_1.OdspSummaryUploadManager(this.snapshotUrl, getStorageToken, logger, epochTracker, !!((_a = this.hostPolicy.sessionOptions) === null || _a === void 0 ? void 0 : _a.forceAccessTokenViaAuthorizationHeader));
|
|
165
58
|
}
|
|
166
|
-
set ops(ops) {
|
|
167
|
-
(0, common_utils_1.assert)(this._ops === undefined, 0x0a5 /* "Trying to set ops when they are already set!" */);
|
|
168
|
-
this._ops = ops;
|
|
169
|
-
}
|
|
170
|
-
get ops() {
|
|
171
|
-
return this._ops;
|
|
172
|
-
}
|
|
173
|
-
get snapshotSequenceNumber() {
|
|
174
|
-
return this._snapshotSequenceNumber;
|
|
175
|
-
}
|
|
176
|
-
get repositoryUrl() {
|
|
177
|
-
return "";
|
|
178
|
-
}
|
|
179
59
|
async createBlob(file) {
|
|
180
60
|
this.checkAttachmentPOSTUrl();
|
|
181
61
|
const response = await (0, odspUtils_1.getWithRetryForTokenRefresh)(async (options) => {
|
|
@@ -199,70 +79,38 @@ class OdspDocumentStorageService {
|
|
|
199
79
|
});
|
|
200
80
|
return response.content;
|
|
201
81
|
}
|
|
202
|
-
async
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
this.
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
blobId }, res.propsToLog));
|
|
225
|
-
}
|
|
226
|
-
return res.content;
|
|
227
|
-
});
|
|
82
|
+
async fetchBlobFromStorage(blobId, evicted) {
|
|
83
|
+
this.checkAttachmentGETUrl();
|
|
84
|
+
const blob = await (0, odspUtils_1.getWithRetryForTokenRefresh)(async (options) => {
|
|
85
|
+
var _a;
|
|
86
|
+
const storageToken = await this.getStorageToken(options, "GetBlob");
|
|
87
|
+
const unAuthedUrl = `${this.attachmentGETUrl}/${encodeURIComponent(blobId)}/content`;
|
|
88
|
+
const { url, headers } = (0, getUrlAndHeadersWithAuth_1.getUrlAndHeadersWithAuth)(unAuthedUrl, storageToken, !!((_a = this.hostPolicy.sessionOptions) === null || _a === void 0 ? void 0 : _a.forceAccessTokenViaAuthorizationHeader));
|
|
89
|
+
return telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, {
|
|
90
|
+
eventName: "readDataBlob",
|
|
91
|
+
blobId,
|
|
92
|
+
evicted,
|
|
93
|
+
headers: Object.keys(headers).length !== 0 ? true : undefined,
|
|
94
|
+
waitQueueLength: this.epochTracker.rateLimiter.waitQueueLength,
|
|
95
|
+
}, async (event) => {
|
|
96
|
+
const res = await this.epochTracker.fetchArray(url, { headers }, "blob");
|
|
97
|
+
event.end(Object.assign(Object.assign({ waitQueueLength: this.epochTracker.rateLimiter.waitQueueLength }, res.propsToLog), { attempts: options.refresh ? 2 : 1 }));
|
|
98
|
+
const cacheControl = res.headers.get("cache-control");
|
|
99
|
+
if (cacheControl === undefined || !(cacheControl.includes("private") || cacheControl.includes("public"))) {
|
|
100
|
+
this.logger.sendErrorEvent(Object.assign({ eventName: "NonCacheableBlob", cacheControl,
|
|
101
|
+
blobId }, res.propsToLog));
|
|
102
|
+
}
|
|
103
|
+
return res.content;
|
|
228
104
|
});
|
|
229
|
-
|
|
230
|
-
|
|
105
|
+
});
|
|
106
|
+
this.blobCache.setBlob(blobId, blob);
|
|
231
107
|
return blob;
|
|
232
108
|
}
|
|
233
|
-
async readBlob(blobId) {
|
|
234
|
-
return this.readBlobCore(blobId);
|
|
235
|
-
}
|
|
236
109
|
async getSnapshotTree(version, scenarioName) {
|
|
237
110
|
if (!this.snapshotUrl) {
|
|
238
111
|
return null;
|
|
239
112
|
}
|
|
240
|
-
|
|
241
|
-
if (!version || !version.id) {
|
|
242
|
-
const versions = await this.getVersions(null, 1, scenarioName);
|
|
243
|
-
if (!versions || versions.length === 0) {
|
|
244
|
-
return null;
|
|
245
|
-
}
|
|
246
|
-
id = versions[0].id;
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
id = version.id;
|
|
250
|
-
}
|
|
251
|
-
const snapshotTree = await this.readTree(id, scenarioName);
|
|
252
|
-
if (!snapshotTree) {
|
|
253
|
-
return null;
|
|
254
|
-
}
|
|
255
|
-
if (snapshotTree.blobs) {
|
|
256
|
-
const attributesBlob = snapshotTree.blobs.attributes;
|
|
257
|
-
if (attributesBlob) {
|
|
258
|
-
this.attributesBlobHandles.add(attributesBlob);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
// When we upload the container snapshot, we upload appTree in ".app" and protocol tree in ".protocol"
|
|
262
|
-
// So when we request the snapshot we get ".app" as tree and not as commit node as in the case just above.
|
|
263
|
-
const appTree = snapshotTree.trees[".app"];
|
|
264
|
-
const protocolTree = snapshotTree.trees[".protocol"];
|
|
265
|
-
return this.combineProtocolAndAppSnapshotTree(appTree, protocolTree);
|
|
113
|
+
return super.getSnapshotTree(version, scenarioName);
|
|
266
114
|
}
|
|
267
115
|
async getVersions(blobid, count, scenarioName) {
|
|
268
116
|
// Regular load workflow uses blobId === documentID to indicate "latest".
|
|
@@ -361,19 +209,7 @@ class OdspDocumentStorageService {
|
|
|
361
209
|
});
|
|
362
210
|
// Successful call, make network calls only
|
|
363
211
|
this.firstVersionCall = false;
|
|
364
|
-
|
|
365
|
-
const { snapshotTree, blobs, ops } = odspSnapshotCacheValue;
|
|
366
|
-
// id should be undefined in case of just ops in snapshot.
|
|
367
|
-
let id;
|
|
368
|
-
if (snapshotTree) {
|
|
369
|
-
id = snapshotTree.id;
|
|
370
|
-
(0, common_utils_1.assert)(id !== undefined, 0x221 /* "Root tree should contain the id" */);
|
|
371
|
-
this.setRootTree(id, snapshotTree);
|
|
372
|
-
}
|
|
373
|
-
if (blobs) {
|
|
374
|
-
this.initBlobsCache(blobs);
|
|
375
|
-
}
|
|
376
|
-
this.ops = ops;
|
|
212
|
+
const id = this.initializeFromSnapshot(odspSnapshotCacheValue);
|
|
377
213
|
return id ? [{ id, treeId: undefined }] : [];
|
|
378
214
|
}
|
|
379
215
|
return (0, odspUtils_1.getWithRetryForTokenRefresh)(async (options) => {
|
|
@@ -458,34 +294,25 @@ class OdspDocumentStorageService {
|
|
|
458
294
|
this.checkSnapshotUrl();
|
|
459
295
|
// Enable flushing only if we have single commit summary and this is not the initial summary for an empty file
|
|
460
296
|
if (".protocol" in summary.tree && context.ackHandle !== undefined) {
|
|
461
|
-
let retry =
|
|
297
|
+
let retry = 1;
|
|
462
298
|
for (;;) {
|
|
463
299
|
const result = await this.flushCallback();
|
|
464
300
|
const seq = result.lastPersistedSequenceNumber;
|
|
465
301
|
if (seq !== undefined && seq >= context.referenceSequenceNumber) {
|
|
466
302
|
break;
|
|
467
303
|
}
|
|
468
|
-
retry++;
|
|
469
304
|
if (retry > 3) {
|
|
470
305
|
this.logger.sendErrorEvent(Object.assign(Object.assign({ eventName: "FlushFailure" }, result), { retry, referenceSequenceNumber: context.referenceSequenceNumber }));
|
|
471
306
|
break;
|
|
472
307
|
}
|
|
473
308
|
this.logger.sendPerformanceEvent(Object.assign(Object.assign({ eventName: "FlushExtraCall" }, result), { retry, referenceSequenceNumber: context.referenceSequenceNumber }));
|
|
309
|
+
retry++;
|
|
474
310
|
await (0, common_utils_1.delay)(1000 * ((_a = result.retryAfter) !== null && _a !== void 0 ? _a : 1));
|
|
475
311
|
}
|
|
476
312
|
}
|
|
477
313
|
const id = await this.odspSummaryUploadManager.writeSummaryTree(summary, context);
|
|
478
314
|
return id;
|
|
479
315
|
}
|
|
480
|
-
async downloadSummary(commit) {
|
|
481
|
-
throw new Error("Not implemented yet");
|
|
482
|
-
}
|
|
483
|
-
setRootTree(id, tree) {
|
|
484
|
-
this.commitCache.set(id, tree);
|
|
485
|
-
}
|
|
486
|
-
initBlobsCache(blobs) {
|
|
487
|
-
this.blobCache.addBlobs(blobs);
|
|
488
|
-
}
|
|
489
316
|
checkSnapshotUrl() {
|
|
490
317
|
if (!this.snapshotUrl) {
|
|
491
318
|
throw new driver_utils_1.NonRetryableError("Method failed because no snapshot url was available", driver_definitions_1.DriverErrorType.genericError, { driverVersion: packageVersion_1.pkgVersion });
|
|
@@ -501,47 +328,27 @@ class OdspDocumentStorageService {
|
|
|
501
328
|
throw new driver_utils_1.NonRetryableError("Method failed because no attachment GET url was available", driver_definitions_1.DriverErrorType.genericError, { driverVersion: packageVersion_1.pkgVersion });
|
|
502
329
|
}
|
|
503
330
|
}
|
|
504
|
-
async
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
}
|
|
526
|
-
// If the version id doesn't match with the id of the tree, then use the id of first tree which in that case
|
|
527
|
-
// will be the actual id of tree to be fetched.
|
|
528
|
-
return (_b = this.commitCache.get(id)) !== null && _b !== void 0 ? _b : this.commitCache.get(treeId);
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
if (!tree) {
|
|
532
|
-
return null;
|
|
533
|
-
}
|
|
534
|
-
return tree;
|
|
535
|
-
}
|
|
536
|
-
combineProtocolAndAppSnapshotTree(hierarchicalAppTree, hierarchicalProtocolTree) {
|
|
537
|
-
const summarySnapshotTree = {
|
|
538
|
-
blobs: Object.assign({}, hierarchicalAppTree.blobs),
|
|
539
|
-
trees: Object.assign(Object.assign({}, hierarchicalAppTree.trees), {
|
|
540
|
-
// the app tree could have a .protocol
|
|
541
|
-
// in that case we want to server protocol to override it
|
|
542
|
-
".protocol": hierarchicalProtocolTree }),
|
|
543
|
-
};
|
|
544
|
-
return summarySnapshotTree;
|
|
331
|
+
async fetchTreeFromSnapshot(id, scenarioName) {
|
|
332
|
+
return (0, odspUtils_1.getWithRetryForTokenRefresh)(async (options) => {
|
|
333
|
+
var _a, _b;
|
|
334
|
+
const storageToken = await this.getStorageToken(options, "ReadCommit");
|
|
335
|
+
const snapshotDownloader = async (url, fetchOptions) => {
|
|
336
|
+
return this.epochTracker.fetchAndParseAsJSON(url, fetchOptions, "snapshotTree", undefined, scenarioName);
|
|
337
|
+
};
|
|
338
|
+
const snapshot = await (0, fetchSnapshot_1.fetchSnapshot)(this.snapshotUrl, storageToken, id, this.fetchFullSnapshot, !!((_a = this.hostPolicy.sessionOptions) === null || _a === void 0 ? void 0 : _a.forceAccessTokenViaAuthorizationHeader), this.logger, snapshotDownloader);
|
|
339
|
+
let treeId = "";
|
|
340
|
+
if (snapshot.snapshotTree) {
|
|
341
|
+
(0, common_utils_1.assert)(snapshot.snapshotTree.id !== undefined, 0x222 /* "Root tree should contain the id!!" */);
|
|
342
|
+
treeId = snapshot.snapshotTree.id;
|
|
343
|
+
this.setRootTree(treeId, snapshot.snapshotTree);
|
|
344
|
+
}
|
|
345
|
+
if (snapshot.blobs) {
|
|
346
|
+
this.initBlobsCache(snapshot.blobs);
|
|
347
|
+
}
|
|
348
|
+
// If the version id doesn't match with the id of the tree, then use the id of first tree which in that case
|
|
349
|
+
// will be the actual id of tree to be fetched.
|
|
350
|
+
return (_b = this.commitCache.get(id)) !== null && _b !== void 0 ? _b : this.commitCache.get(treeId);
|
|
351
|
+
});
|
|
545
352
|
}
|
|
546
353
|
}
|
|
547
354
|
exports.OdspDocumentStorageService = OdspDocumentStorageService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odspDocumentStorageManager.js","sourceRoot":"","sources":["../src/odspDocumentStorageManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,+DAGsC;AACtC,qEAEyC;AAEzC,2EAK4C;AAC5C,+DAA8E;AAC9E,qFAKiD;AAOjD,mDAAsH;AACtH,yEAAsE;AAEtE,2CAGqB;AAErB,iDAA2E;AAC3E,yEAAsE;AAEtE,qDAA+D;AAElD,QAAA,mCAAmC,GAAW,EAAE,GAAG,IAAI,CAAC,CAAC,cAAc;AAEpF,4BAA4B;AAE5B,kFAAkF;AAClF,KAAK,UAAU,qBAAqB,CAAI,QAAsB;IAC1D,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;YAC1B,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAA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AED,2BAA2B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { default as AbortController } from \"abort-controller\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport {\n assert,\n delay,\n} from \"@fluidframework/common-utils\";\nimport {\n PerformanceEvent,\n} from \"@fluidframework/telemetry-utils\";\nimport * as api from \"@fluidframework/protocol-definitions\";\nimport {\n ISummaryContext,\n IDocumentStorageService,\n LoaderCachingPolicy,\n DriverErrorType,\n} from \"@fluidframework/driver-definitions\";\nimport { RateLimiter, NonRetryableError } from \"@fluidframework/driver-utils\";\nimport {\n IOdspResolvedUrl,\n ISnapshotOptions,\n OdspErrorType,\n InstrumentedStorageTokenFetcher,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport {\n IDocumentStorageGetVersionsResponse,\n HostStoragePolicyInternal,\n IVersionedValueWithEpoch,\n ISnapshotCachedEntry,\n} from \"./contracts\";\nimport { downloadSnapshot, fetchSnapshot, fetchSnapshotWithRedeem, SnapshotFormatSupportType } from \"./fetchSnapshot\";\nimport { getUrlAndHeadersWithAuth } from \"./getUrlAndHeadersWithAuth\";\nimport { IOdspCache } from \"./odspCache\";\nimport {\n createCacheSnapshotKey,\n getWithRetryForTokenRefresh,\n} from \"./odspUtils\";\nimport { ISnapshotContents } from \"./odspPublicUtils\";\nimport { defaultCacheExpiryTimeoutMs, EpochTracker } from \"./epochTracker\";\nimport { OdspSummaryUploadManager } from \"./odspSummaryUploadManager\";\nimport { FlushResult } from \"./odspDocumentDeltaConnection\";\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\n\nexport const defaultSummarizerCacheExpiryTimeout: number = 60 * 1000; // 60 seconds.\n\n/* eslint-disable max-len */\n\n// An implementation of Promise.race that gives you the winner of the promise race\nasync function promiseRaceWithWinner<T>(promises: Promise<T>[]): Promise<{ index: number; value: T; }> {\n return new Promise((resolve, reject) => {\n promises.forEach((p, index) => {\n p.then((v) => resolve({ index, value: v })).catch(reject);\n });\n });\n}\n\nclass BlobCache {\n // Save the timeout so we can cancel and reschedule it as needed\n private blobCacheTimeout: ReturnType<typeof setTimeout> | undefined;\n // If the defer flag is set when the timeout fires, we'll reschedule rather than clear immediately\n // This deferral approach is used (rather than clearing/resetting the timer) as current calling patterns trigger\n // too many calls to setTimeout/clearTimeout.\n private deferBlobCacheClear: boolean = false;\n\n private readonly _blobCache: Map<string, ArrayBuffer> = new Map();\n\n // Tracks all blob IDs evicted from cache\n private readonly blobsEvicted: Set<string> = new Set();\n\n // Initial time-out to purge data from cache\n // If this time out is very small, then we purge blobs from cache too soon and that results in a lot of\n // requests to storage, which brings down perf and may trip protection limits causing 429s\n private blobCacheTimeoutDuration = 2 * 60 * 1000;\n\n // SPO does not keep old snapshots around for long, so we are running chances of not\n // being able to rehydrate data store / DDS in the future if we purge anything (and with blob de-duping,\n // even if blob read by runtime, it could be read again in the future)\n // So for now, purging is disabled.\n private readonly purgeEnabled = false;\n\n public get value() {\n return this._blobCache;\n }\n\n public addBlobs(blobs: Map<string, ArrayBuffer>) {\n blobs.forEach((value, blobId) => {\n this._blobCache.set(blobId, value);\n });\n // Reset the timer on cache set\n this.scheduleClearBlobsCache();\n }\n\n /**\n * Schedule a timer for clearing the blob cache or defer the current one.\n */\n private scheduleClearBlobsCache() {\n if (this.blobCacheTimeout !== undefined) {\n // If we already have an outstanding timer, just signal that we should defer the clear\n this.deferBlobCacheClear = true;\n } else if (this.purgeEnabled) {\n // If we don't have an outstanding timer, set a timer\n // When the timer runs out, we'll decide whether to proceed with the cache clear or reset the timer\n const clearCacheOrDefer = () => {\n this.blobCacheTimeout = undefined;\n if (this.deferBlobCacheClear) {\n this.deferBlobCacheClear = false;\n this.scheduleClearBlobsCache();\n } else {\n // NOTE: Slightly better algorithm here would be to purge either only big blobs,\n // or sort them by size and purge enough big blobs to leave only 256Kb of small blobs in cache\n // Purging is optimizing memory footprint. But count controls potential number of storage requests\n // We want to optimize both - memory footprint and number of future requests to storage.\n // Note that Container can realize data store or DDS on-demand at any point in time, so we do not\n // control when blobs will be used.\n this._blobCache.forEach((_, blobId) => this.blobsEvicted.add(blobId));\n this._blobCache.clear();\n }\n };\n this.blobCacheTimeout = setTimeout(clearCacheOrDefer, this.blobCacheTimeoutDuration);\n // any future storage reads that get into the cache should be cleared from cache rather quickly -\n // there is not much value in keeping them longer\n this.blobCacheTimeoutDuration = 10 * 1000;\n }\n }\n\n public getBlob(blobId: string) {\n // Reset the timer on attempted cache read\n this.scheduleClearBlobsCache();\n const blobContent = this._blobCache.get(blobId);\n const evicted = this.blobsEvicted.has(blobId);\n return { blobContent, evicted };\n }\n\n public setBlob(blobId: string, blob: ArrayBuffer) {\n // This API is called as result of cache miss and reading blob from storage.\n // Runtime never reads same blob twice.\n // The only reason we may get read request for same blob is blob de-duping in summaries.\n // Note that the bigger the size, the less likely blobs are the same, so there is very little benefit of caching big blobs.\n // Images are the only exception - user may insert same image twice. But we currently do not de-dup them - only snapshot\n // blobs are de-duped.\n const size = blob.byteLength;\n if (size < 256 * 1024) {\n // Reset the timer on cache set\n this.scheduleClearBlobsCache();\n return this._blobCache.set(blobId, blob);\n } else {\n // we evicted it here by not caching.\n this.blobsEvicted.add(blobId);\n }\n }\n}\n\ninterface GetVersionsTelemetryProps {\n cacheEntryAge?: number;\n cacheSummarizerExpired?: boolean;\n}\nexport class OdspDocumentStorageService implements IDocumentStorageService {\n readonly policies = {\n // By default, ODSP tells the container not to prefetch/cache.\n caching: LoaderCachingPolicy.NoCaching,\n\n // ODSP storage works better if it has less number of blobs / edges\n // Runtime creating many small blobs results in sub-optimal perf.\n // 2K seems like the sweat spot:\n // The smaller the number, less blobs we aggregate. Most storages are very likely to have notion\n // of minimal \"cluster\" size, so having small blobs is wasteful\n // At the same time increasing the limit ensure that more blobs with user content are aggregated,\n // reducing possibility for de-duping of same blobs (i.e. .attributes rolled into aggregate blob\n // are not reused across data stores, or even within data store, resulting in duplication of content)\n // Note that duplication of content should not have significant impact for bytes over wire as\n // compression of http payload mostly takes care of it, but it does impact storage size and in-memory sizes.\n minBlobSize: 2048,\n maximumCacheDurationMs: defaultCacheExpiryTimeoutMs,\n };\n\n private readonly commitCache: Map<string, api.ISnapshotTree> = new Map();\n\n private readonly attributesBlobHandles: Set<string> = new Set();\n\n private readonly odspSummaryUploadManager: OdspSummaryUploadManager;\n private _ops: api.ISequencedDocumentMessage[] | undefined;\n\n private firstVersionCall = true;\n private _snapshotSequenceNumber: number | undefined;\n\n private readonly documentId: string;\n private readonly snapshotUrl: string | undefined;\n private readonly attachmentPOSTUrl: string | undefined;\n private readonly attachmentGETUrl: string | undefined;\n // Driver specified limits for snapshot size and time.\n /**\n * NOTE: While commit cfff6e3 added restrictions to prevent large payloads, snapshot failures will continue to\n * happen until blob request throttling is implemented. Until then, as a temporary fix we set arbitrarily large\n * snapshot size and timeout limits so that such failures are unlikely to occur.\n */\n private readonly maxSnapshotSizeLimit = 500000000; // 500 MB\n private readonly maxSnapshotFetchTimeout = 120000; // 2 min\n\n // limits the amount of parallel \"attachment\" blob uploads\n private readonly createBlobRateLimiter = new RateLimiter(1);\n\n private readonly blobCache = new BlobCache();\n\n public set ops(ops: api.ISequencedDocumentMessage[] | undefined) {\n assert(this._ops === undefined, 0x0a5 /* \"Trying to set ops when they are already set!\" */);\n this._ops = ops;\n }\n\n public get ops(): api.ISequencedDocumentMessage[] | undefined {\n return this._ops;\n }\n\n public get snapshotSequenceNumber() {\n return this._snapshotSequenceNumber;\n }\n\n constructor(\n private readonly odspResolvedUrl: IOdspResolvedUrl,\n private readonly getStorageToken: InstrumentedStorageTokenFetcher,\n private readonly logger: ITelemetryLogger,\n private readonly fetchFullSnapshot: boolean,\n private readonly cache: IOdspCache,\n private readonly hostPolicy: HostStoragePolicyInternal,\n private readonly epochTracker: EpochTracker,\n private readonly flushCallback: () => Promise<FlushResult>,\n private readonly snapshotFormatFetchType?: SnapshotFormatSupportType,\n ) {\n this.documentId = this.odspResolvedUrl.hashedDocumentId;\n this.snapshotUrl = this.odspResolvedUrl.endpoints.snapshotStorageUrl;\n this.attachmentPOSTUrl = this.odspResolvedUrl.endpoints.attachmentPOSTStorageUrl;\n this.attachmentGETUrl = this.odspResolvedUrl.endpoints.attachmentGETStorageUrl;\n this.odspSummaryUploadManager = new OdspSummaryUploadManager(\n this.snapshotUrl,\n getStorageToken,\n logger,\n epochTracker,\n !!this.hostPolicy.sessionOptions?.forceAccessTokenViaAuthorizationHeader,\n );\n }\n\n public get repositoryUrl(): string {\n return \"\";\n }\n\n public async createBlob(file: ArrayBufferLike): Promise<api.ICreateBlobResponse> {\n this.checkAttachmentPOSTUrl();\n\n const response = await getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await this.getStorageToken(options, \"CreateBlob\");\n const { url, headers } = getUrlAndHeadersWithAuth(\n `${this.attachmentPOSTUrl}/content`,\n storageToken,\n !!this.hostPolicy.sessionOptions?.forceAccessTokenViaAuthorizationHeader,\n );\n headers[\"Content-Type\"] = \"application/octet-stream\";\n\n return PerformanceEvent.timedExecAsync(\n this.logger,\n {\n eventName: \"createBlob\",\n size: file.byteLength,\n waitQueueLength: this.createBlobRateLimiter.waitQueueLength,\n },\n async (event) => {\n const res = await this.createBlobRateLimiter.schedule(async () =>\n this.epochTracker.fetchAndParseAsJSON<api.ICreateBlobResponse>(\n url,\n {\n body: file,\n headers,\n method: \"POST\",\n },\n \"createBlob\",\n ));\n event.end({\n blobId: res.content.id,\n ...res.propsToLog,\n });\n return res;\n },\n );\n });\n\n return response.content;\n }\n\n private async readBlobCore(blobId: string): Promise<ArrayBuffer> {\n const { blobContent, evicted } = this.blobCache.getBlob(blobId);\n let blob = blobContent;\n\n if (blob === undefined) {\n this.checkAttachmentGETUrl();\n\n blob = await getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await this.getStorageToken(options, \"GetBlob\");\n const unAuthedUrl = `${this.attachmentGETUrl}/${encodeURIComponent(blobId)}/content`;\n const { url, headers } = getUrlAndHeadersWithAuth(\n unAuthedUrl,\n storageToken,\n !!this.hostPolicy.sessionOptions?.forceAccessTokenViaAuthorizationHeader,\n );\n\n return PerformanceEvent.timedExecAsync(\n this.logger,\n {\n eventName: \"readDataBlob\",\n blobId,\n evicted,\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n waitQueueLength: this.epochTracker.rateLimiter.waitQueueLength,\n },\n async (event) => {\n const res = await this.epochTracker.fetchArray(url, { headers }, \"blob\");\n event.end({\n waitQueueLength: this.epochTracker.rateLimiter.waitQueueLength,\n ...res.propsToLog,\n attempts: options.refresh ? 2 : 1,\n });\n const cacheControl = res.headers.get(\"cache-control\");\n if (cacheControl === undefined || !(cacheControl.includes(\"private\") || cacheControl.includes(\"public\"))) {\n this.logger.sendErrorEvent({\n eventName: \"NonCacheableBlob\",\n cacheControl,\n blobId,\n ...res.propsToLog,\n });\n }\n return res.content;\n },\n );\n });\n this.blobCache.setBlob(blobId, blob);\n }\n\n return blob;\n }\n\n public async readBlob(blobId: string): Promise<ArrayBufferLike> {\n return this.readBlobCore(blobId);\n }\n\n public async getSnapshotTree(version?: api.IVersion, scenarioName?: string): Promise<api.ISnapshotTree | null> {\n if (!this.snapshotUrl) {\n return null;\n }\n\n let id: string;\n if (!version || !version.id) {\n const versions = await this.getVersions(null, 1, scenarioName);\n if (!versions || versions.length === 0) {\n return null;\n }\n id = versions[0].id;\n } else {\n id = version.id;\n }\n\n const snapshotTree = await this.readTree(id, scenarioName);\n if (!snapshotTree) {\n return null;\n }\n\n if (snapshotTree.blobs) {\n const attributesBlob = snapshotTree.blobs.attributes;\n if (attributesBlob) {\n this.attributesBlobHandles.add(attributesBlob);\n }\n }\n\n // When we upload the container snapshot, we upload appTree in \".app\" and protocol tree in \".protocol\"\n // So when we request the snapshot we get \".app\" as tree and not as commit node as in the case just above.\n const appTree = snapshotTree.trees[\".app\"];\n const protocolTree = snapshotTree.trees[\".protocol\"];\n\n return this.combineProtocolAndAppSnapshotTree(appTree, protocolTree);\n }\n\n public async getVersions(blobid: string | null, count: number, scenarioName?: string): Promise<api.IVersion[]> {\n // Regular load workflow uses blobId === documentID to indicate \"latest\".\n if (blobid !== this.documentId && blobid) {\n // FluidFetch & FluidDebugger tools use empty sting to query for versions\n // In such case we need to make a call against SPO to give full picture to the tool.\n // Otherwise, each commit calls getVersions but odsp doesn't have a history for each commit\n // return the blobid as is\n return [\n {\n id: blobid,\n treeId: undefined!,\n },\n ];\n }\n\n // Can't really make a call if we do not have URL\n if (!this.snapshotUrl) {\n return [];\n }\n\n // If count is one, we can use the trees/latest API, which returns the latest version and trees in a single request for better performance\n // Do it only once - we might get more here due to summarizer - it needs only container tree, not full snapshot.\n if (this.firstVersionCall && count === 1 && (blobid === null || blobid === this.documentId)) {\n const hostSnapshotOptions = this.hostPolicy.snapshotOptions;\n const odspSnapshotCacheValue: ISnapshotContents = await PerformanceEvent.timedExecAsync(\n this.logger,\n { eventName: \"ObtainSnapshot\" },\n async (event: PerformanceEvent) => {\n const props: GetVersionsTelemetryProps = {};\n let retrievedSnapshot: ISnapshotContents | undefined;\n // Here's the logic to grab the persistent cache snapshot implemented by the host\n // Epoch tracker is responsible for communicating with the persistent cache, handling epochs and cache versions\n const cachedSnapshotP: Promise<ISnapshotContents | undefined> =\n this.epochTracker.get(createCacheSnapshotKey(this.odspResolvedUrl))\n .then(async (snapshotCachedEntry: ISnapshotCachedEntry) => {\n if (snapshotCachedEntry !== undefined) {\n // If the cached entry does not contain the entry time, then assign it a default of 30 days old.\n const age = Date.now() - (snapshotCachedEntry.cacheEntryTime ??\n (Date.now() - 30 * 24 * 60 * 60 * 1000));\n\n // In order to decrease the number of times we have to execute a snapshot refresh,\n // if this is the summarizer and we have a cache entry but it is past the defaultSummarizerCacheExpiryTimeout,\n // force the network retrieval instead as there might be a more recent snapshot available.\n // See: https://github.com/microsoft/FluidFramework/issues/8995 for additional information.\n if (this.hostPolicy.summarizerClient) {\n if (age > defaultSummarizerCacheExpiryTimeout) {\n props.cacheSummarizerExpired = true;\n return undefined;\n } else {\n props.cacheSummarizerExpired = false;\n }\n }\n\n // Record the cache age\n props.cacheEntryAge = age;\n }\n\n return snapshotCachedEntry;\n });\n\n // Based on the concurrentSnapshotFetch policy:\n // Either retrieve both the network and cache snapshots concurrently and pick the first to return,\n // or grab the cache value and then the network value if the cache value returns undefined.\n let method: string;\n if (this.hostPolicy.concurrentSnapshotFetch && !this.hostPolicy.summarizerClient) {\n const networkSnapshotP = this.fetchSnapshot(hostSnapshotOptions, scenarioName);\n\n // Ensure that failures on both paths are ignored initially.\n // I.e. if cache fails for some reason, we will proceed with network result.\n // And vice versa - if (for example) client is offline and network request fails first, we\n // do want to attempt to succeed with cached data!\n const promiseRaceWinner = await promiseRaceWithWinner([\n cachedSnapshotP.catch(() => undefined),\n networkSnapshotP.catch(() => undefined),\n ]);\n retrievedSnapshot = promiseRaceWinner.value;\n method = promiseRaceWinner.index === 0 ? \"cache\" : \"network\";\n\n if (retrievedSnapshot === undefined) {\n // if network failed -> wait for cache ( then return network failure)\n // If cache returned empty or failed -> wait for network (success of failure)\n if (promiseRaceWinner.index === 1) {\n retrievedSnapshot = await cachedSnapshotP;\n method = \"cache\";\n }\n if (retrievedSnapshot === undefined) {\n retrievedSnapshot = await networkSnapshotP;\n method = \"network\";\n }\n }\n } else {\n // Note: There's a race condition here - another caller may come past the undefined check\n // while the first caller is awaiting later async code in this block.\n\n retrievedSnapshot = await cachedSnapshotP;\n\n method = retrievedSnapshot !== undefined ? \"cache\" : \"network\";\n\n if (retrievedSnapshot === undefined) {\n retrievedSnapshot = await this.fetchSnapshot(hostSnapshotOptions, scenarioName);\n }\n }\n if (method === \"network\") {\n props.cacheEntryAge = undefined;\n }\n event.end({ ...props, method });\n return retrievedSnapshot;\n },\n );\n\n // Successful call, make network calls only\n this.firstVersionCall = false;\n\n this._snapshotSequenceNumber = odspSnapshotCacheValue.sequenceNumber;\n const { snapshotTree, blobs, ops } = odspSnapshotCacheValue;\n // id should be undefined in case of just ops in snapshot.\n let id: string | undefined;\n if (snapshotTree) {\n id = snapshotTree.id;\n assert(id !== undefined, 0x221 /* \"Root tree should contain the id\" */);\n this.setRootTree(id, snapshotTree);\n }\n if (blobs) {\n this.initBlobsCache(blobs);\n }\n\n this.ops = ops;\n return id ? [{ id, treeId: undefined! }] : [];\n }\n\n return getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await this.getStorageToken(options, \"GetVersions\");\n const { url, headers } = getUrlAndHeadersWithAuth(\n `${this.snapshotUrl}/versions?top=${count}`,\n storageToken,\n !!this.hostPolicy.sessionOptions?.forceAccessTokenViaAuthorizationHeader,\n );\n\n // Fetch the latest snapshot versions for the document\n const response = await PerformanceEvent.timedExecAsync(\n this.logger,\n {\n eventName: \"getVersions\",\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n },\n async () => this.epochTracker.fetchAndParseAsJSON<IDocumentStorageGetVersionsResponse>(url, { headers }, \"versions\", undefined, scenarioName),\n );\n const versionsResponse = response.content;\n if (!versionsResponse) {\n throw new NonRetryableError(\n \"No response from /versions endpoint\",\n DriverErrorType.genericNetworkError,\n { driverVersion });\n }\n if (!Array.isArray(versionsResponse.value)) {\n throw new NonRetryableError(\n \"Incorrect response from /versions endpoint, expected an array\",\n DriverErrorType.genericNetworkError,\n { driverVersion });\n }\n return versionsResponse.value.map((version) => {\n return {\n id: version.id,\n treeId: undefined!,\n };\n });\n });\n }\n\n private async fetchSnapshot(hostSnapshotOptions: ISnapshotOptions | undefined, scenarioName?: string) {\n return this.fetchSnapshotCore(hostSnapshotOptions, scenarioName).catch((error) => {\n // Issue #5895:\n // If we are offline, this error is retryable. But that means that RetriableDocumentStorageService\n // will run in circles calling getSnapshotTree, which would result in OdspDocumentStorageService class\n // going getVersions / individual blob download path. This path is very slow, and will not work with\n // delay-loaded data stores and ODSP storage deleting old snapshots and blobs.\n if (typeof error === \"object\" && error !== null) {\n error.canRetry = false;\n }\n throw error;\n });\n }\n\n private async fetchSnapshotCore(hostSnapshotOptions: ISnapshotOptions | undefined, scenarioName?: string) {\n const snapshotOptions: ISnapshotOptions = {\n mds: this.maxSnapshotSizeLimit,\n ...hostSnapshotOptions,\n timeout: hostSnapshotOptions?.timeout ? Math.min(hostSnapshotOptions.timeout, this.maxSnapshotFetchTimeout) : this.maxSnapshotFetchTimeout,\n };\n\n // No limit on size of snapshot or time to fetch, as otherwise we fail all clients to summarize\n if (this.hostPolicy.summarizerClient) {\n snapshotOptions.mds = undefined;\n snapshotOptions.timeout = undefined;\n }\n\n const snapshotDownloader = async (\n finalOdspResolvedUrl: IOdspResolvedUrl,\n storageToken: string,\n options: ISnapshotOptions | undefined,\n controller?: AbortController,\n ) => {\n return downloadSnapshot(\n finalOdspResolvedUrl,\n storageToken,\n this.logger,\n options,\n this.snapshotFormatFetchType,\n controller,\n this.epochTracker,\n scenarioName,\n );\n };\n const putInCache = async (valueWithEpoch: IVersionedValueWithEpoch) => {\n return this.cache.persistedCache.put(\n createCacheSnapshotKey(this.odspResolvedUrl),\n // Epoch tracker will add the epoch and version to the value here. So just send value to cache.\n valueWithEpoch.value,\n );\n };\n const removeEntries = async () => this.cache.persistedCache.removeEntries();\n try {\n const odspSnapshot = await fetchSnapshotWithRedeem(\n this.odspResolvedUrl,\n this.getStorageToken,\n snapshotOptions,\n !!this.hostPolicy.sessionOptions?.forceAccessTokenViaAuthorizationHeader,\n this.logger,\n snapshotDownloader,\n putInCache,\n removeEntries,\n this.hostPolicy.enableRedeemFallback,\n );\n return odspSnapshot;\n } catch (error: any) {\n const errorType = error.errorType;\n // If the snapshot size is too big and the host specified the size limitation(specified in hostSnapshotOptions), then don't try to fetch the snapshot again.\n if ((errorType === OdspErrorType.snapshotTooBig && hostSnapshotOptions?.mds !== undefined) && (this.hostPolicy.summarizerClient !== true)) {\n throw error;\n }\n // If the first snapshot request was with blobs and we either timed out or the size was too big, then try to fetch without blobs.\n if ((errorType === OdspErrorType.snapshotTooBig || errorType === OdspErrorType.fetchTimeout) && snapshotOptions.blobs) {\n this.logger.sendErrorEvent({\n eventName: \"TreeLatest_SecondCall\",\n errorType,\n });\n const snapshotOptionsWithoutBlobs: ISnapshotOptions = { ...snapshotOptions, blobs: 0, mds: undefined, timeout: undefined };\n const odspSnapshot = await fetchSnapshotWithRedeem(\n this.odspResolvedUrl,\n this.getStorageToken,\n snapshotOptionsWithoutBlobs,\n !!this.hostPolicy.sessionOptions?.forceAccessTokenViaAuthorizationHeader,\n this.logger,\n snapshotDownloader,\n putInCache,\n removeEntries,\n this.hostPolicy.enableRedeemFallback,\n );\n return odspSnapshot;\n }\n throw error;\n }\n }\n\n public async uploadSummaryWithContext(summary: api.ISummaryTree, context: ISummaryContext): Promise<string> {\n this.checkSnapshotUrl();\n\n // Enable flushing only if we have single commit summary and this is not the initial summary for an empty file\n if (\".protocol\" in summary.tree && context.ackHandle !== undefined) {\n let retry = 0;\n for (; ;) {\n const result = await this.flushCallback();\n const seq = result.lastPersistedSequenceNumber;\n if (seq !== undefined && seq >= context.referenceSequenceNumber) {\n break;\n }\n\n retry++;\n if (retry > 3) {\n this.logger.sendErrorEvent({\n eventName: \"FlushFailure\",\n ...result,\n retry,\n referenceSequenceNumber: context.referenceSequenceNumber,\n });\n break;\n }\n\n this.logger.sendPerformanceEvent({\n eventName: \"FlushExtraCall\",\n ...result,\n retry,\n referenceSequenceNumber: context.referenceSequenceNumber,\n });\n\n await delay(1000 * (result.retryAfter ?? 1));\n }\n }\n\n const id = await this.odspSummaryUploadManager.writeSummaryTree(summary, context);\n return id;\n }\n\n public async downloadSummary(commit: api.ISummaryHandle): Promise<api.ISummaryTree> {\n throw new Error(\"Not implemented yet\");\n }\n\n private setRootTree(id: string, tree: api.ISnapshotTree) {\n this.commitCache.set(id, tree);\n }\n\n private initBlobsCache(blobs: Map<string, ArrayBuffer>) {\n this.blobCache.addBlobs(blobs);\n }\n\n private checkSnapshotUrl() {\n if (!this.snapshotUrl) {\n throw new NonRetryableError(\n \"Method failed because no snapshot url was available\",\n DriverErrorType.genericError,\n { driverVersion });\n }\n }\n\n private checkAttachmentPOSTUrl() {\n if (!this.attachmentPOSTUrl) {\n throw new NonRetryableError(\n \"Method failed because no attachment POST url was available\",\n DriverErrorType.genericError,\n { driverVersion });\n }\n }\n\n private checkAttachmentGETUrl() {\n if (!this.attachmentGETUrl) {\n throw new NonRetryableError(\n \"Method failed because no attachment GET url was available\",\n DriverErrorType.genericError,\n { driverVersion });\n }\n }\n\n private async readTree(id: string, scenarioName?: string): Promise<api.ISnapshotTree | null> {\n if (!this.snapshotUrl) {\n return null;\n }\n let tree = this.commitCache.get(id);\n if (!tree) {\n tree = await getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await this.getStorageToken(options, \"ReadCommit\");\n const snapshotDownloader = async (url: string, fetchOptions: { [index: string]: any; }) => {\n return this.epochTracker.fetchAndParseAsJSON(\n url,\n fetchOptions,\n \"snapshotTree\",\n undefined,\n scenarioName,\n );\n };\n const snapshot = await fetchSnapshot(\n this.snapshotUrl!,\n storageToken,\n id,\n this.fetchFullSnapshot,\n !!this.hostPolicy.sessionOptions?.forceAccessTokenViaAuthorizationHeader,\n this.logger,\n snapshotDownloader,\n );\n let treeId = \"\";\n if (snapshot.snapshotTree) {\n assert(snapshot.snapshotTree.id !== undefined, 0x222 /* \"Root tree should contain the id!!\" */);\n treeId = snapshot.snapshotTree.id;\n this.setRootTree(treeId, snapshot.snapshotTree);\n }\n if (snapshot.blobs) {\n this.initBlobsCache(snapshot.blobs);\n }\n // If the version id doesn't match with the id of the tree, then use the id of first tree which in that case\n // will be the actual id of tree to be fetched.\n return this.commitCache.get(id) ?? this.commitCache.get(treeId);\n });\n }\n\n if (!tree) {\n return null;\n }\n\n return tree;\n }\n\n private combineProtocolAndAppSnapshotTree(\n hierarchicalAppTree: api.ISnapshotTree,\n hierarchicalProtocolTree: api.ISnapshotTree,\n ) {\n const summarySnapshotTree: api.ISnapshotTree = {\n blobs: {\n ...hierarchicalAppTree.blobs,\n },\n trees: {\n ...hierarchicalAppTree.trees,\n // the app tree could have a .protocol\n // in that case we want to server protocol to override it\n \".protocol\": hierarchicalProtocolTree,\n },\n };\n\n return summarySnapshotTree;\n }\n}\n\n/* eslint-enable max-len */\n"]}
|
|
1
|
+
{"version":3,"file":"odspDocumentStorageManager.js","sourceRoot":"","sources":["../src/odspDocumentStorageManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,+DAGsC;AACtC,qEAEyC;AAEzC,2EAG4C;AAC5C,+DAA8E;AAC9E,qFAKiD;AAOjD,mDAAsH;AACtH,yEAAsE;AAEtE,2CAGqB;AAGrB,yEAAsE;AAEtE,qDAA+D;AAC/D,qFAAkF;AAErE,QAAA,mCAAmC,GAAW,EAAE,GAAG,IAAI,CAAC,CAAC,cAAc;AAEpF,4BAA4B;AAE5B,kFAAkF;AAClF,KAAK,UAAU,qBAAqB,CAAI,QAAsB;IAC1D,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;YAC1B,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC;AAOD,MAAa,0BAA2B,SAAQ,+DAA8B;IAqB1E,YACqB,eAAiC,EACjC,eAAgD,EAChD,MAAwB,EACxB,iBAA0B,EAC1B,KAAiB,EACjB,UAAqC,EACrC,YAA0B,EAC1B,aAAyC,EACzC,uBAAmD;;QAEpE,KAAK,EAAE,CAAC;QAVS,oBAAe,GAAf,eAAe,CAAkB;QACjC,oBAAe,GAAf,eAAe,CAAiC;QAChD,WAAM,GAAN,MAAM,CAAkB;QACxB,sBAAiB,GAAjB,iBAAiB,CAAS;QAC1B,UAAK,GAAL,KAAK,CAAY;QACjB,eA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n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { default as AbortController } from \"abort-controller\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport {\n assert,\n delay,\n} from \"@fluidframework/common-utils\";\nimport {\n PerformanceEvent,\n} from \"@fluidframework/telemetry-utils\";\nimport * as api from \"@fluidframework/protocol-definitions\";\nimport {\n ISummaryContext,\n DriverErrorType,\n} from \"@fluidframework/driver-definitions\";\nimport { RateLimiter, NonRetryableError } from \"@fluidframework/driver-utils\";\nimport {\n IOdspResolvedUrl,\n ISnapshotOptions,\n OdspErrorType,\n InstrumentedStorageTokenFetcher,\n} from \"@fluidframework/odsp-driver-definitions\";\nimport {\n IDocumentStorageGetVersionsResponse,\n HostStoragePolicyInternal,\n IVersionedValueWithEpoch,\n ISnapshotCachedEntry,\n} from \"./contracts\";\nimport { downloadSnapshot, fetchSnapshot, fetchSnapshotWithRedeem, SnapshotFormatSupportType } from \"./fetchSnapshot\";\nimport { getUrlAndHeadersWithAuth } from \"./getUrlAndHeadersWithAuth\";\nimport { IOdspCache } from \"./odspCache\";\nimport {\n createCacheSnapshotKey,\n getWithRetryForTokenRefresh,\n} from \"./odspUtils\";\nimport { ISnapshotContents } from \"./odspPublicUtils\";\nimport { EpochTracker } from \"./epochTracker\";\nimport { OdspSummaryUploadManager } from \"./odspSummaryUploadManager\";\nimport { FlushResult } from \"./odspDocumentDeltaConnection\";\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\nimport { OdspDocumentStorageServiceBase } from \"./odspDocumentStorageServiceBase\";\n\nexport const defaultSummarizerCacheExpiryTimeout: number = 60 * 1000; // 60 seconds.\n\n/* eslint-disable max-len */\n\n// An implementation of Promise.race that gives you the winner of the promise race\nasync function promiseRaceWithWinner<T>(promises: Promise<T>[]): Promise<{ index: number; value: T; }> {\n return new Promise((resolve, reject) => {\n promises.forEach((p, index) => {\n p.then((v) => resolve({ index, value: v })).catch(reject);\n });\n });\n}\n\ninterface GetVersionsTelemetryProps {\n cacheEntryAge?: number;\n cacheSummarizerExpired?: boolean;\n}\n\nexport class OdspDocumentStorageService extends OdspDocumentStorageServiceBase {\n private readonly odspSummaryUploadManager: OdspSummaryUploadManager;\n\n private firstVersionCall = true;\n\n private readonly documentId: string;\n private readonly snapshotUrl: string | undefined;\n private readonly attachmentPOSTUrl: string | undefined;\n private readonly attachmentGETUrl: string | undefined;\n // Driver specified limits for snapshot size and time.\n /**\n * NOTE: While commit cfff6e3 added restrictions to prevent large payloads, snapshot failures will continue to\n * happen until blob request throttling is implemented. Until then, as a temporary fix we set arbitrarily large\n * snapshot size and timeout limits so that such failures are unlikely to occur.\n */\n private readonly maxSnapshotSizeLimit = 500000000; // 500 MB\n private readonly maxSnapshotFetchTimeout = 120000; // 2 min\n\n // limits the amount of parallel \"attachment\" blob uploads\n private readonly createBlobRateLimiter = new RateLimiter(1);\n\n constructor(\n private readonly odspResolvedUrl: IOdspResolvedUrl,\n private readonly getStorageToken: InstrumentedStorageTokenFetcher,\n private readonly logger: ITelemetryLogger,\n private readonly fetchFullSnapshot: boolean,\n private readonly cache: IOdspCache,\n private readonly hostPolicy: HostStoragePolicyInternal,\n private readonly epochTracker: EpochTracker,\n private readonly flushCallback: () => Promise<FlushResult>,\n private readonly snapshotFormatFetchType?: SnapshotFormatSupportType,\n ) {\n super();\n\n this.documentId = this.odspResolvedUrl.hashedDocumentId;\n this.snapshotUrl = this.odspResolvedUrl.endpoints.snapshotStorageUrl;\n this.attachmentPOSTUrl = this.odspResolvedUrl.endpoints.attachmentPOSTStorageUrl;\n this.attachmentGETUrl = this.odspResolvedUrl.endpoints.attachmentGETStorageUrl;\n\n this.odspSummaryUploadManager = new OdspSummaryUploadManager(\n this.snapshotUrl,\n getStorageToken,\n logger,\n epochTracker,\n !!this.hostPolicy.sessionOptions?.forceAccessTokenViaAuthorizationHeader,\n );\n }\n\n public async createBlob(file: ArrayBufferLike): Promise<api.ICreateBlobResponse> {\n this.checkAttachmentPOSTUrl();\n\n const response = await getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await this.getStorageToken(options, \"CreateBlob\");\n const { url, headers } = getUrlAndHeadersWithAuth(\n `${this.attachmentPOSTUrl}/content`,\n storageToken,\n !!this.hostPolicy.sessionOptions?.forceAccessTokenViaAuthorizationHeader,\n );\n headers[\"Content-Type\"] = \"application/octet-stream\";\n\n return PerformanceEvent.timedExecAsync(\n this.logger,\n {\n eventName: \"createBlob\",\n size: file.byteLength,\n waitQueueLength: this.createBlobRateLimiter.waitQueueLength,\n },\n async (event) => {\n const res = await this.createBlobRateLimiter.schedule(async () =>\n this.epochTracker.fetchAndParseAsJSON<api.ICreateBlobResponse>(\n url,\n {\n body: file,\n headers,\n method: \"POST\",\n },\n \"createBlob\",\n ));\n event.end({\n blobId: res.content.id,\n ...res.propsToLog,\n });\n return res;\n },\n );\n });\n\n return response.content;\n }\n\n protected async fetchBlobFromStorage(blobId: string, evicted: boolean): Promise<ArrayBuffer> {\n this.checkAttachmentGETUrl();\n\n const blob = await getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await this.getStorageToken(options, \"GetBlob\");\n const unAuthedUrl = `${this.attachmentGETUrl}/${encodeURIComponent(blobId)}/content`;\n const { url, headers } = getUrlAndHeadersWithAuth(\n unAuthedUrl,\n storageToken,\n !!this.hostPolicy.sessionOptions?.forceAccessTokenViaAuthorizationHeader,\n );\n\n return PerformanceEvent.timedExecAsync(\n this.logger,\n {\n eventName: \"readDataBlob\",\n blobId,\n evicted,\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n waitQueueLength: this.epochTracker.rateLimiter.waitQueueLength,\n },\n async (event) => {\n const res = await this.epochTracker.fetchArray(url, { headers }, \"blob\");\n event.end({\n waitQueueLength: this.epochTracker.rateLimiter.waitQueueLength,\n ...res.propsToLog,\n attempts: options.refresh ? 2 : 1,\n });\n const cacheControl = res.headers.get(\"cache-control\");\n if (cacheControl === undefined || !(cacheControl.includes(\"private\") || cacheControl.includes(\"public\"))) {\n this.logger.sendErrorEvent({\n eventName: \"NonCacheableBlob\",\n cacheControl,\n blobId,\n ...res.propsToLog,\n });\n }\n return res.content;\n },\n );\n });\n this.blobCache.setBlob(blobId, blob);\n return blob;\n }\n\n public async getSnapshotTree(version?: api.IVersion, scenarioName?: string): Promise<api.ISnapshotTree | null> {\n if (!this.snapshotUrl) {\n return null;\n }\n return super.getSnapshotTree(version, scenarioName);\n }\n\n public async getVersions(blobid: string | null, count: number, scenarioName?: string): Promise<api.IVersion[]> {\n // Regular load workflow uses blobId === documentID to indicate \"latest\".\n if (blobid !== this.documentId && blobid) {\n // FluidFetch & FluidDebugger tools use empty sting to query for versions\n // In such case we need to make a call against SPO to give full picture to the tool.\n // Otherwise, each commit calls getVersions but odsp doesn't have a history for each commit\n // return the blobid as is\n return [\n {\n id: blobid,\n treeId: undefined!,\n },\n ];\n }\n\n // Can't really make a call if we do not have URL\n if (!this.snapshotUrl) {\n return [];\n }\n\n // If count is one, we can use the trees/latest API, which returns the latest version and trees in a single request for better performance\n // Do it only once - we might get more here due to summarizer - it needs only container tree, not full snapshot.\n if (this.firstVersionCall && count === 1 && (blobid === null || blobid === this.documentId)) {\n const hostSnapshotOptions = this.hostPolicy.snapshotOptions;\n const odspSnapshotCacheValue: ISnapshotContents = await PerformanceEvent.timedExecAsync(\n this.logger,\n { eventName: \"ObtainSnapshot\" },\n async (event: PerformanceEvent) => {\n const props: GetVersionsTelemetryProps = {};\n let retrievedSnapshot: ISnapshotContents | undefined;\n // Here's the logic to grab the persistent cache snapshot implemented by the host\n // Epoch tracker is responsible for communicating with the persistent cache, handling epochs and cache versions\n const cachedSnapshotP: Promise<ISnapshotContents | undefined> =\n this.epochTracker.get(createCacheSnapshotKey(this.odspResolvedUrl))\n .then(async (snapshotCachedEntry: ISnapshotCachedEntry) => {\n if (snapshotCachedEntry !== undefined) {\n // If the cached entry does not contain the entry time, then assign it a default of 30 days old.\n const age = Date.now() - (snapshotCachedEntry.cacheEntryTime ??\n (Date.now() - 30 * 24 * 60 * 60 * 1000));\n\n // In order to decrease the number of times we have to execute a snapshot refresh,\n // if this is the summarizer and we have a cache entry but it is past the defaultSummarizerCacheExpiryTimeout,\n // force the network retrieval instead as there might be a more recent snapshot available.\n // See: https://github.com/microsoft/FluidFramework/issues/8995 for additional information.\n if (this.hostPolicy.summarizerClient) {\n if (age > defaultSummarizerCacheExpiryTimeout) {\n props.cacheSummarizerExpired = true;\n return undefined;\n } else {\n props.cacheSummarizerExpired = false;\n }\n }\n\n // Record the cache age\n props.cacheEntryAge = age;\n }\n\n return snapshotCachedEntry;\n });\n\n // Based on the concurrentSnapshotFetch policy:\n // Either retrieve both the network and cache snapshots concurrently and pick the first to return,\n // or grab the cache value and then the network value if the cache value returns undefined.\n let method: string;\n if (this.hostPolicy.concurrentSnapshotFetch && !this.hostPolicy.summarizerClient) {\n const networkSnapshotP = this.fetchSnapshot(hostSnapshotOptions, scenarioName);\n\n // Ensure that failures on both paths are ignored initially.\n // I.e. if cache fails for some reason, we will proceed with network result.\n // And vice versa - if (for example) client is offline and network request fails first, we\n // do want to attempt to succeed with cached data!\n const promiseRaceWinner = await promiseRaceWithWinner([\n cachedSnapshotP.catch(() => undefined),\n networkSnapshotP.catch(() => undefined),\n ]);\n retrievedSnapshot = promiseRaceWinner.value;\n method = promiseRaceWinner.index === 0 ? \"cache\" : \"network\";\n\n if (retrievedSnapshot === undefined) {\n // if network failed -> wait for cache ( then return network failure)\n // If cache returned empty or failed -> wait for network (success of failure)\n if (promiseRaceWinner.index === 1) {\n retrievedSnapshot = await cachedSnapshotP;\n method = \"cache\";\n }\n if (retrievedSnapshot === undefined) {\n retrievedSnapshot = await networkSnapshotP;\n method = \"network\";\n }\n }\n } else {\n // Note: There's a race condition here - another caller may come past the undefined check\n // while the first caller is awaiting later async code in this block.\n\n retrievedSnapshot = await cachedSnapshotP;\n\n method = retrievedSnapshot !== undefined ? \"cache\" : \"network\";\n\n if (retrievedSnapshot === undefined) {\n retrievedSnapshot = await this.fetchSnapshot(hostSnapshotOptions, scenarioName);\n }\n }\n if (method === \"network\") {\n props.cacheEntryAge = undefined;\n }\n event.end({ ...props, method });\n return retrievedSnapshot;\n },\n );\n\n // Successful call, make network calls only\n this.firstVersionCall = false;\n const id = this.initializeFromSnapshot(odspSnapshotCacheValue);\n\n return id ? [{ id, treeId: undefined! }] : [];\n }\n\n return getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await this.getStorageToken(options, \"GetVersions\");\n const { url, headers } = getUrlAndHeadersWithAuth(\n `${this.snapshotUrl}/versions?top=${count}`,\n storageToken,\n !!this.hostPolicy.sessionOptions?.forceAccessTokenViaAuthorizationHeader,\n );\n\n // Fetch the latest snapshot versions for the document\n const response = await PerformanceEvent.timedExecAsync(\n this.logger,\n {\n eventName: \"getVersions\",\n headers: Object.keys(headers).length !== 0 ? true : undefined,\n },\n async () => this.epochTracker.fetchAndParseAsJSON<IDocumentStorageGetVersionsResponse>(url, { headers }, \"versions\", undefined, scenarioName),\n );\n const versionsResponse = response.content;\n if (!versionsResponse) {\n throw new NonRetryableError(\n \"No response from /versions endpoint\",\n DriverErrorType.genericNetworkError,\n { driverVersion });\n }\n if (!Array.isArray(versionsResponse.value)) {\n throw new NonRetryableError(\n \"Incorrect response from /versions endpoint, expected an array\",\n DriverErrorType.genericNetworkError,\n { driverVersion });\n }\n return versionsResponse.value.map((version) => {\n return {\n id: version.id,\n treeId: undefined!,\n };\n });\n });\n }\n\n private async fetchSnapshot(hostSnapshotOptions: ISnapshotOptions | undefined, scenarioName?: string) {\n return this.fetchSnapshotCore(hostSnapshotOptions, scenarioName).catch((error) => {\n // Issue #5895:\n // If we are offline, this error is retryable. But that means that RetriableDocumentStorageService\n // will run in circles calling getSnapshotTree, which would result in OdspDocumentStorageService class\n // going getVersions / individual blob download path. This path is very slow, and will not work with\n // delay-loaded data stores and ODSP storage deleting old snapshots and blobs.\n if (typeof error === \"object\" && error !== null) {\n error.canRetry = false;\n }\n throw error;\n });\n }\n\n private async fetchSnapshotCore(hostSnapshotOptions: ISnapshotOptions | undefined, scenarioName?: string) {\n const snapshotOptions: ISnapshotOptions = {\n mds: this.maxSnapshotSizeLimit,\n ...hostSnapshotOptions,\n timeout: hostSnapshotOptions?.timeout ? Math.min(hostSnapshotOptions.timeout, this.maxSnapshotFetchTimeout) : this.maxSnapshotFetchTimeout,\n };\n\n // No limit on size of snapshot or time to fetch, as otherwise we fail all clients to summarize\n if (this.hostPolicy.summarizerClient) {\n snapshotOptions.mds = undefined;\n snapshotOptions.timeout = undefined;\n }\n\n const snapshotDownloader = async (\n finalOdspResolvedUrl: IOdspResolvedUrl,\n storageToken: string,\n options: ISnapshotOptions | undefined,\n controller?: AbortController,\n ) => {\n return downloadSnapshot(\n finalOdspResolvedUrl,\n storageToken,\n this.logger,\n options,\n this.snapshotFormatFetchType,\n controller,\n this.epochTracker,\n scenarioName,\n );\n };\n const putInCache = async (valueWithEpoch: IVersionedValueWithEpoch) => {\n return this.cache.persistedCache.put(\n createCacheSnapshotKey(this.odspResolvedUrl),\n // Epoch tracker will add the epoch and version to the value here. So just send value to cache.\n valueWithEpoch.value,\n );\n };\n const removeEntries = async () => this.cache.persistedCache.removeEntries();\n try {\n const odspSnapshot = await fetchSnapshotWithRedeem(\n this.odspResolvedUrl,\n this.getStorageToken,\n snapshotOptions,\n !!this.hostPolicy.sessionOptions?.forceAccessTokenViaAuthorizationHeader,\n this.logger,\n snapshotDownloader,\n putInCache,\n removeEntries,\n this.hostPolicy.enableRedeemFallback,\n );\n return odspSnapshot;\n } catch (error: any) {\n const errorType = error.errorType;\n // If the snapshot size is too big and the host specified the size limitation(specified in hostSnapshotOptions), then don't try to fetch the snapshot again.\n if ((errorType === OdspErrorType.snapshotTooBig && hostSnapshotOptions?.mds !== undefined) && (this.hostPolicy.summarizerClient !== true)) {\n throw error;\n }\n // If the first snapshot request was with blobs and we either timed out or the size was too big, then try to fetch without blobs.\n if ((errorType === OdspErrorType.snapshotTooBig || errorType === OdspErrorType.fetchTimeout) && snapshotOptions.blobs) {\n this.logger.sendErrorEvent({\n eventName: \"TreeLatest_SecondCall\",\n errorType,\n });\n const snapshotOptionsWithoutBlobs: ISnapshotOptions = { ...snapshotOptions, blobs: 0, mds: undefined, timeout: undefined };\n const odspSnapshot = await fetchSnapshotWithRedeem(\n this.odspResolvedUrl,\n this.getStorageToken,\n snapshotOptionsWithoutBlobs,\n !!this.hostPolicy.sessionOptions?.forceAccessTokenViaAuthorizationHeader,\n this.logger,\n snapshotDownloader,\n putInCache,\n removeEntries,\n this.hostPolicy.enableRedeemFallback,\n );\n return odspSnapshot;\n }\n throw error;\n }\n }\n\n public async uploadSummaryWithContext(summary: api.ISummaryTree, context: ISummaryContext): Promise<string> {\n this.checkSnapshotUrl();\n\n // Enable flushing only if we have single commit summary and this is not the initial summary for an empty file\n if (\".protocol\" in summary.tree && context.ackHandle !== undefined) {\n let retry = 1;\n for (;;) {\n const result = await this.flushCallback();\n const seq = result.lastPersistedSequenceNumber;\n if (seq !== undefined && seq >= context.referenceSequenceNumber) {\n break;\n }\n\n if (retry > 3) {\n this.logger.sendErrorEvent({\n eventName: \"FlushFailure\",\n ...result,\n retry,\n referenceSequenceNumber: context.referenceSequenceNumber,\n });\n break;\n }\n\n this.logger.sendPerformanceEvent({\n eventName: \"FlushExtraCall\",\n ...result,\n retry,\n referenceSequenceNumber: context.referenceSequenceNumber,\n });\n\n retry++;\n await delay(1000 * (result.retryAfter ?? 1));\n }\n }\n\n const id = await this.odspSummaryUploadManager.writeSummaryTree(summary, context);\n return id;\n }\n\n private checkSnapshotUrl() {\n if (!this.snapshotUrl) {\n throw new NonRetryableError(\n \"Method failed because no snapshot url was available\",\n DriverErrorType.genericError,\n { driverVersion });\n }\n }\n\n private checkAttachmentPOSTUrl() {\n if (!this.attachmentPOSTUrl) {\n throw new NonRetryableError(\n \"Method failed because no attachment POST url was available\",\n DriverErrorType.genericError,\n { driverVersion });\n }\n }\n\n private checkAttachmentGETUrl() {\n if (!this.attachmentGETUrl) {\n throw new NonRetryableError(\n \"Method failed because no attachment GET url was available\",\n DriverErrorType.genericError,\n { driverVersion });\n }\n }\n\n protected async fetchTreeFromSnapshot(id: string, scenarioName?: string): Promise<api.ISnapshotTree | undefined> {\n return getWithRetryForTokenRefresh(async (options) => {\n const storageToken = await this.getStorageToken(options, \"ReadCommit\");\n const snapshotDownloader = async (url: string, fetchOptions: { [index: string]: any; }) => {\n return this.epochTracker.fetchAndParseAsJSON(\n url,\n fetchOptions,\n \"snapshotTree\",\n undefined,\n scenarioName,\n );\n };\n const snapshot = await fetchSnapshot(\n this.snapshotUrl!,\n storageToken,\n id,\n this.fetchFullSnapshot,\n !!this.hostPolicy.sessionOptions?.forceAccessTokenViaAuthorizationHeader,\n this.logger,\n snapshotDownloader,\n );\n let treeId = \"\";\n if (snapshot.snapshotTree) {\n assert(snapshot.snapshotTree.id !== undefined, 0x222 /* \"Root tree should contain the id!!\" */);\n treeId = snapshot.snapshotTree.id;\n this.setRootTree(treeId, snapshot.snapshotTree);\n }\n if (snapshot.blobs) {\n this.initBlobsCache(snapshot.blobs);\n }\n // If the version id doesn't match with the id of the tree, then use the id of first tree which in that case\n // will be the actual id of tree to be fetched.\n return this.commitCache.get(id) ?? this.commitCache.get(treeId);\n });\n }\n}\n\n/* eslint-enable max-len */\n"]}
|