@fluidframework/merge-tree 2.23.0-323641 → 2.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/mergeTree.d.ts.map +1 -1
  3. package/dist/mergeTree.js +47 -15
  4. package/dist/mergeTree.js.map +1 -1
  5. package/dist/mergeTreeNodes.d.ts.map +1 -1
  6. package/dist/mergeTreeNodes.js +0 -2
  7. package/dist/mergeTreeNodes.js.map +1 -1
  8. package/dist/partialLengths.d.ts.map +1 -1
  9. package/dist/partialLengths.js +3 -4
  10. package/dist/partialLengths.js.map +1 -1
  11. package/dist/segmentInfos.d.ts +10 -18
  12. package/dist/segmentInfos.d.ts.map +1 -1
  13. package/dist/segmentInfos.js +22 -3
  14. package/dist/segmentInfos.js.map +1 -1
  15. package/dist/snapshotLoader.d.ts.map +1 -1
  16. package/dist/snapshotLoader.js +0 -2
  17. package/dist/snapshotLoader.js.map +1 -1
  18. package/dist/test/obliterate.concurrent.spec.js +53 -1
  19. package/dist/test/obliterate.concurrent.spec.js.map +1 -1
  20. package/lib/mergeTree.d.ts.map +1 -1
  21. package/lib/mergeTree.js +48 -16
  22. package/lib/mergeTree.js.map +1 -1
  23. package/lib/mergeTreeNodes.d.ts.map +1 -1
  24. package/lib/mergeTreeNodes.js +0 -2
  25. package/lib/mergeTreeNodes.js.map +1 -1
  26. package/lib/partialLengths.d.ts.map +1 -1
  27. package/lib/partialLengths.js +4 -5
  28. package/lib/partialLengths.js.map +1 -1
  29. package/lib/segmentInfos.d.ts +10 -18
  30. package/lib/segmentInfos.d.ts.map +1 -1
  31. package/lib/segmentInfos.js +20 -2
  32. package/lib/segmentInfos.js.map +1 -1
  33. package/lib/snapshotLoader.d.ts.map +1 -1
  34. package/lib/snapshotLoader.js +0 -2
  35. package/lib/snapshotLoader.js.map +1 -1
  36. package/lib/test/obliterate.concurrent.spec.js +53 -1
  37. package/lib/test/obliterate.concurrent.spec.js.map +1 -1
  38. package/package.json +17 -17
  39. package/src/mergeTree.ts +57 -15
  40. package/src/mergeTreeNodes.ts +0 -2
  41. package/src/partialLengths.ts +12 -5
  42. package/src/segmentInfos.ts +23 -21
  43. package/src/snapshotLoader.ts +0 -2
