@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.
Files changed (127) hide show
  1. package/dist/checkUrl.d.ts +1 -1
  2. package/dist/checkUrl.js +1 -1
  3. package/dist/checkUrl.js.map +1 -1
  4. package/dist/constants.d.ts +1 -1
  5. package/dist/constants.d.ts.map +1 -1
  6. package/dist/constants.js +1 -1
  7. package/dist/constants.js.map +1 -1
  8. package/dist/contractsPublic.d.ts +1 -0
  9. package/dist/contractsPublic.d.ts.map +1 -1
  10. package/dist/contractsPublic.js.map +1 -1
  11. package/dist/getFileLink.js +0 -4
  12. package/dist/getFileLink.js.map +1 -1
  13. package/dist/localOdspDriver/localOdspDocumentService.d.ts +26 -0
  14. package/dist/localOdspDriver/localOdspDocumentService.d.ts.map +1 -0
  15. package/dist/localOdspDriver/localOdspDocumentService.js +39 -0
  16. package/dist/localOdspDriver/localOdspDocumentService.js.map +1 -0
  17. package/dist/localOdspDriver/localOdspDocumentServiceFactory.d.ts +24 -0
  18. package/dist/localOdspDriver/localOdspDocumentServiceFactory.d.ts.map +1 -0
  19. package/dist/localOdspDriver/localOdspDocumentServiceFactory.js +45 -0
  20. package/dist/localOdspDriver/localOdspDocumentServiceFactory.js.map +1 -0
  21. package/dist/localOdspDriver/localOdspDocumentStorageManager.d.ts +27 -0
  22. package/dist/localOdspDriver/localOdspDocumentStorageManager.d.ts.map +1 -0
  23. package/dist/localOdspDriver/localOdspDocumentStorageManager.js +66 -0
  24. package/dist/localOdspDriver/localOdspDocumentStorageManager.js.map +1 -0
  25. package/dist/odspDeltaStorageService.js.map +1 -1
  26. package/dist/odspDocumentService.d.ts.map +1 -1
  27. package/dist/odspDocumentService.js.map +1 -1
  28. package/dist/odspDocumentServiceFactory.d.ts +2 -1
  29. package/dist/odspDocumentServiceFactory.d.ts.map +1 -1
  30. package/dist/odspDocumentServiceFactory.js +7 -1
  31. package/dist/odspDocumentServiceFactory.js.map +1 -1
  32. package/dist/odspDocumentServiceFactoryCore.d.ts +3 -1
  33. package/dist/odspDocumentServiceFactoryCore.d.ts.map +1 -1
  34. package/dist/odspDocumentServiceFactoryCore.js.map +1 -1
  35. package/dist/odspDocumentStorageManager.d.ts +5 -23
  36. package/dist/odspDocumentStorageManager.d.ts.map +1 -1
  37. package/dist/odspDocumentStorageManager.js +52 -245
  38. package/dist/odspDocumentStorageManager.js.map +1 -1
  39. package/dist/odspDocumentStorageServiceBase.d.ts +58 -0
  40. package/dist/odspDocumentStorageServiceBase.d.ts.map +1 -0
  41. package/dist/odspDocumentStorageServiceBase.js +216 -0
  42. package/dist/odspDocumentStorageServiceBase.js.map +1 -0
  43. package/dist/odspDriverUrlResolver.js +1 -1
  44. package/dist/odspDriverUrlResolver.js.map +1 -1
  45. package/dist/odspDriverUrlResolverForShareLink.d.ts +8 -2
  46. package/dist/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
  47. package/dist/odspDriverUrlResolverForShareLink.js +11 -3
  48. package/dist/odspDriverUrlResolverForShareLink.js.map +1 -1
  49. package/dist/odspFluidFileLink.d.ts.map +1 -1
  50. package/dist/odspFluidFileLink.js +27 -21
  51. package/dist/odspFluidFileLink.js.map +1 -1
  52. package/dist/packageVersion.d.ts +1 -1
  53. package/dist/packageVersion.js +1 -1
  54. package/dist/packageVersion.js.map +1 -1
  55. package/lib/checkUrl.d.ts +1 -1
  56. package/lib/checkUrl.js +1 -1
  57. package/lib/checkUrl.js.map +1 -1
  58. package/lib/constants.d.ts +1 -1
  59. package/lib/constants.d.ts.map +1 -1
  60. package/lib/constants.js +1 -1
  61. package/lib/constants.js.map +1 -1
  62. package/lib/contractsPublic.d.ts +1 -0
  63. package/lib/contractsPublic.d.ts.map +1 -1
  64. package/lib/contractsPublic.js.map +1 -1
  65. package/lib/getFileLink.js +0 -4
  66. package/lib/getFileLink.js.map +1 -1
  67. package/lib/localOdspDriver/localOdspDocumentService.d.ts +26 -0
  68. package/lib/localOdspDriver/localOdspDocumentService.d.ts.map +1 -0
  69. package/lib/localOdspDriver/localOdspDocumentService.js +35 -0
  70. package/lib/localOdspDriver/localOdspDocumentService.js.map +1 -0
  71. package/lib/localOdspDriver/localOdspDocumentServiceFactory.d.ts +24 -0
  72. package/lib/localOdspDriver/localOdspDocumentServiceFactory.d.ts.map +1 -0
  73. package/lib/localOdspDriver/localOdspDocumentServiceFactory.js +41 -0
  74. package/lib/localOdspDriver/localOdspDocumentServiceFactory.js.map +1 -0
  75. package/lib/localOdspDriver/localOdspDocumentStorageManager.d.ts +27 -0
  76. package/lib/localOdspDriver/localOdspDocumentStorageManager.d.ts.map +1 -0
  77. package/lib/localOdspDriver/localOdspDocumentStorageManager.js +62 -0
  78. package/lib/localOdspDriver/localOdspDocumentStorageManager.js.map +1 -0
  79. package/lib/odspDeltaStorageService.js.map +1 -1
  80. package/lib/odspDocumentService.d.ts.map +1 -1
  81. package/lib/odspDocumentService.js +1 -1
  82. package/lib/odspDocumentService.js.map +1 -1
  83. package/lib/odspDocumentServiceFactory.d.ts +2 -1
  84. package/lib/odspDocumentServiceFactory.d.ts.map +1 -1
  85. package/lib/odspDocumentServiceFactory.js +5 -0
  86. package/lib/odspDocumentServiceFactory.js.map +1 -1
  87. package/lib/odspDocumentServiceFactoryCore.d.ts +3 -1
  88. package/lib/odspDocumentServiceFactoryCore.d.ts.map +1 -1
  89. package/lib/odspDocumentServiceFactoryCore.js.map +1 -1
  90. package/lib/odspDocumentStorageManager.d.ts +5 -23
  91. package/lib/odspDocumentStorageManager.d.ts.map +1 -1
  92. package/lib/odspDocumentStorageManager.js +53 -246
  93. package/lib/odspDocumentStorageManager.js.map +1 -1
  94. package/lib/odspDocumentStorageServiceBase.d.ts +58 -0
  95. package/lib/odspDocumentStorageServiceBase.d.ts.map +1 -0
  96. package/lib/odspDocumentStorageServiceBase.js +212 -0
  97. package/lib/odspDocumentStorageServiceBase.js.map +1 -0
  98. package/lib/odspDriverUrlResolver.js +1 -1
  99. package/lib/odspDriverUrlResolver.js.map +1 -1
  100. package/lib/odspDriverUrlResolverForShareLink.d.ts +8 -2
  101. package/lib/odspDriverUrlResolverForShareLink.d.ts.map +1 -1
  102. package/lib/odspDriverUrlResolverForShareLink.js +11 -3
  103. package/lib/odspDriverUrlResolverForShareLink.js.map +1 -1
  104. package/lib/odspFluidFileLink.d.ts.map +1 -1
  105. package/lib/odspFluidFileLink.js +27 -21
  106. package/lib/odspFluidFileLink.js.map +1 -1
  107. package/lib/packageVersion.d.ts +1 -1
  108. package/lib/packageVersion.js +1 -1
  109. package/lib/packageVersion.js.map +1 -1
  110. package/package.json +17 -12
  111. package/src/checkUrl.ts +1 -1
  112. package/src/constants.ts +1 -1
  113. package/src/contractsPublic.ts +1 -0
  114. package/src/getFileLink.ts +0 -5
  115. package/src/localOdspDriver/localOdspDocumentService.ts +54 -0
  116. package/src/localOdspDriver/localOdspDocumentServiceFactory.ts +67 -0
  117. package/src/localOdspDriver/localOdspDocumentStorageManager.ts +83 -0
  118. package/src/odspDeltaStorageService.ts +1 -1
  119. package/src/odspDocumentService.ts +5 -1
  120. package/src/odspDocumentServiceFactory.ts +7 -3
  121. package/src/odspDocumentServiceFactoryCore.ts +1 -1
  122. package/src/odspDocumentStorageManager.ts +81 -312
  123. package/src/odspDocumentStorageServiceBase.ts +268 -0
  124. package/src/odspDriverUrlResolver.ts +1 -1
  125. package/src/odspDriverUrlResolverForShareLink.ts +13 -1
  126. package/src/odspFluidFileLink.ts +26 -22
  127. package/src/packageVersion.ts +1 -1
