@fluidframework/matrix 0.57.0 → 0.58.0-55983
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/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/permutationvector.js +4 -5
- package/dist/permutationvector.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/permutationvector.js +4 -5
- package/lib/permutationvector.js.map +1 -1
- package/package.json +13 -13
- package/src/packageVersion.ts +1 -1
- package/src/permutationvector.ts +5 -5
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/matrix";
|
|
8
|
-
export declare const pkgVersion = "0.
|
|
8
|
+
export declare const pkgVersion = "0.58.0-55983";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,2BAA2B,CAAC;AAChD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,2BAA2B,CAAC;AAChD,eAAO,MAAM,UAAU,iBAAiB,CAAC"}
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/matrix";
|
|
11
|
-
exports.pkgVersion = "0.
|
|
11
|
+
exports.pkgVersion = "0.58.0-55983";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,wBAAwB,CAAC;AACnC,QAAA,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,wBAAwB,CAAC;AACnC,QAAA,UAAU,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/matrix\";\nexport const pkgVersion = \"0.58.0-55983\";\n"]}
|
|
@@ -45,7 +45,7 @@ class PermutationSegment extends merge_tree_1.BaseSegment {
|
|
|
45
45
|
// it is included if the undo stack continues to unwind to the original insertion.
|
|
46
46
|
//
|
|
47
47
|
// Out of paranoia we link and unlink in separate loops to avoid mutating the underlying
|
|
48
|
-
// set during enumeration. In
|
|
48
|
+
// set during enumeration. In practice, this is unlikely to matter since there should be
|
|
49
49
|
// exactly 0 or 1 items in the enumeration.
|
|
50
50
|
for (const group of this.trackingCollection.trackingGroups) {
|
|
51
51
|
group.link(destination);
|
|
@@ -124,7 +124,7 @@ class PermutationVector extends merge_tree_1.Client {
|
|
|
124
124
|
case 0 /* INSERT */:
|
|
125
125
|
// Pass 1: Perform any internal maintenance first to avoid reentrancy.
|
|
126
126
|
for (const { segment, position } of ranges) {
|
|
127
|
-
// HACK: We need to include the allocated handle in the segment's JSON
|
|
127
|
+
// HACK: We need to include the allocated handle in the segment's JSON representation
|
|
128
128
|
// for snapshots, but need to ignore the remote client's handle allocations when
|
|
129
129
|
// processing remote ops.
|
|
130
130
|
segment.reset();
|
|
@@ -260,9 +260,8 @@ class PermutationVector extends merge_tree_1.Client {
|
|
|
260
260
|
// Once we know the current position of the handle, we can use the MergeTree to get the segment
|
|
261
261
|
// containing this position and use 'findReconnectionPosition' to adjust for the local ops that
|
|
262
262
|
// have not yet been submitted.
|
|
263
|
-
// eslint-disable-next-line
|
|
264
|
-
|
|
265
|
-
return this.findReconnectionPostition(containingSegment, localSeq) + containingOffset;
|
|
263
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
264
|
+
return this.findReconnectionPosition(containingSegment, localSeq) + containingOffset;
|
|
266
265
|
}
|
|
267
266
|
// Constructs an ISummaryTreeWithStats for the cell data.
|
|
268
267
|
summarize(runtime, handle, serializer) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permutationvector.js","sourceRoot":"","sources":["../src/permutationvector.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AACtD,qEAA8D;AAG9D,2DAYoC;AAIpC,iEAA2F;AAC3F,+CAAmE;AACnE,mDAAkD;AAClD,+CAA4C;AAU5C,MAAa,kBAAmB,SAAQ,wBAAW;IAW/C,YAAY,MAAc,EAAE,KAAK,gCAAqB;QAClD,KAAK,EAAE,CAAC;QAVJ,WAAM,iCAAsB;QAOpB,SAAI,GAAG,kBAAkB,CAAC,UAAU,CAAC;QAIjD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;IAC/B,CAAC;IAXM,MAAM,CAAC,cAAc,CAAC,IAAS;QAClC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAA8B,CAAC;QACvD,OAAO,IAAI,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACj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ributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { IFluidDataStoreRuntime, IChannelStorageService } from \"@fluidframework/datastore-definitions\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport {\n BaseSegment,\n ISegment,\n LocalReferenceCollection,\n Client,\n IMergeTreeDeltaOpArgs,\n IMergeTreeDeltaCallbackArgs,\n MergeTreeDeltaType,\n IMergeTreeMaintenanceCallbackArgs,\n MergeTreeMaintenanceType,\n LocalReference,\n ReferenceType,\n} from \"@fluidframework/merge-tree\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { HandleTable, Handle, isHandleValid } from \"./handletable\";\nimport { deserializeBlob } from \"./serialization\";\nimport { HandleCache } from \"./handlecache\";\nimport { VectorUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n segments = \"segments\",\n handleTable = \"handleTable\",\n}\n\ntype PermutationSegmentSpec = [number, number];\n\nexport class PermutationSegment extends BaseSegment {\n public static readonly typeString: string = \"PermutationSegment\";\n private _start = Handle.unallocated;\n\n public static fromJSONObject(spec: any) {\n const [length, start] = spec as PermutationSegmentSpec;\n return new PermutationSegment(length, start);\n }\n\n public readonly type = PermutationSegment.typeString;\n\n constructor(length: number, start = Handle.unallocated) {\n super();\n this._start = start;\n this.cachedLength = length;\n }\n\n public get start() { return this._start; }\n public set start(value: Handle) {\n assert(this._start === Handle.unallocated, 0x024 /* \"Start of PermutationSegment already allocated!\" */);\n assert(isHandleValid(value), 0x025 /* \"Trying to set start of PermutationSegment to invalid handle!\" */);\n\n this._start = value;\n }\n\n /**\n * Invoked by '_undoRow/ColRemove' to prepare the newly inserted destination\n * segment to serve as the replacement for this removed segment. This moves handle\n * allocations from this segment to the replacement as well as maintains tracking\n * groups for the undo/redo stack.\n */\n public transferToReplacement(destination: PermutationSegment) {\n // When this segment was removed, it may have been split from a larger original\n // segment. In this case, it will have been added to an undo/redo tracking group\n // that associates all of the fragments from the original insertion.\n //\n // Move this association from the this removed segment to its replacement so that\n // it is included if the undo stack continues to unwind to the original insertion.\n //\n // Out of paranoia we link and unlink in separate loops to avoid mutating the underlying\n // set during enumeration. In pratice, this is unlikely to matter since there should be\n // exactly 0 or 1 items in the enumeration.\n for (const group of this.trackingCollection.trackingGroups) {\n group.link(destination);\n }\n for (const group of this.trackingCollection.trackingGroups) {\n group.unlink(this);\n }\n\n // Move handle allocations from this segment to its replacement.\n destination._start = this._start;\n this.reset();\n }\n\n public reset() {\n this._start = Handle.unallocated;\n }\n\n public toJSONObject() {\n return [this.cachedLength, this.start];\n }\n\n public clone(start = 0, end = this.cachedLength) {\n const b = new PermutationSegment(\n /* length: */ end - start,\n /* start: */ this.start + start);\n this.cloneInto(b);\n return b;\n }\n\n public canAppend(segment: ISegment) {\n const asPerm = segment as PermutationSegment;\n\n return this.start === Handle.unallocated\n ? asPerm.start === Handle.unallocated\n : asPerm.start === this.start + this.cachedLength;\n }\n\n public append(segment: ISegment) {\n // Note: Must call 'LocalReferenceCollection.append(..)' before modifying this segment's length as\n // 'this.cachedLength' is used to adjust the offsets of the local refs.\n LocalReferenceCollection.append(this, segment);\n\n this.cachedLength += segment.cachedLength;\n }\n\n protected createSplitSegmentAt(pos: number) {\n assert(0 < pos && pos < this.cachedLength, 0x026 /* \"Trying to split segment at out-of-bounds position!\" */);\n\n const leafSegment = new PermutationSegment(\n /* length: */ this.cachedLength - pos,\n /* start: */ this.start === Handle.unallocated\n ? Handle.unallocated\n : this.start + pos);\n\n this.cachedLength = pos;\n\n return leafSegment;\n }\n\n public toString() {\n return this.start === Handle.unallocated\n ? `<${this.cachedLength} empty>`\n : `<${this.cachedLength}: ${this.start}..${this.start + this.cachedLength - 1}>`;\n }\n}\n\nexport class PermutationVector extends Client {\n private handleTable = new HandleTable<never>(); // Tracks available storage handles for rows.\n public readonly handleCache = new HandleCache(this);\n public undo: VectorUndoProvider | undefined;\n\n constructor(\n path: string,\n logger: ITelemetryBaseLogger,\n runtime: IFluidDataStoreRuntime,\n private readonly deltaCallback: (position: number, numRemoved: number, numInserted: number) => void,\n private readonly handlesRecycledCallback: (handles: Handle[]) => void,\n ) {\n super(\n PermutationSegment.fromJSONObject,\n ChildLogger.create(logger, `Matrix.${path}.MergeTreeClient`), {\n ...runtime.options,\n newMergeTreeSnapshotFormat: true, // Temporarily force new snapshot format until it is the default.\n }); // (See https://github.com/microsoft/FluidFramework/issues/84)\n\n this.mergeTreeDeltaCallback = this.onDelta;\n this.mergeTreeMaintenanceCallback = this.onMaintenance;\n }\n\n public insert(start: number, length: number) {\n return this.insertSegmentLocal(\n start,\n new PermutationSegment(length));\n }\n\n public insertRelative(segment: ISegment, length: number) {\n const inserted = new PermutationSegment(length);\n\n return {\n op: this.insertAtReferencePositionLocal(\n new LocalReference(this, segment, /* offset: */ 0, ReferenceType.Transient),\n inserted),\n inserted,\n };\n }\n\n public remove(start: number, length: number) {\n return this.removeRangeLocal(start, start + length);\n }\n\n public getMaybeHandle(pos: number): Handle {\n assert(0 <= pos && pos < this.getLength(), 0x027 /* \"Trying to get handle of out-of-bounds position!\" */);\n\n return this.handleCache.getHandle(pos);\n }\n\n public getAllocatedHandle(pos: number): Handle {\n let handle = this.getMaybeHandle(pos);\n if (isHandleValid(handle)) {\n return handle;\n }\n\n this.walkSegments(\n (segment) => {\n const asPerm = segment as PermutationSegment;\n asPerm.start = handle = this.handleTable.allocate();\n return true;\n },\n pos,\n pos + 1,\n /* accum: */ undefined,\n /* splitRange: */ true);\n\n this.handleCache.addHandle(pos, handle);\n\n return handle;\n }\n\n public adjustPosition(pos: number, fromSeq: number, clientId: number) {\n const { segment, offset } = this.mergeTree.getContainingSegment(pos, fromSeq, clientId);\n\n // Note that until the MergeTree GCs, the segment is still reachable via `getContainingSegment()` with\n // a `refSeq` in the past. Prevent remote ops from accidentally allocating or using recycled handles\n // by checking for the presence of 'removedSeq'.\n if (segment === undefined || segment.removedSeq !== undefined) {\n return undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.getPosition(segment) + offset!;\n }\n\n public handleToPosition(handle: Handle, localSeq = this.mergeTree.collabWindow.localSeq) {\n assert(localSeq <= this.mergeTree.collabWindow.localSeq,\n 0x028 /* \"'localSeq' for op being resubmitted must be <= the 'localSeq' of the last submitted op.\" */);\n\n // TODO: In theory, the MergeTree should be able to map the (position, refSeq, localSeq) from\n // the original operation to the current position for resubmitting. This is probably the\n // ideal solution, as we would no longer need to store row/col handles in the op metadata.\n //\n // Failing that, we could avoid the O(n) search below by building a temporary map in the\n // opposite direction from the handle to either it's current position or segment + offset\n // and reuse it for the duration of resubmission. (Ideally, we would know when resubmission\n // ended so we could discard this map.)\n //\n // If we find that we frequently need a reverse handle -> position lookup, we could maintain\n // one using the Tiny-Calc adjust tree.\n let containingSegment!: PermutationSegment;\n let containingOffset: number;\n\n this.mergeTree.walkAllSegments(\n this.mergeTree.root,\n (segment) => {\n const { start, cachedLength } = segment as PermutationSegment;\n\n // If the segment is unallocated, skip it.\n if (!isHandleValid(start)) {\n return true;\n }\n\n const end = start + cachedLength;\n\n if (start <= handle && handle < end) {\n containingSegment = segment as PermutationSegment;\n containingOffset = handle - start;\n return false;\n }\n\n return true;\n });\n\n // We are guaranteed to find the handle in the PermutationVector, even if the corresponding\n // row/col has been removed, because handles are not recycled until the containing segment\n // is unlinked from the MergeTree.\n //\n // Therefore, either a row/col removal has been ACKed, in which case there will be no pending\n // ops that reference the stale handle, or the removal is unACKed, in which case the handle\n // has not yet been recycled.\n\n assert(isHandleValid(containingSegment.start), 0x029 /* \"Invalid handle at start of containing segment!\" */);\n\n // Once we know the current position of the handle, we can use the MergeTree to get the segment\n // containing this position and use 'findReconnectionPosition' to adjust for the local ops that\n // have not yet been submitted.\n\n // eslint-disable-next-line max-len\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion\n return this.findReconnectionPostition(containingSegment, localSeq) + containingOffset!;\n }\n\n // Constructs an ISummaryTreeWithStats for the cell data.\n public summarize(runtime: IFluidDataStoreRuntime, handle: IFluidHandle, serializer: IFluidSerializer):\n ISummaryTreeWithStats {\n const builder = new SummaryTreeBuilder();\n builder.addWithStats(SnapshotPath.segments, super.summarize(runtime, handle, serializer, /* catchUpMsgs: */[]));\n builder.addBlob(SnapshotPath.handleTable, serializer.stringify(this.handleTable.getSummaryContent(), handle));\n return builder.getSummaryTree();\n }\n\n public async load(\n runtime: IFluidDataStoreRuntime,\n storage: IChannelStorageService,\n serializer: IFluidSerializer,\n ) {\n const handleTableData = await deserializeBlob(storage, SnapshotPath.handleTable, serializer);\n\n this.handleTable = HandleTable.load<never>(handleTableData);\n\n return super.load(runtime, new ObjectStoragePartition(storage, SnapshotPath.segments), serializer);\n }\n\n private readonly onDelta = (\n opArgs: IMergeTreeDeltaOpArgs,\n { operation, deltaSegments }: IMergeTreeDeltaCallbackArgs,\n ) => {\n // Apply deltas in descending order to prevent positions from shifting.\n const ranges = deltaSegments\n .map(({ segment }) => ({\n segment: segment as PermutationSegment,\n position: this.getPosition(segment),\n }))\n .sort((left, right) => left.position - right.position);\n\n const isLocal = opArgs.sequencedMessage === undefined;\n\n // Notify the undo provider, if any is attached.\n if (this.undo !== undefined && isLocal) {\n this.undo.record(operation, ranges);\n }\n\n switch (operation) {\n case MergeTreeDeltaType.INSERT:\n // Pass 1: Perform any internal maintenance first to avoid reentrancy.\n for (const { segment, position } of ranges) {\n // HACK: We need to include the allocated handle in the segment's JSON reperesntation\n // for snapshots, but need to ignore the remote client's handle allocations when\n // processing remote ops.\n segment.reset();\n\n this.handleCache.itemsChanged(\n position,\n /* deleteCount: */ 0,\n /* insertCount: */ segment.cachedLength);\n }\n\n // Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n for (const { segment, position } of ranges) {\n this.deltaCallback(position, /* numRemoved: */ 0, /* numInserted: */ segment.cachedLength);\n }\n break;\n\n case MergeTreeDeltaType.REMOVE: {\n // Pass 1: Perform any internal maintenance first to avoid reentrancy.\n for (const { segment, position } of ranges) {\n this.handleCache.itemsChanged(\n position, /* deleteCount: */\n segment.cachedLength,\n /* insertCount: */ 0);\n }\n\n // Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n for (const { segment, position } of ranges) {\n this.deltaCallback(position, /* numRemoved: */ segment.cachedLength, /* numInsert: */ 0);\n }\n break;\n }\n\n default:\n throw new Error(\"Unhandled MergeTreeDeltaType\");\n }\n };\n\n private readonly onMaintenance = (args: IMergeTreeMaintenanceCallbackArgs) => {\n if (args.operation === MergeTreeMaintenanceType.UNLINK) {\n let freed: number[] = [];\n\n for (const { segment } of args.deltaSegments) {\n const asPerm = segment as PermutationSegment;\n if (isHandleValid(asPerm.start)) {\n // Note: Using the spread operator with `.splice()` can exhaust the stack.\n freed = freed.concat(\n new Array(asPerm.cachedLength)\n .fill(0)\n .map((value, index) => index + asPerm.start),\n );\n }\n }\n\n // Notify matrix that handles are about to be freed. The matrix is responsible for clearing\n // the rows/cols prior to free to ensure recycled row/cols are initially empty.\n this.handlesRecycledCallback(freed);\n\n // Now that the physical storage has been cleared, add the recycled handles back to the free pool.\n for (const handle of freed) {\n this.handleTable.free(handle);\n }\n }\n };\n\n public toString() {\n const s: string[] = [];\n\n this.walkSegments((segment) => {\n s.push(`${segment}`);\n return true;\n });\n\n return s.join(\"\");\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"permutationvector.js","sourceRoot":"","sources":["../src/permutationvector.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AACtD,qEAA8D;AAG9D,2DAYoC;AAIpC,iEAA2F;AAC3F,+CAAmE;AACnE,mDAAkD;AAClD,+CAA4C;AAU5C,MAAa,kBAAm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AAC,OAAO,4BAAwB,EAAE,UAAU,CAAC,CAAC;IACvG,CAAC;IA0FM,QAAQ;QACX,MAAM,CAAC,GAAa,EAAE,CAAC;QAEvB,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,EAAE;YAC1B,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,EAAE,CAAC,CAAC;YACrB,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACtB,CAAC;CACJ;AAvQD,8CAuQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { IFluidDataStoreRuntime, IChannelStorageService } from \"@fluidframework/datastore-definitions\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport {\n BaseSegment,\n ISegment,\n LocalReferenceCollection,\n Client,\n IMergeTreeDeltaOpArgs,\n IMergeTreeDeltaCallbackArgs,\n MergeTreeDeltaType,\n IMergeTreeMaintenanceCallbackArgs,\n MergeTreeMaintenanceType,\n LocalReference,\n ReferenceType,\n} from \"@fluidframework/merge-tree\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { HandleTable, Handle, isHandleValid } from \"./handletable\";\nimport { deserializeBlob } from \"./serialization\";\nimport { HandleCache } from \"./handlecache\";\nimport { VectorUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n segments = \"segments\",\n handleTable = \"handleTable\",\n}\n\ntype PermutationSegmentSpec = [number, number];\n\nexport class PermutationSegment extends BaseSegment {\n public static readonly typeString: string = \"PermutationSegment\";\n private _start = Handle.unallocated;\n\n public static fromJSONObject(spec: any) {\n const [length, start] = spec as PermutationSegmentSpec;\n return new PermutationSegment(length, start);\n }\n\n public readonly type = PermutationSegment.typeString;\n\n constructor(length: number, start = Handle.unallocated) {\n super();\n this._start = start;\n this.cachedLength = length;\n }\n\n public get start() { return this._start; }\n public set start(value: Handle) {\n assert(this._start === Handle.unallocated, 0x024 /* \"Start of PermutationSegment already allocated!\" */);\n assert(isHandleValid(value), 0x025 /* \"Trying to set start of PermutationSegment to invalid handle!\" */);\n\n this._start = value;\n }\n\n /**\n * Invoked by '_undoRow/ColRemove' to prepare the newly inserted destination\n * segment to serve as the replacement for this removed segment. This moves handle\n * allocations from this segment to the replacement as well as maintains tracking\n * groups for the undo/redo stack.\n */\n public transferToReplacement(destination: PermutationSegment) {\n // When this segment was removed, it may have been split from a larger original\n // segment. In this case, it will have been added to an undo/redo tracking group\n // that associates all of the fragments from the original insertion.\n //\n // Move this association from the this removed segment to its replacement so that\n // it is included if the undo stack continues to unwind to the original insertion.\n //\n // Out of paranoia we link and unlink in separate loops to avoid mutating the underlying\n // set during enumeration. In practice, this is unlikely to matter since there should be\n // exactly 0 or 1 items in the enumeration.\n for (const group of this.trackingCollection.trackingGroups) {\n group.link(destination);\n }\n for (const group of this.trackingCollection.trackingGroups) {\n group.unlink(this);\n }\n\n // Move handle allocations from this segment to its replacement.\n destination._start = this._start;\n this.reset();\n }\n\n public reset() {\n this._start = Handle.unallocated;\n }\n\n public toJSONObject() {\n return [this.cachedLength, this.start];\n }\n\n public clone(start = 0, end = this.cachedLength) {\n const b = new PermutationSegment(\n /* length: */ end - start,\n /* start: */ this.start + start);\n this.cloneInto(b);\n return b;\n }\n\n public canAppend(segment: ISegment) {\n const asPerm = segment as PermutationSegment;\n\n return this.start === Handle.unallocated\n ? asPerm.start === Handle.unallocated\n : asPerm.start === this.start + this.cachedLength;\n }\n\n public append(segment: ISegment) {\n // Note: Must call 'LocalReferenceCollection.append(..)' before modifying this segment's length as\n // 'this.cachedLength' is used to adjust the offsets of the local refs.\n LocalReferenceCollection.append(this, segment);\n\n this.cachedLength += segment.cachedLength;\n }\n\n protected createSplitSegmentAt(pos: number) {\n assert(0 < pos && pos < this.cachedLength, 0x026 /* \"Trying to split segment at out-of-bounds position!\" */);\n\n const leafSegment = new PermutationSegment(\n /* length: */ this.cachedLength - pos,\n /* start: */ this.start === Handle.unallocated\n ? Handle.unallocated\n : this.start + pos);\n\n this.cachedLength = pos;\n\n return leafSegment;\n }\n\n public toString() {\n return this.start === Handle.unallocated\n ? `<${this.cachedLength} empty>`\n : `<${this.cachedLength}: ${this.start}..${this.start + this.cachedLength - 1}>`;\n }\n}\n\nexport class PermutationVector extends Client {\n private handleTable = new HandleTable<never>(); // Tracks available storage handles for rows.\n public readonly handleCache = new HandleCache(this);\n public undo: VectorUndoProvider | undefined;\n\n constructor(\n path: string,\n logger: ITelemetryBaseLogger,\n runtime: IFluidDataStoreRuntime,\n private readonly deltaCallback: (position: number, numRemoved: number, numInserted: number) => void,\n private readonly handlesRecycledCallback: (handles: Handle[]) => void,\n ) {\n super(\n PermutationSegment.fromJSONObject,\n ChildLogger.create(logger, `Matrix.${path}.MergeTreeClient`), {\n ...runtime.options,\n newMergeTreeSnapshotFormat: true, // Temporarily force new snapshot format until it is the default.\n }); // (See https://github.com/microsoft/FluidFramework/issues/84)\n\n this.mergeTreeDeltaCallback = this.onDelta;\n this.mergeTreeMaintenanceCallback = this.onMaintenance;\n }\n\n public insert(start: number, length: number) {\n return this.insertSegmentLocal(\n start,\n new PermutationSegment(length));\n }\n\n public insertRelative(segment: ISegment, length: number) {\n const inserted = new PermutationSegment(length);\n\n return {\n op: this.insertAtReferencePositionLocal(\n new LocalReference(this, segment, /* offset: */ 0, ReferenceType.Transient),\n inserted),\n inserted,\n };\n }\n\n public remove(start: number, length: number) {\n return this.removeRangeLocal(start, start + length);\n }\n\n public getMaybeHandle(pos: number): Handle {\n assert(0 <= pos && pos < this.getLength(), 0x027 /* \"Trying to get handle of out-of-bounds position!\" */);\n\n return this.handleCache.getHandle(pos);\n }\n\n public getAllocatedHandle(pos: number): Handle {\n let handle = this.getMaybeHandle(pos);\n if (isHandleValid(handle)) {\n return handle;\n }\n\n this.walkSegments(\n (segment) => {\n const asPerm = segment as PermutationSegment;\n asPerm.start = handle = this.handleTable.allocate();\n return true;\n },\n pos,\n pos + 1,\n /* accum: */ undefined,\n /* splitRange: */ true);\n\n this.handleCache.addHandle(pos, handle);\n\n return handle;\n }\n\n public adjustPosition(pos: number, fromSeq: number, clientId: number) {\n const { segment, offset } = this.mergeTree.getContainingSegment(pos, fromSeq, clientId);\n\n // Note that until the MergeTree GCs, the segment is still reachable via `getContainingSegment()` with\n // a `refSeq` in the past. Prevent remote ops from accidentally allocating or using recycled handles\n // by checking for the presence of 'removedSeq'.\n if (segment === undefined || segment.removedSeq !== undefined) {\n return undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.getPosition(segment) + offset!;\n }\n\n public handleToPosition(handle: Handle, localSeq = this.mergeTree.collabWindow.localSeq) {\n assert(localSeq <= this.mergeTree.collabWindow.localSeq,\n 0x028 /* \"'localSeq' for op being resubmitted must be <= the 'localSeq' of the last submitted op.\" */);\n\n // TODO: In theory, the MergeTree should be able to map the (position, refSeq, localSeq) from\n // the original operation to the current position for resubmitting. This is probably the\n // ideal solution, as we would no longer need to store row/col handles in the op metadata.\n //\n // Failing that, we could avoid the O(n) search below by building a temporary map in the\n // opposite direction from the handle to either it's current position or segment + offset\n // and reuse it for the duration of resubmission. (Ideally, we would know when resubmission\n // ended so we could discard this map.)\n //\n // If we find that we frequently need a reverse handle -> position lookup, we could maintain\n // one using the Tiny-Calc adjust tree.\n let containingSegment!: PermutationSegment;\n let containingOffset: number;\n\n this.mergeTree.walkAllSegments(\n this.mergeTree.root,\n (segment) => {\n const { start, cachedLength } = segment as PermutationSegment;\n\n // If the segment is unallocated, skip it.\n if (!isHandleValid(start)) {\n return true;\n }\n\n const end = start + cachedLength;\n\n if (start <= handle && handle < end) {\n containingSegment = segment as PermutationSegment;\n containingOffset = handle - start;\n return false;\n }\n\n return true;\n });\n\n // We are guaranteed to find the handle in the PermutationVector, even if the corresponding\n // row/col has been removed, because handles are not recycled until the containing segment\n // is unlinked from the MergeTree.\n //\n // Therefore, either a row/col removal has been ACKed, in which case there will be no pending\n // ops that reference the stale handle, or the removal is unACKed, in which case the handle\n // has not yet been recycled.\n\n assert(isHandleValid(containingSegment.start), 0x029 /* \"Invalid handle at start of containing segment!\" */);\n\n // Once we know the current position of the handle, we can use the MergeTree to get the segment\n // containing this position and use 'findReconnectionPosition' to adjust for the local ops that\n // have not yet been submitted.\n\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.findReconnectionPosition(containingSegment, localSeq) + containingOffset!;\n }\n\n // Constructs an ISummaryTreeWithStats for the cell data.\n public summarize(runtime: IFluidDataStoreRuntime, handle: IFluidHandle, serializer: IFluidSerializer):\n ISummaryTreeWithStats {\n const builder = new SummaryTreeBuilder();\n builder.addWithStats(SnapshotPath.segments, super.summarize(runtime, handle, serializer, /* catchUpMsgs: */[]));\n builder.addBlob(SnapshotPath.handleTable, serializer.stringify(this.handleTable.getSummaryContent(), handle));\n return builder.getSummaryTree();\n }\n\n public async load(\n runtime: IFluidDataStoreRuntime,\n storage: IChannelStorageService,\n serializer: IFluidSerializer,\n ) {\n const handleTableData = await deserializeBlob(storage, SnapshotPath.handleTable, serializer);\n\n this.handleTable = HandleTable.load<never>(handleTableData);\n\n return super.load(runtime, new ObjectStoragePartition(storage, SnapshotPath.segments), serializer);\n }\n\n private readonly onDelta = (\n opArgs: IMergeTreeDeltaOpArgs,\n { operation, deltaSegments }: IMergeTreeDeltaCallbackArgs,\n ) => {\n // Apply deltas in descending order to prevent positions from shifting.\n const ranges = deltaSegments\n .map(({ segment }) => ({\n segment: segment as PermutationSegment,\n position: this.getPosition(segment),\n }))\n .sort((left, right) => left.position - right.position);\n\n const isLocal = opArgs.sequencedMessage === undefined;\n\n // Notify the undo provider, if any is attached.\n if (this.undo !== undefined && isLocal) {\n this.undo.record(operation, ranges);\n }\n\n switch (operation) {\n case MergeTreeDeltaType.INSERT:\n // Pass 1: Perform any internal maintenance first to avoid reentrancy.\n for (const { segment, position } of ranges) {\n // HACK: We need to include the allocated handle in the segment's JSON representation\n // for snapshots, but need to ignore the remote client's handle allocations when\n // processing remote ops.\n segment.reset();\n\n this.handleCache.itemsChanged(\n position,\n /* deleteCount: */ 0,\n /* insertCount: */ segment.cachedLength);\n }\n\n // Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n for (const { segment, position } of ranges) {\n this.deltaCallback(position, /* numRemoved: */ 0, /* numInserted: */ segment.cachedLength);\n }\n break;\n\n case MergeTreeDeltaType.REMOVE: {\n // Pass 1: Perform any internal maintenance first to avoid reentrancy.\n for (const { segment, position } of ranges) {\n this.handleCache.itemsChanged(\n position, /* deleteCount: */\n segment.cachedLength,\n /* insertCount: */ 0);\n }\n\n // Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n for (const { segment, position } of ranges) {\n this.deltaCallback(position, /* numRemoved: */ segment.cachedLength, /* numInsert: */ 0);\n }\n break;\n }\n\n default:\n throw new Error(\"Unhandled MergeTreeDeltaType\");\n }\n };\n\n private readonly onMaintenance = (args: IMergeTreeMaintenanceCallbackArgs) => {\n if (args.operation === MergeTreeMaintenanceType.UNLINK) {\n let freed: number[] = [];\n\n for (const { segment } of args.deltaSegments) {\n const asPerm = segment as PermutationSegment;\n if (isHandleValid(asPerm.start)) {\n // Note: Using the spread operator with `.splice()` can exhaust the stack.\n freed = freed.concat(\n new Array(asPerm.cachedLength)\n .fill(0)\n .map((value, index) => index + asPerm.start),\n );\n }\n }\n\n // Notify matrix that handles are about to be freed. The matrix is responsible for clearing\n // the rows/cols prior to free to ensure recycled row/cols are initially empty.\n this.handlesRecycledCallback(freed);\n\n // Now that the physical storage has been cleared, add the recycled handles back to the free pool.\n for (const handle of freed) {\n this.handleTable.free(handle);\n }\n }\n };\n\n public toString() {\n const s: string[] = [];\n\n this.walkSegments((segment) => {\n s.push(`${segment}`);\n return true;\n });\n\n return s.join(\"\");\n }\n}\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/matrix";
|
|
8
|
-
export declare const pkgVersion = "0.
|
|
8
|
+
export declare const pkgVersion = "0.58.0-55983";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,2BAA2B,CAAC;AAChD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,2BAA2B,CAAC;AAChD,eAAO,MAAM,UAAU,iBAAiB,CAAC"}
|
package/lib/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,wBAAwB,CAAC;AAChD,MAAM,CAAC,MAAM,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,wBAAwB,CAAC;AAChD,MAAM,CAAC,MAAM,UAAU,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/matrix\";\nexport const pkgVersion = \"0.58.0-55983\";\n"]}
|
package/lib/permutationvector.js
CHANGED
|
@@ -42,7 +42,7 @@ export class PermutationSegment extends BaseSegment {
|
|
|
42
42
|
// it is included if the undo stack continues to unwind to the original insertion.
|
|
43
43
|
//
|
|
44
44
|
// Out of paranoia we link and unlink in separate loops to avoid mutating the underlying
|
|
45
|
-
// set during enumeration. In
|
|
45
|
+
// set during enumeration. In practice, this is unlikely to matter since there should be
|
|
46
46
|
// exactly 0 or 1 items in the enumeration.
|
|
47
47
|
for (const group of this.trackingCollection.trackingGroups) {
|
|
48
48
|
group.link(destination);
|
|
@@ -120,7 +120,7 @@ export class PermutationVector extends Client {
|
|
|
120
120
|
case 0 /* INSERT */:
|
|
121
121
|
// Pass 1: Perform any internal maintenance first to avoid reentrancy.
|
|
122
122
|
for (const { segment, position } of ranges) {
|
|
123
|
-
// HACK: We need to include the allocated handle in the segment's JSON
|
|
123
|
+
// HACK: We need to include the allocated handle in the segment's JSON representation
|
|
124
124
|
// for snapshots, but need to ignore the remote client's handle allocations when
|
|
125
125
|
// processing remote ops.
|
|
126
126
|
segment.reset();
|
|
@@ -256,9 +256,8 @@ export class PermutationVector extends Client {
|
|
|
256
256
|
// Once we know the current position of the handle, we can use the MergeTree to get the segment
|
|
257
257
|
// containing this position and use 'findReconnectionPosition' to adjust for the local ops that
|
|
258
258
|
// have not yet been submitted.
|
|
259
|
-
// eslint-disable-next-line
|
|
260
|
-
|
|
261
|
-
return this.findReconnectionPostition(containingSegment, localSeq) + containingOffset;
|
|
259
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
260
|
+
return this.findReconnectionPosition(containingSegment, localSeq) + containingOffset;
|
|
262
261
|
}
|
|
263
262
|
// Constructs an ISummaryTreeWithStats for the cell data.
|
|
264
263
|
summarize(runtime, handle, serializer) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permutationvector.js","sourceRoot":"","sources":["../src/permutationvector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAG9D,OAAO,EACH,WAAW,EAEX,wBAAwB,EACxB,MAAM,EAMN,cAAc,EACd,aAAa,GAChB,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,EAAE,WAAW,EAAU,aAAa,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAU5C,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IAW/C,YAAY,MAAc,EAAE,KAAK,gCAAqB;QAClD,KAAK,EAAE,CAAC;QAVJ,WAAM,iCAAsB;QAOpB,SAAI,GAAG,kBAAkB,CAAC,UAAU,CAAC;QAIjD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;IAC/B,CAAC;IAXM,MAAM,CAAC,cAAc,CAAC,IAAS;QAClC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAA8B,CAAC;QACvD,OAAO,IAAI,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACjD,CAAC;IAUD,IAAW,KAAK,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1C,IAAW,KAAK,CAAC,KAAa;QAC1B,MAAM,CAAC,IAAI,CAAC,MAAM,kCAAuB,EAAE,KAAK,CAAC,sDAAsD,CAAC,CAAC;QACzG,MAAM,CAAC,aAAa,CAAC,KAAK,CAA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YAAY,4BAAwB,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,CAAA,EAAE,CAAC,CAAC,CAAC;QAChH,OAAO,CAAC,OAAO,kCAA2B,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,iBAAiB,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;QAC9G,OAAO,OAAO,CAAC,cAAc,EAAE,CAAC;IACpC,CAAC;IAEM,KAAK,CAAC,IAAI,CACb,OAA+B,EAC/B,OAA+B,EAC/B,UAA4B;QAE5B,MAAM,eAAe,GAAG,MAAM,eAAe,CAAC,OAAO,mCAA4B,UAAU,CAAC,CAAC;QAE7F,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC,IAAI,CAAQ,eAAe,CAAC,CAAC;QAE5D,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,sBAAsB,CAAC,OAAO,4BAAwB,EAAE,UAAU,CAAC,CAAC;IACvG,CAAC;IA0FM,QAAQ;QACX,MAAM,CAAC,GAAa,EAAE,CAAC;QAEvB,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,EAAE;YAC1B,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,EAAE,CAAC,CAAC;YACrB,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACtB,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { IFluidDataStoreRuntime, IChannelStorageService } from \"@fluidframework/datastore-definitions\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport {\n BaseSegment,\n ISegment,\n LocalReferenceCollection,\n Client,\n IMergeTreeDeltaOpArgs,\n IMergeTreeDeltaCallbackArgs,\n MergeTreeDeltaType,\n IMergeTreeMaintenanceCallbackArgs,\n MergeTreeMaintenanceType,\n LocalReference,\n ReferenceType,\n} from \"@fluidframework/merge-tree\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { HandleTable, Handle, isHandleValid } from \"./handletable\";\nimport { deserializeBlob } from \"./serialization\";\nimport { HandleCache } from \"./handlecache\";\nimport { VectorUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n segments = \"segments\",\n handleTable = \"handleTable\",\n}\n\ntype PermutationSegmentSpec = [number, number];\n\nexport class PermutationSegment extends BaseSegment {\n public static readonly typeString: string = \"PermutationSegment\";\n private _start = Handle.unallocated;\n\n public static fromJSONObject(spec: any) {\n const [length, start] = spec as PermutationSegmentSpec;\n return new PermutationSegment(length, start);\n }\n\n public readonly type = PermutationSegment.typeString;\n\n constructor(length: number, start = Handle.unallocated) {\n super();\n this._start = start;\n this.cachedLength = length;\n }\n\n public get start() { return this._start; }\n public set start(value: Handle) {\n assert(this._start === Handle.unallocated, 0x024 /* \"Start of PermutationSegment already allocated!\" */);\n assert(isHandleValid(value), 0x025 /* \"Trying to set start of PermutationSegment to invalid handle!\" */);\n\n this._start = value;\n }\n\n /**\n * Invoked by '_undoRow/ColRemove' to prepare the newly inserted destination\n * segment to serve as the replacement for this removed segment. This moves handle\n * allocations from this segment to the replacement as well as maintains tracking\n * groups for the undo/redo stack.\n */\n public transferToReplacement(destination: PermutationSegment) {\n // When this segment was removed, it may have been split from a larger original\n // segment. In this case, it will have been added to an undo/redo tracking group\n // that associates all of the fragments from the original insertion.\n //\n // Move this association from the this removed segment to its replacement so that\n // it is included if the undo stack continues to unwind to the original insertion.\n //\n // Out of paranoia we link and unlink in separate loops to avoid mutating the underlying\n // set during enumeration. In pratice, this is unlikely to matter since there should be\n // exactly 0 or 1 items in the enumeration.\n for (const group of this.trackingCollection.trackingGroups) {\n group.link(destination);\n }\n for (const group of this.trackingCollection.trackingGroups) {\n group.unlink(this);\n }\n\n // Move handle allocations from this segment to its replacement.\n destination._start = this._start;\n this.reset();\n }\n\n public reset() {\n this._start = Handle.unallocated;\n }\n\n public toJSONObject() {\n return [this.cachedLength, this.start];\n }\n\n public clone(start = 0, end = this.cachedLength) {\n const b = new PermutationSegment(\n /* length: */ end - start,\n /* start: */ this.start + start);\n this.cloneInto(b);\n return b;\n }\n\n public canAppend(segment: ISegment) {\n const asPerm = segment as PermutationSegment;\n\n return this.start === Handle.unallocated\n ? asPerm.start === Handle.unallocated\n : asPerm.start === this.start + this.cachedLength;\n }\n\n public append(segment: ISegment) {\n // Note: Must call 'LocalReferenceCollection.append(..)' before modifying this segment's length as\n // 'this.cachedLength' is used to adjust the offsets of the local refs.\n LocalReferenceCollection.append(this, segment);\n\n this.cachedLength += segment.cachedLength;\n }\n\n protected createSplitSegmentAt(pos: number) {\n assert(0 < pos && pos < this.cachedLength, 0x026 /* \"Trying to split segment at out-of-bounds position!\" */);\n\n const leafSegment = new PermutationSegment(\n /* length: */ this.cachedLength - pos,\n /* start: */ this.start === Handle.unallocated\n ? Handle.unallocated\n : this.start + pos);\n\n this.cachedLength = pos;\n\n return leafSegment;\n }\n\n public toString() {\n return this.start === Handle.unallocated\n ? `<${this.cachedLength} empty>`\n : `<${this.cachedLength}: ${this.start}..${this.start + this.cachedLength - 1}>`;\n }\n}\n\nexport class PermutationVector extends Client {\n private handleTable = new HandleTable<never>(); // Tracks available storage handles for rows.\n public readonly handleCache = new HandleCache(this);\n public undo: VectorUndoProvider | undefined;\n\n constructor(\n path: string,\n logger: ITelemetryBaseLogger,\n runtime: IFluidDataStoreRuntime,\n private readonly deltaCallback: (position: number, numRemoved: number, numInserted: number) => void,\n private readonly handlesRecycledCallback: (handles: Handle[]) => void,\n ) {\n super(\n PermutationSegment.fromJSONObject,\n ChildLogger.create(logger, `Matrix.${path}.MergeTreeClient`), {\n ...runtime.options,\n newMergeTreeSnapshotFormat: true, // Temporarily force new snapshot format until it is the default.\n }); // (See https://github.com/microsoft/FluidFramework/issues/84)\n\n this.mergeTreeDeltaCallback = this.onDelta;\n this.mergeTreeMaintenanceCallback = this.onMaintenance;\n }\n\n public insert(start: number, length: number) {\n return this.insertSegmentLocal(\n start,\n new PermutationSegment(length));\n }\n\n public insertRelative(segment: ISegment, length: number) {\n const inserted = new PermutationSegment(length);\n\n return {\n op: this.insertAtReferencePositionLocal(\n new LocalReference(this, segment, /* offset: */ 0, ReferenceType.Transient),\n inserted),\n inserted,\n };\n }\n\n public remove(start: number, length: number) {\n return this.removeRangeLocal(start, start + length);\n }\n\n public getMaybeHandle(pos: number): Handle {\n assert(0 <= pos && pos < this.getLength(), 0x027 /* \"Trying to get handle of out-of-bounds position!\" */);\n\n return this.handleCache.getHandle(pos);\n }\n\n public getAllocatedHandle(pos: number): Handle {\n let handle = this.getMaybeHandle(pos);\n if (isHandleValid(handle)) {\n return handle;\n }\n\n this.walkSegments(\n (segment) => {\n const asPerm = segment as PermutationSegment;\n asPerm.start = handle = this.handleTable.allocate();\n return true;\n },\n pos,\n pos + 1,\n /* accum: */ undefined,\n /* splitRange: */ true);\n\n this.handleCache.addHandle(pos, handle);\n\n return handle;\n }\n\n public adjustPosition(pos: number, fromSeq: number, clientId: number) {\n const { segment, offset } = this.mergeTree.getContainingSegment(pos, fromSeq, clientId);\n\n // Note that until the MergeTree GCs, the segment is still reachable via `getContainingSegment()` with\n // a `refSeq` in the past. Prevent remote ops from accidentally allocating or using recycled handles\n // by checking for the presence of 'removedSeq'.\n if (segment === undefined || segment.removedSeq !== undefined) {\n return undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.getPosition(segment) + offset!;\n }\n\n public handleToPosition(handle: Handle, localSeq = this.mergeTree.collabWindow.localSeq) {\n assert(localSeq <= this.mergeTree.collabWindow.localSeq,\n 0x028 /* \"'localSeq' for op being resubmitted must be <= the 'localSeq' of the last submitted op.\" */);\n\n // TODO: In theory, the MergeTree should be able to map the (position, refSeq, localSeq) from\n // the original operation to the current position for resubmitting. This is probably the\n // ideal solution, as we would no longer need to store row/col handles in the op metadata.\n //\n // Failing that, we could avoid the O(n) search below by building a temporary map in the\n // opposite direction from the handle to either it's current position or segment + offset\n // and reuse it for the duration of resubmission. (Ideally, we would know when resubmission\n // ended so we could discard this map.)\n //\n // If we find that we frequently need a reverse handle -> position lookup, we could maintain\n // one using the Tiny-Calc adjust tree.\n let containingSegment!: PermutationSegment;\n let containingOffset: number;\n\n this.mergeTree.walkAllSegments(\n this.mergeTree.root,\n (segment) => {\n const { start, cachedLength } = segment as PermutationSegment;\n\n // If the segment is unallocated, skip it.\n if (!isHandleValid(start)) {\n return true;\n }\n\n const end = start + cachedLength;\n\n if (start <= handle && handle < end) {\n containingSegment = segment as PermutationSegment;\n containingOffset = handle - start;\n return false;\n }\n\n return true;\n });\n\n // We are guaranteed to find the handle in the PermutationVector, even if the corresponding\n // row/col has been removed, because handles are not recycled until the containing segment\n // is unlinked from the MergeTree.\n //\n // Therefore, either a row/col removal has been ACKed, in which case there will be no pending\n // ops that reference the stale handle, or the removal is unACKed, in which case the handle\n // has not yet been recycled.\n\n assert(isHandleValid(containingSegment.start), 0x029 /* \"Invalid handle at start of containing segment!\" */);\n\n // Once we know the current position of the handle, we can use the MergeTree to get the segment\n // containing this position and use 'findReconnectionPosition' to adjust for the local ops that\n // have not yet been submitted.\n\n // eslint-disable-next-line max-len\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion\n return this.findReconnectionPostition(containingSegment, localSeq) + containingOffset!;\n }\n\n // Constructs an ISummaryTreeWithStats for the cell data.\n public summarize(runtime: IFluidDataStoreRuntime, handle: IFluidHandle, serializer: IFluidSerializer):\n ISummaryTreeWithStats {\n const builder = new SummaryTreeBuilder();\n builder.addWithStats(SnapshotPath.segments, super.summarize(runtime, handle, serializer, /* catchUpMsgs: */[]));\n builder.addBlob(SnapshotPath.handleTable, serializer.stringify(this.handleTable.getSummaryContent(), handle));\n return builder.getSummaryTree();\n }\n\n public async load(\n runtime: IFluidDataStoreRuntime,\n storage: IChannelStorageService,\n serializer: IFluidSerializer,\n ) {\n const handleTableData = await deserializeBlob(storage, SnapshotPath.handleTable, serializer);\n\n this.handleTable = HandleTable.load<never>(handleTableData);\n\n return super.load(runtime, new ObjectStoragePartition(storage, SnapshotPath.segments), serializer);\n }\n\n private readonly onDelta = (\n opArgs: IMergeTreeDeltaOpArgs,\n { operation, deltaSegments }: IMergeTreeDeltaCallbackArgs,\n ) => {\n // Apply deltas in descending order to prevent positions from shifting.\n const ranges = deltaSegments\n .map(({ segment }) => ({\n segment: segment as PermutationSegment,\n position: this.getPosition(segment),\n }))\n .sort((left, right) => left.position - right.position);\n\n const isLocal = opArgs.sequencedMessage === undefined;\n\n // Notify the undo provider, if any is attached.\n if (this.undo !== undefined && isLocal) {\n this.undo.record(operation, ranges);\n }\n\n switch (operation) {\n case MergeTreeDeltaType.INSERT:\n // Pass 1: Perform any internal maintenance first to avoid reentrancy.\n for (const { segment, position } of ranges) {\n // HACK: We need to include the allocated handle in the segment's JSON reperesntation\n // for snapshots, but need to ignore the remote client's handle allocations when\n // processing remote ops.\n segment.reset();\n\n this.handleCache.itemsChanged(\n position,\n /* deleteCount: */ 0,\n /* insertCount: */ segment.cachedLength);\n }\n\n // Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n for (const { segment, position } of ranges) {\n this.deltaCallback(position, /* numRemoved: */ 0, /* numInserted: */ segment.cachedLength);\n }\n break;\n\n case MergeTreeDeltaType.REMOVE: {\n // Pass 1: Perform any internal maintenance first to avoid reentrancy.\n for (const { segment, position } of ranges) {\n this.handleCache.itemsChanged(\n position, /* deleteCount: */\n segment.cachedLength,\n /* insertCount: */ 0);\n }\n\n // Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n for (const { segment, position } of ranges) {\n this.deltaCallback(position, /* numRemoved: */ segment.cachedLength, /* numInsert: */ 0);\n }\n break;\n }\n\n default:\n throw new Error(\"Unhandled MergeTreeDeltaType\");\n }\n };\n\n private readonly onMaintenance = (args: IMergeTreeMaintenanceCallbackArgs) => {\n if (args.operation === MergeTreeMaintenanceType.UNLINK) {\n let freed: number[] = [];\n\n for (const { segment } of args.deltaSegments) {\n const asPerm = segment as PermutationSegment;\n if (isHandleValid(asPerm.start)) {\n // Note: Using the spread operator with `.splice()` can exhaust the stack.\n freed = freed.concat(\n new Array(asPerm.cachedLength)\n .fill(0)\n .map((value, index) => index + asPerm.start),\n );\n }\n }\n\n // Notify matrix that handles are about to be freed. The matrix is responsible for clearing\n // the rows/cols prior to free to ensure recycled row/cols are initially empty.\n this.handlesRecycledCallback(freed);\n\n // Now that the physical storage has been cleared, add the recycled handles back to the free pool.\n for (const handle of freed) {\n this.handleTable.free(handle);\n }\n }\n };\n\n public toString() {\n const s: string[] = [];\n\n this.walkSegments((segment) => {\n s.push(`${segment}`);\n return true;\n });\n\n return s.join(\"\");\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"permutationvector.js","sourceRoot":"","sources":["../src/permutationvector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAG9D,OAAO,EACH,WAAW,EAEX,wBAAwB,EACxB,MAAM,EAMN,cAAc,EACd,aAAa,GAChB,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,EAAE,WAAW,EAAU,aAAa,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,WAAW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,IAAI,sBAAsB,CAAC,OAAO,4BAAwB,EAAE,UAAU,CAAC,CAAC;IACvG,CAAC;IA0FM,QAAQ;QACX,MAAM,CAAC,GAAa,EAAE,CAAC;QAEvB,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,EAAE;YAC1B,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,EAAE,CAAC,CAAC;YACrB,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACtB,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { IFluidDataStoreRuntime, IChannelStorageService } from \"@fluidframework/datastore-definitions\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/common-definitions\";\nimport {\n BaseSegment,\n ISegment,\n LocalReferenceCollection,\n Client,\n IMergeTreeDeltaOpArgs,\n IMergeTreeDeltaCallbackArgs,\n MergeTreeDeltaType,\n IMergeTreeMaintenanceCallbackArgs,\n MergeTreeMaintenanceType,\n LocalReference,\n ReferenceType,\n} from \"@fluidframework/merge-tree\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ObjectStoragePartition, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { HandleTable, Handle, isHandleValid } from \"./handletable\";\nimport { deserializeBlob } from \"./serialization\";\nimport { HandleCache } from \"./handlecache\";\nimport { VectorUndoProvider } from \"./undoprovider\";\n\nconst enum SnapshotPath {\n segments = \"segments\",\n handleTable = \"handleTable\",\n}\n\ntype PermutationSegmentSpec = [number, number];\n\nexport class PermutationSegment extends BaseSegment {\n public static readonly typeString: string = \"PermutationSegment\";\n private _start = Handle.unallocated;\n\n public static fromJSONObject(spec: any) {\n const [length, start] = spec as PermutationSegmentSpec;\n return new PermutationSegment(length, start);\n }\n\n public readonly type = PermutationSegment.typeString;\n\n constructor(length: number, start = Handle.unallocated) {\n super();\n this._start = start;\n this.cachedLength = length;\n }\n\n public get start() { return this._start; }\n public set start(value: Handle) {\n assert(this._start === Handle.unallocated, 0x024 /* \"Start of PermutationSegment already allocated!\" */);\n assert(isHandleValid(value), 0x025 /* \"Trying to set start of PermutationSegment to invalid handle!\" */);\n\n this._start = value;\n }\n\n /**\n * Invoked by '_undoRow/ColRemove' to prepare the newly inserted destination\n * segment to serve as the replacement for this removed segment. This moves handle\n * allocations from this segment to the replacement as well as maintains tracking\n * groups for the undo/redo stack.\n */\n public transferToReplacement(destination: PermutationSegment) {\n // When this segment was removed, it may have been split from a larger original\n // segment. In this case, it will have been added to an undo/redo tracking group\n // that associates all of the fragments from the original insertion.\n //\n // Move this association from the this removed segment to its replacement so that\n // it is included if the undo stack continues to unwind to the original insertion.\n //\n // Out of paranoia we link and unlink in separate loops to avoid mutating the underlying\n // set during enumeration. In practice, this is unlikely to matter since there should be\n // exactly 0 or 1 items in the enumeration.\n for (const group of this.trackingCollection.trackingGroups) {\n group.link(destination);\n }\n for (const group of this.trackingCollection.trackingGroups) {\n group.unlink(this);\n }\n\n // Move handle allocations from this segment to its replacement.\n destination._start = this._start;\n this.reset();\n }\n\n public reset() {\n this._start = Handle.unallocated;\n }\n\n public toJSONObject() {\n return [this.cachedLength, this.start];\n }\n\n public clone(start = 0, end = this.cachedLength) {\n const b = new PermutationSegment(\n /* length: */ end - start,\n /* start: */ this.start + start);\n this.cloneInto(b);\n return b;\n }\n\n public canAppend(segment: ISegment) {\n const asPerm = segment as PermutationSegment;\n\n return this.start === Handle.unallocated\n ? asPerm.start === Handle.unallocated\n : asPerm.start === this.start + this.cachedLength;\n }\n\n public append(segment: ISegment) {\n // Note: Must call 'LocalReferenceCollection.append(..)' before modifying this segment's length as\n // 'this.cachedLength' is used to adjust the offsets of the local refs.\n LocalReferenceCollection.append(this, segment);\n\n this.cachedLength += segment.cachedLength;\n }\n\n protected createSplitSegmentAt(pos: number) {\n assert(0 < pos && pos < this.cachedLength, 0x026 /* \"Trying to split segment at out-of-bounds position!\" */);\n\n const leafSegment = new PermutationSegment(\n /* length: */ this.cachedLength - pos,\n /* start: */ this.start === Handle.unallocated\n ? Handle.unallocated\n : this.start + pos);\n\n this.cachedLength = pos;\n\n return leafSegment;\n }\n\n public toString() {\n return this.start === Handle.unallocated\n ? `<${this.cachedLength} empty>`\n : `<${this.cachedLength}: ${this.start}..${this.start + this.cachedLength - 1}>`;\n }\n}\n\nexport class PermutationVector extends Client {\n private handleTable = new HandleTable<never>(); // Tracks available storage handles for rows.\n public readonly handleCache = new HandleCache(this);\n public undo: VectorUndoProvider | undefined;\n\n constructor(\n path: string,\n logger: ITelemetryBaseLogger,\n runtime: IFluidDataStoreRuntime,\n private readonly deltaCallback: (position: number, numRemoved: number, numInserted: number) => void,\n private readonly handlesRecycledCallback: (handles: Handle[]) => void,\n ) {\n super(\n PermutationSegment.fromJSONObject,\n ChildLogger.create(logger, `Matrix.${path}.MergeTreeClient`), {\n ...runtime.options,\n newMergeTreeSnapshotFormat: true, // Temporarily force new snapshot format until it is the default.\n }); // (See https://github.com/microsoft/FluidFramework/issues/84)\n\n this.mergeTreeDeltaCallback = this.onDelta;\n this.mergeTreeMaintenanceCallback = this.onMaintenance;\n }\n\n public insert(start: number, length: number) {\n return this.insertSegmentLocal(\n start,\n new PermutationSegment(length));\n }\n\n public insertRelative(segment: ISegment, length: number) {\n const inserted = new PermutationSegment(length);\n\n return {\n op: this.insertAtReferencePositionLocal(\n new LocalReference(this, segment, /* offset: */ 0, ReferenceType.Transient),\n inserted),\n inserted,\n };\n }\n\n public remove(start: number, length: number) {\n return this.removeRangeLocal(start, start + length);\n }\n\n public getMaybeHandle(pos: number): Handle {\n assert(0 <= pos && pos < this.getLength(), 0x027 /* \"Trying to get handle of out-of-bounds position!\" */);\n\n return this.handleCache.getHandle(pos);\n }\n\n public getAllocatedHandle(pos: number): Handle {\n let handle = this.getMaybeHandle(pos);\n if (isHandleValid(handle)) {\n return handle;\n }\n\n this.walkSegments(\n (segment) => {\n const asPerm = segment as PermutationSegment;\n asPerm.start = handle = this.handleTable.allocate();\n return true;\n },\n pos,\n pos + 1,\n /* accum: */ undefined,\n /* splitRange: */ true);\n\n this.handleCache.addHandle(pos, handle);\n\n return handle;\n }\n\n public adjustPosition(pos: number, fromSeq: number, clientId: number) {\n const { segment, offset } = this.mergeTree.getContainingSegment(pos, fromSeq, clientId);\n\n // Note that until the MergeTree GCs, the segment is still reachable via `getContainingSegment()` with\n // a `refSeq` in the past. Prevent remote ops from accidentally allocating or using recycled handles\n // by checking for the presence of 'removedSeq'.\n if (segment === undefined || segment.removedSeq !== undefined) {\n return undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.getPosition(segment) + offset!;\n }\n\n public handleToPosition(handle: Handle, localSeq = this.mergeTree.collabWindow.localSeq) {\n assert(localSeq <= this.mergeTree.collabWindow.localSeq,\n 0x028 /* \"'localSeq' for op being resubmitted must be <= the 'localSeq' of the last submitted op.\" */);\n\n // TODO: In theory, the MergeTree should be able to map the (position, refSeq, localSeq) from\n // the original operation to the current position for resubmitting. This is probably the\n // ideal solution, as we would no longer need to store row/col handles in the op metadata.\n //\n // Failing that, we could avoid the O(n) search below by building a temporary map in the\n // opposite direction from the handle to either it's current position or segment + offset\n // and reuse it for the duration of resubmission. (Ideally, we would know when resubmission\n // ended so we could discard this map.)\n //\n // If we find that we frequently need a reverse handle -> position lookup, we could maintain\n // one using the Tiny-Calc adjust tree.\n let containingSegment!: PermutationSegment;\n let containingOffset: number;\n\n this.mergeTree.walkAllSegments(\n this.mergeTree.root,\n (segment) => {\n const { start, cachedLength } = segment as PermutationSegment;\n\n // If the segment is unallocated, skip it.\n if (!isHandleValid(start)) {\n return true;\n }\n\n const end = start + cachedLength;\n\n if (start <= handle && handle < end) {\n containingSegment = segment as PermutationSegment;\n containingOffset = handle - start;\n return false;\n }\n\n return true;\n });\n\n // We are guaranteed to find the handle in the PermutationVector, even if the corresponding\n // row/col has been removed, because handles are not recycled until the containing segment\n // is unlinked from the MergeTree.\n //\n // Therefore, either a row/col removal has been ACKed, in which case there will be no pending\n // ops that reference the stale handle, or the removal is unACKed, in which case the handle\n // has not yet been recycled.\n\n assert(isHandleValid(containingSegment.start), 0x029 /* \"Invalid handle at start of containing segment!\" */);\n\n // Once we know the current position of the handle, we can use the MergeTree to get the segment\n // containing this position and use 'findReconnectionPosition' to adjust for the local ops that\n // have not yet been submitted.\n\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.findReconnectionPosition(containingSegment, localSeq) + containingOffset!;\n }\n\n // Constructs an ISummaryTreeWithStats for the cell data.\n public summarize(runtime: IFluidDataStoreRuntime, handle: IFluidHandle, serializer: IFluidSerializer):\n ISummaryTreeWithStats {\n const builder = new SummaryTreeBuilder();\n builder.addWithStats(SnapshotPath.segments, super.summarize(runtime, handle, serializer, /* catchUpMsgs: */[]));\n builder.addBlob(SnapshotPath.handleTable, serializer.stringify(this.handleTable.getSummaryContent(), handle));\n return builder.getSummaryTree();\n }\n\n public async load(\n runtime: IFluidDataStoreRuntime,\n storage: IChannelStorageService,\n serializer: IFluidSerializer,\n ) {\n const handleTableData = await deserializeBlob(storage, SnapshotPath.handleTable, serializer);\n\n this.handleTable = HandleTable.load<never>(handleTableData);\n\n return super.load(runtime, new ObjectStoragePartition(storage, SnapshotPath.segments), serializer);\n }\n\n private readonly onDelta = (\n opArgs: IMergeTreeDeltaOpArgs,\n { operation, deltaSegments }: IMergeTreeDeltaCallbackArgs,\n ) => {\n // Apply deltas in descending order to prevent positions from shifting.\n const ranges = deltaSegments\n .map(({ segment }) => ({\n segment: segment as PermutationSegment,\n position: this.getPosition(segment),\n }))\n .sort((left, right) => left.position - right.position);\n\n const isLocal = opArgs.sequencedMessage === undefined;\n\n // Notify the undo provider, if any is attached.\n if (this.undo !== undefined && isLocal) {\n this.undo.record(operation, ranges);\n }\n\n switch (operation) {\n case MergeTreeDeltaType.INSERT:\n // Pass 1: Perform any internal maintenance first to avoid reentrancy.\n for (const { segment, position } of ranges) {\n // HACK: We need to include the allocated handle in the segment's JSON representation\n // for snapshots, but need to ignore the remote client's handle allocations when\n // processing remote ops.\n segment.reset();\n\n this.handleCache.itemsChanged(\n position,\n /* deleteCount: */ 0,\n /* insertCount: */ segment.cachedLength);\n }\n\n // Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n for (const { segment, position } of ranges) {\n this.deltaCallback(position, /* numRemoved: */ 0, /* numInserted: */ segment.cachedLength);\n }\n break;\n\n case MergeTreeDeltaType.REMOVE: {\n // Pass 1: Perform any internal maintenance first to avoid reentrancy.\n for (const { segment, position } of ranges) {\n this.handleCache.itemsChanged(\n position, /* deleteCount: */\n segment.cachedLength,\n /* insertCount: */ 0);\n }\n\n // Pass 2: Notify the 'deltaCallback', which may involve callbacks into user code.\n for (const { segment, position } of ranges) {\n this.deltaCallback(position, /* numRemoved: */ segment.cachedLength, /* numInsert: */ 0);\n }\n break;\n }\n\n default:\n throw new Error(\"Unhandled MergeTreeDeltaType\");\n }\n };\n\n private readonly onMaintenance = (args: IMergeTreeMaintenanceCallbackArgs) => {\n if (args.operation === MergeTreeMaintenanceType.UNLINK) {\n let freed: number[] = [];\n\n for (const { segment } of args.deltaSegments) {\n const asPerm = segment as PermutationSegment;\n if (isHandleValid(asPerm.start)) {\n // Note: Using the spread operator with `.splice()` can exhaust the stack.\n freed = freed.concat(\n new Array(asPerm.cachedLength)\n .fill(0)\n .map((value, index) => index + asPerm.start),\n );\n }\n }\n\n // Notify matrix that handles are about to be freed. The matrix is responsible for clearing\n // the rows/cols prior to free to ensure recycled row/cols are initially empty.\n this.handlesRecycledCallback(freed);\n\n // Now that the physical storage has been cleared, add the recycled handles back to the free pool.\n for (const handle of freed) {\n this.handleTable.free(handle);\n }\n }\n };\n\n public toString() {\n const s: string[] = [];\n\n this.walkSegments((segment) => {\n s.push(`${segment}`);\n return true;\n });\n\n return s.join(\"\");\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/matrix",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.0-55983",
|
|
4
4
|
"description": "Distributed matrix",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": "https://github.com/microsoft/FluidFramework",
|
|
@@ -57,23 +57,23 @@
|
|
|
57
57
|
"@fluidframework/common-definitions": "^0.20.1",
|
|
58
58
|
"@fluidframework/common-utils": "^0.32.1",
|
|
59
59
|
"@fluidframework/core-interfaces": "^0.42.0",
|
|
60
|
-
"@fluidframework/datastore-definitions": "
|
|
61
|
-
"@fluidframework/merge-tree": "
|
|
62
|
-
"@fluidframework/protocol-base": "^0.
|
|
63
|
-
"@fluidframework/protocol-definitions": "^0.
|
|
64
|
-
"@fluidframework/runtime-definitions": "
|
|
65
|
-
"@fluidframework/runtime-utils": "
|
|
66
|
-
"@fluidframework/shared-object-base": "
|
|
67
|
-
"@fluidframework/telemetry-utils": "
|
|
60
|
+
"@fluidframework/datastore-definitions": "0.58.0-55983",
|
|
61
|
+
"@fluidframework/merge-tree": "0.58.0-55983",
|
|
62
|
+
"@fluidframework/protocol-base": "^0.1035.0-0",
|
|
63
|
+
"@fluidframework/protocol-definitions": "^0.1027.0-0",
|
|
64
|
+
"@fluidframework/runtime-definitions": "0.58.0-55983",
|
|
65
|
+
"@fluidframework/runtime-utils": "0.58.0-55983",
|
|
66
|
+
"@fluidframework/shared-object-base": "0.58.0-55983",
|
|
67
|
+
"@fluidframework/telemetry-utils": "0.58.0-55983",
|
|
68
68
|
"@tiny-calc/nano": "0.0.0-alpha.5",
|
|
69
69
|
"tslib": "^1.10.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@fluid-internal/test-dds-utils": "
|
|
72
|
+
"@fluid-internal/test-dds-utils": "0.58.0-55983",
|
|
73
73
|
"@fluidframework/build-common": "^0.23.0",
|
|
74
|
-
"@fluidframework/eslint-config-fluid": "^0.26.0",
|
|
75
|
-
"@fluidframework/mocha-test-setup": "
|
|
76
|
-
"@fluidframework/test-runtime-utils": "
|
|
74
|
+
"@fluidframework/eslint-config-fluid": "^0.26.0-0",
|
|
75
|
+
"@fluidframework/mocha-test-setup": "0.58.0-55983",
|
|
76
|
+
"@fluidframework/test-runtime-utils": "0.58.0-55983",
|
|
77
77
|
"@microsoft/api-extractor": "^7.16.1",
|
|
78
78
|
"@rushstack/eslint-config": "^2.5.1",
|
|
79
79
|
"@tiny-calc/micro": "0.0.0-alpha.5",
|
package/src/packageVersion.ts
CHANGED
package/src/permutationvector.ts
CHANGED
|
@@ -76,7 +76,7 @@ export class PermutationSegment extends BaseSegment {
|
|
|
76
76
|
// it is included if the undo stack continues to unwind to the original insertion.
|
|
77
77
|
//
|
|
78
78
|
// Out of paranoia we link and unlink in separate loops to avoid mutating the underlying
|
|
79
|
-
// set during enumeration. In
|
|
79
|
+
// set during enumeration. In practice, this is unlikely to matter since there should be
|
|
80
80
|
// exactly 0 or 1 items in the enumeration.
|
|
81
81
|
for (const group of this.trackingCollection.trackingGroups) {
|
|
82
82
|
group.link(destination);
|
|
@@ -282,9 +282,9 @@ export class PermutationVector extends Client {
|
|
|
282
282
|
// containing this position and use 'findReconnectionPosition' to adjust for the local ops that
|
|
283
283
|
// have not yet been submitted.
|
|
284
284
|
|
|
285
|
-
|
|
286
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
287
|
-
return this.
|
|
285
|
+
|
|
286
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
287
|
+
return this.findReconnectionPosition(containingSegment, localSeq) + containingOffset!;
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
// Constructs an ISummaryTreeWithStats for the cell data.
|
|
@@ -331,7 +331,7 @@ export class PermutationVector extends Client {
|
|
|
331
331
|
case MergeTreeDeltaType.INSERT:
|
|
332
332
|
// Pass 1: Perform any internal maintenance first to avoid reentrancy.
|
|
333
333
|
for (const { segment, position } of ranges) {
|
|
334
|
-
// HACK: We need to include the allocated handle in the segment's JSON
|
|
334
|
+
// HACK: We need to include the allocated handle in the segment's JSON representation
|
|
335
335
|
// for snapshots, but need to ignore the remote client's handle allocations when
|
|
336
336
|
// processing remote ops.
|
|
337
337
|
segment.reset();
|