@@ -1 +1 @@
1
- {"version":3,"file":"snapshotLoader.js","sourceRoot":"","sources":["../src/snapshotLoader.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6DAA6D;AAE7D,+DAA8D;AAC9D,iFAAoE;AACpE,kEAA6D;AAO7D,uEAIkD;AAGlD,iDAA0E;AAI1E,uDAM2B;AAC3B,2DAI6B;AAC7B,mDAA6C;AAC7C,2DAAqD;AAErD,MAAa,cAAc;IAG1B,YACkB,OAA+B,EAE/B,MAAc,EACd,SAAoB,EACrC,MAA2B,EACV,UAA4B;QAL5B,YAAO,GAAP,OAAO,CAAwB;QAE/B,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAW;QAEpB,eAAU,GAAV,UAAU,CAAkB;QAmD7B,kBAAa,GAAG,CAChC,IAA8C,EACZ,EAAE;YACpC,IAAI,IAAA,gCAAY,EAAC,IAAI,CAAC,EAAE,CAAC;gBACxB,MAAM,GAAG,GAAG,IAAA,+BAAa,EAAiB,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;oBAC/E,QAAQ,EACP,IAAI,CAAC,MAAM,KAAK,SAAS;wBACxB,CAAC,CAAC,8BAAe;wBACjB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC;oBAClD,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,sCAAuB;iBACxC,CAAC,CAAC;gBAEH,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;oBACnC,sEAAsE;oBACtE,oEAAoE;oBACpE,kEAAkE;oBAClE,8CAA8C;oBAC9C,MAAM,iB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ACP,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,IAAA,6BAAc,EAAC,MAAM,WAAW,EAAE,MAAM,CAAC,CACV,CAAC;IAClC,CAAC;CACD;AAnRD,wCAmRC","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 {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tUsageError,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { Client } from \"./client.js\";\nimport { NonCollabClient, UniversalSequenceNumber } from \"./constants.js\";\nimport { MergeTree } from \"./mergeTree.js\";\nimport { ISegmentPrivate } from \"./mergeTreeNodes.js\";\nimport { IJSONSegment } from \"./ops.js\";\nimport {\n\tIRemovalInfo,\n\toverwriteInfo,\n\ttype IInsertionInfo,\n\ttype IMoveInfo,\n\ttype SegmentWithInfo,\n} from \"./segmentInfos.js\";\nimport {\n\tIJSONSegmentWithMergeInfo,\n\tMergeTreeChunkV1,\n\thasMergeInfo,\n} from \"./snapshotChunks.js\";\nimport { SnapshotV1 } from \"./snapshotV1.js\";\nimport { SnapshotLegacy } from \"./snapshotlegacy.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<IInsertionInfo> => {\n\t\tif (hasMergeInfo(spec)) {\n\t\t\tconst seg = overwriteInfo<IInsertionInfo>(this.client.specToSegment(spec.json), {\n\t\t\t\tclientId:\n\t\t\t\t\tspec.client === undefined\n\t\t\t\t\t\t? NonCollabClient\n\t\t\t\t\t\t: this.client.getOrAddShortClientId(spec.client),\n\t\t\t\tseq: spec.seq ?? UniversalSequenceNumber,\n\t\t\t});\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\toverwriteInfo<IRemovalInfo>(seg, {\n\t\t\t\t\tremovedSeq: spec.removedSeq,\n\t\t\t\t\tremovedClientIds: spec.removedClientIds.map((id) =>\n\t\t\t\t\t\tthis.client.getOrAddShortClientId(id),\n\t\t\t\t\t),\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\toverwriteInfo<IMoveInfo>(seg, {\n\t\t\t\t\tmovedSeq: spec.movedSeq,\n\t\t\t\t\tmovedSeqs: spec.movedSeqs,\n\t\t\t\t\tmovedClientIds: spec.movedClientIds.map((id) =>\n\t\t\t\t\t\tthis.client.getOrAddShortClientId(id),\n\t\t\t\t\t),\n\t\t\t\t\t// TODO:AB#29553: This property should be derived from segment data, not hard-coded.\n\t\t\t\t\twasMovedOnInsert: false,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn seg;\n\t\t}\n\t\treturn overwriteInfo(this.client.specToSegment(spec), {\n\t\t\tseq: UniversalSequenceNumber,\n\t\t\tclientId: NonCollabClient,\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<IInsertionInfo>[] = [];\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\tsegs.push(...newSegs);\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[], cli: 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\t/* refSeq: */ UniversalSequenceNumber,\n\t\t\t\tcli,\n\t\t\t\tseq,\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<IInsertionInfo>[] = [];\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;\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,+DAA8D;AAC9D,iFAAoE;AACpE,kEAA6D;AAO7D,uEAIkD;AAGlD,iDAA0E;AAI1E,uDAM2B;AAC3B,2DAI6B;AAC7B,mDAA6C;AAC7C,2DAAqD;AAErD,MAAa,cAAc;IAG1B,YACkB,OAA+B,EAE/B,MAAc,EACd,SAAoB,EACrC,MAA2B,EACV,UAA4B;QAL5B,YAAO,GAAP,OAAO,CAAwB;QAE/B,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAW;QAEpB,eAAU,GAAV,UAAU,CAAkB;QAmD7B,kBAAa,GAAG,CAChC,IAA8C,EACZ,EAAE;YACpC,IAAI,IAAA,gCAAY,EAAC,IAAI,CAAC,EAAE,CAAC;gBACxB,MAAM,GAAG,GAAG,IAAA,+BAAa,EAAiB,IAAI,CAA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7C,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;gBACrC,MAAM,IAAI,qBAAU,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,IAAA,6BAAc,EAAC,MAAM,WAAW,EAAE,MAAM,CAAC,CACV,CAAC;IAClC,CAAC;CACD;AAjRD,wCAiRC","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 {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tUsageError,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { Client } from \"./client.js\";\nimport { NonCollabClient, UniversalSequenceNumber } from \"./constants.js\";\nimport { MergeTree } from \"./mergeTree.js\";\nimport { ISegmentPrivate } from \"./mergeTreeNodes.js\";\nimport { IJSONSegment } from \"./ops.js\";\nimport {\n\tIRemovalInfo,\n\toverwriteInfo,\n\ttype IInsertionInfo,\n\ttype IMoveInfo,\n\ttype SegmentWithInfo,\n} from \"./segmentInfos.js\";\nimport {\n\tIJSONSegmentWithMergeInfo,\n\tMergeTreeChunkV1,\n\thasMergeInfo,\n} from \"./snapshotChunks.js\";\nimport { SnapshotV1 } from \"./snapshotV1.js\";\nimport { SnapshotLegacy } from \"./snapshotlegacy.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<IInsertionInfo> => {\n\t\tif (hasMergeInfo(spec)) {\n\t\t\tconst seg = overwriteInfo<IInsertionInfo>(this.client.specToSegment(spec.json), {\n\t\t\t\tclientId:\n\t\t\t\t\tspec.client === undefined\n\t\t\t\t\t\t? NonCollabClient\n\t\t\t\t\t\t: this.client.getOrAddShortClientId(spec.client),\n\t\t\t\tseq: spec.seq ?? UniversalSequenceNumber,\n\t\t\t});\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\toverwriteInfo<IRemovalInfo>(seg, {\n\t\t\t\t\tremovedSeq: spec.removedSeq,\n\t\t\t\t\tremovedClientIds: spec.removedClientIds.map((id) =>\n\t\t\t\t\t\tthis.client.getOrAddShortClientId(id),\n\t\t\t\t\t),\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\toverwriteInfo<IMoveInfo>(seg, {\n\t\t\t\t\tmovedSeq: spec.movedSeq,\n\t\t\t\t\tmovedSeqs: spec.movedSeqs,\n\t\t\t\t\tmovedClientIds: spec.movedClientIds.map((id) =>\n\t\t\t\t\t\tthis.client.getOrAddShortClientId(id),\n\t\t\t\t\t),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn seg;\n\t\t}\n\t\treturn overwriteInfo(this.client.specToSegment(spec), {\n\t\t\tseq: UniversalSequenceNumber,\n\t\t\tclientId: NonCollabClient,\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<IInsertionInfo>[] = [];\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\tsegs.push(...newSegs);\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[], cli: 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\t/* refSeq: */ UniversalSequenceNumber,\n\t\t\t\tcli,\n\t\t\t\tseq,\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<IInsertionInfo>[] = [];\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;\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"]}
@@ -944,7 +944,7 @@ for (const incremental of [true, false]) {
944
944
  node_assert_1.strict.equal(helper.clients.A.getText(), "FZGBA");
945
945
  helper.logger.validate();
946
946
  });
