@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.
Files changed (308) hide show
  1. package/CHANGELOG.md +403 -399
  2. package/api-report/merge-tree.legacy.alpha.api.md +1 -0
  3. package/dist/MergeTreeTextHelper.d.ts +9 -3
  4. package/dist/MergeTreeTextHelper.d.ts.map +1 -1
  5. package/dist/MergeTreeTextHelper.js +5 -5
  6. package/dist/MergeTreeTextHelper.js.map +1 -1
  7. package/dist/client.d.ts +7 -13
  8. package/dist/client.d.ts.map +1 -1
  9. package/dist/client.js +136 -110
  10. package/dist/client.js.map +1 -1
  11. package/dist/endOfTreeSegment.d.ts +12 -8
  12. package/dist/endOfTreeSegment.d.ts.map +1 -1
  13. package/dist/endOfTreeSegment.js +2 -4
  14. package/dist/endOfTreeSegment.js.map +1 -1
  15. package/dist/index.d.ts +6 -3
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +2 -3
  18. package/dist/index.js.map +1 -1
  19. package/dist/mergeTree.d.ts +37 -23
  20. package/dist/mergeTree.d.ts.map +1 -1
  21. package/dist/mergeTree.js +400 -483
  22. package/dist/mergeTree.js.map +1 -1
  23. package/dist/mergeTreeDeltaCallback.d.ts +4 -8
  24. package/dist/mergeTreeDeltaCallback.d.ts.map +1 -1
  25. package/dist/mergeTreeDeltaCallback.js.map +1 -1
  26. package/dist/mergeTreeNodes.d.ts +32 -10
  27. package/dist/mergeTreeNodes.d.ts.map +1 -1
  28. package/dist/mergeTreeNodes.js +43 -28
  29. package/dist/mergeTreeNodes.js.map +1 -1
  30. package/dist/partialLengths.d.ts +2 -2
  31. package/dist/partialLengths.d.ts.map +1 -1
  32. package/dist/partialLengths.js +181 -109
  33. package/dist/partialLengths.js.map +1 -1
  34. package/dist/perspective.d.ts +8 -27
  35. package/dist/perspective.d.ts.map +1 -1
  36. package/dist/perspective.js +7 -67
  37. package/dist/perspective.js.map +1 -1
  38. package/dist/revertibles.d.ts.map +1 -1
  39. package/dist/revertibles.js +2 -2
  40. package/dist/revertibles.js.map +1 -1
  41. package/dist/segmentInfos.d.ts +20 -106
  42. package/dist/segmentInfos.d.ts.map +1 -1
  43. package/dist/segmentInfos.js +28 -42
  44. package/dist/segmentInfos.js.map +1 -1
  45. package/dist/segmentPropertiesManager.d.ts +1 -14
  46. package/dist/segmentPropertiesManager.d.ts.map +1 -1
  47. package/dist/segmentPropertiesManager.js +3 -17
  48. package/dist/segmentPropertiesManager.js.map +1 -1
  49. package/dist/snapshotLoader.d.ts.map +1 -1
  50. package/dist/snapshotLoader.js +62 -19
  51. package/dist/snapshotLoader.js.map +1 -1
  52. package/dist/snapshotV1.d.ts.map +1 -1
  53. package/dist/snapshotV1.js +55 -24
  54. package/dist/snapshotV1.js.map +1 -1
  55. package/dist/snapshotlegacy.d.ts.map +1 -1
  56. package/dist/snapshotlegacy.js +6 -9
  57. package/dist/snapshotlegacy.js.map +1 -1
  58. package/dist/stamps.d.ts +1 -1
  59. package/dist/stamps.js +1 -1
  60. package/dist/stamps.js.map +1 -1
  61. package/dist/test/Insertion.perf.spec.js +6 -51
  62. package/dist/test/Insertion.perf.spec.js.map +1 -1
  63. package/dist/test/PartialLengths.perf.spec.js +18 -25
  64. package/dist/test/PartialLengths.perf.spec.js.map +1 -1
  65. package/dist/test/Removal.perf.spec.js +13 -41
  66. package/dist/test/Removal.perf.spec.js.map +1 -1
  67. package/dist/test/beastTest.spec.d.ts.map +1 -1
  68. package/dist/test/beastTest.spec.js +41 -66
  69. package/dist/test/beastTest.spec.js.map +1 -1
  70. package/dist/test/client.annotateMarker.spec.js +1 -11
  71. package/dist/test/client.annotateMarker.spec.js.map +1 -1
  72. package/dist/test/client.applyMsg.spec.js +14 -14
  73. package/dist/test/client.applyMsg.spec.js.map +1 -1
  74. package/dist/test/client.getPosition.spec.js +1 -1
  75. package/dist/test/client.getPosition.spec.js.map +1 -1
  76. package/dist/test/client.localReference.spec.js +1 -1
  77. package/dist/test/client.localReference.spec.js.map +1 -1
  78. package/dist/test/client.rollback.spec.js +49 -58
  79. package/dist/test/client.rollback.spec.js.map +1 -1
  80. package/dist/test/client.rollbackFarm.spec.js +1 -1
  81. package/dist/test/client.rollbackFarm.spec.js.map +1 -1
  82. package/dist/test/client.searchForMarker.spec.js +4 -21
  83. package/dist/test/client.searchForMarker.spec.js.map +1 -1
  84. package/dist/test/index.d.ts +2 -2
  85. package/dist/test/index.d.ts.map +1 -1
  86. package/dist/test/index.js +2 -6
  87. package/dist/test/index.js.map +1 -1
  88. package/dist/test/mergeTree.annotate.deltaCallback.spec.js +14 -59
  89. package/dist/test/mergeTree.annotate.deltaCallback.spec.js.map +1 -1
  90. package/dist/test/mergeTree.annotate.spec.js +47 -63
  91. package/dist/test/mergeTree.annotate.spec.js.map +1 -1
  92. package/dist/test/mergeTree.insert.deltaCallback.spec.js +9 -62
  93. package/dist/test/mergeTree.insert.deltaCallback.spec.js.map +1 -1
  94. package/dist/test/mergeTree.insertingWalk.spec.js +59 -125
  95. package/dist/test/mergeTree.insertingWalk.spec.js.map +1 -1
  96. package/dist/test/mergeTree.markRangeRemoved.deltaCallback.spec.js +12 -93
  97. package/dist/test/mergeTree.markRangeRemoved.deltaCallback.spec.js.map +1 -1
  98. package/dist/test/mergeTree.markRangeRemoved.spec.js +10 -7
  99. package/dist/test/mergeTree.markRangeRemoved.spec.js.map +1 -1
  100. package/dist/test/mergeTree.walk.spec.js +2 -14
  101. package/dist/test/mergeTree.walk.spec.js.map +1 -1
  102. package/dist/test/mergeTreeOperationRunner.js +2 -2
  103. package/dist/test/mergeTreeOperationRunner.js.map +1 -1
  104. package/dist/test/obliterate.concurrent.spec.js +18 -23
  105. package/dist/test/obliterate.concurrent.spec.js.map +1 -1
  106. package/dist/test/obliterate.partialLength.spec.js +166 -136
  107. package/dist/test/obliterate.partialLength.spec.js.map +1 -1
  108. package/dist/test/obliterate.spec.js +16 -126
  109. package/dist/test/obliterate.spec.js.map +1 -1
  110. package/dist/test/partialLength.spec.js +28 -196
  111. package/dist/test/partialLength.spec.js.map +1 -1
  112. package/dist/test/perspective.spec.js +34 -0
  113. package/dist/test/perspective.spec.js.map +1 -1
  114. package/dist/test/propertyManager.spec.js +1 -1
  115. package/dist/test/propertyManager.spec.js.map +1 -1
  116. package/dist/test/resetPendingSegmentsToOp.spec.js +0 -2
  117. package/dist/test/resetPendingSegmentsToOp.spec.js.map +1 -1
  118. package/dist/test/segmentGroupCollection.spec.js +10 -4
  119. package/dist/test/segmentGroupCollection.spec.js.map +1 -1
  120. package/dist/test/testClient.d.ts +1 -0
  121. package/dist/test/testClient.d.ts.map +1 -1
  122. package/dist/test/testClient.js +16 -26
  123. package/dist/test/testClient.js.map +1 -1
  124. package/dist/test/testClientLogger.d.ts.map +1 -1
  125. package/dist/test/testClientLogger.js +3 -10
  126. package/dist/test/testClientLogger.js.map +1 -1
  127. package/dist/test/testServer.d.ts +2 -1
  128. package/dist/test/testServer.d.ts.map +1 -1
  129. package/dist/test/testServer.js +7 -5
  130. package/dist/test/testServer.js.map +1 -1
  131. package/dist/test/testUtils.d.ts +36 -56
  132. package/dist/test/testUtils.d.ts.map +1 -1
  133. package/dist/test/testUtils.js +68 -77
  134. package/dist/test/testUtils.js.map +1 -1
  135. package/dist/test/text.d.ts +2 -2
  136. package/dist/test/text.d.ts.map +1 -1
  137. package/dist/test/text.js +5 -2
  138. package/dist/test/text.js.map +1 -1
  139. package/dist/textSegment.d.ts +0 -6
  140. package/dist/textSegment.d.ts.map +1 -1
  141. package/dist/textSegment.js.map +1 -1
  142. package/dist/zamboni.d.ts.map +1 -1
  143. package/dist/zamboni.js +53 -26
  144. package/dist/zamboni.js.map +1 -1
  145. package/lib/MergeTreeTextHelper.d.ts +9 -3
  146. package/lib/MergeTreeTextHelper.d.ts.map +1 -1
  147. package/lib/MergeTreeTextHelper.js +5 -5
  148. package/lib/MergeTreeTextHelper.js.map +1 -1
  149. package/lib/client.d.ts +7 -13
  150. package/lib/client.d.ts.map +1 -1
  151. package/lib/client.js +117 -116
  152. package/lib/client.js.map +1 -1
  153. package/lib/endOfTreeSegment.d.ts +12 -8
  154. package/lib/endOfTreeSegment.d.ts.map +1 -1
  155. package/lib/endOfTreeSegment.js +2 -4
  156. package/lib/endOfTreeSegment.js.map +1 -1
  157. package/lib/index.d.ts +6 -3
  158. package/lib/index.d.ts.map +1 -1
  159. package/lib/index.js +1 -1
  160. package/lib/index.js.map +1 -1
  161. package/lib/mergeTree.d.ts +37 -23
  162. package/lib/mergeTree.d.ts.map +1 -1
  163. package/lib/mergeTree.js +381 -488
  164. package/lib/mergeTree.js.map +1 -1
  165. package/lib/mergeTreeDeltaCallback.d.ts +4 -8
  166. package/lib/mergeTreeDeltaCallback.d.ts.map +1 -1
  167. package/lib/mergeTreeDeltaCallback.js.map +1 -1
  168. package/lib/mergeTreeNodes.d.ts +32 -10
  169. package/lib/mergeTreeNodes.d.ts.map +1 -1
  170. package/lib/mergeTreeNodes.js +42 -29
  171. package/lib/mergeTreeNodes.js.map +1 -1
  172. package/lib/partialLengths.d.ts +2 -2
  173. package/lib/partialLengths.d.ts.map +1 -1
  174. package/lib/partialLengths.js +160 -111
  175. package/lib/partialLengths.js.map +1 -1
  176. package/lib/perspective.d.ts +8 -27
  177. package/lib/perspective.d.ts.map +1 -1
  178. package/lib/perspective.js +8 -68
  179. package/lib/perspective.js.map +1 -1
  180. package/lib/revertibles.d.ts.map +1 -1
  181. package/lib/revertibles.js +2 -2
  182. package/lib/revertibles.js.map +1 -1
  183. package/lib/segmentInfos.d.ts +20 -106
  184. package/lib/segmentInfos.d.ts.map +1 -1
  185. package/lib/segmentInfos.js +26 -37
  186. package/lib/segmentInfos.js.map +1 -1
  187. package/lib/segmentPropertiesManager.d.ts +1 -14
  188. package/lib/segmentPropertiesManager.d.ts.map +1 -1
  189. package/lib/segmentPropertiesManager.js +2 -16
  190. package/lib/segmentPropertiesManager.js.map +1 -1
  191. package/lib/snapshotLoader.d.ts.map +1 -1
  192. package/lib/snapshotLoader.js +39 -19
  193. package/lib/snapshotLoader.js.map +1 -1
  194. package/lib/snapshotV1.d.ts.map +1 -1
  195. package/lib/snapshotV1.js +34 -26
  196. package/lib/snapshotV1.js.map +1 -1
  197. package/lib/snapshotlegacy.d.ts.map +1 -1
  198. package/lib/snapshotlegacy.js +7 -10
  199. package/lib/snapshotlegacy.js.map +1 -1
  200. package/lib/stamps.d.ts +1 -1
  201. package/lib/stamps.js +1 -1
  202. package/lib/stamps.js.map +1 -1
  203. package/lib/test/Insertion.perf.spec.js +6 -51
  204. package/lib/test/Insertion.perf.spec.js.map +1 -1
  205. package/lib/test/PartialLengths.perf.spec.js +18 -25
  206. package/lib/test/PartialLengths.perf.spec.js.map +1 -1
  207. package/lib/test/Removal.perf.spec.js +13 -41
  208. package/lib/test/Removal.perf.spec.js.map +1 -1
  209. package/lib/test/beastTest.spec.d.ts.map +1 -1
  210. package/lib/test/beastTest.spec.js +42 -67
  211. package/lib/test/beastTest.spec.js.map +1 -1
  212. package/lib/test/client.annotateMarker.spec.js +1 -11
  213. package/lib/test/client.annotateMarker.spec.js.map +1 -1
  214. package/lib/test/client.applyMsg.spec.js +14 -14
  215. package/lib/test/client.applyMsg.spec.js.map +1 -1
  216. package/lib/test/client.getPosition.spec.js +1 -1
  217. package/lib/test/client.getPosition.spec.js.map +1 -1
  218. package/lib/test/client.localReference.spec.js +1 -1
  219. package/lib/test/client.localReference.spec.js.map +1 -1
  220. package/lib/test/client.rollback.spec.js +50 -59
  221. package/lib/test/client.rollback.spec.js.map +1 -1
  222. package/lib/test/client.rollbackFarm.spec.js +1 -1
  223. package/lib/test/client.rollbackFarm.spec.js.map +1 -1
  224. package/lib/test/client.searchForMarker.spec.js +4 -21
  225. package/lib/test/client.searchForMarker.spec.js.map +1 -1
  226. package/lib/test/index.d.ts +2 -2
  227. package/lib/test/index.d.ts.map +1 -1
  228. package/lib/test/index.js +1 -1
  229. package/lib/test/index.js.map +1 -1
  230. package/lib/test/mergeTree.annotate.deltaCallback.spec.js +15 -60
  231. package/lib/test/mergeTree.annotate.deltaCallback.spec.js.map +1 -1
  232. package/lib/test/mergeTree.annotate.spec.js +48 -64
  233. package/lib/test/mergeTree.annotate.spec.js.map +1 -1
  234. package/lib/test/mergeTree.insert.deltaCallback.spec.js +10 -63
  235. package/lib/test/mergeTree.insert.deltaCallback.spec.js.map +1 -1
  236. package/lib/test/mergeTree.insertingWalk.spec.js +61 -127
  237. package/lib/test/mergeTree.insertingWalk.spec.js.map +1 -1
  238. package/lib/test/mergeTree.markRangeRemoved.deltaCallback.spec.js +13 -94
  239. package/lib/test/mergeTree.markRangeRemoved.deltaCallback.spec.js.map +1 -1
  240. package/lib/test/mergeTree.markRangeRemoved.spec.js +10 -7
  241. package/lib/test/mergeTree.markRangeRemoved.spec.js.map +1 -1
  242. package/lib/test/mergeTree.walk.spec.js +2 -14
  243. package/lib/test/mergeTree.walk.spec.js.map +1 -1
  244. package/lib/test/mergeTreeOperationRunner.js +3 -3
  245. package/lib/test/mergeTreeOperationRunner.js.map +1 -1
  246. package/lib/test/obliterate.concurrent.spec.js +18 -23
  247. package/lib/test/obliterate.concurrent.spec.js.map +1 -1
  248. package/lib/test/obliterate.partialLength.spec.js +167 -137
  249. package/lib/test/obliterate.partialLength.spec.js.map +1 -1
  250. package/lib/test/obliterate.spec.js +17 -127
  251. package/lib/test/obliterate.spec.js.map +1 -1
  252. package/lib/test/partialLength.spec.js +29 -197
  253. package/lib/test/partialLength.spec.js.map +1 -1
  254. package/lib/test/perspective.spec.js +34 -0
  255. package/lib/test/perspective.spec.js.map +1 -1
  256. package/lib/test/propertyManager.spec.js +2 -2
  257. package/lib/test/propertyManager.spec.js.map +1 -1
  258. package/lib/test/resetPendingSegmentsToOp.spec.js +0 -2
  259. package/lib/test/resetPendingSegmentsToOp.spec.js.map +1 -1
  260. package/lib/test/segmentGroupCollection.spec.js +10 -4
  261. package/lib/test/segmentGroupCollection.spec.js.map +1 -1
  262. package/lib/test/testClient.d.ts +1 -0
  263. package/lib/test/testClient.d.ts.map +1 -1
  264. package/lib/test/testClient.js +18 -28
  265. package/lib/test/testClient.js.map +1 -1
  266. package/lib/test/testClientLogger.d.ts.map +1 -1
  267. package/lib/test/testClientLogger.js +3 -10
  268. package/lib/test/testClientLogger.js.map +1 -1
  269. package/lib/test/testServer.d.ts +2 -1
  270. package/lib/test/testServer.d.ts.map +1 -1
  271. package/lib/test/testServer.js +7 -5
  272. package/lib/test/testServer.js.map +1 -1
  273. package/lib/test/testUtils.d.ts +36 -56
  274. package/lib/test/testUtils.d.ts.map +1 -1
  275. package/lib/test/testUtils.js +66 -48
  276. package/lib/test/testUtils.js.map +1 -1
  277. package/lib/test/text.d.ts +2 -2
  278. package/lib/test/text.d.ts.map +1 -1
  279. package/lib/test/text.js +6 -3
  280. package/lib/test/text.js.map +1 -1
  281. package/lib/textSegment.d.ts +0 -6
  282. package/lib/textSegment.d.ts.map +1 -1
  283. package/lib/textSegment.js.map +1 -1
  284. package/lib/tsdoc-metadata.json +1 -1
  285. package/lib/zamboni.d.ts.map +1 -1
  286. package/lib/zamboni.js +32 -28
  287. package/lib/zamboni.js.map +1 -1
  288. package/package.json +17 -20
  289. package/src/MergeTreeTextHelper.ts +17 -12
  290. package/src/client.ts +141 -197
  291. package/src/endOfTreeSegment.ts +11 -8
  292. package/src/index.ts +4 -3
  293. package/src/mergeTree.ts +482 -633
  294. package/src/mergeTreeDeltaCallback.ts +4 -8
  295. package/src/mergeTreeNodes.ts +66 -45
  296. package/src/partialLengths.ts +181 -137
  297. package/src/perspective.ts +17 -95
  298. package/src/revertibles.ts +2 -7
  299. package/src/segmentInfos.ts +48 -141
  300. package/src/segmentPropertiesManager.ts +2 -16
  301. package/src/snapshotLoader.ts +62 -30
  302. package/src/snapshotV1.ts +36 -28
  303. package/src/snapshotlegacy.ts +7 -16
  304. package/src/stamps.ts +1 -1
  305. package/src/textSegment.ts +0 -13
  306. package/src/zamboni.ts +38 -32
  307. package/tsconfig.json +1 -0
  308. package/prettier.config.cjs +0 -8
