@fluidframework/merge-tree 2.102.0 → 2.103.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/CHANGELOG.md +4 -0
- package/dist/client.d.ts +3 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js.map +1 -1
- package/dist/snapshotChunks.d.ts +4 -4
- package/dist/snapshotChunks.d.ts.map +1 -1
- package/dist/snapshotChunks.js.map +1 -1
- package/dist/snapshotLoader.d.ts +2 -2
- package/dist/snapshotLoader.d.ts.map +1 -1
- package/dist/snapshotLoader.js.map +1 -1
- package/dist/snapshotV1.d.ts +4 -4
- package/dist/snapshotV1.d.ts.map +1 -1
- package/dist/snapshotV1.js.map +1 -1
- package/dist/snapshotlegacy.d.ts +2 -2
- package/dist/snapshotlegacy.d.ts.map +1 -1
- package/dist/snapshotlegacy.js.map +1 -1
- package/lib/client.d.ts +3 -3
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js.map +1 -1
- package/lib/snapshotChunks.d.ts +4 -4
- package/lib/snapshotChunks.d.ts.map +1 -1
- package/lib/snapshotChunks.js.map +1 -1
- package/lib/snapshotLoader.d.ts +2 -2
- package/lib/snapshotLoader.d.ts.map +1 -1
- package/lib/snapshotLoader.js.map +1 -1
- package/lib/snapshotV1.d.ts +4 -4
- package/lib/snapshotV1.d.ts.map +1 -1
- package/lib/snapshotV1.js.map +1 -1
- package/lib/snapshotlegacy.d.ts +2 -2
- package/lib/snapshotlegacy.d.ts.map +1 -1
- package/lib/snapshotlegacy.js.map +1 -1
- package/package.json +15 -15
- package/src/client.ts +2 -2
- package/src/snapshotChunks.ts +4 -4
- package/src/snapshotLoader.ts +3 -3
- package/src/snapshotV1.ts +5 -5
- package/src/snapshotlegacy.ts +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshotLoader.js","sourceRoot":"","sources":["../src/snapshotLoader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,6DA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ation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport type { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport type { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\ttype ITelemetryLoggerExt,\n\tUsageError,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { Client } from \"./client.js\";\nimport { NonCollabClient, UniversalSequenceNumber } from \"./constants.js\";\nimport type { MergeTree } from \"./mergeTree.js\";\nimport type { ISegmentPrivate } from \"./mergeTreeNodes.js\";\nimport type { IJSONSegment } from \"./ops.js\";\nimport { PriorPerspective } from \"./perspective.js\";\nimport {\n\ttype IHasRemovalInfo,\n\toverwriteInfo,\n\ttype IHasInsertionInfo,\n\ttype SegmentWithInfo,\n} from \"./segmentInfos.js\";\nimport {\n\ttype IJSONSegmentWithMergeInfo,\n\ttype MergeTreeChunkV1,\n\thasMergeInfo,\n} from \"./snapshotChunks.js\";\nimport { SnapshotV1 } from \"./snapshotV1.js\";\nimport { SnapshotLegacy } from \"./snapshotlegacy.js\";\nimport type { RemoveOperationStamp } from \"./stamps.js\";\nimport * as opstampUtils from \"./stamps.js\";\n\nexport class SnapshotLoader {\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tconstructor(\n\t\tprivate readonly runtime: IFluidDataStoreRuntime,\n\n\t\tprivate readonly client: Client,\n\t\tprivate readonly mergeTree: MergeTree,\n\t\tlogger: ITelemetryLoggerExt,\n\t\tprivate readonly serializer: IFluidSerializer,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"SnapshotLoader\" });\n\t}\n\n\tpublic async initialize(\n\t\tservices: IChannelStorageService,\n\t): Promise<{ catchupOpsP: Promise<ISequencedDocumentMessage[]> }> {\n\t\tconst headerLoadedP = services.readBlob(SnapshotLegacy.header).then((header) => {\n\t\t\tassert(!!header, 0x05f /* \"Missing blob header on legacy snapshot!\" */);\n\t\t\treturn this.loadHeader(bufferToString(header, \"utf8\"));\n\t\t});\n\n\t\tconst catchupOpsP = this.loadBodyAndCatchupOps(headerLoadedP, services);\n\n\t\tcatchupOpsP.catch((error) =>\n\t\t\tthis.logger.sendErrorEvent({ eventName: \"CatchupOpsLoadFailure\" }, error),\n\t\t);\n\n\t\tawait headerLoadedP;\n\n\t\treturn { catchupOpsP };\n\t}\n\n\tprivate async loadBodyAndCatchupOps(\n\t\theaderChunkP: Promise<MergeTreeChunkV1>,\n\t\tservices: IChannelStorageService,\n\t): Promise<ISequencedDocumentMessage[]> {\n\t\tconst blobsP = services.list(\"\");\n\t\tconst headerChunk = await headerChunkP;\n\n\t\t// TODO we shouldn't need to wait on the body being complete to finish initialization.\n\t\t// To fully support this we need to be able to process inbound ops for pending segments.\n\t\tawait this.loadBody(headerChunk, services);\n\n\t\tconst blobs = await blobsP;\n\t\tif (blobs.length === headerChunk.headerMetadata!.orderedChunkMetadata.length + 1) {\n\t\t\tfor (const md of headerChunk.headerMetadata!.orderedChunkMetadata)\n\t\t\t\tblobs.splice(blobs.indexOf(md.id), 1);\n\t\t\tassert(blobs.length === 1, 0x060 /* There should be only one blob with catch up ops */);\n\n\t\t\t// TODO: The 'Snapshot.catchupOps' tree entry is purely for backwards compatibility.\n\t\t\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\n\t\t\treturn this.loadCatchupOps(services.readBlob(blobs[0]), this.serializer);\n\t\t} else if (blobs.length !== headerChunk.headerMetadata!.orderedChunkMetadata.length) {\n\t\t\tthrow new Error(\"Unexpected blobs in snapshot\");\n\t\t}\n\t\treturn [];\n\t}\n\n\tprivate readonly specToSegment = (\n\t\tspec: IJSONSegment | IJSONSegmentWithMergeInfo,\n\t): SegmentWithInfo<IHasInsertionInfo> => {\n\t\tif (hasMergeInfo(spec)) {\n\t\t\tconst seg = overwriteInfo<IHasInsertionInfo>(this.client.specToSegment(spec.json), {\n\t\t\t\tinsert: {\n\t\t\t\t\ttype: \"insert\",\n\t\t\t\t\tseq: spec.seq ?? UniversalSequenceNumber,\n\t\t\t\t\tclientId:\n\t\t\t\t\t\tspec.client === undefined\n\t\t\t\t\t\t\t? NonCollabClient\n\t\t\t\t\t\t\t: this.client.getOrAddShortClientId(spec.client),\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconst removes: RemoveOperationStamp[] = [];\n\n\t\t\tif (spec.removedSeq !== undefined) {\n\t\t\t\t// this format had a bug where it didn't store all the overlap clients\n\t\t\t\t// this is for back compat, so we change the singular id to an array\n\t\t\t\t// this will only cause problems if there is an overlapping delete\n\t\t\t\t// spanning the snapshot, which should be rare\n\t\t\t\tconst specAsBuggyFormat: IJSONSegmentWithMergeInfo & { removedClient?: string } = spec;\n\t\t\t\tif (specAsBuggyFormat.removedClient !== undefined) {\n\t\t\t\t\tspec.removedClientIds ??= [specAsBuggyFormat.removedClient];\n\t\t\t\t}\n\t\t\t\tassert(spec.removedClientIds !== undefined, 0xaac /* must have removedClient ids */);\n\t\t\t\tconst firstRemovedSeq = spec.removedSeq;\n\t\t\t\t// TODO:AB#32299: To correctly support perspectives from other clients which don't assume they have seen\n\t\t\t\t// all ops, we need to actually record these in the summary. For now we use fake data, and it turns\n\t\t\t\t// out ok since none of these values end up being used. (specifically, the 'firstRemovedSeq' is fake\n\t\t\t\t// for all values other than the actual first remove).\n\t\t\t\t// This issue only affects V1 summaries, as the strategy in snapshotlegacy avoids storing merge info directly.\n\t\t\t\tfor (const id of spec.removedClientIds) {\n\t\t\t\t\tremoves.push({\n\t\t\t\t\t\ttype: \"setRemove\",\n\t\t\t\t\t\tseq: firstRemovedSeq,\n\t\t\t\t\t\tclientId: this.client.getOrAddShortClientId(id),\n\t\t\t\t\t} as const);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (spec.movedSeq !== undefined) {\n\t\t\t\tassert(\n\t\t\t\t\tspec.movedClientIds !== undefined && spec.movedSeqs !== undefined,\n\t\t\t\t\t0xaa5 /* must have movedIds ids */,\n\t\t\t\t);\n\t\t\t\tassert(\n\t\t\t\t\tspec.movedClientIds.length === spec.movedSeqs.length,\n\t\t\t\t\t0xb5f /* Expected same length for client ids and seqs */,\n\t\t\t\t);\n\n\t\t\t\t// Avoid spreading into push: a large array could exceed the engine's\n\t\t\t\t// argument-count limit and throw RangeError.\n\t\t\t\tfor (let i = 0; i < spec.movedClientIds.length; i++) {\n\t\t\t\t\tremoves.push({\n\t\t\t\t\t\ttype: \"sliceRemove\",\n\t\t\t\t\t\tseq: spec.movedSeqs[i],\n\t\t\t\t\t\tclientId: this.client.getOrAddShortClientId(spec.movedClientIds[i]),\n\t\t\t\t\t} as const);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (removes.length > 0) {\n\t\t\t\tremoves.sort(opstampUtils.compare);\n\t\t\t\toverwriteInfo<IHasRemovalInfo>(seg, { removes });\n\t\t\t}\n\n\t\t\treturn seg;\n\t\t}\n\t\treturn overwriteInfo(this.client.specToSegment(spec), {\n\t\t\tinsert: {\n\t\t\t\ttype: \"insert\",\n\t\t\t\tseq: UniversalSequenceNumber,\n\t\t\t\tclientId: NonCollabClient,\n\t\t\t},\n\t\t});\n\t};\n\n\tprivate loadHeader(header: string): MergeTreeChunkV1 {\n\t\tconst chunk = SnapshotV1.processChunk(\n\t\t\tSnapshotLegacy.header,\n\t\t\theader,\n\t\t\tthis.logger,\n\t\t\tthis.mergeTree.options,\n\t\t\tthis.serializer,\n\t\t);\n\t\tconst segs = chunk.segments.map((element) => this.specToSegment(element));\n\t\tthis.extractAttribution(segs, chunk);\n\n\t\tthis.mergeTree.reloadFromSegments(segs);\n\n\t\tif (chunk.headerMetadata === undefined) {\n\t\t\tthrow new Error(\"header metadata not available\");\n\t\t}\n\t\t// If we load a detached container from snapshot, then we don't supply a default clientId\n\t\t// because we don't want to start collaboration.\n\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\t// specify a default client id, \"snapshot\" here as we\n\t\t\t// should enter collaboration/op sending mode if we load\n\t\t\t// a snapshot in any case (summary or attach message)\n\t\t\t// once we get a client id this will be called with that\n\t\t\t// clientId in the connected event\n\t\t\tthis.client.startOrUpdateCollaboration(\n\t\t\t\tthis.runtime.clientId ?? \"snapshot\",\n\n\t\t\t\t// TODO: Make 'minSeq' non-optional once the new snapshot format becomes the default?\n\t\t\t\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\t\t\t\t/* minSeq: */ chunk.headerMetadata.minSequenceNumber ??\n\t\t\t\t\tchunk.headerMetadata.sequenceNumber,\n\t\t\t\t/* currentSeq: */ chunk.headerMetadata.sequenceNumber,\n\t\t\t);\n\t\t}\n\n\t\treturn chunk;\n\t}\n\n\tprivate async loadBody(\n\t\tchunk1: MergeTreeChunkV1,\n\t\tservices: IChannelStorageService,\n\t): Promise<void> {\n\t\tconst headerMetadata = chunk1.headerMetadata!;\n\t\tassert(chunk1.length <= headerMetadata.totalLength, 0x061 /* \"Mismatch in totalLength\" */);\n\n\t\tassert(\n\t\t\tchunk1.segmentCount <= headerMetadata.totalSegmentCount,\n\t\t\t0x062 /* \"Mismatch in totalSegmentCount\" */,\n\t\t);\n\n\t\tif (chunk1.segmentCount === headerMetadata.totalSegmentCount) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet chunksWithAttribution = chunk1.attribution === undefined ? 0 : 1;\n\t\tconst segs: SegmentWithInfo<IHasInsertionInfo>[] = [];\n\t\tlet lengthSofar = chunk1.length;\n\t\tfor (\n\t\t\tlet chunkIndex = 1;\n\t\t\tchunkIndex < headerMetadata.orderedChunkMetadata.length;\n\t\t\tchunkIndex++\n\t\t) {\n\t\t\tconst chunk = await SnapshotV1.loadChunk(\n\t\t\t\tservices,\n\t\t\t\theaderMetadata.orderedChunkMetadata[chunkIndex].id,\n\t\t\t\tthis.logger,\n\t\t\t\tthis.mergeTree.options,\n\t\t\t\tthis.serializer,\n\t\t\t);\n\t\t\tlengthSofar += chunk.length;\n\t\t\t// Deserialize each chunk segment and append it to the end of the MergeTree.\n\t\t\tconst newSegs = chunk.segments.map((element) => this.specToSegment(element));\n\t\t\tthis.extractAttribution(newSegs, chunk);\n\t\t\tchunksWithAttribution += chunk.attribution === undefined ? 0 : 1;\n\t\t\t// Avoid `push(...newSegs)`: spreading a large array into a variadic call\n\t\t\t// can exceed the engine's argument-count limit and throw RangeError.\n\t\t\tfor (const seg of newSegs) {\n\t\t\t\tsegs.push(seg);\n\t\t\t}\n\t\t}\n\n\t\tassert(\n\t\t\tchunksWithAttribution === 0 ||\n\t\t\t\tchunksWithAttribution === headerMetadata.orderedChunkMetadata.length,\n\t\t\t0x4c0 /* all or no chunks should have attribution information */,\n\t\t);\n\n\t\tassert(lengthSofar === headerMetadata.totalLength, 0x063 /* \"Mismatch in totalLength\" */);\n\n\t\tassert(\n\t\t\tchunk1.segmentCount + segs.length === headerMetadata.totalSegmentCount,\n\t\t\t0x064 /* \"Mismatch in totalSegmentCount\" */,\n\t\t);\n\n\t\t// Helper to insert segments at the end of the MergeTree.\n\t\tconst mergeTree = this.mergeTree;\n\t\tconst append = (segments: ISegmentPrivate[], clientId: number, seq: number): void => {\n\t\t\tmergeTree.insertSegments(\n\t\t\t\tmergeTree.root.cachedLength ?? 0,\n\t\t\t\tsegments,\n\t\t\t\tnew PriorPerspective(UniversalSequenceNumber, clientId),\n\t\t\t\t{ seq, clientId },\n\t\t\t\tundefined,\n\t\t\t);\n\t\t};\n\n\t\t// Helpers to batch-insert segments that are below the min seq\n\t\tconst batch: SegmentWithInfo<IHasInsertionInfo>[] = [];\n\t\tconst flushBatch = (): void => {\n\t\t\tif (batch.length > 0) {\n\t\t\t\tappend(batch, NonCollabClient, UniversalSequenceNumber);\n\t\t\t}\n\t\t};\n\n\t\tfor (const seg of segs) {\n\t\t\tconst { clientId, seq } = seg.insert;\n\t\t\t// If the segment can be batch inserted, add it to the 'batch' array. Otherwise, flush\n\t\t\t// any batched segments and then insert the current segment individually.\n\t\t\tif (clientId === NonCollabClient && seq === UniversalSequenceNumber) {\n\t\t\t\tbatch.push(seg);\n\t\t\t} else {\n\t\t\t\tflushBatch();\n\t\t\t\tappend([seg], clientId, seq);\n\t\t\t}\n\t\t}\n\n\t\tflushBatch();\n\t}\n\n\tprivate extractAttribution(segments: ISegmentPrivate[], chunk: MergeTreeChunkV1): void {\n\t\tif (chunk.attribution) {\n\t\t\tconst { attributionPolicy } = this.mergeTree;\n\t\t\tif (attributionPolicy === undefined) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"Attribution policy must be provided when loading a document with attribution information.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst { isAttached, attach, serializer } = attributionPolicy;\n\t\t\tif (!isAttached) {\n\t\t\t\tattach(this.client);\n\t\t\t}\n\t\t\tserializer.populateAttributionCollections(segments, chunk.attribution);\n\t\t} else {\n\t\t\tconst { attributionPolicy } = this.mergeTree;\n\t\t\tif (attributionPolicy?.isAttached) {\n\t\t\t\tattributionPolicy?.detach();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * If loading from a snapshot, get the catchup messages.\n\t * @param rawMessages - The messages in original encoding\n\t * @returns The decoded messages with parsed+hydrated handles. Matches the format that will be passed in\n\t * SharedObject.processCore.\n\t */\n\tprivate async loadCatchupOps(\n\t\trawMessages: Promise<ArrayBufferLike>,\n\t\tserializer: IFluidSerializer,\n\t): Promise<ISequencedDocumentMessage[]> {\n\t\treturn serializer.parse(\n\t\t\tbufferToString(await rawMessages, \"utf8\"),\n\t\t) as ISequencedDocumentMessage[];\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"snapshotLoader.js","sourceRoot":"","sources":["../src/snapshotLoader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,6DAA6D;AAE7D,OAAO,EAAE,cAAc,EA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,KAAK,eAAe,IAAI,GAAG,KAAK,uBAAuB,EAAE,CAAC;gBACrE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACjB,CAAC;iBAAM,CAAC;gBACP,UAAU,EAAE,CAAC;gBACb,MAAM,CAAC,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;YAC9B,CAAC;QACF,CAAC;QAED,UAAU,EAAE,CAAC;IACd,CAAC;IAEO,kBAAkB,CAAC,QAA2B,EAAE,KAAuB;QAC9E,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;YACvB,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;YAC7C,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;gBACrC,MAAM,IAAI,UAAU,CACnB,2FAA2F,CAC3F,CAAC;YACH,CAAC;YAED,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,iBAAiB,CAAC;YAC7D,IAAI,CAAC,UAAU,EAAE,CAAC;gBACjB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACrB,CAAC;YACD,UAAU,CAAC,8BAA8B,CAAC,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;QACxE,CAAC;aAAM,CAAC;YACP,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;YAC7C,IAAI,iBAAiB,EAAE,UAAU,EAAE,CAAC;gBACnC,iBAAiB,EAAE,MAAM,EAAE,CAAC;YAC7B,CAAC;QACF,CAAC;IACF,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,cAAc,CAC3B,WAAqC,EACrC,UAA4B;QAE5B,OAAO,UAAU,CAAC,KAAK,CACtB,cAAc,CAAC,MAAM,WAAW,EAAE,MAAM,CAAC,CACV,CAAC;IAClC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport type { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport type { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\ttype TelemetryLoggerExt,\n\tUsageError,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { Client } from \"./client.js\";\nimport { NonCollabClient, UniversalSequenceNumber } from \"./constants.js\";\nimport type { MergeTree } from \"./mergeTree.js\";\nimport type { ISegmentPrivate } from \"./mergeTreeNodes.js\";\nimport type { IJSONSegment } from \"./ops.js\";\nimport { PriorPerspective } from \"./perspective.js\";\nimport {\n\ttype IHasRemovalInfo,\n\toverwriteInfo,\n\ttype IHasInsertionInfo,\n\ttype SegmentWithInfo,\n} from \"./segmentInfos.js\";\nimport {\n\ttype IJSONSegmentWithMergeInfo,\n\ttype MergeTreeChunkV1,\n\thasMergeInfo,\n} from \"./snapshotChunks.js\";\nimport { SnapshotV1 } from \"./snapshotV1.js\";\nimport { SnapshotLegacy } from \"./snapshotlegacy.js\";\nimport type { RemoveOperationStamp } from \"./stamps.js\";\nimport * as opstampUtils from \"./stamps.js\";\n\nexport class SnapshotLoader {\n\tprivate readonly logger: TelemetryLoggerExt;\n\n\tconstructor(\n\t\tprivate readonly runtime: IFluidDataStoreRuntime,\n\n\t\tprivate readonly client: Client,\n\t\tprivate readonly mergeTree: MergeTree,\n\t\tlogger: TelemetryLoggerExt,\n\t\tprivate readonly serializer: IFluidSerializer,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"SnapshotLoader\" });\n\t}\n\n\tpublic async initialize(\n\t\tservices: IChannelStorageService,\n\t): Promise<{ catchupOpsP: Promise<ISequencedDocumentMessage[]> }> {\n\t\tconst headerLoadedP = services.readBlob(SnapshotLegacy.header).then((header) => {\n\t\t\tassert(!!header, 0x05f /* \"Missing blob header on legacy snapshot!\" */);\n\t\t\treturn this.loadHeader(bufferToString(header, \"utf8\"));\n\t\t});\n\n\t\tconst catchupOpsP = this.loadBodyAndCatchupOps(headerLoadedP, services);\n\n\t\tcatchupOpsP.catch((error) =>\n\t\t\tthis.logger.sendErrorEvent({ eventName: \"CatchupOpsLoadFailure\" }, error),\n\t\t);\n\n\t\tawait headerLoadedP;\n\n\t\treturn { catchupOpsP };\n\t}\n\n\tprivate async loadBodyAndCatchupOps(\n\t\theaderChunkP: Promise<MergeTreeChunkV1>,\n\t\tservices: IChannelStorageService,\n\t): Promise<ISequencedDocumentMessage[]> {\n\t\tconst blobsP = services.list(\"\");\n\t\tconst headerChunk = await headerChunkP;\n\n\t\t// TODO we shouldn't need to wait on the body being complete to finish initialization.\n\t\t// To fully support this we need to be able to process inbound ops for pending segments.\n\t\tawait this.loadBody(headerChunk, services);\n\n\t\tconst blobs = await blobsP;\n\t\tif (blobs.length === headerChunk.headerMetadata!.orderedChunkMetadata.length + 1) {\n\t\t\tfor (const md of headerChunk.headerMetadata!.orderedChunkMetadata)\n\t\t\t\tblobs.splice(blobs.indexOf(md.id), 1);\n\t\t\tassert(blobs.length === 1, 0x060 /* There should be only one blob with catch up ops */);\n\n\t\t\t// TODO: The 'Snapshot.catchupOps' tree entry is purely for backwards compatibility.\n\t\t\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\n\t\t\treturn this.loadCatchupOps(services.readBlob(blobs[0]), this.serializer);\n\t\t} else if (blobs.length !== headerChunk.headerMetadata!.orderedChunkMetadata.length) {\n\t\t\tthrow new Error(\"Unexpected blobs in snapshot\");\n\t\t}\n\t\treturn [];\n\t}\n\n\tprivate readonly specToSegment = (\n\t\tspec: IJSONSegment | IJSONSegmentWithMergeInfo,\n\t): SegmentWithInfo<IHasInsertionInfo> => {\n\t\tif (hasMergeInfo(spec)) {\n\t\t\tconst seg = overwriteInfo<IHasInsertionInfo>(this.client.specToSegment(spec.json), {\n\t\t\t\tinsert: {\n\t\t\t\t\ttype: \"insert\",\n\t\t\t\t\tseq: spec.seq ?? UniversalSequenceNumber,\n\t\t\t\t\tclientId:\n\t\t\t\t\t\tspec.client === undefined\n\t\t\t\t\t\t\t? NonCollabClient\n\t\t\t\t\t\t\t: this.client.getOrAddShortClientId(spec.client),\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconst removes: RemoveOperationStamp[] = [];\n\n\t\t\tif (spec.removedSeq !== undefined) {\n\t\t\t\t// this format had a bug where it didn't store all the overlap clients\n\t\t\t\t// this is for back compat, so we change the singular id to an array\n\t\t\t\t// this will only cause problems if there is an overlapping delete\n\t\t\t\t// spanning the snapshot, which should be rare\n\t\t\t\tconst specAsBuggyFormat: IJSONSegmentWithMergeInfo & { removedClient?: string } = spec;\n\t\t\t\tif (specAsBuggyFormat.removedClient !== undefined) {\n\t\t\t\t\tspec.removedClientIds ??= [specAsBuggyFormat.removedClient];\n\t\t\t\t}\n\t\t\t\tassert(spec.removedClientIds !== undefined, 0xaac /* must have removedClient ids */);\n\t\t\t\tconst firstRemovedSeq = spec.removedSeq;\n\t\t\t\t// TODO:AB#32299: To correctly support perspectives from other clients which don't assume they have seen\n\t\t\t\t// all ops, we need to actually record these in the summary. For now we use fake data, and it turns\n\t\t\t\t// out ok since none of these values end up being used. (specifically, the 'firstRemovedSeq' is fake\n\t\t\t\t// for all values other than the actual first remove).\n\t\t\t\t// This issue only affects V1 summaries, as the strategy in snapshotlegacy avoids storing merge info directly.\n\t\t\t\tfor (const id of spec.removedClientIds) {\n\t\t\t\t\tremoves.push({\n\t\t\t\t\t\ttype: \"setRemove\",\n\t\t\t\t\t\tseq: firstRemovedSeq,\n\t\t\t\t\t\tclientId: this.client.getOrAddShortClientId(id),\n\t\t\t\t\t} as const);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (spec.movedSeq !== undefined) {\n\t\t\t\tassert(\n\t\t\t\t\tspec.movedClientIds !== undefined && spec.movedSeqs !== undefined,\n\t\t\t\t\t0xaa5 /* must have movedIds ids */,\n\t\t\t\t);\n\t\t\t\tassert(\n\t\t\t\t\tspec.movedClientIds.length === spec.movedSeqs.length,\n\t\t\t\t\t0xb5f /* Expected same length for client ids and seqs */,\n\t\t\t\t);\n\n\t\t\t\t// Avoid spreading into push: a large array could exceed the engine's\n\t\t\t\t// argument-count limit and throw RangeError.\n\t\t\t\tfor (let i = 0; i < spec.movedClientIds.length; i++) {\n\t\t\t\t\tremoves.push({\n\t\t\t\t\t\ttype: \"sliceRemove\",\n\t\t\t\t\t\tseq: spec.movedSeqs[i],\n\t\t\t\t\t\tclientId: this.client.getOrAddShortClientId(spec.movedClientIds[i]),\n\t\t\t\t\t} as const);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (removes.length > 0) {\n\t\t\t\tremoves.sort(opstampUtils.compare);\n\t\t\t\toverwriteInfo<IHasRemovalInfo>(seg, { removes });\n\t\t\t}\n\n\t\t\treturn seg;\n\t\t}\n\t\treturn overwriteInfo(this.client.specToSegment(spec), {\n\t\t\tinsert: {\n\t\t\t\ttype: \"insert\",\n\t\t\t\tseq: UniversalSequenceNumber,\n\t\t\t\tclientId: NonCollabClient,\n\t\t\t},\n\t\t});\n\t};\n\n\tprivate loadHeader(header: string): MergeTreeChunkV1 {\n\t\tconst chunk = SnapshotV1.processChunk(\n\t\t\tSnapshotLegacy.header,\n\t\t\theader,\n\t\t\tthis.logger,\n\t\t\tthis.mergeTree.options,\n\t\t\tthis.serializer,\n\t\t);\n\t\tconst segs = chunk.segments.map((element) => this.specToSegment(element));\n\t\tthis.extractAttribution(segs, chunk);\n\n\t\tthis.mergeTree.reloadFromSegments(segs);\n\n\t\tif (chunk.headerMetadata === undefined) {\n\t\t\tthrow new Error(\"header metadata not available\");\n\t\t}\n\t\t// If we load a detached container from snapshot, then we don't supply a default clientId\n\t\t// because we don't want to start collaboration.\n\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\t// specify a default client id, \"snapshot\" here as we\n\t\t\t// should enter collaboration/op sending mode if we load\n\t\t\t// a snapshot in any case (summary or attach message)\n\t\t\t// once we get a client id this will be called with that\n\t\t\t// clientId in the connected event\n\t\t\tthis.client.startOrUpdateCollaboration(\n\t\t\t\tthis.runtime.clientId ?? \"snapshot\",\n\n\t\t\t\t// TODO: Make 'minSeq' non-optional once the new snapshot format becomes the default?\n\t\t\t\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\t\t\t\t/* minSeq: */ chunk.headerMetadata.minSequenceNumber ??\n\t\t\t\t\tchunk.headerMetadata.sequenceNumber,\n\t\t\t\t/* currentSeq: */ chunk.headerMetadata.sequenceNumber,\n\t\t\t);\n\t\t}\n\n\t\treturn chunk;\n\t}\n\n\tprivate async loadBody(\n\t\tchunk1: MergeTreeChunkV1,\n\t\tservices: IChannelStorageService,\n\t): Promise<void> {\n\t\tconst headerMetadata = chunk1.headerMetadata!;\n\t\tassert(chunk1.length <= headerMetadata.totalLength, 0x061 /* \"Mismatch in totalLength\" */);\n\n\t\tassert(\n\t\t\tchunk1.segmentCount <= headerMetadata.totalSegmentCount,\n\t\t\t0x062 /* \"Mismatch in totalSegmentCount\" */,\n\t\t);\n\n\t\tif (chunk1.segmentCount === headerMetadata.totalSegmentCount) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet chunksWithAttribution = chunk1.attribution === undefined ? 0 : 1;\n\t\tconst segs: SegmentWithInfo<IHasInsertionInfo>[] = [];\n\t\tlet lengthSofar = chunk1.length;\n\t\tfor (\n\t\t\tlet chunkIndex = 1;\n\t\t\tchunkIndex < headerMetadata.orderedChunkMetadata.length;\n\t\t\tchunkIndex++\n\t\t) {\n\t\t\tconst chunk = await SnapshotV1.loadChunk(\n\t\t\t\tservices,\n\t\t\t\theaderMetadata.orderedChunkMetadata[chunkIndex].id,\n\t\t\t\tthis.logger,\n\t\t\t\tthis.mergeTree.options,\n\t\t\t\tthis.serializer,\n\t\t\t);\n\t\t\tlengthSofar += chunk.length;\n\t\t\t// Deserialize each chunk segment and append it to the end of the MergeTree.\n\t\t\tconst newSegs = chunk.segments.map((element) => this.specToSegment(element));\n\t\t\tthis.extractAttribution(newSegs, chunk);\n\t\t\tchunksWithAttribution += chunk.attribution === undefined ? 0 : 1;\n\t\t\t// Avoid `push(...newSegs)`: spreading a large array into a variadic call\n\t\t\t// can exceed the engine's argument-count limit and throw RangeError.\n\t\t\tfor (const seg of newSegs) {\n\t\t\t\tsegs.push(seg);\n\t\t\t}\n\t\t}\n\n\t\tassert(\n\t\t\tchunksWithAttribution === 0 ||\n\t\t\t\tchunksWithAttribution === headerMetadata.orderedChunkMetadata.length,\n\t\t\t0x4c0 /* all or no chunks should have attribution information */,\n\t\t);\n\n\t\tassert(lengthSofar === headerMetadata.totalLength, 0x063 /* \"Mismatch in totalLength\" */);\n\n\t\tassert(\n\t\t\tchunk1.segmentCount + segs.length === headerMetadata.totalSegmentCount,\n\t\t\t0x064 /* \"Mismatch in totalSegmentCount\" */,\n\t\t);\n\n\t\t// Helper to insert segments at the end of the MergeTree.\n\t\tconst mergeTree = this.mergeTree;\n\t\tconst append = (segments: ISegmentPrivate[], clientId: number, seq: number): void => {\n\t\t\tmergeTree.insertSegments(\n\t\t\t\tmergeTree.root.cachedLength ?? 0,\n\t\t\t\tsegments,\n\t\t\t\tnew PriorPerspective(UniversalSequenceNumber, clientId),\n\t\t\t\t{ seq, clientId },\n\t\t\t\tundefined,\n\t\t\t);\n\t\t};\n\n\t\t// Helpers to batch-insert segments that are below the min seq\n\t\tconst batch: SegmentWithInfo<IHasInsertionInfo>[] = [];\n\t\tconst flushBatch = (): void => {\n\t\t\tif (batch.length > 0) {\n\t\t\t\tappend(batch, NonCollabClient, UniversalSequenceNumber);\n\t\t\t}\n\t\t};\n\n\t\tfor (const seg of segs) {\n\t\t\tconst { clientId, seq } = seg.insert;\n\t\t\t// If the segment can be batch inserted, add it to the 'batch' array. Otherwise, flush\n\t\t\t// any batched segments and then insert the current segment individually.\n\t\t\tif (clientId === NonCollabClient && seq === UniversalSequenceNumber) {\n\t\t\t\tbatch.push(seg);\n\t\t\t} else {\n\t\t\t\tflushBatch();\n\t\t\t\tappend([seg], clientId, seq);\n\t\t\t}\n\t\t}\n\n\t\tflushBatch();\n\t}\n\n\tprivate extractAttribution(segments: ISegmentPrivate[], chunk: MergeTreeChunkV1): void {\n\t\tif (chunk.attribution) {\n\t\t\tconst { attributionPolicy } = this.mergeTree;\n\t\t\tif (attributionPolicy === undefined) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"Attribution policy must be provided when loading a document with attribution information.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst { isAttached, attach, serializer } = attributionPolicy;\n\t\t\tif (!isAttached) {\n\t\t\t\tattach(this.client);\n\t\t\t}\n\t\t\tserializer.populateAttributionCollections(segments, chunk.attribution);\n\t\t} else {\n\t\t\tconst { attributionPolicy } = this.mergeTree;\n\t\t\tif (attributionPolicy?.isAttached) {\n\t\t\t\tattributionPolicy?.detach();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * If loading from a snapshot, get the catchup messages.\n\t * @param rawMessages - The messages in original encoding\n\t * @returns The decoded messages with parsed+hydrated handles. Matches the format that will be passed in\n\t * SharedObject.processCore.\n\t */\n\tprivate async loadCatchupOps(\n\t\trawMessages: Promise<ArrayBufferLike>,\n\t\tserializer: IFluidSerializer,\n\t): Promise<ISequencedDocumentMessage[]> {\n\t\treturn serializer.parse(\n\t\t\tbufferToString(await rawMessages, \"utf8\"),\n\t\t) as ISequencedDocumentMessage[];\n\t}\n}\n"]}
|
package/lib/snapshotV1.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { IFluidHandle } from "@fluidframework/core-interfaces";
|
|
|
6
6
|
import type { IChannelStorageService } from "@fluidframework/datastore-definitions/internal";
|
|
7
7
|
import type { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions/internal";
|
|
8
8
|
import type { IFluidSerializer } from "@fluidframework/shared-object-base/internal";
|
|
9
|
-
import { type
|
|
9
|
+
import { type TelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
|
|
10
10
|
import type { MergeTree } from "./mergeTree.js";
|
|
11
11
|
import { type PropertySet } from "./properties.js";
|
|
12
12
|
import { type JsonSegmentSpecs, type MergeTreeChunkV1 } from "./snapshotChunks.js";
|
|
@@ -22,7 +22,7 @@ export declare class SnapshotV1 {
|
|
|
22
22
|
private readonly attributionCollections;
|
|
23
23
|
private readonly logger;
|
|
24
24
|
private readonly chunkSize;
|
|
25
|
-
constructor(mergeTree: MergeTree, logger:
|
|
25
|
+
constructor(mergeTree: MergeTree, logger: TelemetryLoggerExt, getLongClientId: (id: number) => string, filename?: string | undefined, onCompletion?: (() => void) | undefined);
|
|
26
26
|
private getSeqLengthSegs;
|
|
27
27
|
/**
|
|
28
28
|
* Emits the snapshot to an ISummarizeResult. If provided the optional IFluidSerializer will be used when
|
|
@@ -30,7 +30,7 @@ export declare class SnapshotV1 {
|
|
|
30
30
|
*/
|
|
31
31
|
emit(serializer: IFluidSerializer, bind: IFluidHandle): ISummaryTreeWithStats;
|
|
32
32
|
extractSync(): JsonSegmentSpecs[];
|
|
33
|
-
static loadChunk(storage: IChannelStorageService, path: string, logger:
|
|
34
|
-
static processChunk(path: string, chunk: string, logger:
|
|
33
|
+
static loadChunk(storage: IChannelStorageService, path: string, logger: TelemetryLoggerExt, options: PropertySet | undefined, serializer?: IFluidSerializer): Promise<MergeTreeChunkV1>;
|
|
34
|
+
static processChunk(path: string, chunk: string, logger: TelemetryLoggerExt, options: PropertySet | undefined, serializer?: IFluidSerializer): MergeTreeChunkV1;
|
|
35
35
|
}
|
|
36
36
|
//# sourceMappingURL=snapshotV1.d.ts.map
|
package/lib/snapshotV1.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshotV1.d.ts","sourceRoot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E,sEAAsE;AAC/C,oBAAS,GAAW,KAAK,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { IChannelStorageService } from \"@fluidframework/datastore-definitions/internal\";\nimport type {\n\tISummaryTreeWithStats,\n\tAttributionKey,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport type { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\ttype ITelemetryLoggerExt,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { IAttributionCollection } from \"./attributionCollection.js\";\nimport { NonCollabClient } from \"./constants.js\";\nimport type { MergeTree } from \"./mergeTree.js\";\nimport { walkAllChildSegments } from \"./mergeTreeNodeWalk.js\";\nimport type { ISegmentPrivate } from \"./mergeTreeNodes.js\";\nimport type { IJSONSegment } from \"./ops.js\";\nimport { type PropertySet, matchProperties } from \"./properties.js\";\nimport { assertInserted, isRemoved } from \"./segmentInfos.js\";\nimport {\n\ttype IJSONSegmentWithMergeInfo,\n\ttype JsonSegmentSpecs,\n\ttype MergeTreeChunkV1,\n\ttype MergeTreeHeaderMetadata,\n\tserializeAsMaxSupportedVersion,\n\ttoLatestVersion,\n\ttype VersionedMergeTreeChunk,\n} from \"./snapshotChunks.js\";\nimport { SnapshotLegacy } from \"./snapshotlegacy.js\";\nimport type { OperationStamp } from \"./stamps.js\";\nimport * as opstampUtils from \"./stamps.js\";\n\nexport class SnapshotV1 {\n\t// Split snapshot into two entries - headers (small) and body (overflow) for faster loading initial content\n\t// Please note that this number has no direct relationship to anything other than size of raw text (characters).\n\t// As we produce json for the blob (and then send over the wire compressed), this number\n\t// is really hard to correlate with any actual metric that matters (like bytes over the wire).\n\t// For test with small number of chunks it would be closer to blob size,\n\t// for very chunky text, blob size can easily be 4x-8x of that number.\n\tpublic static readonly chunkSize: number = 10000;\n\n\tprivate readonly header: MergeTreeHeaderMetadata;\n\tprivate readonly segments: JsonSegmentSpecs[];\n\tprivate readonly segmentLengths: number[];\n\tprivate readonly attributionCollections: IAttributionCollection<AttributionKey>[];\n\tprivate readonly logger: ITelemetryLoggerExt;\n\tprivate readonly chunkSize: number;\n\n\tconstructor(\n\t\tpublic mergeTree: MergeTree,\n\t\tlogger: ITelemetryLoggerExt,\n\t\tprivate readonly getLongClientId: (id: number) => string,\n\t\tpublic filename?: string,\n\t\tpublic onCompletion?: () => void,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"Snapshot\" });\n\t\tthis.chunkSize = mergeTree?.options?.mergeTreeSnapshotChunkSize ?? SnapshotV1.chunkSize;\n\n\t\tconst { currentSeq, minSeq } = mergeTree.collabWindow;\n\t\tthis.header = {\n\t\t\tminSequenceNumber: minSeq,\n\t\t\tsequenceNumber: currentSeq,\n\t\t\torderedChunkMetadata: [],\n\t\t\ttotalLength: 0,\n\t\t\ttotalSegmentCount: 0,\n\t\t};\n\n\t\tthis.segments = [];\n\t\tthis.segmentLengths = [];\n\t\tthis.attributionCollections = [];\n\t}\n\n\tprivate getSeqLengthSegs(\n\t\tallSegments: JsonSegmentSpecs[],\n\t\tallLengths: number[],\n\t\tattributionCollections: IAttributionCollection<AttributionKey>[],\n\t\tapproxSequenceLength: number,\n\t\tstartIndex = 0,\n\t): MergeTreeChunkV1 {\n\t\tconst segments: JsonSegmentSpecs[] = [];\n\t\tconst collections: {\n\t\t\tattribution: IAttributionCollection<AttributionKey>;\n\t\t\tcachedLength: number;\n\t\t}[] = [];\n\t\tlet length = 0;\n\t\tlet segmentCount = 0;\n\t\tlet hasAttribution = false;\n\t\twhile (length < approxSequenceLength && startIndex + segmentCount < allSegments.length) {\n\t\t\tconst pseg = allSegments[startIndex + segmentCount];\n\t\t\tsegments.push(pseg);\n\t\t\tlength += allLengths[startIndex + segmentCount];\n\t\t\tif (attributionCollections[startIndex + segmentCount]) {\n\t\t\t\thasAttribution = true;\n\t\t\t\tcollections.push({\n\t\t\t\t\tattribution: attributionCollections[startIndex + segmentCount],\n\t\t\t\t\tcachedLength: allLengths[startIndex + segmentCount],\n\t\t\t\t});\n\t\t\t}\n\t\t\tsegmentCount++;\n\t\t}\n\n\t\tconst attributionSerializer = this.mergeTree.attributionPolicy?.serializer;\n\t\tassert(\n\t\t\t!hasAttribution || attributionSerializer !== undefined,\n\t\t\t0x55a /* attribution serializer must be provided when there are segments with attribution. */,\n\t\t);\n\n\t\treturn {\n\t\t\tversion: \"1\",\n\t\t\tsegmentCount,\n\t\t\tlength,\n\t\t\tsegments,\n\t\t\tstartIndex,\n\t\t\theaderMetadata: undefined,\n\t\t\tattribution: hasAttribution\n\t\t\t\t? attributionSerializer?.serializeAttributionCollections(collections)\n\t\t\t\t: undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Emits the snapshot to an ISummarizeResult. If provided the optional IFluidSerializer will be used when\n\t * serializing the summary data rather than JSON.stringify.\n\t */\n\temit(serializer: IFluidSerializer, bind: IFluidHandle): ISummaryTreeWithStats {\n\t\tconst chunks: MergeTreeChunkV1[] = [];\n\t\tthis.header.totalSegmentCount = 0;\n\t\tthis.header.totalLength = 0;\n\t\tdo {\n\t\t\tconst chunk = this.getSeqLengthSegs(\n\t\t\t\tthis.segments,\n\t\t\t\tthis.segmentLengths,\n\t\t\t\tthis.attributionCollections,\n\t\t\t\tthis.chunkSize,\n\t\t\t\tthis.header.totalSegmentCount,\n\t\t\t);\n\t\t\tchunks.push(chunk);\n\t\t\tthis.header.totalSegmentCount += chunk.segmentCount;\n\t\t\tthis.header.totalLength += chunk.length;\n\t\t} while (this.header.totalSegmentCount < this.segments.length);\n\n\t\t// The do while loop should have added at least one chunk\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst headerChunk = chunks.shift()!;\n\t\theaderChunk.headerMetadata = this.header;\n\t\theaderChunk.headerMetadata.orderedChunkMetadata = [{ id: SnapshotLegacy.header }];\n\t\tconst blobs: [key: string, content: string][] = [];\n\t\tfor (const [index, chunk] of chunks.entries()) {\n\t\t\tconst id = `${SnapshotLegacy.body}_${index}`;\n\t\t\tthis.header.orderedChunkMetadata.push({ id });\n\t\t\tblobs.push([\n\t\t\t\tid,\n\t\t\t\tserializeAsMaxSupportedVersion(\n\t\t\t\t\tid,\n\t\t\t\t\tchunk,\n\t\t\t\t\tthis.logger,\n\t\t\t\t\tthis.mergeTree.options,\n\t\t\t\t\tserializer,\n\t\t\t\t\tbind,\n\t\t\t\t),\n\t\t\t]);\n\t\t}\n\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addBlob(\n\t\t\tSnapshotLegacy.header,\n\t\t\tserializeAsMaxSupportedVersion(\n\t\t\t\tSnapshotLegacy.header,\n\t\t\t\theaderChunk,\n\t\t\t\tthis.logger,\n\t\t\t\tthis.mergeTree.options,\n\t\t\t\tserializer,\n\t\t\t\tbind,\n\t\t\t),\n\t\t);\n\t\tfor (const value of blobs) {\n\t\t\tbuilder.addBlob(value[0], value[1]);\n\t\t}\n\n\t\treturn builder.getSummaryTree();\n\t}\n\n\textractSync(): JsonSegmentSpecs[] {\n\t\tconst mergeTree = this.mergeTree;\n\t\tconst minSeq = this.header.minSequenceNumber;\n\t\tconst minSeqStamp: OperationStamp = { seq: minSeq, clientId: NonCollabClient };\n\n\t\tlet originalSegments = 0;\n\t\tlet segmentsAfterCombine = 0;\n\n\t\t// Helper to add the given `MergeTreeChunkV0SegmentSpec` to the snapshot.\n\t\tconst pushSegRaw = (\n\t\t\tjson: JsonSegmentSpecs,\n\t\t\tlength: number,\n\t\t\tattribution: IAttributionCollection<AttributionKey> | undefined,\n\t\t): void => {\n\t\t\tsegmentsAfterCombine += 1;\n\t\t\tthis.segments.push(json);\n\t\t\tthis.segmentLengths.push(length);\n\t\t\tif (attribution) {\n\t\t\t\tthis.attributionCollections.push(attribution);\n\t\t\t}\n\t\t};\n\n\t\t// Helper to serialize the given `segment` and add it to the snapshot (if a segment is provided).\n\t\tconst pushSeg = (segment?: ISegmentPrivate): void => {\n\t\t\tif (segment) {\n\t\t\t\tif (segment.properties !== undefined && Object.keys(segment.properties).length === 0) {\n\t\t\t\t\tsegment.properties = undefined;\n\t\t\t\t}\n\t\t\t\tpushSegRaw(\n\t\t\t\t\tsegment.toJSONObject() as JsonSegmentSpecs,\n\t\t\t\t\tsegment.cachedLength,\n\t\t\t\t\tsegment.attribution,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tlet prev: ISegmentPrivate | undefined;\n\t\tconst extractSegment = (segment: ISegmentPrivate): boolean => {\n\t\t\tassertInserted(segment);\n\t\t\t// Elide segments that do not need to be included in the snapshot. A segment may be elided if\n\t\t\t// either condition is true:\n\t\t\t// a) The segment has not yet been ACKed. We do not need to snapshot unACKed segments because\n\t\t\t// there is a pending insert op that will deliver the segment on reconnection.\n\t\t\t// b) The segment was removed at or below the MSN. Pending ops can no longer reference this\n\t\t\t// segment, and therefore we can discard it.\n\t\t\tif (\n\t\t\t\topstampUtils.isLocal(segment.insert) ||\n\t\t\t\t(isRemoved(segment) && opstampUtils.lte(segment.removes[0], minSeqStamp))\n\t\t\t) {\n\t\t\t\tif (opstampUtils.isAcked(segment.insert)) {\n\t\t\t\t\toriginalSegments += 1;\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\toriginalSegments += 1;\n\n\t\t\t// Next determine if the snapshot needs to preserve information required for merging the segment\n\t\t\t// (seq, client, etc.) This information is only needed if the segment is above the MSN (and doesn't\n\t\t\t// have a pending remove.)\n\t\t\tif (\n\t\t\t\topstampUtils.lte(segment.insert, minSeqStamp) && // Segment is below the MSN, and...\n\t\t\t\t(!isRemoved(segment) || opstampUtils.isLocal(segment.removes[0]))\n\t\t\t) {\n\t\t\t\t// This segment is below the MSN, which means that future ops will not reference it. Attempt to\n\t\t\t\t// coalesce the new segment with the previous (if any).\n\t\t\t\tif (!prev) {\n\t\t\t\t\t// We do not have a previous candidate for coalescing. Make the current segment the new candidate.\n\t\t\t\t\tprev = segment;\n\t\t\t\t} else if (\n\t\t\t\t\tprev.canAppend(segment) &&\n\t\t\t\t\tmatchProperties(prev.properties, segment.properties)\n\t\t\t\t) {\n\t\t\t\t\t// We have a compatible pair. Replace `prev` with the coalesced segment. Clone to avoid\n\t\t\t\t\t// modifying the segment instances currently in the MergeTree.\n\t\t\t\t\tprev = prev.clone();\n\t\t\t\t\tprev.append(segment.clone());\n\t\t\t\t} else {\n\t\t\t\t\t// The segment pair could not be coalesced. Record the `prev` segment in the snapshot\n\t\t\t\t\t// and make the current segment the new candidate for coalescing.\n\t\t\t\t\tpushSeg(prev);\n\t\t\t\t\tprev = segment;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// This segment needs to preserve its metadata as it may be referenced by future ops. It's ineligible\n\t\t\t\t// for coalescing, so emit the 'prev' segment now (if any).\n\t\t\t\tpushSeg(prev);\n\t\t\t\tprev = undefined;\n\n\t\t\t\tif (segment.properties !== undefined && Object.keys(segment.properties).length === 0) {\n\t\t\t\t\tsegment.properties = undefined;\n\t\t\t\t}\n\t\t\t\tconst raw: IJSONSegmentWithMergeInfo & { removedClient?: string } = {\n\t\t\t\t\tjson: segment.toJSONObject() as IJSONSegment,\n\t\t\t\t};\n\t\t\t\t// If the segment insertion is above the MSN, record the insertion merge info.\n\t\t\t\tif (opstampUtils.greaterThan(segment.insert, minSeqStamp)) {\n\t\t\t\t\traw.seq = segment.insert.seq;\n\t\t\t\t\traw.client = this.getLongClientId(segment.insert.clientId);\n\t\t\t\t}\n\n\t\t\t\t// We have already dispensed with removed segments below the MSN and removed segments with unassigned\n\t\t\t\t// sequence numbers. Any remaining removal info should be preserved.\n\t\t\t\tif (isRemoved(segment) && segment.removes.some((r) => r.type === \"setRemove\")) {\n\t\t\t\t\tconst removes = segment.removes.filter((r) => r.type === \"setRemove\");\n\t\t\t\t\tconst firstRemove = removes[0];\n\t\t\t\t\tassert(\n\t\t\t\t\t\topstampUtils.isAcked(firstRemove) &&\n\t\t\t\t\t\t\topstampUtils.greaterThan(firstRemove, minSeqStamp),\n\t\t\t\t\t\t0x065 /* \"On removal info preservation, segment has invalid removed sequence number!\" */,\n\t\t\t\t\t);\n\t\t\t\t\t// TODO:AB#32299 By not preserving sequence numbers other than the first move,\n\t\t\t\t\t// We drop data here which will be necessary to allow perspectives of remote clients that\n\t\t\t\t\t// don't include all of their ops. This should be remedied at some point.\n\t\t\t\t\traw.removedSeq = firstRemove.seq;\n\n\t\t\t\t\t// back compat for when we split overlap and removed client\n\t\t\t\t\t// This can be removed when we can safely assume no clients running Fluid packages <= 0.58 will ever\n\t\t\t\t\t// load a document produced by a version beyond the removal. It is vestigial in the meantime.\n\t\t\t\t\traw.removedClient = this.getLongClientId(firstRemove.clientId);\n\n\t\t\t\t\traw.removedClientIds = removes.map(({ clientId }) => this.getLongClientId(clientId));\n\t\t\t\t}\n\n\t\t\t\tif (isRemoved(segment) && segment.removes.some((r) => r.type === \"sliceRemove\")) {\n\t\t\t\t\t// In this format, we used the term \"move\" to refer to a sliceRemove/obliterate.\n\t\t\t\t\tconst moves = segment.removes.filter((r) => r.type === \"sliceRemove\");\n\t\t\t\t\tconst firstMove = moves[0];\n\t\t\t\t\tassert(\n\t\t\t\t\t\topstampUtils.isAcked(firstMove) &&\n\t\t\t\t\t\t\topstampUtils.greaterThan(firstMove, minSeqStamp),\n\t\t\t\t\t\t0x873 /* On move info preservation, segment has invalid moved sequence number! */,\n\t\t\t\t\t);\n\t\t\t\t\traw.movedSeq = firstMove.seq;\n\t\t\t\t\traw.movedSeqs = moves.map(({ seq }) => seq);\n\t\t\t\t\traw.movedClientIds = moves.map(({ clientId }) => this.getLongClientId(clientId));\n\t\t\t\t}\n\n\t\t\t\t// Sanity check that we are preserving either the seq > minSeq or a (re)moved segment's info.\n\t\t\t\tassert(\n\t\t\t\t\t(raw.seq !== undefined && raw.client !== undefined) ||\n\t\t\t\t\t\t(raw.removedSeq !== undefined && raw.removedClientIds !== undefined) ||\n\t\t\t\t\t\t(raw.movedSeq !== undefined &&\n\t\t\t\t\t\t\traw.movedClientIds !== undefined &&\n\t\t\t\t\t\t\traw.movedClientIds.length > 0 &&\n\t\t\t\t\t\t\traw.movedSeqs !== undefined &&\n\t\t\t\t\t\t\traw.movedSeqs.length > 0),\n\t\t\t\t\t0x066 /* \"Corrupted preservation of segment metadata!\" */,\n\t\t\t\t);\n\n\t\t\t\t// Record the segment with its required metadata.\n\t\t\t\tpushSegRaw(raw, segment.cachedLength, segment.attribution);\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\twalkAllChildSegments(mergeTree.root, extractSegment);\n\n\t\t// If the last segment in the walk was coalescable, push it now.\n\t\tpushSeg(prev);\n\n\t\t// To reduce potential spam from this telemetry, we sample only a small\n\t\t// percentage of summaries\n\t\tif (Math.abs(originalSegments - segmentsAfterCombine) > 500 && Math.random() < 0.005) {\n\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"MergeTreeV1SummarizeSegmentCount\",\n\t\t\t\toriginalSegments,\n\t\t\t\tsegmentsAfterCombine,\n\t\t\t\tsegmentsLen: this.segments.length,\n\t\t\t});\n\t\t}\n\n\t\treturn this.segments;\n\t}\n\n\tpublic static async loadChunk(\n\t\tstorage: IChannelStorageService,\n\t\tpath: string,\n\t\tlogger: ITelemetryLoggerExt,\n\t\toptions: PropertySet | undefined,\n\t\tserializer?: IFluidSerializer,\n\t): Promise<MergeTreeChunkV1> {\n\t\tconst blob = await storage.readBlob(path);\n\t\tconst chunkAsString = bufferToString(blob, \"utf8\");\n\t\treturn SnapshotV1.processChunk(path, chunkAsString, logger, options, serializer);\n\t}\n\n\tpublic static processChunk(\n\t\tpath: string,\n\t\tchunk: string,\n\t\tlogger: ITelemetryLoggerExt,\n\t\toptions: PropertySet | undefined,\n\t\tserializer?: IFluidSerializer,\n\t): MergeTreeChunkV1 {\n\t\tconst chunkObj: VersionedMergeTreeChunk = serializer\n\t\t\t? (serializer.parse(chunk) as VersionedMergeTreeChunk)\n\t\t\t: (JSON.parse(chunk) as VersionedMergeTreeChunk);\n\t\treturn toLatestVersion(path, chunkObj, logger, options);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"snapshotV1.js","sourceRoot":"","sources":["../src/snapshotV1.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAM7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAE5E,OAAO,EAEN,iBAAiB,GACjB,MAAM,0CAA0C,CAAC;AAGlD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,OAAO,EAAoB,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAKN,8BAA8B,EAC9B,eAAe,GAEf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,YAAY,MAAM,aAAa,CAAC;AAE5C,MAAM,OAAO,UAAU;IAgBtB,YACQ,SAAoB,EAC3B,MAA0B,EACT,eAAuC,EACjD,QAAiB,EACjB,YAAyB;QAJzB,cAAS,GAAT,SAAS,CAAW;QAEV,oBAAe,GAAf,eAAe,CAAwB;QACjD,aAAQ,GAAR,QAAQ,CAAS;QACjB,iBAAY,GAAZ,YAAY,CAAa;QAEhC,IAAI,CAAC,MAAM,GAAG,iBAAiB,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;QACnE,IAAI,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,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnD,OAAO,UAAU,CAAC,YAAY,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;IAClF,CAAC;IAEM,MAAM,CAAC,YAAY,CACzB,IAAY,EACZ,KAAa,EACb,MAA0B,EAC1B,OAAgC,EAChC,UAA6B;QAE7B,MAAM,QAAQ,GAA4B,UAAU;YACnD,CAAC,CAAE,UAAU,CAAC,KAAK,CAAC,KAAK,CAA6B;YACtD,CAAC,CAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAA6B,CAAC;QAClD,OAAO,eAAe,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;;AA3VD,2GAA2G;AAC3G,gHAAgH;AAChH,wFAAwF;AACxF,8FAA8F;AAC9F,wEAAwE;AACxE,sEAAsE;AAC/C,oBAAS,GAAW,KAAK,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { IChannelStorageService } from \"@fluidframework/datastore-definitions/internal\";\nimport type {\n\tISummaryTreeWithStats,\n\tAttributionKey,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport type { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\ttype TelemetryLoggerExt,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { IAttributionCollection } from \"./attributionCollection.js\";\nimport { NonCollabClient } from \"./constants.js\";\nimport type { MergeTree } from \"./mergeTree.js\";\nimport { walkAllChildSegments } from \"./mergeTreeNodeWalk.js\";\nimport type { ISegmentPrivate } from \"./mergeTreeNodes.js\";\nimport type { IJSONSegment } from \"./ops.js\";\nimport { type PropertySet, matchProperties } from \"./properties.js\";\nimport { assertInserted, isRemoved } from \"./segmentInfos.js\";\nimport {\n\ttype IJSONSegmentWithMergeInfo,\n\ttype JsonSegmentSpecs,\n\ttype MergeTreeChunkV1,\n\ttype MergeTreeHeaderMetadata,\n\tserializeAsMaxSupportedVersion,\n\ttoLatestVersion,\n\ttype VersionedMergeTreeChunk,\n} from \"./snapshotChunks.js\";\nimport { SnapshotLegacy } from \"./snapshotlegacy.js\";\nimport type { OperationStamp } from \"./stamps.js\";\nimport * as opstampUtils from \"./stamps.js\";\n\nexport class SnapshotV1 {\n\t// Split snapshot into two entries - headers (small) and body (overflow) for faster loading initial content\n\t// Please note that this number has no direct relationship to anything other than size of raw text (characters).\n\t// As we produce json for the blob (and then send over the wire compressed), this number\n\t// is really hard to correlate with any actual metric that matters (like bytes over the wire).\n\t// For test with small number of chunks it would be closer to blob size,\n\t// for very chunky text, blob size can easily be 4x-8x of that number.\n\tpublic static readonly chunkSize: number = 10000;\n\n\tprivate readonly header: MergeTreeHeaderMetadata;\n\tprivate readonly segments: JsonSegmentSpecs[];\n\tprivate readonly segmentLengths: number[];\n\tprivate readonly attributionCollections: IAttributionCollection<AttributionKey>[];\n\tprivate readonly logger: TelemetryLoggerExt;\n\tprivate readonly chunkSize: number;\n\n\tconstructor(\n\t\tpublic mergeTree: MergeTree,\n\t\tlogger: TelemetryLoggerExt,\n\t\tprivate readonly getLongClientId: (id: number) => string,\n\t\tpublic filename?: string,\n\t\tpublic onCompletion?: () => void,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"Snapshot\" });\n\t\tthis.chunkSize = mergeTree?.options?.mergeTreeSnapshotChunkSize ?? SnapshotV1.chunkSize;\n\n\t\tconst { currentSeq, minSeq } = mergeTree.collabWindow;\n\t\tthis.header = {\n\t\t\tminSequenceNumber: minSeq,\n\t\t\tsequenceNumber: currentSeq,\n\t\t\torderedChunkMetadata: [],\n\t\t\ttotalLength: 0,\n\t\t\ttotalSegmentCount: 0,\n\t\t};\n\n\t\tthis.segments = [];\n\t\tthis.segmentLengths = [];\n\t\tthis.attributionCollections = [];\n\t}\n\n\tprivate getSeqLengthSegs(\n\t\tallSegments: JsonSegmentSpecs[],\n\t\tallLengths: number[],\n\t\tattributionCollections: IAttributionCollection<AttributionKey>[],\n\t\tapproxSequenceLength: number,\n\t\tstartIndex = 0,\n\t): MergeTreeChunkV1 {\n\t\tconst segments: JsonSegmentSpecs[] = [];\n\t\tconst collections: {\n\t\t\tattribution: IAttributionCollection<AttributionKey>;\n\t\t\tcachedLength: number;\n\t\t}[] = [];\n\t\tlet length = 0;\n\t\tlet segmentCount = 0;\n\t\tlet hasAttribution = false;\n\t\twhile (length < approxSequenceLength && startIndex + segmentCount < allSegments.length) {\n\t\t\tconst pseg = allSegments[startIndex + segmentCount];\n\t\t\tsegments.push(pseg);\n\t\t\tlength += allLengths[startIndex + segmentCount];\n\t\t\tif (attributionCollections[startIndex + segmentCount]) {\n\t\t\t\thasAttribution = true;\n\t\t\t\tcollections.push({\n\t\t\t\t\tattribution: attributionCollections[startIndex + segmentCount],\n\t\t\t\t\tcachedLength: allLengths[startIndex + segmentCount],\n\t\t\t\t});\n\t\t\t}\n\t\t\tsegmentCount++;\n\t\t}\n\n\t\tconst attributionSerializer = this.mergeTree.attributionPolicy?.serializer;\n\t\tassert(\n\t\t\t!hasAttribution || attributionSerializer !== undefined,\n\t\t\t0x55a /* attribution serializer must be provided when there are segments with attribution. */,\n\t\t);\n\n\t\treturn {\n\t\t\tversion: \"1\",\n\t\t\tsegmentCount,\n\t\t\tlength,\n\t\t\tsegments,\n\t\t\tstartIndex,\n\t\t\theaderMetadata: undefined,\n\t\t\tattribution: hasAttribution\n\t\t\t\t? attributionSerializer?.serializeAttributionCollections(collections)\n\t\t\t\t: undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Emits the snapshot to an ISummarizeResult. If provided the optional IFluidSerializer will be used when\n\t * serializing the summary data rather than JSON.stringify.\n\t */\n\temit(serializer: IFluidSerializer, bind: IFluidHandle): ISummaryTreeWithStats {\n\t\tconst chunks: MergeTreeChunkV1[] = [];\n\t\tthis.header.totalSegmentCount = 0;\n\t\tthis.header.totalLength = 0;\n\t\tdo {\n\t\t\tconst chunk = this.getSeqLengthSegs(\n\t\t\t\tthis.segments,\n\t\t\t\tthis.segmentLengths,\n\t\t\t\tthis.attributionCollections,\n\t\t\t\tthis.chunkSize,\n\t\t\t\tthis.header.totalSegmentCount,\n\t\t\t);\n\t\t\tchunks.push(chunk);\n\t\t\tthis.header.totalSegmentCount += chunk.segmentCount;\n\t\t\tthis.header.totalLength += chunk.length;\n\t\t} while (this.header.totalSegmentCount < this.segments.length);\n\n\t\t// The do while loop should have added at least one chunk\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst headerChunk = chunks.shift()!;\n\t\theaderChunk.headerMetadata = this.header;\n\t\theaderChunk.headerMetadata.orderedChunkMetadata = [{ id: SnapshotLegacy.header }];\n\t\tconst blobs: [key: string, content: string][] = [];\n\t\tfor (const [index, chunk] of chunks.entries()) {\n\t\t\tconst id = `${SnapshotLegacy.body}_${index}`;\n\t\t\tthis.header.orderedChunkMetadata.push({ id });\n\t\t\tblobs.push([\n\t\t\t\tid,\n\t\t\t\tserializeAsMaxSupportedVersion(\n\t\t\t\t\tid,\n\t\t\t\t\tchunk,\n\t\t\t\t\tthis.logger,\n\t\t\t\t\tthis.mergeTree.options,\n\t\t\t\t\tserializer,\n\t\t\t\t\tbind,\n\t\t\t\t),\n\t\t\t]);\n\t\t}\n\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addBlob(\n\t\t\tSnapshotLegacy.header,\n\t\t\tserializeAsMaxSupportedVersion(\n\t\t\t\tSnapshotLegacy.header,\n\t\t\t\theaderChunk,\n\t\t\t\tthis.logger,\n\t\t\t\tthis.mergeTree.options,\n\t\t\t\tserializer,\n\t\t\t\tbind,\n\t\t\t),\n\t\t);\n\t\tfor (const value of blobs) {\n\t\t\tbuilder.addBlob(value[0], value[1]);\n\t\t}\n\n\t\treturn builder.getSummaryTree();\n\t}\n\n\textractSync(): JsonSegmentSpecs[] {\n\t\tconst mergeTree = this.mergeTree;\n\t\tconst minSeq = this.header.minSequenceNumber;\n\t\tconst minSeqStamp: OperationStamp = { seq: minSeq, clientId: NonCollabClient };\n\n\t\tlet originalSegments = 0;\n\t\tlet segmentsAfterCombine = 0;\n\n\t\t// Helper to add the given `MergeTreeChunkV0SegmentSpec` to the snapshot.\n\t\tconst pushSegRaw = (\n\t\t\tjson: JsonSegmentSpecs,\n\t\t\tlength: number,\n\t\t\tattribution: IAttributionCollection<AttributionKey> | undefined,\n\t\t): void => {\n\t\t\tsegmentsAfterCombine += 1;\n\t\t\tthis.segments.push(json);\n\t\t\tthis.segmentLengths.push(length);\n\t\t\tif (attribution) {\n\t\t\t\tthis.attributionCollections.push(attribution);\n\t\t\t}\n\t\t};\n\n\t\t// Helper to serialize the given `segment` and add it to the snapshot (if a segment is provided).\n\t\tconst pushSeg = (segment?: ISegmentPrivate): void => {\n\t\t\tif (segment) {\n\t\t\t\tif (segment.properties !== undefined && Object.keys(segment.properties).length === 0) {\n\t\t\t\t\tsegment.properties = undefined;\n\t\t\t\t}\n\t\t\t\tpushSegRaw(\n\t\t\t\t\tsegment.toJSONObject() as JsonSegmentSpecs,\n\t\t\t\t\tsegment.cachedLength,\n\t\t\t\t\tsegment.attribution,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tlet prev: ISegmentPrivate | undefined;\n\t\tconst extractSegment = (segment: ISegmentPrivate): boolean => {\n\t\t\tassertInserted(segment);\n\t\t\t// Elide segments that do not need to be included in the snapshot. A segment may be elided if\n\t\t\t// either condition is true:\n\t\t\t// a) The segment has not yet been ACKed. We do not need to snapshot unACKed segments because\n\t\t\t// there is a pending insert op that will deliver the segment on reconnection.\n\t\t\t// b) The segment was removed at or below the MSN. Pending ops can no longer reference this\n\t\t\t// segment, and therefore we can discard it.\n\t\t\tif (\n\t\t\t\topstampUtils.isLocal(segment.insert) ||\n\t\t\t\t(isRemoved(segment) && opstampUtils.lte(segment.removes[0], minSeqStamp))\n\t\t\t) {\n\t\t\t\tif (opstampUtils.isAcked(segment.insert)) {\n\t\t\t\t\toriginalSegments += 1;\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\toriginalSegments += 1;\n\n\t\t\t// Next determine if the snapshot needs to preserve information required for merging the segment\n\t\t\t// (seq, client, etc.) This information is only needed if the segment is above the MSN (and doesn't\n\t\t\t// have a pending remove.)\n\t\t\tif (\n\t\t\t\topstampUtils.lte(segment.insert, minSeqStamp) && // Segment is below the MSN, and...\n\t\t\t\t(!isRemoved(segment) || opstampUtils.isLocal(segment.removes[0]))\n\t\t\t) {\n\t\t\t\t// This segment is below the MSN, which means that future ops will not reference it. Attempt to\n\t\t\t\t// coalesce the new segment with the previous (if any).\n\t\t\t\tif (!prev) {\n\t\t\t\t\t// We do not have a previous candidate for coalescing. Make the current segment the new candidate.\n\t\t\t\t\tprev = segment;\n\t\t\t\t} else if (\n\t\t\t\t\tprev.canAppend(segment) &&\n\t\t\t\t\tmatchProperties(prev.properties, segment.properties)\n\t\t\t\t) {\n\t\t\t\t\t// We have a compatible pair. Replace `prev` with the coalesced segment. Clone to avoid\n\t\t\t\t\t// modifying the segment instances currently in the MergeTree.\n\t\t\t\t\tprev = prev.clone();\n\t\t\t\t\tprev.append(segment.clone());\n\t\t\t\t} else {\n\t\t\t\t\t// The segment pair could not be coalesced. Record the `prev` segment in the snapshot\n\t\t\t\t\t// and make the current segment the new candidate for coalescing.\n\t\t\t\t\tpushSeg(prev);\n\t\t\t\t\tprev = segment;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// This segment needs to preserve its metadata as it may be referenced by future ops. It's ineligible\n\t\t\t\t// for coalescing, so emit the 'prev' segment now (if any).\n\t\t\t\tpushSeg(prev);\n\t\t\t\tprev = undefined;\n\n\t\t\t\tif (segment.properties !== undefined && Object.keys(segment.properties).length === 0) {\n\t\t\t\t\tsegment.properties = undefined;\n\t\t\t\t}\n\t\t\t\tconst raw: IJSONSegmentWithMergeInfo & { removedClient?: string } = {\n\t\t\t\t\tjson: segment.toJSONObject() as IJSONSegment,\n\t\t\t\t};\n\t\t\t\t// If the segment insertion is above the MSN, record the insertion merge info.\n\t\t\t\tif (opstampUtils.greaterThan(segment.insert, minSeqStamp)) {\n\t\t\t\t\traw.seq = segment.insert.seq;\n\t\t\t\t\traw.client = this.getLongClientId(segment.insert.clientId);\n\t\t\t\t}\n\n\t\t\t\t// We have already dispensed with removed segments below the MSN and removed segments with unassigned\n\t\t\t\t// sequence numbers. Any remaining removal info should be preserved.\n\t\t\t\tif (isRemoved(segment) && segment.removes.some((r) => r.type === \"setRemove\")) {\n\t\t\t\t\tconst removes = segment.removes.filter((r) => r.type === \"setRemove\");\n\t\t\t\t\tconst firstRemove = removes[0];\n\t\t\t\t\tassert(\n\t\t\t\t\t\topstampUtils.isAcked(firstRemove) &&\n\t\t\t\t\t\t\topstampUtils.greaterThan(firstRemove, minSeqStamp),\n\t\t\t\t\t\t0x065 /* \"On removal info preservation, segment has invalid removed sequence number!\" */,\n\t\t\t\t\t);\n\t\t\t\t\t// TODO:AB#32299 By not preserving sequence numbers other than the first move,\n\t\t\t\t\t// We drop data here which will be necessary to allow perspectives of remote clients that\n\t\t\t\t\t// don't include all of their ops. This should be remedied at some point.\n\t\t\t\t\traw.removedSeq = firstRemove.seq;\n\n\t\t\t\t\t// back compat for when we split overlap and removed client\n\t\t\t\t\t// This can be removed when we can safely assume no clients running Fluid packages <= 0.58 will ever\n\t\t\t\t\t// load a document produced by a version beyond the removal. It is vestigial in the meantime.\n\t\t\t\t\traw.removedClient = this.getLongClientId(firstRemove.clientId);\n\n\t\t\t\t\traw.removedClientIds = removes.map(({ clientId }) => this.getLongClientId(clientId));\n\t\t\t\t}\n\n\t\t\t\tif (isRemoved(segment) && segment.removes.some((r) => r.type === \"sliceRemove\")) {\n\t\t\t\t\t// In this format, we used the term \"move\" to refer to a sliceRemove/obliterate.\n\t\t\t\t\tconst moves = segment.removes.filter((r) => r.type === \"sliceRemove\");\n\t\t\t\t\tconst firstMove = moves[0];\n\t\t\t\t\tassert(\n\t\t\t\t\t\topstampUtils.isAcked(firstMove) &&\n\t\t\t\t\t\t\topstampUtils.greaterThan(firstMove, minSeqStamp),\n\t\t\t\t\t\t0x873 /* On move info preservation, segment has invalid moved sequence number! */,\n\t\t\t\t\t);\n\t\t\t\t\traw.movedSeq = firstMove.seq;\n\t\t\t\t\traw.movedSeqs = moves.map(({ seq }) => seq);\n\t\t\t\t\traw.movedClientIds = moves.map(({ clientId }) => this.getLongClientId(clientId));\n\t\t\t\t}\n\n\t\t\t\t// Sanity check that we are preserving either the seq > minSeq or a (re)moved segment's info.\n\t\t\t\tassert(\n\t\t\t\t\t(raw.seq !== undefined && raw.client !== undefined) ||\n\t\t\t\t\t\t(raw.removedSeq !== undefined && raw.removedClientIds !== undefined) ||\n\t\t\t\t\t\t(raw.movedSeq !== undefined &&\n\t\t\t\t\t\t\traw.movedClientIds !== undefined &&\n\t\t\t\t\t\t\traw.movedClientIds.length > 0 &&\n\t\t\t\t\t\t\traw.movedSeqs !== undefined &&\n\t\t\t\t\t\t\traw.movedSeqs.length > 0),\n\t\t\t\t\t0x066 /* \"Corrupted preservation of segment metadata!\" */,\n\t\t\t\t);\n\n\t\t\t\t// Record the segment with its required metadata.\n\t\t\t\tpushSegRaw(raw, segment.cachedLength, segment.attribution);\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\twalkAllChildSegments(mergeTree.root, extractSegment);\n\n\t\t// If the last segment in the walk was coalescable, push it now.\n\t\tpushSeg(prev);\n\n\t\t// To reduce potential spam from this telemetry, we sample only a small\n\t\t// percentage of summaries\n\t\tif (Math.abs(originalSegments - segmentsAfterCombine) > 500 && Math.random() < 0.005) {\n\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"MergeTreeV1SummarizeSegmentCount\",\n\t\t\t\toriginalSegments,\n\t\t\t\tsegmentsAfterCombine,\n\t\t\t\tsegmentsLen: this.segments.length,\n\t\t\t});\n\t\t}\n\n\t\treturn this.segments;\n\t}\n\n\tpublic static async loadChunk(\n\t\tstorage: IChannelStorageService,\n\t\tpath: string,\n\t\tlogger: TelemetryLoggerExt,\n\t\toptions: PropertySet | undefined,\n\t\tserializer?: IFluidSerializer,\n\t): Promise<MergeTreeChunkV1> {\n\t\tconst blob = await storage.readBlob(path);\n\t\tconst chunkAsString = bufferToString(blob, \"utf8\");\n\t\treturn SnapshotV1.processChunk(path, chunkAsString, logger, options, serializer);\n\t}\n\n\tpublic static processChunk(\n\t\tpath: string,\n\t\tchunk: string,\n\t\tlogger: TelemetryLoggerExt,\n\t\toptions: PropertySet | undefined,\n\t\tserializer?: IFluidSerializer,\n\t): MergeTreeChunkV1 {\n\t\tconst chunkObj: VersionedMergeTreeChunk = serializer\n\t\t\t? (serializer.parse(chunk) as VersionedMergeTreeChunk)\n\t\t\t: (JSON.parse(chunk) as VersionedMergeTreeChunk);\n\t\treturn toLatestVersion(path, chunkObj, logger, options);\n\t}\n}\n"]}
|
package/lib/snapshotlegacy.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { IFluidHandle } from "@fluidframework/core-interfaces";
|
|
|
6
6
|
import type { ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
|
|
7
7
|
import type { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions/internal";
|
|
8
8
|
import type { IFluidSerializer } from "@fluidframework/shared-object-base/internal";
|
|
9
|
-
import { type
|
|
9
|
+
import { type TelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
|
|
10
10
|
import type { MergeTree } from "./mergeTree.js";
|
|
11
11
|
import { type ISegmentPrivate } from "./mergeTreeNodes.js";
|
|
12
12
|
/**
|
|
@@ -25,7 +25,7 @@ export declare class SnapshotLegacy {
|
|
|
25
25
|
private segments;
|
|
26
26
|
private readonly logger;
|
|
27
27
|
private readonly chunkSize;
|
|
28
|
-
constructor(mergeTree: MergeTree, logger:
|
|
28
|
+
constructor(mergeTree: MergeTree, logger: TelemetryLoggerExt, filename?: string | undefined, onCompletion?: (() => void) | undefined);
|
|
29
29
|
private getSeqLengthSegs;
|
|
30
30
|
/**
|
|
31
31
|
* Emits the snapshot to an ISummarizeResult. If provided the optional IFluidSerializer will be used when
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshotlegacy.d.ts","sourceRoot":"","sources":["../src/snapshotlegacy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAEpE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAE1F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AACpF,OAAO,EACN,KAAK,
|
|
1
|
+
{"version":3,"file":"snapshotlegacy.d.ts","sourceRoot":"","sources":["../src/snapshotlegacy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAEpE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAE1F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AACpF,OAAO,EACN,KAAK,kBAAkB,EAEvB,MAAM,0CAA0C,CAAC;AAGlD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAoB1E;;GAEG;AACH,qBAAa,cAAc;IAoBlB,SAAS,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,CAAC;IACtB,CAAC;;AAzNsB,qBAAM,GAAG,QAAQ,CAAC;AAClB,mBAAI,GAAG,MAAM,CAAC;AACb,yBAAU,GAAG,YAAY,CAAC;AAElD,2GAA2G;AAC3G,gHAAgH;AAChH,wFAAwF;AACxF,8FAA8F;AAC9F,wEAAwE;AACxE,sEAAsE;AAC/C,+BAAgB,GAAW,KAAK,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport type { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport type { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\ttype ITelemetryLoggerExt,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { NonCollabClient } from \"./constants.js\";\nimport type { MergeTree } from \"./mergeTree.js\";\nimport { isSegmentLeaf, type ISegmentPrivate } from \"./mergeTreeNodes.js\";\nimport { PriorPerspective } from \"./perspective.js\";\nimport { matchProperties } from \"./properties.js\";\nimport {\n\ttype JsonSegmentSpecs,\n\ttype MergeTreeChunkLegacy,\n\tserializeAsMinSupportedVersion,\n} from \"./snapshotChunks.js\";\n\ninterface SnapshotHeader {\n\tchunkCount?: number;\n\tsegmentsTotalLength: number;\n\tindexOffset?: number;\n\tsegmentsOffset?: number;\n\tseq: number;\n\t// TODO: Make 'minSeq' non-optional once the new snapshot format becomes the default?\n\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\tminSeq?: number;\n}\n\n/**\n * @internal\n */\nexport class SnapshotLegacy {\n\tpublic static readonly header = \"header\";\n\tpublic static readonly body = \"body\";\n\tprivate static readonly catchupOps = \"catchupOps\";\n\n\t// Split snapshot into two entries - headers (small) and body (overflow) for faster loading initial content\n\t// Please note that this number has no direct relationship to anything other than size of raw text (characters).\n\t// As we produce json for the blob (and then send over the wire compressed), this number\n\t// is really hard to correlate with any actual metric that matters (like bytes over the wire).\n\t// For test with small number of chunks it would be closer to blob size,\n\t// for very chunky text, blob size can easily be 4x-8x of that number.\n\tpublic static readonly sizeOfFirstChunk: number = 10000;\n\n\tprivate header: SnapshotHeader | undefined;\n\tprivate seq: number | undefined;\n\tprivate segments: ISegmentPrivate[] | undefined;\n\tprivate readonly logger: ITelemetryLoggerExt;\n\tprivate readonly chunkSize: number;\n\n\tconstructor(\n\t\tpublic mergeTree: MergeTree,\n\t\tlogger: ITelemetryLoggerExt,\n\t\tpublic filename?: string,\n\t\tpublic onCompletion?: () => void,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"Snapshot\" });\n\t\tthis.chunkSize =\n\t\t\tmergeTree?.options?.mergeTreeSnapshotChunkSize ?? SnapshotLegacy.sizeOfFirstChunk;\n\t}\n\n\tprivate getSeqLengthSegs(\n\t\tallSegments: ISegmentPrivate[],\n\t\tapproxSequenceLength: number,\n\t\tstartIndex = 0,\n\t): MergeTreeChunkLegacy {\n\t\tconst segs: ISegmentPrivate[] = [];\n\t\tlet sequenceLength = 0;\n\t\tlet segCount = 0;\n\t\tlet segsWithAttribution = 0;\n\t\twhile (\n\t\t\tsequenceLength < approxSequenceLength &&\n\t\t\tstartIndex + segCount < allSegments.length\n\t\t) {\n\t\t\tconst pseg = allSegments[startIndex + segCount];\n\t\t\tsegs.push(pseg);\n\t\t\tif (pseg.attribution) {\n\t\t\t\tsegsWithAttribution++;\n\t\t\t}\n\t\t\tsequenceLength += pseg.cachedLength;\n\t\t\tsegCount++;\n\t\t}\n\n\t\tassert(\n\t\t\tsegsWithAttribution === 0 || segsWithAttribution === segCount,\n\t\t\t0x4bf /* all or no segments should have attribution */,\n\t\t);\n\n\t\tconst attributionSerializer = this.mergeTree.attributionPolicy?.serializer;\n\t\tassert(\n\t\t\tsegsWithAttribution === 0 || attributionSerializer !== undefined,\n\t\t\t0x559 /* attribution serializer must be provided when there are segments with attribution. */,\n\t\t);\n\t\treturn {\n\t\t\tversion: undefined,\n\t\t\tchunkStartSegmentIndex: startIndex,\n\t\t\tchunkSegmentCount: segCount,\n\t\t\tchunkLengthChars: sequenceLength,\n\t\t\ttotalLengthChars: this.header!.segmentsTotalLength,\n\t\t\ttotalSegmentCount: allSegments.length,\n\t\t\tchunkSequenceNumber: this.header!.seq,\n\t\t\tsegmentTexts: segs.map((seg) => seg.toJSONObject() as JsonSegmentSpecs),\n\t\t\tattribution:\n\t\t\t\tsegsWithAttribution > 0 || this.mergeTree.attributionPolicy?.isAttached\n\t\t\t\t\t? attributionSerializer?.serializeAttributionCollections(segs)\n\t\t\t\t\t: undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Emits the snapshot to an ISummarizeResult. If provided the optional IFluidSerializer will be used when\n\t * serializing the summary data rather than JSON.stringify.\n\t */\n\temit(\n\t\tcatchUpMsgs: ISequencedDocumentMessage[],\n\t\tserializer: IFluidSerializer,\n\t\tbind: IFluidHandle,\n\t): ISummaryTreeWithStats {\n\t\tconst chunk1 = this.getSeqLengthSegs(this.segments!, this.chunkSize);\n\t\tlet length: number = chunk1.chunkLengthChars;\n\t\tlet segments: number = chunk1.chunkSegmentCount;\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addBlob(\n\t\t\tSnapshotLegacy.header,\n\t\t\tserializeAsMinSupportedVersion(\n\t\t\t\tSnapshotLegacy.header,\n\t\t\t\tchunk1,\n\t\t\t\tthis.logger,\n\t\t\t\tthis.mergeTree.options,\n\t\t\t\tserializer,\n\t\t\t\tbind,\n\t\t\t),\n\t\t);\n\n\t\tif (chunk1.chunkSegmentCount < chunk1.totalSegmentCount!) {\n\t\t\tconst chunk2 = this.getSeqLengthSegs(\n\t\t\t\tthis.segments!,\n\t\t\t\tthis.header!.segmentsTotalLength,\n\t\t\t\tchunk1.chunkSegmentCount,\n\t\t\t);\n\t\t\tlength += chunk2.chunkLengthChars;\n\t\t\tsegments += chunk2.chunkSegmentCount;\n\t\t\tbuilder.addBlob(\n\t\t\t\tSnapshotLegacy.body,\n\t\t\t\tserializeAsMinSupportedVersion(\n\t\t\t\t\tSnapshotLegacy.body,\n\t\t\t\t\tchunk2,\n\t\t\t\t\tthis.logger,\n\t\t\t\t\tthis.mergeTree.options,\n\t\t\t\t\tserializer,\n\t\t\t\t\tbind,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tassert(\n\t\t\tlength === this.header!.segmentsTotalLength,\n\t\t\t0x05d /* \"emit: mismatch in segmentsTotalLength\" */,\n\t\t);\n\n\t\tassert(\n\t\t\tsegments === chunk1.totalSegmentCount,\n\t\t\t0x05e /* \"emit: mismatch in totalSegmentCount\" */,\n\t\t);\n\n\t\tif (catchUpMsgs !== undefined && catchUpMsgs.length > 0) {\n\t\t\t// Messages used to have a \"term\" property which has since been removed.\n\t\t\t// It is benign so it doesn't really need to be deleted here, but doing so permits snapshot tests\n\t\t\t// to pass with an exact match (and matching the updated definition of ISequencedDocumentMessage).\n\t\t\tfor (const message of catchUpMsgs) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\tdelete (message as any).term;\n\t\t\t}\n\t\t\tbuilder.addBlob(\n\t\t\t\tthis.mergeTree.options?.catchUpBlobName ?? SnapshotLegacy.catchupOps,\n\t\t\t\tserializer ? serializer.stringify(catchUpMsgs, bind) : JSON.stringify(catchUpMsgs),\n\t\t\t);\n\t\t}\n\n\t\treturn builder.getSummaryTree();\n\t}\n\n\textractSync(): ISegmentPrivate[] {\n\t\tconst collabWindow = this.mergeTree.collabWindow;\n\t\tconst seq = (this.seq = collabWindow.minSeq);\n\t\tconst minSeqPerspective = new PriorPerspective(this.seq, NonCollabClient);\n\t\tthis.header = {\n\t\t\tsegmentsTotalLength: this.mergeTree.getLength(minSeqPerspective),\n\t\t\tseq: this.mergeTree.collabWindow.minSeq,\n\t\t};\n\n\t\tlet originalSegments = 0;\n\n\t\tconst segs: ISegmentPrivate[] = [];\n\t\tlet prev: ISegmentPrivate | undefined;\n\t\tconst extractSegment = (segment: ISegmentPrivate): boolean => {\n\t\t\tif (isSegmentLeaf(segment) && minSeqPerspective.isSegmentPresent(segment)) {\n\t\t\t\toriginalSegments += 1;\n\t\t\t\tconst properties =\n\t\t\t\t\tsegment.propertyManager?.getAtSeq(segment.properties, seq) ?? segment.properties;\n\t\t\t\tif (prev?.canAppend(segment) && matchProperties(prev.properties, properties)) {\n\t\t\t\t\tprev.append(segment.clone());\n\t\t\t\t} else {\n\t\t\t\t\tprev = segment.clone();\n\t\t\t\t\tprev.properties = properties;\n\t\t\t\t\tsegs.push(prev);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\tthis.mergeTree.mapRange(extractSegment, minSeqPerspective, undefined);\n\n\t\tthis.segments = [];\n\t\tlet totalLength: number = 0;\n\t\tsegs.map((segment) => {\n\t\t\ttotalLength += segment.cachedLength;\n\t\t\tif (segment.properties !== undefined && Object.keys(segment.properties).length === 0) {\n\t\t\t\tsegment.properties = undefined;\n\t\t\t}\n\t\t\tthis.segments!.push(segment);\n\t\t});\n\n\t\t// To reduce potential spam from this telemetry, we sample only a small\n\t\t// percentage of summaries\n\t\tif (Math.abs(originalSegments - segs.length) > 500 && Math.random() < 0.005) {\n\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"MergeTreeLegacySummarizeSegmentCount\",\n\t\t\t\toriginalSegments,\n\t\t\t\tsegmentsAfterCombine: segs.length,\n\t\t\t\tsegmentsLen: this.segments.length,\n\t\t\t});\n\t\t}\n\n\t\t// We observed this.header.segmentsTotalLength < totalLength to happen in some cases\n\t\t// When this condition happens, we might not write out all segments in getSeqLengthSegs()\n\t\t// when writing out \"body\". Issue #1995 tracks following up on the core of the problem.\n\t\t// In the meantime, this code makes sure we will write out all segments properly\n\n\t\tif (this.header.segmentsTotalLength !== totalLength) {\n\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\teventName: \"SegmentsTotalLengthMismatch\",\n\t\t\t\ttotalLength,\n\t\t\t\tsegmentsTotalLength: this.header.segmentsTotalLength,\n\t\t\t});\n\t\t\tthis.header.segmentsTotalLength = totalLength;\n\t\t}\n\n\t\treturn this.segments;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"snapshotlegacy.js","sourceRoot":"","sources":["../src/snapshotlegacy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAG7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAE5E,OAAO,EAEN,iBAAiB,GACjB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAwB,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAGN,8BAA8B,GAC9B,MAAM,qBAAqB,CAAC;AAa7B;;GAEG;AACH,MAAM,OAAO,cAAc;IAmB1B,YACQ,SAAoB,EAC3B,MAA0B,EACnB,QAAiB,EACjB,YAAyB;QAHzB,cAAS,GAAT,SAAS,CAAW;QAEpB,aAAQ,GAAR,QAAQ,CAAS;QACjB,iBAAY,GAAZ,YAAY,CAAa;QAEhC,IAAI,CAAC,MAAM,GAAG,iBAAiB,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;QACnE,IAAI,CAAC,SAAS;YACb,SAAS,EAAE,OAAO,EAAE,0BAA0B,IAAI,cAAc,CAAC,gBAAgB,CAAC;IACpF,CAAC;IAEO,g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AAC,CAAC;QAC9B,CAAC,CAAC,CAAC;QAEH,uEAAuE;QACvE,0BAA0B;QAC1B,IAAI,IAAI,CAAC,GAAG,CAAC,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;YAC7E,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC;gBAC9B,SAAS,EAAE,sCAAsC;gBACjD,gBAAgB;gBAChB,oBAAoB,EAAE,IAAI,CAAC,MAAM;gBACjC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM;aACjC,CAAC,CAAC;QACJ,CAAC;QAED,oFAAoF;QACpF,yFAAyF;QACzF,uFAAuF;QACvF,gFAAgF;QAEhF,IAAI,IAAI,CAAC,MAAM,CAAC,mBAAmB,KAAK,WAAW,EAAE,CAAC;YACrD,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;gBAC1B,SAAS,EAAE,6BAA6B;gBACxC,WAAW;gBACX,mBAAmB,EAAE,IAAI,CAAC,MAAM,CAAC,mBAAmB;aACpD,CAAC,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,mBAAmB,GAAG,WAAW,CAAC;QAC/C,CAAC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;;AAzNsB,qBAAM,GAAG,QAAQ,CAAC;AAClB,mBAAI,GAAG,MAAM,CAAC;AACb,yBAAU,GAAG,YAAY,CAAC;AAElD,2GAA2G;AAC3G,gHAAgH;AAChH,wFAAwF;AACxF,8FAA8F;AAC9F,wEAAwE;AACxE,sEAAsE;AAC/C,+BAAgB,GAAW,KAAK,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport type { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport type { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\ttype TelemetryLoggerExt,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { NonCollabClient } from \"./constants.js\";\nimport type { MergeTree } from \"./mergeTree.js\";\nimport { isSegmentLeaf, type ISegmentPrivate } from \"./mergeTreeNodes.js\";\nimport { PriorPerspective } from \"./perspective.js\";\nimport { matchProperties } from \"./properties.js\";\nimport {\n\ttype JsonSegmentSpecs,\n\ttype MergeTreeChunkLegacy,\n\tserializeAsMinSupportedVersion,\n} from \"./snapshotChunks.js\";\n\ninterface SnapshotHeader {\n\tchunkCount?: number;\n\tsegmentsTotalLength: number;\n\tindexOffset?: number;\n\tsegmentsOffset?: number;\n\tseq: number;\n\t// TODO: Make 'minSeq' non-optional once the new snapshot format becomes the default?\n\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\tminSeq?: number;\n}\n\n/**\n * @internal\n */\nexport class SnapshotLegacy {\n\tpublic static readonly header = \"header\";\n\tpublic static readonly body = \"body\";\n\tprivate static readonly catchupOps = \"catchupOps\";\n\n\t// Split snapshot into two entries - headers (small) and body (overflow) for faster loading initial content\n\t// Please note that this number has no direct relationship to anything other than size of raw text (characters).\n\t// As we produce json for the blob (and then send over the wire compressed), this number\n\t// is really hard to correlate with any actual metric that matters (like bytes over the wire).\n\t// For test with small number of chunks it would be closer to blob size,\n\t// for very chunky text, blob size can easily be 4x-8x of that number.\n\tpublic static readonly sizeOfFirstChunk: number = 10000;\n\n\tprivate header: SnapshotHeader | undefined;\n\tprivate seq: number | undefined;\n\tprivate segments: ISegmentPrivate[] | undefined;\n\tprivate readonly logger: TelemetryLoggerExt;\n\tprivate readonly chunkSize: number;\n\n\tconstructor(\n\t\tpublic mergeTree: MergeTree,\n\t\tlogger: TelemetryLoggerExt,\n\t\tpublic filename?: string,\n\t\tpublic onCompletion?: () => void,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"Snapshot\" });\n\t\tthis.chunkSize =\n\t\t\tmergeTree?.options?.mergeTreeSnapshotChunkSize ?? SnapshotLegacy.sizeOfFirstChunk;\n\t}\n\n\tprivate getSeqLengthSegs(\n\t\tallSegments: ISegmentPrivate[],\n\t\tapproxSequenceLength: number,\n\t\tstartIndex = 0,\n\t): MergeTreeChunkLegacy {\n\t\tconst segs: ISegmentPrivate[] = [];\n\t\tlet sequenceLength = 0;\n\t\tlet segCount = 0;\n\t\tlet segsWithAttribution = 0;\n\t\twhile (\n\t\t\tsequenceLength < approxSequenceLength &&\n\t\t\tstartIndex + segCount < allSegments.length\n\t\t) {\n\t\t\tconst pseg = allSegments[startIndex + segCount];\n\t\t\tsegs.push(pseg);\n\t\t\tif (pseg.attribution) {\n\t\t\t\tsegsWithAttribution++;\n\t\t\t}\n\t\t\tsequenceLength += pseg.cachedLength;\n\t\t\tsegCount++;\n\t\t}\n\n\t\tassert(\n\t\t\tsegsWithAttribution === 0 || segsWithAttribution === segCount,\n\t\t\t0x4bf /* all or no segments should have attribution */,\n\t\t);\n\n\t\tconst attributionSerializer = this.mergeTree.attributionPolicy?.serializer;\n\t\tassert(\n\t\t\tsegsWithAttribution === 0 || attributionSerializer !== undefined,\n\t\t\t0x559 /* attribution serializer must be provided when there are segments with attribution. */,\n\t\t);\n\t\treturn {\n\t\t\tversion: undefined,\n\t\t\tchunkStartSegmentIndex: startIndex,\n\t\t\tchunkSegmentCount: segCount,\n\t\t\tchunkLengthChars: sequenceLength,\n\t\t\ttotalLengthChars: this.header!.segmentsTotalLength,\n\t\t\ttotalSegmentCount: allSegments.length,\n\t\t\tchunkSequenceNumber: this.header!.seq,\n\t\t\tsegmentTexts: segs.map((seg) => seg.toJSONObject() as JsonSegmentSpecs),\n\t\t\tattribution:\n\t\t\t\tsegsWithAttribution > 0 || this.mergeTree.attributionPolicy?.isAttached\n\t\t\t\t\t? attributionSerializer?.serializeAttributionCollections(segs)\n\t\t\t\t\t: undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Emits the snapshot to an ISummarizeResult. If provided the optional IFluidSerializer will be used when\n\t * serializing the summary data rather than JSON.stringify.\n\t */\n\temit(\n\t\tcatchUpMsgs: ISequencedDocumentMessage[],\n\t\tserializer: IFluidSerializer,\n\t\tbind: IFluidHandle,\n\t): ISummaryTreeWithStats {\n\t\tconst chunk1 = this.getSeqLengthSegs(this.segments!, this.chunkSize);\n\t\tlet length: number = chunk1.chunkLengthChars;\n\t\tlet segments: number = chunk1.chunkSegmentCount;\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addBlob(\n\t\t\tSnapshotLegacy.header,\n\t\t\tserializeAsMinSupportedVersion(\n\t\t\t\tSnapshotLegacy.header,\n\t\t\t\tchunk1,\n\t\t\t\tthis.logger,\n\t\t\t\tthis.mergeTree.options,\n\t\t\t\tserializer,\n\t\t\t\tbind,\n\t\t\t),\n\t\t);\n\n\t\tif (chunk1.chunkSegmentCount < chunk1.totalSegmentCount!) {\n\t\t\tconst chunk2 = this.getSeqLengthSegs(\n\t\t\t\tthis.segments!,\n\t\t\t\tthis.header!.segmentsTotalLength,\n\t\t\t\tchunk1.chunkSegmentCount,\n\t\t\t);\n\t\t\tlength += chunk2.chunkLengthChars;\n\t\t\tsegments += chunk2.chunkSegmentCount;\n\t\t\tbuilder.addBlob(\n\t\t\t\tSnapshotLegacy.body,\n\t\t\t\tserializeAsMinSupportedVersion(\n\t\t\t\t\tSnapshotLegacy.body,\n\t\t\t\t\tchunk2,\n\t\t\t\t\tthis.logger,\n\t\t\t\t\tthis.mergeTree.options,\n\t\t\t\t\tserializer,\n\t\t\t\t\tbind,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tassert(\n\t\t\tlength === this.header!.segmentsTotalLength,\n\t\t\t0x05d /* \"emit: mismatch in segmentsTotalLength\" */,\n\t\t);\n\n\t\tassert(\n\t\t\tsegments === chunk1.totalSegmentCount,\n\t\t\t0x05e /* \"emit: mismatch in totalSegmentCount\" */,\n\t\t);\n\n\t\tif (catchUpMsgs !== undefined && catchUpMsgs.length > 0) {\n\t\t\t// Messages used to have a \"term\" property which has since been removed.\n\t\t\t// It is benign so it doesn't really need to be deleted here, but doing so permits snapshot tests\n\t\t\t// to pass with an exact match (and matching the updated definition of ISequencedDocumentMessage).\n\t\t\tfor (const message of catchUpMsgs) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\tdelete (message as any).term;\n\t\t\t}\n\t\t\tbuilder.addBlob(\n\t\t\t\tthis.mergeTree.options?.catchUpBlobName ?? SnapshotLegacy.catchupOps,\n\t\t\t\tserializer ? serializer.stringify(catchUpMsgs, bind) : JSON.stringify(catchUpMsgs),\n\t\t\t);\n\t\t}\n\n\t\treturn builder.getSummaryTree();\n\t}\n\n\textractSync(): ISegmentPrivate[] {\n\t\tconst collabWindow = this.mergeTree.collabWindow;\n\t\tconst seq = (this.seq = collabWindow.minSeq);\n\t\tconst minSeqPerspective = new PriorPerspective(this.seq, NonCollabClient);\n\t\tthis.header = {\n\t\t\tsegmentsTotalLength: this.mergeTree.getLength(minSeqPerspective),\n\t\t\tseq: this.mergeTree.collabWindow.minSeq,\n\t\t};\n\n\t\tlet originalSegments = 0;\n\n\t\tconst segs: ISegmentPrivate[] = [];\n\t\tlet prev: ISegmentPrivate | undefined;\n\t\tconst extractSegment = (segment: ISegmentPrivate): boolean => {\n\t\t\tif (isSegmentLeaf(segment) && minSeqPerspective.isSegmentPresent(segment)) {\n\t\t\t\toriginalSegments += 1;\n\t\t\t\tconst properties =\n\t\t\t\t\tsegment.propertyManager?.getAtSeq(segment.properties, seq) ?? segment.properties;\n\t\t\t\tif (prev?.canAppend(segment) && matchProperties(prev.properties, properties)) {\n\t\t\t\t\tprev.append(segment.clone());\n\t\t\t\t} else {\n\t\t\t\t\tprev = segment.clone();\n\t\t\t\t\tprev.properties = properties;\n\t\t\t\t\tsegs.push(prev);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\tthis.mergeTree.mapRange(extractSegment, minSeqPerspective, undefined);\n\n\t\tthis.segments = [];\n\t\tlet totalLength: number = 0;\n\t\tsegs.map((segment) => {\n\t\t\ttotalLength += segment.cachedLength;\n\t\t\tif (segment.properties !== undefined && Object.keys(segment.properties).length === 0) {\n\t\t\t\tsegment.properties = undefined;\n\t\t\t}\n\t\t\tthis.segments!.push(segment);\n\t\t});\n\n\t\t// To reduce potential spam from this telemetry, we sample only a small\n\t\t// percentage of summaries\n\t\tif (Math.abs(originalSegments - segs.length) > 500 && Math.random() < 0.005) {\n\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"MergeTreeLegacySummarizeSegmentCount\",\n\t\t\t\toriginalSegments,\n\t\t\t\tsegmentsAfterCombine: segs.length,\n\t\t\t\tsegmentsLen: this.segments.length,\n\t\t\t});\n\t\t}\n\n\t\t// We observed this.header.segmentsTotalLength < totalLength to happen in some cases\n\t\t// When this condition happens, we might not write out all segments in getSeqLengthSegs()\n\t\t// when writing out \"body\". Issue #1995 tracks following up on the core of the problem.\n\t\t// In the meantime, this code makes sure we will write out all segments properly\n\n\t\tif (this.header.segmentsTotalLength !== totalLength) {\n\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\teventName: \"SegmentsTotalLengthMismatch\",\n\t\t\t\ttotalLength,\n\t\t\t\tsegmentsTotalLength: this.header.segmentsTotalLength,\n\t\t\t});\n\t\t\tthis.header.segmentsTotalLength = totalLength;\n\t\t}\n\n\t\treturn this.segments;\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/merge-tree",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.103.0",
|
|
4
4
|
"description": "Merge tree",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -81,30 +81,30 @@
|
|
|
81
81
|
"temp-directory": "nyc/.nyc_output"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@fluid-internal/client-utils": "~2.
|
|
85
|
-
"@fluidframework/container-definitions": "~2.
|
|
86
|
-
"@fluidframework/core-interfaces": "~2.
|
|
87
|
-
"@fluidframework/core-utils": "~2.
|
|
88
|
-
"@fluidframework/datastore-definitions": "~2.
|
|
89
|
-
"@fluidframework/driver-definitions": "~2.
|
|
90
|
-
"@fluidframework/runtime-definitions": "~2.
|
|
91
|
-
"@fluidframework/runtime-utils": "~2.
|
|
92
|
-
"@fluidframework/shared-object-base": "~2.
|
|
93
|
-
"@fluidframework/telemetry-utils": "~2.
|
|
84
|
+
"@fluid-internal/client-utils": "~2.103.0",
|
|
85
|
+
"@fluidframework/container-definitions": "~2.103.0",
|
|
86
|
+
"@fluidframework/core-interfaces": "~2.103.0",
|
|
87
|
+
"@fluidframework/core-utils": "~2.103.0",
|
|
88
|
+
"@fluidframework/datastore-definitions": "~2.103.0",
|
|
89
|
+
"@fluidframework/driver-definitions": "~2.103.0",
|
|
90
|
+
"@fluidframework/runtime-definitions": "~2.103.0",
|
|
91
|
+
"@fluidframework/runtime-utils": "~2.103.0",
|
|
92
|
+
"@fluidframework/shared-object-base": "~2.103.0",
|
|
93
|
+
"@fluidframework/telemetry-utils": "~2.103.0"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
96
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
97
97
|
"@biomejs/biome": "~2.4.5",
|
|
98
|
-
"@fluid-internal/mocha-test-setup": "~2.
|
|
99
|
-
"@fluid-private/stochastic-test-utils": "~2.
|
|
100
|
-
"@fluid-private/test-pairwise-generator": "~2.
|
|
98
|
+
"@fluid-internal/mocha-test-setup": "~2.103.0",
|
|
99
|
+
"@fluid-private/stochastic-test-utils": "~2.103.0",
|
|
100
|
+
"@fluid-private/test-pairwise-generator": "~2.103.0",
|
|
101
101
|
"@fluid-tools/benchmark": "^0.59.0",
|
|
102
102
|
"@fluid-tools/build-cli": "^0.65.0",
|
|
103
103
|
"@fluidframework/build-common": "^2.0.3",
|
|
104
104
|
"@fluidframework/build-tools": "^0.65.0",
|
|
105
105
|
"@fluidframework/eslint-config-fluid": "^9.0.0",
|
|
106
106
|
"@fluidframework/merge-tree-previous": "npm:@fluidframework/merge-tree@2.101.0",
|
|
107
|
-
"@fluidframework/test-runtime-utils": "~2.
|
|
107
|
+
"@fluidframework/test-runtime-utils": "~2.103.0",
|
|
108
108
|
"@microsoft/api-extractor": "7.58.1",
|
|
109
109
|
"@types/diff": "^3.5.1",
|
|
110
110
|
"@types/mocha": "^10.0.10",
|
package/src/client.ts
CHANGED
|
@@ -25,7 +25,7 @@ import type { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions/
|
|
|
25
25
|
import { toDeltaManagerInternal } from "@fluidframework/runtime-utils/internal";
|
|
26
26
|
import type { IFluidSerializer } from "@fluidframework/shared-object-base/internal";
|
|
27
27
|
import {
|
|
28
|
-
type
|
|
28
|
+
type TelemetryLoggerExt,
|
|
29
29
|
LoggingError,
|
|
30
30
|
UsageError,
|
|
31
31
|
} from "@fluidframework/telemetry-utils/internal";
|
|
@@ -193,7 +193,7 @@ export class Client extends TypedEventEmitter<IClientEvents> {
|
|
|
193
193
|
*/
|
|
194
194
|
constructor(
|
|
195
195
|
public readonly specToSegment: (spec: IJSONSegment) => ISegment,
|
|
196
|
-
public readonly logger:
|
|
196
|
+
public readonly logger: TelemetryLoggerExt,
|
|
197
197
|
options?: IMergeTreeOptionsInternal & PropertySet,
|
|
198
198
|
private readonly getMinInFlightRefSeq: () => number | undefined = (): undefined =>
|
|
199
199
|
undefined,
|
package/src/snapshotChunks.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import type { IFluidHandle } from "@fluidframework/core-interfaces";
|
|
9
9
|
import type { IFluidSerializer } from "@fluidframework/shared-object-base/internal";
|
|
10
|
-
import type {
|
|
10
|
+
import type { TelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
|
|
11
11
|
|
|
12
12
|
import type { SerializedAttributionCollection } from "./attributionCollection.js";
|
|
13
13
|
import type { IJSONSegment } from "./ops.js";
|
|
@@ -85,7 +85,7 @@ export function hasMergeInfo(
|
|
|
85
85
|
export function serializeAsMinSupportedVersion(
|
|
86
86
|
path: string,
|
|
87
87
|
chunk: VersionedMergeTreeChunk,
|
|
88
|
-
logger:
|
|
88
|
+
logger: TelemetryLoggerExt,
|
|
89
89
|
options: PropertySet | undefined,
|
|
90
90
|
serializer: IFluidSerializer,
|
|
91
91
|
bind: IFluidHandle,
|
|
@@ -141,7 +141,7 @@ export function serializeAsMinSupportedVersion(
|
|
|
141
141
|
export function serializeAsMaxSupportedVersion(
|
|
142
142
|
path: string,
|
|
143
143
|
chunk: VersionedMergeTreeChunk,
|
|
144
|
-
logger:
|
|
144
|
+
logger: TelemetryLoggerExt,
|
|
145
145
|
options: PropertySet | undefined,
|
|
146
146
|
serializer: IFluidSerializer,
|
|
147
147
|
bind: IFluidHandle,
|
|
@@ -153,7 +153,7 @@ export function serializeAsMaxSupportedVersion(
|
|
|
153
153
|
export function toLatestVersion(
|
|
154
154
|
path: string,
|
|
155
155
|
chunk: VersionedMergeTreeChunk,
|
|
156
|
-
logger:
|
|
156
|
+
logger: TelemetryLoggerExt,
|
|
157
157
|
options: PropertySet | undefined,
|
|
158
158
|
): MergeTreeChunkV1 {
|
|
159
159
|
switch (chunk.version) {
|
package/src/snapshotLoader.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type {
|
|
|
15
15
|
import type { ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
|
|
16
16
|
import type { IFluidSerializer } from "@fluidframework/shared-object-base/internal";
|
|
17
17
|
import {
|
|
18
|
-
type
|
|
18
|
+
type TelemetryLoggerExt,
|
|
19
19
|
UsageError,
|
|
20
20
|
createChildLogger,
|
|
21
21
|
} from "@fluidframework/telemetry-utils/internal";
|
|
@@ -43,14 +43,14 @@ import type { RemoveOperationStamp } from "./stamps.js";
|
|
|
43
43
|
import * as opstampUtils from "./stamps.js";
|
|
44
44
|
|
|
45
45
|
export class SnapshotLoader {
|
|
46
|
-
private readonly logger:
|
|
46
|
+
private readonly logger: TelemetryLoggerExt;
|
|
47
47
|
|
|
48
48
|
constructor(
|
|
49
49
|
private readonly runtime: IFluidDataStoreRuntime,
|
|
50
50
|
|
|
51
51
|
private readonly client: Client,
|
|
52
52
|
private readonly mergeTree: MergeTree,
|
|
53
|
-
logger:
|
|
53
|
+
logger: TelemetryLoggerExt,
|
|
54
54
|
private readonly serializer: IFluidSerializer,
|
|
55
55
|
) {
|
|
56
56
|
this.logger = createChildLogger({ logger, namespace: "SnapshotLoader" });
|
package/src/snapshotV1.ts
CHANGED
|
@@ -14,7 +14,7 @@ import type {
|
|
|
14
14
|
import { SummaryTreeBuilder } from "@fluidframework/runtime-utils/internal";
|
|
15
15
|
import type { IFluidSerializer } from "@fluidframework/shared-object-base/internal";
|
|
16
16
|
import {
|
|
17
|
-
type
|
|
17
|
+
type TelemetryLoggerExt,
|
|
18
18
|
createChildLogger,
|
|
19
19
|
} from "@fluidframework/telemetry-utils/internal";
|
|
20
20
|
|
|
@@ -52,12 +52,12 @@ export class SnapshotV1 {
|
|
|
52
52
|
private readonly segments: JsonSegmentSpecs[];
|
|
53
53
|
private readonly segmentLengths: number[];
|
|
54
54
|
private readonly attributionCollections: IAttributionCollection<AttributionKey>[];
|
|
55
|
-
private readonly logger:
|
|
55
|
+
private readonly logger: TelemetryLoggerExt;
|
|
56
56
|
private readonly chunkSize: number;
|
|
57
57
|
|
|
58
58
|
constructor(
|
|
59
59
|
public mergeTree: MergeTree,
|
|
60
|
-
logger:
|
|
60
|
+
logger: TelemetryLoggerExt,
|
|
61
61
|
private readonly getLongClientId: (id: number) => string,
|
|
62
62
|
public filename?: string,
|
|
63
63
|
public onCompletion?: () => void,
|
|
@@ -367,7 +367,7 @@ export class SnapshotV1 {
|
|
|
367
367
|
public static async loadChunk(
|
|
368
368
|
storage: IChannelStorageService,
|
|
369
369
|
path: string,
|
|
370
|
-
logger:
|
|
370
|
+
logger: TelemetryLoggerExt,
|
|
371
371
|
options: PropertySet | undefined,
|
|
372
372
|
serializer?: IFluidSerializer,
|
|
373
373
|
): Promise<MergeTreeChunkV1> {
|
|
@@ -379,7 +379,7 @@ export class SnapshotV1 {
|
|
|
379
379
|
public static processChunk(
|
|
380
380
|
path: string,
|
|
381
381
|
chunk: string,
|
|
382
|
-
logger:
|
|
382
|
+
logger: TelemetryLoggerExt,
|
|
383
383
|
options: PropertySet | undefined,
|
|
384
384
|
serializer?: IFluidSerializer,
|
|
385
385
|
): MergeTreeChunkV1 {
|
package/src/snapshotlegacy.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions/
|
|
|
12
12
|
import { SummaryTreeBuilder } from "@fluidframework/runtime-utils/internal";
|
|
13
13
|
import type { IFluidSerializer } from "@fluidframework/shared-object-base/internal";
|
|
14
14
|
import {
|
|
15
|
-
type
|
|
15
|
+
type TelemetryLoggerExt,
|
|
16
16
|
createChildLogger,
|
|
17
17
|
} from "@fluidframework/telemetry-utils/internal";
|
|
18
18
|
|
|
@@ -57,12 +57,12 @@ export class SnapshotLegacy {
|
|
|
57
57
|
private header: SnapshotHeader | undefined;
|
|
58
58
|
private seq: number | undefined;
|
|
59
59
|
private segments: ISegmentPrivate[] | undefined;
|
|
60
|
-
private readonly logger:
|
|
60
|
+
private readonly logger: TelemetryLoggerExt;
|
|
61
61
|
private readonly chunkSize: number;
|
|
62
62
|
|
|
63
63
|
constructor(
|
|
64
64
|
public mergeTree: MergeTree,
|
|
65
|
-
logger:
|
|
65
|
+
logger: TelemetryLoggerExt,
|
|
66
66
|
public filename?: string,
|
|
67
67
|
public onCompletion?: () => void,
|
|
68
68
|
) {
|