947
- it("wasMovedOnInsert remains after leaf node is split", () => {
947
+ it("wasMovedOnInsert computation remains accurate after leaf node is split", () => {
948
948
  const helper = new reconnectHelper_js_1.ReconnectTestHelper();
949
949
  // CD-B-A
950
950
  // I-(C-(G)H-E)-F-D-B-A
@@ -1499,6 +1499,58 @@ for (const incremental of [true, false]) {
1499
1499
  helper.processAllOps();
1500
1500
  helper.logger.validate({ baseText: "8m" });
1501
1501
  });
1502
+ // See 'Local obliterate wins post-insertion of segment previously thought to have won' (below) for a simpler
1503
+ // to understand version of this test. This test is the original partial synchronization fuzz variant which
1504
+ // demonstrated that issue, and has been preserved for now in case it catches additional related problems.
1505
+ // Once fuzz testing more meaninfully leverages ops being sent to different clients at different types (partial
1506
+ // synchronization), it's probably fine to remove this.
1507
+ it("fuzz regression: Local obliterate wins post-insertion of segment previously thought to have won", () => {
1508
+ const helper = new partialSyncHelper_js_1.PartialSyncTestHelper();
1509
+ helper.insertText("A", 0, "Hx15J");
1510
+ helper.processAllOps();
1511
+ helper.insertText("A", 0, "9T");
1512
+ helper.insertText("B", 0, "c8v");
1513
+ helper.advanceClients("A", "C");
1514
+ helper.removeRange("A", 2, 5);
1515
+ helper.removeRange("A", 0, 1);
1516
+ helper.obliterateRange("A", 0, 3);
1517
+ helper.obliterateRange("C", { pos: 1, side: sequencePlace_js_1.Side.After }, { pos: 4, side: sequencePlace_js_1.Side.Before });
1518
+ helper.insertText("B", 0, "4qpo");
1519
+ helper.insertText("C", 2, "fP");
1520
+ helper.insertText("A", 0, "hn");
1521
+ helper.advanceClients("A", "C");
1522
+ helper.obliterateRange("A", { pos: 5, side: sequencePlace_js_1.Side.After }, { pos: 9, side: sequencePlace_js_1.Side.After });
1523
+ helper.obliterateRange("B", { pos: 3, side: sequencePlace_js_1.Side.Before }, { pos: 9, side: sequencePlace_js_1.Side.After });
1524
+ // At the time of the original bug, this would hit 0xa3f.
1525
+ helper.processAllOps();
1526
+ helper.logger.validate({ baseText: "hn4qpJ" });
1527
+ });
1528
+ // Simpler version of the above test which has the same root cause but reproduces a slightly different failure mode.
1529
+ it("Local obliterate wins post-insertion of segment previously thought to have won", () => {
1530
+ const helper = new partialSyncHelper_js_1.PartialSyncTestHelper();
1531
+ helper.insertText("A", 0, "1xx2");
1532
+ helper.processAllOps();
1533
+ // A and B both obliterate the 'xx' segment with an expanding obliterate, then try to insert
1534
+ // into the gap that it leaves.
1535
+ helper.obliterateRange("A", { pos: 0, side: sequencePlace_js_1.Side.After }, { pos: 3, side: sequencePlace_js_1.Side.Before });
1536
+ helper.insertText("A", 1, "aaaa");
1537
+ helper.obliterateRange("B", { pos: 0, side: sequencePlace_js_1.Side.After }, { pos: 3, side: sequencePlace_js_1.Side.Before });
1538
+ helper.insertText("B", 1, "bbb");
1539
+ helper.advanceClients("A", "B");
1540
+ // Meanwhile, C attempts the same thing without seeing A or B's obliterate & insertions
1541
+ helper.obliterateRange("C", { pos: 0, side: sequencePlace_js_1.Side.After }, { pos: 3, side: sequencePlace_js_1.Side.Before });
1542
+ helper.insertText("C", 1, "ccc");
1543
+ // Before seeing C's ops, B attempts to insert more content. Since B hasn't yet seen C's obliterate,
1544
+ // A and B are under the impression that B's obliterate has won and the string contents are '1bbb2'.
1545
+ helper.insertText("B", 5, "B");
1546
+ helper.insertText("A", 5, "A");
1547
+ helper.processAllOps();
1548
+ // By now, all clients realize C actually won the obliterate and should have additionally applied B's
1549
+ // op correctly as it was outside of the obliterated range.
1550
+ // At the time this test was written, client C had trouble recognizing that A and B think that B has won
1551
+ // and merged incorrectly, hitting 'MergeTree insert failed'.
1552
+ helper.logger.validate({ baseText: "1ccc2AB" });
1553
+ });
1502
1554
  });
1503
1555
  });
1504
1556
  }