@fluid-experimental/tree 1.0.1 → 1.1.0-75972

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 (57) hide show
  1. package/dist/EditLog.d.ts.map +1 -1
  2. package/dist/EditLog.js +4 -7
  3. package/dist/EditLog.js.map +1 -1
  4. package/dist/LogViewer.d.ts.map +1 -1
  5. package/dist/LogViewer.js +1 -7
  6. package/dist/LogViewer.js.map +1 -1
  7. package/dist/SharedTree.d.ts.map +1 -1
  8. package/dist/SharedTree.js +12 -12
  9. package/dist/SharedTree.js.map +1 -1
  10. package/dist/SharedTreeEncoder.d.ts.map +1 -1
  11. package/dist/SharedTreeEncoder.js +6 -12
  12. package/dist/SharedTreeEncoder.js.map +1 -1
  13. package/dist/TransactionInternal.d.ts.map +1 -1
  14. package/dist/TransactionInternal.js +4 -7
  15. package/dist/TransactionInternal.js.map +1 -1
  16. package/dist/id-compressor/IdCompressor.d.ts +3 -1
  17. package/dist/id-compressor/IdCompressor.d.ts.map +1 -1
  18. package/dist/id-compressor/IdCompressor.js +45 -17
  19. package/dist/id-compressor/IdCompressor.js.map +1 -1
  20. package/lib/EditLog.d.ts.map +1 -1
  21. package/lib/EditLog.js +4 -7
  22. package/lib/EditLog.js.map +1 -1
  23. package/lib/LogViewer.d.ts.map +1 -1
  24. package/lib/LogViewer.js +1 -7
  25. package/lib/LogViewer.js.map +1 -1
  26. package/lib/SharedTree.d.ts.map +1 -1
  27. package/lib/SharedTree.js +12 -12
  28. package/lib/SharedTree.js.map +1 -1
  29. package/lib/SharedTreeEncoder.d.ts.map +1 -1
  30. package/lib/SharedTreeEncoder.js +6 -12
  31. package/lib/SharedTreeEncoder.js.map +1 -1
  32. package/lib/TransactionInternal.d.ts.map +1 -1
  33. package/lib/TransactionInternal.js +4 -7
  34. package/lib/TransactionInternal.js.map +1 -1
  35. package/lib/id-compressor/IdCompressor.d.ts +3 -1
  36. package/lib/id-compressor/IdCompressor.d.ts.map +1 -1
  37. package/lib/id-compressor/IdCompressor.js +45 -17
  38. package/lib/id-compressor/IdCompressor.js.map +1 -1
  39. package/lib/test/MergeHealthTelemetryHeartbeat.tests.js +1 -1
  40. package/lib/test/MergeHealthTelemetryHeartbeat.tests.js.map +1 -1
  41. package/lib/test/SessionIdNormalizer.tests.js +4 -6
  42. package/lib/test/SessionIdNormalizer.tests.js.map +1 -1
  43. package/lib/test/Summary.tests.js +3 -6
  44. package/lib/test/Summary.tests.js.map +1 -1
  45. package/lib/test/utilities/SharedTreeTests.d.ts.map +1 -1
  46. package/lib/test/utilities/SharedTreeTests.js +33 -11
  47. package/lib/test/utilities/SharedTreeTests.js.map +1 -1
  48. package/lib/test/utilities/TestNode.d.ts.map +1 -1
  49. package/lib/test/utilities/TestNode.js +2 -12
  50. package/lib/test/utilities/TestNode.js.map +1 -1
  51. package/package.json +18 -18
  52. package/src/EditLog.ts +21 -23
  53. package/src/LogViewer.ts +1 -6
  54. package/src/SharedTree.ts +17 -16
  55. package/src/SharedTreeEncoder.ts +6 -17
  56. package/src/TransactionInternal.ts +11 -13
  57. package/src/id-compressor/IdCompressor.ts +46 -15
@@ -8,7 +8,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
8
8
  };
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.hasOngoingSession = exports.IdCompressor = exports.isLocalId = exports.isFinalId = exports.legacySharedTreeInitialTreeId = exports.defaultClusterCapacity = void 0;
11
- /* eslint-disable @typescript-eslint/restrict-plus-operands */
12
11
  const sorted_btree_1 = __importDefault(require("sorted-btree"));
13
12
  const Common_1 = require("../Common");
14
13
  const UuidUtilities_1 = require("../UuidUtilities");