@@ -3,6 +3,29 @@
3
3
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
4
  * Licensed under the MIT License.
5
5
  */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || function (mod) {
23
+ if (mod && mod.__esModule) return mod;
24
+ var result = {};
25
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
26
+ __setModuleDefault(result, mod);
27
+ return result;
28
+ };
6
29
  Object.defineProperty(exports, "__esModule", { value: true });
7
30
  exports.SnapshotV1 = void 0;
8
31
  const client_utils_1 = require("@fluid-internal/client-utils");
@@ -15,6 +38,7 @@ const properties_js_1 = require("./properties.js");
15
38
  const segmentInfos_js_1 = require("./segmentInfos.js");
16
39
  const snapshotChunks_js_1 = require("./snapshotChunks.js");
17
40
  const snapshotlegacy_js_1 = require("./snapshotlegacy.js");
41
+ const opstampUtils = __importStar(require("./stamps.js"));
18
42
  class SnapshotV1 {
19
43
  constructor(mergeTree, logger, getLongClientId, filename, onCompletion) {
20
44
  this.mergeTree = mergeTree;
@@ -106,6 +130,7 @@ class SnapshotV1 {
106
130
  extractSync() {
107
131
  const mergeTree = this.mergeTree;
108
132
  const minSeq = this.header.minSequenceNumber;
133
+ const minSeqStamp = { seq: minSeq, clientId: constants_js_1.NonCollabClient };
109
134
  let originalSegments = 0;
110
135
  let segmentsAfterCombine = 0;
111
136
  // Helper to add the given `MergeTreeChunkV0SegmentSpec` to the snapshot.
@@ -135,10 +160,9 @@ class SnapshotV1 {
135
160
  // there is a pending insert op that will deliver the segment on reconnection.
136
161
  // b) The segment was removed at or below the MSN. Pending ops can no longer reference this
137
162
  // segment, and therefore we can discard it.
138
- if (segment.seq === constants_js_1.UnassignedSequenceNumber ||
139
- ((0, segmentInfos_js_1.isRemoved)(segment) && segment.removedSeq <= minSeq) ||
140
- ((0, segmentInfos_js_1.isMoved)(segment) && segment.movedSeq <= minSeq)) {
141
- if (segment.seq !== constants_js_1.UnassignedSequenceNumber) {
163
+ if (opstampUtils.isLocal(segment.insert) ||
164
+ ((0, segmentInfos_js_1.isRemoved)(segment) && opstampUtils.lte(segment.removes[0], minSeqStamp))) {
165
+ if (opstampUtils.isAcked(segment.insert)) {
142
166
  originalSegments += 1;
143
167
  }
144
168
  return true;
@@ -147,10 +171,8 @@ class SnapshotV1 {
147
171
  // Next determine if the snapshot needs to preserve information required for merging the segment
148
172
  // (seq, client, etc.) This information is only needed if the segment is above the MSN (and doesn't
149
173
  // have a pending remove.)
150
- if (segment.seq <= minSeq && // Segment is below the MSN, and...
151
- (!(0, segmentInfos_js_1.isRemoved)(segment) || // .. Segment has not been removed, or...
152
- segment.removedSeq === constants_js_1.UnassignedSequenceNumber) && // .. Removal op to be delivered on reconnect
153
- (!(0, segmentInfos_js_1.isMoved)(segment) || segment.movedSeq === constants_js_1.UnassignedSequenceNumber)) {
174
+ if (opstampUtils.lte(segment.insert, minSeqStamp) && // Segment is below the MSN, and...
175
+ (!(0, segmentInfos_js_1.isRemoved)(segment) || opstampUtils.isLocal(segment.removes[0]))) {
154
176
  // This segment is below the MSN, which means that future ops will not reference it. Attempt to
155
177
  // coalesce the new segment with the previous (if any).
156
178
  if (!prev) {
@@ -183,27 +205,36 @@ class SnapshotV1 {
183
205
  json: segment.toJSONObject(),
184
206
  };
185
207
  // If the segment insertion is above the MSN, record the insertion merge info.
186
- if (segment.seq > minSeq) {
187
- raw.seq = segment.seq;
188
- raw.client = this.getLongClientId(segment.clientId);
208
+ if (opstampUtils.greaterThan(segment.insert, minSeqStamp)) {
209
+ raw.seq = segment.insert.seq;
210
+ raw.client = this.getLongClientId(segment.insert.clientId);
189
211
  }
190
212
  // We have already dispensed with removed segments below the MSN and removed segments with unassigned
191
213
  // sequence numbers. Any remaining removal info should be preserved.
192
- if ((0, segmentInfos_js_1.isRemoved)(segment)) {
193
- (0, internal_1.assert)(segment.removedSeq !== constants_js_1.UnassignedSequenceNumber && segment.removedSeq > minSeq, 0x065 /* "On removal info preservation, segment has invalid removed sequence number!" */);
194
- raw.removedSeq = segment.removedSeq;
214
+ if ((0, segmentInfos_js_1.isRemoved)(segment) && segment.removes.some((r) => r.type === "setRemove")) {
215
+ const removes = segment.removes.filter((r) => r.type === "setRemove");
216
+ const firstRemove = removes[0];
217
+ (0, internal_1.assert)(opstampUtils.isAcked(firstRemove) &&
218
+ opstampUtils.greaterThan(firstRemove, minSeqStamp), 0x065 /* "On removal info preservation, segment has invalid removed sequence number!" */);
219
+ // TODO:AB#32299 By not preserving sequence numbers other than the first move,
220
+ // We drop data here which will be necessary to allow perspectives of remote clients that
221
+ // don't include all of their ops. This should be remedied at some point.
222
+ raw.removedSeq = firstRemove.seq;
195
223
  // back compat for when we split overlap and removed client
196
- raw.removedClient =
197
- segment.removedClientIds === undefined
198
- ? undefined
199
- : this.getLongClientId(segment.removedClientIds[0]);
200
- raw.removedClientIds = segment.removedClientIds?.map((id) => this.getLongClientId(id));
224
+ // This can be removed when we can safely assume no clients running Fluid packages <= 0.58 will ever
225
+ // load a document produced by a version beyond the removal. It is vestigial in the meantime.
226
+ raw.removedClient = this.getLongClientId(firstRemove.clientId);
227
+ raw.removedClientIds = removes.map(({ clientId }) => this.getLongClientId(clientId));
201
228
  }
202
- if ((0, segmentInfos_js_1.isMoved)(segment)) {
203
- (0, internal_1.assert)(segment.movedSeq !== constants_js_1.UnassignedSequenceNumber && segment.movedSeq > minSeq, 0x873 /* On move info preservation, segment has invalid moved sequence number! */);
204
- raw.movedSeq = segment.movedSeq;
205
- raw.movedSeqs = segment.movedSeqs;
206
- raw.movedClientIds = segment.movedClientIds?.map((id) => this.getLongClientId(id));
229
+ if ((0, segmentInfos_js_1.isRemoved)(segment) && segment.removes.some((r) => r.type === "sliceRemove")) {
230
+ // In this format, we used the term "move" to refer to a sliceRemove/obliterate.
231
+ const moves = segment.removes.filter((r) => r.type === "sliceRemove");
232
+ const firstMove = moves[0];
233
+ (0, internal_1.assert)(opstampUtils.isAcked(firstMove) &&
234
+ opstampUtils.greaterThan(firstMove, minSeqStamp), 0x873 /* On move info preservation, segment has invalid moved sequence number! */);
235
+ raw.movedSeq = firstMove.seq;
236
+ raw.movedSeqs = moves.map(({ seq }) => seq);
237
+ raw.movedClientIds = moves.map(({ clientId }) => this.getLongClientId(clientId));
207
238
  }
208
239
  // Sanity check that we are preserving either the seq > minSeq or a (re)moved segment's info.
209
240
  (0, internal_1.assert)((raw.seq !== undefined && raw.client !== undefined) ||
@@ -1 +1 @@
1
- {"version":3,"file":"snapshotV1.js","sourceRoot":"","sources":["../src/snapshotV1.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA8D;AAE9D,kEAA6D;AAM7D,qEAA4E;AAE5E,uEAGkD;AAGlD,iDAA0D;AAE1D,iEAA8D;AAG9D,mDAA+D;AAC/D,uDAAuE;AACvE,2DAQ6B;AAC7B,2DAAqD;AAErD,MAAa,UAAU;IAgBtB,YACQ,SAAoB,EAC3B,MAA2B,EACV,eAAuC,EACjD,QAAiB,EACjB,YAAyB;QAJzB,cAAS,GAAT,SAAS,CAAW;QAEV,oBAAe,GAAf,eAAe,CAAwB;QACjD,aAAQ,GAAR,QAAQ,CAAS;QACjB,iBAAY,GAAZ,YAAY,CAAa;QA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8FAA8F;AAC9F,wEAAwE;AACxE,sEAAsE;AAC/C,oBAAS,GAAW,KAAK,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { IChannelStorageService } from \"@fluidframework/datastore-definitions/internal\";\nimport {\n\tISummaryTreeWithStats,\n\tAttributionKey,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { IAttributionCollection } from \"./attributionCollection.js\";\nimport { UnassignedSequenceNumber } from \"./constants.js\";\nimport { MergeTree } from \"./mergeTree.js\";\nimport { walkAllChildSegments } from \"./mergeTreeNodeWalk.js\";\nimport { ISegmentPrivate } from \"./mergeTreeNodes.js\";\nimport type { IJSONSegment } from \"./ops.js\";\nimport { PropertySet, matchProperties } from \"./properties.js\";\nimport { assertInserted, isMoved, isRemoved } from \"./segmentInfos.js\";\nimport {\n\tIJSONSegmentWithMergeInfo,\n\tJsonSegmentSpecs,\n\tMergeTreeChunkV1,\n\tMergeTreeHeaderMetadata,\n\tserializeAsMaxSupportedVersion,\n\ttoLatestVersion,\n\ttype VersionedMergeTreeChunk,\n} from \"./snapshotChunks.js\";\nimport { SnapshotLegacy } from \"./snapshotlegacy.js\";\n\nexport class SnapshotV1 {\n\t// Split snapshot into two entries - headers (small) and body (overflow) for faster loading initial content\n\t// Please note that this number has no direct relationship to anything other than size of raw text (characters).\n\t// As we produce json for the blob (and then send over the wire compressed), this number\n\t// is really hard to correlate with any actual metric that matters (like bytes over the wire).\n\t// For test with small number of chunks it would be closer to blob size,\n\t// for very chunky text, blob size can easily be 4x-8x of that number.\n\tpublic static readonly chunkSize: number = 10000;\n\n\tprivate readonly header: MergeTreeHeaderMetadata;\n\tprivate readonly segments: JsonSegmentSpecs[];\n\tprivate readonly segmentLengths: number[];\n\tprivate readonly attributionCollections: IAttributionCollection<AttributionKey>[];\n\tprivate readonly logger: ITelemetryLoggerExt;\n\tprivate readonly chunkSize: number;\n\n\tconstructor(\n\t\tpublic mergeTree: MergeTree,\n\t\tlogger: ITelemetryLoggerExt,\n\t\tprivate readonly getLongClientId: (id: number) => string,\n\t\tpublic filename?: string,\n\t\tpublic onCompletion?: () => void,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"Snapshot\" });\n\t\tthis.chunkSize = mergeTree?.options?.mergeTreeSnapshotChunkSize ?? SnapshotV1.chunkSize;\n\n\t\tconst { currentSeq, minSeq } = mergeTree.collabWindow;\n\t\tthis.header = {\n\t\t\tminSequenceNumber: minSeq,\n\t\t\tsequenceNumber: currentSeq,\n\t\t\torderedChunkMetadata: [],\n\t\t\ttotalLength: 0,\n\t\t\ttotalSegmentCount: 0,\n\t\t};\n\n\t\tthis.segments = [];\n\t\tthis.segmentLengths = [];\n\t\tthis.attributionCollections = [];\n\t}\n\n\tprivate getSeqLengthSegs(\n\t\tallSegments: JsonSegmentSpecs[],\n\t\tallLengths: number[],\n\t\tattributionCollections: IAttributionCollection<AttributionKey>[],\n\t\tapproxSequenceLength: number,\n\t\tstartIndex = 0,\n\t): MergeTreeChunkV1 {\n\t\tconst segments: JsonSegmentSpecs[] = [];\n\t\tconst collections: {\n\t\t\tattribution: IAttributionCollection<AttributionKey>;\n\t\t\tcachedLength: number;\n\t\t}[] = [];\n\t\tlet length = 0;\n\t\tlet segmentCount = 0;\n\t\tlet hasAttribution = false;\n\t\twhile (length < approxSequenceLength && startIndex + segmentCount < allSegments.length) {\n\t\t\tconst pseg = allSegments[startIndex + segmentCount];\n\t\t\tsegments.push(pseg);\n\t\t\tlength += allLengths[startIndex + segmentCount];\n\t\t\tif (attributionCollections[startIndex + segmentCount]) {\n\t\t\t\thasAttribution = true;\n\t\t\t\tcollections.push({\n\t\t\t\t\tattribution: attributionCollections[startIndex + segmentCount],\n\t\t\t\t\tcachedLength: allLengths[startIndex + segmentCount],\n\t\t\t\t});\n\t\t\t}\n\t\t\tsegmentCount++;\n\t\t}\n\n\t\tconst attributionSerializer = this.mergeTree.attributionPolicy?.serializer;\n\t\tassert(\n\t\t\t!hasAttribution || attributionSerializer !== undefined,\n\t\t\t0x55a /* attribution serializer must be provided when there are segments with attribution. */,\n\t\t);\n\n\t\treturn {\n\t\t\tversion: \"1\",\n\t\t\tsegmentCount,\n\t\t\tlength,\n\t\t\tsegments,\n\t\t\tstartIndex,\n\t\t\theaderMetadata: undefined,\n\t\t\tattribution: hasAttribution\n\t\t\t\t? attributionSerializer?.serializeAttributionCollections(collections)\n\t\t\t\t: undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Emits the snapshot to an ISummarizeResult. If provided the optional IFluidSerializer will be used when\n\t * serializing the summary data rather than JSON.stringify.\n\t */\n\temit(serializer: IFluidSerializer, bind: IFluidHandle): ISummaryTreeWithStats {\n\t\tconst chunks: MergeTreeChunkV1[] = [];\n\t\tthis.header.totalSegmentCount = 0;\n\t\tthis.header.totalLength = 0;\n\t\tdo {\n\t\t\tconst chunk = this.getSeqLengthSegs(\n\t\t\t\tthis.segments,\n\t\t\t\tthis.segmentLengths,\n\t\t\t\tthis.attributionCollections,\n\t\t\t\tthis.chunkSize,\n\t\t\t\tthis.header.totalSegmentCount,\n\t\t\t);\n\t\t\tchunks.push(chunk);\n\t\t\tthis.header.totalSegmentCount += chunk.segmentCount;\n\t\t\tthis.header.totalLength += chunk.length;\n\t\t} while (this.header.totalSegmentCount < this.segments.length);\n\n\t\t// The do while loop should have added at least one chunk\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst headerChunk = chunks.shift()!;\n\t\theaderChunk.headerMetadata = this.header;\n\t\theaderChunk.headerMetadata.orderedChunkMetadata = [{ id: SnapshotLegacy.header }];\n\t\tconst blobs: [key: string, content: string][] = [];\n\t\tfor (const [index, chunk] of chunks.entries()) {\n\t\t\tconst id = `${SnapshotLegacy.body}_${index}`;\n\t\t\tthis.header.orderedChunkMetadata.push({ id });\n\t\t\tblobs.push([\n\t\t\t\tid,\n\t\t\t\tserializeAsMaxSupportedVersion(\n\t\t\t\t\tid,\n\t\t\t\t\tchunk,\n\t\t\t\t\tthis.logger,\n\t\t\t\t\tthis.mergeTree.options,\n\t\t\t\t\tserializer,\n\t\t\t\t\tbind,\n\t\t\t\t),\n\t\t\t]);\n\t\t}\n\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addBlob(\n\t\t\tSnapshotLegacy.header,\n\t\t\tserializeAsMaxSupportedVersion(\n\t\t\t\tSnapshotLegacy.header,\n\t\t\t\theaderChunk,\n\t\t\t\tthis.logger,\n\t\t\t\tthis.mergeTree.options,\n\t\t\t\tserializer,\n\t\t\t\tbind,\n\t\t\t),\n\t\t);\n\t\tfor (const value of blobs) {\n\t\t\tbuilder.addBlob(value[0], value[1]);\n\t\t}\n\n\t\treturn builder.getSummaryTree();\n\t}\n\n\textractSync(): JsonSegmentSpecs[] {\n\t\tconst mergeTree = this.mergeTree;\n\t\tconst minSeq = this.header.minSequenceNumber;\n\n\t\tlet originalSegments = 0;\n\t\tlet segmentsAfterCombine = 0;\n\n\t\t// Helper to add the given `MergeTreeChunkV0SegmentSpec` to the snapshot.\n\t\tconst pushSegRaw = (\n\t\t\tjson: JsonSegmentSpecs,\n\t\t\tlength: number,\n\t\t\tattribution: IAttributionCollection<AttributionKey> | undefined,\n\t\t): void => {\n\t\t\tsegmentsAfterCombine += 1;\n\t\t\tthis.segments.push(json);\n\t\t\tthis.segmentLengths.push(length);\n\t\t\tif (attribution) {\n\t\t\t\tthis.attributionCollections.push(attribution);\n\t\t\t}\n\t\t};\n\n\t\t// Helper to serialize the given `segment` and add it to the snapshot (if a segment is provided).\n\t\tconst pushSeg = (segment?: ISegmentPrivate): void => {\n\t\t\tif (segment) {\n\t\t\t\tif (segment.properties !== undefined && Object.keys(segment.properties).length === 0) {\n\t\t\t\t\tsegment.properties = undefined;\n\t\t\t\t}\n\t\t\t\tpushSegRaw(\n\t\t\t\t\tsegment.toJSONObject() as JsonSegmentSpecs,\n\t\t\t\t\tsegment.cachedLength,\n\t\t\t\t\tsegment.attribution,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tlet prev: ISegmentPrivate | undefined;\n\t\tconst extractSegment = (segment: ISegmentPrivate): boolean => {\n\t\t\tassertInserted(segment);\n\t\t\t// Elide segments that do not need to be included in the snapshot. A segment may be elided if\n\t\t\t// either condition is true:\n\t\t\t// a) The segment has not yet been ACKed. We do not need to snapshot unACKed segments because\n\t\t\t// there is a pending insert op that will deliver the segment on reconnection.\n\t\t\t// b) The segment was removed at or below the MSN. Pending ops can no longer reference this\n\t\t\t// segment, and therefore we can discard it.\n\t\t\tif (\n\t\t\t\tsegment.seq === UnassignedSequenceNumber ||\n\t\t\t\t(isRemoved(segment) && segment.removedSeq <= minSeq) ||\n\t\t\t\t(isMoved(segment) && segment.movedSeq <= minSeq)\n\t\t\t) {\n\t\t\t\tif (segment.seq !== UnassignedSequenceNumber) {\n\t\t\t\t\toriginalSegments += 1;\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\toriginalSegments += 1;\n\n\t\t\t// Next determine if the snapshot needs to preserve information required for merging the segment\n\t\t\t// (seq, client, etc.) This information is only needed if the segment is above the MSN (and doesn't\n\t\t\t// have a pending remove.)\n\t\t\tif (\n\t\t\t\tsegment.seq <= minSeq && // Segment is below the MSN, and...\n\t\t\t\t(!isRemoved(segment) || // .. Segment has not been removed, or...\n\t\t\t\t\tsegment.removedSeq === UnassignedSequenceNumber) && // .. Removal op to be delivered on reconnect\n\t\t\t\t(!isMoved(segment) || segment.movedSeq === UnassignedSequenceNumber)\n\t\t\t) {\n\t\t\t\t// This segment is below the MSN, which means that future ops will not reference it. Attempt to\n\t\t\t\t// coalesce the new segment with the previous (if any).\n\t\t\t\tif (!prev) {\n\t\t\t\t\t// We do not have a previous candidate for coalescing. Make the current segment the new candidate.\n\t\t\t\t\tprev = segment;\n\t\t\t\t} else if (\n\t\t\t\t\tprev.canAppend(segment) &&\n\t\t\t\t\tmatchProperties(prev.properties, segment.properties)\n\t\t\t\t) {\n\t\t\t\t\t// We have a compatible pair. Replace `prev` with the coalesced segment. Clone to avoid\n\t\t\t\t\t// modifying the segment instances currently in the MergeTree.\n\t\t\t\t\tprev = prev.clone();\n\t\t\t\t\tprev.append(segment.clone());\n\t\t\t\t} else {\n\t\t\t\t\t// The segment pair could not be coalesced. Record the `prev` segment in the snapshot\n\t\t\t\t\t// and make the current segment the new candidate for coalescing.\n\t\t\t\t\tpushSeg(prev);\n\t\t\t\t\tprev = segment;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// This segment needs to preserve its metadata as it may be referenced by future ops. It's ineligible\n\t\t\t\t// for coalescing, so emit the 'prev' segment now (if any).\n\t\t\t\tpushSeg(prev);\n\t\t\t\tprev = undefined;\n\n\t\t\t\tif (segment.properties !== undefined && Object.keys(segment.properties).length === 0) {\n\t\t\t\t\tsegment.properties = undefined;\n\t\t\t\t}\n\t\t\t\tconst raw: IJSONSegmentWithMergeInfo & { removedClient?: string } = {\n\t\t\t\t\tjson: segment.toJSONObject() as IJSONSegment,\n\t\t\t\t};\n\t\t\t\t// If the segment insertion is above the MSN, record the insertion merge info.\n\t\t\t\tif (segment.seq > minSeq) {\n\t\t\t\t\traw.seq = segment.seq;\n\t\t\t\t\traw.client = this.getLongClientId(segment.clientId);\n\t\t\t\t}\n\t\t\t\t// We have already dispensed with removed segments below the MSN and removed segments with unassigned\n\t\t\t\t// sequence numbers. Any remaining removal info should be preserved.\n\t\t\t\tif (isRemoved(segment)) {\n\t\t\t\t\tassert(\n\t\t\t\t\t\tsegment.removedSeq !== UnassignedSequenceNumber && segment.removedSeq > minSeq,\n\t\t\t\t\t\t0x065 /* \"On removal info preservation, segment has invalid removed sequence number!\" */,\n\t\t\t\t\t);\n\t\t\t\t\traw.removedSeq = segment.removedSeq;\n\n\t\t\t\t\t// back compat for when we split overlap and removed client\n\t\t\t\t\traw.removedClient =\n\t\t\t\t\t\tsegment.removedClientIds === undefined\n\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t: this.getLongClientId(segment.removedClientIds[0]);\n\n\t\t\t\t\traw.removedClientIds = segment.removedClientIds?.map((id) =>\n\t\t\t\t\t\tthis.getLongClientId(id),\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (isMoved(segment)) {\n\t\t\t\t\tassert(\n\t\t\t\t\t\tsegment.movedSeq !== UnassignedSequenceNumber && segment.movedSeq > minSeq,\n\t\t\t\t\t\t0x873 /* On move info preservation, segment has invalid moved sequence number! */,\n\t\t\t\t\t);\n\t\t\t\t\traw.movedSeq = segment.movedSeq;\n\t\t\t\t\traw.movedSeqs = segment.movedSeqs;\n\t\t\t\t\traw.movedClientIds = segment.movedClientIds?.map((id) => this.getLongClientId(id));\n\t\t\t\t}\n\n\t\t\t\t// Sanity check that we are preserving either the seq > minSeq or a (re)moved segment's info.\n\t\t\t\tassert(\n\t\t\t\t\t(raw.seq !== undefined && raw.client !== undefined) ||\n\t\t\t\t\t\t(raw.removedSeq !== undefined && raw.removedClientIds !== undefined) ||\n\t\t\t\t\t\t(raw.movedSeq !== undefined &&\n\t\t\t\t\t\t\traw.movedClientIds !== undefined &&\n\t\t\t\t\t\t\traw.movedClientIds.length > 0 &&\n\t\t\t\t\t\t\traw.movedSeqs !== undefined &&\n\t\t\t\t\t\t\traw.movedSeqs.length > 0),\n\t\t\t\t\t0x066 /* \"Corrupted preservation of segment metadata!\" */,\n\t\t\t\t);\n\n\t\t\t\t// Record the segment with its required metadata.\n\t\t\t\tpushSegRaw(raw, segment.cachedLength, segment.attribution);\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\twalkAllChildSegments(mergeTree.root, extractSegment);\n\n\t\t// If the last segment in the walk was coalescable, push it now.\n\t\tpushSeg(prev);\n\n\t\t// To reduce potential spam from this telemetry, we sample only a small\n\t\t// percentage of summaries\n\t\tif (Math.abs(originalSegments - segmentsAfterCombine) > 500 && Math.random() < 0.005) {\n\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"MergeTreeV1SummarizeSegmentCount\",\n\t\t\t\toriginalSegments,\n\t\t\t\tsegmentsAfterCombine,\n\t\t\t\tsegmentsLen: this.segments.length,\n\t\t\t});\n\t\t}\n\n\t\treturn this.segments;\n\t}\n\n\tpublic static async loadChunk(\n\t\tstorage: IChannelStorageService,\n\t\tpath: string,\n\t\tlogger: ITelemetryLoggerExt,\n\t\toptions: PropertySet | undefined,\n\t\tserializer?: IFluidSerializer,\n\t): Promise<MergeTreeChunkV1> {\n\t\tconst blob = await storage.readBlob(path);\n\t\tconst chunkAsString = bufferToString(blob, \"utf8\");\n\t\treturn SnapshotV1.processChunk(path, chunkAsString, logger, options, serializer);\n\t}\n\n\tpublic static processChunk(\n\t\tpath: string,\n\t\tchunk: string,\n\t\tlogger: ITelemetryLoggerExt,\n\t\toptions: PropertySet | undefined,\n\t\tserializer?: IFluidSerializer,\n\t): MergeTreeChunkV1 {\n\t\tconst chunkObj: VersionedMergeTreeChunk = serializer\n\t\t\t? (serializer.parse(chunk) as VersionedMergeTreeChunk)\n\t\t\t: (JSON.parse(chunk) as VersionedMergeTreeChunk);\n\t\treturn toLatestVersion(path, chunkObj, logger, options);\n\t}\n}\n"]}
1
+ {"version":3,"file":"snapshotV1.js","sourceRoot":"","sources":["../src/snapshotV1.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+DAA8D;AAE9D,kEAA6D;AAM7D,qEAA4E;AAE5E,uEAGkD;AAGlD,iDAAiD;AAEjD,iEAA8D;AAG9D,mDAA+D;AAC/D,uD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AI,CAAC,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;YACtF,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC;gBAC9B,SAAS,EAAE,kCAAkC;gBAC7C,gBAAgB;gBAChB,oBAAoB;gBACpB,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM;aACjC,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,SAAS,CAC5B,OAA+B,EAC/B,IAAY,EACZ,MAA2B,EAC3B,OAAgC,EAChC,UAA6B;QAE7B,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC1C,MAAM,aAAa,GAAG,IAAA,6BAAc,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnD,OAAO,UAAU,CAAC,YAAY,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;IAClF,CAAC;IAEM,MAAM,CAAC,YAAY,CACzB,IAAY,EACZ,KAAa,EACb,MAA2B,EAC3B,OAAgC,EAChC,UAA6B;QAE7B,MAAM,QAAQ,GAA4B,UAAU;YACnD,CAAC,CAAE,UAAU,CAAC,KAAK,CAAC,KAAK,CAA6B;YACtD,CAAC,CAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAA6B,CAAC;QAClD,OAAO,IAAA,mCAAe,EAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;;AA5VF,gCA6VC;AA5VA,2GAA2G;AAC3G,gHAAgH;AAChH,wFAAwF;AACxF,8FAA8F;AAC9F,wEAAwE;AACxE,sEAAsE;AAC/C,oBAAS,GAAW,KAAK,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { IChannelStorageService } from \"@fluidframework/datastore-definitions/internal\";\nimport {\n\tISummaryTreeWithStats,\n\tAttributionKey,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { IAttributionCollection } from \"./attributionCollection.js\";\nimport { NonCollabClient } from \"./constants.js\";\nimport { MergeTree } from \"./mergeTree.js\";\nimport { walkAllChildSegments } from \"./mergeTreeNodeWalk.js\";\nimport { ISegmentPrivate } from \"./mergeTreeNodes.js\";\nimport type { IJSONSegment } from \"./ops.js\";\nimport { PropertySet, matchProperties } from \"./properties.js\";\nimport { assertInserted, isRemoved } from \"./segmentInfos.js\";\nimport {\n\tIJSONSegmentWithMergeInfo,\n\tJsonSegmentSpecs,\n\tMergeTreeChunkV1,\n\tMergeTreeHeaderMetadata,\n\tserializeAsMaxSupportedVersion,\n\ttoLatestVersion,\n\ttype VersionedMergeTreeChunk,\n} from \"./snapshotChunks.js\";\nimport { SnapshotLegacy } from \"./snapshotlegacy.js\";\nimport type { OperationStamp } from \"./stamps.js\";\nimport * as opstampUtils from \"./stamps.js\";\n\nexport class SnapshotV1 {\n\t// Split snapshot into two entries - headers (small) and body (overflow) for faster loading initial content\n\t// Please note that this number has no direct relationship to anything other than size of raw text (characters).\n\t// As we produce json for the blob (and then send over the wire compressed), this number\n\t// is really hard to correlate with any actual metric that matters (like bytes over the wire).\n\t// For test with small number of chunks it would be closer to blob size,\n\t// for very chunky text, blob size can easily be 4x-8x of that number.\n\tpublic static readonly chunkSize: number = 10000;\n\n\tprivate readonly header: MergeTreeHeaderMetadata;\n\tprivate readonly segments: JsonSegmentSpecs[];\n\tprivate readonly segmentLengths: number[];\n\tprivate readonly attributionCollections: IAttributionCollection<AttributionKey>[];\n\tprivate readonly logger: ITelemetryLoggerExt;\n\tprivate readonly chunkSize: number;\n\n\tconstructor(\n\t\tpublic mergeTree: MergeTree,\n\t\tlogger: ITelemetryLoggerExt,\n\t\tprivate readonly getLongClientId: (id: number) => string,\n\t\tpublic filename?: string,\n\t\tpublic onCompletion?: () => void,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"Snapshot\" });\n\t\tthis.chunkSize = mergeTree?.options?.mergeTreeSnapshotChunkSize ?? SnapshotV1.chunkSize;\n\n\t\tconst { currentSeq, minSeq } = mergeTree.collabWindow;\n\t\tthis.header = {\n\t\t\tminSequenceNumber: minSeq,\n\t\t\tsequenceNumber: currentSeq,\n\t\t\torderedChunkMetadata: [],\n\t\t\ttotalLength: 0,\n\t\t\ttotalSegmentCount: 0,\n\t\t};\n\n\t\tthis.segments = [];\n\t\tthis.segmentLengths = [];\n\t\tthis.attributionCollections = [];\n\t}\n\n\tprivate getSeqLengthSegs(\n\t\tallSegments: JsonSegmentSpecs[],\n\t\tallLengths: number[],\n\t\tattributionCollections: IAttributionCollection<AttributionKey>[],\n\t\tapproxSequenceLength: number,\n\t\tstartIndex = 0,\n\t): MergeTreeChunkV1 {\n\t\tconst segments: JsonSegmentSpecs[] = [];\n\t\tconst collections: {\n\t\t\tattribution: IAttributionCollection<AttributionKey>;\n\t\t\tcachedLength: number;\n\t\t}[] = [];\n\t\tlet length = 0;\n\t\tlet segmentCount = 0;\n\t\tlet hasAttribution = false;\n\t\twhile (length < approxSequenceLength && startIndex + segmentCount < allSegments.length) {\n\t\t\tconst pseg = allSegments[startIndex + segmentCount];\n\t\t\tsegments.push(pseg);\n\t\t\tlength += allLengths[startIndex + segmentCount];\n\t\t\tif (attributionCollections[startIndex + segmentCount]) {\n\t\t\t\thasAttribution = true;\n\t\t\t\tcollections.push({\n\t\t\t\t\tattribution: attributionCollections[startIndex + segmentCount],\n\t\t\t\t\tcachedLength: allLengths[startIndex + segmentCount],\n\t\t\t\t});\n\t\t\t}\n\t\t\tsegmentCount++;\n\t\t}\n\n\t\tconst attributionSerializer = this.mergeTree.attributionPolicy?.serializer;\n\t\tassert(\n\t\t\t!hasAttribution || attributionSerializer !== undefined,\n\t\t\t0x55a /* attribution serializer must be provided when there are segments with attribution. */,\n\t\t);\n\n\t\treturn {\n\t\t\tversion: \"1\",\n\t\t\tsegmentCount,\n\t\t\tlength,\n\t\t\tsegments,\n\t\t\tstartIndex,\n\t\t\theaderMetadata: undefined,\n\t\t\tattribution: hasAttribution\n\t\t\t\t? attributionSerializer?.serializeAttributionCollections(collections)\n\t\t\t\t: undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Emits the snapshot to an ISummarizeResult. If provided the optional IFluidSerializer will be used when\n\t * serializing the summary data rather than JSON.stringify.\n\t */\n\temit(serializer: IFluidSerializer, bind: IFluidHandle): ISummaryTreeWithStats {\n\t\tconst chunks: MergeTreeChunkV1[] = [];\n\t\tthis.header.totalSegmentCount = 0;\n\t\tthis.header.totalLength = 0;\n\t\tdo {\n\t\t\tconst chunk = this.getSeqLengthSegs(\n\t\t\t\tthis.segments,\n\t\t\t\tthis.segmentLengths,\n\t\t\t\tthis.attributionCollections,\n\t\t\t\tthis.chunkSize,\n\t\t\t\tthis.header.totalSegmentCount,\n\t\t\t);\n\t\t\tchunks.push(chunk);\n\t\t\tthis.header.totalSegmentCount += chunk.segmentCount;\n\t\t\tthis.header.totalLength += chunk.length;\n\t\t} while (this.header.totalSegmentCount < this.segments.length);\n\n\t\t// The do while loop should have added at least one chunk\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst headerChunk = chunks.shift()!;\n\t\theaderChunk.headerMetadata = this.header;\n\t\theaderChunk.headerMetadata.orderedChunkMetadata = [{ id: SnapshotLegacy.header }];\n\t\tconst blobs: [key: string, content: string][] = [];\n\t\tfor (const [index, chunk] of chunks.entries()) {\n\t\t\tconst id = `${SnapshotLegacy.body}_${index}`;\n\t\t\tthis.header.orderedChunkMetadata.push({ id });\n\t\t\tblobs.push([\n\t\t\t\tid,\n\t\t\t\tserializeAsMaxSupportedVersion(\n\t\t\t\t\tid,\n\t\t\t\t\tchunk,\n\t\t\t\t\tthis.logger,\n\t\t\t\t\tthis.mergeTree.options,\n\t\t\t\t\tserializer,\n\t\t\t\t\tbind,\n\t\t\t\t),\n\t\t\t]);\n\t\t}\n\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addBlob(\n\t\t\tSnapshotLegacy.header,\n\t\t\tserializeAsMaxSupportedVersion(\n\t\t\t\tSnapshotLegacy.header,\n\t\t\t\theaderChunk,\n\t\t\t\tthis.logger,\n\t\t\t\tthis.mergeTree.options,\n\t\t\t\tserializer,\n\t\t\t\tbind,\n\t\t\t),\n\t\t);\n\t\tfor (const value of blobs) {\n\t\t\tbuilder.addBlob(value[0], value[1]);\n\t\t}\n\n\t\treturn builder.getSummaryTree();\n\t}\n\n\textractSync(): JsonSegmentSpecs[] {\n\t\tconst mergeTree = this.mergeTree;\n\t\tconst minSeq = this.header.minSequenceNumber;\n\t\tconst minSeqStamp: OperationStamp = { seq: minSeq, clientId: NonCollabClient };\n\n\t\tlet originalSegments = 0;\n\t\tlet segmentsAfterCombine = 0;\n\n\t\t// Helper to add the given `MergeTreeChunkV0SegmentSpec` to the snapshot.\n\t\tconst pushSegRaw = (\n\t\t\tjson: JsonSegmentSpecs,\n\t\t\tlength: number,\n\t\t\tattribution: IAttributionCollection<AttributionKey> | undefined,\n\t\t): void => {\n\t\t\tsegmentsAfterCombine += 1;\n\t\t\tthis.segments.push(json);\n\t\t\tthis.segmentLengths.push(length);\n\t\t\tif (attribution) {\n\t\t\t\tthis.attributionCollections.push(attribution);\n\t\t\t}\n\t\t};\n\n\t\t// Helper to serialize the given `segment` and add it to the snapshot (if a segment is provided).\n\t\tconst pushSeg = (segment?: ISegmentPrivate): void => {\n\t\t\tif (segment) {\n\t\t\t\tif (segment.properties !== undefined && Object.keys(segment.properties).length === 0) {\n\t\t\t\t\tsegment.properties = undefined;\n\t\t\t\t}\n\t\t\t\tpushSegRaw(\n\t\t\t\t\tsegment.toJSONObject() as JsonSegmentSpecs,\n\t\t\t\t\tsegment.cachedLength,\n\t\t\t\t\tsegment.attribution,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tlet prev: ISegmentPrivate | undefined;\n\t\tconst extractSegment = (segment: ISegmentPrivate): boolean => {\n\t\t\tassertInserted(segment);\n\t\t\t// Elide segments that do not need to be included in the snapshot. A segment may be elided if\n\t\t\t// either condition is true:\n\t\t\t// a) The segment has not yet been ACKed. We do not need to snapshot unACKed segments because\n\t\t\t// there is a pending insert op that will deliver the segment on reconnection.\n\t\t\t// b) The segment was removed at or below the MSN. Pending ops can no longer reference this\n\t\t\t// segment, and therefore we can discard it.\n\t\t\tif (\n\t\t\t\topstampUtils.isLocal(segment.insert) ||\n\t\t\t\t(isRemoved(segment) && opstampUtils.lte(segment.removes[0], minSeqStamp))\n\t\t\t) {\n\t\t\t\tif (opstampUtils.isAcked(segment.insert)) {\n\t\t\t\t\toriginalSegments += 1;\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\toriginalSegments += 1;\n\n\t\t\t// Next determine if the snapshot needs to preserve information required for merging the segment\n\t\t\t// (seq, client, etc.) This information is only needed if the segment is above the MSN (and doesn't\n\t\t\t// have a pending remove.)\n\t\t\tif (\n\t\t\t\topstampUtils.lte(segment.insert, minSeqStamp) && // Segment is below the MSN, and...\n\t\t\t\t(!isRemoved(segment) || opstampUtils.isLocal(segment.removes[0]))\n\t\t\t) {\n\t\t\t\t// This segment is below the MSN, which means that future ops will not reference it. Attempt to\n\t\t\t\t// coalesce the new segment with the previous (if any).\n\t\t\t\tif (!prev) {\n\t\t\t\t\t// We do not have a previous candidate for coalescing. Make the current segment the new candidate.\n\t\t\t\t\tprev = segment;\n\t\t\t\t} else if (\n\t\t\t\t\tprev.canAppend(segment) &&\n\t\t\t\t\tmatchProperties(prev.properties, segment.properties)\n\t\t\t\t) {\n\t\t\t\t\t// We have a compatible pair. Replace `prev` with the coalesced segment. Clone to avoid\n\t\t\t\t\t// modifying the segment instances currently in the MergeTree.\n\t\t\t\t\tprev = prev.clone();\n\t\t\t\t\tprev.append(segment.clone());\n\t\t\t\t} else {\n\t\t\t\t\t// The segment pair could not be coalesced. Record the `prev` segment in the snapshot\n\t\t\t\t\t// and make the current segment the new candidate for coalescing.\n\t\t\t\t\tpushSeg(prev);\n\t\t\t\t\tprev = segment;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// This segment needs to preserve its metadata as it may be referenced by future ops. It's ineligible\n\t\t\t\t// for coalescing, so emit the 'prev' segment now (if any).\n\t\t\t\tpushSeg(prev);\n\t\t\t\tprev = undefined;\n\n\t\t\t\tif (segment.properties !== undefined && Object.keys(segment.properties).length === 0) {\n\t\t\t\t\tsegment.properties = undefined;\n\t\t\t\t}\n\t\t\t\tconst raw: IJSONSegmentWithMergeInfo & { removedClient?: string } = {\n\t\t\t\t\tjson: segment.toJSONObject() as IJSONSegment,\n\t\t\t\t};\n\t\t\t\t// If the segment insertion is above the MSN, record the insertion merge info.\n\t\t\t\tif (opstampUtils.greaterThan(segment.insert, minSeqStamp)) {\n\t\t\t\t\traw.seq = segment.insert.seq;\n\t\t\t\t\traw.client = this.getLongClientId(segment.insert.clientId);\n\t\t\t\t}\n\n\t\t\t\t// We have already dispensed with removed segments below the MSN and removed segments with unassigned\n\t\t\t\t// sequence numbers. Any remaining removal info should be preserved.\n\t\t\t\tif (isRemoved(segment) && segment.removes.some((r) => r.type === \"setRemove\")) {\n\t\t\t\t\tconst removes = segment.removes.filter((r) => r.type === \"setRemove\");\n\t\t\t\t\tconst firstRemove = removes[0];\n\t\t\t\t\tassert(\n\t\t\t\t\t\topstampUtils.isAcked(firstRemove) &&\n\t\t\t\t\t\t\topstampUtils.greaterThan(firstRemove, minSeqStamp),\n\t\t\t\t\t\t0x065 /* \"On removal info preservation, segment has invalid removed sequence number!\" */,\n\t\t\t\t\t);\n\t\t\t\t\t// TODO:AB#32299 By not preserving sequence numbers other than the first move,\n\t\t\t\t\t// We drop data here which will be necessary to allow perspectives of remote clients that\n\t\t\t\t\t// don't include all of their ops. This should be remedied at some point.\n\t\t\t\t\traw.removedSeq = firstRemove.seq;\n\n\t\t\t\t\t// back compat for when we split overlap and removed client\n\t\t\t\t\t// This can be removed when we can safely assume no clients running Fluid packages <= 0.58 will ever\n\t\t\t\t\t// load a document produced by a version beyond the removal. It is vestigial in the meantime.\n\t\t\t\t\traw.removedClient = this.getLongClientId(firstRemove.clientId);\n\n\t\t\t\t\traw.removedClientIds = removes.map(({ clientId }) => this.getLongClientId(clientId));\n\t\t\t\t}\n\n\t\t\t\tif (isRemoved(segment) && segment.removes.some((r) => r.type === \"sliceRemove\")) {\n\t\t\t\t\t// In this format, we used the term \"move\" to refer to a sliceRemove/obliterate.\n\t\t\t\t\tconst moves = segment.removes.filter((r) => r.type === \"sliceRemove\");\n\t\t\t\t\tconst firstMove = moves[0];\n\t\t\t\t\tassert(\n\t\t\t\t\t\topstampUtils.isAcked(firstMove) &&\n\t\t\t\t\t\t\topstampUtils.greaterThan(firstMove, minSeqStamp),\n\t\t\t\t\t\t0x873 /* On move info preservation, segment has invalid moved sequence number! */,\n\t\t\t\t\t);\n\t\t\t\t\traw.movedSeq = firstMove.seq;\n\t\t\t\t\traw.movedSeqs = moves.map(({ seq }) => seq);\n\t\t\t\t\traw.movedClientIds = moves.map(({ clientId }) => this.getLongClientId(clientId));\n\t\t\t\t}\n\n\t\t\t\t// Sanity check that we are preserving either the seq > minSeq or a (re)moved segment's info.\n\t\t\t\tassert(\n\t\t\t\t\t(raw.seq !== undefined && raw.client !== undefined) ||\n\t\t\t\t\t\t(raw.removedSeq !== undefined && raw.removedClientIds !== undefined) ||\n\t\t\t\t\t\t(raw.movedSeq !== undefined &&\n\t\t\t\t\t\t\traw.movedClientIds !== undefined &&\n\t\t\t\t\t\t\traw.movedClientIds.length > 0 &&\n\t\t\t\t\t\t\traw.movedSeqs !== undefined &&\n\t\t\t\t\t\t\traw.movedSeqs.length > 0),\n\t\t\t\t\t0x066 /* \"Corrupted preservation of segment metadata!\" */,\n\t\t\t\t);\n\n\t\t\t\t// Record the segment with its required metadata.\n\t\t\t\tpushSegRaw(raw, segment.cachedLength, segment.attribution);\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\twalkAllChildSegments(mergeTree.root, extractSegment);\n\n\t\t// If the last segment in the walk was coalescable, push it now.\n\t\tpushSeg(prev);\n\n\t\t// To reduce potential spam from this telemetry, we sample only a small\n\t\t// percentage of summaries\n\t\tif (Math.abs(originalSegments - segmentsAfterCombine) > 500 && Math.random() < 0.005) {\n\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"MergeTreeV1SummarizeSegmentCount\",\n\t\t\t\toriginalSegments,\n\t\t\t\tsegmentsAfterCombine,\n\t\t\t\tsegmentsLen: this.segments.length,\n\t\t\t});\n\t\t}\n\n\t\treturn this.segments;\n\t}\n\n\tpublic static async loadChunk(\n\t\tstorage: IChannelStorageService,\n\t\tpath: string,\n\t\tlogger: ITelemetryLoggerExt,\n\t\toptions: PropertySet | undefined,\n\t\tserializer?: IFluidSerializer,\n\t): Promise<MergeTreeChunkV1> {\n\t\tconst blob = await storage.readBlob(path);\n\t\tconst chunkAsString = bufferToString(blob, \"utf8\");\n\t\treturn SnapshotV1.processChunk(path, chunkAsString, logger, options, serializer);\n\t}\n\n\tpublic static processChunk(\n\t\tpath: string,\n\t\tchunk: string,\n\t\tlogger: ITelemetryLoggerExt,\n\t\toptions: PropertySet | undefined,\n\t\tserializer?: IFluidSerializer,\n\t): MergeTreeChunkV1 {\n\t\tconst chunkObj: VersionedMergeTreeChunk = serializer\n\t\t\t? (serializer.parse(chunk) as VersionedMergeTreeChunk)\n\t\t\t: (JSON.parse(chunk) as VersionedMergeTreeChunk);\n\t\treturn toLatestVersion(path,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BAAqB;IAiExB,WAAW,IAAI,eAAe,EAAE;CAoEhC"}
@@ -9,8 +9,9 @@ const internal_1 = require("@fluidframework/core-utils/internal");
9
9
  const internal_2 = require("@fluidframework/runtime-utils/internal");
10
10
  const internal_3 = require("@fluidframework/telemetry-utils/internal");
11
11
  const constants_js_1 = require("./constants.js");
12
+ const mergeTreeNodes_js_1 = require("./mergeTreeNodes.js");
13
+ const perspective_js_1 = require("./perspective.js");
12
14
  const properties_js_1 = require("./properties.js");
13
- const segmentInfos_js_1 = require("./segmentInfos.js");
14
15
  const snapshotChunks_js_1 = require("./snapshotChunks.js");
15
16
  /**
16
17
  * @internal
@@ -89,20 +90,16 @@ class SnapshotLegacy {
89
90
  extractSync() {
90
91
  const collabWindow = this.mergeTree.collabWindow;
91
92
  const seq = (this.seq = collabWindow.minSeq);
93
+ const minSeqPerspective = new perspective_js_1.PriorPerspective(this.seq, constants_js_1.NonCollabClient);
92
94
  this.header = {
93
- segmentsTotalLength: this.mergeTree.getLength(this.mergeTree.collabWindow.minSeq, constants_js_1.NonCollabClient),
95
+ segmentsTotalLength: this.mergeTree.getLength(minSeqPerspective),
94
96
  seq: this.mergeTree.collabWindow.minSeq,
95
97
  };
96
98
  let originalSegments = 0;
97
99
  const segs = [];
98
100
  let prev;
99
101
  const extractSegment = (segment) => {
100
- if ((0, segmentInfos_js_1.isInserted)(segment) &&
101
- segment.seq !== constants_js_1.UnassignedSequenceNumber &&
102
- segment.seq <= seq &&
103
- (!(0, segmentInfos_js_1.isRemoved)(segment) ||
104
- segment.removedSeq === constants_js_1.UnassignedSequenceNumber ||
105
- segment.removedSeq > seq)) {
102
+ if ((0, mergeTreeNodes_js_1.isSegmentLeaf)(segment) && minSeqPerspective.isSegmentPresent(segment)) {
106
103
  originalSegments += 1;
107
104
  const properties = segment.propertyManager?.getAtSeq(segment.properties, seq) ?? segment.properties;
108
105
  if (prev?.canAppend(segment) && (0, properties_js_1.matchProperties)(prev.properties, properties)) {
@@ -116,7 +113,7 @@ class SnapshotLegacy {
116
113
  }
117
114
  return true;
118
115
  };
119
- this.mergeTree.mapRange(extractSegment, this.seq, constants_js_1.NonCollabClient, undefined);
116
+ this.mergeTree.mapRange(extractSegment, minSeqPerspective, undefined);
120
117
  this.segments = [];
121
118
  let totalLength = 0;
122
119
  segs.map((segment) => {
@@ -1 +1 @@
1
- {"version":3,"file":"snapshotlegacy.js","sourceRoot":"","sources":["../src/snapshotlegacy.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,kEAA6D;AAG7D,qEAA4E;AAE5E,uEAGkD;AAElD,iDAA2E;AAG3E,mDAAkD;AAClD,uDAA0D;AAC1D,2DAI6B;AAa7B;;GAEG;AACH,MAAa,cAAc;IAmB1B,YACQ,SAAoB,EAC3B,MAA2B,EACpB,QAAiB,EACjB,YAAyB;QAHzB,cAAS,GAAT,SAAS,CAAW;QAEpB,aAAQ,GAAR,QAAQ,CAAS;QACjB,iBAAY,GAAZ,YAAY,CAAa;QAEhC,IAAI,CAAC,MAAM,GAAG,IAAA,4BAAiB,EAAC,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;QACnE,IAAI,CAAC,SAAS;YACb,SAAS,EAAE,OAAO,EAAE,0BAA0B,IAAI,cAAc,CAAC,gBAAgB,CAAC;IACpF,CAAC;IAEO,gBAAgB,CACvB,WAA8B,EAC9B,oBAA4B,EAC5B,UAAU,GAAG,CAAC;QAEd,MAAM,IAAI,GAAsB,EAAE,CAAC;QACnC,IAAI,cAAc,GAAG,CAAC,CAAC;QACvB,IAAI,QAAQ,GAAG,CAAC,CAAC;QACjB,IAAI,mBAAmB,GAAG,CAAC,CAAC;QAC5B,OACC,cAAc,GAAG,oBAAoB;YACrC,UAAU,GAAG,QAAQ,GAAG,WAAW,CAAC,MAAM,EACzC,CAAC;YACF,MAAM,IAAI,GAAG,WAAW,CAAC,UAAU,GAAG,QAAQ,CAAC,CAAC;YAChD,IAAI,CAAC,IAAI,CAAC,IAAI,C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,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC;gBAC9B,SAAS,EAAE,sCAAsC;gBACjD,gBAAgB;gBAChB,oBAAoB,EAAE,IAAI,CAAC,MAAM;gBACjC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM;aACjC,CAAC,CAAC;QACJ,CAAC;QAED,oFAAoF;QACpF,yFAAyF;QACzF,uFAAuF;QACvF,gFAAgF;QAEhF,IAAI,IAAI,CAAC,MAAM,CAAC,mBAAmB,KAAK,WAAW,EAAE,CAAC;YACrD,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;gBAC1B,SAAS,EAAE,6BAA6B;gBACxC,WAAW;gBACX,mBAAmB,EAAE,IAAI,CAAC,MAAM,CAAC,mBAAmB;aACpD,CAAC,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,mBAAmB,GAAG,WAAW,CAAC;QAC/C,CAAC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;;AAnOF,wCAoOC;AAnOuB,qBAAM,GAAG,QAAQ,CAAC;AAClB,mBAAI,GAAG,MAAM,CAAC;AACb,yBAAU,GAAG,YAAY,CAAC;AAElD,2GAA2G;AAC3G,gHAAgH;AAChH,wFAAwF;AACxF,8FAA8F;AAC9F,wEAAwE;AACxE,sEAAsE;AAC/C,+BAAgB,GAAW,KAAK,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { NonCollabClient, UnassignedSequenceNumber } from \"./constants.js\";\nimport { MergeTree } from \"./mergeTree.js\";\nimport { type ISegmentPrivate } from \"./mergeTreeNodes.js\";\nimport { matchProperties } from \"./properties.js\";\nimport { isInserted, isRemoved } from \"./segmentInfos.js\";\nimport {\n\tJsonSegmentSpecs,\n\tMergeTreeChunkLegacy,\n\tserializeAsMinSupportedVersion,\n} from \"./snapshotChunks.js\";\n\ninterface SnapshotHeader {\n\tchunkCount?: number;\n\tsegmentsTotalLength: number;\n\tindexOffset?: number;\n\tsegmentsOffset?: number;\n\tseq: number;\n\t// TODO: Make 'minSeq' non-optional once the new snapshot format becomes the default?\n\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\tminSeq?: number;\n}\n\n/**\n * @internal\n */\nexport class SnapshotLegacy {\n\tpublic static readonly header = \"header\";\n\tpublic static readonly body = \"body\";\n\tprivate static readonly catchupOps = \"catchupOps\";\n\n\t// Split snapshot into two entries - headers (small) and body (overflow) for faster loading initial content\n\t// Please note that this number has no direct relationship to anything other than size of raw text (characters).\n\t// As we produce json for the blob (and then send over the wire compressed), this number\n\t// is really hard to correlate with any actual metric that matters (like bytes over the wire).\n\t// For test with small number of chunks it would be closer to blob size,\n\t// for very chunky text, blob size can easily be 4x-8x of that number.\n\tpublic static readonly sizeOfFirstChunk: number = 10000;\n\n\tprivate header: SnapshotHeader | undefined;\n\tprivate seq: number | undefined;\n\tprivate segments: ISegmentPrivate[] | undefined;\n\tprivate readonly logger: ITelemetryLoggerExt;\n\tprivate readonly chunkSize: number;\n\n\tconstructor(\n\t\tpublic mergeTree: MergeTree,\n\t\tlogger: ITelemetryLoggerExt,\n\t\tpublic filename?: string,\n\t\tpublic onCompletion?: () => void,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"Snapshot\" });\n\t\tthis.chunkSize =\n\t\t\tmergeTree?.options?.mergeTreeSnapshotChunkSize ?? SnapshotLegacy.sizeOfFirstChunk;\n\t}\n\n\tprivate getSeqLengthSegs(\n\t\tallSegments: ISegmentPrivate[],\n\t\tapproxSequenceLength: number,\n\t\tstartIndex = 0,\n\t): MergeTreeChunkLegacy {\n\t\tconst segs: ISegmentPrivate[] = [];\n\t\tlet sequenceLength = 0;\n\t\tlet segCount = 0;\n\t\tlet segsWithAttribution = 0;\n\t\twhile (\n\t\t\tsequenceLength < approxSequenceLength &&\n\t\t\tstartIndex + segCount < allSegments.length\n\t\t) {\n\t\t\tconst pseg = allSegments[startIndex + segCount];\n\t\t\tsegs.push(pseg);\n\t\t\tif (pseg.attribution) {\n\t\t\t\tsegsWithAttribution++;\n\t\t\t}\n\t\t\tsequenceLength += pseg.cachedLength;\n\t\t\tsegCount++;\n\t\t}\n\n\t\tassert(\n\t\t\tsegsWithAttribution === 0 || segsWithAttribution === segCount,\n\t\t\t0x4bf /* all or no segments should have attribution */,\n\t\t);\n\n\t\tconst attributionSerializer = this.mergeTree.attributionPolicy?.serializer;\n\t\tassert(\n\t\t\tsegsWithAttribution === 0 || attributionSerializer !== undefined,\n\t\t\t0x559 /* attribution serializer must be provided when there are segments with attribution. */,\n\t\t);\n\t\treturn {\n\t\t\tversion: undefined,\n\t\t\tchunkStartSegmentIndex: startIndex,\n\t\t\tchunkSegmentCount: segCount,\n\t\t\tchunkLengthChars: sequenceLength,\n\t\t\ttotalLengthChars: this.header!.segmentsTotalLength,\n\t\t\ttotalSegmentCount: allSegments.length,\n\t\t\tchunkSequenceNumber: this.header!.seq,\n\t\t\tsegmentTexts: segs.map((seg) => seg.toJSONObject() as JsonSegmentSpecs),\n\t\t\tattribution:\n\t\t\t\tsegsWithAttribution > 0 || this.mergeTree.attributionPolicy?.isAttached\n\t\t\t\t\t? attributionSerializer?.serializeAttributionCollections(segs)\n\t\t\t\t\t: undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Emits the snapshot to an ISummarizeResult. If provided the optional IFluidSerializer will be used when\n\t * serializing the summary data rather than JSON.stringify.\n\t */\n\temit(\n\t\tcatchUpMsgs: ISequencedDocumentMessage[],\n\t\tserializer: IFluidSerializer,\n\t\tbind: IFluidHandle,\n\t): ISummaryTreeWithStats {\n\t\tconst chunk1 = this.getSeqLengthSegs(this.segments!, this.chunkSize);\n\t\tlet length: number = chunk1.chunkLengthChars;\n\t\tlet segments: number = chunk1.chunkSegmentCount;\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addBlob(\n\t\t\tSnapshotLegacy.header,\n\t\t\tserializeAsMinSupportedVersion(\n\t\t\t\tSnapshotLegacy.header,\n\t\t\t\tchunk1,\n\t\t\t\tthis.logger,\n\t\t\t\tthis.mergeTree.options,\n\t\t\t\tserializer,\n\t\t\t\tbind,\n\t\t\t),\n\t\t);\n\n\t\tif (chunk1.chunkSegmentCount < chunk1.totalSegmentCount!) {\n\t\t\tconst chunk2 = this.getSeqLengthSegs(\n\t\t\t\tthis.segments!,\n\t\t\t\tthis.header!.segmentsTotalLength,\n\t\t\t\tchunk1.chunkSegmentCount,\n\t\t\t);\n\t\t\tlength += chunk2.chunkLengthChars;\n\t\t\tsegments += chunk2.chunkSegmentCount;\n\t\t\tbuilder.addBlob(\n\t\t\t\tSnapshotLegacy.body,\n\t\t\t\tserializeAsMinSupportedVersion(\n\t\t\t\t\tSnapshotLegacy.body,\n\t\t\t\t\tchunk2,\n\t\t\t\t\tthis.logger,\n\t\t\t\t\tthis.mergeTree.options,\n\t\t\t\t\tserializer,\n\t\t\t\t\tbind,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tassert(\n\t\t\tlength === this.header!.segmentsTotalLength,\n\t\t\t0x05d /* \"emit: mismatch in segmentsTotalLength\" */,\n\t\t);\n\n\t\tassert(\n\t\t\tsegments === chunk1.totalSegmentCount,\n\t\t\t0x05e /* \"emit: mismatch in totalSegmentCount\" */,\n\t\t);\n\n\t\tif (catchUpMsgs !== undefined && catchUpMsgs.length > 0) {\n\t\t\t// Messages used to have a \"term\" property which has since been removed.\n\t\t\t// It is benign so it doesn't really need to be deleted here, but doing so permits snapshot tests\n\t\t\t// to pass with an exact match (and matching the updated definition of ISequencedDocumentMessage).\n\t\t\tfor (const message of catchUpMsgs) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\tdelete (message as any).term;\n\t\t\t}\n\t\t\tbuilder.addBlob(\n\t\t\t\tthis.mergeTree.options?.catchUpBlobName ?? SnapshotLegacy.catchupOps,\n\t\t\t\tserializer ? serializer.stringify(catchUpMsgs, bind) : JSON.stringify(catchUpMsgs),\n\t\t\t);\n\t\t}\n\n\t\treturn builder.getSummaryTree();\n\t}\n\n\textractSync(): ISegmentPrivate[] {\n\t\tconst collabWindow = this.mergeTree.collabWindow;\n\t\tconst seq = (this.seq = collabWindow.minSeq);\n\t\tthis.header = {\n\t\t\tsegmentsTotalLength: this.mergeTree.getLength(\n\t\t\t\tthis.mergeTree.collabWindow.minSeq,\n\t\t\t\tNonCollabClient,\n\t\t\t),\n\t\t\tseq: this.mergeTree.collabWindow.minSeq,\n\t\t};\n\n\t\tlet originalSegments = 0;\n\n\t\tconst segs: ISegmentPrivate[] = [];\n\t\tlet prev: ISegmentPrivate | undefined;\n\t\tconst extractSegment = (segment: ISegmentPrivate): boolean => {\n\t\t\tif (\n\t\t\t\tisInserted(segment) &&\n\t\t\t\tsegment.seq !== UnassignedSequenceNumber &&\n\t\t\t\tsegment.seq <= seq &&\n\t\t\t\t(!isRemoved(segment) ||\n\t\t\t\t\tsegment.removedSeq === UnassignedSequenceNumber ||\n\t\t\t\t\tsegment.removedSeq > seq)\n\t\t\t) {\n\t\t\t\toriginalSegments += 1;\n\t\t\t\tconst properties =\n\t\t\t\t\tsegment.propertyManager?.getAtSeq(segment.properties, seq) ?? segment.properties;\n\t\t\t\tif (prev?.canAppend(segment) && matchProperties(prev.properties, properties)) {\n\t\t\t\t\tprev.append(segment.clone());\n\t\t\t\t} else {\n\t\t\t\t\tprev = segment.clone();\n\t\t\t\t\tprev.properties = properties;\n\t\t\t\t\tsegs.push(prev);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\tthis.mergeTree.mapRange(extractSegment, this.seq, NonCollabClient, undefined);\n\n\t\tthis.segments = [];\n\t\tlet totalLength: number = 0;\n\t\tsegs.map((segment) => {\n\t\t\ttotalLength += segment.cachedLength;\n\t\t\tif (segment.properties !== undefined && Object.keys(segment.properties).length === 0) {\n\t\t\t\tsegment.properties = undefined;\n\t\t\t}\n\t\t\tthis.segments!.push(segment);\n\t\t});\n\n\t\t// To reduce potential spam from this telemetry, we sample only a small\n\t\t// percentage of summaries\n\t\tif (Math.abs(originalSegments - segs.length) > 500 && Math.random() < 0.005) {\n\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"MergeTreeLegacySummarizeSegmentCount\",\n\t\t\t\toriginalSegments,\n\t\t\t\tsegmentsAfterCombine: segs.length,\n\t\t\t\tsegmentsLen: this.segments.length,\n\t\t\t});\n\t\t}\n\n\t\t// We observed this.header.segmentsTotalLength < totalLength to happen in some cases\n\t\t// When this condition happens, we might not write out all segments in getSeqLengthSegs()\n\t\t// when writing out \"body\". Issue #1995 tracks following up on the core of the problem.\n\t\t// In the meantime, this code makes sure we will write out all segments properly\n\n\t\tif (this.header.segmentsTotalLength !== totalLength) {\n\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\teventName: \"SegmentsTotalLengthMismatch\",\n\t\t\t\ttotalLength,\n\t\t\t\tsegmentsTotalLength: this.header.segmentsTotalLength,\n\t\t\t});\n\t\t\tthis.header.segmentsTotalLength = totalLength;\n\t\t}\n\n\t\treturn this.segments;\n\t}\n}\n"]}
1
+ {"version":3,"file":"snapshotlegacy.js","sourceRoot":"","sources":["../src/snapshotlegacy.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,kEAA6D;AAG7D,qEAA4E;AAE5E,uEAGkD;AAElD,iDAAiD;AAEjD,2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C,MAAM,CAAC,mBAAmB,GAAG,WAAW,CAAC;QAC/C,CAAC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;;AA1NF,wCA2NC;AA1NuB,qBAAM,GAAG,QAAQ,CAAC;AAClB,mBAAI,GAAG,MAAM,CAAC;AACb,yBAAU,GAAG,YAAY,CAAC;AAElD,2GAA2G;AAC3G,gHAAgH;AAChH,wFAAwF;AACxF,8FAA8F;AAC9F,wEAAwE;AACxE,sEAAsE;AAC/C,+BAAgB,GAAW,KAAK,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { NonCollabClient } from \"./constants.js\";\nimport { MergeTree } from \"./mergeTree.js\";\nimport { isSegmentLeaf, type ISegmentPrivate } from \"./mergeTreeNodes.js\";\nimport { PriorPerspective } from \"./perspective.js\";\nimport { matchProperties } from \"./properties.js\";\nimport {\n\tJsonSegmentSpecs,\n\tMergeTreeChunkLegacy,\n\tserializeAsMinSupportedVersion,\n} from \"./snapshotChunks.js\";\n\ninterface SnapshotHeader {\n\tchunkCount?: number;\n\tsegmentsTotalLength: number;\n\tindexOffset?: number;\n\tsegmentsOffset?: number;\n\tseq: number;\n\t// TODO: Make 'minSeq' non-optional once the new snapshot format becomes the default?\n\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\tminSeq?: number;\n}\n\n/**\n * @internal\n */\nexport class SnapshotLegacy {\n\tpublic static readonly header = \"header\";\n\tpublic static readonly body = \"body\";\n\tprivate static readonly catchupOps = \"catchupOps\";\n\n\t// Split snapshot into two entries - headers (small) and body (overflow) for faster loading initial content\n\t// Please note that this number has no direct relationship to anything other than size of raw text (characters).\n\t// As we produce json for the blob (and then send over the wire compressed), this number\n\t// is really hard to correlate with any actual metric that matters (like bytes over the wire).\n\t// For test with small number of chunks it would be closer to blob size,\n\t// for very chunky text, blob size can easily be 4x-8x of that number.\n\tpublic static readonly sizeOfFirstChunk: number = 10000;\n\n\tprivate header: SnapshotHeader | undefined;\n\tprivate seq: number | undefined;\n\tprivate segments: ISegmentPrivate[] | undefined;\n\tprivate readonly logger: ITelemetryLoggerExt;\n\tprivate readonly chunkSize: number;\n\n\tconstructor(\n\t\tpublic mergeTree: MergeTree,\n\t\tlogger: ITelemetryLoggerExt,\n\t\tpublic filename?: string,\n\t\tpublic onCompletion?: () => void,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"Snapshot\" });\n\t\tthis.chunkSize =\n\t\t\tmergeTree?.options?.mergeTreeSnapshotChunkSize ?? SnapshotLegacy.sizeOfFirstChunk;\n\t}\n\n\tprivate getSeqLengthSegs(\n\t\tallSegments: ISegmentPrivate[],\n\t\tapproxSequenceLength: number,\n\t\tstartIndex = 0,\n\t): MergeTreeChunkLegacy {\n\t\tconst segs: ISegmentPrivate[] = [];\n\t\tlet sequenceLength = 0;\n\t\tlet segCount = 0;\n\t\tlet segsWithAttribution = 0;\n\t\twhile (\n\t\t\tsequenceLength < approxSequenceLength &&\n\t\t\tstartIndex + segCount < allSegments.length\n\t\t) {\n\t\t\tconst pseg = allSegments[startIndex + segCount];\n\t\t\tsegs.push(pseg);\n\t\t\tif (pseg.attribution) {\n\t\t\t\tsegsWithAttribution++;\n\t\t\t}\n\t\t\tsequenceLength += pseg.cachedLength;\n\t\t\tsegCount++;\n\t\t}\n\n\t\tassert(\n\t\t\tsegsWithAttribution === 0 || segsWithAttribution === segCount,\n\t\t\t0x4bf /* all or no segments should have attribution */,\n\t\t);\n\n\t\tconst attributionSerializer = this.mergeTree.attributionPolicy?.serializer;\n\t\tassert(\n\t\t\tsegsWithAttribution === 0 || attributionSerializer !== undefined,\n\t\t\t0x559 /* attribution serializer must be provided when there are segments with attribution. */,\n\t\t);\n\t\treturn {\n\t\t\tversion: undefined,\n\t\t\tchunkStartSegmentIndex: startIndex,\n\t\t\tchunkSegmentCount: segCount,\n\t\t\tchunkLengthChars: sequenceLength,\n\t\t\ttotalLengthChars: this.header!.segmentsTotalLength,\n\t\t\ttotalSegmentCount: allSegments.length,\n\t\t\tchunkSequenceNumber: this.header!.seq,\n\t\t\tsegmentTexts: segs.map((seg) => seg.toJSONObject() as JsonSegmentSpecs),\n\t\t\tattribution:\n\t\t\t\tsegsWithAttribution > 0 || this.mergeTree.attributionPolicy?.isAttached\n\t\t\t\t\t? attributionSerializer?.serializeAttributionCollections(segs)\n\t\t\t\t\t: undefined,\n\t\t};\n\t}\n\n\t/**\n\t * Emits the snapshot to an ISummarizeResult. If provided the optional IFluidSerializer will be used when\n\t * serializing the summary data rather than JSON.stringify.\n\t */\n\temit(\n\t\tcatchUpMsgs: ISequencedDocumentMessage[],\n\t\tserializer: IFluidSerializer,\n\t\tbind: IFluidHandle,\n\t): ISummaryTreeWithStats {\n\t\tconst chunk1 = this.getSeqLengthSegs(this.segments!, this.chunkSize);\n\t\tlet length: number = chunk1.chunkLengthChars;\n\t\tlet segments: number = chunk1.chunkSegmentCount;\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addBlob(\n\t\t\tSnapshotLegacy.header,\n\t\t\tserializeAsMinSupportedVersion(\n\t\t\t\tSnapshotLegacy.header,\n\t\t\t\tchunk1,\n\t\t\t\tthis.logger,\n\t\t\t\tthis.mergeTree.options,\n\t\t\t\tserializer,\n\t\t\t\tbind,\n\t\t\t),\n\t\t);\n\n\t\tif (chunk1.chunkSegmentCount < chunk1.totalSegmentCount!) {\n\t\t\tconst chunk2 = this.getSeqLengthSegs(\n\t\t\t\tthis.segments!,\n\t\t\t\tthis.header!.segmentsTotalLength,\n\t\t\t\tchunk1.chunkSegmentCount,\n\t\t\t);\n\t\t\tlength += chunk2.chunkLengthChars;\n\t\t\tsegments += chunk2.chunkSegmentCount;\n\t\t\tbuilder.addBlob(\n\t\t\t\tSnapshotLegacy.body,\n\t\t\t\tserializeAsMinSupportedVersion(\n\t\t\t\t\tSnapshotLegacy.body,\n\t\t\t\t\tchunk2,\n\t\t\t\t\tthis.logger,\n\t\t\t\t\tthis.mergeTree.options,\n\t\t\t\t\tserializer,\n\t\t\t\t\tbind,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tassert(\n\t\t\tlength === this.header!.segmentsTotalLength,\n\t\t\t0x05d /* \"emit: mismatch in segmentsTotalLength\" */,\n\t\t);\n\n\t\tassert(\n\t\t\tsegments === chunk1.totalSegmentCount,\n\t\t\t0x05e /* \"emit: mismatch in totalSegmentCount\" */,\n\t\t);\n\n\t\tif (catchUpMsgs !== undefined && catchUpMsgs.length > 0) {\n\t\t\t// Messages used to have a \"term\" property which has since been removed.\n\t\t\t// It is benign so it doesn't really need to be deleted here, but doing so permits snapshot tests\n\t\t\t// to pass with an exact match (and matching the updated definition of ISequencedDocumentMessage).\n\t\t\tfor (const message of catchUpMsgs) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\tdelete (message as any).term;\n\t\t\t}\n\t\t\tbuilder.addBlob(\n\t\t\t\tthis.mergeTree.options?.catchUpBlobName ?? SnapshotLegacy.catchupOps,\n\t\t\t\tserializer ? serializer.stringify(catchUpMsgs, bind) : JSON.stringify(catchUpMsgs),\n\t\t\t);\n\t\t}\n\n\t\treturn builder.getSummaryTree();\n\t}\n\n\textractSync(): ISegmentPrivate[] {\n\t\tconst collabWindow = this.mergeTree.collabWindow;\n\t\tconst seq = (this.seq = collabWindow.minSeq);\n\t\tconst minSeqPerspective = new PriorPerspective(this.seq, NonCollabClient);\n\t\tthis.header = {\n\t\t\tsegmentsTotalLength: this.mergeTree.getLength(minSeqPerspective),\n\t\t\tseq: this.mergeTree.collabWindow.minSeq,\n\t\t};\n\n\t\tlet originalSegments = 0;\n\n\t\tconst segs: ISegmentPrivate[] = [];\n\t\tlet prev: ISegmentPrivate | undefined;\n\t\tconst extractSegment = (segment: ISegmentPrivate): boolean => {\n\t\t\tif (isSegmentLeaf(segment) && minSeqPerspective.isSegmentPresent(segment)) {\n\t\t\t\toriginalSegments += 1;\n\t\t\t\tconst properties =\n\t\t\t\t\tsegment.propertyManager?.getAtSeq(segment.properties, seq) ?? segment.properties;\n\t\t\t\tif (prev?.canAppend(segment) && matchProperties(prev.properties, properties)) {\n\t\t\t\t\tprev.append(segment.clone());\n\t\t\t\t} else {\n\t\t\t\t\tprev = segment.clone();\n\t\t\t\t\tprev.properties = properties;\n\t\t\t\t\tsegs.push(prev);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\tthis.mergeTree.mapRange(extractSegment, minSeqPerspective, undefined);\n\n\t\tthis.segments = [];\n\t\tlet totalLength: number = 0;\n\t\tsegs.map((segment) => {\n\t\t\ttotalLength += segment.cachedLength;\n\t\t\tif (segment.properties !== undefined && Object.keys(segment.properties).length === 0) {\n\t\t\t\tsegment.properties = undefined;\n\t\t\t}\n\t\t\tthis.segments!.push(segment);\n\t\t});\n\n\t\t// To reduce potential spam from this telemetry, we sample only a small\n\t\t// percentage of summaries\n\t\tif (Math.abs(originalSegments - segs.length) > 500 && Math.random() < 0.005) {\n\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"MergeTreeLegacySummarizeSegmentCount\",\n\t\t\t\toriginalSegments,\n\t\t\t\tsegmentsAfterCombine: segs.length,\n\t\t\t\tsegmentsLen: this.segments.length,\n\t\t\t});\n\t\t}\n\n\t\t// We observed this.header.segmentsTotalLength < totalLength to happen in some cases\n\t\t// When this condition happens, we might not write out all segments in getSeqLengthSegs()\n\t\t// when writing out \"body\". Issue #1995 tracks following up on the core of the problem.\n\t\t// In the meantime, this code makes sure we will write out all segments properly\n\n\t\tif (this.header.segmentsTotalLength !== totalLength) {\n\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\teventName: \"SegmentsTotalLengthMismatch\",\n\t\t\t\ttotalLength,\n\t\t\t\tsegmentsTotalLength: this.header.segmentsTotalLength,\n\t\t\t});\n\t\t\tthis.header.segmentsTotalLength = totalLength;\n\t\t}\n\n\t\treturn this.segments;\n\t}\n}\n"]}
package/dist/stamps.d.ts CHANGED
@@ -81,7 +81,7 @@ export declare function isAcked(a: OperationStamp): boolean;
81
81
  * Inserts a stamp into a sorted list of stamps in the correct (sorted) position.
82
82
  *
83
83
  * Beware that this uses Array.splice, thus requires asymptotics considerations.
84
- * If inserting a variable number of timestamp, consider just pushing them and sorting the list
84
+ * If inserting a variable number of timestamps, consider just pushing them and sorting the list
85
85
  * after using {@link compare} instead.
86
86
  */
87
87
  export declare function spliceIntoList(list: OperationStamp[], stamp: OperationStamp): void;
package/dist/stamps.js CHANGED
@@ -52,7 +52,7 @@ exports.isAcked = isAcked;
52
52
  * Inserts a stamp into a sorted list of stamps in the correct (sorted) position.
53
53
  *
54
54
  * Beware that this uses Array.splice, thus requires asymptotics considerations.
55
- * If inserting a variable number of timestamp, consider just pushing them and sorting the list
55
+ * If inserting a variable number of timestamps, consider just pushing them and sorting the list
56
56
  * after using {@link compare} instead.
57
57
  */
58
58
  function spliceIntoList(list, stamp) {
@@ -1 +1 @@
1
- {"version":3,"file":"stamps.js","sourceRoot":"","sources":["../src/stamps.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iDAA0D;AA6E1D,SAAgB,QAAQ,CAAC,CAAiB,EAAE,CAAiB;IAC5D,IAAI,CAAC,CAAC,GAAG,KAAK,uCAAwB,EAAE,CAAC;QACxC,oEAAoE;QACpE,OAAO,CAA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;AACF,CAAC;AARD,0BAQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UnassignedSequenceNumber } from \"./constants.js\";\n\n/**\n * A stamp that identifies provenance of an operation performed on the MergeTree.\n *\n * Stamps identify a point in time (`seq`/`localSeq`) as well as the source (`clientId`) for the operation.\n * This provides enough information to linearize all known applied operations: acked operations happen before\n * local+unacked ones, with acked operations ordered by their sequence numbers and local+unacked operations\n * ordered by their localSeq.\n *\n * By including `clientId`, it also provides enough information to resolve whether segments are visible\n * from alternative perspectives: a remote client will have seen all of its own previous operations as well as\n * those at or below the op's reference sequence number.\n *\n * @remarks - As the `readonly` identifies suggest, these stamps should be treated as immutable.\n * New operations applied to a merge-tree should create new stamps rather than modify existing ones (e.g. when\n * a change's ack happens).\n * @internal\n */\nexport interface OperationStamp {\n\t/**\n\t * The sequence number at which this operation was applied.\n\t */\n\treadonly seq: number;\n\n\t/**\n\t * Short clientId for the client that performed this operation.\n\t */\n\treadonly clientId: number;\n\n\t/**\n\t * Local seq at which this operation was applied.\n\t * This is defined if and only if the operation is pending an ack, i.e. `seq` is UnassignedSequenceNumber.\n\t *\n\t * @privateRemarks\n\t * See {@link CollaborationWindow.localSeq} for more information on the semantics of localSeq.\n\t */\n\treadonly localSeq?: number;\n}\n\n/**\n * {@link OperationStamp} for an 'insert' operation.\n */\nexport interface InsertOperationStamp extends OperationStamp {\n\treadonly type: \"insert\";\n}\n\n/**\n * {@link OperationStamp} for a 'set remove' operation. This aligns with the `markRangeRemoved` API in MergeTree.\n *\n * @remarks The terminology here comes from the fact that the removal should affect only the *set* of nodes that were\n * specified at the time the local client issued the remove, and not any nodes that were inserted concurrently.\n *\n * Not using \"remove\" and \"obliterate\" here allows us to unambiguously use the term \"remove\" elsewhere in code to mean\n * \"removed from the tree, either by MergeTree.obliterateRange or MergeTree.removeRange\". This is convenient as the vast majority\n * of merge-tree code only cares about segment visibility and not the specific operation that caused a segment to be removed.\n */\nexport interface SetRemoveOperationStamp extends OperationStamp {\n\treadonly type: \"setRemove\";\n}\n\n/**\n * {@link OperationStamp} for a 'set remove' operation. This aligns with the `obliterateRange` API in MergeTree.\n *\n * @remarks The terminology here comes from the fact that the removal should affect the *slice* of nodes between the\n * start and end point specified by the local client, which includes any nodes that were inserted concurrently.\n *\n * Not using \"remove\" and \"obliterate\" here allows us to unambiguously use the term \"remove\" elsewhere in code to mean\n * \"removed from the tree, either by MergeTree.obliterateRange or MergeTree.removeRange\". This is convenient as the vast majority\n * of merge-tree code only cares about segment visibility and not the specific operation that caused a segment to be removed.\n */\nexport interface SliceRemoveOperationStamp extends OperationStamp {\n\treadonly type: \"sliceRemove\";\n}\n\nexport type RemoveOperationStamp = SetRemoveOperationStamp | SliceRemoveOperationStamp;\n\nexport function lessThan(a: OperationStamp, b: OperationStamp): boolean {\n\tif (a.seq === UnassignedSequenceNumber) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn b.seq === UnassignedSequenceNumber && a.localSeq! < b.localSeq!;\n\t}\n\n\tif (b.seq === UnassignedSequenceNumber) {\n\t\treturn true;\n\t}\n\n\treturn a.seq < b.seq;\n}\n\nexport function gte(a: OperationStamp, b: OperationStamp): boolean {\n\treturn !lessThan(a, b);\n}\n\nexport function greaterThan(a: OperationStamp, b: OperationStamp): boolean {\n\tif (a.seq === UnassignedSequenceNumber) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn b.seq !== UnassignedSequenceNumber || a.localSeq! > b.localSeq!;\n\t}\n\n\tif (b.seq === UnassignedSequenceNumber) {\n\t\treturn false;\n\t}\n\n\treturn a.seq > b.seq;\n}\n\nexport function lte(a: OperationStamp, b: OperationStamp): boolean {\n\treturn !greaterThan(a, b);\n}\n\nexport function equal(a: OperationStamp, b: OperationStamp): boolean {\n\treturn a.seq === b.seq && a.clientId === b.clientId && a.localSeq === b.localSeq;\n}\n\nexport function isLocal(a: OperationStamp): boolean {\n\treturn a.seq === UnassignedSequenceNumber;\n}\n\nexport function isAcked(a: OperationStamp): boolean {\n\treturn a.seq !== UnassignedSequenceNumber;\n}\n\n/**\n * Inserts a stamp into a sorted list of stamps in the correct (sorted) position.\n *\n * Beware that this uses Array.splice, thus requires asymptotics considerations.\n * If inserting a variable number of timestamp, consider just pushing them and sorting the list\n * after using {@link compare} instead.\n */\nexport function spliceIntoList(list: OperationStamp[], stamp: OperationStamp): void {\n\tif (isLocal(stamp) || list.length === 0) {\n\t\tlist.push(stamp);\n\t} else {\n\t\tfor (let i = list.length - 1; i >= 0; i--) {\n\t\t\tif (greaterThan(stamp, list[i])) {\n\t\t\t\tlist.splice(i + 1, 0, stamp);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// Less than all stamps in the list: put it at the beginning.\n\t\tlist.unshift(stamp);\n\t}\n}\n\nexport function hasAnyAckedOperation(list: OperationStamp[]): boolean {\n\treturn list.some((ts) => isAcked(ts));\n}\n\nexport function compare(a: OperationStamp, b: OperationStamp): number {\n\tif (greaterThan(a, b)) {\n\t\treturn 1;\n\t} else if (lessThan(a, b)) {\n\t\treturn -1;\n\t} else {\n\t\treturn 0;\n\t}\n}\n"]}
1
+ {"version":3,"file":"stamps.js","sourceRoot":"","sources":["../src/stamps.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iDAA0D;AA6E1D,SAAgB,QAAQ,CAAC,CAAiB,EAAE,CAAiB;IAC5D,IAAI,CAAC,CAAC,GAAG,KAAK,uCAAwB,EAAE,CAAC;QACxC,oEAAoE;QACpE,OAAO,CAAC,CAAC,GAAG,KAAK,uCAAwB,IAAI,CAAC,CAAC,QAAS,GAAG,CAAC,CAAC,QAAS,CAAC;IACxE,CAAC;IAED,IAAI,CAAC,CAAC,GAAG,KAAK,uCAAwB,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAA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CAAC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC;SAAM,CAAC;QACP,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3C,IAAI,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBACjC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;gBAC7B,OAAO;YACR,CAAC;QACF,CAAC;QAED,6DAA6D;QAC7D,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACF,CAAC;AAdD,wCAcC;AAED,SAAgB,oBAAoB,CAAC,IAAsB;IAC1D,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;AACvC,CAAC;AAFD,oDAEC;AAED,SAAgB,OAAO,CAAC,CAAiB,EAAE,CAAiB;IAC3D,IAAI,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QACvB,OAAO,CAAC,CAAC;IACV,CAAC;SAAM,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QAC3B,OAAO,CAAC,CAAC,CAAC;IACX,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,CAAC;IACV,CAAC;AACF,CAAC;AARD,0BAQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UnassignedSequenceNumber } from \"./constants.js\";\n\n/**\n * A stamp that identifies provenance of an operation performed on the MergeTree.\n *\n * Stamps identify a point in time (`seq`/`localSeq`) as well as the source (`clientId`) for the operation.\n * This provides enough information to linearize all known applied operations: acked operations happen before\n * local+unacked ones, with acked operations ordered by their sequence numbers and local+unacked operations\n * ordered by their localSeq.\n *\n * By including `clientId`, it also provides enough information to resolve whether segments are visible\n * from alternative perspectives: a remote client will have seen all of its own previous operations as well as\n * those at or below the op's reference sequence number.\n *\n * @remarks - As the `readonly` identifies suggest, these stamps should be treated as immutable.\n * New operations applied to a merge-tree should create new stamps rather than modify existing ones (e.g. when\n * a change's ack happens).\n * @internal\n */\nexport interface OperationStamp {\n\t/**\n\t * The sequence number at which this operation was applied.\n\t */\n\treadonly seq: number;\n\n\t/**\n\t * Short clientId for the client that performed this operation.\n\t */\n\treadonly clientId: number;\n\n\t/**\n\t * Local seq at which this operation was applied.\n\t * This is defined if and only if the operation is pending an ack, i.e. `seq` is UnassignedSequenceNumber.\n\t *\n\t * @privateRemarks\n\t * See {@link CollaborationWindow.localSeq} for more information on the semantics of localSeq.\n\t */\n\treadonly localSeq?: number;\n}\n\n/**\n * {@link OperationStamp} for an 'insert' operation.\n */\nexport interface InsertOperationStamp extends OperationStamp {\n\treadonly type: \"insert\";\n}\n\n/**\n * {@link OperationStamp} for a 'set remove' operation. This aligns with the `markRangeRemoved` API in MergeTree.\n *\n * @remarks The terminology here comes from the fact that the removal should affect only the *set* of nodes that were\n * specified at the time the local client issued the remove, and not any nodes that were inserted concurrently.\n *\n * Not using \"remove\" and \"obliterate\" here allows us to unambiguously use the term \"remove\" elsewhere in code to mean\n * \"removed from the tree, either by MergeTree.obliterateRange or MergeTree.removeRange\". This is convenient as the vast majority\n * of merge-tree code only cares about segment visibility and not the specific operation that caused a segment to be removed.\n */\nexport interface SetRemoveOperationStamp extends OperationStamp {\n\treadonly type: \"setRemove\";\n}\n\n/**\n * {@link OperationStamp} for a 'set remove' operation. This aligns with the `obliterateRange` API in MergeTree.\n *\n * @remarks The terminology here comes from the fact that the removal should affect the *slice* of nodes between the\n * start and end point specified by the local client, which includes any nodes that were inserted concurrently.\n *\n * Not using \"remove\" and \"obliterate\" here allows us to unambiguously use the term \"remove\" elsewhere in code to mean\n * \"removed from the tree, either by MergeTree.obliterateRange or MergeTree.removeRange\". This is convenient as the vast majority\n * of merge-tree code only cares about segment visibility and not the specific operation that caused a segment to be removed.\n */\nexport interface SliceRemoveOperationStamp extends OperationStamp {\n\treadonly type: \"sliceRemove\";\n}\n\nexport type RemoveOperationStamp = SetRemoveOperationStamp | SliceRemoveOperationStamp;\n\nexport function lessThan(a: OperationStamp, b: OperationStamp): boolean {\n\tif (a.seq === UnassignedSequenceNumber) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn b.seq === UnassignedSequenceNumber && a.localSeq! < b.localSeq!;\n\t}\n\n\tif (b.seq === UnassignedSequenceNumber) {\n\t\treturn true;\n\t}\n\n\treturn a.seq < b.seq;\n}\n\nexport function gte(a: OperationStamp, b: OperationStamp): boolean {\n\treturn !lessThan(a, b);\n}\n\nexport function greaterThan(a: OperationStamp, b: OperationStamp): boolean {\n\tif (a.seq === UnassignedSequenceNumber) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\treturn b.seq !== UnassignedSequenceNumber || a.localSeq! > b.localSeq!;\n\t}\n\n\tif (b.seq === UnassignedSequenceNumber) {\n\t\treturn false;\n\t}\n\n\treturn a.seq > b.seq;\n}\n\nexport function lte(a: OperationStamp, b: OperationStamp): boolean {\n\treturn !greaterThan(a, b);\n}\n\nexport function equal(a: OperationStamp, b: OperationStamp): boolean {\n\treturn a.seq === b.seq && a.clientId === b.clientId && a.localSeq === b.localSeq;\n}\n\nexport function isLocal(a: OperationStamp): boolean {\n\treturn a.seq === UnassignedSequenceNumber;\n}\n\nexport function isAcked(a: OperationStamp): boolean {\n\treturn a.seq !== UnassignedSequenceNumber;\n}\n\n/**\n * Inserts a stamp into a sorted list of stamps in the correct (sorted) position.\n *\n * Beware that this uses Array.splice, thus requires asymptotics considerations.\n * If inserting a variable number of timestamps, consider just pushing them and sorting the list\n * after using {@link compare} instead.\n */\nexport function spliceIntoList(list: OperationStamp[], stamp: OperationStamp): void {\n\tif (isLocal(stamp) || list.length === 0) {\n\t\tlist.push(stamp);\n\t} else {\n\t\tfor (let i = list.length - 1; i >= 0; i--) {\n\t\t\tif (greaterThan(stamp, list[i])) {\n\t\t\t\tlist.splice(i + 1, 0, stamp);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// Less than all stamps in the list: put it at the beginning.\n\t\tlist.unshift(stamp);\n\t}\n}\n\nexport function hasAnyAckedOperation(list: OperationStamp[]): boolean {\n\treturn list.some((ts) => isAcked(ts));\n}\n\nexport function compare(a: OperationStamp, b: OperationStamp): number {\n\tif (greaterThan(a, b)) {\n\t\treturn 1;\n\t} else if (lessThan(a, b)) {\n\t\treturn -1;\n\t} else {\n\t\treturn 0;\n\t}\n}\n"]}
@@ -7,20 +7,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const benchmark_1 = require("@fluid-tools/benchmark");
8
8
  const mergeTree_js_1 = require("../mergeTree.js");
9
9
  const ops_js_1 = require("../ops.js");
10
- const testUtils_js_1 = require("./testUtils.js");
10
+ const textSegment_js_1 = require("../textSegment.js");
11
11
  function constructTree(numOfSegments) {
12
12
  const mergeTree = new mergeTree_js_1.MergeTree();
13
13
  for (let i = 0; i < numOfSegments; i++) {
14
- (0, testUtils_js_1.insertText)({
15
- mergeTree,
16
- pos: 0,
17
- refSeq: i,
18
- clientId: 0,
19
- seq: i,
20
- text: "a",
21
- props: undefined,
22
- opArgs: { op: { type: ops_js_1.MergeTreeDeltaType.INSERT } },
23
- });
14
+ mergeTree.insertSegments(0, [textSegment_js_1.TextSegment.make("a")], mergeTree.localPerspective, { seq: i, clientId: 0 }, { op: { type: ops_js_1.MergeTreeDeltaType.INSERT } });
24
15
  }
25
16
  return mergeTree;
26
17
  }
@@ -31,16 +22,7 @@ describe("MergeTree insertion", () => {
31
22
  title: "insert into empty tree",
32
23
  benchmarkFn: () => {
33
24
  const emptyTree = new mergeTree_js_1.MergeTree();
34
- (0, testUtils_js_1.insertText)({
35
- mergeTree: emptyTree,
36
- pos: 0,
37
- refSeq: 0,
38
- clientId: 0,
39
- seq: 0,
40
- text: "a",
41
- props: undefined,
42
- opArgs: { op: { type: ops_js_1.MergeTreeDeltaType.INSERT } },
43
- });
25
+ emptyTree.insertSegments(0, [textSegment_js_1.TextSegment.make("a")], emptyTree.localPerspective, { seq: 0, clientId: 0 }, { op: { type: ops_js_1.MergeTreeDeltaType.INSERT } });
44
26
  },
45
27
  });
46
28
  let startTree = constructTree(TREE_SIZE);
@@ -49,16 +31,7 @@ describe("MergeTree insertion", () => {
49
31
  title: "insert at start of large tree",
50
32
  benchmarkFn: () => {
51
33
  for (let i = TREE_SIZE; i < TREE_SIZE + 25; i++) {
52
- (0, testUtils_js_1.insertText)({
53
- mergeTree: startTree,
54
- pos: 0,
55
- refSeq: i,
56
- clientId: 0,
57
- seq: i + 1,
58
- text: "a",
59
- props: undefined,
60
- opArgs: { op: { type: ops_js_1.MergeTreeDeltaType.INSERT } },
61
- });
34
+ startTree.insertSegments(0, [textSegment_js_1.TextSegment.make("a")], startTree.localPerspective, { seq: i + 1, clientId: 0 }, { op: { type: ops_js_1.MergeTreeDeltaType.INSERT } });
62
35
  }
63
36
  },
64
37
  beforeEachBatch: () => {
@@ -71,16 +44,7 @@ describe("MergeTree insertion", () => {
71
44
  title: "insert at middle of large tree",
72
45
  benchmarkFn: () => {
73
46
  for (let i = TREE_SIZE; i < TREE_SIZE + 25; i++) {
74
- (0, testUtils_js_1.insertText)({
75
- mergeTree: middleTree,
76
- pos: TREE_SIZE / 2,
77
- refSeq: i,
78
- clientId: 0,
79
- seq: i + 1,
80
- text: "a",
81
- props: undefined,
82
- opArgs: { op: { type: ops_js_1.MergeTreeDeltaType.INSERT } },
83
- });
47
+ middleTree.insertSegments(TREE_SIZE / 2, [textSegment_js_1.TextSegment.make("a")], middleTree.localPerspective, { seq: i + 1, clientId: 0 }, { op: { type: ops_js_1.MergeTreeDeltaType.INSERT } });
84
48
  }
85
49
  },
86
50
  beforeEachBatch: () => {
@@ -93,16 +57,7 @@ describe("MergeTree insertion", () => {
93
57
  title: "insert at end of large tree",
94
58
  benchmarkFn: () => {
95
59
  for (let i = TREE_SIZE; i < TREE_SIZE + 25; i++) {
96
- (0, testUtils_js_1.insertText)({
97
- mergeTree: endTree,
98
- pos: i,
99
- refSeq: i,
100
- clientId: 0,
101
- seq: i + 1,
102
- text: "a",
103
- props: undefined,
104
- opArgs: { op: { type: ops_js_1.MergeTreeDeltaType.INSERT } },
105
- });
60
+ endTree.insertSegments(i, [textSegment_js_1.TextSegment.make("a")], endTree.localPerspective, { seq: i + 1, clientId: 0 }, { op: { type: ops_js_1.MergeTreeDeltaType.INSERT } });
106
61
  }
107
62
  },
108
63
  beforeEachBatch: () => {
@@ -1 +1 @@
1
- {"version":3,"file":"Insertion.perf.spec.js","sourceRoot":"","sources":["../../src/test/Insertion.perf.spec.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,sDAAkE;AAElE,kDAA4C;AAC5C,sCAA+C;AAE/C,iDAA4C;AAE5C,SAAS,aAAa,CAAC,aAAqB;IAC3C,MAAM,SAAS,GAAG,IAAI,wBAAS,EAAE,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,aAAa,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,IAAA,yBAAU,EAAC;YACV,SAAS;YACT,GAAG,EAAE,CAAC;YACN,MAAM,EAAE,CAAC;YACT,QAAQ,EAAE,CAAC;YACX,GAAG,EAAE,CAAC;YACN,IAAI,EAAE,GAAG;YACT,KAAK,EAAE,SAAS;YAChB,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,2BAAkB,CAAC,MAAM,EAAE,EAAE;SACnD,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,MAAM,SAAS,GAAW,IAAI,CAAC;AAE/B,QAAQ,C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E,SAAS;oBAChB,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,2BAAkB,CAAC,MAAM,EAAE,EAAE;iBACnD,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;QACD,eAAe,EAAE,GAAG,EAAE;YACrB,OAAO,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;QACpC,CAAC;KACD,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { BenchmarkType, benchmark } from \"@fluid-tools/benchmark\";\n\nimport { MergeTree } from \"../mergeTree.js\";\nimport { MergeTreeDeltaType } from \"../ops.js\";\n\nimport { insertText } from \"./testUtils.js\";\n\nfunction constructTree(numOfSegments: number): MergeTree {\n\tconst mergeTree = new MergeTree();\n\tfor (let i = 0; i < numOfSegments; i++) {\n\t\tinsertText({\n\t\t\tmergeTree,\n\t\t\tpos: 0,\n\t\t\trefSeq: i,\n\t\t\tclientId: 0,\n\t\t\tseq: i,\n\t\t\ttext: \"a\",\n\t\t\tprops: undefined,\n\t\t\topArgs: { op: { type: MergeTreeDeltaType.INSERT } },\n\t\t});\n\t}\n\treturn mergeTree;\n}\n\nconst TREE_SIZE: number = 7500;\n\ndescribe(\"MergeTree insertion\", () => {\n\tbenchmark({\n\t\ttype: BenchmarkType.Measurement,\n\t\ttitle: \"insert into empty tree\",\n\t\tbenchmarkFn: () => {\n\t\t\tconst emptyTree = new MergeTree();\n\t\t\tinsertText({\n\t\t\t\tmergeTree: emptyTree,\n\t\t\t\tpos: 0,\n\t\t\t\trefSeq: 0,\n\t\t\t\tclientId: 0,\n\t\t\t\tseq: 0,\n\t\t\t\ttext: \"a\",\n\t\t\t\tprops: undefined,\n\t\t\t\topArgs: { op: { type: MergeTreeDeltaType.INSERT } },\n\t\t\t});\n\t\t},\n\t});\n\n\tlet startTree = constructTree(TREE_SIZE);\n\tbenchmark({\n\t\ttype: BenchmarkType.Measurement,\n\t\ttitle: \"insert at start of large tree\",\n\t\tbenchmarkFn: () => {\n\t\t\tfor (let i = TREE_SIZE; i < TREE_SIZE + 25; i++) {\n\t\t\t\tinsertText({\n\t\t\t\t\tmergeTree: startTree,\n\t\t\t\t\tpos: 0,\n\t\t\t\t\trefSeq: i,\n\t\t\t\t\tclientId: 0,\n\t\t\t\t\tseq: i + 1,\n\t\t\t\t\ttext: \"a\",\n\t\t\t\t\tprops: undefined,\n\t\t\t\t\topArgs: { op: { type: MergeTreeDeltaType.INSERT } },\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tbeforeEachBatch: () => {\n\t\t\tstartTree = constructTree(TREE_SIZE);\n\t\t},\n\t});\n\n\tlet middleTree = constructTree(TREE_SIZE);\n\tbenchmark({\n\t\ttype: BenchmarkType.Measurement,\n\t\ttitle: \"insert at middle of large tree\",\n\t\tbenchmarkFn: () => {\n\t\t\tfor (let i = TREE_SIZE; i < TREE_SIZE + 25; i++) {\n\t\t\t\tinsertText({\n\t\t\t\t\tmergeTree: middleTree,\n\t\t\t\t\tpos: TREE_SIZE / 2,\n\t\t\t\t\trefSeq: i,\n\t\t\t\t\tclientId: 0,\n\t\t\t\t\tseq: i + 1,\n\t\t\t\t\ttext: \"a\",\n\t\t\t\t\tprops: undefined,\n\t\t\t\t\topArgs: { op: { type: MergeTreeDeltaType.INSERT } },\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tbeforeEachBatch: () => {\n\t\t\tmiddleTree = constructTree(TREE_SIZE);\n\t\t},\n\t});\n\n\tlet endTree = constructTree(TREE_SIZE);\n\tbenchmark({\n\t\ttype: BenchmarkType.Measurement,\n\t\ttitle: \"insert at end of large tree\",\n\t\tbenchmarkFn: () => {\n\t\t\tfor (let i = TREE_SIZE; i < TREE_SIZE + 25; i++) {\n\t\t\t\tinsertText({\n\t\t\t\t\tmergeTree: endTree,\n\t\t\t\t\tpos: i,\n\t\t\t\t\trefSeq: i,\n\t\t\t\t\tclientId: 0,\n\t\t\t\t\tseq: i + 1,\n\t\t\t\t\ttext: \"a\",\n\t\t\t\t\tprops: undefined,\n\t\t\t\t\topArgs: { op: { type: MergeTreeDeltaType.INSERT } },\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tbeforeEachBatch: () => {\n\t\t\tendTree = constructTree(TREE_SIZE);\n\t\t},\n\t});\n});\n"]}
1
+ {"version":3,"file":"Insertion.perf.spec.js","sourceRoot":"","sources":["../../src/test/Insertion.perf.spec.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,sDAAkE;AAElE,kDAA4C;AAC5C,sCAA+C;AAC/C,sDAAgD;AAEhD,SAAS,aAAa,CAAC,aAAqB;IAC3C,MAAM,SAAS,GAAG,IAAI,wBAAS,EAAE,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,aAAa,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,SAAS,CAAC,cAAc,CACvB,CAAC,EACD,CAAC,4BAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EACvB,SAAS,CAAC,gBAAgB,EAC1B,EAAE,GAAG,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,EACvB,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,2BAAkB,CAAC,MAAM,EAAE,EAAE,CAC3C,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,MAAM,SAAS,GAAW,IAAI,CAAC;AAE/B,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACpC,IAAA,qBAAS,EAAC;QACT,IAAI,EAAE,yBAAa,CAAC,WAAW;QAC/B,KAAK,EAAE,wBAAwB;QAC/B,WAAW,EAAE,GAAG,EAAE;YACjB,MAAM,SAAS,GAAG,IAAI,wBAAS,EAAE,CAAC;YAClC,SAAS,CAAC,cAAc,CACvB,CAAC,EACD,CAAC,4BAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAC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AAC,IAAI,CAAC,GAAG,CAAC,CAAC,EACvB,UAAU,CAAC,gBAAgB,EAC3B,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,EAC3B,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,2BAAkB,CAAC,MAAM,EAAE,EAAE,CAC3C,CAAC;YACH,CAAC;QACF,CAAC;QACD,eAAe,EAAE,GAAG,EAAE;YACrB,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;QACvC,CAAC;KACD,CAAC,CAAC;IAEH,IAAI,OAAO,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;IACvC,IAAA,qBAAS,EAAC;QACT,IAAI,EAAE,yBAAa,CAAC,WAAW;QAC/B,KAAK,EAAE,6BAA6B;QACpC,WAAW,EAAE,GAAG,EAAE;YACjB,KAAK,IAAI,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;gBACjD,OAAO,CAAC,cAAc,CACrB,CAAC,EACD,CAAC,4BAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EACvB,OAAO,CAAC,gBAAgB,EACxB,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,EAC3B,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,2BAAkB,CAAC,MAAM,EAAE,EAAE,CAC3C,CAAC;YACH,CAAC;QACF,CAAC;QACD,eAAe,EAAE,GAAG,EAAE;YACrB,OAAO,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;QACpC,CAAC;KACD,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { BenchmarkType, benchmark } from \"@fluid-tools/benchmark\";\n\nimport { MergeTree } from \"../mergeTree.js\";\nimport { MergeTreeDeltaType } from \"../ops.js\";\nimport { TextSegment } from \"../textSegment.js\";\n\nfunction constructTree(numOfSegments: number): MergeTree {\n\tconst mergeTree = new MergeTree();\n\tfor (let i = 0; i < numOfSegments; i++) {\n\t\tmergeTree.insertSegments(\n\t\t\t0,\n\t\t\t[TextSegment.make(\"a\")],\n\t\t\tmergeTree.localPerspective,\n\t\t\t{ seq: i, clientId: 0 },\n\t\t\t{ op: { type: MergeTreeDeltaType.INSERT } },\n\t\t);\n\t}\n\treturn mergeTree;\n}\n\nconst TREE_SIZE: number = 7500;\n\ndescribe(\"MergeTree insertion\", () => {\n\tbenchmark({\n\t\ttype: BenchmarkType.Measurement,\n\t\ttitle: \"insert into empty tree\",\n\t\tbenchmarkFn: () => {\n\t\t\tconst emptyTree = new MergeTree();\n\t\t\temptyTree.insertSegments(\n\t\t\t\t0,\n\t\t\t\t[TextSegment.make(\"a\")],\n\t\t\t\temptyTree.localPerspective,\n\t\t\t\t{ seq: 0, clientId: 0 },\n\t\t\t\t{ op: { type: MergeTreeDeltaType.INSERT } },\n\t\t\t);\n\t\t},\n\t});\n\n\tlet startTree = constructTree(TREE_SIZE);\n\tbenchmark({\n\t\ttype: BenchmarkType.Measurement,\n\t\ttitle: \"insert at start of large tree\",\n\t\tbenchmarkFn: () => {\n\t\t\tfor (let i = TREE_SIZE; i < TREE_SIZE + 25; i++) {\n\t\t\t\tstartTree.insertSegments(\n\t\t\t\t\t0,\n\t\t\t\t\t[TextSegment.make(\"a\")],\n\t\t\t\t\tstartTree.localPerspective,\n\t\t\t\t\t{ seq: i + 1, clientId: 0 },\n\t\t\t\t\t{ op: { type: MergeTreeDeltaType.INSERT } },\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\tbeforeEachBatch: () => {\n\t\t\tstartTree = constructTree(TREE_SIZE);\n\t\t},\n\t});\n\n\tlet middleTree = constructTree(TREE_SIZE);\n\tbenchmark({\n\t\ttype: BenchmarkType.Measurement,\n\t\ttitle: \"insert at middle of large tree\",\n\t\tbenchmarkFn: () => {\n\t\t\tfor (let i = TREE_SIZE; i < TREE_SIZE + 25; i++) {\n\t\t\t\tmiddleTree.insertSegments(\n\t\t\t\t\tTREE_SIZE / 2,\n\t\t\t\t\t[TextSegment.make(\"a\")],\n\t\t\t\t\tmiddleTree.localPerspective,\n\t\t\t\t\t{ seq: i + 1, clientId: 0 },\n\t\t\t\t\t{ op: { type: MergeTreeDeltaType.INSERT } },\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\tbeforeEachBatch: () => {\n\t\t\tmiddleTree = constructTree(TREE_SIZE);\n\t\t},\n\t});\n\n\tlet endTree = constructTree(TREE_SIZE);\n\tbenchmark({\n\t\ttype: BenchmarkType.Measurement,\n\t\ttitle: \"insert at end of large tree\",\n\t\tbenchmarkFn: () => {\n\t\t\tfor (let i = TREE_SIZE; i < TREE_SIZE + 25; i++) {\n\t\t\t\tendTree.insertSegments(\n\t\t\t\t\ti,\n\t\t\t\t\t[TextSegment.make(\"a\")],\n\t\t\t\t\tendTree.localPerspective,\n\t\t\t\t\t{ seq: i + 1, clientId: 0 },\n\t\t\t\t\t{ op: { type: MergeTreeDeltaType.INSERT } },\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\tbeforeEachBatch: () => {\n\t\t\tendTree = constructTree(TREE_SIZE);\n\t\t},\n\t});\n});\n"]}