Skip to content

Commit 60f16f1

Browse files
jatgargJatin Garg
and
Jatin Garg
authored
Extract serialized blobs from the ISnapshot instead of fetching from driver which could make network calls (#21908)
## Description Extract serialized blobs from the ISnapshot which contains blob contents instead of fetching from driver which could make network calls. This affects the cases in Data virtualization where initial blob contents for some trees are missing in the snapshot and therefore driver does not have the contents cached, so it ends up making a bunch of network calls. --------- Co-authored-by: Jatin Garg <[email protected]>
1 parent 63141a0 commit 60f16f1

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

packages/loader/container-loader/src/containerStorageAdapter.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
ISnapshotTree,
2121
IVersion,
2222
} from "@fluidframework/driver-definitions/internal";
23-
import { UsageError } from "@fluidframework/driver-utils/internal";
23+
import { isInstanceOfISnapshot, UsageError } from "@fluidframework/driver-utils/internal";
2424
import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
2525

2626
// eslint-disable-next-line import/no-deprecated
@@ -31,7 +31,7 @@ import type {
3131
ISerializedStateManagerDocumentStorageService,
3232
ISnapshotInfo,
3333
} from "./serializedStateManager.js";
34-
import { convertSnapshotInfoToSnapshot, getDocumentAttributes } from "./utils.js";
34+
import { convertSnapshotInfoToSnapshot } from "./utils.js";
3535

3636
/**
3737
* Stringified blobs from a summary/snapshot tree.
@@ -179,8 +179,10 @@ export class ContainerStorageAdapter
179179
const localSnapshot =
180180
this.loadingGroupIdSnapshotsFromPendingState[snapshotFetchOptions.loadingGroupIds[0]];
181181
assert(localSnapshot !== undefined, 0x970 /* Local snapshot must be present */);
182-
const attributes = await getDocumentAttributes(this, localSnapshot.baseSnapshot);
183-
snapshot = convertSnapshotInfoToSnapshot(localSnapshot, attributes.sequenceNumber);
182+
snapshot = convertSnapshotInfoToSnapshot(
183+
localSnapshot,
184+
localSnapshot.snapshotSequenceNumber,
185+
);
184186
} else {
185187
if (this._storageService.getSnapshot === undefined) {
186188
throw new UsageError(
@@ -315,11 +317,19 @@ const redirectTableBlobName = ".redirectTable";
315317
* Get blob contents of a snapshot tree from storage (or, ideally, cache)
316318
*/
317319
export async function getBlobContentsFromTree(
318-
snapshot: ISnapshotTree,
320+
snapshot: ISnapshot | ISnapshotTree,
319321
storage: Pick<IDocumentStorageService, "readBlob">,
320322
): Promise<ISerializableBlobContents> {
321323
const blobs = {};
322-
await getBlobContentsFromTreeCore(snapshot, blobs, storage);
324+
if (isInstanceOfISnapshot(snapshot)) {
325+
const blobContents = snapshot.blobContents;
326+
for (const [id, content] of blobContents.entries()) {
327+
// ArrayBufferLike will not survive JSON.stringify()
328+
blobs[id] = bufferToString(content, "utf8");
329+
}
330+
} else {
331+
await getBlobContentsFromTreeCore(snapshot, blobs, storage);
332+
}
323333
return blobs;
324334
}
325335

packages/loader/container-loader/src/serializedStateManager.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,7 @@ export class SerializedStateManager {
242242
const baseSnapshotTree: ISnapshotTree | undefined = getSnapshotTree(baseSnapshot);
243243
// non-interactive clients will not have any pending state we want to save
244244
if (this.offlineLoadEnabled) {
245-
const snapshotBlobs = await getBlobContentsFromTree(
246-
baseSnapshotTree,
247-
this.storageAdapter,
248-
);
245+
const snapshotBlobs = await getBlobContentsFromTree(baseSnapshot, this.storageAdapter);
249246
const attributes = await getDocumentAttributes(this.storageAdapter, baseSnapshotTree);
250247
this.snapshot = {
251248
baseSnapshot: baseSnapshotTree,
@@ -524,7 +521,7 @@ export async function getLatestSnapshotInfo(
524521

525522
const baseSnapshotTree: ISnapshotTree | undefined = getSnapshotTree(baseSnapshot);
526523
const snapshotFetchedTime = Date.now();
527-
const snapshotBlobs = await getBlobContentsFromTree(baseSnapshotTree, storageAdapter);
524+
const snapshotBlobs = await getBlobContentsFromTree(baseSnapshot, storageAdapter);
528525
const attributes: IDocumentAttributes = await getDocumentAttributes(
529526
storageAdapter,
530527
baseSnapshotTree,

packages/test/test-end-to-end-tests/src/test/data-virtualization/groupIdBlobReads.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describeCompat("Odsp Network calls", "NoCompat", (getTestObjectProvider) => {
6262
mainObject._root.set("dataObjectB", dataStoreB.entryPoint);
6363
};
6464

65-
it.skip("Should not make odsp network calls", async () => {
65+
it("Should not make odsp network calls", async () => {
6666
const container = await provider.makeTestContainer({
6767
runtimeOptions,
6868
loaderProps: { configProvider },

0 commit comments

Comments
 (0)