@@ -118,9 +117,10 @@ class IdCompressor {
118
117
  * this compressor will generate its own. An `AttributionId` is an `UuidString` which may be validated via
119
118
  * {@link isUuidString} or generated via {@link generateStableId}.
120
119
  */
121
- constructor(localSessionId, reservedIdCount, attributionId) {
120
+ constructor(localSessionId, reservedIdCount, attributionId, logger) {
122
121
  this.localSessionId = localSessionId;
123
122
  this.reservedIdCount = reservedIdCount;
123
+ this.logger = logger;
124
124
  /**
125
125
  * Trivially reach consensus on default cluster size and reserved IDs.
126
126
  * These initial values must *NOT* change without careful consideration to compatibility.
@@ -329,7 +329,7 @@ class IdCompressor {
329
329
  * @param range - the range of session-local IDs to finalize.
330
330
  */
331
331
  finalizeCreationRange(range) {
332
- var _a, _b, _c, _d;
332
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
333
333
  const { sessionId, attributionId } = range;
334
334
  const isLocal = sessionId === this.localSessionId;
335
335
  const session = (_a = this.sessions.get(sessionId)) !== null && _a !== void 0 ? _a : this.createSession(sessionId, attributionId);
@@ -350,6 +350,7 @@ class IdCompressor {
350
350
  // The total number of session-local IDs to finalize
351
351
  const finalizeCount = normalizedLastFinalizedLocal - newLastFinalizedLocal;
352
352
  (0, Common_1.assert)(finalizeCount >= 1, 'Cannot finalize an empty range.');
353
+ let eagerFinalIdCount = 0;
353
354
  let initialClusterCount = 0;
354
355
  let remainingCount = finalizeCount;
355
356
  let newBaseUuid;
@@ -360,6 +361,7 @@ class IdCompressor {
360
361
  Math.min(currentCluster.count + finalizeCount, currentCluster.capacity) -
361
362
  1);
362
363
  if (lastFinalInCluster > lastKnownFinal) {
364
+ eagerFinalIdCount = lastFinalInCluster - (lastKnownFinal + 1);
363
365
  this.sessionIdNormalizer.addFinalIds((lastKnownFinal + 1), lastFinalInCluster, currentCluster);
364
366
  }
365
367
  }
@@ -375,6 +377,7 @@ class IdCompressor {
375
377
  // The cluster is full but is the last in the list of clusters.
376
378
  // This allows it to be expanded instead of allocating a new one.
377
379
  const expansionAmount = this.newClusterCapacity + overflow;
380
+ const previousCapacity = currentCluster.capacity;
378
381
  currentCluster.capacity += expansionAmount;
379
382
  this.nextClusterBaseFinalId = (this.nextClusterBaseFinalId + expansionAmount);
380
383
  (0, Common_1.assert)(this.nextClusterBaseFinalId < Number.MAX_SAFE_INTEGER, 'The number of allocated final IDs must not exceed the JS maximum safe integer.');
@@ -393,6 +396,13 @@ class IdCompressor {
393
396
  const lastFinalizedFinal = (currentBaseFinalId + currentCluster.count - 1);
394
397
  const finalPivot = (lastFinalizedFinal - overflow + 1);
395
398
  this.sessionIdNormalizer.addFinalIds(finalPivot, lastFinalizedFinal, currentCluster);
399
+ (_d = this.logger) === null || _d === void 0 ? void 0 : _d.sendTelemetryEvent({
400
+ eventName: 'IdCompressor:ClusterExpansion',
401
+ sessionId: this.localSessionId,
402
+ previousCapacity,
403
+ newCapacity: currentCluster.capacity,
404
+ overflow,
405
+ });
396
406
  }
397
407
  }
398
408
  }
@@ -402,11 +412,19 @@ class IdCompressor {
402
412
  newBaseUuid = (0, NumericUuid_1.incrementUuid)(currentCluster.baseUuid, currentCluster.capacity);
403
413
  currentCluster.count += remainingCapacity;
404
414
  remainingCount -= remainingCapacity;
415
+ (_e = this.logger) === null || _e === void 0 ? void 0 : _e.sendTelemetryEvent({
416
+ eventName: 'IdCompressor:OverfilledCluster',
417
+ sessionId: this.localSessionId,
418
+ });
405
419
  }
406
420
  }
407
421
  else {
408
422
  // Session has never made a cluster, form a new one with the session UUID as the baseUuid
409
423
  newBaseUuid = session.sessionUuid;
424
+ (_f = this.logger) === null || _f === void 0 ? void 0 : _f.sendTelemetryEvent({
425
+ eventName: 'IdCompressor:FirstCluster',
426
+ sessionId: this.localSessionId,
427
+ });
410
428
  }
411
429
  // Finalizing a range results in one of three cases:
412
430
  // 1. All local IDs are finalized into a new cluster (because there was either never a cluster for that session, or the current
@@ -427,15 +445,22 @@ class IdCompressor {
427
445
  (0, Common_1.fail)('Cluster must be filled before another is allocated.');
428
446
  }
429
447
  newBaseFinalId = this.nextClusterBaseFinalId;
448
+ const newCapacity = Math.max(this.newClusterCapacity, remainingCount);
430
449
  newCluster = {
431
450
  baseUuid: newBaseUuid,
432
- capacity: Math.max(this.newClusterCapacity, remainingCount),
451
+ capacity: newCapacity,
433
452
  count: remainingCount,
434
453
  session,
435
454
  };
436
455
  const usedCapacity = finalizeCount - remainingCount;
437
456
  localIdPivot = (newFirstFinalizedLocal - usedCapacity);
438
457
  if (isLocal) {
458
+ (_g = this.logger) === null || _g === void 0 ? void 0 : _g.sendTelemetryEvent({
459
+ eventName: 'IdCompressor:NewCluster',
460
+ sessionId: this.localSessionId,
461
+ clusterCapacity: newCapacity,
462
+ clusterCount: remainingCount,
463
+ });
439
464
  const lastFinalizedFinal = (newBaseFinalId + newCluster.count - 1);
440
465
  this.sessionIdNormalizer.addFinalIds(newBaseFinalId, lastFinalizedFinal, newCluster);
441
466
  }
@@ -475,7 +500,7 @@ class IdCompressor {
475
500
  (normalizedLastFinalizedLocal - overriddenLocal) -
476
501
  1);
477
502
  }
478
- (_d = cluster.overrides) !== null && _d !== void 0 ? _d : (cluster.overrides = new Map());
503
+ (_h = cluster.overrides) !== null && _h !== void 0 ? _h : (cluster.overrides = new Map());
479
504
  const inversionKey = IdCompressor.createInversionKey(override);
480
505
  const existingIds = this.getExistingIdsForNewOverride(inversionKey, true);
481
506
  let overrideForCluster;
@@ -541,6 +566,15 @@ class IdCompressor {
541
566
  }
542
567
  }