@@ -4,15 +4,15 @@
4
4
  */
5
5
  import { assert, delay, } from "@fluidframework/common-utils";
6
6
  import { PerformanceEvent, } from "@fluidframework/telemetry-utils";
7
- import { LoaderCachingPolicy, DriverErrorType, } from "@fluidframework/driver-definitions";
7
+ import { DriverErrorType, } from "@fluidframework/driver-definitions";
8
8
  import { RateLimiter, NonRetryableError } from "@fluidframework/driver-utils";
9
9
  import { OdspErrorType, } from "@fluidframework/odsp-driver-definitions";
10
10
  import { downloadSnapshot, fetchSnapshot, fetchSnapshotWithRedeem } from "./fetchSnapshot";
11
11
  import { getUrlAndHeadersWithAuth } from "./getUrlAndHeadersWithAuth";
12
12
  import { createCacheSnapshotKey, getWithRetryForTokenRefresh, } from "./odspUtils";
13
- import { defaultCacheExpiryTimeoutMs } from "./epochTracker";
14
13
  import { OdspSummaryUploadManager } from "./odspSummaryUploadManager";
15
14
  import { pkgVersion as driverVersion } from "./packageVersion";
15
+ import { OdspDocumentStorageServiceBase } from "./odspDocumentStorageServiceBase";
16
16
  export const defaultSummarizerCacheExpiryTimeout = 60 * 1000; // 60 seconds.
