@fluidframework/container-runtime 2.0.0-internal.7.3.0 → 2.0.0-internal.7.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/api-extractor-lint.json +13 -0
- package/api-extractor.json +9 -1
- package/api-report/container-runtime.api.md +124 -107
- package/dist/blobManager.d.ts +4 -4
- package/dist/blobManager.d.ts.map +1 -1
- package/dist/blobManager.js.map +1 -1
- package/dist/container-runtime-alpha.d.ts +1473 -0
- package/dist/container-runtime-beta.d.ts +300 -0
- package/dist/container-runtime-public.d.ts +300 -0
- package/dist/container-runtime-untrimmed.d.ts +1836 -0
- package/dist/containerRuntime.d.ts +30 -30
- package/dist/containerRuntime.d.ts.map +1 -1
- package/dist/containerRuntime.js +62 -40
- package/dist/containerRuntime.js.map +1 -1
- package/dist/dataStoreRegistry.d.ts +1 -1
- package/dist/dataStoreRegistry.js +1 -1
- package/dist/dataStoreRegistry.js.map +1 -1
- package/dist/dataStores.d.ts +10 -15
- package/dist/dataStores.d.ts.map +1 -1
- package/dist/dataStores.js +77 -40
- package/dist/dataStores.js.map +1 -1
- package/dist/gc/garbageCollection.d.ts +41 -13
- package/dist/gc/garbageCollection.d.ts.map +1 -1
- package/dist/gc/garbageCollection.js +215 -78
- package/dist/gc/garbageCollection.js.map +1 -1
- package/dist/gc/gcConfigs.d.ts.map +1 -1
- package/dist/gc/gcConfigs.js +34 -37
- package/dist/gc/gcConfigs.js.map +1 -1
- package/dist/gc/gcDefinitions.d.ts +121 -46
- package/dist/gc/gcDefinitions.d.ts.map +1 -1
- package/dist/gc/gcDefinitions.js +26 -18
- package/dist/gc/gcDefinitions.js.map +1 -1
- package/dist/gc/gcHelpers.d.ts +18 -25
- package/dist/gc/gcHelpers.d.ts.map +1 -1
- package/dist/gc/gcHelpers.js +29 -45
- package/dist/gc/gcHelpers.js.map +1 -1
- package/dist/gc/gcTelemetry.d.ts +0 -5
- package/dist/gc/gcTelemetry.d.ts.map +1 -1
- package/dist/gc/gcTelemetry.js +14 -42
- package/dist/gc/gcTelemetry.js.map +1 -1
- package/dist/gc/gcUnreferencedStateTracker.d.ts +11 -5
- package/dist/gc/gcUnreferencedStateTracker.d.ts.map +1 -1
- package/dist/gc/gcUnreferencedStateTracker.js +43 -19
- package/dist/gc/gcUnreferencedStateTracker.js.map +1 -1
- package/dist/gc/index.d.ts +1 -1
- package/dist/gc/index.d.ts.map +1 -1
- package/dist/gc/index.js +4 -5
- package/dist/gc/index.js.map +1 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -5
- package/dist/index.js.map +1 -1
- package/dist/messageTypes.d.ts +15 -7
- package/dist/messageTypes.d.ts.map +1 -1
- package/dist/messageTypes.js +6 -1
- package/dist/messageTypes.js.map +1 -1
- package/dist/opLifecycle/definitions.d.ts +1 -1
- package/dist/opLifecycle/definitions.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/pendingStateManager.d.ts +1 -0
- package/dist/pendingStateManager.d.ts.map +1 -1
- package/dist/pendingStateManager.js +1 -0
- package/dist/pendingStateManager.js.map +1 -1
- package/dist/summary/orderedClientElection.d.ts +1 -1
- package/dist/summary/orderedClientElection.js.map +1 -1
- package/dist/summary/runWhileConnectedCoordinator.d.ts +2 -2
- package/dist/summary/runWhileConnectedCoordinator.js +1 -1
- package/dist/summary/runWhileConnectedCoordinator.js.map +1 -1
- package/dist/summary/summarizer.d.ts +1 -1
- package/dist/summary/summarizer.js +1 -1
- package/dist/summary/summarizer.js.map +1 -1
- package/dist/summary/summarizerTypes.d.ts +30 -30
- package/dist/summary/summarizerTypes.js.map +1 -1
- package/dist/summary/summaryCollection.d.ts +10 -10
- package/dist/summary/summaryCollection.js +1 -1
- package/dist/summary/summaryCollection.js.map +1 -1
- package/dist/summary/summaryFormat.d.ts +3 -3
- package/dist/summary/summaryFormat.js.map +1 -1
- package/lib/blobManager.d.ts +4 -4
- package/lib/blobManager.d.ts.map +1 -1
- package/lib/blobManager.js.map +1 -1
- package/lib/container-runtime-alpha.d.ts +1473 -0
- package/lib/container-runtime-beta.d.ts +300 -0
- package/lib/container-runtime-public.d.ts +300 -0
- package/lib/container-runtime-untrimmed.d.ts +1836 -0
- package/lib/containerRuntime.d.ts +30 -30
- package/lib/containerRuntime.d.ts.map +1 -1
- package/lib/containerRuntime.js +64 -42
- package/lib/containerRuntime.js.map +1 -1
- package/lib/dataStoreRegistry.d.ts +1 -1
- package/lib/dataStoreRegistry.js +1 -1
- package/lib/dataStoreRegistry.js.map +1 -1
- package/lib/dataStores.d.ts +10 -15
- package/lib/dataStores.d.ts.map +1 -1
- package/lib/dataStores.js +80 -43
- package/lib/dataStores.js.map +1 -1
- package/lib/gc/garbageCollection.d.ts +41 -13
- package/lib/gc/garbageCollection.d.ts.map +1 -1
- package/lib/gc/garbageCollection.js +217 -80
- package/lib/gc/garbageCollection.js.map +1 -1
- package/lib/gc/gcConfigs.d.ts.map +1 -1
- package/lib/gc/gcConfigs.js +37 -40
- package/lib/gc/gcConfigs.js.map +1 -1
- package/lib/gc/gcDefinitions.d.ts +121 -46
- package/lib/gc/gcDefinitions.d.ts.map +1 -1
- package/lib/gc/gcDefinitions.js +25 -17
- package/lib/gc/gcDefinitions.js.map +1 -1
- package/lib/gc/gcHelpers.d.ts +18 -25
- package/lib/gc/gcHelpers.d.ts.map +1 -1
- package/lib/gc/gcHelpers.js +27 -43
- package/lib/gc/gcHelpers.js.map +1 -1
- package/lib/gc/gcTelemetry.d.ts +0 -5
- package/lib/gc/gcTelemetry.d.ts.map +1 -1
- package/lib/gc/gcTelemetry.js +15 -43
- package/lib/gc/gcTelemetry.js.map +1 -1
- package/lib/gc/gcUnreferencedStateTracker.d.ts +11 -5
- package/lib/gc/gcUnreferencedStateTracker.d.ts.map +1 -1
- package/lib/gc/gcUnreferencedStateTracker.js +43 -19
- package/lib/gc/gcUnreferencedStateTracker.js.map +1 -1
- package/lib/gc/index.d.ts +1 -1
- package/lib/gc/index.d.ts.map +1 -1
- package/lib/gc/index.js +1 -1
- package/lib/gc/index.js.map +1 -1
- package/lib/index.d.ts +14 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +15 -1
- package/lib/index.js.map +1 -1
- package/lib/messageTypes.d.ts +15 -7
- package/lib/messageTypes.d.ts.map +1 -1
- package/lib/messageTypes.js +6 -1
- package/lib/messageTypes.js.map +1 -1
- package/lib/opLifecycle/definitions.d.ts +1 -1
- package/lib/opLifecycle/definitions.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/pendingStateManager.d.ts +1 -0
- package/lib/pendingStateManager.d.ts.map +1 -1
- package/lib/pendingStateManager.js +1 -0
- package/lib/pendingStateManager.js.map +1 -1
- package/lib/summary/orderedClientElection.d.ts +1 -1
- package/lib/summary/orderedClientElection.js.map +1 -1
- package/lib/summary/runWhileConnectedCoordinator.d.ts +2 -2
- package/lib/summary/runWhileConnectedCoordinator.js +1 -1
- package/lib/summary/runWhileConnectedCoordinator.js.map +1 -1
- package/lib/summary/summarizer.d.ts +1 -1
- package/lib/summary/summarizer.js +1 -1
- package/lib/summary/summarizer.js.map +1 -1
- package/lib/summary/summarizerTypes.d.ts +30 -30
- package/lib/summary/summarizerTypes.js.map +1 -1
- package/lib/summary/summaryCollection.d.ts +10 -10
- package/lib/summary/summaryCollection.js +1 -1
- package/lib/summary/summaryCollection.js.map +1 -1
- package/lib/summary/summaryFormat.d.ts +3 -3
- package/lib/summary/summaryFormat.js.map +1 -1
- package/package.json +42 -19
- package/src/blobManager.ts +5 -5
- package/src/containerRuntime.ts +86 -56
- package/src/dataStoreRegistry.ts +1 -1
- package/src/dataStores.ts +140 -69
- package/src/gc/garbageCollection.md +14 -15
- package/src/gc/garbageCollection.ts +256 -96
- package/src/gc/gcConfigs.ts +50 -52
- package/src/gc/gcDefinitions.ts +137 -52
- package/src/gc/gcHelpers.ts +31 -52
- package/src/gc/gcTelemetry.ts +16 -57
- package/src/gc/gcUnreferencedStateTracker.ts +61 -22
- package/src/gc/index.ts +6 -4
- package/src/index.ts +19 -1
- package/src/messageTypes.ts +19 -4
- package/src/opLifecycle/definitions.ts +1 -1
- package/src/packageVersion.ts +1 -1
- package/src/pendingStateManager.ts +1 -0
- package/src/summary/orderedClientElection.ts +1 -1
- package/src/summary/runWhileConnectedCoordinator.ts +2 -2
- package/src/summary/summarizer.ts +1 -1
- package/src/summary/summarizerTypes.ts +30 -30
- package/src/summary/summaryCollection.ts +10 -10
- package/src/summary/summaryFormat.ts +3 -3
- package/dist/id-compressor/appendOnlySortedMap.d.ts +0 -124
- package/dist/id-compressor/appendOnlySortedMap.d.ts.map +0 -1
- package/dist/id-compressor/appendOnlySortedMap.js +0 -318
- package/dist/id-compressor/appendOnlySortedMap.js.map +0 -1
- package/dist/id-compressor/finalSpace.d.ts +0 -29
- package/dist/id-compressor/finalSpace.d.ts.map +0 -1
- package/dist/id-compressor/finalSpace.js +0 -62
- package/dist/id-compressor/finalSpace.js.map +0 -1
- package/dist/id-compressor/idCompressor.d.ts +0 -54
- package/dist/id-compressor/idCompressor.d.ts.map +0 -1
- package/dist/id-compressor/idCompressor.js +0 -495
- package/dist/id-compressor/idCompressor.js.map +0 -1
- package/dist/id-compressor/identifiers.d.ts +0 -32
- package/dist/id-compressor/identifiers.d.ts.map +0 -1
- package/dist/id-compressor/identifiers.js +0 -15
- package/dist/id-compressor/identifiers.js.map +0 -1
- package/dist/id-compressor/index.d.ts +0 -13
- package/dist/id-compressor/index.d.ts.map +0 -1
- package/dist/id-compressor/index.js +0 -32
- package/dist/id-compressor/index.js.map +0 -1
- package/dist/id-compressor/persistanceUtilities.d.ts +0 -22
- package/dist/id-compressor/persistanceUtilities.d.ts.map +0 -1
- package/dist/id-compressor/persistanceUtilities.js +0 -43
- package/dist/id-compressor/persistanceUtilities.js.map +0 -1
- package/dist/id-compressor/sessionSpaceNormalizer.d.ts +0 -46
- package/dist/id-compressor/sessionSpaceNormalizer.d.ts.map +0 -1
- package/dist/id-compressor/sessionSpaceNormalizer.js +0 -80
- package/dist/id-compressor/sessionSpaceNormalizer.js.map +0 -1
- package/dist/id-compressor/sessions.d.ts +0 -115
- package/dist/id-compressor/sessions.d.ts.map +0 -1
- package/dist/id-compressor/sessions.js +0 -305
- package/dist/id-compressor/sessions.js.map +0 -1
- package/dist/id-compressor/utilities.d.ts +0 -52
- package/dist/id-compressor/utilities.d.ts.map +0 -1
- package/dist/id-compressor/utilities.js +0 -169
- package/dist/id-compressor/utilities.js.map +0 -1
- package/lib/id-compressor/appendOnlySortedMap.d.ts +0 -124
- package/lib/id-compressor/appendOnlySortedMap.d.ts.map +0 -1
- package/lib/id-compressor/appendOnlySortedMap.js +0 -314
- package/lib/id-compressor/appendOnlySortedMap.js.map +0 -1
- package/lib/id-compressor/finalSpace.d.ts +0 -29
- package/lib/id-compressor/finalSpace.d.ts.map +0 -1
- package/lib/id-compressor/finalSpace.js +0 -58
- package/lib/id-compressor/finalSpace.js.map +0 -1
- package/lib/id-compressor/idCompressor.d.ts +0 -54
- package/lib/id-compressor/idCompressor.d.ts.map +0 -1
- package/lib/id-compressor/idCompressor.js +0 -491
- package/lib/id-compressor/idCompressor.js.map +0 -1
- package/lib/id-compressor/identifiers.d.ts +0 -32
- package/lib/id-compressor/identifiers.d.ts.map +0 -1
- package/lib/id-compressor/identifiers.js +0 -11
- package/lib/id-compressor/identifiers.js.map +0 -1
- package/lib/id-compressor/index.d.ts +0 -13
- package/lib/id-compressor/index.d.ts.map +0 -1
- package/lib/id-compressor/index.js +0 -13
- package/lib/id-compressor/index.js.map +0 -1
- package/lib/id-compressor/persistanceUtilities.d.ts +0 -22
- package/lib/id-compressor/persistanceUtilities.d.ts.map +0 -1
- package/lib/id-compressor/persistanceUtilities.js +0 -34
- package/lib/id-compressor/persistanceUtilities.js.map +0 -1
- package/lib/id-compressor/sessionSpaceNormalizer.d.ts +0 -46
- package/lib/id-compressor/sessionSpaceNormalizer.d.ts.map +0 -1
- package/lib/id-compressor/sessionSpaceNormalizer.js +0 -76
- package/lib/id-compressor/sessionSpaceNormalizer.js.map +0 -1
- package/lib/id-compressor/sessions.d.ts +0 -115
- package/lib/id-compressor/sessions.d.ts.map +0 -1
- package/lib/id-compressor/sessions.js +0 -290
- package/lib/id-compressor/sessions.js.map +0 -1
- package/lib/id-compressor/utilities.d.ts +0 -52
- package/lib/id-compressor/utilities.d.ts.map +0 -1
- package/lib/id-compressor/utilities.js +0 -151
- package/lib/id-compressor/utilities.js.map +0 -1
- package/src/id-compressor/README.md +0 -3
- package/src/id-compressor/appendOnlySortedMap.ts +0 -366
- package/src/id-compressor/finalSpace.ts +0 -67
- package/src/id-compressor/idCompressor.ts +0 -630
- package/src/id-compressor/identifiers.ts +0 -42
- package/src/id-compressor/index.ts +0 -26
- package/src/id-compressor/persistanceUtilities.ts +0 -58
- package/src/id-compressor/sessionSpaceNormalizer.ts +0 -83
- package/src/id-compressor/sessions.ts +0 -405
- package/src/id-compressor/utilities.ts +0 -190
|
@@ -1,495 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.IdCompressor = void 0;
|
|
8
|
-
const core_utils_1 = require("@fluidframework/core-utils");
|
|
9
|
-
const client_utils_1 = require("@fluid-internal/client-utils");
|
|
10
|
-
const runtime_definitions_1 = require("@fluidframework/runtime-definitions");
|
|
11
|
-
const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
|
|
12
|
-
const identifiers_1 = require("./identifiers");
|
|
13
|
-
const utilities_1 = require("./utilities");
|
|
14
|
-
const persistanceUtilities_1 = require("./persistanceUtilities");
|
|
15
|
-
const sessions_1 = require("./sessions");
|
|
16
|
-
const sessionSpaceNormalizer_1 = require("./sessionSpaceNormalizer");
|
|
17
|
-
const finalSpace_1 = require("./finalSpace");
|
|
18
|
-
/**
|
|
19
|
-
* The version of IdCompressor that is currently persisted.
|
|
20
|
-
* This should not be changed without careful consideration to compatibility.
|
|
21
|
-
*/
|
|
22
|
-
const currentWrittenVersion = 1;
|
|
23
|
-
/**
|
|
24
|
-
* See {@link IIdCompressor} and {@link IIdCompressorCore}
|
|
25
|
-
*/
|
|
26
|
-
class IdCompressor {
|
|
27
|
-
// -----------------------
|
|
28
|
-
constructor(localSessionIdOrDeserialized, logger) {
|
|
29
|
-
this.logger = logger;
|
|
30
|
-
this.normalizer = new sessionSpaceNormalizer_1.SessionSpaceNormalizer();
|
|
31
|
-
// The number of IDs generated by the local session
|
|
32
|
-
this.localGenCount = 0;
|
|
33
|
-
// -----------------------
|
|
34
|
-
// ----- Final state -----
|
|
35
|
-
// The gen count to be annotated on the range returned by the next call to `takeNextCreationRange`.
|
|
36
|
-
// This is updated to be equal to `generatedIdCount` + 1 each time it is called.
|
|
37
|
-
this.nextRangeBaseGenCount = 1;
|
|
38
|
-
// The capacity of the next cluster to be created
|
|
39
|
-
this.newClusterCapacity = runtime_definitions_1.initialClusterCapacity;
|
|
40
|
-
this.sessions = new sessions_1.Sessions();
|
|
41
|
-
this.finalSpace = new finalSpace_1.FinalSpace();
|
|
42
|
-
// -----------------------
|
|
43
|
-
// ----- Telemetry state -----
|
|
44
|
-
// The number of local IDs generated since the last telemetry was sent.
|
|
45
|
-
this.telemetryLocalIdCount = 0;
|
|
46
|
-
// The number of eager final IDs generated since the last telemetry was sent.
|
|
47
|
-
this.telemetryEagerFinalIdCount = 0;
|
|
48
|
-
if (typeof localSessionIdOrDeserialized === "string") {
|
|
49
|
-
this.localSessionId = localSessionIdOrDeserialized;
|
|
50
|
-
this.localSession = this.sessions.getOrCreate(localSessionIdOrDeserialized);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
// Deserialize case
|
|
54
|
-
this.sessions = localSessionIdOrDeserialized;
|
|
55
|
-
// As policy, the first session is always the local session. Preserve this invariant
|
|
56
|
-
// during deserialization.
|
|
57
|
-
const firstSession = localSessionIdOrDeserialized.sessions().next();
|
|
58
|
-
(0, core_utils_1.assert)(!firstSession.done, 0x754 /* First session must be present. */);
|
|
59
|
-
this.localSession = firstSession.value;
|
|
60
|
-
this.localSessionId = (0, utilities_1.stableIdFromNumericUuid)(this.localSession.sessionUuid);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
static create(sessionIdOrLogger, loggerOrUndefined) {
|
|
64
|
-
let localSessionId;
|
|
65
|
-
let logger;
|
|
66
|
-
if (sessionIdOrLogger === undefined) {
|
|
67
|
-
localSessionId = (0, utilities_1.createSessionId)();
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
if (typeof sessionIdOrLogger === "string") {
|
|
71
|
-
localSessionId = sessionIdOrLogger;
|
|
72
|
-
logger = loggerOrUndefined;
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
localSessionId = (0, utilities_1.createSessionId)();
|
|
76
|
-
logger = loggerOrUndefined;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
const compressor = new IdCompressor(localSessionId, logger === undefined ? undefined : (0, telemetry_utils_1.createChildLogger)({ logger }));
|
|
80
|
-
return compressor;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* The size of each newly created ID cluster.
|
|
84
|
-
*/
|
|
85
|
-
get clusterCapacity() {
|
|
86
|
-
return this.newClusterCapacity;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Must only be set with a value upon which consensus has been reached. Value must be greater than zero and less than
|
|
90
|
-
* `IdCompressor.maxClusterSize`.
|
|
91
|
-
*/
|
|
92
|
-
set clusterCapacity(value) {
|
|
93
|
-
if (value <= 0) {
|
|
94
|
-
throw new Error("Clusters must have a positive capacity.");
|
|
95
|
-
}
|
|
96
|
-
if (value > IdCompressor.maxClusterSize) {
|
|
97
|
-
throw new Error("Clusters must not exceed max cluster size.");
|
|
98
|
-
}
|
|
99
|
-
this.newClusterCapacity = value;
|
|
100
|
-
}
|
|
101
|
-
generateCompressedId() {
|
|
102
|
-
this.localGenCount++;
|
|
103
|
-
const lastCluster = this.localSession.getLastCluster();
|
|
104
|
-
if (lastCluster === undefined) {
|
|
105
|
-
this.telemetryLocalIdCount++;
|
|
106
|
-
return this.generateNextLocalId();
|
|
107
|
-
}
|
|
108
|
-
// If there exists a cluster of final IDs already claimed by the local session that still has room in it,
|
|
109
|
-
// it is known prior to range sequencing what a local ID's corresponding final ID will be.
|
|
110
|
-
// In this case, it is safe to return the final ID immediately. This is guaranteed to be safe because
|
|
111
|
-
// any op that the local session sends that contains one of those final IDs are guaranteed to arrive to
|
|
112
|
-
// collaborators *after* the one containing the creation range.
|
|
113
|
-
const clusterOffset = this.localGenCount - (0, utilities_1.genCountFromLocalId)(lastCluster.baseLocalId);
|
|
114
|
-
if (lastCluster.capacity > clusterOffset) {
|
|
115
|
-
this.telemetryEagerFinalIdCount++;
|
|
116
|
-
// Space in the cluster: eager final
|
|
117
|
-
return (lastCluster.baseFinalId +
|
|
118
|
-
clusterOffset);
|
|
119
|
-
}
|
|
120
|
-
// No space in the cluster, return next local
|
|
121
|
-
this.telemetryLocalIdCount++;
|
|
122
|
-
return this.generateNextLocalId();
|
|
123
|
-
}
|
|
124
|
-
generateNextLocalId() {
|
|
125
|
-
// Must tell the normalizer that we generated a local ID
|
|
126
|
-
this.normalizer.addLocalRange(this.localGenCount, 1);
|
|
127
|
-
return (0, utilities_1.localIdFromGenCount)(this.localGenCount);
|
|
128
|
-
}
|
|
129
|
-
takeNextCreationRange() {
|
|
130
|
-
const count = this.localGenCount - (this.nextRangeBaseGenCount - 1);
|
|
131
|
-
if (count === 0) {
|
|
132
|
-
return {
|
|
133
|
-
sessionId: this.localSessionId,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
const range = {
|
|
137
|
-
sessionId: this.localSessionId,
|
|
138
|
-
ids: {
|
|
139
|
-
firstGenCount: this.nextRangeBaseGenCount,
|
|
140
|
-
count,
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
this.nextRangeBaseGenCount = this.localGenCount + 1;
|
|
144
|
-
return range;
|
|
145
|
-
}
|
|
146
|
-
finalizeCreationRange(range) {
|
|
147
|
-
// Check if the range has IDs
|
|
148
|
-
if (range.ids === undefined) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
(0, core_utils_1.assert)(range.ids.count > 0, 0x755 /* Malformed ID Range. */);
|
|
152
|
-
const { sessionId, ids } = range;
|
|
153
|
-
const { count, firstGenCount } = ids;
|
|
154
|
-
const session = this.sessions.getOrCreate(sessionId);
|
|
155
|
-
const isLocal = session === this.localSession;
|
|
156
|
-
const rangeBaseLocal = (0, utilities_1.localIdFromGenCount)(firstGenCount);
|
|
157
|
-
let lastCluster = session.getLastCluster();
|
|
158
|
-
if (lastCluster === undefined) {
|
|
159
|
-
// This is the first cluster in the session space
|
|
160
|
-
if (rangeBaseLocal !== -1) {
|
|
161
|
-
throw new Error("Ranges finalized out of order.");
|
|
162
|
-
}
|
|
163
|
-
lastCluster = this.addEmptyCluster(session, this.clusterCapacity + count);
|
|
164
|
-
if (isLocal) {
|
|
165
|
-
this.logger?.sendTelemetryEvent({
|
|
166
|
-
eventName: "RuntimeIdCompressor:FirstCluster",
|
|
167
|
-
sessionId: this.localSessionId,
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
const remainingCapacity = lastCluster.capacity - lastCluster.count;
|
|
172
|
-
if (lastCluster.baseLocalId - lastCluster.count !== rangeBaseLocal) {
|
|
173
|
-
throw new Error("Ranges finalized out of order.");
|
|
174
|
-
}
|
|
175
|
-
if (remainingCapacity >= count) {
|
|
176
|
-
// The current range fits in the existing cluster
|
|
177
|
-
lastCluster.count += count;
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
const overflow = count - remainingCapacity;
|
|
181
|
-
const newClaimedFinalCount = overflow + this.clusterCapacity;
|
|
182
|
-
if (lastCluster === this.finalSpace.getLastCluster()) {
|
|
183
|
-
// The last cluster in the sessions chain is the last cluster globally, so it can be expanded.
|
|
184
|
-
lastCluster.capacity += newClaimedFinalCount;
|
|
185
|
-
lastCluster.count += count;
|
|
186
|
-
(0, core_utils_1.assert)(!this.sessions.clusterCollides(lastCluster), 0x756 /* Cluster collision detected. */);
|
|
187
|
-
if (isLocal) {
|
|
188
|
-
this.logger?.sendTelemetryEvent({
|
|
189
|
-
eventName: "RuntimeIdCompressor:ClusterExpansion",
|
|
190
|
-
sessionId: this.localSessionId,
|
|
191
|
-
previousCapacity: lastCluster.capacity - newClaimedFinalCount,
|
|
192
|
-
newCapacity: lastCluster.capacity,
|
|
193
|
-
overflow,
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
// The last cluster in the sessions chain is *not* the last cluster globally. Fill and overflow to new.
|
|
199
|
-
lastCluster.count = lastCluster.capacity;
|
|
200
|
-
const newCluster = this.addEmptyCluster(session, newClaimedFinalCount);
|
|
201
|
-
newCluster.count += overflow;
|
|
202
|
-
if (isLocal) {
|
|
203
|
-
this.logger?.sendTelemetryEvent({
|
|
204
|
-
eventName: "RuntimeIdCompressor:NewCluster",
|
|
205
|
-
sessionId: this.localSessionId,
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
if (isLocal) {
|
|
211
|
-
this.logger?.sendTelemetryEvent({
|
|
212
|
-
eventName: "RuntimeIdCompressor:IdCompressorStatus",
|
|
213
|
-
eagerFinalIdCount: this.telemetryEagerFinalIdCount,
|
|
214
|
-
localIdCount: this.telemetryLocalIdCount,
|
|
215
|
-
sessionId: this.localSessionId,
|
|
216
|
-
});
|
|
217
|
-
this.telemetryEagerFinalIdCount = 0;
|
|
218
|
-
this.telemetryLocalIdCount = 0;
|
|
219
|
-
}
|
|
220
|
-
(0, core_utils_1.assert)(!session.isEmpty(), 0x757 /* Empty sessions should not be created. */);
|
|
221
|
-
}
|
|
222
|
-
addEmptyCluster(session, capacity) {
|
|
223
|
-
const newCluster = session.addNewCluster(this.finalSpace.getAllocatedIdLimit(), capacity, 0);
|
|
224
|
-
(0, core_utils_1.assert)(!this.sessions.clusterCollides(newCluster), 0x758 /* Cluster collision detected. */);
|
|
225
|
-
this.finalSpace.addCluster(newCluster);
|
|
226
|
-
return newCluster;
|
|
227
|
-
}
|
|
228
|
-
normalizeToOpSpace(id) {
|
|
229
|
-
if ((0, identifiers_1.isFinalId)(id)) {
|
|
230
|
-
return id;
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
const local = id;
|
|
234
|
-
if (!this.normalizer.contains(local)) {
|
|
235
|
-
throw new Error("Invalid ID to normalize.");
|
|
236
|
-
}
|
|
237
|
-
const finalForm = this.localSession.tryConvertToFinal(local, true);
|
|
238
|
-
return finalForm === undefined
|
|
239
|
-
? local
|
|
240
|
-
: finalForm;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
normalizeToSessionSpace(id, originSessionId) {
|
|
244
|
-
if ((0, identifiers_1.isFinalId)(id)) {
|
|
245
|
-
const containingCluster = this.localSession.getClusterByAllocatedFinal(id);
|
|
246
|
-
if (containingCluster === undefined) {
|
|
247
|
-
// Does not exist in local cluster chain
|
|
248
|
-
if (id >= this.finalSpace.getFinalizedIdLimit()) {
|
|
249
|
-
throw new Error("Unknown op space ID.");
|
|
250
|
-
}
|
|
251
|
-
return id;
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
const alignedLocal = (0, sessions_1.getAlignedLocal)(containingCluster, id);
|
|
255
|
-
if (this.normalizer.contains(alignedLocal)) {
|
|
256
|
-
return alignedLocal;
|
|
257
|
-
}
|
|
258
|
-
else {
|
|
259
|
-
if ((0, utilities_1.genCountFromLocalId)(alignedLocal) > this.localGenCount) {
|
|
260
|
-
throw new Error("Unknown op space ID.");
|
|
261
|
-
}
|
|
262
|
-
return id;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
const localToNormalize = id;
|
|
268
|
-
if (originSessionId === this.localSessionId) {
|
|
269
|
-
if (this.normalizer.contains(localToNormalize)) {
|
|
270
|
-
return localToNormalize;
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
// We never generated this local ID, so fail
|
|
274
|
-
throw new Error("Unknown op space ID.");
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
// LocalId from a remote session
|
|
279
|
-
const remoteSession = this.sessions.get(originSessionId);
|
|
280
|
-
if (remoteSession === undefined) {
|
|
281
|
-
throw new Error("No IDs have ever been finalized by the supplied session.");
|
|
282
|
-
}
|
|
283
|
-
const correspondingFinal = remoteSession.tryConvertToFinal(localToNormalize, false);
|
|
284
|
-
if (correspondingFinal === undefined) {
|
|
285
|
-
throw new Error("Unknown op space ID.");
|
|
286
|
-
}
|
|
287
|
-
return correspondingFinal;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
decompress(id) {
|
|
292
|
-
if ((0, identifiers_1.isFinalId)(id)) {
|
|
293
|
-
const containingCluster = sessions_1.Session.getContainingCluster(id, this.finalSpace.clusters);
|
|
294
|
-
if (containingCluster === undefined) {
|
|
295
|
-
throw new Error("Unknown ID");
|
|
296
|
-
}
|
|
297
|
-
const alignedLocal = (0, sessions_1.getAlignedLocal)(containingCluster, id);
|
|
298
|
-
const alignedGenCount = (0, utilities_1.genCountFromLocalId)(alignedLocal);
|
|
299
|
-
const lastFinalizedGenCount = (0, utilities_1.genCountFromLocalId)((0, sessions_1.lastFinalizedLocal)(containingCluster));
|
|
300
|
-
if (alignedGenCount > lastFinalizedGenCount) {
|
|
301
|
-
// should be an eager final id generated by the local session
|
|
302
|
-
if (containingCluster.session === this.localSession) {
|
|
303
|
-
(0, core_utils_1.assert)(!this.normalizer.contains(alignedLocal), 0x759 /* Normalizer out of sync. */);
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
throw new Error("Unknown ID");
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
return (0, utilities_1.stableIdFromNumericUuid)((0, utilities_1.offsetNumericUuid)(containingCluster.session.sessionUuid, alignedGenCount - 1));
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
const localToDecompress = id;
|
|
313
|
-
if (!this.normalizer.contains(localToDecompress)) {
|
|
314
|
-
throw new Error("Unknown ID");
|
|
315
|
-
}
|
|
316
|
-
return (0, utilities_1.stableIdFromNumericUuid)((0, utilities_1.offsetNumericUuid)(this.localSession.sessionUuid, (0, utilities_1.genCountFromLocalId)(localToDecompress) - 1));
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
recompress(uncompressed) {
|
|
320
|
-
const recompressed = this.tryRecompress(uncompressed);
|
|
321
|
-
if (recompressed === undefined) {
|
|
322
|
-
throw new Error("Could not recompress.");
|
|
323
|
-
}
|
|
324
|
-
return recompressed;
|
|
325
|
-
}
|
|
326
|
-
tryRecompress(uncompressed) {
|
|
327
|
-
const match = this.sessions.getContainingCluster(uncompressed);
|
|
328
|
-
if (match === undefined) {
|
|
329
|
-
const numericUncompressed = (0, utilities_1.numericUuidFromStableId)(uncompressed);
|
|
330
|
-
const offset = (0, utilities_1.subtractNumericUuids)(numericUncompressed, this.localSession.sessionUuid);
|
|
331
|
-
if (offset < Number.MAX_SAFE_INTEGER) {
|
|
332
|
-
const genCountEquivalent = Number(offset) + 1;
|
|
333
|
-
const localEquivalent = (0, utilities_1.localIdFromGenCount)(genCountEquivalent);
|
|
334
|
-
if (this.normalizer.contains(localEquivalent)) {
|
|
335
|
-
return localEquivalent;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
return undefined;
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
const [containingCluster, alignedLocal] = match;
|
|
342
|
-
if (containingCluster.session === this.localSession) {
|
|
343
|
-
// Local session
|
|
344
|
-
if (this.normalizer.contains(alignedLocal)) {
|
|
345
|
-
return alignedLocal;
|
|
346
|
-
}
|
|
347
|
-
else {
|
|
348
|
-
(0, core_utils_1.assert)((0, utilities_1.genCountFromLocalId)(alignedLocal) <= this.localGenCount, 0x75a /* Clusters out of sync. */);
|
|
349
|
-
// Id is an eager final
|
|
350
|
-
return (0, sessions_1.getAlignedFinal)(containingCluster, alignedLocal);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
// Not the local session
|
|
355
|
-
return (0, utilities_1.genCountFromLocalId)(alignedLocal) >= (0, sessions_1.lastFinalizedLocal)(containingCluster)
|
|
356
|
-
? (0, sessions_1.getAlignedFinal)(containingCluster, alignedLocal)
|
|
357
|
-
: undefined;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
serialize(hasLocalState) {
|
|
362
|
-
const { normalizer, finalSpace, sessions } = this;
|
|
363
|
-
const sessionIndexMap = new Map();
|
|
364
|
-
let sessionIndex = 0;
|
|
365
|
-
for (const session of sessions.sessions()) {
|
|
366
|
-
// Filter empty sessions to prevent them accumulating in the serialized state
|
|
367
|
-
if (!session.isEmpty() || hasLocalState) {
|
|
368
|
-
sessionIndexMap.set(session, sessionIndex);
|
|
369
|
-
sessionIndex++;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
const localStateSize = hasLocalState
|
|
373
|
-
? 1 + // generated ID count
|
|
374
|
-
1 + // next range base genCount
|
|
375
|
-
1 + // count of normalizer pairs
|
|
376
|
-
this.normalizer.idRanges.size * 2 // pairs
|
|
377
|
-
: 0;
|
|
378
|
-
// Layout size, in 8 byte increments
|
|
379
|
-
const totalSize = 1 + // version
|
|
380
|
-
1 + // hasLocalState
|
|
381
|
-
1 + // cluster capacity
|
|
382
|
-
1 + // session count
|
|
383
|
-
1 + // cluster count
|
|
384
|
-
sessionIndexMap.size * 2 + // session IDs
|
|
385
|
-
finalSpace.clusters.length * 3 + // clusters: (sessionIndex, capacity, count)[]
|
|
386
|
-
localStateSize; // local state, if present
|
|
387
|
-
const serializedFloat = new Float64Array(totalSize);
|
|
388
|
-
const serializedUint = new BigUint64Array(serializedFloat.buffer);
|
|
389
|
-
let index = 0;
|
|
390
|
-
index = (0, persistanceUtilities_1.writeNumber)(serializedFloat, index, currentWrittenVersion);
|
|
391
|
-
index = (0, persistanceUtilities_1.writeBoolean)(serializedFloat, index, hasLocalState);
|
|
392
|
-
index = (0, persistanceUtilities_1.writeNumber)(serializedFloat, index, this.clusterCapacity);
|
|
393
|
-
index = (0, persistanceUtilities_1.writeNumber)(serializedFloat, index, sessionIndexMap.size);
|
|
394
|
-
index = (0, persistanceUtilities_1.writeNumber)(serializedFloat, index, finalSpace.clusters.length);
|
|
395
|
-
for (const [session] of sessionIndexMap.entries()) {
|
|
396
|
-
index = (0, persistanceUtilities_1.writeNumericUuid)(serializedUint, index, session.sessionUuid);
|
|
397
|
-
}
|
|
398
|
-
finalSpace.clusters.forEach((cluster) => {
|
|
399
|
-
index = (0, persistanceUtilities_1.writeNumber)(serializedFloat, index, sessionIndexMap.get(cluster.session));
|
|
400
|
-
index = (0, persistanceUtilities_1.writeNumber)(serializedFloat, index, cluster.capacity);
|
|
401
|
-
index = (0, persistanceUtilities_1.writeNumber)(serializedFloat, index, cluster.count);
|
|
402
|
-
});
|
|
403
|
-
if (hasLocalState) {
|
|
404
|
-
index = (0, persistanceUtilities_1.writeNumber)(serializedFloat, index, this.localGenCount);
|
|
405
|
-
index = (0, persistanceUtilities_1.writeNumber)(serializedFloat, index, this.nextRangeBaseGenCount);
|
|
406
|
-
index = (0, persistanceUtilities_1.writeNumber)(serializedFloat, index, normalizer.idRanges.size);
|
|
407
|
-
for (const [leadingGenCount, count] of normalizer.idRanges.entries()) {
|
|
408
|
-
index = (0, persistanceUtilities_1.writeNumber)(serializedFloat, index, leadingGenCount);
|
|
409
|
-
index = (0, persistanceUtilities_1.writeNumber)(serializedFloat, index, count);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
(0, core_utils_1.assert)(index === totalSize, 0x75b /* Serialized size was incorrectly calculated. */);
|
|
413
|
-
this.logger?.sendTelemetryEvent({
|
|
414
|
-
eventName: "RuntimeIdCompressor:SerializedIdCompressorSize",
|
|
415
|
-
size: serializedFloat.byteLength,
|
|
416
|
-
clusterCount: finalSpace.clusters.length,
|
|
417
|
-
sessionCount: sessionIndexMap.size,
|
|
418
|
-
});
|
|
419
|
-
return (0, client_utils_1.bufferToString)(serializedFloat.buffer, "base64");
|
|
420
|
-
}
|
|
421
|
-
static deserialize(serialized, sessionId) {
|
|
422
|
-
const buffer = (0, client_utils_1.stringToBuffer)(serialized, "base64");
|
|
423
|
-
const index = {
|
|
424
|
-
index: 0,
|
|
425
|
-
bufferFloat: new Float64Array(buffer),
|
|
426
|
-
bufferUint: new BigUint64Array(buffer),
|
|
427
|
-
};
|
|
428
|
-
const version = (0, persistanceUtilities_1.readNumber)(index);
|
|
429
|
-
(0, core_utils_1.assert)(version === currentWrittenVersion, 0x75c /* Unknown serialized version. */);
|
|
430
|
-
const hasLocalState = (0, persistanceUtilities_1.readBoolean)(index);
|
|
431
|
-
const clusterCapacity = (0, persistanceUtilities_1.readNumber)(index);
|
|
432
|
-
const sessionCount = (0, persistanceUtilities_1.readNumber)(index);
|
|
433
|
-
const clusterCount = (0, persistanceUtilities_1.readNumber)(index);
|
|
434
|
-
// Sessions
|
|
435
|
-
let sessionOffset = 0;
|
|
436
|
-
const sessions = [];
|
|
437
|
-
if (!hasLocalState) {
|
|
438
|
-
// If !hasLocalState, there won't be a serialized local session ID so insert one at the beginning
|
|
439
|
-
(0, core_utils_1.assert)(sessionId !== undefined, 0x75d /* Local session ID is undefined. */);
|
|
440
|
-
const localSessionNumeric = (0, utilities_1.numericUuidFromStableId)(sessionId);
|
|
441
|
-
sessions.push([localSessionNumeric, new sessions_1.Session(localSessionNumeric)]);
|
|
442
|
-
sessionOffset = 1;
|
|
443
|
-
}
|
|
444
|
-
else {
|
|
445
|
-
(0, core_utils_1.assert)(sessionId === undefined, 0x75e /* Local state should not exist in serialized form. */);
|
|
446
|
-
}
|
|
447
|
-
for (let i = 0; i < sessionCount; i++) {
|
|
448
|
-
const numeric = (0, persistanceUtilities_1.readNumericUuid)(index);
|
|
449
|
-
sessions.push([numeric, new sessions_1.Session(numeric)]);
|
|
450
|
-
}
|
|
451
|
-
const compressor = new IdCompressor(new sessions_1.Sessions(sessions));
|
|
452
|
-
compressor.clusterCapacity = clusterCapacity;
|
|
453
|
-
// Clusters
|
|
454
|
-
let baseFinalId = 0;
|
|
455
|
-
for (let i = 0; i < clusterCount; i++) {
|
|
456
|
-
const sessionIndex = (0, persistanceUtilities_1.readNumber)(index);
|
|
457
|
-
const session = sessions[sessionIndex + sessionOffset][1];
|
|
458
|
-
const capacity = (0, persistanceUtilities_1.readNumber)(index);
|
|
459
|
-
const count = (0, persistanceUtilities_1.readNumber)(index);
|
|
460
|
-
const cluster = session.addNewCluster(baseFinalId, capacity, count);
|
|
461
|
-
compressor.finalSpace.addCluster(cluster);
|
|
462
|
-
baseFinalId += capacity;
|
|
463
|
-
}
|
|
464
|
-
// Local state
|
|
465
|
-
if (hasLocalState) {
|
|
466
|
-
compressor.localGenCount = (0, persistanceUtilities_1.readNumber)(index);
|
|
467
|
-
compressor.nextRangeBaseGenCount = (0, persistanceUtilities_1.readNumber)(index);
|
|
468
|
-
const normalizerCount = (0, persistanceUtilities_1.readNumber)(index);
|
|
469
|
-
for (let i = 0; i < normalizerCount; i++) {
|
|
470
|
-
compressor.normalizer.addLocalRange((0, persistanceUtilities_1.readNumber)(index), (0, persistanceUtilities_1.readNumber)(index));
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
(0, core_utils_1.assert)(index.index === index.bufferFloat.length, 0x75f /* Failed to read entire serialized compressor. */);
|
|
474
|
-
return compressor;
|
|
475
|
-
}
|
|
476
|
-
equals(other, includeLocalState) {
|
|
477
|
-
if (includeLocalState &&
|
|
478
|
-
(this.localSessionId !== other.localSessionId ||
|
|
479
|
-
!this.localSession.equals(other.localSession) ||
|
|
480
|
-
!this.normalizer.equals(other.normalizer) ||
|
|
481
|
-
this.nextRangeBaseGenCount !== other.nextRangeBaseGenCount ||
|
|
482
|
-
this.localGenCount !== other.localGenCount)) {
|
|
483
|
-
return false;
|
|
484
|
-
}
|
|
485
|
-
return (this.newClusterCapacity === other.newClusterCapacity &&
|
|
486
|
-
this.sessions.equals(other.sessions, includeLocalState) &&
|
|
487
|
-
this.finalSpace.equals(other.finalSpace));
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
exports.IdCompressor = IdCompressor;
|
|
491
|
-
/**
|
|
492
|
-
* Max allowed initial cluster size.
|
|
493
|
-
*/
|
|
494
|
-
IdCompressor.maxClusterSize = 2 ** 20;
|
|
495
|
-
//# sourceMappingURL=idCompressor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"idCompressor.js","sourceRoot":"","sources":["../../src/id-compressor/idCompressor.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2DAAoD;AACpD,+DAA8E;AAC9E,6EAY6C;AAE7C,qEAAyF;AACzF,+CAA6F;AAC7F,2CAQqB;AACrB,iEAQgC;AAChC,yCAOoB;AACpB,qEAAkE;AAClE,6CAA0C;AAE1C;;;GAGG;AACH,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEhC;;GAEG;AACH,MAAa,YAAY;IAmCxB,0BAA0B;IAE1B,YACC,4BAAkD,EACjC,MAA4B;QAA5B,WAAM,GAAN,MAAM,CAAsB;QA7B7B,eAAU,GAAG,IAAI,+CAAsB,EAAE,CAAC;QAC3D,mDAAmD;QAC3C,kBAAa,GAAG,CAAC,CAAC;QAE1B,0BAA0B;QAE1B,0BAA0B;QAE1B,mGAAmG;QACnG,gFAAgF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,KAAK,CAAC,cAAc;gBAC5C,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC;gBAC7C,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;gBACzC,IAAI,CAAC,qBAAqB,KAAK,KAAK,CAAC,qBAAqB;gBAC1D,IAAI,CAAC,aAAa,KAAK,KAAK,CAAC,aAAa,CAAC,EAC3C;YACD,OAAO,KAAK,CAAC;SACb;QACD,OAAO,CACN,IAAI,CAAC,kBAAkB,KAAK,KAAK,CAAC,kBAAkB;YACpD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,iBAAiB,CAAC;YACvD,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CACxC,CAAC;IACH,CAAC;;AAvjBF,oCAwjBC;AAvjBA;;GAEG;AACoB,2BAAc,GAAG,CAAC,IAAI,EAAE,AAAV,CAAW","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport { bufferToString, stringToBuffer } from \"@fluid-internal/client-utils\";\nimport {\n\tIdCreationRange,\n\tIIdCompressor,\n\tIIdCompressorCore,\n\tOpSpaceCompressedId,\n\tSerializedIdCompressor,\n\tSerializedIdCompressorWithNoSession,\n\tSerializedIdCompressorWithOngoingSession,\n\tSessionId,\n\tSessionSpaceCompressedId,\n\tStableId,\n\tinitialClusterCapacity,\n} from \"@fluidframework/runtime-definitions\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { ITelemetryLoggerExt, createChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { FinalCompressedId, isFinalId, LocalCompressedId, NumericUuid } from \"./identifiers\";\nimport {\n\tcreateSessionId,\n\tlocalIdFromGenCount,\n\tgenCountFromLocalId,\n\tnumericUuidFromStableId,\n\toffsetNumericUuid,\n\tstableIdFromNumericUuid,\n\tsubtractNumericUuids,\n} from \"./utilities\";\nimport {\n\tIndex,\n\treadBoolean,\n\treadNumber,\n\treadNumericUuid,\n\twriteBoolean,\n\twriteNumber,\n\twriteNumericUuid,\n} from \"./persistanceUtilities\";\nimport {\n\tgetAlignedLocal,\n\tgetAlignedFinal,\n\tIdCluster,\n\tlastFinalizedLocal,\n\tSession,\n\tSessions,\n} from \"./sessions\";\nimport { SessionSpaceNormalizer } from \"./sessionSpaceNormalizer\";\nimport { FinalSpace } from \"./finalSpace\";\n\n/**\n * The version of IdCompressor that is currently persisted.\n * This should not be changed without careful consideration to compatibility.\n */\nconst currentWrittenVersion = 1;\n\n/**\n * See {@link IIdCompressor} and {@link IIdCompressorCore}\n */\nexport class IdCompressor implements IIdCompressor, IIdCompressorCore {\n\t/**\n\t * Max allowed initial cluster size.\n\t */\n\tpublic static readonly maxClusterSize = 2 ** 20;\n\n\t// ----- Local state -----\n\n\tpublic readonly localSessionId: SessionId;\n\tprivate readonly localSession: Session;\n\tprivate readonly normalizer = new SessionSpaceNormalizer();\n\t// The number of IDs generated by the local session\n\tprivate localGenCount = 0;\n\n\t// -----------------------\n\n\t// ----- Final state -----\n\n\t// The gen count to be annotated on the range returned by the next call to `takeNextCreationRange`.\n\t// This is updated to be equal to `generatedIdCount` + 1 each time it is called.\n\tprivate nextRangeBaseGenCount = 1;\n\t// The capacity of the next cluster to be created\n\tprivate newClusterCapacity = initialClusterCapacity;\n\tprivate readonly sessions = new Sessions();\n\tprivate readonly finalSpace = new FinalSpace();\n\n\t// -----------------------\n\n\t// ----- Telemetry state -----\n\n\t// The number of local IDs generated since the last telemetry was sent.\n\tprivate telemetryLocalIdCount = 0;\n\t// The number of eager final IDs generated since the last telemetry was sent.\n\tprivate telemetryEagerFinalIdCount = 0;\n\n\t// -----------------------\n\n\tprivate constructor(\n\t\tlocalSessionIdOrDeserialized: SessionId | Sessions,\n\t\tprivate readonly logger?: ITelemetryLoggerExt,\n\t) {\n\t\tif (typeof localSessionIdOrDeserialized === \"string\") {\n\t\t\tthis.localSessionId = localSessionIdOrDeserialized;\n\t\t\tthis.localSession = this.sessions.getOrCreate(localSessionIdOrDeserialized);\n\t\t} else {\n\t\t\t// Deserialize case\n\t\t\tthis.sessions = localSessionIdOrDeserialized;\n\t\t\t// As policy, the first session is always the local session. Preserve this invariant\n\t\t\t// during deserialization.\n\t\t\tconst firstSession = localSessionIdOrDeserialized.sessions().next();\n\t\t\tassert(!firstSession.done, 0x754 /* First session must be present. */);\n\t\t\tthis.localSession = firstSession.value;\n\t\t\tthis.localSessionId = stableIdFromNumericUuid(\n\t\t\t\tthis.localSession.sessionUuid,\n\t\t\t) as SessionId;\n\t\t}\n\t}\n\n\tpublic static create(logger?: ITelemetryBaseLogger): IdCompressor;\n\tpublic static create(sessionId: SessionId, logger?: ITelemetryBaseLogger): IdCompressor;\n\tpublic static create(\n\t\tsessionIdOrLogger?: SessionId | ITelemetryBaseLogger,\n\t\tloggerOrUndefined?: ITelemetryBaseLogger,\n\t): IdCompressor {\n\t\tlet localSessionId: SessionId;\n\t\tlet logger: ITelemetryBaseLogger | undefined;\n\t\tif (sessionIdOrLogger === undefined) {\n\t\t\tlocalSessionId = createSessionId();\n\t\t} else {\n\t\t\tif (typeof sessionIdOrLogger === \"string\") {\n\t\t\t\tlocalSessionId = sessionIdOrLogger;\n\t\t\t\tlogger = loggerOrUndefined;\n\t\t\t} else {\n\t\t\t\tlocalSessionId = createSessionId();\n\t\t\t\tlogger = loggerOrUndefined;\n\t\t\t}\n\t\t}\n\t\tconst compressor = new IdCompressor(\n\t\t\tlocalSessionId,\n\t\t\tlogger === undefined ? undefined : createChildLogger({ logger }),\n\t\t);\n\t\treturn compressor;\n\t}\n\n\t/**\n\t * The size of each newly created ID cluster.\n\t */\n\tpublic get clusterCapacity(): number {\n\t\treturn this.newClusterCapacity;\n\t}\n\n\t/**\n\t * Must only be set with a value upon which consensus has been reached. Value must be greater than zero and less than\n\t * `IdCompressor.maxClusterSize`.\n\t */\n\tpublic set clusterCapacity(value: number) {\n\t\tif (value <= 0) {\n\t\t\tthrow new Error(\"Clusters must have a positive capacity.\");\n\t\t}\n\t\tif (value > IdCompressor.maxClusterSize) {\n\t\t\tthrow new Error(\"Clusters must not exceed max cluster size.\");\n\t\t}\n\t\tthis.newClusterCapacity = value;\n\t}\n\n\tpublic generateCompressedId(): SessionSpaceCompressedId {\n\t\tthis.localGenCount++;\n\t\tconst lastCluster = this.localSession.getLastCluster();\n\t\tif (lastCluster === undefined) {\n\t\t\tthis.telemetryLocalIdCount++;\n\t\t\treturn this.generateNextLocalId();\n\t\t}\n\n\t\t// If there exists a cluster of final IDs already claimed by the local session that still has room in it,\n\t\t// it is known prior to range sequencing what a local ID's corresponding final ID will be.\n\t\t// In this case, it is safe to return the final ID immediately. This is guaranteed to be safe because\n\t\t// any op that the local session sends that contains one of those final IDs are guaranteed to arrive to\n\t\t// collaborators *after* the one containing the creation range.\n\t\tconst clusterOffset = this.localGenCount - genCountFromLocalId(lastCluster.baseLocalId);\n\t\tif (lastCluster.capacity > clusterOffset) {\n\t\t\tthis.telemetryEagerFinalIdCount++;\n\t\t\t// Space in the cluster: eager final\n\t\t\treturn ((lastCluster.baseFinalId as number) +\n\t\t\t\tclusterOffset) as SessionSpaceCompressedId;\n\t\t}\n\t\t// No space in the cluster, return next local\n\t\tthis.telemetryLocalIdCount++;\n\t\treturn this.generateNextLocalId();\n\t}\n\n\tprivate generateNextLocalId(): LocalCompressedId {\n\t\t// Must tell the normalizer that we generated a local ID\n\t\tthis.normalizer.addLocalRange(this.localGenCount, 1);\n\t\treturn localIdFromGenCount(this.localGenCount);\n\t}\n\n\tpublic takeNextCreationRange(): IdCreationRange {\n\t\tconst count = this.localGenCount - (this.nextRangeBaseGenCount - 1);\n\t\tif (count === 0) {\n\t\t\treturn {\n\t\t\t\tsessionId: this.localSessionId,\n\t\t\t};\n\t\t}\n\t\tconst range: IdCreationRange = {\n\t\t\tsessionId: this.localSessionId,\n\t\t\tids: {\n\t\t\t\tfirstGenCount: this.nextRangeBaseGenCount,\n\t\t\t\tcount,\n\t\t\t},\n\t\t};\n\t\tthis.nextRangeBaseGenCount = this.localGenCount + 1;\n\t\treturn range;\n\t}\n\n\tpublic finalizeCreationRange(range: IdCreationRange): void {\n\t\t// Check if the range has IDs\n\t\tif (range.ids === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tassert(range.ids.count > 0, 0x755 /* Malformed ID Range. */);\n\t\tconst { sessionId, ids } = range;\n\t\tconst { count, firstGenCount } = ids;\n\t\tconst session = this.sessions.getOrCreate(sessionId);\n\t\tconst isLocal = session === this.localSession;\n\t\tconst rangeBaseLocal = localIdFromGenCount(firstGenCount);\n\t\tlet lastCluster = session.getLastCluster();\n\t\tif (lastCluster === undefined) {\n\t\t\t// This is the first cluster in the session space\n\t\t\tif (rangeBaseLocal !== -1) {\n\t\t\t\tthrow new Error(\"Ranges finalized out of order.\");\n\t\t\t}\n\t\t\tlastCluster = this.addEmptyCluster(session, this.clusterCapacity + count);\n\t\t\tif (isLocal) {\n\t\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\t\teventName: \"RuntimeIdCompressor:FirstCluster\",\n\t\t\t\t\tsessionId: this.localSessionId,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst remainingCapacity = lastCluster.capacity - lastCluster.count;\n\t\tif (lastCluster.baseLocalId - lastCluster.count !== rangeBaseLocal) {\n\t\t\tthrow new Error(\"Ranges finalized out of order.\");\n\t\t}\n\n\t\tif (remainingCapacity >= count) {\n\t\t\t// The current range fits in the existing cluster\n\t\t\tlastCluster.count += count;\n\t\t} else {\n\t\t\tconst overflow = count - remainingCapacity;\n\t\t\tconst newClaimedFinalCount = overflow + this.clusterCapacity;\n\t\t\tif (lastCluster === this.finalSpace.getLastCluster()) {\n\t\t\t\t// The last cluster in the sessions chain is the last cluster globally, so it can be expanded.\n\t\t\t\tlastCluster.capacity += newClaimedFinalCount;\n\t\t\t\tlastCluster.count += count;\n\t\t\t\tassert(\n\t\t\t\t\t!this.sessions.clusterCollides(lastCluster),\n\t\t\t\t\t0x756 /* Cluster collision detected. */,\n\t\t\t\t);\n\t\t\t\tif (isLocal) {\n\t\t\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\t\t\teventName: \"RuntimeIdCompressor:ClusterExpansion\",\n\t\t\t\t\t\tsessionId: this.localSessionId,\n\t\t\t\t\t\tpreviousCapacity: lastCluster.capacity - newClaimedFinalCount,\n\t\t\t\t\t\tnewCapacity: lastCluster.capacity,\n\t\t\t\t\t\toverflow,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// The last cluster in the sessions chain is *not* the last cluster globally. Fill and overflow to new.\n\t\t\t\tlastCluster.count = lastCluster.capacity;\n\t\t\t\tconst newCluster = this.addEmptyCluster(session, newClaimedFinalCount);\n\t\t\t\tnewCluster.count += overflow;\n\t\t\t\tif (isLocal) {\n\t\t\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\t\t\teventName: \"RuntimeIdCompressor:NewCluster\",\n\t\t\t\t\t\tsessionId: this.localSessionId,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (isLocal) {\n\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\teventName: \"RuntimeIdCompressor:IdCompressorStatus\",\n\t\t\t\teagerFinalIdCount: this.telemetryEagerFinalIdCount,\n\t\t\t\tlocalIdCount: this.telemetryLocalIdCount,\n\t\t\t\tsessionId: this.localSessionId,\n\t\t\t});\n\t\t\tthis.telemetryEagerFinalIdCount = 0;\n\t\t\tthis.telemetryLocalIdCount = 0;\n\t\t}\n\n\t\tassert(!session.isEmpty(), 0x757 /* Empty sessions should not be created. */);\n\t}\n\n\tprivate addEmptyCluster(session: Session, capacity: number): IdCluster {\n\t\tconst newCluster = session.addNewCluster(\n\t\t\tthis.finalSpace.getAllocatedIdLimit(),\n\t\t\tcapacity,\n\t\t\t0,\n\t\t);\n\t\tassert(!this.sessions.clusterCollides(newCluster), 0x758 /* Cluster collision detected. */);\n\t\tthis.finalSpace.addCluster(newCluster);\n\t\treturn newCluster;\n\t}\n\n\tpublic normalizeToOpSpace(id: SessionSpaceCompressedId): OpSpaceCompressedId {\n\t\tif (isFinalId(id)) {\n\t\t\treturn id;\n\t\t} else {\n\t\t\tconst local = id as unknown as LocalCompressedId;\n\t\t\tif (!this.normalizer.contains(local)) {\n\t\t\t\tthrow new Error(\"Invalid ID to normalize.\");\n\t\t\t}\n\t\t\tconst finalForm = this.localSession.tryConvertToFinal(local, true);\n\t\t\treturn finalForm === undefined\n\t\t\t\t? (local as unknown as OpSpaceCompressedId)\n\t\t\t\t: (finalForm as OpSpaceCompressedId);\n\t\t}\n\t}\n\n\tpublic normalizeToSessionSpace(\n\t\tid: OpSpaceCompressedId,\n\t\toriginSessionId: SessionId,\n\t): SessionSpaceCompressedId {\n\t\tif (isFinalId(id)) {\n\t\t\tconst containingCluster = this.localSession.getClusterByAllocatedFinal(id);\n\t\t\tif (containingCluster === undefined) {\n\t\t\t\t// Does not exist in local cluster chain\n\t\t\t\tif (id >= this.finalSpace.getFinalizedIdLimit()) {\n\t\t\t\t\tthrow new Error(\"Unknown op space ID.\");\n\t\t\t\t}\n\t\t\t\treturn id as unknown as SessionSpaceCompressedId;\n\t\t\t} else {\n\t\t\t\tconst alignedLocal = getAlignedLocal(containingCluster, id);\n\t\t\t\tif (this.normalizer.contains(alignedLocal)) {\n\t\t\t\t\treturn alignedLocal;\n\t\t\t\t} else {\n\t\t\t\t\tif (genCountFromLocalId(alignedLocal) > this.localGenCount) {\n\t\t\t\t\t\tthrow new Error(\"Unknown op space ID.\");\n\t\t\t\t\t}\n\t\t\t\t\treturn id as unknown as SessionSpaceCompressedId;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tconst localToNormalize = id as unknown as LocalCompressedId;\n\t\t\tif (originSessionId === this.localSessionId) {\n\t\t\t\tif (this.normalizer.contains(localToNormalize)) {\n\t\t\t\t\treturn localToNormalize;\n\t\t\t\t} else {\n\t\t\t\t\t// We never generated this local ID, so fail\n\t\t\t\t\tthrow new Error(\"Unknown op space ID.\");\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// LocalId from a remote session\n\t\t\t\tconst remoteSession = this.sessions.get(originSessionId);\n\t\t\t\tif (remoteSession === undefined) {\n\t\t\t\t\tthrow new Error(\"No IDs have ever been finalized by the supplied session.\");\n\t\t\t\t}\n\t\t\t\tconst correspondingFinal = remoteSession.tryConvertToFinal(localToNormalize, false);\n\t\t\t\tif (correspondingFinal === undefined) {\n\t\t\t\t\tthrow new Error(\"Unknown op space ID.\");\n\t\t\t\t}\n\t\t\t\treturn correspondingFinal as unknown as SessionSpaceCompressedId;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic decompress(id: SessionSpaceCompressedId): StableId {\n\t\tif (isFinalId(id)) {\n\t\t\tconst containingCluster = Session.getContainingCluster(id, this.finalSpace.clusters);\n\t\t\tif (containingCluster === undefined) {\n\t\t\t\tthrow new Error(\"Unknown ID\");\n\t\t\t}\n\t\t\tconst alignedLocal = getAlignedLocal(containingCluster, id);\n\t\t\tconst alignedGenCount = genCountFromLocalId(alignedLocal);\n\t\t\tconst lastFinalizedGenCount = genCountFromLocalId(\n\t\t\t\tlastFinalizedLocal(containingCluster),\n\t\t\t);\n\t\t\tif (alignedGenCount > lastFinalizedGenCount) {\n\t\t\t\t// should be an eager final id generated by the local session\n\t\t\t\tif (containingCluster.session === this.localSession) {\n\t\t\t\t\tassert(\n\t\t\t\t\t\t!this.normalizer.contains(alignedLocal),\n\t\t\t\t\t\t0x759 /* Normalizer out of sync. */,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(\"Unknown ID\");\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn stableIdFromNumericUuid(\n\t\t\t\toffsetNumericUuid(containingCluster.session.sessionUuid, alignedGenCount - 1),\n\t\t\t);\n\t\t} else {\n\t\t\tconst localToDecompress = id as unknown as LocalCompressedId;\n\t\t\tif (!this.normalizer.contains(localToDecompress)) {\n\t\t\t\tthrow new Error(\"Unknown ID\");\n\t\t\t}\n\t\t\treturn stableIdFromNumericUuid(\n\t\t\t\toffsetNumericUuid(\n\t\t\t\t\tthis.localSession.sessionUuid,\n\t\t\t\t\tgenCountFromLocalId(localToDecompress) - 1,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic recompress(uncompressed: StableId): SessionSpaceCompressedId {\n\t\tconst recompressed = this.tryRecompress(uncompressed);\n\t\tif (recompressed === undefined) {\n\t\t\tthrow new Error(\"Could not recompress.\");\n\t\t}\n\t\treturn recompressed;\n\t}\n\n\tpublic tryRecompress(uncompressed: StableId): SessionSpaceCompressedId | undefined {\n\t\tconst match = this.sessions.getContainingCluster(uncompressed);\n\t\tif (match === undefined) {\n\t\t\tconst numericUncompressed = numericUuidFromStableId(uncompressed);\n\t\t\tconst offset = subtractNumericUuids(numericUncompressed, this.localSession.sessionUuid);\n\t\t\tif (offset < Number.MAX_SAFE_INTEGER) {\n\t\t\t\tconst genCountEquivalent = Number(offset) + 1;\n\t\t\t\tconst localEquivalent = localIdFromGenCount(genCountEquivalent);\n\t\t\t\tif (this.normalizer.contains(localEquivalent)) {\n\t\t\t\t\treturn localEquivalent;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined;\n\t\t} else {\n\t\t\tconst [containingCluster, alignedLocal] = match;\n\t\t\tif (containingCluster.session === this.localSession) {\n\t\t\t\t// Local session\n\t\t\t\tif (this.normalizer.contains(alignedLocal)) {\n\t\t\t\t\treturn alignedLocal;\n\t\t\t\t} else {\n\t\t\t\t\tassert(\n\t\t\t\t\t\tgenCountFromLocalId(alignedLocal) <= this.localGenCount,\n\t\t\t\t\t\t0x75a /* Clusters out of sync. */,\n\t\t\t\t\t);\n\t\t\t\t\t// Id is an eager final\n\t\t\t\t\treturn getAlignedFinal(containingCluster, alignedLocal) as\n\t\t\t\t\t\t| SessionSpaceCompressedId\n\t\t\t\t\t\t| undefined;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Not the local session\n\t\t\t\treturn genCountFromLocalId(alignedLocal) >= lastFinalizedLocal(containingCluster)\n\t\t\t\t\t? (getAlignedFinal(containingCluster, alignedLocal) as\n\t\t\t\t\t\t\t| SessionSpaceCompressedId\n\t\t\t\t\t\t\t| undefined)\n\t\t\t\t\t: undefined;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic serialize(withSession: true): SerializedIdCompressorWithOngoingSession;\n\tpublic serialize(withSession: false): SerializedIdCompressorWithNoSession;\n\tpublic serialize(hasLocalState: boolean): SerializedIdCompressor {\n\t\tconst { normalizer, finalSpace, sessions } = this;\n\t\tconst sessionIndexMap = new Map<Session, number>();\n\t\tlet sessionIndex = 0;\n\t\tfor (const session of sessions.sessions()) {\n\t\t\t// Filter empty sessions to prevent them accumulating in the serialized state\n\t\t\tif (!session.isEmpty() || hasLocalState) {\n\t\t\t\tsessionIndexMap.set(session, sessionIndex);\n\t\t\t\tsessionIndex++;\n\t\t\t}\n\t\t}\n\t\tconst localStateSize = hasLocalState\n\t\t\t? 1 + // generated ID count\n\t\t\t 1 + // next range base genCount\n\t\t\t 1 + // count of normalizer pairs\n\t\t\t this.normalizer.idRanges.size * 2 // pairs\n\t\t\t: 0;\n\t\t// Layout size, in 8 byte increments\n\t\tconst totalSize =\n\t\t\t1 + // version\n\t\t\t1 + // hasLocalState\n\t\t\t1 + // cluster capacity\n\t\t\t1 + // session count\n\t\t\t1 + // cluster count\n\t\t\tsessionIndexMap.size * 2 + // session IDs\n\t\t\tfinalSpace.clusters.length * 3 + // clusters: (sessionIndex, capacity, count)[]\n\t\t\tlocalStateSize; // local state, if present\n\n\t\tconst serializedFloat = new Float64Array(totalSize);\n\t\tconst serializedUint = new BigUint64Array(serializedFloat.buffer);\n\t\tlet index = 0;\n\t\tindex = writeNumber(serializedFloat, index, currentWrittenVersion);\n\t\tindex = writeBoolean(serializedFloat, index, hasLocalState);\n\t\tindex = writeNumber(serializedFloat, index, this.clusterCapacity);\n\t\tindex = writeNumber(serializedFloat, index, sessionIndexMap.size);\n\t\tindex = writeNumber(serializedFloat, index, finalSpace.clusters.length);\n\n\t\tfor (const [session] of sessionIndexMap.entries()) {\n\t\t\tindex = writeNumericUuid(serializedUint, index, session.sessionUuid);\n\t\t}\n\n\t\tfinalSpace.clusters.forEach((cluster) => {\n\t\t\tindex = writeNumber(\n\t\t\t\tserializedFloat,\n\t\t\t\tindex,\n\t\t\t\tsessionIndexMap.get(cluster.session) as number,\n\t\t\t);\n\t\t\tindex = writeNumber(serializedFloat, index, cluster.capacity);\n\t\t\tindex = writeNumber(serializedFloat, index, cluster.count);\n\t\t});\n\n\t\tif (hasLocalState) {\n\t\t\tindex = writeNumber(serializedFloat, index, this.localGenCount);\n\t\t\tindex = writeNumber(serializedFloat, index, this.nextRangeBaseGenCount);\n\t\t\tindex = writeNumber(serializedFloat, index, normalizer.idRanges.size);\n\t\t\tfor (const [leadingGenCount, count] of normalizer.idRanges.entries()) {\n\t\t\t\tindex = writeNumber(serializedFloat, index, leadingGenCount);\n\t\t\t\tindex = writeNumber(serializedFloat, index, count);\n\t\t\t}\n\t\t}\n\n\t\tassert(index === totalSize, 0x75b /* Serialized size was incorrectly calculated. */);\n\t\tthis.logger?.sendTelemetryEvent({\n\t\t\teventName: \"RuntimeIdCompressor:SerializedIdCompressorSize\",\n\t\t\tsize: serializedFloat.byteLength,\n\t\t\tclusterCount: finalSpace.clusters.length,\n\t\t\tsessionCount: sessionIndexMap.size,\n\t\t});\n\n\t\treturn bufferToString(serializedFloat.buffer, \"base64\") as SerializedIdCompressor;\n\t}\n\n\tpublic static deserialize(serialized: SerializedIdCompressorWithOngoingSession): IdCompressor;\n\tpublic static deserialize(\n\t\tserialized: SerializedIdCompressorWithNoSession,\n\t\tnewSessionId: SessionId,\n\t): IdCompressor;\n\tpublic static deserialize(\n\t\tserialized: SerializedIdCompressor,\n\t\tsessionId?: SessionId,\n\t): IdCompressor {\n\t\tconst buffer = stringToBuffer(serialized, \"base64\");\n\t\tconst index: Index = {\n\t\t\tindex: 0,\n\t\t\tbufferFloat: new Float64Array(buffer),\n\t\t\tbufferUint: new BigUint64Array(buffer),\n\t\t};\n\t\tconst version = readNumber(index);\n\t\tassert(version === currentWrittenVersion, 0x75c /* Unknown serialized version. */);\n\t\tconst hasLocalState = readBoolean(index);\n\t\tconst clusterCapacity = readNumber(index);\n\t\tconst sessionCount = readNumber(index);\n\t\tconst clusterCount = readNumber(index);\n\n\t\t// Sessions\n\t\tlet sessionOffset = 0;\n\t\tconst sessions: [NumericUuid, Session][] = [];\n\t\tif (!hasLocalState) {\n\t\t\t// If !hasLocalState, there won't be a serialized local session ID so insert one at the beginning\n\t\t\tassert(sessionId !== undefined, 0x75d /* Local session ID is undefined. */);\n\t\t\tconst localSessionNumeric = numericUuidFromStableId(sessionId);\n\t\t\tsessions.push([localSessionNumeric, new Session(localSessionNumeric)]);\n\t\t\tsessionOffset = 1;\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tsessionId === undefined,\n\t\t\t\t0x75e /* Local state should not exist in serialized form. */,\n\t\t\t);\n\t\t}\n\n\t\tfor (let i = 0; i < sessionCount; i++) {\n\t\t\tconst numeric = readNumericUuid(index);\n\t\t\tsessions.push([numeric, new Session(numeric)]);\n\t\t}\n\n\t\tconst compressor = new IdCompressor(new Sessions(sessions));\n\t\tcompressor.clusterCapacity = clusterCapacity;\n\n\t\t// Clusters\n\t\tlet baseFinalId = 0;\n\t\tfor (let i = 0; i < clusterCount; i++) {\n\t\t\tconst sessionIndex = readNumber(index);\n\t\t\tconst session = sessions[sessionIndex + sessionOffset][1];\n\t\t\tconst capacity = readNumber(index);\n\t\t\tconst count = readNumber(index);\n\t\t\tconst cluster = session.addNewCluster(\n\t\t\t\tbaseFinalId as FinalCompressedId,\n\t\t\t\tcapacity,\n\t\t\t\tcount,\n\t\t\t);\n\t\t\tcompressor.finalSpace.addCluster(cluster);\n\t\t\tbaseFinalId += capacity;\n\t\t}\n\n\t\t// Local state\n\t\tif (hasLocalState) {\n\t\t\tcompressor.localGenCount = readNumber(index);\n\t\t\tcompressor.nextRangeBaseGenCount = readNumber(index);\n\t\t\tconst normalizerCount = readNumber(index);\n\t\t\tfor (let i = 0; i < normalizerCount; i++) {\n\t\t\t\tcompressor.normalizer.addLocalRange(readNumber(index), readNumber(index));\n\t\t\t}\n\t\t}\n\n\t\tassert(\n\t\t\tindex.index === index.bufferFloat.length,\n\t\t\t0x75f /* Failed to read entire serialized compressor. */,\n\t\t);\n\t\treturn compressor;\n\t}\n\n\tpublic equals(other: IdCompressor, includeLocalState: boolean): boolean {\n\t\tif (\n\t\t\tincludeLocalState &&\n\t\t\t(this.localSessionId !== other.localSessionId ||\n\t\t\t\t!this.localSession.equals(other.localSession) ||\n\t\t\t\t!this.normalizer.equals(other.normalizer) ||\n\t\t\t\tthis.nextRangeBaseGenCount !== other.nextRangeBaseGenCount ||\n\t\t\t\tthis.localGenCount !== other.localGenCount)\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t\treturn (\n\t\t\tthis.newClusterCapacity === other.newClusterCapacity &&\n\t\t\tthis.sessions.equals(other.sessions, includeLocalState) &&\n\t\t\tthis.finalSpace.equals(other.finalSpace)\n\t\t);\n\t}\n}\n"]}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { OpSpaceCompressedId, SessionSpaceCompressedId } from "@fluidframework/runtime-definitions";
|
|
6
|
-
/**
|
|
7
|
-
* A compressed ID that is stable and unique within the scope of network of compressors (i.e. a document).
|
|
8
|
-
* It can only be used/decompressed in the context of the originating document.
|
|
9
|
-
*/
|
|
10
|
-
export type FinalCompressedId = number & {
|
|
11
|
-
readonly FinalCompressedId: "5d83d1e2-98b7-4e4e-a889-54c855cfa73d";
|
|
12
|
-
readonly OpNormalized: "9209432d-a959-4df7-b2ad-767ead4dbcae";
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* A compressed ID that is local to a session (can only be decompressed when paired with a SessionId).
|
|
16
|
-
* Internally, it should not be persisted outside a scope annotated with the originating SessionId in order to be unambiguous.
|
|
17
|
-
* If external persistence is needed (e.g. by a client), a StableId should be used instead.
|
|
18
|
-
*/
|
|
19
|
-
export type LocalCompressedId = number & {
|
|
20
|
-
readonly LocalCompressedId: "6fccb42f-e2a4-4243-bd29-f13d12b9c6d1";
|
|
21
|
-
} & SessionSpaceCompressedId;
|
|
22
|
-
/**
|
|
23
|
-
* @returns true if the supplied ID is a final ID.
|
|
24
|
-
*/
|
|
25
|
-
export declare function isFinalId(id: SessionSpaceCompressedId | OpSpaceCompressedId): id is FinalCompressedId;
|
|
26
|
-
/**
|
|
27
|
-
* A StableId which is suitable for use as a session identifier
|
|
28
|
-
*/
|
|
29
|
-
export type NumericUuid = bigint & {
|
|
30
|
-
readonly NumericUuid: "be04dd4d-9d7e-4337-a833-eec64c61aa46";
|
|
31
|
-
};
|
|
32
|
-
//# sourceMappingURL=identifiers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"identifiers.d.ts","sourceRoot":"","sources":["../../src/id-compressor/identifiers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAEpG;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG;IACxC,QAAQ,CAAC,iBAAiB,EAAE,sCAAsC,CAAC;IAGnE,QAAQ,CAAC,YAAY,EAAE,sCAAsC,CAAC;CAC9D,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG;IACxC,QAAQ,CAAC,iBAAiB,EAAE,sCAAsC,CAAC;CACnE,GAAG,wBAAwB,CAAC;AAE7B;;GAEG;AACH,wBAAgB,SAAS,CACxB,EAAE,EAAE,wBAAwB,GAAG,mBAAmB,GAChD,EAAE,IAAI,iBAAiB,CAEzB;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG;IAClC,QAAQ,CAAC,WAAW,EAAE,sCAAsC,CAAC;CAC7D,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.isFinalId = void 0;
|
|
8
|
-
/**
|
|
9
|
-
* @returns true if the supplied ID is a final ID.
|
|
10
|
-
*/
|
|
11
|
-
function isFinalId(id) {
|
|
12
|
-
return id >= 0;
|
|
13
|
-
}
|
|
14
|
-
exports.isFinalId = isFinalId;
|
|
15
|
-
//# sourceMappingURL=identifiers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"identifiers.js","sourceRoot":"","sources":["../../src/id-compressor/identifiers.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAwBH;;GAEG;AACH,SAAgB,SAAS,CACxB,EAAkD;IAElD,OAAO,EAAE,IAAI,CAAC,CAAC;AAChB,CAAC;AAJD,8BAIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { OpSpaceCompressedId, SessionSpaceCompressedId } from \"@fluidframework/runtime-definitions\";\n\n/**\n * A compressed ID that is stable and unique within the scope of network of compressors (i.e. a document).\n * It can only be used/decompressed in the context of the originating document.\n */\nexport type FinalCompressedId = number & {\n\treadonly FinalCompressedId: \"5d83d1e2-98b7-4e4e-a889-54c855cfa73d\";\n\n\t// Same brand as OpNormalizedCompressedId, as final IDs are always finally normalized\n\treadonly OpNormalized: \"9209432d-a959-4df7-b2ad-767ead4dbcae\";\n};\n\n/**\n * A compressed ID that is local to a session (can only be decompressed when paired with a SessionId).\n * Internally, it should not be persisted outside a scope annotated with the originating SessionId in order to be unambiguous.\n * If external persistence is needed (e.g. by a client), a StableId should be used instead.\n */\nexport type LocalCompressedId = number & {\n\treadonly LocalCompressedId: \"6fccb42f-e2a4-4243-bd29-f13d12b9c6d1\";\n} & SessionSpaceCompressedId; // Same brand as CompressedId, as local IDs are always locally normalized\n\n/**\n * @returns true if the supplied ID is a final ID.\n */\nexport function isFinalId(\n\tid: SessionSpaceCompressedId | OpSpaceCompressedId,\n): id is FinalCompressedId {\n\treturn id >= 0;\n}\n\n/**\n * A StableId which is suitable for use as a session identifier\n */\nexport type NumericUuid = bigint & {\n\treadonly NumericUuid: \"be04dd4d-9d7e-4337-a833-eec64c61aa46\";\n};\n"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Exports for `id-compressor`
|
|
7
|
-
*/
|
|
8
|
-
export { IdCompressor } from "./idCompressor";
|
|
9
|
-
export { compareFiniteNumbers, createSessionId, assertIsSessionId, numericUuidFromStableId, offsetNumericUuid, stableIdFromNumericUuid, subtractNumericUuids, addNumericUuids, assertIsStableId, generateStableId, isStableId, } from "./utilities";
|
|
10
|
-
export { readNumericUuid, writeNumericUuid } from "./persistanceUtilities";
|
|
11
|
-
export { AppendOnlySortedMap } from "./appendOnlySortedMap";
|
|
12
|
-
export { SessionSpaceNormalizer } from "./sessionSpaceNormalizer";
|
|
13
|
-
//# sourceMappingURL=index.d.ts.map
|