@fluidframework/merge-tree 2.118.0 → 3.0.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 +34 -4
- package/README.md +53 -50
- package/{api-extractor.json → api-extractor/api-extractor-model.json} +1 -1
- package/dist/MergeTreeTextHelper.js +1 -0
- package/dist/MergeTreeTextHelper.js.map +1 -1
- package/dist/attributionCollection.js +6 -4
- package/dist/attributionCollection.js.map +1 -1
- package/dist/attributionPolicy.js +3 -4
- package/dist/attributionPolicy.js.map +1 -1
- package/dist/client.js +27 -10
- package/dist/client.js.map +1 -1
- package/dist/collections/rbTree.d.ts.map +1 -1
- package/dist/collections/rbTree.js +3 -0
- package/dist/collections/rbTree.js.map +1 -1
- package/dist/endOfTreeSegment.d.ts.map +1 -1
- package/dist/endOfTreeSegment.js +25 -26
- package/dist/endOfTreeSegment.js.map +1 -1
- package/dist/localReference.js +17 -7
- package/dist/localReference.js.map +1 -1
- package/dist/mergeTree.d.ts.map +1 -1
- package/dist/mergeTree.js +90 -74
- package/dist/mergeTree.js.map +1 -1
- package/dist/mergeTreeNodeWalk.js +5 -5
- package/dist/mergeTreeNodeWalk.js.map +1 -1
- package/dist/mergeTreeNodes.d.ts.map +1 -1
- package/dist/mergeTreeNodes.js +117 -90
- package/dist/mergeTreeNodes.js.map +1 -1
- package/dist/mergeTreeTracking.js +4 -0
- package/dist/mergeTreeTracking.js.map +1 -1
- package/dist/opBuilder.js +9 -10
- package/dist/opBuilder.js.map +1 -1
- package/dist/ordinal.js +1 -2
- package/dist/ordinal.js.map +1 -1
- package/dist/partialLengths.js +109 -73
- package/dist/partialLengths.js.map +1 -1
- package/dist/perspective.js +31 -11
- package/dist/perspective.js.map +1 -1
- package/dist/properties.js +6 -7
- package/dist/properties.js.map +1 -1
- package/dist/referencePositions.d.ts.map +1 -1
- package/dist/referencePositions.js +7 -7
- package/dist/referencePositions.js.map +1 -1
- package/dist/revertibles.js +4 -5
- package/dist/revertibles.js.map +1 -1
- package/dist/segmentGroupCollection.js +2 -0
- package/dist/segmentGroupCollection.js.map +1 -1
- package/dist/segmentInfos.d.ts.map +1 -1
- package/dist/segmentInfos.js +5 -5
- package/dist/segmentInfos.js.map +1 -1
- package/dist/segmentPropertiesManager.js +3 -5
- package/dist/segmentPropertiesManager.js.map +1 -1
- package/dist/sequencePlace.js +3 -3
- package/dist/sequencePlace.js.map +1 -1
- package/dist/snapshotChunks.js +4 -5
- package/dist/snapshotChunks.js.map +1 -1
- package/dist/snapshotLoader.js +85 -70
- package/dist/snapshotLoader.js.map +1 -1
- package/dist/snapshotV1.d.ts.map +1 -1
- package/dist/snapshotV1.js +34 -14
- package/dist/snapshotV1.js.map +1 -1
- package/dist/snapshotlegacy.d.ts.map +1 -1
- package/dist/snapshotlegacy.js +18 -10
- package/dist/snapshotlegacy.js.map +1 -1
- package/dist/sortedSet.js +1 -3
- package/dist/sortedSet.js.map +1 -1
- package/dist/stamps.js +11 -12
- package/dist/stamps.js.map +1 -1
- package/dist/test/attributionCollection.spec.js +1 -1
- package/dist/test/attributionCollection.spec.js.map +1 -1
- package/dist/test/beastTest.spec.js +15 -11
- package/dist/test/beastTest.spec.js.map +1 -1
- package/dist/test/client.apis.spec.js +2 -3
- package/dist/test/client.apis.spec.js.map +1 -1
- package/dist/test/client.replay.spec.js +17 -7
- package/dist/test/client.replay.spec.js.map +1 -1
- package/dist/test/clientTestHelper.js +7 -4
- package/dist/test/clientTestHelper.js.map +1 -1
- package/dist/test/mergeTreeOperationRunner.js +26 -16
- package/dist/test/mergeTreeOperationRunner.js.map +1 -1
- package/dist/test/obliterateOperations.d.ts.map +1 -1
- package/dist/test/revertibles.spec.js +1 -2
- package/dist/test/revertibles.spec.js.map +1 -1
- package/dist/test/snapshot.utils.d.ts.map +1 -1
- package/dist/test/snapshot.utils.js +7 -5
- package/dist/test/snapshot.utils.js.map +1 -1
- package/dist/test/stamps.spec.js +17 -7
- package/dist/test/stamps.spec.js.map +1 -1
- package/dist/test/testClient.d.ts.map +1 -1
- package/dist/test/testClient.js +19 -17
- package/dist/test/testClient.js.map +1 -1
- package/dist/test/testClientLogger.d.ts.map +1 -1
- package/dist/test/testClientLogger.js +12 -8
- package/dist/test/testClientLogger.js.map +1 -1
- package/dist/test/testServer.js +7 -7
- package/dist/test/testServer.js.map +1 -1
- package/dist/test/testUtils.d.ts +0 -1
- package/dist/test/testUtils.d.ts.map +1 -1
- package/dist/test/testUtils.js +9 -10
- package/dist/test/testUtils.js.map +1 -1
- package/dist/test/text.js +2 -3
- package/dist/test/text.js.map +1 -1
- package/dist/test/wordUnitTests.spec.js +1 -2
- package/dist/test/wordUnitTests.spec.js.map +1 -1
- package/dist/textSegment.js +3 -2
- package/dist/textSegment.js.map +1 -1
- package/dist/zamboni.js +20 -10
- package/dist/zamboni.js.map +1 -1
- package/lib/MergeTreeTextHelper.js +1 -0
- package/lib/MergeTreeTextHelper.js.map +1 -1
- package/lib/attributionCollection.js +4 -2
- package/lib/attributionCollection.js.map +1 -1
- package/lib/client.js +10 -3
- package/lib/client.js.map +1 -1
- package/lib/collections/rbTree.d.ts.map +1 -1
- package/lib/collections/rbTree.js +3 -0
- package/lib/collections/rbTree.js.map +1 -1
- package/lib/endOfTreeSegment.d.ts.map +1 -1
- package/lib/endOfTreeSegment.js +25 -26
- package/lib/endOfTreeSegment.js.map +1 -1
- package/lib/legacy.d.ts +1 -1
- package/lib/localReference.js +12 -2
- package/lib/localReference.js.map +1 -1
- package/lib/mergeTree.d.ts.map +1 -1
- package/lib/mergeTree.js +68 -62
- package/lib/mergeTree.js.map +1 -1
- package/lib/mergeTreeNodes.d.ts.map +1 -1
- package/lib/mergeTreeNodes.js +111 -84
- package/lib/mergeTreeNodes.js.map +1 -1
- package/lib/mergeTreeTracking.js +4 -0
- package/lib/mergeTreeTracking.js.map +1 -1
- package/lib/partialLengths.js +89 -63
- package/lib/partialLengths.js.map +1 -1
- package/lib/perspective.js +12 -2
- package/lib/perspective.js.map +1 -1
- package/lib/public.d.ts +1 -1
- package/lib/referencePositions.d.ts.map +1 -1
- package/lib/segmentGroupCollection.js +2 -0
- package/lib/segmentGroupCollection.js.map +1 -1
- package/lib/segmentInfos.d.ts.map +1 -1
- package/lib/segmentPropertiesManager.js +1 -3
- package/lib/segmentPropertiesManager.js.map +1 -1
- package/lib/snapshotLoader.js +68 -63
- package/lib/snapshotLoader.js.map +1 -1
- package/lib/snapshotV1.d.ts.map +1 -1
- package/lib/snapshotV1.js +17 -7
- package/lib/snapshotV1.js.map +1 -1
- package/lib/snapshotlegacy.d.ts.map +1 -1
- package/lib/snapshotlegacy.js +18 -10
- package/lib/snapshotlegacy.js.map +1 -1
- package/lib/sortedSet.js +1 -3
- package/lib/sortedSet.js.map +1 -1
- package/lib/test/attributionCollection.spec.js +1 -1
- package/lib/test/attributionCollection.spec.js.map +1 -1
- package/lib/test/beastTest.spec.js +7 -3
- package/lib/test/beastTest.spec.js.map +1 -1
- package/lib/test/clientTestHelper.js +7 -4
- package/lib/test/clientTestHelper.js.map +1 -1
- package/lib/test/obliterateOperations.d.ts.map +1 -1
- package/lib/test/snapshot.utils.d.ts.map +1 -1
- package/lib/test/snapshot.utils.js +5 -3
- package/lib/test/snapshot.utils.js.map +1 -1
- package/lib/test/testClient.d.ts.map +1 -1
- package/lib/test/testClient.js +16 -14
- package/lib/test/testClient.js.map +1 -1
- package/lib/test/testClientLogger.d.ts.map +1 -1
- package/lib/test/testClientLogger.js +10 -6
- package/lib/test/testClientLogger.js.map +1 -1
- package/lib/test/testServer.js +5 -5
- package/lib/test/testServer.js.map +1 -1
- package/lib/test/testUtils.d.ts +0 -1
- package/lib/test/testUtils.d.ts.map +1 -1
- package/lib/textSegment.js +3 -2
- package/lib/textSegment.js.map +1 -1
- package/package.json +39 -58
- package/tsconfig.json +1 -1
- package/internal.d.ts +0 -11
- package/legacy.d.ts +0 -11
- /package/api-extractor/{api-extractor.current.json → api-extractor-report.current.json} +0 -0
- /package/api-extractor/{api-extractor.legacy.json → api-extractor-report.legacy.json} +0 -0
package/dist/snapshotV1.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshotV1.js","sourceRoot":"","sources":["../src/snapshotV1.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+DAA8D;AAE9D,kEAA6D;AAM7D,qEAA4E;AAE5E,uEAGkD;AAGlD,iDAAiD;AAEjD,iEAA8D;AAG9D,mDAAoE;AACpE,uDAA8D;AAC9D,2DAQ6B;AAC7B,2DAAqD;AAErD,0DAA4C;AAE5C,MAAa,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,IAAA,4BAAiB,EAAC,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;QACnE,IAAI,CAAC,SAAS,GAAG,SAAS,EAAE,OAAO,EAAE,0BAA0B,IAAI,UAAU,CAAC,SAAS,CAAC;QAExF,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,YAAY,CAAC;QACtD,IAAI,CAAC,MAAM,GAAG;YACb,iBAAiB,EAAE,MAAM;YACzB,cAAc,EAAE,UAAU;YAC1B,oBAAoB,EAAE,EAAE;YACxB,WAAW,EAAE,CAAC;YACd,iBAAiB,EAAE,CAAC;SACpB,CAAC;QAEF,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,sBAAsB,GAAG,EAAE,CAAC;IAClC,CAAC;IAEO,gBAAgB,CACvB,WAA+B,EAC/B,UAAoB,EACpB,sB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AAe,EAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;;AA5VF,gCA6VC;AA5VA,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\tcreateChildLogger,\n\ttype TelemetryLoggerExt,\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"]}
|
|
1
|
+
{"version":3,"file":"snapshotV1.js","sourceRoot":"","sources":["../src/snapshotV1.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+DAA8D;AAE9D,kEAA6D;AAM7D,qEAA4E;AAE5E,uEAGkD;AAGlD,iDAAiD;AAEjD,iEAA8D;AAG9D,mDAAoE;AACpE,uDAA8D;AAC9D,2DAQ6B;AAC7B,2DAAqD;AAErD,0DAA4C;AAE5C,MAAa,UAAU;IAiBd;IAEU;IACV;IACA;IApBR,2GAA2G;IAC3G,gHAAgH;IAChH,wFAAwF;IACxF,8FAA8F;IAC9F,wEAAwE;IACxE,sEAAsE;IAC/D,MAAM,CAAU,SAAS,GAAW,KAAK,CAAC;IAEhC,MAAM,CAA0B;IAChC,QAAQ,CAAqB;IAC7B,cAAc,CAAW;IACzB,sBAAsB,CAA2C;IACjE,MAAM,CAAqB;IAC3B,SAAS,CAAS;IAEnC,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,IAAA,4BAAiB,EAAC,EAAE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AC/B,IAAY,EACZ,MAA0B,EAC1B,OAAgC,EAChC,UAA6B;QAE7B,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC1C,MAAM,aAAa,GAAG,IAAA,6BAAc,EAAC,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,IAAA,mCAAe,EAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;;AA5VF,gCA6VC","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\tcreateChildLogger,\n\ttype TelemetryLoggerExt,\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"]}
|
|
@@ -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,EAEN,KAAK,kBAAkB,EACvB,MAAM,0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,EAAE,kBAAkB,EACnB,QAAQ,CAAC,EAAE,MAAM,YAAA,EACjB,YAAY,CAAC,GAAE,MAAM,IAAI,aAAA;IAOjC,OAAO,CAAC,gBAAgB;IAgDxB;;;OAGG;IACH,IAAI,CACH,WAAW,EAAE,yBAAyB,EAAE,EACxC,UAAU,EAAE,gBAAgB,EAC5B,IAAI,EAAE,YAAY,GAChB,qBAAqB;IAiExB,WAAW,IAAI,eAAe,EAAE;CAoEhC"}
|
package/dist/snapshotlegacy.js
CHANGED
|
@@ -17,6 +17,24 @@ const snapshotChunks_js_1 = require("./snapshotChunks.js");
|
|
|
17
17
|
* @internal
|
|
18
18
|
*/
|
|
19
19
|
class SnapshotLegacy {
|
|
20
|
+
mergeTree;
|
|
21
|
+
filename;
|
|
22
|
+
onCompletion;
|
|
23
|
+
static header = "header";
|
|
24
|
+
static body = "body";
|
|
25
|
+
static catchupOps = "catchupOps";
|
|
26
|
+
// Split snapshot into two entries - headers (small) and body (overflow) for faster loading initial content
|
|
27
|
+
// Please note that this number has no direct relationship to anything other than size of raw text (characters).
|
|
28
|
+
// As we produce json for the blob (and then send over the wire compressed), this number
|
|
29
|
+
// is really hard to correlate with any actual metric that matters (like bytes over the wire).
|
|
30
|
+
// For test with small number of chunks it would be closer to blob size,
|
|
31
|
+
// for very chunky text, blob size can easily be 4x-8x of that number.
|
|
32
|
+
static sizeOfFirstChunk = 10000;
|
|
33
|
+
header;
|
|
34
|
+
seq;
|
|
35
|
+
segments;
|
|
36
|
+
logger;
|
|
37
|
+
chunkSize;
|
|
20
38
|
constructor(mergeTree, logger, filename, onCompletion) {
|
|
21
39
|
this.mergeTree = mergeTree;
|
|
22
40
|
this.filename = filename;
|
|
@@ -149,14 +167,4 @@ class SnapshotLegacy {
|
|
|
149
167
|
}
|
|
150
168
|
}
|
|
151
169
|
exports.SnapshotLegacy = SnapshotLegacy;
|
|
152
|
-
SnapshotLegacy.header = "header";
|
|
153
|
-
SnapshotLegacy.body = "body";
|
|
154
|
-
SnapshotLegacy.catchupOps = "catchupOps";
|
|
155
|
-
// Split snapshot into two entries - headers (small) and body (overflow) for faster loading initial content
|
|
156
|
-
// Please note that this number has no direct relationship to anything other than size of raw text (characters).
|
|
157
|
-
// As we produce json for the blob (and then send over the wire compressed), this number
|
|
158
|
-
// is really hard to correlate with any actual metric that matters (like bytes over the wire).
|
|
159
|
-
// For test with small number of chunks it would be closer to blob size,
|
|
160
|
-
// for very chunky text, blob size can easily be 4x-8x of that number.
|
|
161
|
-
SnapshotLegacy.sizeOfFirstChunk = 10000;
|
|
162
170
|
//# sourceMappingURL=snapshotlegacy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshotlegacy.js","sourceRoot":"","sources":["../src/snapshotlegacy.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,kEAA6D;AAG7D,qEAA4E;AAE5E,uEAGkD;AAElD,iDAAiD;AAEjD,2DAA0E;AAC1E,qDAAoD;AACpD,mDAAkD;AAClD,2DAI6B;AAa7B;;GAEG;AACH,MAAa,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,IAAA,4BAAiB,EAAC,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,gBAAgB,CACvB,WAA8B,EAC9B,oBAA4B,EAC5B,UAAU,GAAG,CAAC;QAEd,MAAM,IAAI,GAAsB,EAAE,CAAC;QACnC,IAAI,cAAc,GAAG,CAAC,CAAC;QACvB,IAAI,QAAQ,GAAG,CAAC,CAAC;QACjB,IAAI,mBAAmB,G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AC,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;;AA1NF,wCA2NC;AA1NuB,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\tcreateChildLogger,\n\ttype TelemetryLoggerExt,\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"]}
|
|
1
|
+
{"version":3,"file":"snapshotlegacy.js","sourceRoot":"","sources":["../src/snapshotlegacy.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,kEAA6D;AAG7D,qEAA4E;AAE5E,uEAGkD;AAElD,iDAAiD;AAEjD,2DAA0E;AAC1E,qDAAoD;AACpD,mDAAkD;AAClD,2DAI6B;AAa7B;;GAEG;AACH,MAAa,cAAc;IAoBlB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,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;;AA1NF,wCA2NC","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\tcreateChildLogger,\n\ttype TelemetryLoggerExt,\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/dist/sortedSet.js
CHANGED
package/dist/sortedSet.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sortedSet.js","sourceRoot":"","sources":["../src/sortedSet.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;GAEG;AACH,MAAsB,SAAS;
|
|
1
|
+
{"version":3,"file":"sortedSet.js","sourceRoot":"","sources":["../src/sortedSet.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;GAEG;AACH,MAAsB,SAAS;IASX,WAAW,GAAQ,EAAE,CAAC;IAEzC,IAAW,IAAI;QACd,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;IAChC,CAAC;IAED,IAAW,KAAK;QACf,OAAO,IAAI,CAAC,WAAW,CAAC;IACzB,CAAC;IAEM,WAAW,CAAC,OAAU,EAAE,MAA8C;QAC5E,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAChD,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YACrB,MAAM,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;QACrD,CAAC;aAAM,C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BACrB,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;gBACjC,CAAC;gBACD,GAAG,GAAG,KAAK,GAAG,CAAC,CAAC;YACjB,CAAC;iBAAM,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;gBAC9B,IAAI,KAAK,KAAK,GAAG,EAAE,CAAC;oBACnB,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC;gBAC5C,CAAC;gBACD,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC;YACnB,CAAC;iBAAM,IAAI,aAAa,KAAK,CAAC,EAAE,CAAC;gBAChC,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC3C,CAAC;QACF,CAAC;QACD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IACjC,CAAC;IAED;;;;;;OAMG;IACO,gBAAgB,CAAC,IAAO,EAAE,KAAa;QAChD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAChC,CAAC;CACD;AAhFD,8BAgFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * @internal\n */\nexport abstract class SortedSet<T> {\n\t/**\n\t * Standard comparator semantics:\n\t * - If a \\< b, return a negative number\n\t * - If a \\> b, return a positive number\n\t * - If a and b are equivalent, return 0\n\t */\n\tprotected abstract compare(a: T, b: T): number;\n\n\tprotected readonly sortedItems: T[] = [];\n\n\tpublic get size(): number {\n\t\treturn this.sortedItems.length;\n\t}\n\n\tpublic get items(): readonly T[] {\n\t\treturn this.sortedItems;\n\t}\n\n\tpublic addOrUpdate(newItem: T, update?: (existingItem: T, newItem: T) => void): void {\n\t\tconst position = this.findItemPosition(newItem);\n\t\tif (position.exists) {\n\t\t\tupdate?.(this.sortedItems[position.index], newItem);\n\t\t} else {\n\t\t\tthis.sortedItems.splice(position.index, 0, newItem);\n\t\t}\n\t}\n\n\tpublic remove(item: T): boolean {\n\t\tconst position = this.findItemPosition(item);\n\t\tif (position.exists) {\n\t\t\tthis.sortedItems.splice(position.index, 1);\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tpublic has(item: T): boolean {\n\t\tconst position = this.findItemPosition(item);\n\t\treturn position.exists;\n\t}\n\n\tprotected findItemPosition(item: T): { exists: boolean; index: number } {\n\t\tif (this.sortedItems.length === 0) {\n\t\t\treturn { exists: false, index: 0 };\n\t\t}\n\t\tlet start = 0;\n\t\tlet end = this.sortedItems.length - 1;\n\t\tlet index = -1;\n\n\t\twhile (start <= end) {\n\t\t\tindex = start + Math.floor((end - start) / 2);\n\t\t\tconst compareResult = this.compare(item, this.sortedItems[index]);\n\t\t\tif (compareResult < 0) {\n\t\t\t\tif (start === index) {\n\t\t\t\t\treturn { exists: false, index };\n\t\t\t\t}\n\t\t\t\tend = index - 1;\n\t\t\t} else if (compareResult > 0) {\n\t\t\t\tif (index === end) {\n\t\t\t\t\treturn { exists: false, index: index + 1 };\n\t\t\t\t}\n\t\t\t\tstart = index + 1;\n\t\t\t} else if (compareResult === 0) {\n\t\t\t\treturn this.onFindEquivalent(item, index);\n\t\t\t}\n\t\t}\n\t\treturn { exists: false, index };\n\t}\n\n\t/**\n\t * Invoked when `findItemPosition` finds an equivalent item (i.e. `compare` returns 0 between that item and the search item).\n\t *\n\t * By default, `SortedSet` assumes that equivalent items are equal and returns the found index.\n\t * @param item - The item that is being searched for (argument to `findItemPosition`)\n\t * @param index - The index of the equivalent item in the sorted set\n\t */\n\tprotected onFindEquivalent(item: T, index: number): { exists: boolean; index: number } {\n\t\treturn { exists: true, index };\n\t}\n}\n"]}
|
package/dist/stamps.js
CHANGED
|
@@ -4,7 +4,17 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.lessThan = lessThan;
|
|
8
|
+
exports.gte = gte;
|
|
9
|
+
exports.greaterThan = greaterThan;
|
|
10
|
+
exports.lte = lte;
|
|
11
|
+
exports.equal = equal;
|
|
12
|
+
exports.isLocal = isLocal;
|
|
13
|
+
exports.isSquashedOp = isSquashedOp;
|
|
14
|
+
exports.isAcked = isAcked;
|
|
15
|
+
exports.spliceIntoList = spliceIntoList;
|
|
16
|
+
exports.hasAnyAckedOperation = hasAnyAckedOperation;
|
|
17
|
+
exports.compare = compare;
|
|
8
18
|
const constants_js_1 = require("./constants.js");
|
|
9
19
|
function lessThan(a, b) {
|
|
10
20
|
if (a.seq === constants_js_1.UnassignedSequenceNumber) {
|
|
@@ -16,11 +26,9 @@ function lessThan(a, b) {
|
|
|
16
26
|
}
|
|
17
27
|
return a.seq < b.seq;
|
|
18
28
|
}
|
|
19
|
-
exports.lessThan = lessThan;
|
|
20
29
|
function gte(a, b) {
|
|
21
30
|
return !lessThan(a, b);
|
|
22
31
|
}
|
|
23
|
-
exports.gte = gte;
|
|
24
32
|
function greaterThan(a, b) {
|
|
25
33
|
if (a.seq === constants_js_1.UnassignedSequenceNumber) {
|
|
26
34
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -31,27 +39,21 @@ function greaterThan(a, b) {
|
|
|
31
39
|
}
|
|
32
40
|
return a.seq > b.seq;
|
|
33
41
|
}
|
|
34
|
-
exports.greaterThan = greaterThan;
|
|
35
42
|
function lte(a, b) {
|
|
36
43
|
return !greaterThan(a, b);
|
|
37
44
|
}
|
|
38
|
-
exports.lte = lte;
|
|
39
45
|
function equal(a, b) {
|
|
40
46
|
return a.seq === b.seq && a.clientId === b.clientId && a.localSeq === b.localSeq;
|
|
41
47
|
}
|
|
42
|
-
exports.equal = equal;
|
|
43
48
|
function isLocal(a) {
|
|
44
49
|
return a.seq === constants_js_1.UnassignedSequenceNumber;
|
|
45
50
|
}
|
|
46
|
-
exports.isLocal = isLocal;
|
|
47
51
|
function isSquashedOp(a) {
|
|
48
52
|
return a.clientId === constants_js_1.SquashClient && a.seq === constants_js_1.UniversalSequenceNumber;
|
|
49
53
|
}
|
|
50
|
-
exports.isSquashedOp = isSquashedOp;
|
|
51
54
|
function isAcked(a) {
|
|
52
55
|
return a.seq !== constants_js_1.UnassignedSequenceNumber;
|
|
53
56
|
}
|
|
54
|
-
exports.isAcked = isAcked;
|
|
55
57
|
/**
|
|
56
58
|
* Inserts a stamp into a sorted list of stamps in the correct (sorted) position.
|
|
57
59
|
*
|
|
@@ -74,11 +76,9 @@ function spliceIntoList(list, stamp) {
|
|
|
74
76
|
list.unshift(stamp);
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
|
-
exports.spliceIntoList = spliceIntoList;
|
|
78
79
|
function hasAnyAckedOperation(list) {
|
|
79
80
|
return list.some((ts) => isAcked(ts));
|
|
80
81
|
}
|
|
81
|
-
exports.hasAnyAckedOperation = hasAnyAckedOperation;
|
|
82
82
|
function compare(a, b) {
|
|
83
83
|
if (greaterThan(a, b)) {
|
|
84
84
|
return 1;
|
|
@@ -90,5 +90,4 @@ function compare(a, b) {
|
|
|
90
90
|
return 0;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
exports.compare = compare;
|
|
94
93
|
//# sourceMappingURL=stamps.js.map
|
package/dist/stamps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stamps.js","sourceRoot":"","sources":["../src/stamps.ts"],"names":[],"mappings":";AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"stamps.js","sourceRoot":"","sources":["../src/stamps.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAmFH,4BAWC;AAED,kBAEC;AAED,kCAWC;AAED,kBAEC;AAED,sBAEC;AAED,0BAEC;AAED,oCAEC;AAED,0BAEC;AASD,wCAcC;AAED,oDAEC;AAED,0BAQC;AAtKD,iDAIwB;AA6ExB,SAAgB,QAAQ,CAAC,CAAiB,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AAE,CAAC,CAAC,EAAE,CAAC;QAC3B,OAAO,CAAC,CAAC,CAAC;IACX,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,CAAC;IACV,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tSquashClient,\n\tUnassignedSequenceNumber,\n\tUniversalSequenceNumber,\n} from \"./constants.js\";\n\n/**\n * A stamp that identifies provenance of an operation performed on the MergeTree.\n *\n * Stamps identify a point in time (`seq`/`localSeq`) as well as the source (`clientId`) for the operation.\n * This provides enough information to linearize all known applied operations: acked operations happen before\n * local+unacked ones, with acked operations ordered by their sequence numbers and local+unacked operations\n * ordered by their localSeq.\n *\n * By including `clientId`, it also provides enough information to resolve whether segments are visible\n * from alternative perspectives: a remote client will have seen all of its own previous operations as well as\n * those at or below the op's reference sequence number.\n *\n * @remarks As the `readonly` identifies suggest, these stamps should be treated as immutable.\n * New operations applied to a merge-tree should create new stamps rather than modify existing ones (e.g. when\n * a change's ack happens).\n * @internal\n */\nexport interface OperationStamp {\n\t/**\n\t * The sequence number at which this operation was applied.\n\t */\n\treadonly seq: number;\n\n\t/**\n\t * Short clientId for the client that performed this operation.\n\t */\n\treadonly clientId: number;\n\n\t/**\n\t * Local seq at which this operation was applied.\n\t * This is defined if and only if the operation is pending an ack, i.e. `seq` is UnassignedSequenceNumber.\n\t *\n\t * @privateRemarks\n\t * See {@link CollaborationWindow.localSeq} for more information on the semantics of localSeq.\n\t */\n\treadonly localSeq?: number;\n}\n\n/**\n * {@link OperationStamp} for an 'insert' operation.\n */\nexport interface InsertOperationStamp extends OperationStamp {\n\treadonly type: \"insert\";\n}\n\n/**\n * {@link OperationStamp} for a 'set remove' operation. This aligns with the `markRangeRemoved` API in MergeTree.\n *\n * @remarks The terminology here comes from the fact that the removal should affect only the *set* of nodes that were\n * specified at the time the local client issued the remove, and not any nodes that were inserted concurrently.\n *\n * Not using \"remove\" and \"obliterate\" here allows us to unambiguously use the term \"remove\" elsewhere in code to mean\n * \"removed from the tree, either by MergeTree.obliterateRange or MergeTree.removeRange\". This is convenient as the vast majority\n * of merge-tree code only cares about segment visibility and not the specific operation that caused a segment to be removed.\n */\nexport interface SetRemoveOperationStamp extends OperationStamp {\n\treadonly type: \"setRemove\";\n}\n\n/**\n * {@link OperationStamp} for a 'set remove' operation. This aligns with the `obliterateRange` API in MergeTree.\n *\n * @remarks The terminology here comes from the fact that the removal should affect the *slice* of nodes between the\n * start and end point specified by the local client, which includes any nodes that were inserted concurrently.\n *\n * Not using \"remove\" and \"obliterate\" here allows us to unambiguously use the term \"remove\" elsewhere in code to mean\n * \"removed from the tree, either by MergeTree.obliterateRange or MergeTree.removeRange\". This is convenient as the vast majority\n * of merge-tree code only cares about segment visibility and not the specific operation that caused a segment to be removed.\n */\nexport interface SliceRemoveOperationStamp extends OperationStamp {\n\treadonly type: \"sliceRemove\";\n}\n\nexport type RemoveOperationStamp = SetRemoveOperationStamp | SliceRemoveOperationStamp;\n\nexport function lessThan(a: OperationStamp, b: OperationStamp): boolean {\n\tif (a.seq === UnassignedSequenceNumber) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn b.seq === UnassignedSequenceNumber && a.localSeq! < b.localSeq!;\n\t}\n\n\tif (b.seq === UnassignedSequenceNumber) {\n\t\treturn true;\n\t}\n\n\treturn a.seq < b.seq;\n}\n\nexport function gte(a: OperationStamp, b: OperationStamp): boolean {\n\treturn !lessThan(a, b);\n}\n\nexport function greaterThan(a: OperationStamp, b: OperationStamp): boolean {\n\tif (a.seq === UnassignedSequenceNumber) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn b.seq !== UnassignedSequenceNumber || a.localSeq! > b.localSeq!;\n\t}\n\n\tif (b.seq === UnassignedSequenceNumber) {\n\t\treturn false;\n\t}\n\n\treturn a.seq > b.seq;\n}\n\nexport function lte(a: OperationStamp, b: OperationStamp): boolean {\n\treturn !greaterThan(a, b);\n}\n\nexport function equal(a: OperationStamp, b: OperationStamp): boolean {\n\treturn a.seq === b.seq && a.clientId === b.clientId && a.localSeq === b.localSeq;\n}\n\nexport function isLocal(a: OperationStamp): boolean {\n\treturn a.seq === UnassignedSequenceNumber;\n}\n\nexport function isSquashedOp(a: OperationStamp): boolean {\n\treturn a.clientId === SquashClient && a.seq === UniversalSequenceNumber;\n}\n\nexport function isAcked(a: OperationStamp): boolean {\n\treturn a.seq !== UnassignedSequenceNumber;\n}\n\n/**\n * Inserts a stamp into a sorted list of stamps in the correct (sorted) position.\n *\n * Beware that this uses Array.splice, thus requires asymptotics considerations.\n * If inserting a variable number of timestamps, consider just pushing them and sorting the list\n * after using {@link compare} instead.\n */\nexport function spliceIntoList(list: OperationStamp[], stamp: OperationStamp): void {\n\tif (isLocal(stamp) || list.length === 0) {\n\t\tlist.push(stamp);\n\t} else {\n\t\tfor (let i = list.length - 1; i >= 0; i--) {\n\t\t\tif (greaterThan(stamp, list[i])) {\n\t\t\t\tlist.splice(i + 1, 0, stamp);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// Less than all stamps in the list: put it at the beginning.\n\t\tlist.unshift(stamp);\n\t}\n}\n\nexport function hasAnyAckedOperation(list: OperationStamp[]): boolean {\n\treturn list.some((ts) => isAcked(ts));\n}\n\nexport function compare(a: OperationStamp, b: OperationStamp): number {\n\tif (greaterThan(a, b)) {\n\t\treturn 1;\n\t} else if (lessThan(a, b)) {\n\t\treturn -1;\n\t} else {\n\t\treturn 0;\n\t}\n}\n"]}
|
|
@@ -444,9 +444,9 @@ describe("AttributionCollection", () => {
|
|
|
444
444
|
});
|
|
445
445
|
describe("serialized structure is independent of segment lengths", () => {
|
|
446
446
|
class Segment extends mergeTreeNodes_js_1.BaseSegment {
|
|
447
|
+
type = "testSeg";
|
|
447
448
|
constructor(length) {
|
|
448
449
|
super();
|
|
449
|
-
this.type = "testSeg";
|
|
450
450
|
this.cachedLength = length;
|
|
451
451
|
}
|
|
452
452
|
toJSONObject() {
|