17
17
  /* eslint-disable max-len */
18
18
  // An implementation of Promise.race that gives you the winner of the promise race
@@ -23,98 +23,10 @@ async function promiseRaceWithWinner(promises) {
23
23
  });
24
24
  });
25
25
  }
26
- class BlobCache {
27
- constructor() {
28
- // If the defer flag is set when the timeout fires, we'll reschedule rather than clear immediately
29
- // This deferral approach is used (rather than clearing/resetting the timer) as current calling patterns trigger
30
- // too many calls to setTimeout/clearTimeout.
31
- this.deferBlobCacheClear = false;
32
- this._blobCache = new Map();
33
- // Tracks all blob IDs evicted from cache
34
- this.blobsEvicted = new Set();
35
- // Initial time-out to purge data from cache
36
- // If this time out is very small, then we purge blobs from cache too soon and that results in a lot of
37
- // requests to storage, which brings down perf and may trip protection limits causing 429s
38
- this.blobCacheTimeoutDuration = 2 * 60 * 1000;
39
- // SPO does not keep old snapshots around for long, so we are running chances of not
40
- // being able to rehydrate data store / DDS in the future if we purge anything (and with blob de-duping,
41
- // even if blob read by runtime, it could be read again in the future)
42
- // So for now, purging is disabled.
43
- this.purgeEnabled = false;
44
- }
45
- get value() {
46
- return this._blobCache;
47
- }
48
- addBlobs(blobs) {
49
- blobs.forEach((value, blobId) => {
50
- this._blobCache.set(blobId, value);
51
- });
52
- // Reset the timer on cache set
53
- this.scheduleClearBlobsCache();
54
- }
55
- /**
56
- * Schedule a timer for clearing the blob cache or defer the current one.
57
- */
58
- scheduleClearBlobsCache() {
59
- if (this.blobCacheTimeout !== undefined) {
60
- // If we already have an outstanding timer, just signal that we should defer the clear
61
- this.deferBlobCacheClear = true;
62
- }
63
- else if (this.purgeEnabled) {
64
- // If we don't have an outstanding timer, set a timer
65
- // When the timer runs out, we'll decide whether to proceed with the cache clear or reset the timer
66
- const clearCacheOrDefer = () => {
67
- this.blobCacheTimeout = undefined;
68
- if (this.deferBlobCacheClear) {
69
- this.deferBlobCacheClear = false;
70
- this.scheduleClearBlobsCache();
71
- }
72
- else {
73
- // NOTE: Slightly better algorithm here would be to purge either only big blobs,
74
- // or sort them by size and purge enough big blobs to leave only 256Kb of small blobs in cache
75
- // Purging is optimizing memory footprint. But count controls potential number of storage requests
76
- // We want to optimize both - memory footprint and number of future requests to storage.
77
- // Note that Container can realize data store or DDS on-demand at any point in time, so we do not
78
- // control when blobs will be used.
79
- this._blobCache.forEach((_, blobId) => this.blobsEvicted.add(blobId));
80
- this._blobCache.clear();
81
- }
82
- };
83
- this.blobCacheTimeout = setTimeout(clearCacheOrDefer, this.blobCacheTimeoutDuration);
84
- // any future storage reads that get into the cache should be cleared from cache rather quickly -
85
- // there is not much value in keeping them longer
86
- this.blobCacheTimeoutDuration = 10 * 1000;
87
- }
88
- }
89
- getBlob(blobId) {
90
- // Reset the timer on attempted cache read
91
- this.scheduleClearBlobsCache();
92
- const blobContent = this._blobCache.get(blobId);
93
- const evicted = this.blobsEvicted.has(blobId);
94
- return { blobContent, evicted };
95
- }
96
- setBlob(blobId, blob) {
97
- // This API is called as result of cache miss and reading blob from storage.
98
- // Runtime never reads same blob twice.
99
- // The only reason we may get read request for same blob is blob de-duping in summaries.
100
- // Note that the bigger the size, the less likely blobs are the same, so there is very little benefit of caching big blobs.
101
- // Images are the only exception - user may insert same image twice. But we currently do not de-dup them - only snapshot
102
- // blobs are de-duped.
103
- const size = blob.byteLength;
104
- if (size < 256 * 1024) {
105
- // Reset the timer on cache set
106
- this.scheduleClearBlobsCache();
107
- return this._blobCache.set(blobId, blob);
108
- }
109
- else {
110
- // we evicted it here by not caching.
111
- this.blobsEvicted.add(blobId);
112
- }
113
- }
114
- }
115
- export class OdspDocumentStorageService {
26
+ export class OdspDocumentStorageService extends OdspDocumentStorageServiceBase {
116
27
  constructor(odspResolvedUrl, getStorageToken, logger, fetchFullSnapshot, cache, hostPolicy, epochTracker, flushCallback, snapshotFormatFetchType) {
117
28
  var _a;
29
+ super();
118
30
  this.odspResolvedUrl = odspResolvedUrl;
119
31
  this.getStorageToken = getStorageToken;
120
32
  this.logger = logger;
@@ -124,24 +36,6 @@ export class OdspDocumentStorageService {
124
36
  this.epochTracker = epochTracker;
125
37
  this.flushCallback = flushCallback;
126
38
  this.snapshotFormatFetchType = snapshotFormatFetchType;
127
- this.policies = {
128
- // By default, ODSP tells the container not to prefetch/cache.
129
- caching: LoaderCachingPolicy.NoCaching,
130
- // ODSP storage works better if it has less number of blobs / edges
131
- // Runtime creating many small blobs results in sub-optimal perf.
132
- // 2K seems like the sweat spot:
133
- // The smaller the number, less blobs we aggregate. Most storages are very likely to have notion
134
- // of minimal "cluster" size, so having small blobs is wasteful
135
- // At the same time increasing the limit ensure that more blobs with user content are aggregated,
136
- // reducing possibility for de-duping of same blobs (i.e. .attributes rolled into aggregate blob
137
- // are not reused across data stores, or even within data store, resulting in duplication of content)
138
- // Note that duplication of content should not have significant impact for bytes over wire as
139
- // compression of http payload mostly takes care of it, but it does impact storage size and in-memory sizes.
140
- minBlobSize: 2048,
141
- maximumCacheDurationMs: defaultCacheExpiryTimeoutMs,
142
- };
143
- this.commitCache = new Map();
144
- this.attributesBlobHandles = new Set();
145
39
  this.firstVersionCall = true;
146
40
  // Driver specified limits for snapshot size and time.
147
41
  /**
@@ -153,26 +47,12 @@ export class OdspDocumentStorageService {
153
47
  this.maxSnapshotFetchTimeout = 120000; // 2 min
154
48
  // limits the amount of parallel "attachment" blob uploads
155
49
  this.createBlobRateLimiter = new RateLimiter(1);
156
- this.blobCache = new BlobCache();
157
50
  this.documentId = this.odspResolvedUrl.hashedDocumentId;
158
51
  this.snapshotUrl = this.odspResolvedUrl.endpoints.snapshotStorageUrl;
159
52
  this.attachmentPOSTUrl = this.odspResolvedUrl.endpoints.attachmentPOSTStorageUrl;
160
53
  this.attachmentGETUrl = this.odspResolvedUrl.endpoints.attachmentGETStorageUrl;
161
54
  this.odspSummaryUploadManager = new OdspSummaryUploadManager(this.snapshotUrl, getStorageToken, logger, epochTracker, !!((_a = this.hostPolicy.sessionOptions) === null || _a === void 0 ? void 0 : _a.forceAccessTokenViaAuthorizationHeader));
162
55
  }
163
- set ops(ops) {
164
- assert(this._ops === undefined, 0x0a5 /* "Trying to set ops when they are already set!" */);
165
- this._ops = ops;
166
- }
167
- get ops() {
168
- return this._ops;
169
- }
170
- get snapshotSequenceNumber() {
171
- return this._snapshotSequenceNumber;
172
- }
173
- get repositoryUrl() {
174
- return "";
175
- }
176
56
  async createBlob(file) {
177
57
  this.checkAttachmentPOSTUrl();
178
58
  const response = await getWithRetryForTokenRefresh(async (options) => {
@@ -196,70 +76,38 @@ export class OdspDocumentStorageService {
196
76
  });
197
77
  return response.content;
198
78
  }
199
- async readBlobCore(blobId) {
200
- const { blobContent, evicted } = this.blobCache.getBlob(blobId);
201
- let blob = blobContent;
202
- if (blob === undefined) {
203
- this.checkAttachmentGETUrl();
204
- blob = await getWithRetryForTokenRefresh(async (options) => {
205
- var _a;
206
- const storageToken = await this.getStorageToken(options, "GetBlob");
207
- const unAuthedUrl = `${this.attachmentGETUrl}/${encodeURIComponent(blobId)}/content`;
208
- const { url, headers } = getUrlAndHeadersWithAuth(unAuthedUrl, storageToken, !!((_a = this.hostPolicy.sessionOptions) === null || _a === void 0 ? void 0 : _a.forceAccessTokenViaAuthorizationHeader));
209
- return PerformanceEvent.timedExecAsync(this.logger, {
210
- eventName: "readDataBlob",
211
- blobId,
212
- evicted,
213
- headers: Object.keys(headers).length !== 0 ? true : undefined,
214
- waitQueueLength: this.epochTracker.rateLimiter.waitQueueLength,
215
- }, async (event) => {
216
- const res = await this.epochTracker.fetchArray(url, { headers }, "blob");
217
- event.end(Object.assign(Object.assign({ waitQueueLength: this.epochTracker.rateLimiter.waitQueueLength }, res.propsToLog), { attempts: options.refresh ? 2 : 1 }));
218
- const cacheControl = res.headers.get("cache-control");
219
- if (cacheControl === undefined || !(cacheControl.includes("private") || cacheControl.includes("public"))) {
220
- this.logger.sendErrorEvent(Object.assign({ eventName: "NonCacheableBlob", cacheControl,
221
- blobId }, res.propsToLog));
222
- }
223
- return res.content;
224
- });
79
+ async fetchBlobFromStorage(blobId, evicted) {
80
+ this.checkAttachmentGETUrl();
81
+ const blob = await getWithRetryForTokenRefresh(async (options) => {
82
+ var _a;
83
+ const storageToken = await this.getStorageToken(options, "GetBlob");
84
+ const unAuthedUrl = `${this.attachmentGETUrl}/${encodeURIComponent(blobId)}/content`;
85
+ const { url, headers } = getUrlAndHeadersWithAuth(unAuthedUrl, storageToken, !!((_a = this.hostPolicy.sessionOptions) === null || _a === void 0 ? void 0 : _a.forceAccessTokenViaAuthorizationHeader));
86
+ return PerformanceEvent.timedExecAsync(this.logger, {
87
+ eventName: "readDataBlob",
88
+ blobId,
89
+ evicted,
90
+ headers: Object.keys(headers).length !== 0 ? true : undefined,
91
+ waitQueueLength: this.epochTracker.rateLimiter.waitQueueLength,
92
+ }, async (event) => {
93
+ const res = await this.epochTracker.fetchArray(url, { headers }, "blob");
94
+ event.end(Object.assign(Object.assign({ waitQueueLength: this.epochTracker.rateLimiter.waitQueueLength }, res.propsToLog), { attempts: options.refresh ? 2 : 1 }));
95
+ const cacheControl = res.headers.get("cache-control");
96
+ if (cacheControl === undefined || !(cacheControl.includes("private") || cacheControl.includes("public"))) {
97
+ this.logger.sendErrorEvent(Object.assign({ eventName: "NonCacheableBlob", cacheControl,
98
+ blobId }, res.propsToLog));
99
+ }
100
+ return res.content;
225
101
  });
226
- this.blobCache.setBlob(blobId, blob);
227
- }
102
+ });
103
+ this.blobCache.setBlob(blobId, blob);
228
104
  return blob;
229
105
  }
230
- async readBlob(blobId) {
231
- return this.readBlobCore(blobId);
232
- }
233
106
  async getSnapshotTree(version, scenarioName) {
234
107
  if (!this.snapshotUrl) {
235
108
  return null;
236
109
  }
237
- let id;
238
- if (!version || !version.id) {
239
- const versions = await this.getVersions(null, 1, scenarioName);
240
- if (!versions || versions.length === 0) {
241
- return null;
242
- }
243
- id = versions[0].id;
244
- }
245
- else {
246
- id = version.id;
247
- }
248
- const snapshotTree = await this.readTree(id, scenarioName);
249
- if (!snapshotTree) {
250
- return null;
251
- }
252
- if (snapshotTree.blobs) {
253
- const attributesBlob = snapshotTree.blobs.attributes;
254
- if (attributesBlob) {
255
- this.attributesBlobHandles.add(attributesBlob);
256
- }
257
- }
258
- // When we upload the container snapshot, we upload appTree in ".app" and protocol tree in ".protocol"
259
- // So when we request the snapshot we get ".app" as tree and not as commit node as in the case just above.
260
- const appTree = snapshotTree.trees[".app"];
261
- const protocolTree = snapshotTree.trees[".protocol"];
262
- return this.combineProtocolAndAppSnapshotTree(appTree, protocolTree);
110
+ return super.getSnapshotTree(version, scenarioName);
263
111
  }
264
112
  async getVersions(blobid, count, scenarioName) {
265
113
  // Regular load workflow uses blobId === documentID to indicate "latest".
@@ -358,19 +206,7 @@ export class OdspDocumentStorageService {
358
206
  });
359
207
  // Successful call, make network calls only
360
208
  this.firstVersionCall = false;
361
- this._snapshotSequenceNumber = odspSnapshotCacheValue.sequenceNumber;
362
- const { snapshotTree, blobs, ops } = odspSnapshotCacheValue;
363
- // id should be undefined in case of just ops in snapshot.
364
- let id;
365
- if (snapshotTree) {
366
- id = snapshotTree.id;
367
- assert(id !== undefined, 0x221 /* "Root tree should contain the id" */);
368
- this.setRootTree(id, snapshotTree);
369
- }
370
- if (blobs) {
371
- this.initBlobsCache(blobs);
372
- }
373
- this.ops = ops;
209
+ const id = this.initializeFromSnapshot(odspSnapshotCacheValue);
374
210
  return id ? [{ id, treeId: undefined }] : [];
375
211
  }
376
212
  return getWithRetryForTokenRefresh(async (options) => {
@@ -455,34 +291,25 @@ export class OdspDocumentStorageService {
455
291
  this.checkSnapshotUrl();
456
292
  // Enable flushing only if we have single commit summary and this is not the initial summary for an empty file
457
293
  if (".protocol" in summary.tree && context.ackHandle !== undefined) {
458
- let retry = 0;
294
+ let retry = 1;
459
295
  for (;;) {
460
296
  const result = await this.flushCallback();
461
297
  const seq = result.lastPersistedSequenceNumber;
462
298
  if (seq !== undefined && seq >= context.referenceSequenceNumber) {
463
299
  break;
464
300
  }
465
- retry++;
466
301
  if (retry > 3) {
467
302
  this.logger.sendErrorEvent(Object.assign(Object.assign({ eventName: "FlushFailure" }, result), { retry, referenceSequenceNumber: context.referenceSequenceNumber }));
468
303
  break;
469
304
  }
470
305
  this.logger.sendPerformanceEvent(Object.assign(Object.assign({ eventName: "FlushExtraCall" }, result), { retry, referenceSequenceNumber: context.referenceSequenceNumber }));
306
+ retry++;
471
307
  await delay(1000 * ((_a = result.retryAfter) !== null && _a !== void 0 ? _a : 1));
472
308
  }
473
309
  }
474
310
  const id = await this.odspSummaryUploadManager.writeSummaryTree(summary, context);
475
311
  return id;
476
312
  }
477
- async downloadSummary(commit) {
478
- throw new Error("Not implemented yet");
479
- }
480
- setRootTree(id, tree) {
481
- this.commitCache.set(id, tree);
482
- }
483
- initBlobsCache(blobs) {
484
- this.blobCache.addBlobs(blobs);
485
- }
486
313
  checkSnapshotUrl() {
487
314
  if (!this.snapshotUrl) {
488
315
  throw new NonRetryableError("Method failed because no snapshot url was available", DriverErrorType.genericError, { driverVersion });
@@ -498,47 +325,27 @@ export class OdspDocumentStorageService {
498
325
  throw new NonRetryableError("Method failed because no attachment GET url was available", DriverErrorType.genericError, { driverVersion });
499
326
  }
500
327
  }
501
- async readTree(id, scenarioName) {
502
- if (!this.snapshotUrl) {
503
- return null;
504
- }
505
- let tree = this.commitCache.get(id);
506
- if (!tree) {
507
- tree = await getWithRetryForTokenRefresh(async (options) => {
508
- var _a, _b;
509
- const storageToken = await this.getStorageToken(options, "ReadCommit");
510
- const snapshotDownloader = async (url, fetchOptions) => {
511
- return this.epochTracker.fetchAndParseAsJSON(url, fetchOptions, "snapshotTree", undefined, scenarioName);
512
- };
513
- const snapshot = await fetchSnapshot(this.snapshotUrl, storageToken, id, this.fetchFullSnapshot, !!((_a = this.hostPolicy.sessionOptions) === null || _a === void 0 ? void 0 : _a.forceAccessTokenViaAuthorizationHeader), this.logger, snapshotDownloader);
514
- let treeId = "";
515
- if (snapshot.snapshotTree) {
516
- assert(snapshot.snapshotTree.id !== undefined, 0x222 /* "Root tree should contain the id!!" */);
517
- treeId = snapshot.snapshotTree.id;
518
- this.setRootTree(treeId, snapshot.snapshotTree);
519
- }
520
- if (snapshot.blobs) {
521
- this.initBlobsCache(snapshot.blobs);
522
- }
523
- // If the version id doesn't match with the id of the tree, then use the id of first tree which in that case
524
- // will be the actual id of tree to be fetched.
525
- return (_b = this.commitCache.get(id)) !== null && _b !== void 0 ? _b : this.commitCache.get(treeId);
526
- });
527
- }
528
- if (!tree) {
529
- return null;
530
- }
531
- return tree;
532
- }
533
- combineProtocolAndAppSnapshotTree(hierarchicalAppTree, hierarchicalProtocolTree) {
534
- const summarySnapshotTree = {
535
- blobs: Object.assign({}, hierarchicalAppTree.blobs),
536
- trees: Object.assign(Object.assign({}, hierarchicalAppTree.trees), {
537
- // the app tree could have a .protocol
538
- // in that case we want to server protocol to override it
539
- ".protocol": hierarchicalProtocolTree }),
540
- };
541
- return summarySnapshotTree;
328
+ async fetchTreeFromSnapshot(id, scenarioName) {
329
+ return getWithRetryForTokenRefresh(async (options) => {
330
+ var _a, _b;
331
+ const storageToken = await this.getStorageToken(options, "ReadCommit");
332
+ const snapshotDownloader = async (url, fetchOptions) => {
333
+ return this.epochTracker.fetchAndParseAsJSON(url, fetchOptions, "snapshotTree", undefined, scenarioName);
334
+ };
335
+ const snapshot = await fetchSnapshot(this.snapshotUrl, storageToken, id, this.fetchFullSnapshot, !!((_a = this.hostPolicy.sessionOptions) === null || _a === void 0 ? void 0 : _a.forceAccessTokenViaAuthorizationHeader), this.logger, snapshotDownloader);
336
+ let treeId = "";
337
+ if (snapshot.snapshotTree) {
338
+ assert(snapshot.snapshotTree.id !== undefined, 0x222 /* "Root tree should contain the id!!" */);
339
+ treeId = snapshot.snapshotTree.id;
340
+ this.setRootTree(treeId, snapshot.snapshotTree);
341
+ }
342
+ if (snapshot.blobs) {
343
+ this.initBlobsCache(snapshot.blobs);
344
+ }
345
+ // If the version id doesn't match with the id of the tree, then use the id of first tree which in that case
346
+ // will be the actual id of tree to be fetched.
347
+ return (_b = this.commitCache.get(id)) !== null && _b !== void 0 ? _b : this.commitCache.get(treeId);
348
+ });
542
349
  }
543
350
  }
544
351
  /* eslint-enable max-len */
@@ -1 +1 @@
1
- {"version":3,"file":"odspDocumentStorageManager.js","sourceRoot":"","sources":["../src/odspDocumentStorageManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACH,MAAM,EACN,KAAK,GACR,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACH,gBAAgB,GACnB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAGH,mBAAmB,EACnB,eAAe,GAClB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAGH,aAAa,GAEhB,MAAM,yCAAyC,CAAC;AAOjD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,uBAAuB,EAA6B,MAAM,iBAAiB,CAAC;AACtH,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,OAAO,EACH,sBAAsB,EACtB,2BAA2B,GAC9B,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,2BAA2B,EAAgB,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,OAAO,EAAE,UAAU,IAAI,aAAa,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C3C,KAAK,oBACE,mBAAmB,CAAC,KAAK,CAC/B;YACD,KAAK,kCACE,mBAAmB,CAAC,KAAK;gBAC5B,sCAAsC;gBACtC,yDAAyD;gBACzD,WAAW,EAAE,wBAAwB,GACxC;SACJ,CAAC;QAEF,OAAO,mBAAmB,CAAC;IAC/B,CAAC;CACJ;AAED,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,OAAO,EACH,MAAM,EACN,KAAK,GACR,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACH,gBAAgB,GACnB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAEH,eAAe,GAClB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAGH,aAAa,GAEhB,MAAM,yCAAyC,CAAC;AAOjD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,uBAAuB,EAA6B,MAAM,iBAAiB,CAAC;AACtH,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,OAAO,EACH,sBAAsB,EACtB,2BAA2B,GAC9B,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAElF,MAAM,CAAC,MAAM,mCAAmC,GAAW,EAAE,GAAG,IAAI,CAAC,CAAC,cAAc;AAEpF,4BAA4B;AAE5B,kFAAkF;AAClF,KAAK,UAAU,qBAAqB,CAAI,QAAsB;IAC1D,OAAO,IAAI,OAAO,CAA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K,SAAS,EAAE,KAAK,CAAC,yCAAyC,CAAC,CAAC;gBAChG,MAAM,GAAG,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;gBAClC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;aACnD;YACD,IAAI,QAAQ,CAAC,KAAK,EAAE;gBAChB,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;aACvC;YACD,4GAA4G;YAC5G,+CAA+C;YAC/C,OAAO,MAAA,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,mCAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACpE,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,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 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"]}