543
568
  }
569
+ if (isLocal) {
570
+ (_j = this.logger) === null || _j === void 0 ? void 0 : _j.sendTelemetryEvent({
571
+ eventName: 'IdCompressor:IdCompressorStatus',
572
+ eagerFinalIdCount,
573
+ localIdCount: remainingCount,
574
+ overridesCount: (_k = overrides === null || overrides === void 0 ? void 0 : overrides.length) !== null && _k !== void 0 ? _k : 0,
575
+ sessionId: this.localSessionId,
576
+ });
577
+ }
544
578
  session.lastFinalizedLocalId = newLastFinalizedLocal;
545
579
  }
546
580
  checkClusterForCollision(cluster) {
@@ -758,12 +792,9 @@ class IdCompressor {
758
792
  // `localOverrides`s. Otherwise, it is a sequential allocation from the session UUID and can simply be negated and
759
793
  // added to that UUID to obtain the stable ID associated with it.
760
794
  const localOverride = (_a = this.localOverrides) === null || _a === void 0 ? void 0 : _a.get(id);
761
- if (localOverride !== undefined) {
762
- return localOverride;
763
- }
764
- else {
765
- return (0, NumericUuid_1.stableIdFromNumericUuid)(this.localSession.sessionUuid, idOffset - 1);
766
- }
795
+ return localOverride !== undefined
796
+ ? localOverride
797
+ : (0, NumericUuid_1.stableIdFromNumericUuid)(this.localSession.sessionUuid, idOffset - 1);
767
798
  }
768
799
  }
769
800
  /**
@@ -797,12 +828,9 @@ class IdCompressor {
797
828
  const [key, compressionMapping] = closestMatch;
798
829
  if (!IdCompressor.isClusterInfo(compressionMapping)) {
799
830
  if (key === inversionKey) {
800
- if (IdCompressor.isUnfinalizedOverride(compressionMapping)) {
801
- return compressionMapping;
802
- }
803
- else {
804
- return ((_a = compressionMapping.associatedLocalId) !== null && _a !== void 0 ? _a : compressionMapping.originalOverridingFinal);
805
- }
831
+ return IdCompressor.isUnfinalizedOverride(compressionMapping)
832
+ ? compressionMapping
833
+ : (_a = compressionMapping.associatedLocalId) !== null && _a !== void 0 ? _a : compressionMapping.originalOverridingFinal;
806
834
  }
807
835
  }
808
836
  else {