@fluidframework/merge-tree 2.30.0 → 2.31.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 +403 -399
- package/api-report/merge-tree.legacy.alpha.api.md +1 -0
- package/dist/MergeTreeTextHelper.d.ts +9 -3
- package/dist/MergeTreeTextHelper.d.ts.map +1 -1
- package/dist/MergeTreeTextHelper.js +5 -5
- package/dist/MergeTreeTextHelper.js.map +1 -1
- package/dist/client.d.ts +7 -13
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +136 -110
- package/dist/client.js.map +1 -1
- package/dist/endOfTreeSegment.d.ts +12 -8
- package/dist/endOfTreeSegment.d.ts.map +1 -1
- package/dist/endOfTreeSegment.js +2 -4
- package/dist/endOfTreeSegment.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/mergeTree.d.ts +37 -23
- package/dist/mergeTree.d.ts.map +1 -1
- package/dist/mergeTree.js +400 -483
- package/dist/mergeTree.js.map +1 -1
- package/dist/mergeTreeDeltaCallback.d.ts +4 -8
- package/dist/mergeTreeDeltaCallback.d.ts.map +1 -1
- package/dist/mergeTreeDeltaCallback.js.map +1 -1
- package/dist/mergeTreeNodes.d.ts +32 -10
- package/dist/mergeTreeNodes.d.ts.map +1 -1
- package/dist/mergeTreeNodes.js +43 -28
- package/dist/mergeTreeNodes.js.map +1 -1
- package/dist/partialLengths.d.ts +2 -2
- package/dist/partialLengths.d.ts.map +1 -1
- package/dist/partialLengths.js +181 -109
- package/dist/partialLengths.js.map +1 -1
- package/dist/perspective.d.ts +8 -27
- package/dist/perspective.d.ts.map +1 -1
- package/dist/perspective.js +7 -67
- package/dist/perspective.js.map +1 -1
- package/dist/revertibles.d.ts.map +1 -1
- package/dist/revertibles.js +2 -2
- package/dist/revertibles.js.map +1 -1
- package/dist/segmentInfos.d.ts +20 -106
- package/dist/segmentInfos.d.ts.map +1 -1
- package/dist/segmentInfos.js +28 -42
- package/dist/segmentInfos.js.map +1 -1
- package/dist/segmentPropertiesManager.d.ts +1 -14
- package/dist/segmentPropertiesManager.d.ts.map +1 -1
- package/dist/segmentPropertiesManager.js +3 -17
- package/dist/segmentPropertiesManager.js.map +1 -1
- package/dist/snapshotLoader.d.ts.map +1 -1
- package/dist/snapshotLoader.js +62 -19
- package/dist/snapshotLoader.js.map +1 -1
- package/dist/snapshotV1.d.ts.map +1 -1
- package/dist/snapshotV1.js +55 -24
- package/dist/snapshotV1.js.map +1 -1
- package/dist/snapshotlegacy.d.ts.map +1 -1
- package/dist/snapshotlegacy.js +6 -9
- package/dist/snapshotlegacy.js.map +1 -1
- package/dist/stamps.d.ts +1 -1
- package/dist/stamps.js +1 -1
- package/dist/stamps.js.map +1 -1
- package/dist/test/Insertion.perf.spec.js +6 -51
- package/dist/test/Insertion.perf.spec.js.map +1 -1
- package/dist/test/PartialLengths.perf.spec.js +18 -25
- package/dist/test/PartialLengths.perf.spec.js.map +1 -1
- package/dist/test/Removal.perf.spec.js +13 -41
- package/dist/test/Removal.perf.spec.js.map +1 -1
- package/dist/test/beastTest.spec.d.ts.map +1 -1
- package/dist/test/beastTest.spec.js +41 -66
- package/dist/test/beastTest.spec.js.map +1 -1
- package/dist/test/client.annotateMarker.spec.js +1 -11
- package/dist/test/client.annotateMarker.spec.js.map +1 -1
- package/dist/test/client.applyMsg.spec.js +14 -14
- package/dist/test/client.applyMsg.spec.js.map +1 -1
- package/dist/test/client.getPosition.spec.js +1 -1
- package/dist/test/client.getPosition.spec.js.map +1 -1
- package/dist/test/client.localReference.spec.js +1 -1
- package/dist/test/client.localReference.spec.js.map +1 -1
- package/dist/test/client.rollback.spec.js +49 -58
- package/dist/test/client.rollback.spec.js.map +1 -1
- package/dist/test/client.rollbackFarm.spec.js +1 -1
- package/dist/test/client.rollbackFarm.spec.js.map +1 -1
- package/dist/test/client.searchForMarker.spec.js +4 -21
- package/dist/test/client.searchForMarker.spec.js.map +1 -1
- package/dist/test/index.d.ts +2 -2
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +2 -6
- package/dist/test/index.js.map +1 -1
- package/dist/test/mergeTree.annotate.deltaCallback.spec.js +14 -59
- package/dist/test/mergeTree.annotate.deltaCallback.spec.js.map +1 -1
- package/dist/test/mergeTree.annotate.spec.js +47 -63
- package/dist/test/mergeTree.annotate.spec.js.map +1 -1
- package/dist/test/mergeTree.insert.deltaCallback.spec.js +9 -62
- package/dist/test/mergeTree.insert.deltaCallback.spec.js.map +1 -1
- package/dist/test/mergeTree.insertingWalk.spec.js +59 -125
- package/dist/test/mergeTree.insertingWalk.spec.js.map +1 -1
- package/dist/test/mergeTree.markRangeRemoved.deltaCallback.spec.js +12 -93
- package/dist/test/mergeTree.markRangeRemoved.deltaCallback.spec.js.map +1 -1
- package/dist/test/mergeTree.markRangeRemoved.spec.js +10 -7
- package/dist/test/mergeTree.markRangeRemoved.spec.js.map +1 -1
- package/dist/test/mergeTree.walk.spec.js +2 -14
- package/dist/test/mergeTree.walk.spec.js.map +1 -1
- package/dist/test/mergeTreeOperationRunner.js +2 -2
- package/dist/test/mergeTreeOperationRunner.js.map +1 -1
- package/dist/test/obliterate.concurrent.spec.js +18 -23
- package/dist/test/obliterate.concurrent.spec.js.map +1 -1
- package/dist/test/obliterate.partialLength.spec.js +166 -136
- package/dist/test/obliterate.partialLength.spec.js.map +1 -1
- package/dist/test/obliterate.spec.js +16 -126
- package/dist/test/obliterate.spec.js.map +1 -1
- package/dist/test/partialLength.spec.js +28 -196
- package/dist/test/partialLength.spec.js.map +1 -1
- package/dist/test/perspective.spec.js +34 -0
- package/dist/test/perspective.spec.js.map +1 -1
- package/dist/test/propertyManager.spec.js +1 -1
- package/dist/test/propertyManager.spec.js.map +1 -1
- package/dist/test/resetPendingSegmentsToOp.spec.js +0 -2
- package/dist/test/resetPendingSegmentsToOp.spec.js.map +1 -1
- package/dist/test/segmentGroupCollection.spec.js +10 -4
- package/dist/test/segmentGroupCollection.spec.js.map +1 -1
- package/dist/test/testClient.d.ts +1 -0
- package/dist/test/testClient.d.ts.map +1 -1
- package/dist/test/testClient.js +16 -26
- package/dist/test/testClient.js.map +1 -1
- package/dist/test/testClientLogger.d.ts.map +1 -1
- package/dist/test/testClientLogger.js +3 -10
- package/dist/test/testClientLogger.js.map +1 -1
- package/dist/test/testServer.d.ts +2 -1
- package/dist/test/testServer.d.ts.map +1 -1
- package/dist/test/testServer.js +7 -5
- package/dist/test/testServer.js.map +1 -1
- package/dist/test/testUtils.d.ts +36 -56
- package/dist/test/testUtils.d.ts.map +1 -1
- package/dist/test/testUtils.js +68 -77
- package/dist/test/testUtils.js.map +1 -1
- package/dist/test/text.d.ts +2 -2
- package/dist/test/text.d.ts.map +1 -1
- package/dist/test/text.js +5 -2
- package/dist/test/text.js.map +1 -1
- package/dist/textSegment.d.ts +0 -6
- package/dist/textSegment.d.ts.map +1 -1
- package/dist/textSegment.js.map +1 -1
- package/dist/zamboni.d.ts.map +1 -1
- package/dist/zamboni.js +53 -26
- package/dist/zamboni.js.map +1 -1
- package/lib/MergeTreeTextHelper.d.ts +9 -3
- package/lib/MergeTreeTextHelper.d.ts.map +1 -1
- package/lib/MergeTreeTextHelper.js +5 -5
- package/lib/MergeTreeTextHelper.js.map +1 -1
- package/lib/client.d.ts +7 -13
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +117 -116
- package/lib/client.js.map +1 -1
- package/lib/endOfTreeSegment.d.ts +12 -8
- package/lib/endOfTreeSegment.d.ts.map +1 -1
- package/lib/endOfTreeSegment.js +2 -4
- package/lib/endOfTreeSegment.js.map +1 -1
- package/lib/index.d.ts +6 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/mergeTree.d.ts +37 -23
- package/lib/mergeTree.d.ts.map +1 -1
- package/lib/mergeTree.js +381 -488
- package/lib/mergeTree.js.map +1 -1
- package/lib/mergeTreeDeltaCallback.d.ts +4 -8
- package/lib/mergeTreeDeltaCallback.d.ts.map +1 -1
- package/lib/mergeTreeDeltaCallback.js.map +1 -1
- package/lib/mergeTreeNodes.d.ts +32 -10
- package/lib/mergeTreeNodes.d.ts.map +1 -1
- package/lib/mergeTreeNodes.js +42 -29
- package/lib/mergeTreeNodes.js.map +1 -1
- package/lib/partialLengths.d.ts +2 -2
- package/lib/partialLengths.d.ts.map +1 -1
- package/lib/partialLengths.js +160 -111
- package/lib/partialLengths.js.map +1 -1
- package/lib/perspective.d.ts +8 -27
- package/lib/perspective.d.ts.map +1 -1
- package/lib/perspective.js +8 -68
- package/lib/perspective.js.map +1 -1
- package/lib/revertibles.d.ts.map +1 -1
- package/lib/revertibles.js +2 -2
- package/lib/revertibles.js.map +1 -1
- package/lib/segmentInfos.d.ts +20 -106
- package/lib/segmentInfos.d.ts.map +1 -1
- package/lib/segmentInfos.js +26 -37
- package/lib/segmentInfos.js.map +1 -1
- package/lib/segmentPropertiesManager.d.ts +1 -14
- package/lib/segmentPropertiesManager.d.ts.map +1 -1
- package/lib/segmentPropertiesManager.js +2 -16
- package/lib/segmentPropertiesManager.js.map +1 -1
- package/lib/snapshotLoader.d.ts.map +1 -1
- package/lib/snapshotLoader.js +39 -19
- package/lib/snapshotLoader.js.map +1 -1
- package/lib/snapshotV1.d.ts.map +1 -1
- package/lib/snapshotV1.js +34 -26
- package/lib/snapshotV1.js.map +1 -1
- package/lib/snapshotlegacy.d.ts.map +1 -1
- package/lib/snapshotlegacy.js +7 -10
- package/lib/snapshotlegacy.js.map +1 -1
- package/lib/stamps.d.ts +1 -1
- package/lib/stamps.js +1 -1
- package/lib/stamps.js.map +1 -1
- package/lib/test/Insertion.perf.spec.js +6 -51
- package/lib/test/Insertion.perf.spec.js.map +1 -1
- package/lib/test/PartialLengths.perf.spec.js +18 -25
- package/lib/test/PartialLengths.perf.spec.js.map +1 -1
- package/lib/test/Removal.perf.spec.js +13 -41
- package/lib/test/Removal.perf.spec.js.map +1 -1
- package/lib/test/beastTest.spec.d.ts.map +1 -1
- package/lib/test/beastTest.spec.js +42 -67
- package/lib/test/beastTest.spec.js.map +1 -1
- package/lib/test/client.annotateMarker.spec.js +1 -11
- package/lib/test/client.annotateMarker.spec.js.map +1 -1
- package/lib/test/client.applyMsg.spec.js +14 -14
- package/lib/test/client.applyMsg.spec.js.map +1 -1
- package/lib/test/client.getPosition.spec.js +1 -1
- package/lib/test/client.getPosition.spec.js.map +1 -1
- package/lib/test/client.localReference.spec.js +1 -1
- package/lib/test/client.localReference.spec.js.map +1 -1
- package/lib/test/client.rollback.spec.js +50 -59
- package/lib/test/client.rollback.spec.js.map +1 -1
- package/lib/test/client.rollbackFarm.spec.js +1 -1
- package/lib/test/client.rollbackFarm.spec.js.map +1 -1
- package/lib/test/client.searchForMarker.spec.js +4 -21
- package/lib/test/client.searchForMarker.spec.js.map +1 -1
- package/lib/test/index.d.ts +2 -2
- package/lib/test/index.d.ts.map +1 -1
- package/lib/test/index.js +1 -1
- package/lib/test/index.js.map +1 -1
- package/lib/test/mergeTree.annotate.deltaCallback.spec.js +15 -60
- package/lib/test/mergeTree.annotate.deltaCallback.spec.js.map +1 -1
- package/lib/test/mergeTree.annotate.spec.js +48 -64
- package/lib/test/mergeTree.annotate.spec.js.map +1 -1
- package/lib/test/mergeTree.insert.deltaCallback.spec.js +10 -63
- package/lib/test/mergeTree.insert.deltaCallback.spec.js.map +1 -1
- package/lib/test/mergeTree.insertingWalk.spec.js +61 -127
- package/lib/test/mergeTree.insertingWalk.spec.js.map +1 -1
- package/lib/test/mergeTree.markRangeRemoved.deltaCallback.spec.js +13 -94
- package/lib/test/mergeTree.markRangeRemoved.deltaCallback.spec.js.map +1 -1
- package/lib/test/mergeTree.markRangeRemoved.spec.js +10 -7
- package/lib/test/mergeTree.markRangeRemoved.spec.js.map +1 -1
- package/lib/test/mergeTree.walk.spec.js +2 -14
- package/lib/test/mergeTree.walk.spec.js.map +1 -1
- package/lib/test/mergeTreeOperationRunner.js +3 -3
- package/lib/test/mergeTreeOperationRunner.js.map +1 -1
- package/lib/test/obliterate.concurrent.spec.js +18 -23
- package/lib/test/obliterate.concurrent.spec.js.map +1 -1
- package/lib/test/obliterate.partialLength.spec.js +167 -137
- package/lib/test/obliterate.partialLength.spec.js.map +1 -1
- package/lib/test/obliterate.spec.js +17 -127
- package/lib/test/obliterate.spec.js.map +1 -1
- package/lib/test/partialLength.spec.js +29 -197
- package/lib/test/partialLength.spec.js.map +1 -1
- package/lib/test/perspective.spec.js +34 -0
- package/lib/test/perspective.spec.js.map +1 -1
- package/lib/test/propertyManager.spec.js +2 -2
- package/lib/test/propertyManager.spec.js.map +1 -1
- package/lib/test/resetPendingSegmentsToOp.spec.js +0 -2
- package/lib/test/resetPendingSegmentsToOp.spec.js.map +1 -1
- package/lib/test/segmentGroupCollection.spec.js +10 -4
- package/lib/test/segmentGroupCollection.spec.js.map +1 -1
- package/lib/test/testClient.d.ts +1 -0
- package/lib/test/testClient.d.ts.map +1 -1
- package/lib/test/testClient.js +18 -28
- package/lib/test/testClient.js.map +1 -1
- package/lib/test/testClientLogger.d.ts.map +1 -1
- package/lib/test/testClientLogger.js +3 -10
- package/lib/test/testClientLogger.js.map +1 -1
- package/lib/test/testServer.d.ts +2 -1
- package/lib/test/testServer.d.ts.map +1 -1
- package/lib/test/testServer.js +7 -5
- package/lib/test/testServer.js.map +1 -1
- package/lib/test/testUtils.d.ts +36 -56
- package/lib/test/testUtils.d.ts.map +1 -1
- package/lib/test/testUtils.js +66 -48
- package/lib/test/testUtils.js.map +1 -1
- package/lib/test/text.d.ts +2 -2
- package/lib/test/text.d.ts.map +1 -1
- package/lib/test/text.js +6 -3
- package/lib/test/text.js.map +1 -1
- package/lib/textSegment.d.ts +0 -6
- package/lib/textSegment.d.ts.map +1 -1
- package/lib/textSegment.js.map +1 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/zamboni.d.ts.map +1 -1
- package/lib/zamboni.js +32 -28
- package/lib/zamboni.js.map +1 -1
- package/package.json +17 -20
- package/src/MergeTreeTextHelper.ts +17 -12
- package/src/client.ts +141 -197
- package/src/endOfTreeSegment.ts +11 -8
- package/src/index.ts +4 -3
- package/src/mergeTree.ts +482 -633
- package/src/mergeTreeDeltaCallback.ts +4 -8
- package/src/mergeTreeNodes.ts +66 -45
- package/src/partialLengths.ts +181 -137
- package/src/perspective.ts +17 -95
- package/src/revertibles.ts +2 -7
- package/src/segmentInfos.ts +48 -141
- package/src/segmentPropertiesManager.ts +2 -16
- package/src/snapshotLoader.ts +62 -30
- package/src/snapshotV1.ts +36 -28
- package/src/snapshotlegacy.ts +7 -16
- package/src/stamps.ts +1 -1
- package/src/textSegment.ts +0 -13
- package/src/zamboni.ts +38 -32
- package/tsconfig.json +1 -0
- package/prettier.config.cjs +0 -8
|
@@ -4,19 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { IMergeTreeAnnotateAdjustMsg, IMergeTreeAnnotateMsg } from "./ops.js";
|
|
6
6
|
import { MapLike, PropertySet } from "./properties.js";
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export declare enum PropertiesRollback {
|
|
11
|
-
/**
|
|
12
|
-
* Not in a rollback
|
|
13
|
-
*/
|
|
14
|
-
None = 0,
|
|
15
|
-
/**
|
|
16
|
-
* Rollback
|
|
17
|
-
*/
|
|
18
|
-
Rollback = 1
|
|
19
|
-
}
|
|
20
7
|
/**
|
|
21
8
|
* Minimally copies properties and the property manager from source to destination.
|
|
22
9
|
* @internal
|
|
@@ -69,7 +56,7 @@ export declare class PropertiesManager {
|
|
|
69
56
|
*/
|
|
70
57
|
handleProperties(op: PropsOrAdjust, seg: {
|
|
71
58
|
properties?: MapLike<unknown>;
|
|
72
|
-
}, seq: number, msn: number, collaborating?: boolean, rollback?:
|
|
59
|
+
}, seq: number, msn: number, collaborating?: boolean, rollback?: boolean): MapLike<unknown>;
|
|
73
60
|
/**
|
|
74
61
|
* Acknowledges property changes.
|
|
75
62
|
* This method acknowledges the property changes based on the provided sequence number and operation.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segmentPropertiesManager.d.ts","sourceRoot":"","sources":["../src/segmentPropertiesManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAEX,2BAA2B,EAC3B,qBAAqB,EACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,OAAO,EAAE,WAAW,EAAoB,MAAM,iBAAiB,CAAC;AAEzE
|
|
1
|
+
{"version":3,"file":"segmentPropertiesManager.d.ts","sourceRoot":"","sources":["../src/segmentPropertiesManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAEX,2BAA2B,EAC3B,qBAAqB,EACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,OAAO,EAAE,WAAW,EAAoB,MAAM,iBAAiB,CAAC;AAEzE;;;GAGG;AACH,wBAAgB,wBAAwB,CACvC,MAAM,EAAE;IACP,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,eAAe,CAAC,EAAE,iBAAiB,CAAC;CACpC,EACD,WAAW,EAAE;IACZ,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,eAAe,CAAC,EAAE,iBAAiB,CAAC;CACpC,GACC,IAAI,CASN;AAsCD;;GAEG;AACH,MAAM,MAAM,aAAa,GACtB,IAAI,CAAC,2BAA2B,EAAE,OAAO,GAAG,QAAQ,CAAC,GACrD,IAAI,CAAC,qBAAqB,EAAE,OAAO,GAAG,QAAQ,CAAC,CAAC;AAoCnD;;;;;;GAMG;AACH,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsC;IAE9D;;;;;;;;;OASG;IACI,kBAAkB,CACxB,EAAE,EAAE,aAAa,EACjB,GAAG,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;KAAE,EACtC,aAAa,GAAE,OAAe,GAC5B,OAAO,CAAC,OAAO,CAAC;IA+BnB;;;;;;;;;;;;OAYG;IACI,gBAAgB,CACtB,EAAE,EAAE,aAAa,EACjB,GAAG,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;KAAE,EACtC,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,aAAa,GAAE,OAAe,EAC9B,QAAQ,GAAE,OAAe,GACvB,OAAO,CAAC,OAAO,CAAC;IA6CnB;;;;;;;OAOG;IACI,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,aAAa,GAAG,IAAI;IAqB7D;;;;;OAKG;IACI,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAkBnC;;;;;;OAMG;IACI,MAAM,CACZ,QAAQ,EAAE,WAAW,GAAG,SAAS,EACjC,IAAI,EAAE;QACL,UAAU,CAAC,EAAE,WAAW,CAAC;QACzB,eAAe,CAAC,EAAE,iBAAiB,CAAC;KACpC,GACC,IAAI;IAYP;;;;;;;;;OASG;IACI,QAAQ,CACd,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,SAAS,EACtC,cAAc,EAAE,MAAM,GACpB,OAAO,CAAC,OAAO,CAAC;IAenB;;;;;OAKG;IACI,oBAAoB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO;CAQxD"}
|
|
@@ -6,20 +6,6 @@ import { assert } from "@fluidframework/core-utils/internal";
|
|
|
6
6
|
import { DoublyLinkedList, iterateListValuesWhile } from "./collections/index.js";
|
|
7
7
|
import { UnassignedSequenceNumber, UniversalSequenceNumber } from "./constants.js";
|
|
8
8
|
import { clone, createMap } from "./properties.js";
|
|
9
|
-
/**
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export var PropertiesRollback;
|
|
13
|
-
(function (PropertiesRollback) {
|
|
14
|
-
/**
|
|
15
|
-
* Not in a rollback
|
|
16
|
-
*/
|
|
17
|
-
PropertiesRollback[PropertiesRollback["None"] = 0] = "None";
|
|
18
|
-
/**
|
|
19
|
-
* Rollback
|
|
20
|
-
*/
|
|
21
|
-
PropertiesRollback[PropertiesRollback["Rollback"] = 1] = "Rollback";
|
|
22
|
-
})(PropertiesRollback || (PropertiesRollback = {}));
|
|
23
9
|
/**
|
|
24
10
|
* Minimally copies properties and the property manager from source to destination.
|
|
25
11
|
* @internal
|
|
@@ -135,8 +121,8 @@ export class PropertiesManager {
|
|
|
135
121
|
* @param rollback - Specifies if the changes should be rolled back. Defaults to PropertiesRollback.None.
|
|
136
122
|
* @returns The deltas of the applied or rolled-back properties. This is a map-like object representing the changes.
|
|
137
123
|
*/
|
|
138
|
-
handleProperties(op, seg, seq, msn, collaborating = false, rollback =
|
|
139
|
-
if (rollback
|
|
124
|
+
handleProperties(op, seg, seq, msn, collaborating = false, rollback = false) {
|
|
125
|
+
if (rollback) {
|
|
140
126
|
return this.rollbackProperties(op, seg, collaborating);
|
|
141
127
|
}
|
|
142
128
|
const rtn = applyChanges(op, seg, seq, (properties, deltas, key, value) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segmentPropertiesManager.js","sourceRoot":"","sources":["../src/segmentPropertiesManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAMnF,OAAO,EAAwB,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEzE;;GAEG;AACH,MAAM,CAAN,IAAY,kBAUX;AAVD,WAAY,kBAAkB;IAC7B;;OAEG;IACH,2DAAI,CAAA;IAEJ;;OAEG;IACH,mEAAQ,CAAA;AACT,CAAC,EAVW,kBAAkB,KAAlB,kBAAkB,QA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AAI,CAAC,GAAG,IAAI,cAAc,CAAC,CACjF,CAAC;YACF,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC9B,gEAAgE;gBAChE,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC;YACxB,CAAC;QACF,CAAC;QACD,OAAO,UAAU,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACI,oBAAoB,CAAC,KAAkB;QAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAClD,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;gBACzE,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport { DoublyLinkedList, iterateListValuesWhile } from \"./collections/index.js\";\nimport { UnassignedSequenceNumber, UniversalSequenceNumber } from \"./constants.js\";\nimport type {\n\tAdjustParams,\n\tIMergeTreeAnnotateAdjustMsg,\n\tIMergeTreeAnnotateMsg,\n} from \"./ops.js\";\nimport { MapLike, PropertySet, clone, createMap } from \"./properties.js\";\n\n/**\n * @internal\n */\nexport enum PropertiesRollback {\n\t/**\n\t * Not in a rollback\n\t */\n\tNone,\n\n\t/**\n\t * Rollback\n\t */\n\tRollback,\n}\n/**\n * Minimally copies properties and the property manager from source to destination.\n * @internal\n */\nexport function copyPropertiesAndManager(\n\tsource: {\n\t\tproperties?: PropertySet;\n\t\tpropertyManager?: PropertiesManager;\n\t},\n\tdestination: {\n\t\tproperties?: PropertySet;\n\t\tpropertyManager?: PropertiesManager;\n\t},\n): void {\n\tif (source.properties) {\n\t\tif (source.propertyManager === undefined) {\n\t\t\tdestination.properties = clone(source.properties);\n\t\t} else {\n\t\t\tdestination.propertyManager ??= new PropertiesManager();\n\t\t\tsource.propertyManager.copyTo(source.properties, destination);\n\t\t}\n\t}\n}\n\ntype PropertyChange = {\n\tseq: number;\n} & ({ adjust: AdjustParams; raw?: undefined } | { raw: unknown; adjust?: undefined });\n\ninterface PropertyChanges {\n\tmsnConsensus: unknown;\n\tremote: DoublyLinkedList<PropertyChange>;\n\tlocal: DoublyLinkedList<PropertyChange>;\n}\n\nfunction computePropertyValue(\n\tconsensus: unknown,\n\t...changes: Iterable<PropertyChange>[]\n): unknown {\n\tlet computedValue: unknown = consensus;\n\tfor (const change of changes) {\n\t\tfor (const op of change) {\n\t\t\tconst { raw, adjust } = op;\n\t\t\tif (adjust === undefined) {\n\t\t\t\tcomputedValue = raw;\n\t\t\t} else {\n\t\t\t\tconst adjusted =\n\t\t\t\t\t(typeof computedValue === \"number\" ? computedValue : 0) + adjust.delta;\n\t\t\t\tif (adjust.max !== undefined && adjusted > adjust.max) {\n\t\t\t\t\tcomputedValue = adjust.max;\n\t\t\t\t} else if (adjust.min !== undefined && adjusted < adjust.min) {\n\t\t\t\t\tcomputedValue = adjust.min;\n\t\t\t\t} else {\n\t\t\t\t\tcomputedValue = adjusted;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn computedValue;\n}\n\n/**\n * @internal\n */\nexport type PropsOrAdjust =\n\t| Pick<IMergeTreeAnnotateAdjustMsg, \"props\" | \"adjust\">\n\t| Pick<IMergeTreeAnnotateMsg, \"props\" | \"adjust\">;\n\nconst opToChanges = (op: PropsOrAdjust, seq: number): [string, PropertyChange][] => [\n\t...Object.entries(op.props ?? {})\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t.map<[string, PropertyChange]>(([k, raw]) => [k, { raw, seq }])\n\t\t.filter(([_, v]) => v.raw !== undefined),\n\t...Object.entries(op.adjust ?? {}).map<[string, PropertyChange]>(([k, adjust]) => [\n\t\tk,\n\t\t{ adjust, seq },\n\t]),\n];\n\nfunction applyChanges(\n\top: PropsOrAdjust,\n\tseg: { properties?: MapLike<unknown> },\n\tseq: number,\n\trun: (\n\t\tproperties: MapLike<unknown>,\n\t\tdeltas: MapLike<unknown>,\n\t\tkey: string,\n\t\tvalue: PropertyChange,\n\t) => void,\n): MapLike<unknown> {\n\tconst properties = (seg.properties ??= createMap<unknown>());\n\tconst deltas: MapLike<unknown> = {};\n\tfor (const [key, value] of opToChanges(op, seq)) {\n\t\trun(properties, deltas, key, value);\n\t\tif (properties[key] === null) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\tdelete properties[key];\n\t\t}\n\t}\n\treturn deltas;\n}\n\n/**\n * The PropertiesManager class handles changes to properties, both remote and local.\n * It manages the lifecycle for local property changes, ensures all property changes are eventually consistent,\n * and provides methods to acknowledge changes, update the minimum sequence number (msn), and copy properties to another manager.\n * This class is essential for maintaining the integrity and consistency of property changes in collaborative environments.\n * @internal\n */\nexport class PropertiesManager {\n\tprivate readonly changes = new Map<string, PropertyChanges>();\n\n\t/**\n\t * Rolls back local property changes.\n\t * This method reverts property changes based on the provided operation and segment.\n\t * If the operation is part of a collaborative session, it ensures that the changes are consistent with the remote state.\n\t *\n\t * @param op - The operation containing property changes. This can be an adjustment or a set of properties.\n\t * @param seg - The segment containing properties. This object may have a properties map that will be modified.\n\t * @param collaborating - Indicates if the operation is part of a collaborative session. Defaults to false.\n\t * @returns The deltas of the rolled-back properties. This is a map-like object representing the changes that were reverted.\n\t */\n\tpublic rollbackProperties(\n\t\top: PropsOrAdjust,\n\t\tseg: { properties?: MapLike<unknown> },\n\t\tcollaborating: boolean = false,\n\t): MapLike<unknown> {\n\t\treturn applyChanges(op, seg, UniversalSequenceNumber, (properties, deltas, key, value) => {\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tconst previousValue = properties[key] ?? null;\n\n\t\t\tconst pending = this.changes.get(key);\n\t\t\tif (collaborating) {\n\t\t\t\tassert(\n\t\t\t\t\tpending !== undefined,\n\t\t\t\t\t0xa6f /* Pending changes must exist for rollback when collaborating */,\n\t\t\t\t);\n\t\t\t\tpending.local.pop();\n\t\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\t\tpending.msnConsensus,\n\t\t\t\t\tpending.remote.map((n) => n.data),\n\t\t\t\t\tpending.local.map((n) => n.data),\n\t\t\t\t);\n\t\t\t\tif (pending.local.empty && pending.remote.empty) {\n\t\t\t\t\tthis.changes.delete(key);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassert(\n\t\t\t\t\tpending === undefined,\n\t\t\t\t\t0xa70 /* Pending changes must not exist when not collaborating */,\n\t\t\t\t);\n\t\t\t\tproperties[key] = computePropertyValue(previousValue, [value]);\n\t\t\t}\n\t\t\tdeltas[key] = previousValue;\n\t\t});\n\t}\n\n\t/**\n\t * Handles property changes.\n\t * This method applies property changes based on the provided operation, segment, sequence number, and collaboration state.\n\t * It also handles rolling back changes if specified.\n\t *\n\t * @param op - The operation containing property changes.\n\t * @param seg - The segment containing properties.\n\t * @param seq - The sequence number for the operation.\n\t * @param msn - The minimum sequence number for the operation.\n\t * @param collaborating - Indicates if the operation is part of a collaborative session. Defaults to false.\n\t * @param rollback - Specifies if the changes should be rolled back. Defaults to PropertiesRollback.None.\n\t * @returns The deltas of the applied or rolled-back properties. This is a map-like object representing the changes.\n\t */\n\tpublic handleProperties(\n\t\top: PropsOrAdjust,\n\t\tseg: { properties?: MapLike<unknown> },\n\t\tseq: number,\n\t\tmsn: number,\n\t\tcollaborating: boolean = false,\n\t\trollback: PropertiesRollback = PropertiesRollback.None,\n\t): MapLike<unknown> {\n\t\tif (rollback === PropertiesRollback.Rollback) {\n\t\t\treturn this.rollbackProperties(op, seg, collaborating);\n\t\t}\n\t\tconst rtn = applyChanges(op, seg, seq, (properties, deltas, key, value) => {\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tconst previousValue = properties[key] ?? null;\n\t\t\tif (collaborating) {\n\t\t\t\tconst pending: PropertyChanges | undefined = this.changes.get(key) ?? {\n\t\t\t\t\tmsnConsensus: previousValue,\n\t\t\t\t\tremote: new DoublyLinkedList(),\n\t\t\t\t\tlocal: new DoublyLinkedList(),\n\t\t\t\t};\n\t\t\t\tthis.changes.set(key, pending);\n\t\t\t\tconst local = seq === UnassignedSequenceNumber;\n\t\t\t\tif (local) {\n\t\t\t\t\tpending.local.push(value);\n\t\t\t\t} else {\n\t\t\t\t\t// we only track remotes if there are adjusts, as only adjusts make application anti-commutative\n\t\t\t\t\t// this will limit the impact of this change to only those using adjusts. Additionally, we only\n\t\t\t\t\t// need to track remotes at all to support emitting the legacy snapshot format, which only sharedstring\n\t\t\t\t\t// uses. when we remove the ability to emit that format, we can remove all remote op tracking\n\t\t\t\t\tif (value.raw !== undefined && pending.remote.empty) {\n\t\t\t\t\t\tpending.msnConsensus = computePropertyValue(pending.msnConsensus, [value]);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpending.remote.push(value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\t\tpending.msnConsensus,\n\t\t\t\t\tpending.remote.map((n) => n.data),\n\t\t\t\t\tpending.local.map((n) => n.data),\n\t\t\t\t);\n\t\t\t\tif (local || pending.local.empty || properties[key] !== previousValue) {\n\t\t\t\t\tdeltas[key] = previousValue;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tproperties[key] = computePropertyValue(previousValue, [value]);\n\t\t\t\tdeltas[key] = previousValue;\n\t\t\t}\n\t\t});\n\t\tthis.updateMsn(msn);\n\t\treturn rtn;\n\t}\n\n\t/**\n\t * Acknowledges property changes.\n\t * This method acknowledges the property changes based on the provided sequence number and operation.\n\t *\n\t * @param seq - The sequence number for the operation.\n\t * @param msn - The minimum sequence number for the operation.\n\t * @param op - The operation containing property changes.\n\t */\n\tpublic ack(seq: number, msn: number, op: PropsOrAdjust): void {\n\t\tfor (const [key, value] of opToChanges(op, seq)) {\n\t\t\tconst change = this.changes.get(key);\n\t\t\tconst acked = change?.local?.shift();\n\t\t\tassert(\n\t\t\t\tchange !== undefined && acked !== undefined,\n\t\t\t\t0xa71 /* must have local change to ack */,\n\t\t\t);\n\t\t\t// we only track remotes if there are adjusts, as only adjusts make application anti-commutative\n\t\t\t// this will limit the impact of this change to only those using adjusts. Additionally, we only\n\t\t\t// need to track remotes at all to support emitting the legacy snapshot format, which only sharedstring\n\t\t\t// uses. when we remove the ability to emit that format, we can remove all remote op tracking\n\t\t\tif (value.raw !== undefined && change.remote.empty) {\n\t\t\t\tchange.msnConsensus = computePropertyValue(change.msnConsensus, [value]);\n\t\t\t} else {\n\t\t\t\tchange.remote.push(value);\n\t\t\t}\n\t\t}\n\t\tthis.updateMsn(msn);\n\t}\n\n\t/**\n\t * Updates the minimum sequence number (msn).\n\t * This method updates the minimum sequence number and removes any changes that have been acknowledged.\n\t *\n\t * @param msn - The minimum sequence number to update.\n\t */\n\tpublic updateMsn(msn: number): void {\n\t\tfor (const [key, pending] of this.changes) {\n\t\t\tpending.msnConsensus = computePropertyValue(\n\t\t\t\tpending.msnConsensus,\n\t\t\t\titerateListValuesWhile(pending.remote.first, (n) => {\n\t\t\t\t\tif (n.data.seq <= msn) {\n\t\t\t\t\t\tn.list?.remove(n);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\treturn false;\n\t\t\t\t}),\n\t\t\t);\n\t\t\tif (pending.local.empty && pending.remote.empty) {\n\t\t\t\tthis.changes.delete(key);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Copies properties to another manager.\n\t * This method copies the properties and their changes from the current manager to the destination manager.\n\t *\n\t * @param oldProps - The old properties to be copied.\n\t * @param dest - The destination object containing properties and property manager.\n\t */\n\tpublic copyTo(\n\t\toldProps: PropertySet | undefined,\n\t\tdest: {\n\t\t\tproperties?: PropertySet;\n\t\t\tpropertyManager?: PropertiesManager;\n\t\t},\n\t): void {\n\t\tconst newManager = (dest.propertyManager ??= new PropertiesManager());\n\t\tdest.properties = clone(oldProps);\n\t\tfor (const [key, { local, remote, msnConsensus }] of this.changes.entries()) {\n\t\t\tnewManager.changes.set(key, {\n\t\t\t\tmsnConsensus,\n\t\t\t\tremote: new DoublyLinkedList(remote.empty ? undefined : remote.map((c) => c.data)),\n\t\t\t\tlocal: new DoublyLinkedList(local.empty ? undefined : local.map((c) => c.data)),\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Gets properties at a specific sequence number.\n\t * This method retrieves the properties at the given sequence number.\n\t * This is only needed to support emitting snapshots in the legacy format.\n\t * If we remove the ability to emit the legacy format, we can remove this method, along with the need to track remote changes at all.\n\t *\n\t * @param oldProps - The old properties to be retrieved.\n\t * @param sequenceNumber - The sequence number to get properties at.\n\t * @returns The properties at the given sequence number.\n\t */\n\tpublic getAtSeq(\n\t\toldProps: MapLike<unknown> | undefined,\n\t\tsequenceNumber: number,\n\t): MapLike<unknown> {\n\t\tconst properties: MapLike<unknown> = { ...oldProps };\n\t\tfor (const [key, changes] of this.changes) {\n\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\tchanges.msnConsensus,\n\t\t\t\titerateListValuesWhile(changes.remote.first, (c) => c.data.seq <= sequenceNumber),\n\t\t\t);\n\t\t\tif (properties[key] === null) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\t\tdelete properties[key];\n\t\t\t}\n\t\t}\n\t\treturn properties;\n\t}\n\n\t/**\n\t * Determines if all of the defined properties in a given property set are pending.\n\t *\n\t * @param props - The properties to check.\n\t * @returns True if all the properties are pending, false otherwise.\n\t */\n\tpublic hasPendingProperties(props: PropertySet): boolean {\n\t\tfor (const [key, value] of Object.entries(props)) {\n\t\t\tif (value !== undefined && this.changes.get(key)?.local.empty !== false) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n"]}
|
|
1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AAM,UAAU,GAAqB,EAAE,GAAG,QAAQ,EAAE,CAAC;QACrD,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC3C,UAAU,CAAC,GAAG,CAAC,GAAG,oBAAoB,CACrC,OAAO,CAAC,YAAY,EACpB,sBAAsB,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,cAAc,CAAC,CACjF,CAAC;YACF,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC9B,gEAAgE;gBAChE,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC;YACxB,CAAC;QACF,CAAC;QACD,OAAO,UAAU,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACI,oBAAoB,CAAC,KAAkB;QAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAClD,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;gBACzE,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport { DoublyLinkedList, iterateListValuesWhile } from \"./collections/index.js\";\nimport { UnassignedSequenceNumber, UniversalSequenceNumber } from \"./constants.js\";\nimport type {\n\tAdjustParams,\n\tIMergeTreeAnnotateAdjustMsg,\n\tIMergeTreeAnnotateMsg,\n} from \"./ops.js\";\nimport { MapLike, PropertySet, clone, createMap } from \"./properties.js\";\n\n/**\n * Minimally copies properties and the property manager from source to destination.\n * @internal\n */\nexport function copyPropertiesAndManager(\n\tsource: {\n\t\tproperties?: PropertySet;\n\t\tpropertyManager?: PropertiesManager;\n\t},\n\tdestination: {\n\t\tproperties?: PropertySet;\n\t\tpropertyManager?: PropertiesManager;\n\t},\n): void {\n\tif (source.properties) {\n\t\tif (source.propertyManager === undefined) {\n\t\t\tdestination.properties = clone(source.properties);\n\t\t} else {\n\t\t\tdestination.propertyManager ??= new PropertiesManager();\n\t\t\tsource.propertyManager.copyTo(source.properties, destination);\n\t\t}\n\t}\n}\n\ntype PropertyChange = {\n\tseq: number;\n} & ({ adjust: AdjustParams; raw?: undefined } | { raw: unknown; adjust?: undefined });\n\ninterface PropertyChanges {\n\tmsnConsensus: unknown;\n\tremote: DoublyLinkedList<PropertyChange>;\n\tlocal: DoublyLinkedList<PropertyChange>;\n}\n\nfunction computePropertyValue(\n\tconsensus: unknown,\n\t...changes: Iterable<PropertyChange>[]\n): unknown {\n\tlet computedValue: unknown = consensus;\n\tfor (const change of changes) {\n\t\tfor (const op of change) {\n\t\t\tconst { raw, adjust } = op;\n\t\t\tif (adjust === undefined) {\n\t\t\t\tcomputedValue = raw;\n\t\t\t} else {\n\t\t\t\tconst adjusted =\n\t\t\t\t\t(typeof computedValue === \"number\" ? computedValue : 0) + adjust.delta;\n\t\t\t\tif (adjust.max !== undefined && adjusted > adjust.max) {\n\t\t\t\t\tcomputedValue = adjust.max;\n\t\t\t\t} else if (adjust.min !== undefined && adjusted < adjust.min) {\n\t\t\t\t\tcomputedValue = adjust.min;\n\t\t\t\t} else {\n\t\t\t\t\tcomputedValue = adjusted;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn computedValue;\n}\n\n/**\n * @internal\n */\nexport type PropsOrAdjust =\n\t| Pick<IMergeTreeAnnotateAdjustMsg, \"props\" | \"adjust\">\n\t| Pick<IMergeTreeAnnotateMsg, \"props\" | \"adjust\">;\n\nconst opToChanges = (op: PropsOrAdjust, seq: number): [string, PropertyChange][] => [\n\t...Object.entries(op.props ?? {})\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t.map<[string, PropertyChange]>(([k, raw]) => [k, { raw, seq }])\n\t\t.filter(([_, v]) => v.raw !== undefined),\n\t...Object.entries(op.adjust ?? {}).map<[string, PropertyChange]>(([k, adjust]) => [\n\t\tk,\n\t\t{ adjust, seq },\n\t]),\n];\n\nfunction applyChanges(\n\top: PropsOrAdjust,\n\tseg: { properties?: MapLike<unknown> },\n\tseq: number,\n\trun: (\n\t\tproperties: MapLike<unknown>,\n\t\tdeltas: MapLike<unknown>,\n\t\tkey: string,\n\t\tvalue: PropertyChange,\n\t) => void,\n): MapLike<unknown> {\n\tconst properties = (seg.properties ??= createMap<unknown>());\n\tconst deltas: MapLike<unknown> = {};\n\tfor (const [key, value] of opToChanges(op, seq)) {\n\t\trun(properties, deltas, key, value);\n\t\tif (properties[key] === null) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\tdelete properties[key];\n\t\t}\n\t}\n\treturn deltas;\n}\n\n/**\n * The PropertiesManager class handles changes to properties, both remote and local.\n * It manages the lifecycle for local property changes, ensures all property changes are eventually consistent,\n * and provides methods to acknowledge changes, update the minimum sequence number (msn), and copy properties to another manager.\n * This class is essential for maintaining the integrity and consistency of property changes in collaborative environments.\n * @internal\n */\nexport class PropertiesManager {\n\tprivate readonly changes = new Map<string, PropertyChanges>();\n\n\t/**\n\t * Rolls back local property changes.\n\t * This method reverts property changes based on the provided operation and segment.\n\t * If the operation is part of a collaborative session, it ensures that the changes are consistent with the remote state.\n\t *\n\t * @param op - The operation containing property changes. This can be an adjustment or a set of properties.\n\t * @param seg - The segment containing properties. This object may have a properties map that will be modified.\n\t * @param collaborating - Indicates if the operation is part of a collaborative session. Defaults to false.\n\t * @returns The deltas of the rolled-back properties. This is a map-like object representing the changes that were reverted.\n\t */\n\tpublic rollbackProperties(\n\t\top: PropsOrAdjust,\n\t\tseg: { properties?: MapLike<unknown> },\n\t\tcollaborating: boolean = false,\n\t): MapLike<unknown> {\n\t\treturn applyChanges(op, seg, UniversalSequenceNumber, (properties, deltas, key, value) => {\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tconst previousValue = properties[key] ?? null;\n\n\t\t\tconst pending = this.changes.get(key);\n\t\t\tif (collaborating) {\n\t\t\t\tassert(\n\t\t\t\t\tpending !== undefined,\n\t\t\t\t\t0xa6f /* Pending changes must exist for rollback when collaborating */,\n\t\t\t\t);\n\t\t\t\tpending.local.pop();\n\t\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\t\tpending.msnConsensus,\n\t\t\t\t\tpending.remote.map((n) => n.data),\n\t\t\t\t\tpending.local.map((n) => n.data),\n\t\t\t\t);\n\t\t\t\tif (pending.local.empty && pending.remote.empty) {\n\t\t\t\t\tthis.changes.delete(key);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassert(\n\t\t\t\t\tpending === undefined,\n\t\t\t\t\t0xa70 /* Pending changes must not exist when not collaborating */,\n\t\t\t\t);\n\t\t\t\tproperties[key] = computePropertyValue(previousValue, [value]);\n\t\t\t}\n\t\t\tdeltas[key] = previousValue;\n\t\t});\n\t}\n\n\t/**\n\t * Handles property changes.\n\t * This method applies property changes based on the provided operation, segment, sequence number, and collaboration state.\n\t * It also handles rolling back changes if specified.\n\t *\n\t * @param op - The operation containing property changes.\n\t * @param seg - The segment containing properties.\n\t * @param seq - The sequence number for the operation.\n\t * @param msn - The minimum sequence number for the operation.\n\t * @param collaborating - Indicates if the operation is part of a collaborative session. Defaults to false.\n\t * @param rollback - Specifies if the changes should be rolled back. Defaults to PropertiesRollback.None.\n\t * @returns The deltas of the applied or rolled-back properties. This is a map-like object representing the changes.\n\t */\n\tpublic handleProperties(\n\t\top: PropsOrAdjust,\n\t\tseg: { properties?: MapLike<unknown> },\n\t\tseq: number,\n\t\tmsn: number,\n\t\tcollaborating: boolean = false,\n\t\trollback: boolean = false,\n\t): MapLike<unknown> {\n\t\tif (rollback) {\n\t\t\treturn this.rollbackProperties(op, seg, collaborating);\n\t\t}\n\t\tconst rtn = applyChanges(op, seg, seq, (properties, deltas, key, value) => {\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tconst previousValue = properties[key] ?? null;\n\t\t\tif (collaborating) {\n\t\t\t\tconst pending: PropertyChanges | undefined = this.changes.get(key) ?? {\n\t\t\t\t\tmsnConsensus: previousValue,\n\t\t\t\t\tremote: new DoublyLinkedList(),\n\t\t\t\t\tlocal: new DoublyLinkedList(),\n\t\t\t\t};\n\t\t\t\tthis.changes.set(key, pending);\n\t\t\t\tconst local = seq === UnassignedSequenceNumber;\n\t\t\t\tif (local) {\n\t\t\t\t\tpending.local.push(value);\n\t\t\t\t} else {\n\t\t\t\t\t// we only track remotes if there are adjusts, as only adjusts make application anti-commutative\n\t\t\t\t\t// this will limit the impact of this change to only those using adjusts. Additionally, we only\n\t\t\t\t\t// need to track remotes at all to support emitting the legacy snapshot format, which only sharedstring\n\t\t\t\t\t// uses. when we remove the ability to emit that format, we can remove all remote op tracking\n\t\t\t\t\tif (value.raw !== undefined && pending.remote.empty) {\n\t\t\t\t\t\tpending.msnConsensus = computePropertyValue(pending.msnConsensus, [value]);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpending.remote.push(value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\t\tpending.msnConsensus,\n\t\t\t\t\tpending.remote.map((n) => n.data),\n\t\t\t\t\tpending.local.map((n) => n.data),\n\t\t\t\t);\n\t\t\t\tif (local || pending.local.empty || properties[key] !== previousValue) {\n\t\t\t\t\tdeltas[key] = previousValue;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tproperties[key] = computePropertyValue(previousValue, [value]);\n\t\t\t\tdeltas[key] = previousValue;\n\t\t\t}\n\t\t});\n\t\tthis.updateMsn(msn);\n\t\treturn rtn;\n\t}\n\n\t/**\n\t * Acknowledges property changes.\n\t * This method acknowledges the property changes based on the provided sequence number and operation.\n\t *\n\t * @param seq - The sequence number for the operation.\n\t * @param msn - The minimum sequence number for the operation.\n\t * @param op - The operation containing property changes.\n\t */\n\tpublic ack(seq: number, msn: number, op: PropsOrAdjust): void {\n\t\tfor (const [key, value] of opToChanges(op, seq)) {\n\t\t\tconst change = this.changes.get(key);\n\t\t\tconst acked = change?.local?.shift();\n\t\t\tassert(\n\t\t\t\tchange !== undefined && acked !== undefined,\n\t\t\t\t0xa71 /* must have local change to ack */,\n\t\t\t);\n\t\t\t// we only track remotes if there are adjusts, as only adjusts make application anti-commutative\n\t\t\t// this will limit the impact of this change to only those using adjusts. Additionally, we only\n\t\t\t// need to track remotes at all to support emitting the legacy snapshot format, which only sharedstring\n\t\t\t// uses. when we remove the ability to emit that format, we can remove all remote op tracking\n\t\t\tif (value.raw !== undefined && change.remote.empty) {\n\t\t\t\tchange.msnConsensus = computePropertyValue(change.msnConsensus, [value]);\n\t\t\t} else {\n\t\t\t\tchange.remote.push(value);\n\t\t\t}\n\t\t}\n\t\tthis.updateMsn(msn);\n\t}\n\n\t/**\n\t * Updates the minimum sequence number (msn).\n\t * This method updates the minimum sequence number and removes any changes that have been acknowledged.\n\t *\n\t * @param msn - The minimum sequence number to update.\n\t */\n\tpublic updateMsn(msn: number): void {\n\t\tfor (const [key, pending] of this.changes) {\n\t\t\tpending.msnConsensus = computePropertyValue(\n\t\t\t\tpending.msnConsensus,\n\t\t\t\titerateListValuesWhile(pending.remote.first, (n) => {\n\t\t\t\t\tif (n.data.seq <= msn) {\n\t\t\t\t\t\tn.list?.remove(n);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\treturn false;\n\t\t\t\t}),\n\t\t\t);\n\t\t\tif (pending.local.empty && pending.remote.empty) {\n\t\t\t\tthis.changes.delete(key);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Copies properties to another manager.\n\t * This method copies the properties and their changes from the current manager to the destination manager.\n\t *\n\t * @param oldProps - The old properties to be copied.\n\t * @param dest - The destination object containing properties and property manager.\n\t */\n\tpublic copyTo(\n\t\toldProps: PropertySet | undefined,\n\t\tdest: {\n\t\t\tproperties?: PropertySet;\n\t\t\tpropertyManager?: PropertiesManager;\n\t\t},\n\t): void {\n\t\tconst newManager = (dest.propertyManager ??= new PropertiesManager());\n\t\tdest.properties = clone(oldProps);\n\t\tfor (const [key, { local, remote, msnConsensus }] of this.changes.entries()) {\n\t\t\tnewManager.changes.set(key, {\n\t\t\t\tmsnConsensus,\n\t\t\t\tremote: new DoublyLinkedList(remote.empty ? undefined : remote.map((c) => c.data)),\n\t\t\t\tlocal: new DoublyLinkedList(local.empty ? undefined : local.map((c) => c.data)),\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Gets properties at a specific sequence number.\n\t * This method retrieves the properties at the given sequence number.\n\t * This is only needed to support emitting snapshots in the legacy format.\n\t * If we remove the ability to emit the legacy format, we can remove this method, along with the need to track remote changes at all.\n\t *\n\t * @param oldProps - The old properties to be retrieved.\n\t * @param sequenceNumber - The sequence number to get properties at.\n\t * @returns The properties at the given sequence number.\n\t */\n\tpublic getAtSeq(\n\t\toldProps: MapLike<unknown> | undefined,\n\t\tsequenceNumber: number,\n\t): MapLike<unknown> {\n\t\tconst properties: MapLike<unknown> = { ...oldProps };\n\t\tfor (const [key, changes] of this.changes) {\n\t\t\tproperties[key] = computePropertyValue(\n\t\t\t\tchanges.msnConsensus,\n\t\t\t\titerateListValuesWhile(changes.remote.first, (c) => c.data.seq <= sequenceNumber),\n\t\t\t);\n\t\t\tif (properties[key] === null) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\t\tdelete properties[key];\n\t\t\t}\n\t\t}\n\t\treturn properties;\n\t}\n\n\t/**\n\t * Determines if all of the defined properties in a given property set are pending.\n\t *\n\t * @param props - The properties to check.\n\t * @returns True if all the properties are pending, false otherwise.\n\t */\n\tpublic hasPendingProperties(props: PropertySet): boolean {\n\t\tfor (const [key, value] of Object.entries(props)) {\n\t\t\tif (value !== undefined && this.changes.get(key)?.local.empty !== false) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshotLoader.d.ts","sourceRoot":"","sources":["../src/snapshotLoader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAC/E,OAAO,EACN,mBAAmB,EAGnB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"snapshotLoader.d.ts","sourceRoot":"","sources":["../src/snapshotLoader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAC/E,OAAO,EACN,mBAAmB,EAGnB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAoB3C,qBAAa,cAAc;IAIzB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAExB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAE1B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAR5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;gBAG3B,OAAO,EAAE,sBAAsB,EAE/B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACrC,MAAM,EAAE,mBAAmB,EACV,UAAU,EAAE,gBAAgB;IAKjC,UAAU,CACtB,QAAQ,EAAE,sBAAsB,GAC9B,OAAO,CAAC;QAAE,WAAW,EAAE,OAAO,CAAC,yBAAyB,EAAE,CAAC,CAAA;KAAE,CAAC;YAiBnD,qBAAqB;IA2BnC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAgF5B;IAEF,OAAO,CAAC,UAAU;YAsCJ,QAAQ;IAuFtB,OAAO,CAAC,kBAAkB;IAsB1B;;;;;OAKG;YACW,cAAc;CAQ5B"}
|
package/lib/snapshotLoader.js
CHANGED
|
@@ -8,10 +8,12 @@ import { AttachState } from "@fluidframework/container-definitions";
|
|
|
8
8
|
import { assert } from "@fluidframework/core-utils/internal";
|
|
9
9
|
import { UsageError, createChildLogger, } from "@fluidframework/telemetry-utils/internal";
|
|
10
10
|
import { NonCollabClient, UniversalSequenceNumber } from "./constants.js";
|
|
11
|
+
import { PriorPerspective } from "./perspective.js";
|
|
11
12
|
import { overwriteInfo, } from "./segmentInfos.js";
|
|
12
13
|
import { hasMergeInfo, } from "./snapshotChunks.js";
|
|
13
14
|
import { SnapshotV1 } from "./snapshotV1.js";
|
|
14
15
|
import { SnapshotLegacy } from "./snapshotlegacy.js";
|
|
16
|
+
import * as opstampUtils from "./stamps.js";
|
|
15
17
|
export class SnapshotLoader {
|
|
16
18
|
constructor(runtime, client, mergeTree, logger, serializer) {
|
|
17
19
|
this.runtime = runtime;
|
|
@@ -21,11 +23,15 @@ export class SnapshotLoader {
|
|
|
21
23
|
this.specToSegment = (spec) => {
|
|
22
24
|
if (hasMergeInfo(spec)) {
|
|
23
25
|
const seg = overwriteInfo(this.client.specToSegment(spec.json), {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
:
|
|
27
|
-
|
|
26
|
+
insert: {
|
|
27
|
+
type: "insert",
|
|
28
|
+
seq: spec.seq ?? UniversalSequenceNumber,
|
|
29
|
+
clientId: spec.client === undefined
|
|
30
|
+
? NonCollabClient
|
|
31
|
+
: this.client.getOrAddShortClientId(spec.client),
|
|
32
|
+
},
|
|
28
33
|
});
|
|
34
|
+
const removes = [];
|
|
29
35
|
if (spec.removedSeq !== undefined) {
|
|
30
36
|
// this format had a bug where it didn't store all the overlap clients
|
|
31
37
|
// this is for back compat, so we change the singular id to an array
|
|
@@ -36,24 +42,39 @@ export class SnapshotLoader {
|
|
|
36
42
|
spec.removedClientIds ??= [specAsBuggyFormat.removedClient];
|
|
37
43
|
}
|
|
38
44
|
assert(spec.removedClientIds !== undefined, 0xaac /* must have removedClient ids */);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
const firstRemovedSeq = spec.removedSeq;
|
|
46
|
+
// TODO:AB#32299: To correctly support perspectives from other clients which don't assume they have seen
|
|
47
|
+
// all ops, we need to actually record these in the summary. For now we use fake data, and it turns
|
|
48
|
+
// out ok since none of these values end up being used. (specifically, the 'firstRemovedSeq' is fake
|
|
49
|
+
// for all values other than the actual first remove).
|
|
50
|
+
// This issue only affects V1 summaries, as the strategy in snapshotlegacy avoids storing merge info directly.
|
|
51
|
+
removes.push(...spec.removedClientIds.map((id) => ({
|
|
52
|
+
type: "setRemove",
|
|
53
|
+
seq: firstRemovedSeq,
|
|
54
|
+
clientId: this.client.getOrAddShortClientId(id),
|
|
55
|
+
})));
|
|
43
56
|
}
|
|
44
57
|
if (spec.movedSeq !== undefined) {
|
|
45
58
|
assert(spec.movedClientIds !== undefined && spec.movedSeqs !== undefined, 0xaa5 /* must have movedIds ids */);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
59
|
+
assert(spec.movedClientIds.length === spec.movedSeqs.length, 0xb5f /* Expected same length for client ids and seqs */);
|
|
60
|
+
removes.push(...spec.movedClientIds.map((id, i) => ({
|
|
61
|
+
type: "sliceRemove",
|
|
62
|
+
seq: spec.movedSeqs[i],
|
|
63
|
+
clientId: this.client.getOrAddShortClientId(id),
|
|
64
|
+
})));
|
|
65
|
+
}
|
|
66
|
+
if (removes.length > 0) {
|
|
67
|
+
removes.sort(opstampUtils.compare);
|
|
68
|
+
overwriteInfo(seg, { removes });
|
|
51
69
|
}
|
|
52
70
|
return seg;
|
|
53
71
|
}
|
|
54
72
|
return overwriteInfo(this.client.specToSegment(spec), {
|
|
55
|
-
|
|
56
|
-
|
|
73
|
+
insert: {
|
|
74
|
+
type: "insert",
|
|
75
|
+
seq: UniversalSequenceNumber,
|
|
76
|
+
clientId: NonCollabClient,
|
|
77
|
+
},
|
|
57
78
|
});
|
|
58
79
|
};
|
|
59
80
|
this.logger = createChildLogger({ logger, namespace: "SnapshotLoader" });
|
|
@@ -138,9 +159,8 @@ export class SnapshotLoader {
|
|
|
138
159
|
assert(chunk1.segmentCount + segs.length === headerMetadata.totalSegmentCount, 0x064 /* "Mismatch in totalSegmentCount" */);
|
|
139
160
|
// Helper to insert segments at the end of the MergeTree.
|
|
140
161
|
const mergeTree = this.mergeTree;
|
|
141
|
-
const append = (segments,
|
|
142
|
-
mergeTree.insertSegments(mergeTree.root.cachedLength ?? 0, segments,
|
|
143
|
-
/* refSeq: */ UniversalSequenceNumber, cli, seq, undefined);
|
|
162
|
+
const append = (segments, clientId, seq) => {
|
|
163
|
+
mergeTree.insertSegments(mergeTree.root.cachedLength ?? 0, segments, new PriorPerspective(UniversalSequenceNumber, clientId), { seq, clientId }, undefined);
|
|
144
164
|
};
|
|
145
165
|
// Helpers to batch-insert segments that are below the min seq
|
|
146
166
|
const batch = [];
|
|
@@ -150,7 +170,7 @@ export class SnapshotLoader {
|
|
|
150
170
|
}
|
|
151
171
|
};
|
|
152
172
|
for (const seg of segs) {
|
|
153
|
-
const { clientId, seq } = seg;
|
|
173
|
+
const { clientId, seq } = seg.insert;
|
|
154
174
|
// If the segment can be batch inserted, add it to the 'batch' array. Otherwise, flush
|
|
155
175
|
// any batched segments and then insert the current segment individually.
|
|
156
176
|
if (clientId === NonCollabClient && seq === UniversalSequenceNumber) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshotLoader.js","sourceRoot":"","sources":["../src/snapshotLoader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,6DAA6D;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAO7D,OAAO,EAEN,UAAU,EACV,iBAAiB,GACjB,MAAM,0CAA0C,CAAC;AAGlD,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAI1E,OAAO,EAEN,aAAa,GAIb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAGN,YAAY,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM,OAAO,cAAc;IAG1B,YACkB,OAA+B,EAE/B,MAAc,EACd,SAAoB,EACrC,MAA2B,EACV,UAA4B;QAL5B,YAAO,GAAP,OAAO,CAAwB;QAE/B,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAW;QAEpB,eAAU,GAAV,UAAU,CAAkB;QAmD7B,kBAAa,GAAG,CAChC,IAA8C,EACZ,EAAE;YACpC,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;gBACxB,MAAM,GAAG,GAAG,aAAa,CAAiB,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;oBAC/E,QAAQ,EACP,IAAI,CAAC,MAAM,KAAK,SAAS;wBACxB,CAAC,CAAC,eAAe;wB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C,MAAM,CAAC,CAAC;YACrB,CAAC;YACD,UAAU,CAAC,8BAA8B,CAAC,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;QACxE,CAAC;aAAM,CAAC;YACP,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;YAC7C,IAAI,iBAAiB,EAAE,UAAU,EAAE,CAAC;gBACnC,iBAAiB,EAAE,MAAM,EAAE,CAAC;YAC7B,CAAC;QACF,CAAC;IACF,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,cAAc,CAC3B,WAAqC,EACrC,UAA4B;QAE5B,OAAO,UAAU,CAAC,KAAK,CACtB,cAAc,CAAC,MAAM,WAAW,EAAE,MAAM,CAAC,CACV,CAAC;IAClC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tUsageError,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { Client } from \"./client.js\";\nimport { NonCollabClient, UniversalSequenceNumber } from \"./constants.js\";\nimport { MergeTree } from \"./mergeTree.js\";\nimport { ISegmentPrivate } from \"./mergeTreeNodes.js\";\nimport { IJSONSegment } from \"./ops.js\";\nimport {\n\tIRemovalInfo,\n\toverwriteInfo,\n\ttype IInsertionInfo,\n\ttype IMoveInfo,\n\ttype SegmentWithInfo,\n} from \"./segmentInfos.js\";\nimport {\n\tIJSONSegmentWithMergeInfo,\n\tMergeTreeChunkV1,\n\thasMergeInfo,\n} from \"./snapshotChunks.js\";\nimport { SnapshotV1 } from \"./snapshotV1.js\";\nimport { SnapshotLegacy } from \"./snapshotlegacy.js\";\n\nexport class SnapshotLoader {\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tconstructor(\n\t\tprivate readonly runtime: IFluidDataStoreRuntime,\n\n\t\tprivate readonly client: Client,\n\t\tprivate readonly mergeTree: MergeTree,\n\t\tlogger: ITelemetryLoggerExt,\n\t\tprivate readonly serializer: IFluidSerializer,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"SnapshotLoader\" });\n\t}\n\n\tpublic async initialize(\n\t\tservices: IChannelStorageService,\n\t): Promise<{ catchupOpsP: Promise<ISequencedDocumentMessage[]> }> {\n\t\tconst headerLoadedP = services.readBlob(SnapshotLegacy.header).then((header) => {\n\t\t\tassert(!!header, 0x05f /* \"Missing blob header on legacy snapshot!\" */);\n\t\t\treturn this.loadHeader(bufferToString(header, \"utf8\"));\n\t\t});\n\n\t\tconst catchupOpsP = this.loadBodyAndCatchupOps(headerLoadedP, services);\n\n\t\tcatchupOpsP.catch((error) =>\n\t\t\tthis.logger.sendErrorEvent({ eventName: \"CatchupOpsLoadFailure\" }, error),\n\t\t);\n\n\t\tawait headerLoadedP;\n\n\t\treturn { catchupOpsP };\n\t}\n\n\tprivate async loadBodyAndCatchupOps(\n\t\theaderChunkP: Promise<MergeTreeChunkV1>,\n\t\tservices: IChannelStorageService,\n\t): Promise<ISequencedDocumentMessage[]> {\n\t\tconst blobsP = services.list(\"\");\n\t\tconst headerChunk = await headerChunkP;\n\n\t\t// TODO we shouldn't need to wait on the body being complete to finish initialization.\n\t\t// To fully support this we need to be able to process inbound ops for pending segments.\n\t\tawait this.loadBody(headerChunk, services);\n\n\t\tconst blobs = await blobsP;\n\t\tif (blobs.length === headerChunk.headerMetadata!.orderedChunkMetadata.length + 1) {\n\t\t\tfor (const md of headerChunk.headerMetadata!.orderedChunkMetadata)\n\t\t\t\tblobs.splice(blobs.indexOf(md.id), 1);\n\t\t\tassert(blobs.length === 1, 0x060 /* There should be only one blob with catch up ops */);\n\n\t\t\t// TODO: The 'Snapshot.catchupOps' tree entry is purely for backwards compatibility.\n\t\t\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\n\t\t\treturn this.loadCatchupOps(services.readBlob(blobs[0]), this.serializer);\n\t\t} else if (blobs.length !== headerChunk.headerMetadata!.orderedChunkMetadata.length) {\n\t\t\tthrow new Error(\"Unexpected blobs in snapshot\");\n\t\t}\n\t\treturn [];\n\t}\n\n\tprivate readonly specToSegment = (\n\t\tspec: IJSONSegment | IJSONSegmentWithMergeInfo,\n\t): SegmentWithInfo<IInsertionInfo> => {\n\t\tif (hasMergeInfo(spec)) {\n\t\t\tconst seg = overwriteInfo<IInsertionInfo>(this.client.specToSegment(spec.json), {\n\t\t\t\tclientId:\n\t\t\t\t\tspec.client === undefined\n\t\t\t\t\t\t? NonCollabClient\n\t\t\t\t\t\t: this.client.getOrAddShortClientId(spec.client),\n\t\t\t\tseq: spec.seq ?? UniversalSequenceNumber,\n\t\t\t});\n\n\t\t\tif (spec.removedSeq !== undefined) {\n\t\t\t\t// this format had a bug where it didn't store all the overlap clients\n\t\t\t\t// this is for back compat, so we change the singular id to an array\n\t\t\t\t// this will only cause problems if there is an overlapping delete\n\t\t\t\t// spanning the snapshot, which should be rare\n\t\t\t\tconst specAsBuggyFormat: IJSONSegmentWithMergeInfo & { removedClient?: string } = spec;\n\t\t\t\tif (specAsBuggyFormat.removedClient !== undefined) {\n\t\t\t\t\tspec.removedClientIds ??= [specAsBuggyFormat.removedClient];\n\t\t\t\t}\n\t\t\t\tassert(spec.removedClientIds !== undefined, 0xaac /* must have removedClient ids */);\n\t\t\t\toverwriteInfo<IRemovalInfo>(seg, {\n\t\t\t\t\tremovedSeq: spec.removedSeq,\n\t\t\t\t\tremovedClientIds: spec.removedClientIds.map((id) =>\n\t\t\t\t\t\tthis.client.getOrAddShortClientId(id),\n\t\t\t\t\t),\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (spec.movedSeq !== undefined) {\n\t\t\t\tassert(\n\t\t\t\t\tspec.movedClientIds !== undefined && spec.movedSeqs !== undefined,\n\t\t\t\t\t0xaa5 /* must have movedIds ids */,\n\t\t\t\t);\n\t\t\t\toverwriteInfo<IMoveInfo>(seg, {\n\t\t\t\t\tmovedSeq: spec.movedSeq,\n\t\t\t\t\tmovedSeqs: spec.movedSeqs,\n\t\t\t\t\tmovedClientIds: spec.movedClientIds.map((id) =>\n\t\t\t\t\t\tthis.client.getOrAddShortClientId(id),\n\t\t\t\t\t),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn seg;\n\t\t}\n\t\treturn overwriteInfo(this.client.specToSegment(spec), {\n\t\t\tseq: UniversalSequenceNumber,\n\t\t\tclientId: NonCollabClient,\n\t\t});\n\t};\n\n\tprivate loadHeader(header: string): MergeTreeChunkV1 {\n\t\tconst chunk = SnapshotV1.processChunk(\n\t\t\tSnapshotLegacy.header,\n\t\t\theader,\n\t\t\tthis.logger,\n\t\t\tthis.mergeTree.options,\n\t\t\tthis.serializer,\n\t\t);\n\t\tconst segs = chunk.segments.map((element) => this.specToSegment(element));\n\t\tthis.extractAttribution(segs, chunk);\n\n\t\tthis.mergeTree.reloadFromSegments(segs);\n\n\t\tif (chunk.headerMetadata === undefined) {\n\t\t\tthrow new Error(\"header metadata not available\");\n\t\t}\n\t\t// If we load a detached container from snapshot, then we don't supply a default clientId\n\t\t// because we don't want to start collaboration.\n\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\t// specify a default client id, \"snapshot\" here as we\n\t\t\t// should enter collaboration/op sending mode if we load\n\t\t\t// a snapshot in any case (summary or attach message)\n\t\t\t// once we get a client id this will be called with that\n\t\t\t// clientId in the connected event\n\t\t\tthis.client.startOrUpdateCollaboration(\n\t\t\t\tthis.runtime.clientId ?? \"snapshot\",\n\n\t\t\t\t// TODO: Make 'minSeq' non-optional once the new snapshot format becomes the default?\n\t\t\t\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\t\t\t\t/* minSeq: */ chunk.headerMetadata.minSequenceNumber ??\n\t\t\t\t\tchunk.headerMetadata.sequenceNumber,\n\t\t\t\t/* currentSeq: */ chunk.headerMetadata.sequenceNumber,\n\t\t\t);\n\t\t}\n\n\t\treturn chunk;\n\t}\n\n\tprivate async loadBody(\n\t\tchunk1: MergeTreeChunkV1,\n\t\tservices: IChannelStorageService,\n\t): Promise<void> {\n\t\tconst headerMetadata = chunk1.headerMetadata!;\n\t\tassert(chunk1.length <= headerMetadata.totalLength, 0x061 /* \"Mismatch in totalLength\" */);\n\n\t\tassert(\n\t\t\tchunk1.segmentCount <= headerMetadata.totalSegmentCount,\n\t\t\t0x062 /* \"Mismatch in totalSegmentCount\" */,\n\t\t);\n\n\t\tif (chunk1.segmentCount === headerMetadata.totalSegmentCount) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet chunksWithAttribution = chunk1.attribution === undefined ? 0 : 1;\n\t\tconst segs: SegmentWithInfo<IInsertionInfo>[] = [];\n\t\tlet lengthSofar = chunk1.length;\n\t\tfor (\n\t\t\tlet chunkIndex = 1;\n\t\t\tchunkIndex < headerMetadata.orderedChunkMetadata.length;\n\t\t\tchunkIndex++\n\t\t) {\n\t\t\tconst chunk = await SnapshotV1.loadChunk(\n\t\t\t\tservices,\n\t\t\t\theaderMetadata.orderedChunkMetadata[chunkIndex].id,\n\t\t\t\tthis.logger,\n\t\t\t\tthis.mergeTree.options,\n\t\t\t\tthis.serializer,\n\t\t\t);\n\t\t\tlengthSofar += chunk.length;\n\t\t\t// Deserialize each chunk segment and append it to the end of the MergeTree.\n\t\t\tconst newSegs = chunk.segments.map((element) => this.specToSegment(element));\n\t\t\tthis.extractAttribution(newSegs, chunk);\n\t\t\tchunksWithAttribution += chunk.attribution === undefined ? 0 : 1;\n\t\t\tsegs.push(...newSegs);\n\t\t}\n\n\t\tassert(\n\t\t\tchunksWithAttribution === 0 ||\n\t\t\t\tchunksWithAttribution === headerMetadata.orderedChunkMetadata.length,\n\t\t\t0x4c0 /* all or no chunks should have attribution information */,\n\t\t);\n\n\t\tassert(lengthSofar === headerMetadata.totalLength, 0x063 /* \"Mismatch in totalLength\" */);\n\n\t\tassert(\n\t\t\tchunk1.segmentCount + segs.length === headerMetadata.totalSegmentCount,\n\t\t\t0x064 /* \"Mismatch in totalSegmentCount\" */,\n\t\t);\n\n\t\t// Helper to insert segments at the end of the MergeTree.\n\t\tconst mergeTree = this.mergeTree;\n\t\tconst append = (segments: ISegmentPrivate[], cli: number, seq: number): void => {\n\t\t\tmergeTree.insertSegments(\n\t\t\t\tmergeTree.root.cachedLength ?? 0,\n\t\t\t\tsegments,\n\t\t\t\t/* refSeq: */ UniversalSequenceNumber,\n\t\t\t\tcli,\n\t\t\t\tseq,\n\t\t\t\tundefined,\n\t\t\t);\n\t\t};\n\n\t\t// Helpers to batch-insert segments that are below the min seq\n\t\tconst batch: SegmentWithInfo<IInsertionInfo>[] = [];\n\t\tconst flushBatch = (): void => {\n\t\t\tif (batch.length > 0) {\n\t\t\t\tappend(batch, NonCollabClient, UniversalSequenceNumber);\n\t\t\t}\n\t\t};\n\n\t\tfor (const seg of segs) {\n\t\t\tconst { clientId, seq } = seg;\n\t\t\t// If the segment can be batch inserted, add it to the 'batch' array. Otherwise, flush\n\t\t\t// any batched segments and then insert the current segment individually.\n\t\t\tif (clientId === NonCollabClient && seq === UniversalSequenceNumber) {\n\t\t\t\tbatch.push(seg);\n\t\t\t} else {\n\t\t\t\tflushBatch();\n\t\t\t\tappend([seg], clientId, seq);\n\t\t\t}\n\t\t}\n\n\t\tflushBatch();\n\t}\n\n\tprivate extractAttribution(segments: ISegmentPrivate[], chunk: MergeTreeChunkV1): void {\n\t\tif (chunk.attribution) {\n\t\t\tconst { attributionPolicy } = this.mergeTree;\n\t\t\tif (attributionPolicy === undefined) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"Attribution policy must be provided when loading a document with attribution information.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst { isAttached, attach, serializer } = attributionPolicy;\n\t\t\tif (!isAttached) {\n\t\t\t\tattach(this.client);\n\t\t\t}\n\t\t\tserializer.populateAttributionCollections(segments, chunk.attribution);\n\t\t} else {\n\t\t\tconst { attributionPolicy } = this.mergeTree;\n\t\t\tif (attributionPolicy?.isAttached) {\n\t\t\t\tattributionPolicy?.detach();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * If loading from a snapshot, get the catchup messages.\n\t * @param rawMessages - The messages in original encoding\n\t * @returns The decoded messages with parsed+hydrated handles. Matches the format that will be passed in\n\t * SharedObject.processCore.\n\t */\n\tprivate async loadCatchupOps(\n\t\trawMessages: Promise<ArrayBufferLike>,\n\t\tserializer: IFluidSerializer,\n\t): Promise<ISequencedDocumentMessage[]> {\n\t\treturn serializer.parse(\n\t\t\tbufferToString(await rawMessages, \"utf8\"),\n\t\t) as ISequencedDocumentMessage[];\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"snapshotLoader.js","sourceRoot":"","sources":["../src/snapshotLoader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,6DAA6D;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAO7D,OAAO,EAEN,UAAU,EACV,iBAAiB,GACjB,MAAM,0CAA0C,CAAC;AAGlD,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAI1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAEN,aAAa,GAGb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAGN,YAAY,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAA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YAC7D,IAAI,CAAC,UAAU,EAAE,CAAC;gBACjB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACrB,CAAC;YACD,UAAU,CAAC,8BAA8B,CAAC,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;QACxE,CAAC;aAAM,CAAC;YACP,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;YAC7C,IAAI,iBAAiB,EAAE,UAAU,EAAE,CAAC;gBACnC,iBAAiB,EAAE,MAAM,EAAE,CAAC;YAC7B,CAAC;QACF,CAAC;IACF,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,cAAc,CAC3B,WAAqC,EACrC,UAA4B;QAE5B,OAAO,UAAU,CAAC,KAAK,CACtB,cAAc,CAAC,MAAM,WAAW,EAAE,MAAM,CAAC,CACV,CAAC;IAClC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tUsageError,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { Client } from \"./client.js\";\nimport { NonCollabClient, UniversalSequenceNumber } from \"./constants.js\";\nimport { MergeTree } from \"./mergeTree.js\";\nimport { ISegmentPrivate } from \"./mergeTreeNodes.js\";\nimport { IJSONSegment } from \"./ops.js\";\nimport { PriorPerspective } from \"./perspective.js\";\nimport {\n\tIHasRemovalInfo,\n\toverwriteInfo,\n\ttype IHasInsertionInfo,\n\ttype SegmentWithInfo,\n} from \"./segmentInfos.js\";\nimport {\n\tIJSONSegmentWithMergeInfo,\n\tMergeTreeChunkV1,\n\thasMergeInfo,\n} from \"./snapshotChunks.js\";\nimport { SnapshotV1 } from \"./snapshotV1.js\";\nimport { SnapshotLegacy } from \"./snapshotlegacy.js\";\nimport type { RemoveOperationStamp } from \"./stamps.js\";\nimport * as opstampUtils from \"./stamps.js\";\n\nexport class SnapshotLoader {\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tconstructor(\n\t\tprivate readonly runtime: IFluidDataStoreRuntime,\n\n\t\tprivate readonly client: Client,\n\t\tprivate readonly mergeTree: MergeTree,\n\t\tlogger: ITelemetryLoggerExt,\n\t\tprivate readonly serializer: IFluidSerializer,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"SnapshotLoader\" });\n\t}\n\n\tpublic async initialize(\n\t\tservices: IChannelStorageService,\n\t): Promise<{ catchupOpsP: Promise<ISequencedDocumentMessage[]> }> {\n\t\tconst headerLoadedP = services.readBlob(SnapshotLegacy.header).then((header) => {\n\t\t\tassert(!!header, 0x05f /* \"Missing blob header on legacy snapshot!\" */);\n\t\t\treturn this.loadHeader(bufferToString(header, \"utf8\"));\n\t\t});\n\n\t\tconst catchupOpsP = this.loadBodyAndCatchupOps(headerLoadedP, services);\n\n\t\tcatchupOpsP.catch((error) =>\n\t\t\tthis.logger.sendErrorEvent({ eventName: \"CatchupOpsLoadFailure\" }, error),\n\t\t);\n\n\t\tawait headerLoadedP;\n\n\t\treturn { catchupOpsP };\n\t}\n\n\tprivate async loadBodyAndCatchupOps(\n\t\theaderChunkP: Promise<MergeTreeChunkV1>,\n\t\tservices: IChannelStorageService,\n\t): Promise<ISequencedDocumentMessage[]> {\n\t\tconst blobsP = services.list(\"\");\n\t\tconst headerChunk = await headerChunkP;\n\n\t\t// TODO we shouldn't need to wait on the body being complete to finish initialization.\n\t\t// To fully support this we need to be able to process inbound ops for pending segments.\n\t\tawait this.loadBody(headerChunk, services);\n\n\t\tconst blobs = await blobsP;\n\t\tif (blobs.length === headerChunk.headerMetadata!.orderedChunkMetadata.length + 1) {\n\t\t\tfor (const md of headerChunk.headerMetadata!.orderedChunkMetadata)\n\t\t\t\tblobs.splice(blobs.indexOf(md.id), 1);\n\t\t\tassert(blobs.length === 1, 0x060 /* There should be only one blob with catch up ops */);\n\n\t\t\t// TODO: The 'Snapshot.catchupOps' tree entry is purely for backwards compatibility.\n\t\t\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\n\t\t\treturn this.loadCatchupOps(services.readBlob(blobs[0]), this.serializer);\n\t\t} else if (blobs.length !== headerChunk.headerMetadata!.orderedChunkMetadata.length) {\n\t\t\tthrow new Error(\"Unexpected blobs in snapshot\");\n\t\t}\n\t\treturn [];\n\t}\n\n\tprivate readonly specToSegment = (\n\t\tspec: IJSONSegment | IJSONSegmentWithMergeInfo,\n\t): SegmentWithInfo<IHasInsertionInfo> => {\n\t\tif (hasMergeInfo(spec)) {\n\t\t\tconst seg = overwriteInfo<IHasInsertionInfo>(this.client.specToSegment(spec.json), {\n\t\t\t\tinsert: {\n\t\t\t\t\ttype: \"insert\",\n\t\t\t\t\tseq: spec.seq ?? UniversalSequenceNumber,\n\t\t\t\t\tclientId:\n\t\t\t\t\t\tspec.client === undefined\n\t\t\t\t\t\t\t? NonCollabClient\n\t\t\t\t\t\t\t: this.client.getOrAddShortClientId(spec.client),\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconst removes: RemoveOperationStamp[] = [];\n\n\t\t\tif (spec.removedSeq !== undefined) {\n\t\t\t\t// this format had a bug where it didn't store all the overlap clients\n\t\t\t\t// this is for back compat, so we change the singular id to an array\n\t\t\t\t// this will only cause problems if there is an overlapping delete\n\t\t\t\t// spanning the snapshot, which should be rare\n\t\t\t\tconst specAsBuggyFormat: IJSONSegmentWithMergeInfo & { removedClient?: string } = spec;\n\t\t\t\tif (specAsBuggyFormat.removedClient !== undefined) {\n\t\t\t\t\tspec.removedClientIds ??= [specAsBuggyFormat.removedClient];\n\t\t\t\t}\n\t\t\t\tassert(spec.removedClientIds !== undefined, 0xaac /* must have removedClient ids */);\n\t\t\t\tconst firstRemovedSeq = spec.removedSeq;\n\t\t\t\t// TODO:AB#32299: To correctly support perspectives from other clients which don't assume they have seen\n\t\t\t\t// all ops, we need to actually record these in the summary. For now we use fake data, and it turns\n\t\t\t\t// out ok since none of these values end up being used. (specifically, the 'firstRemovedSeq' is fake\n\t\t\t\t// for all values other than the actual first remove).\n\t\t\t\t// This issue only affects V1 summaries, as the strategy in snapshotlegacy avoids storing merge info directly.\n\t\t\t\tremoves.push(\n\t\t\t\t\t...spec.removedClientIds.map(\n\t\t\t\t\t\t(id) =>\n\t\t\t\t\t\t\t({\n\t\t\t\t\t\t\t\ttype: \"setRemove\",\n\t\t\t\t\t\t\t\tseq: firstRemovedSeq,\n\t\t\t\t\t\t\t\tclientId: this.client.getOrAddShortClientId(id),\n\t\t\t\t\t\t\t}) as const,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (spec.movedSeq !== undefined) {\n\t\t\t\tassert(\n\t\t\t\t\tspec.movedClientIds !== undefined && spec.movedSeqs !== undefined,\n\t\t\t\t\t0xaa5 /* must have movedIds ids */,\n\t\t\t\t);\n\t\t\t\tassert(\n\t\t\t\t\tspec.movedClientIds.length === spec.movedSeqs.length,\n\t\t\t\t\t0xb5f /* Expected same length for client ids and seqs */,\n\t\t\t\t);\n\n\t\t\t\tremoves.push(\n\t\t\t\t\t...spec.movedClientIds.map(\n\t\t\t\t\t\t(id, i) =>\n\t\t\t\t\t\t\t({\n\t\t\t\t\t\t\t\ttype: \"sliceRemove\",\n\t\t\t\t\t\t\t\tseq: spec.movedSeqs![i],\n\t\t\t\t\t\t\t\tclientId: this.client.getOrAddShortClientId(id),\n\t\t\t\t\t\t\t}) as const,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (removes.length > 0) {\n\t\t\t\tremoves.sort(opstampUtils.compare);\n\t\t\t\toverwriteInfo<IHasRemovalInfo>(seg, { removes });\n\t\t\t}\n\n\t\t\treturn seg;\n\t\t}\n\t\treturn overwriteInfo(this.client.specToSegment(spec), {\n\t\t\tinsert: {\n\t\t\t\ttype: \"insert\",\n\t\t\t\tseq: UniversalSequenceNumber,\n\t\t\t\tclientId: NonCollabClient,\n\t\t\t},\n\t\t});\n\t};\n\n\tprivate loadHeader(header: string): MergeTreeChunkV1 {\n\t\tconst chunk = SnapshotV1.processChunk(\n\t\t\tSnapshotLegacy.header,\n\t\t\theader,\n\t\t\tthis.logger,\n\t\t\tthis.mergeTree.options,\n\t\t\tthis.serializer,\n\t\t);\n\t\tconst segs = chunk.segments.map((element) => this.specToSegment(element));\n\t\tthis.extractAttribution(segs, chunk);\n\n\t\tthis.mergeTree.reloadFromSegments(segs);\n\n\t\tif (chunk.headerMetadata === undefined) {\n\t\t\tthrow new Error(\"header metadata not available\");\n\t\t}\n\t\t// If we load a detached container from snapshot, then we don't supply a default clientId\n\t\t// because we don't want to start collaboration.\n\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\t// specify a default client id, \"snapshot\" here as we\n\t\t\t// should enter collaboration/op sending mode if we load\n\t\t\t// a snapshot in any case (summary or attach message)\n\t\t\t// once we get a client id this will be called with that\n\t\t\t// clientId in the connected event\n\t\t\tthis.client.startOrUpdateCollaboration(\n\t\t\t\tthis.runtime.clientId ?? \"snapshot\",\n\n\t\t\t\t// TODO: Make 'minSeq' non-optional once the new snapshot format becomes the default?\n\t\t\t\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\t\t\t\t/* minSeq: */ chunk.headerMetadata.minSequenceNumber ??\n\t\t\t\t\tchunk.headerMetadata.sequenceNumber,\n\t\t\t\t/* currentSeq: */ chunk.headerMetadata.sequenceNumber,\n\t\t\t);\n\t\t}\n\n\t\treturn chunk;\n\t}\n\n\tprivate async loadBody(\n\t\tchunk1: MergeTreeChunkV1,\n\t\tservices: IChannelStorageService,\n\t): Promise<void> {\n\t\tconst headerMetadata = chunk1.headerMetadata!;\n\t\tassert(chunk1.length <= headerMetadata.totalLength, 0x061 /* \"Mismatch in totalLength\" */);\n\n\t\tassert(\n\t\t\tchunk1.segmentCount <= headerMetadata.totalSegmentCount,\n\t\t\t0x062 /* \"Mismatch in totalSegmentCount\" */,\n\t\t);\n\n\t\tif (chunk1.segmentCount === headerMetadata.totalSegmentCount) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet chunksWithAttribution = chunk1.attribution === undefined ? 0 : 1;\n\t\tconst segs: SegmentWithInfo<IHasInsertionInfo>[] = [];\n\t\tlet lengthSofar = chunk1.length;\n\t\tfor (\n\t\t\tlet chunkIndex = 1;\n\t\t\tchunkIndex < headerMetadata.orderedChunkMetadata.length;\n\t\t\tchunkIndex++\n\t\t) {\n\t\t\tconst chunk = await SnapshotV1.loadChunk(\n\t\t\t\tservices,\n\t\t\t\theaderMetadata.orderedChunkMetadata[chunkIndex].id,\n\t\t\t\tthis.logger,\n\t\t\t\tthis.mergeTree.options,\n\t\t\t\tthis.serializer,\n\t\t\t);\n\t\t\tlengthSofar += chunk.length;\n\t\t\t// Deserialize each chunk segment and append it to the end of the MergeTree.\n\t\t\tconst newSegs = chunk.segments.map((element) => this.specToSegment(element));\n\t\t\tthis.extractAttribution(newSegs, chunk);\n\t\t\tchunksWithAttribution += chunk.attribution === undefined ? 0 : 1;\n\t\t\tsegs.push(...newSegs);\n\t\t}\n\n\t\tassert(\n\t\t\tchunksWithAttribution === 0 ||\n\t\t\t\tchunksWithAttribution === headerMetadata.orderedChunkMetadata.length,\n\t\t\t0x4c0 /* all or no chunks should have attribution information */,\n\t\t);\n\n\t\tassert(lengthSofar === headerMetadata.totalLength, 0x063 /* \"Mismatch in totalLength\" */);\n\n\t\tassert(\n\t\t\tchunk1.segmentCount + segs.length === headerMetadata.totalSegmentCount,\n\t\t\t0x064 /* \"Mismatch in totalSegmentCount\" */,\n\t\t);\n\n\t\t// Helper to insert segments at the end of the MergeTree.\n\t\tconst mergeTree = this.mergeTree;\n\t\tconst append = (segments: ISegmentPrivate[], clientId: number, seq: number): void => {\n\t\t\tmergeTree.insertSegments(\n\t\t\t\tmergeTree.root.cachedLength ?? 0,\n\t\t\t\tsegments,\n\t\t\t\tnew PriorPerspective(UniversalSequenceNumber, clientId),\n\t\t\t\t{ seq, clientId },\n\t\t\t\tundefined,\n\t\t\t);\n\t\t};\n\n\t\t// Helpers to batch-insert segments that are below the min seq\n\t\tconst batch: SegmentWithInfo<IHasInsertionInfo>[] = [];\n\t\tconst flushBatch = (): void => {\n\t\t\tif (batch.length > 0) {\n\t\t\t\tappend(batch, NonCollabClient, UniversalSequenceNumber);\n\t\t\t}\n\t\t};\n\n\t\tfor (const seg of segs) {\n\t\t\tconst { clientId, seq } = seg.insert;\n\t\t\t// If the segment can be batch inserted, add it to the 'batch' array. Otherwise, flush\n\t\t\t// any batched segments and then insert the current segment individually.\n\t\t\tif (clientId === NonCollabClient && seq === UniversalSequenceNumber) {\n\t\t\t\tbatch.push(seg);\n\t\t\t} else {\n\t\t\t\tflushBatch();\n\t\t\t\tappend([seg], clientId, seq);\n\t\t\t}\n\t\t}\n\n\t\tflushBatch();\n\t}\n\n\tprivate extractAttribution(segments: ISegmentPrivate[], chunk: MergeTreeChunkV1): void {\n\t\tif (chunk.attribution) {\n\t\t\tconst { attributionPolicy } = this.mergeTree;\n\t\t\tif (attributionPolicy === undefined) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"Attribution policy must be provided when loading a document with attribution information.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst { isAttached, attach, serializer } = attributionPolicy;\n\t\t\tif (!isAttached) {\n\t\t\t\tattach(this.client);\n\t\t\t}\n\t\t\tserializer.populateAttributionCollections(segments, chunk.attribution);\n\t\t} else {\n\t\t\tconst { attributionPolicy } = this.mergeTree;\n\t\t\tif (attributionPolicy?.isAttached) {\n\t\t\t\tattributionPolicy?.detach();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * If loading from a snapshot, get the catchup messages.\n\t * @param rawMessages - The messages in original encoding\n\t * @returns The decoded messages with parsed+hydrated handles. Matches the format that will be passed in\n\t * SharedObject.processCore.\n\t */\n\tprivate async loadCatchupOps(\n\t\trawMessages: Promise<ArrayBufferLike>,\n\t\tserializer: IFluidSerializer,\n\t): Promise<ISequencedDocumentMessage[]> {\n\t\treturn serializer.parse(\n\t\t\tbufferToString(await rawMessages, \"utf8\"),\n\t\t) as ISequencedDocumentMessage[];\n\t}\n}\n"]}
|
package/lib/snapshotV1.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshotV1.d.ts","sourceRoot":"","sources":["../src/snapshotV1.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AACxF,OAAO,EACN,qBAAqB,EAErB,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAC/E,OAAO,EACN,mBAAmB,EAEnB,MAAM,0CAA0C,CAAC;AAIlD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI3C,OAAO,EAAE,WAAW,EAAmB,MAAM,iBAAiB,CAAC;AAE/D,OAAO,EAEN,gBAAgB,EAChB,gBAAgB,EAKhB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"snapshotV1.d.ts","sourceRoot":"","sources":["../src/snapshotV1.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AACxF,OAAO,EACN,qBAAqB,EAErB,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EA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,CAAC;WAMd,YAAY,CACzB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,WAAW,GAAG,SAAS,EAChC,UAAU,CAAC,EAAE,gBAAgB,GAC3B,gBAAgB;CAMnB"}
|
package/lib/snapshotV1.js
CHANGED
|
@@ -6,12 +6,13 @@ import { bufferToString } from "@fluid-internal/client-utils";
|
|
|
6
6
|
import { assert } from "@fluidframework/core-utils/internal";
|
|
7
7
|
import { SummaryTreeBuilder } from "@fluidframework/runtime-utils/internal";
|
|
8
8
|
import { createChildLogger, } from "@fluidframework/telemetry-utils/internal";
|
|
9
|
-
import {
|
|
9
|
+
import { NonCollabClient } from "./constants.js";
|
|
10
10
|
import { walkAllChildSegments } from "./mergeTreeNodeWalk.js";
|
|
11
11
|
import { matchProperties } from "./properties.js";
|
|
12
|
-
import { assertInserted,
|
|
12
|
+
import { assertInserted, isRemoved } from "./segmentInfos.js";
|
|
13
13
|
import { serializeAsMaxSupportedVersion, toLatestVersion, } from "./snapshotChunks.js";
|
|
14
14
|
import { SnapshotLegacy } from "./snapshotlegacy.js";
|
|
15
|
+
import * as opstampUtils from "./stamps.js";
|
|
15
16
|
export class SnapshotV1 {
|
|
16
17
|
constructor(mergeTree, logger, getLongClientId, filename, onCompletion) {
|
|
17
18
|
this.mergeTree = mergeTree;
|
|
@@ -103,6 +104,7 @@ export class SnapshotV1 {
|
|
|
103
104
|
extractSync() {
|
|
104
105
|
const mergeTree = this.mergeTree;
|
|
105
106
|
const minSeq = this.header.minSequenceNumber;
|
|
107
|
+
const minSeqStamp = { seq: minSeq, clientId: NonCollabClient };
|
|
106
108
|
let originalSegments = 0;
|
|
107
109
|
let segmentsAfterCombine = 0;
|
|
108
110
|
// Helper to add the given `MergeTreeChunkV0SegmentSpec` to the snapshot.
|
|
@@ -132,10 +134,9 @@ export class SnapshotV1 {
|
|
|
132
134
|
// there is a pending insert op that will deliver the segment on reconnection.
|
|
133
135
|
// b) The segment was removed at or below the MSN. Pending ops can no longer reference this
|
|
134
136
|
// segment, and therefore we can discard it.
|
|
135
|
-
if (segment.
|
|
136
|
-
(isRemoved(segment) && segment.
|
|
137
|
-
(
|
|
138
|
-
if (segment.seq !== UnassignedSequenceNumber) {
|
|
137
|
+
if (opstampUtils.isLocal(segment.insert) ||
|
|
138
|
+
(isRemoved(segment) && opstampUtils.lte(segment.removes[0], minSeqStamp))) {
|
|
139
|
+
if (opstampUtils.isAcked(segment.insert)) {
|
|
139
140
|
originalSegments += 1;
|
|
140
141
|
}
|
|
141
142
|
return true;
|
|
@@ -144,10 +145,8 @@ export class SnapshotV1 {
|
|
|
144
145
|
// Next determine if the snapshot needs to preserve information required for merging the segment
|
|
145
146
|
// (seq, client, etc.) This information is only needed if the segment is above the MSN (and doesn't
|
|
146
147
|
// have a pending remove.)
|
|
147
|
-
if (segment.
|
|
148
|
-
(!isRemoved(segment) ||
|
|
149
|
-
segment.removedSeq === UnassignedSequenceNumber) && // .. Removal op to be delivered on reconnect
|
|
150
|
-
(!isMoved(segment) || segment.movedSeq === UnassignedSequenceNumber)) {
|
|
148
|
+
if (opstampUtils.lte(segment.insert, minSeqStamp) && // Segment is below the MSN, and...
|
|
149
|
+
(!isRemoved(segment) || opstampUtils.isLocal(segment.removes[0]))) {
|
|
151
150
|
// This segment is below the MSN, which means that future ops will not reference it. Attempt to
|
|
152
151
|
// coalesce the new segment with the previous (if any).
|
|
153
152
|
if (!prev) {
|
|
@@ -180,27 +179,36 @@ export class SnapshotV1 {
|
|
|
180
179
|
json: segment.toJSONObject(),
|
|
181
180
|
};
|
|
182
181
|
// If the segment insertion is above the MSN, record the insertion merge info.
|
|
183
|
-
if (segment.
|
|
184
|
-
raw.seq = segment.seq;
|
|
185
|
-
raw.client = this.getLongClientId(segment.clientId);
|
|
182
|
+
if (opstampUtils.greaterThan(segment.insert, minSeqStamp)) {
|
|
183
|
+
raw.seq = segment.insert.seq;
|
|
184
|
+
raw.client = this.getLongClientId(segment.insert.clientId);
|
|
186
185
|
}
|
|
187
186
|
// We have already dispensed with removed segments below the MSN and removed segments with unassigned
|
|
188
187
|
// sequence numbers. Any remaining removal info should be preserved.
|
|
189
|
-
if (isRemoved(segment)) {
|
|
190
|
-
|
|
191
|
-
|
|
188
|
+
if (isRemoved(segment) && segment.removes.some((r) => r.type === "setRemove")) {
|
|
189
|
+
const removes = segment.removes.filter((r) => r.type === "setRemove");
|
|
190
|
+
const firstRemove = removes[0];
|
|
191
|
+
assert(opstampUtils.isAcked(firstRemove) &&
|
|
192
|
+
opstampUtils.greaterThan(firstRemove, minSeqStamp), 0x065 /* "On removal info preservation, segment has invalid removed sequence number!" */);
|
|
193
|
+
// TODO:AB#32299 By not preserving sequence numbers other than the first move,
|
|
194
|
+
// We drop data here which will be necessary to allow perspectives of remote clients that
|
|
195
|
+
// don't include all of their ops. This should be remedied at some point.
|
|
196
|
+
raw.removedSeq = firstRemove.seq;
|
|
192
197
|
// back compat for when we split overlap and removed client
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
raw.removedClientIds = segment.removedClientIds?.map((id) => this.getLongClientId(id));
|
|
198
|
+
// This can be removed when we can safely assume no clients running Fluid packages <= 0.58 will ever
|
|
199
|
+
// load a document produced by a version beyond the removal. It is vestigial in the meantime.
|
|
200
|
+
raw.removedClient = this.getLongClientId(firstRemove.clientId);
|
|
201
|
+
raw.removedClientIds = removes.map(({ clientId }) => this.getLongClientId(clientId));
|
|
198
202
|
}
|
|
199
|
-
if (
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
203
|
+
if (isRemoved(segment) && segment.removes.some((r) => r.type === "sliceRemove")) {
|
|
204
|
+
// In this format, we used the term "move" to refer to a sliceRemove/obliterate.
|
|
205
|
+
const moves = segment.removes.filter((r) => r.type === "sliceRemove");
|
|
206
|
+
const firstMove = moves[0];
|
|
207
|
+
assert(opstampUtils.isAcked(firstMove) &&
|
|
208
|
+
opstampUtils.greaterThan(firstMove, minSeqStamp), 0x873 /* On move info preservation, segment has invalid moved sequence number! */);
|
|
209
|
+
raw.movedSeq = firstMove.seq;
|
|
210
|
+
raw.movedSeqs = moves.map(({ seq }) => seq);
|
|
211
|
+
raw.movedClientIds = moves.map(({ clientId }) => this.getLongClientId(clientId));
|
|
204
212
|
}
|
|
205
213
|
// Sanity check that we are preserving either the seq > minSeq or a (re)moved segment's info.
|
|
206
214
|
assert((raw.seq !== undefined && raw.client !== undefined) ||
|