@fluidframework/container-runtime 2.0.0-internal.6.1.1 → 2.0.0-internal.6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/README.md +4 -3
- package/dist/batchTracker.d.ts +1 -1
- package/dist/batchTracker.d.ts.map +1 -1
- package/dist/batchTracker.js +5 -4
- package/dist/batchTracker.js.map +1 -1
- package/dist/blobManager.d.ts +4 -21
- package/dist/blobManager.d.ts.map +1 -1
- package/dist/blobManager.js +119 -185
- package/dist/blobManager.js.map +1 -1
- package/dist/connectionTelemetry.d.ts.map +1 -1
- package/dist/connectionTelemetry.js +13 -12
- package/dist/connectionTelemetry.js.map +1 -1
- package/dist/containerRuntime.d.ts +99 -16
- package/dist/containerRuntime.d.ts.map +1 -1
- package/dist/containerRuntime.js +380 -242
- package/dist/containerRuntime.js.map +1 -1
- package/dist/dataStore.d.ts.map +1 -1
- package/dist/dataStore.js +4 -5
- package/dist/dataStore.js.map +1 -1
- package/dist/dataStoreContext.d.ts +2 -1
- package/dist/dataStoreContext.d.ts.map +1 -1
- package/dist/dataStoreContext.js +40 -41
- package/dist/dataStoreContext.js.map +1 -1
- package/dist/dataStoreContexts.d.ts +1 -2
- package/dist/dataStoreContexts.d.ts.map +1 -1
- package/dist/dataStoreContexts.js +7 -8
- package/dist/dataStoreContexts.js.map +1 -1
- package/dist/dataStoreRegistry.js +2 -2
- package/dist/dataStoreRegistry.js.map +1 -1
- package/dist/dataStores.d.ts.map +1 -1
- package/dist/dataStores.js +23 -25
- package/dist/dataStores.js.map +1 -1
- package/dist/deltaManagerProxyBase.d.ts +1 -1
- package/dist/deltaManagerProxyBase.js +2 -2
- package/dist/deltaManagerProxyBase.js.map +1 -1
- package/dist/deltaScheduler.js +6 -6
- package/dist/deltaScheduler.js.map +1 -1
- package/dist/error.d.ts +14 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +21 -0
- package/dist/error.js.map +1 -0
- package/dist/gc/garbageCollection.d.ts +4 -6
- package/dist/gc/garbageCollection.d.ts.map +1 -1
- package/dist/gc/garbageCollection.js +26 -25
- package/dist/gc/garbageCollection.js.map +1 -1
- package/dist/gc/gcConfigs.d.ts.map +1 -1
- package/dist/gc/gcConfigs.js +5 -3
- package/dist/gc/gcConfigs.js.map +1 -1
- package/dist/gc/gcDefinitions.d.ts +4 -2
- package/dist/gc/gcDefinitions.d.ts.map +1 -1
- package/dist/gc/gcDefinitions.js.map +1 -1
- package/dist/gc/gcHelpers.js +7 -7
- package/dist/gc/gcHelpers.js.map +1 -1
- package/dist/gc/gcSummaryStateTracker.d.ts +4 -7
- package/dist/gc/gcSummaryStateTracker.d.ts.map +1 -1
- package/dist/gc/gcSummaryStateTracker.js +15 -52
- package/dist/gc/gcSummaryStateTracker.js.map +1 -1
- package/dist/gc/gcTelemetry.d.ts.map +1 -1
- package/dist/gc/gcTelemetry.js +2 -0
- package/dist/gc/gcTelemetry.js.map +1 -1
- package/dist/gc/gcUnreferencedStateTracker.js +4 -4
- 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 +1 -2
- package/dist/gc/index.js.map +1 -1
- package/dist/id-compressor/appendOnlySortedMap.d.ts +8 -30
- package/dist/id-compressor/appendOnlySortedMap.d.ts.map +1 -1
- package/dist/id-compressor/appendOnlySortedMap.js +26 -68
- package/dist/id-compressor/appendOnlySortedMap.js.map +1 -1
- package/dist/id-compressor/finalSpace.d.ts +29 -0
- package/dist/id-compressor/finalSpace.d.ts.map +1 -0
- package/dist/id-compressor/finalSpace.js +62 -0
- package/dist/id-compressor/finalSpace.js.map +1 -0
- package/dist/id-compressor/idCompressor.d.ts +25 -250
- package/dist/id-compressor/idCompressor.d.ts.map +1 -1
- package/dist/id-compressor/idCompressor.js +387 -1150
- package/dist/id-compressor/idCompressor.js.map +1 -1
- package/dist/id-compressor/identifiers.d.ts +32 -0
- package/dist/id-compressor/identifiers.d.ts.map +1 -0
- package/dist/id-compressor/identifiers.js +15 -0
- package/dist/id-compressor/identifiers.js.map +1 -0
- package/dist/id-compressor/index.d.ts +5 -6
- package/dist/id-compressor/index.d.ts.map +1 -1
- package/dist/id-compressor/index.js +20 -26
- package/dist/id-compressor/index.js.map +1 -1
- package/dist/id-compressor/persistanceUtilities.d.ts +22 -0
- package/dist/id-compressor/persistanceUtilities.d.ts.map +1 -0
- package/dist/id-compressor/persistanceUtilities.js +43 -0
- package/dist/id-compressor/persistanceUtilities.js.map +1 -0
- package/dist/id-compressor/sessionSpaceNormalizer.d.ts +46 -0
- package/dist/id-compressor/sessionSpaceNormalizer.d.ts.map +1 -0
- package/dist/id-compressor/sessionSpaceNormalizer.js +80 -0
- package/dist/id-compressor/sessionSpaceNormalizer.js.map +1 -0
- package/dist/id-compressor/sessions.d.ts +115 -0
- package/dist/id-compressor/sessions.d.ts.map +1 -0
- package/dist/id-compressor/sessions.js +305 -0
- package/dist/id-compressor/sessions.js.map +1 -0
- package/dist/id-compressor/utilities.d.ts +49 -0
- package/dist/id-compressor/utilities.d.ts.map +1 -0
- package/dist/id-compressor/utilities.js +166 -0
- package/dist/id-compressor/utilities.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/opLifecycle/opCompressor.js +5 -5
- package/dist/opLifecycle/opCompressor.js.map +1 -1
- package/dist/opLifecycle/opDecompressor.d.ts.map +1 -1
- package/dist/opLifecycle/opDecompressor.js +11 -10
- package/dist/opLifecycle/opDecompressor.js.map +1 -1
- package/dist/opLifecycle/opGroupingManager.js +3 -3
- package/dist/opLifecycle/opGroupingManager.js.map +1 -1
- package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
- package/dist/opLifecycle/opSplitter.js +14 -15
- package/dist/opLifecycle/opSplitter.js.map +1 -1
- package/dist/opLifecycle/outbox.d.ts +1 -0
- package/dist/opLifecycle/outbox.d.ts.map +1 -1
- package/dist/opLifecycle/outbox.js +16 -17
- package/dist/opLifecycle/outbox.js.map +1 -1
- package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
- package/dist/opLifecycle/remoteMessageProcessor.js +11 -5
- package/dist/opLifecycle/remoteMessageProcessor.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 +12 -5
- package/dist/pendingStateManager.d.ts.map +1 -1
- package/dist/pendingStateManager.js +36 -23
- package/dist/pendingStateManager.js.map +1 -1
- package/dist/scheduleManager.d.ts.map +1 -1
- package/dist/scheduleManager.js +23 -23
- package/dist/scheduleManager.js.map +1 -1
- package/dist/summary/index.d.ts +3 -3
- package/dist/summary/index.d.ts.map +1 -1
- package/dist/summary/index.js +2 -1
- package/dist/summary/index.js.map +1 -1
- package/dist/summary/orderedClientElection.d.ts +2 -3
- package/dist/summary/orderedClientElection.d.ts.map +1 -1
- package/dist/summary/orderedClientElection.js +8 -8
- package/dist/summary/orderedClientElection.js.map +1 -1
- package/dist/summary/runWhileConnectedCoordinator.js +3 -3
- package/dist/summary/runWhileConnectedCoordinator.js.map +1 -1
- package/dist/summary/runningSummarizer.d.ts +27 -4
- package/dist/summary/runningSummarizer.d.ts.map +1 -1
- package/dist/summary/runningSummarizer.js +246 -74
- package/dist/summary/runningSummarizer.js.map +1 -1
- package/dist/summary/summarizer.d.ts +6 -5
- package/dist/summary/summarizer.d.ts.map +1 -1
- package/dist/summary/summarizer.js +73 -69
- package/dist/summary/summarizer.js.map +1 -1
- package/dist/summary/summarizerClientElection.d.ts +2 -2
- package/dist/summary/summarizerClientElection.d.ts.map +1 -1
- package/dist/summary/summarizerClientElection.js +2 -2
- package/dist/summary/summarizerClientElection.js.map +1 -1
- package/dist/summary/summarizerHeuristics.js +2 -2
- package/dist/summary/summarizerHeuristics.js.map +1 -1
- package/dist/summary/summarizerNode/index.d.ts +1 -1
- package/dist/summary/summarizerNode/index.d.ts.map +1 -1
- package/dist/summary/summarizerNode/index.js.map +1 -1
- package/dist/summary/summarizerNode/summarizerNode.d.ts +5 -14
- package/dist/summary/summarizerNode/summarizerNode.d.ts.map +1 -1
- package/dist/summary/summarizerNode/summarizerNode.js +32 -109
- package/dist/summary/summarizerNode/summarizerNode.js.map +1 -1
- package/dist/summary/summarizerNode/summarizerNodeUtils.d.ts +6 -30
- package/dist/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
- package/dist/summary/summarizerNode/summarizerNodeUtils.js.map +1 -1
- package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts +0 -11
- package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
- package/dist/summary/summarizerNode/summarizerNodeWithGc.js +5 -88
- package/dist/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -1
- package/dist/summary/summarizerTypes.d.ts +38 -25
- package/dist/summary/summarizerTypes.d.ts.map +1 -1
- package/dist/summary/summarizerTypes.js.map +1 -1
- package/dist/summary/summaryCollection.d.ts +2 -3
- package/dist/summary/summaryCollection.d.ts.map +1 -1
- package/dist/summary/summaryCollection.js +9 -8
- package/dist/summary/summaryCollection.js.map +1 -1
- package/dist/summary/summaryFormat.js +2 -2
- package/dist/summary/summaryFormat.js.map +1 -1
- package/dist/summary/summaryGenerator.d.ts +10 -4
- package/dist/summary/summaryGenerator.d.ts.map +1 -1
- package/dist/summary/summaryGenerator.js +52 -48
- package/dist/summary/summaryGenerator.js.map +1 -1
- package/dist/summary/summaryManager.d.ts +7 -6
- package/dist/summary/summaryManager.d.ts.map +1 -1
- package/dist/summary/summaryManager.js +30 -22
- package/dist/summary/summaryManager.js.map +1 -1
- package/lib/batchTracker.d.ts +1 -1
- package/lib/batchTracker.d.ts.map +1 -1
- package/lib/batchTracker.js +3 -2
- package/lib/batchTracker.js.map +1 -1
- package/lib/blobManager.d.ts +4 -21
- package/lib/blobManager.d.ts.map +1 -1
- package/lib/blobManager.js +91 -157
- package/lib/blobManager.js.map +1 -1
- package/lib/connectionTelemetry.d.ts.map +1 -1
- package/lib/connectionTelemetry.js +2 -1
- package/lib/connectionTelemetry.js.map +1 -1
- package/lib/containerRuntime.d.ts +99 -16
- package/lib/containerRuntime.d.ts.map +1 -1
- package/lib/containerRuntime.js +332 -192
- package/lib/containerRuntime.js.map +1 -1
- package/lib/dataStore.d.ts.map +1 -1
- package/lib/dataStore.js +2 -3
- package/lib/dataStore.js.map +1 -1
- package/lib/dataStoreContext.d.ts +2 -1
- package/lib/dataStoreContext.d.ts.map +1 -1
- package/lib/dataStoreContext.js +3 -4
- package/lib/dataStoreContext.js.map +1 -1
- package/lib/dataStoreContexts.d.ts +1 -2
- package/lib/dataStoreContexts.d.ts.map +1 -1
- package/lib/dataStoreContexts.js +1 -2
- package/lib/dataStoreContexts.js.map +1 -1
- package/lib/dataStoreRegistry.js +1 -1
- package/lib/dataStoreRegistry.js.map +1 -1
- package/lib/dataStores.d.ts.map +1 -1
- package/lib/dataStores.js +2 -4
- package/lib/dataStores.js.map +1 -1
- package/lib/deltaManagerProxyBase.d.ts +1 -1
- package/lib/deltaManagerProxyBase.js +1 -1
- package/lib/deltaManagerProxyBase.js.map +1 -1
- package/lib/deltaScheduler.js +1 -1
- package/lib/deltaScheduler.js.map +1 -1
- package/lib/error.d.ts +14 -0
- package/lib/error.d.ts.map +1 -0
- package/lib/error.js +17 -0
- package/lib/error.js.map +1 -0
- package/lib/gc/garbageCollection.d.ts +4 -6
- package/lib/gc/garbageCollection.d.ts.map +1 -1
- package/lib/gc/garbageCollection.js +26 -25
- package/lib/gc/garbageCollection.js.map +1 -1
- package/lib/gc/gcConfigs.d.ts.map +1 -1
- package/lib/gc/gcConfigs.js +3 -1
- package/lib/gc/gcConfigs.js.map +1 -1
- package/lib/gc/gcDefinitions.d.ts +4 -2
- package/lib/gc/gcDefinitions.d.ts.map +1 -1
- package/lib/gc/gcDefinitions.js.map +1 -1
- package/lib/gc/gcHelpers.js +1 -1
- package/lib/gc/gcHelpers.js.map +1 -1
- package/lib/gc/gcSummaryStateTracker.d.ts +4 -7
- package/lib/gc/gcSummaryStateTracker.d.ts.map +1 -1
- package/lib/gc/gcSummaryStateTracker.js +16 -53
- package/lib/gc/gcSummaryStateTracker.js.map +1 -1
- package/lib/gc/gcTelemetry.d.ts.map +1 -1
- package/lib/gc/gcTelemetry.js +2 -0
- package/lib/gc/gcTelemetry.js.map +1 -1
- package/lib/gc/gcUnreferencedStateTracker.js +1 -1
- 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/id-compressor/appendOnlySortedMap.d.ts +8 -30
- package/lib/id-compressor/appendOnlySortedMap.d.ts.map +1 -1
- package/lib/id-compressor/appendOnlySortedMap.js +25 -66
- package/lib/id-compressor/appendOnlySortedMap.js.map +1 -1
- package/lib/id-compressor/finalSpace.d.ts +29 -0
- package/lib/id-compressor/finalSpace.d.ts.map +1 -0
- package/lib/id-compressor/finalSpace.js +58 -0
- package/lib/id-compressor/finalSpace.js.map +1 -0
- package/lib/id-compressor/idCompressor.d.ts +25 -250
- package/lib/id-compressor/idCompressor.d.ts.map +1 -1
- package/lib/id-compressor/idCompressor.js +382 -1139
- package/lib/id-compressor/idCompressor.js.map +1 -1
- package/lib/id-compressor/identifiers.d.ts +32 -0
- package/lib/id-compressor/identifiers.d.ts.map +1 -0
- package/lib/id-compressor/identifiers.js +11 -0
- package/lib/id-compressor/identifiers.js.map +1 -0
- package/lib/id-compressor/index.d.ts +5 -6
- package/lib/id-compressor/index.d.ts.map +1 -1
- package/lib/id-compressor/index.js +5 -6
- package/lib/id-compressor/index.js.map +1 -1
- package/lib/id-compressor/persistanceUtilities.d.ts +22 -0
- package/lib/id-compressor/persistanceUtilities.d.ts.map +1 -0
- package/lib/id-compressor/persistanceUtilities.js +34 -0
- package/lib/id-compressor/persistanceUtilities.js.map +1 -0
- package/lib/id-compressor/sessionSpaceNormalizer.d.ts +46 -0
- package/lib/id-compressor/sessionSpaceNormalizer.d.ts.map +1 -0
- package/lib/id-compressor/sessionSpaceNormalizer.js +76 -0
- package/lib/id-compressor/sessionSpaceNormalizer.js.map +1 -0
- package/lib/id-compressor/sessions.d.ts +115 -0
- package/lib/id-compressor/sessions.d.ts.map +1 -0
- package/lib/id-compressor/sessions.js +290 -0
- package/lib/id-compressor/sessions.js.map +1 -0
- package/lib/id-compressor/utilities.d.ts +49 -0
- package/lib/id-compressor/utilities.d.ts.map +1 -0
- package/lib/id-compressor/utilities.js +148 -0
- package/lib/id-compressor/utilities.js.map +1 -0
- package/lib/index.d.ts +3 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/opLifecycle/opCompressor.js +3 -3
- package/lib/opLifecycle/opCompressor.js.map +1 -1
- package/lib/opLifecycle/opDecompressor.d.ts.map +1 -1
- package/lib/opLifecycle/opDecompressor.js +2 -1
- package/lib/opLifecycle/opDecompressor.js.map +1 -1
- package/lib/opLifecycle/opGroupingManager.js +1 -1
- package/lib/opLifecycle/opGroupingManager.js.map +1 -1
- package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
- package/lib/opLifecycle/opSplitter.js +2 -3
- package/lib/opLifecycle/opSplitter.js.map +1 -1
- package/lib/opLifecycle/outbox.d.ts +1 -0
- package/lib/opLifecycle/outbox.d.ts.map +1 -1
- package/lib/opLifecycle/outbox.js +7 -8
- package/lib/opLifecycle/outbox.js.map +1 -1
- package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
- package/lib/opLifecycle/remoteMessageProcessor.js +12 -6
- package/lib/opLifecycle/remoteMessageProcessor.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 +12 -5
- package/lib/pendingStateManager.d.ts.map +1 -1
- package/lib/pendingStateManager.js +21 -8
- package/lib/pendingStateManager.js.map +1 -1
- package/lib/scheduleManager.d.ts.map +1 -1
- package/lib/scheduleManager.js +3 -3
- package/lib/scheduleManager.js.map +1 -1
- package/lib/summary/index.d.ts +3 -3
- package/lib/summary/index.d.ts.map +1 -1
- package/lib/summary/index.js +1 -1
- package/lib/summary/index.js.map +1 -1
- package/lib/summary/orderedClientElection.d.ts +2 -3
- package/lib/summary/orderedClientElection.d.ts.map +1 -1
- package/lib/summary/orderedClientElection.js +3 -3
- package/lib/summary/orderedClientElection.js.map +1 -1
- package/lib/summary/runWhileConnectedCoordinator.js +1 -1
- package/lib/summary/runWhileConnectedCoordinator.js.map +1 -1
- package/lib/summary/runningSummarizer.d.ts +27 -4
- package/lib/summary/runningSummarizer.d.ts.map +1 -1
- package/lib/summary/runningSummarizer.js +240 -68
- package/lib/summary/runningSummarizer.js.map +1 -1
- package/lib/summary/summarizer.d.ts +6 -5
- package/lib/summary/summarizer.d.ts.map +1 -1
- package/lib/summary/summarizer.js +69 -65
- package/lib/summary/summarizer.js.map +1 -1
- package/lib/summary/summarizerClientElection.d.ts +2 -2
- package/lib/summary/summarizerClientElection.d.ts.map +1 -1
- package/lib/summary/summarizerClientElection.js +1 -1
- package/lib/summary/summarizerClientElection.js.map +1 -1
- package/lib/summary/summarizerHeuristics.js +1 -1
- package/lib/summary/summarizerHeuristics.js.map +1 -1
- package/lib/summary/summarizerNode/index.d.ts +1 -1
- package/lib/summary/summarizerNode/index.d.ts.map +1 -1
- package/lib/summary/summarizerNode/index.js.map +1 -1
- package/lib/summary/summarizerNode/summarizerNode.d.ts +5 -14
- package/lib/summary/summarizerNode/summarizerNode.d.ts.map +1 -1
- package/lib/summary/summarizerNode/summarizerNode.js +16 -93
- package/lib/summary/summarizerNode/summarizerNode.js.map +1 -1
- package/lib/summary/summarizerNode/summarizerNodeUtils.d.ts +6 -30
- package/lib/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
- package/lib/summary/summarizerNode/summarizerNodeUtils.js.map +1 -1
- package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts +0 -11
- package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
- package/lib/summary/summarizerNode/summarizerNodeWithGc.js +3 -86
- package/lib/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -1
- package/lib/summary/summarizerTypes.d.ts +38 -25
- package/lib/summary/summarizerTypes.d.ts.map +1 -1
- package/lib/summary/summarizerTypes.js.map +1 -1
- package/lib/summary/summaryCollection.d.ts +2 -3
- package/lib/summary/summaryCollection.d.ts.map +1 -1
- package/lib/summary/summaryCollection.js +2 -1
- package/lib/summary/summaryCollection.js.map +1 -1
- package/lib/summary/summaryFormat.js +1 -1
- package/lib/summary/summaryFormat.js.map +1 -1
- package/lib/summary/summaryGenerator.d.ts +10 -4
- package/lib/summary/summaryGenerator.d.ts.map +1 -1
- package/lib/summary/summaryGenerator.js +46 -42
- package/lib/summary/summaryGenerator.js.map +1 -1
- package/lib/summary/summaryManager.d.ts +7 -6
- package/lib/summary/summaryManager.d.ts.map +1 -1
- package/lib/summary/summaryManager.js +26 -18
- package/lib/summary/summaryManager.js.map +1 -1
- package/package.json +30 -29
- package/src/batchTracker.ts +3 -2
- package/src/blobManager.ts +105 -185
- package/src/connectionTelemetry.ts +2 -1
- package/src/containerRuntime.ts +481 -267
- package/src/dataStore.ts +2 -3
- package/src/dataStoreContext.ts +5 -8
- package/src/dataStoreContexts.ts +2 -4
- package/src/dataStoreRegistry.ts +1 -1
- package/src/dataStores.ts +4 -7
- package/src/deltaManagerProxyBase.ts +1 -1
- package/src/deltaScheduler.ts +1 -1
- package/src/error.ts +18 -0
- package/src/gc/garbageCollection.ts +39 -41
- package/src/gc/gcConfigs.ts +4 -2
- package/src/gc/gcDefinitions.ts +4 -6
- package/src/gc/gcHelpers.ts +1 -1
- package/src/gc/gcSummaryStateTracker.ts +19 -65
- package/src/gc/gcTelemetry.ts +2 -0
- package/src/gc/gcUnreferencedStateTracker.ts +1 -1
- package/src/gc/index.ts +0 -1
- package/src/id-compressor/appendOnlySortedMap.ts +26 -87
- package/src/id-compressor/finalSpace.ts +67 -0
- package/src/id-compressor/idCompressor.ts +456 -1681
- package/src/id-compressor/identifiers.ts +42 -0
- package/src/id-compressor/index.ts +11 -20
- package/src/id-compressor/persistanceUtilities.ts +58 -0
- package/src/id-compressor/sessionSpaceNormalizer.ts +83 -0
- package/src/id-compressor/sessions.ts +405 -0
- package/src/id-compressor/utilities.ts +187 -0
- package/src/index.ts +7 -1
- package/src/opLifecycle/opCompressor.ts +3 -3
- package/src/opLifecycle/opDecompressor.ts +2 -1
- package/src/opLifecycle/opGroupingManager.ts +1 -1
- package/src/opLifecycle/opSplitter.ts +4 -4
- package/src/opLifecycle/outbox.ts +14 -11
- package/src/opLifecycle/remoteMessageProcessor.ts +19 -6
- package/src/packageVersion.ts +1 -1
- package/src/pendingStateManager.ts +50 -29
- package/src/scheduleManager.ts +6 -4
- package/src/summary/index.ts +4 -3
- package/src/summary/orderedClientElection.ts +8 -5
- package/src/summary/runWhileConnectedCoordinator.ts +1 -1
- package/src/summary/runningSummarizer.ts +273 -97
- package/src/summary/summarizer.ts +23 -12
- package/src/summary/summarizerClientElection.ts +2 -2
- package/src/summary/summarizerHeuristics.ts +1 -1
- package/src/summary/summarizerNode/index.ts +1 -2
- package/src/summary/summarizerNode/summarizerNode.ts +23 -145
- package/src/summary/summarizerNode/summarizerNodeUtils.ts +7 -38
- package/src/summary/summarizerNode/summarizerNodeWithGc.ts +3 -123
- package/src/summary/summarizerTypes.ts +40 -25
- package/src/summary/summaryCollection.ts +3 -3
- package/src/summary/summaryFormat.ts +1 -1
- package/src/summary/summaryGenerator.ts +52 -55
- package/src/summary/summaryManager.ts +36 -13
- package/dist/id-compressor/idRange.d.ts +0 -11
- package/dist/id-compressor/idRange.d.ts.map +0 -1
- package/dist/id-compressor/idRange.js +0 -29
- package/dist/id-compressor/idRange.js.map +0 -1
- package/dist/id-compressor/numericUuid.d.ts +0 -59
- package/dist/id-compressor/numericUuid.d.ts.map +0 -1
- package/dist/id-compressor/numericUuid.js +0 -325
- package/dist/id-compressor/numericUuid.js.map +0 -1
- package/dist/id-compressor/sessionIdNormalizer.d.ts +0 -138
- package/dist/id-compressor/sessionIdNormalizer.d.ts.map +0 -1
- package/dist/id-compressor/sessionIdNormalizer.js +0 -483
- package/dist/id-compressor/sessionIdNormalizer.js.map +0 -1
- package/dist/id-compressor/utils.d.ts +0 -57
- package/dist/id-compressor/utils.d.ts.map +0 -1
- package/dist/id-compressor/utils.js +0 -90
- package/dist/id-compressor/utils.js.map +0 -1
- package/dist/id-compressor/uuidUtilities.d.ts +0 -28
- package/dist/id-compressor/uuidUtilities.d.ts.map +0 -1
- package/dist/id-compressor/uuidUtilities.js +0 -104
- package/dist/id-compressor/uuidUtilities.js.map +0 -1
- package/lib/id-compressor/idRange.d.ts +0 -11
- package/lib/id-compressor/idRange.d.ts.map +0 -1
- package/lib/id-compressor/idRange.js +0 -25
- package/lib/id-compressor/idRange.js.map +0 -1
- package/lib/id-compressor/numericUuid.d.ts +0 -59
- package/lib/id-compressor/numericUuid.d.ts.map +0 -1
- package/lib/id-compressor/numericUuid.js +0 -315
- package/lib/id-compressor/numericUuid.js.map +0 -1
- package/lib/id-compressor/sessionIdNormalizer.d.ts +0 -138
- package/lib/id-compressor/sessionIdNormalizer.d.ts.map +0 -1
- package/lib/id-compressor/sessionIdNormalizer.js +0 -479
- package/lib/id-compressor/sessionIdNormalizer.js.map +0 -1
- package/lib/id-compressor/utils.d.ts +0 -57
- package/lib/id-compressor/utils.d.ts.map +0 -1
- package/lib/id-compressor/utils.js +0 -79
- package/lib/id-compressor/utils.js.map +0 -1
- package/lib/id-compressor/uuidUtilities.d.ts +0 -28
- package/lib/id-compressor/uuidUtilities.d.ts.map +0 -1
- package/lib/id-compressor/uuidUtilities.js +0 -96
- package/lib/id-compressor/uuidUtilities.js.map +0 -1
- package/src/id-compressor/idRange.ts +0 -35
- package/src/id-compressor/numericUuid.ts +0 -383
- package/src/id-compressor/sessionIdNormalizer.ts +0 -609
- package/src/id-compressor/utils.ts +0 -114
- package/src/id-compressor/uuidUtilities.ts +0 -120
|
@@ -3,112 +3,81 @@
|
|
|
3
3
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
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");
|
|
14
11
|
const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
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");
|
|
21
18
|
/**
|
|
22
|
-
*
|
|
23
|
-
* This
|
|
19
|
+
* The version of IdCompressor that is currently persisted.
|
|
20
|
+
* This should not be changed without careful consideration to compatibility.
|
|
24
21
|
*/
|
|
25
|
-
|
|
22
|
+
const currentWrittenVersion = 1;
|
|
26
23
|
/**
|
|
27
|
-
*
|
|
28
|
-
* This should not be changed without consideration to compatibility.
|
|
29
|
-
*/
|
|
30
|
-
const reservedSessionId = (0, numericUuid_1.ensureSessionUuid)((0, uuidUtilities_1.assertIsStableId)("decaf40b-3c1a-47f8-a7a1-e8461ddb69ce"));
|
|
31
|
-
/**
|
|
32
|
-
* @returns true if the supplied ID is a final ID.
|
|
33
|
-
*/
|
|
34
|
-
function isFinalId(id) {
|
|
35
|
-
return id >= 0;
|
|
36
|
-
}
|
|
37
|
-
exports.isFinalId = isFinalId;
|
|
38
|
-
/**
|
|
39
|
-
* @returns true if the supplied ID is a local ID.
|
|
40
|
-
*/
|
|
41
|
-
function isLocalId(id) {
|
|
42
|
-
return id < 0;
|
|
43
|
-
}
|
|
44
|
-
exports.isLocalId = isLocalId;
|
|
45
|
-
/** Prepended to all keys in {@link IdCompressor.clustersAndOverridesInversion} that are override strings and not valid `StableIds` */
|
|
46
|
-
const nonStableOverridePrefix = "\ue15e"; // A character in the Private Use Area of the BMP (https://en.wikipedia.org/wiki/Private_Use_Areas)
|
|
47
|
-
/**
|
|
48
|
-
* See {@link IIdCompressor}
|
|
24
|
+
* See {@link IIdCompressor} and {@link IIdCompressorCore}
|
|
49
25
|
*/
|
|
50
26
|
class IdCompressor {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
this.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Maps the first final ID in a cluster to its owning cluster.
|
|
107
|
-
* Can be searched in O(log n) to determine clusters for any final ID.
|
|
108
|
-
*/
|
|
109
|
-
this.finalIdToCluster = new appendOnlySortedMap_1.AppendOnlySortedMap(utils_1.compareFiniteNumbers);
|
|
110
|
-
this.localSession = this.createSession(localSessionId);
|
|
111
|
-
this.logger = (0, telemetry_utils_1.createChildLogger)({ logger });
|
|
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;
|
|
112
81
|
}
|
|
113
82
|
/**
|
|
114
83
|
* The size of each newly created ID cluster.
|
|
@@ -121,184 +90,77 @@ class IdCompressor {
|
|
|
121
90
|
* `IdCompressor.maxClusterSize`.
|
|
122
91
|
*/
|
|
123
92
|
set clusterCapacity(value) {
|
|
124
|
-
|
|
125
|
-
|
|
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
|
+
}
|
|
126
99
|
this.newClusterCapacity = value;
|
|
127
100
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return
|
|
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);
|
|
148
128
|
}
|
|
149
|
-
/**
|
|
150
|
-
* Returns a range of local IDs created by this session in a format for sending to the server for finalizing.
|
|
151
|
-
* The range will include all local IDs generated via calls to `generateCompressedId` since the last time this method was called.
|
|
152
|
-
* @returns the range of session-local IDs, which may be empty. This range must be sent to the server for ordering before
|
|
153
|
-
* it is finalized. Ranges must be sent to the server in the order that they are taken via calls to this method.
|
|
154
|
-
*/
|
|
155
129
|
takeNextCreationRange() {
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const firstLocalInRange = (lastTakenNormalized - 1);
|
|
162
|
-
const overrides = [
|
|
163
|
-
...this.localOverrides.getRange((lastTakenNormalized - 1), lastLocalInRange),
|
|
164
|
-
];
|
|
165
|
-
if ((0, utils_1.hasAtLeastLength)(overrides, 1)) {
|
|
166
|
-
(0, common_utils_1.assert)(overrides[0][0] <= firstLocalInRange, 0x486 /* Inconsistent override state */);
|
|
167
|
-
(0, common_utils_1.assert)(overrides[overrides.length - 1][0] >= lastLocalInRange, 0x487 /* Inconsistent override state */);
|
|
168
|
-
ids = {
|
|
169
|
-
overrides,
|
|
170
|
-
};
|
|
171
|
-
const first = firstLocalInRange === overrides[0][0] ? undefined : firstLocalInRange;
|
|
172
|
-
const last = lastLocalInRange === overrides[overrides.length - 1][0]
|
|
173
|
-
? undefined
|
|
174
|
-
: lastLocalInRange;
|
|
175
|
-
(0, utils_1.setPropertyIfDefined)(first, ids, "first");
|
|
176
|
-
(0, utils_1.setPropertyIfDefined)(last, ids, "last");
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
ids = {
|
|
180
|
-
first: firstLocalInRange,
|
|
181
|
-
last: lastLocalInRange,
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
this.lastTakenLocalId = lastLocalInRange;
|
|
185
|
-
}
|
|
186
|
-
const range = { sessionId: this.localSessionId };
|
|
187
|
-
if (ids === undefined) {
|
|
188
|
-
return range;
|
|
130
|
+
const count = this.localGenCount - (this.nextRangeBaseGenCount - 1);
|
|
131
|
+
if (count === 0) {
|
|
132
|
+
return {
|
|
133
|
+
sessionId: this.localSessionId,
|
|
134
|
+
};
|
|
189
135
|
}
|
|
190
|
-
|
|
191
|
-
this.
|
|
192
|
-
|
|
136
|
+
const range = {
|
|
137
|
+
sessionId: this.localSessionId,
|
|
138
|
+
ids: {
|
|
139
|
+
firstGenCount: this.nextRangeBaseGenCount,
|
|
140
|
+
count,
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
this.nextRangeBaseGenCount = this.localGenCount + 1;
|
|
193
144
|
return range;
|
|
194
145
|
}
|
|
195
|
-
/**
|
|
196
|
-
* Finalizes the supplied range of IDs (which may be from either a remote or local session).
|
|
197
|
-
* @param range - the range of session-local IDs to finalize.
|
|
198
|
-
*/
|
|
199
146
|
finalizeCreationRange(range) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const session = this.sessions.get(sessionId) ?? this.createSession(sessionId);
|
|
203
|
-
const ids = (0, idRange_1.getIds)(range);
|
|
204
|
-
if (ids === undefined) {
|
|
147
|
+
// Check if the range has IDs
|
|
148
|
+
if (range.ids === undefined) {
|
|
205
149
|
return;
|
|
206
150
|
}
|
|
207
|
-
|
|
208
|
-
const {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
let initialClusterCount = 0;
|
|
221
|
-
let remainingCount = finalizeCount;
|
|
222
|
-
let newBaseUuid;
|
|
223
|
-
if (currentClusterExists) {
|
|
224
|
-
if (isLocal) {
|
|
225
|
-
const lastKnownFinal = this.sessionIdNormalizer.getLastFinalId() ??
|
|
226
|
-
(0, utils_1.fail)("Cluster exists but normalizer does not have an entry for it.");
|
|
227
|
-
const lastAlignedFinalInCluster = (currentBaseFinalId +
|
|
228
|
-
Math.min(currentCluster.count + finalizeCount, currentCluster.capacity) -
|
|
229
|
-
1);
|
|
230
|
-
if (lastAlignedFinalInCluster > lastKnownFinal) {
|
|
231
|
-
this.sessionIdNormalizer.addFinalIds((lastKnownFinal + 1), lastAlignedFinalInCluster, currentCluster);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
initialClusterCount = currentCluster.count;
|
|
235
|
-
const remainingCapacity = currentCluster.capacity - initialClusterCount;
|
|
236
|
-
const overflow = remainingCount - remainingCapacity;
|
|
237
|
-
const hasRoom = overflow <= 0;
|
|
238
|
-
if (hasRoom || currentBaseFinalId === this.finalIdToCluster.maxKey()) {
|
|
239
|
-
currentCluster.count += remainingCount;
|
|
240
|
-
eagerFinalIdCount = remainingCount;
|
|
241
|
-
remainingCount = 0;
|
|
242
|
-
// The common case is that there is room in the cluster, and the new final IDs can simply be added to it
|
|
243
|
-
if (!hasRoom) {
|
|
244
|
-
// The cluster is full but is the last in the list of clusters.
|
|
245
|
-
// This allows it to be expanded instead of allocating a new one.
|
|
246
|
-
const expansionAmount = this.newClusterCapacity + overflow;
|
|
247
|
-
const previousCapacity = currentCluster.capacity;
|
|
248
|
-
currentCluster.capacity += expansionAmount;
|
|
249
|
-
this.nextClusterBaseFinalId = (this.nextClusterBaseFinalId +
|
|
250
|
-
expansionAmount);
|
|
251
|
-
(0, common_utils_1.assert)(this.nextClusterBaseFinalId < Number.MAX_SAFE_INTEGER, 0x48b /* The number of allocated final IDs must not exceed the JS maximum safe integer. */);
|
|
252
|
-
this.checkClusterForCollision(currentCluster);
|
|
253
|
-
if (isLocal) {
|
|
254
|
-
// Example with cluster size of 3:
|
|
255
|
-
// Ids generated so far: -1 1 2 -4 -5 <-- note positive numbers are eager finals
|
|
256
|
-
// Cluster: [ 0 1 2 ]
|
|
257
|
-
// ~ finalizing happens, causing expansion of 2 (overflow) + 3 (cluster capacity) ~
|
|
258
|
-
// Cluster: [ 0 1 2 3 4 _ _ _ ]
|
|
259
|
-
// corresponding locals: -1 -4 -5
|
|
260
|
-
// lastFinalizedLocalId^ ^newLastFinalizedLocalId = -5
|
|
261
|
-
// overflow = 2: ----
|
|
262
|
-
// localIdPivot^
|
|
263
|
-
// lastFinalizedFinal^
|
|
264
|
-
const newLastFinalizedFinal = (currentBaseFinalId +
|
|
265
|
-
currentCluster.count -
|
|
266
|
-
1);
|
|
267
|
-
(0, common_utils_1.assert)(session.lastFinalizedLocalId !== undefined, 0x48c /* Cluster already exists for session but there is no finalized local ID */);
|
|
268
|
-
const finalPivot = (newLastFinalizedFinal -
|
|
269
|
-
overflow +
|
|
270
|
-
1);
|
|
271
|
-
// Inform the normalizer of all IDs that we now know will end up being finalized into this cluster, including the ones
|
|
272
|
-
// that were given out as locals (non-eager) because they exceeded the bounds of the current cluster before it was expanded.
|
|
273
|
-
// It is safe to associate the unfinalized locals with their future final IDs even before the ranges for those locals are
|
|
274
|
-
// actually finalized, because total order broadcast guarantees that any usage of those final IDs will be observed after
|
|
275
|
-
// the finalization of the ranges.
|
|
276
|
-
this.sessionIdNormalizer.registerFinalIdBlock(finalPivot, expansionAmount, currentCluster);
|
|
277
|
-
this.logger?.sendTelemetryEvent({
|
|
278
|
-
eventName: "RuntimeIdCompressor:ClusterExpansion",
|
|
279
|
-
sessionId: this.localSessionId,
|
|
280
|
-
previousCapacity,
|
|
281
|
-
newCapacity: currentCluster.capacity,
|
|
282
|
-
overflow,
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
// The range cannot be fully allocated in the existing cluster, so allocate any space left in it and
|
|
289
|
-
// form a new one by incrementing the previous baseUuid
|
|
290
|
-
newBaseUuid = (0, numericUuid_1.incrementUuid)(currentCluster.baseUuid, currentCluster.capacity);
|
|
291
|
-
currentCluster.count += remainingCapacity;
|
|
292
|
-
remainingCount -= remainingCapacity;
|
|
293
|
-
this.logger?.sendTelemetryEvent({
|
|
294
|
-
eventName: "RuntimeIdCompressor:OverfilledCluster",
|
|
295
|
-
sessionId: this.localSessionId,
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
// Session has never made a cluster, form a new one with the session UUID as the baseUuid
|
|
301
|
-
newBaseUuid = session.sessionUuid;
|
|
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);
|
|
302
164
|
if (isLocal) {
|
|
303
165
|
this.logger?.sendTelemetryEvent({
|
|
304
166
|
eventName: "RuntimeIdCompressor:FirstCluster",
|
|
@@ -306,953 +168,328 @@ class IdCompressor {
|
|
|
306
168
|
});
|
|
307
169
|
}
|
|
308
170
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
// 2. All local IDs are finalized into the existing (current) cluster for the session.
|
|
313
|
-
// 3. Local IDs are finalized into both the current cluster and a new one, as the current cluster did not have enough room.
|
|
314
|
-
let newCluster;
|
|
315
|
-
let newBaseFinalId;
|
|
316
|
-
// The first local ID that will be finalized into a new cluster, if there is one.
|
|
317
|
-
// This lets us quickly compare which cluster an override string will go into.
|
|
318
|
-
let localIdPivot;
|
|
319
|
-
// Need to make a new cluster
|
|
320
|
-
if (newBaseUuid !== undefined) {
|
|
321
|
-
if (remainingCount <= 0) {
|
|
322
|
-
(0, utils_1.fail)("Should not create an empty cluster.");
|
|
323
|
-
}
|
|
324
|
-
if (currentCluster !== undefined && currentCluster.capacity !== currentCluster.count) {
|
|
325
|
-
(0, utils_1.fail)("Cluster must be filled before another is allocated.");
|
|
326
|
-
}
|
|
327
|
-
newBaseFinalId = this.nextClusterBaseFinalId;
|
|
328
|
-
const newCapacity = Math.max(this.newClusterCapacity, remainingCount);
|
|
329
|
-
newCluster = {
|
|
330
|
-
baseUuid: newBaseUuid,
|
|
331
|
-
capacity: newCapacity,
|
|
332
|
-
count: remainingCount,
|
|
333
|
-
session,
|
|
334
|
-
};
|
|
335
|
-
const usedCapacity = finalizeCount - remainingCount;
|
|
336
|
-
localIdPivot = (newFirstFinalizedLocal - usedCapacity);
|
|
337
|
-
if (isLocal) {
|
|
338
|
-
this.logger?.sendTelemetryEvent({
|
|
339
|
-
eventName: "RuntimeIdCompressor:NewCluster",
|
|
340
|
-
sessionId: this.localSessionId,
|
|
341
|
-
clusterCapacity: newCapacity,
|
|
342
|
-
clusterCount: remainingCount,
|
|
343
|
-
});
|
|
344
|
-
this.sessionIdNormalizer.registerFinalIdBlock(newBaseFinalId, newCluster.capacity, newCluster);
|
|
345
|
-
}
|
|
346
|
-
this.checkClusterForCollision(newCluster);
|
|
347
|
-
this.clustersAndOverridesInversion.set((0, numericUuid_1.stableIdFromNumericUuid)(newCluster.baseUuid), {
|
|
348
|
-
clusterBase: newBaseFinalId,
|
|
349
|
-
cluster: newCluster,
|
|
350
|
-
});
|
|
351
|
-
session.currentClusterDetails = { cluster: newCluster, clusterBase: newBaseFinalId };
|
|
352
|
-
this.nextClusterBaseFinalId = (this.nextClusterBaseFinalId +
|
|
353
|
-
newCluster.capacity);
|
|
354
|
-
(0, common_utils_1.assert)(this.nextClusterBaseFinalId < Number.MAX_SAFE_INTEGER, 0x48e /* The number of allocated final IDs must not exceed the JS maximum safe integer. */);
|
|
355
|
-
this.finalIdToCluster.append(newBaseFinalId, newCluster);
|
|
171
|
+
const remainingCapacity = lastCluster.capacity - lastCluster.count;
|
|
172
|
+
if (lastCluster.baseLocalId - lastCluster.count !== rangeBaseLocal) {
|
|
173
|
+
throw new Error("Ranges finalized out of order.");
|
|
356
174
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
(0, common_utils_1.assert)(currentCluster !== undefined && currentBaseFinalId !== undefined, 0x493 /* No cluster exists but IDs were finalized. */);
|
|
378
|
-
cluster = currentCluster;
|
|
379
|
-
overriddenFinal = (currentBaseFinalId +
|
|
380
|
-
initialClusterCount +
|
|
381
|
-
(normalizedLastFinalizedLocal - overriddenLocal) -
|
|
382
|
-
1);
|
|
383
|
-
}
|
|
384
|
-
cluster.overrides ?? (cluster.overrides = new Map());
|
|
385
|
-
const inversionKey = IdCompressor.createInversionKey(override);
|
|
386
|
-
const existingIds = this.getExistingIdsForNewOverride(inversionKey, true);
|
|
387
|
-
let overrideForCluster;
|
|
388
|
-
let associatedLocal;
|
|
389
|
-
if (existingIds !== undefined) {
|
|
390
|
-
let mostFinalExistingOverride;
|
|
391
|
-
if (typeof existingIds === "number") {
|
|
392
|
-
mostFinalExistingOverride = existingIds;
|
|
393
|
-
if (isLocalId(mostFinalExistingOverride)) {
|
|
394
|
-
associatedLocal = mostFinalExistingOverride;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
else {
|
|
398
|
-
[associatedLocal, mostFinalExistingOverride] = existingIds;
|
|
399
|
-
}
|
|
400
|
-
if (isFinalId(mostFinalExistingOverride)) {
|
|
401
|
-
// A previous range already finalized an ID with this override. See `IdCluster` for more.
|
|
402
|
-
overrideForCluster = mostFinalExistingOverride;
|
|
403
|
-
}
|
|
404
|
-
else {
|
|
405
|
-
(0, common_utils_1.assert)(!isLocal || mostFinalExistingOverride === overriddenLocal, 0x494 /* Cannot have multiple local IDs with identical overrides. */);
|
|
406
|
-
// This session has created an ID with this override before, but has not finalized it yet. The incoming
|
|
407
|
-
// range "wins" and will contain the final ID associated with that override, regardless of if that range was
|
|
408
|
-
// made by this session or not.
|
|
409
|
-
overrideForCluster = override;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
else {
|
|
413
|
-
// This is the first time this override has been associated with any ID
|
|
414
|
-
overrideForCluster = override;
|
|
415
|
-
}
|
|
416
|
-
(0, common_utils_1.assert)(!cluster.overrides.has(overriddenFinal), 0x495 /* Cannot add a second override for final id */);
|
|
417
|
-
if (typeof overrideForCluster === "string") {
|
|
418
|
-
if (isLocal || associatedLocal === undefined) {
|
|
419
|
-
cluster.overrides.set(overriddenFinal, override);
|
|
420
|
-
}
|
|
421
|
-
else {
|
|
422
|
-
cluster.overrides.set(overriddenFinal, {
|
|
423
|
-
override,
|
|
424
|
-
originalOverridingFinal: overriddenFinal,
|
|
425
|
-
associatedLocalId: associatedLocal,
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
else {
|
|
430
|
-
const unifiedOverride = {
|
|
431
|
-
override,
|
|
432
|
-
originalOverridingFinal: overrideForCluster,
|
|
433
|
-
};
|
|
434
|
-
(0, utils_1.setPropertyIfDefined)(associatedLocal, unifiedOverride, "associatedLocalId");
|
|
435
|
-
cluster.overrides.set(overriddenFinal, unifiedOverride);
|
|
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
|
+
});
|
|
436
195
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
if (
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
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
|
+
});
|
|
448
207
|
}
|
|
449
208
|
}
|
|
450
209
|
}
|
|
451
210
|
if (isLocal) {
|
|
452
211
|
this.logger?.sendTelemetryEvent({
|
|
453
212
|
eventName: "RuntimeIdCompressor:IdCompressorStatus",
|
|
454
|
-
eagerFinalIdCount:
|
|
455
|
-
localIdCount:
|
|
456
|
-
overridesCount: overrides?.length ?? 0,
|
|
213
|
+
eagerFinalIdCount: this.telemetryEagerFinalIdCount,
|
|
214
|
+
localIdCount: this.telemetryLocalIdCount,
|
|
457
215
|
sessionId: this.localSessionId,
|
|
458
216
|
});
|
|
217
|
+
this.telemetryEagerFinalIdCount = 0;
|
|
218
|
+
this.telemetryLocalIdCount = 0;
|
|
459
219
|
}
|
|
460
|
-
session.
|
|
461
|
-
}
|
|
462
|
-
checkClusterForCollision(cluster) {
|
|
463
|
-
const maxClusterUuid = (0, numericUuid_1.incrementUuid)(cluster.baseUuid, cluster.capacity - 1);
|
|
464
|
-
const maxClusterStableId = (0, numericUuid_1.stableIdFromNumericUuid)(maxClusterUuid);
|
|
465
|
-
const closestMatch = this.clustersAndOverridesInversion.getPairOrNextLower(maxClusterStableId);
|
|
466
|
-
if (closestMatch !== undefined) {
|
|
467
|
-
const [inversionKey, compressionMapping] = closestMatch;
|
|
468
|
-
if (!IdCompressor.isClusterInfo(compressionMapping)) {
|
|
469
|
-
if ((0, uuidUtilities_1.isStableId)(inversionKey) &&
|
|
470
|
-
IdCompressor.uuidsMightCollide(inversionKey, maxClusterStableId, cluster.capacity)) {
|
|
471
|
-
const numericOverride = (0, numericUuid_1.numericUuidFromStableId)(inversionKey);
|
|
472
|
-
const delta = (0, numericUuid_1.getPositiveDelta)(maxClusterUuid, numericOverride, cluster.capacity - 1);
|
|
473
|
-
if (delta !== undefined) {
|
|
474
|
-
IdCompressor.failWithCollidingOverride(inversionKey);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
static failWithCollidingOverride(override) {
|
|
481
|
-
(0, utils_1.fail)(`Override '${override}' collides with another allocated UUID.`);
|
|
482
|
-
}
|
|
483
|
-
static isClusterInfo(compressionMapping) {
|
|
484
|
-
return compressionMapping.clusterBase !== undefined;
|
|
485
|
-
}
|
|
486
|
-
static isUnfinalizedOverride(compressionMapping) {
|
|
487
|
-
return typeof compressionMapping === "number";
|
|
488
|
-
}
|
|
489
|
-
static createInversionKey(inversionKey) {
|
|
490
|
-
return (0, uuidUtilities_1.isStableId)(inversionKey)
|
|
491
|
-
? inversionKey
|
|
492
|
-
: `${nonStableOverridePrefix}${inversionKey}`;
|
|
493
|
-
}
|
|
494
|
-
static isStableInversionKey(inversionKey) {
|
|
495
|
-
return inversionKey.charAt(0) !== nonStableOverridePrefix;
|
|
496
|
-
}
|
|
497
|
-
/**
|
|
498
|
-
* Returns an existing ID associated with an override, or undefined if none exists.
|
|
499
|
-
*/
|
|
500
|
-
getExistingIdsForNewOverride(inversionKey, isFinalOverride) {
|
|
501
|
-
const closestMatch = this.clustersAndOverridesInversion.getPairOrNextLower(inversionKey, reusedArray);
|
|
502
|
-
let numericOverride;
|
|
503
|
-
let stableOverride;
|
|
504
|
-
if (closestMatch !== undefined) {
|
|
505
|
-
const [key, compressionMapping] = closestMatch;
|
|
506
|
-
if (!IdCompressor.isClusterInfo(compressionMapping)) {
|
|
507
|
-
if (key === inversionKey) {
|
|
508
|
-
if (IdCompressor.isUnfinalizedOverride(compressionMapping)) {
|
|
509
|
-
return compressionMapping;
|
|
510
|
-
}
|
|
511
|
-
const finalizedOverride = compressionMapping;
|
|
512
|
-
return finalizedOverride.associatedLocalId !== undefined
|
|
513
|
-
? [
|
|
514
|
-
finalizedOverride.associatedLocalId,
|
|
515
|
-
finalizedOverride.originalOverridingFinal,
|
|
516
|
-
]
|
|
517
|
-
: finalizedOverride.originalOverridingFinal;
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
else if (IdCompressor.isStableInversionKey(inversionKey)) {
|
|
521
|
-
stableOverride = inversionKey;
|
|
522
|
-
const cluster = compressionMapping.cluster;
|
|
523
|
-
if (IdCompressor.uuidsMightCollide(inversionKey, key, cluster.capacity)) {
|
|
524
|
-
numericOverride = (0, numericUuid_1.numericUuidFromStableId)(stableOverride);
|
|
525
|
-
const delta = (0, numericUuid_1.getPositiveDelta)(numericOverride, cluster.baseUuid, cluster.capacity - 1);
|
|
526
|
-
if (delta !== undefined) {
|
|
527
|
-
if (!isFinalOverride) {
|
|
528
|
-
if (delta >= cluster.count) {
|
|
529
|
-
// TODO:#283: Properly implement unification
|
|
530
|
-
return undefined;
|
|
531
|
-
}
|
|
532
|
-
return this.normalizeToSessionSpace((compressionMapping.clusterBase + delta));
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
const override = numericOverride ??
|
|
539
|
-
stableOverride ??
|
|
540
|
-
(IdCompressor.isStableInversionKey(inversionKey) ? inversionKey : undefined);
|
|
541
|
-
if (override !== undefined) {
|
|
542
|
-
const sessionSpaceId = this.getCompressedIdForStableId(override);
|
|
543
|
-
if (sessionSpaceId !== undefined) {
|
|
544
|
-
return sessionSpaceId;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
return undefined;
|
|
220
|
+
(0, core_utils_1.assert)(!session.isEmpty(), 0x757 /* Empty sessions should not be created. */);
|
|
548
221
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
// Check if any of the UUIDs in the cluster collide (i.e. any in [base, base + capacity)).
|
|
555
|
-
// Optimization: All UUIDs in a cluster are the same string up until the last few characters which encode the offset from
|
|
556
|
-
// the cluster base. So, first compute the length of that shared string, and early out if it is different from the override
|
|
557
|
-
// UUID. This way we usually need not do the more expensive check below.
|
|
558
|
-
const hexDigitsToCheck = 32 - Math.ceil(Math.log2(range) / 2);
|
|
559
|
-
if (a.startsWith(b.slice(0, hexDigitsToCheck))) {
|
|
560
|
-
return true;
|
|
561
|
-
}
|
|
562
|
-
return false;
|
|
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;
|
|
563
227
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
static tryGetOverride(cluster, finalId) {
|
|
568
|
-
const override = cluster.overrides?.get(finalId);
|
|
569
|
-
if (override === undefined) {
|
|
570
|
-
return undefined;
|
|
571
|
-
}
|
|
572
|
-
if (typeof override === "string") {
|
|
573
|
-
return override;
|
|
574
|
-
}
|
|
575
|
-
return override.override;
|
|
576
|
-
}
|
|
577
|
-
/**
|
|
578
|
-
* Generates a new compressed ID or returns an existing one.
|
|
579
|
-
* This should ONLY be called to generate IDs for local operations.
|
|
580
|
-
* @param override - Specifies a specific string to be associated with the returned compressed ID.
|
|
581
|
-
* Performance note: assigning override strings incurs a performance overhead.
|
|
582
|
-
* @returns an existing ID if one already exists for `override`, and a new local ID otherwise. The returned ID is in session space.
|
|
583
|
-
*/
|
|
584
|
-
generateCompressedId(override) {
|
|
585
|
-
let overrideInversionKey;
|
|
586
|
-
if (override !== undefined) {
|
|
587
|
-
overrideInversionKey = IdCompressor.createInversionKey(override);
|
|
588
|
-
const existingIds = this.getExistingIdsForNewOverride(overrideInversionKey, false);
|
|
589
|
-
if (existingIds !== undefined) {
|
|
590
|
-
return typeof existingIds === "number" ? existingIds : existingIds[0];
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
// Bump local counter regardless, then attempt to optimistically return a final ID.
|
|
594
|
-
// If the local session has reserved a cluster range via consensus, it is safe to hand out final IDs prior to
|
|
595
|
-
// finalizing the range that includes these locals.
|
|
596
|
-
const newLocalId = -++this.localIdCount;
|
|
597
|
-
const { currentClusterDetails } = this.localSession;
|
|
598
|
-
const { sessionIdNormalizer } = this;
|
|
599
|
-
let eagerFinalId;
|
|
600
|
-
let cluster;
|
|
601
|
-
if (currentClusterDetails !== undefined) {
|
|
602
|
-
cluster = currentClusterDetails.cluster;
|
|
603
|
-
const lastFinalKnown = sessionIdNormalizer.getLastFinalId();
|
|
604
|
-
if (lastFinalKnown !== undefined &&
|
|
605
|
-
lastFinalKnown - currentClusterDetails.clusterBase + 1 < cluster.capacity) {
|
|
606
|
-
eagerFinalId = (lastFinalKnown + 1);
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
if (overrideInversionKey !== undefined) {
|
|
610
|
-
const registeredLocal = sessionIdNormalizer.addLocalId();
|
|
611
|
-
(0, common_utils_1.assert)(registeredLocal === newLocalId, 0x496 /* Session ID Normalizer produced unexpected local ID */);
|
|
612
|
-
if (eagerFinalId !== undefined) {
|
|
613
|
-
sessionIdNormalizer.addFinalIds(eagerFinalId, eagerFinalId, cluster ?? (0, utils_1.fail)("No cluster when generating compressed ID"));
|
|
614
|
-
}
|
|
615
|
-
this.localOverrides.append(newLocalId, override ?? (0, utils_1.fail)("Override must be defined"));
|
|
616
|
-
// Since the local ID was just created, it is in both session and op space
|
|
617
|
-
const compressionMapping = newLocalId;
|
|
618
|
-
this.clustersAndOverridesInversion.set(overrideInversionKey, compressionMapping);
|
|
619
|
-
}
|
|
620
|
-
else if (eagerFinalId !== undefined) {
|
|
621
|
-
sessionIdNormalizer.addFinalIds(eagerFinalId, eagerFinalId, cluster ?? (0, utils_1.fail)("No cluster when generating compressed ID"));
|
|
622
|
-
return eagerFinalId;
|
|
228
|
+
normalizeToOpSpace(id) {
|
|
229
|
+
if ((0, identifiers_1.isFinalId)(id)) {
|
|
230
|
+
return id;
|
|
623
231
|
}
|
|
624
232
|
else {
|
|
625
|
-
const
|
|
626
|
-
(
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
*/
|
|
643
|
-
tryDecompress(id) {
|
|
644
|
-
if (isFinalId(id)) {
|
|
645
|
-
const possibleCluster = this.getClusterForFinalId(id);
|
|
646
|
-
if (possibleCluster === undefined) {
|
|
647
|
-
// It may be an unfinalized eager final ID, so check with normalizer to get the offset from the session UUID
|
|
648
|
-
const creationIndex = this.sessionIdNormalizer.getCreationIndex(id);
|
|
649
|
-
if (creationIndex !== undefined) {
|
|
650
|
-
return (0, numericUuid_1.stableIdFromNumericUuid)(this.localSession.sessionUuid, creationIndex);
|
|
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.");
|
|
651
250
|
}
|
|
652
|
-
return
|
|
251
|
+
return id;
|
|
653
252
|
}
|
|
654
253
|
else {
|
|
655
|
-
const
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
return override;
|
|
254
|
+
const alignedLocal = (0, sessions_1.getAlignedLocal)(containingCluster, id);
|
|
255
|
+
if (this.normalizer.contains(alignedLocal)) {
|
|
256
|
+
return alignedLocal;
|
|
659
257
|
}
|
|
660
258
|
else {
|
|
661
|
-
|
|
662
|
-
|
|
259
|
+
if ((0, utilities_1.genCountFromLocalId)(alignedLocal) > this.localGenCount) {
|
|
260
|
+
throw new Error("Unknown op space ID.");
|
|
261
|
+
}
|
|
262
|
+
return id;
|
|
663
263
|
}
|
|
664
264
|
}
|
|
665
265
|
}
|
|
666
266
|
else {
|
|
667
|
-
const
|
|
668
|
-
if (
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
const localOverride = this.localOverrides?.get(id);
|
|
676
|
-
return localOverride !== undefined
|
|
677
|
-
? localOverride
|
|
678
|
-
: (0, numericUuid_1.stableIdFromNumericUuid)(this.localSession.sessionUuid, idOffset - 1);
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
/**
|
|
682
|
-
* Recompresses a decompressed ID, which could be a UUID or an override string.
|
|
683
|
-
* @param uncompressed - the UUID or override string to recompress.
|
|
684
|
-
* @returns the `CompressedId` associated with `uncompressed`. Fails if it has not been previously compressed by this compressor.
|
|
685
|
-
*/
|
|
686
|
-
recompress(uncompressed) {
|
|
687
|
-
return this.tryRecompress(uncompressed) ?? (0, utils_1.fail)("No such string has ever been compressed");
|
|
688
|
-
}
|
|
689
|
-
/**
|
|
690
|
-
* Attempts to recompresses a decompressed ID, which could be a UUID or an override string.
|
|
691
|
-
* @param uncompressed - the UUID or override string to recompress,
|
|
692
|
-
* @returns the `CompressedId` associated with `uncompressed` or undefined if it has not been previously compressed by this compressor.
|
|
693
|
-
*/
|
|
694
|
-
tryRecompress(uncompressed) {
|
|
695
|
-
return this.recompressInternal(uncompressed);
|
|
696
|
-
}
|
|
697
|
-
/**
|
|
698
|
-
* Helper to compress an uncompressed UUID. It can optionally be supplied with the numeric form of `uncompressedUuid` as a
|
|
699
|
-
* performance optimization.
|
|
700
|
-
*/
|
|
701
|
-
recompressInternal(uncompressed, uncompressedUuidNumeric) {
|
|
702
|
-
let numericUuid = uncompressedUuidNumeric;
|
|
703
|
-
const inversionKey = IdCompressor.createInversionKey(uncompressed);
|
|
704
|
-
const isStable = IdCompressor.isStableInversionKey(inversionKey);
|
|
705
|
-
const closestMatch = this.clustersAndOverridesInversion.getPairOrNextLower(inversionKey, reusedArray);
|
|
706
|
-
if (closestMatch !== undefined) {
|
|
707
|
-
const [key, compressionMapping] = closestMatch;
|
|
708
|
-
if (!IdCompressor.isClusterInfo(compressionMapping)) {
|
|
709
|
-
if (key === inversionKey) {
|
|
710
|
-
return IdCompressor.isUnfinalizedOverride(compressionMapping)
|
|
711
|
-
? compressionMapping
|
|
712
|
-
: compressionMapping.associatedLocalId ??
|
|
713
|
-
compressionMapping.originalOverridingFinal;
|
|
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.");
|
|
714
275
|
}
|
|
715
276
|
}
|
|
716
277
|
else {
|
|
717
|
-
|
|
718
|
-
|
|
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.");
|
|
719
282
|
}
|
|
720
|
-
const
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
if (uuidOffset !== undefined) {
|
|
724
|
-
let targetFinalId = (closestBaseFinalId + uuidOffset);
|
|
725
|
-
const override = closestCluster.overrides?.get(targetFinalId);
|
|
726
|
-
if (typeof override === "object") {
|
|
727
|
-
if (override.associatedLocalId !== undefined) {
|
|
728
|
-
return override.associatedLocalId;
|
|
729
|
-
}
|
|
730
|
-
// This may be a UUID that should actually compress into a different final ID that it aligns with, due to
|
|
731
|
-
// another session having an identical override (see `IdCluster` for more).
|
|
732
|
-
targetFinalId = override.originalOverridingFinal;
|
|
733
|
-
}
|
|
734
|
-
return this.normalizeToSessionSpace(targetFinalId);
|
|
283
|
+
const correspondingFinal = remoteSession.tryConvertToFinal(localToNormalize, false);
|
|
284
|
+
if (correspondingFinal === undefined) {
|
|
285
|
+
throw new Error("Unknown op space ID.");
|
|
735
286
|
}
|
|
287
|
+
return correspondingFinal;
|
|
736
288
|
}
|
|
737
289
|
}
|
|
738
|
-
if (isStable) {
|
|
739
|
-
// May have already computed the numeric UUID, so avoid recomputing if possible
|
|
740
|
-
const sessionSpaceId = this.getCompressedIdForStableId(numericUuid ?? inversionKey);
|
|
741
|
-
if (sessionSpaceId !== undefined) {
|
|
742
|
-
return sessionSpaceId;
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
return undefined;
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* Normalizes a session space ID into op space.
|
|
749
|
-
* @param id - the local ID to normalize.
|
|
750
|
-
* @returns the ID in op space.
|
|
751
|
-
*/
|
|
752
|
-
normalizeToOpSpace(id) {
|
|
753
|
-
if (isFinalId(id)) {
|
|
754
|
-
return id;
|
|
755
|
-
}
|
|
756
|
-
// Check if this local ID has not been allocated yet
|
|
757
|
-
if (-id > this.localIdCount) {
|
|
758
|
-
(0, utils_1.fail)("Supplied local ID was not created by this compressor.");
|
|
759
|
-
}
|
|
760
|
-
// Check if this local ID has not been finalized yet.
|
|
761
|
-
// Comparing lastFinalizedLocalId is a safe check for eager final IDs because the local IDs corresponding to them
|
|
762
|
-
// are never handed out to a consumer, and thus could not be passed into this method.
|
|
763
|
-
const { lastFinalizedLocalId } = this.localSession;
|
|
764
|
-
if (lastFinalizedLocalId === undefined || id < lastFinalizedLocalId) {
|
|
765
|
-
// Eager final IDs do not have overrides in the cluster until finalizing
|
|
766
|
-
// This means that using the normalizer to get the final/cluster associated would succeed but would not have the override,
|
|
767
|
-
// so checking localOverrides first is necessary.
|
|
768
|
-
const override = this.localOverrides.get(id);
|
|
769
|
-
if (override !== undefined) {
|
|
770
|
-
const inversionKey = IdCompressor.createInversionKey(override);
|
|
771
|
-
const compressionMapping = this.clustersAndOverridesInversion.get(inversionKey) ??
|
|
772
|
-
(0, utils_1.fail)("Bimap is malformed.");
|
|
773
|
-
return !IdCompressor.isClusterInfo(compressionMapping) &&
|
|
774
|
-
!IdCompressor.isUnfinalizedOverride(compressionMapping) &&
|
|
775
|
-
compressionMapping.associatedLocalId === id
|
|
776
|
-
? compressionMapping.originalOverridingFinal
|
|
777
|
-
: id;
|
|
778
|
-
}
|
|
779
|
-
const possibleFinal = this.sessionIdNormalizer.getFinalId(id);
|
|
780
|
-
return possibleFinal?.[0] ?? id;
|
|
781
|
-
}
|
|
782
|
-
const [correspondingFinal, cluster] = this.sessionIdNormalizer.getFinalId(id) ??
|
|
783
|
-
(0, utils_1.fail)("Locally created cluster should be added to the map when allocated");
|
|
784
|
-
if (cluster.overrides) {
|
|
785
|
-
const override = cluster.overrides.get(correspondingFinal);
|
|
786
|
-
if (typeof override === "object" && override.originalOverridingFinal !== undefined) {
|
|
787
|
-
// Rare case of two local IDs with same overrides are created concurrently. See `IdCluster` for more.
|
|
788
|
-
return override.originalOverridingFinal;
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
return correspondingFinal;
|
|
792
290
|
}
|
|
793
|
-
|
|
794
|
-
if (
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
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");
|
|
799
307
|
}
|
|
800
|
-
return id;
|
|
801
|
-
}
|
|
802
|
-
else {
|
|
803
|
-
const session = this.sessions.get(sessionIdIfLocal) ??
|
|
804
|
-
(0, utils_1.fail)("No IDs have ever been finalized by the supplied session.");
|
|
805
|
-
const localCount = -id;
|
|
806
|
-
const numericUuid = (0, numericUuid_1.incrementUuid)(session.sessionUuid, localCount - 1);
|
|
807
|
-
return (this.compressNumericUuid(numericUuid) ??
|
|
808
|
-
(0, utils_1.fail)("ID is not known to this compressor."));
|
|
809
308
|
}
|
|
309
|
+
return (0, utilities_1.stableIdFromNumericUuid)((0, utilities_1.offsetNumericUuid)(containingCluster.session.sessionUuid, alignedGenCount - 1));
|
|
810
310
|
}
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
// Check for a unified override finalized first by another session but to which the local session
|
|
816
|
-
// still has an associated local ID.
|
|
817
|
-
const [_, cluster] = this.getClusterForFinalId(id) ??
|
|
818
|
-
(0, utils_1.fail)("Supplied final ID was not finalized by this compressor.");
|
|
819
|
-
const override = cluster.overrides?.get(id);
|
|
820
|
-
if (typeof override === "object" && override.associatedLocalId !== undefined) {
|
|
821
|
-
return override.associatedLocalId;
|
|
822
|
-
}
|
|
823
|
-
return id;
|
|
824
|
-
}
|
|
825
|
-
/**
|
|
826
|
-
* Returns the session-space compressed ID corresponding to the numeric UUID, or undefined if it is not known to this compressor.
|
|
827
|
-
* Typically, it will return the session-space ID sequentially aligned with it (which will be local if `numericUuid` was made by
|
|
828
|
-
* the local session, or final otherwise). However, in the event that the aligned session-space ID was overridden with a UUID
|
|
829
|
-
* *and* that override UUID was concurrently used in an older ID (earlier, w.r.t. sequencing), this method can return the first
|
|
830
|
-
* ID to correspond to that override.
|
|
831
|
-
*
|
|
832
|
-
* As an example, consider the following two clients:
|
|
833
|
-
* ClientA, session UUID: A0000000-0000-0000-0000-000000000000
|
|
834
|
-
* ClientB, session UUID: B0000000-0000-0000-0000-000000000000
|
|
835
|
-
*
|
|
836
|
-
* If concurrently, two clients performed:
|
|
837
|
-
* ClientA: generateCompressedId(override: 'X0000000-0000-0000-0000-000000000000') // aligned with A0000000-0000-0000-0000-000000000000
|
|
838
|
-
*
|
|
839
|
-
* ClientB: generateCompressedId() // aligned with B0000000-0000-0000-0000-000000000000
|
|
840
|
-
* ClientB: generateCompressedId(override: 'X0000000-0000-0000-0000-000000000000') // aligned with B0000000-0000-0000-0000-000000000001
|
|
841
|
-
*
|
|
842
|
-
* After sequencing, calling this method and passing the numeric UUID for B0000000-0000-0000-0000-000000000001 would return the
|
|
843
|
-
* session-space ID corresponding to A0000000-0000-0000-0000-000000000000 (with override X0000000-0000-0000-0000-000000000000).
|
|
844
|
-
*/
|
|
845
|
-
compressNumericUuid(numericUuid) {
|
|
846
|
-
const stableId = (0, numericUuid_1.stableIdFromNumericUuid)(numericUuid);
|
|
847
|
-
const sessionSpaceId = this.recompressInternal(stableId, numericUuid);
|
|
848
|
-
if (sessionSpaceId === undefined) {
|
|
849
|
-
return undefined;
|
|
850
|
-
}
|
|
851
|
-
return sessionSpaceId;
|
|
852
|
-
}
|
|
853
|
-
/**
|
|
854
|
-
* Returns a compressed ID for the supplied stable ID if it was created by the local session, and undefined otherwise.
|
|
855
|
-
*/
|
|
856
|
-
getCompressedIdForStableId(stableId) {
|
|
857
|
-
const numericUuid = typeof stableId === "string" ? (0, numericUuid_1.numericUuidFromStableId)(stableId) : stableId;
|
|
858
|
-
const creationIndex = (0, numericUuid_1.getPositiveDelta)(numericUuid, this.localSession.sessionUuid, this.localIdCount - 1);
|
|
859
|
-
if (creationIndex !== undefined) {
|
|
860
|
-
const sessionSpaceId = this.sessionIdNormalizer.getIdByCreationIndex(creationIndex);
|
|
861
|
-
if (sessionSpaceId !== undefined) {
|
|
862
|
-
return sessionSpaceId;
|
|
311
|
+
else {
|
|
312
|
+
const localToDecompress = id;
|
|
313
|
+
if (!this.normalizer.contains(localToDecompress)) {
|
|
314
|
+
throw new Error("Unknown ID");
|
|
863
315
|
}
|
|
316
|
+
return (0, utilities_1.stableIdFromNumericUuid)((0, utilities_1.offsetNumericUuid)(this.localSession.sessionUuid, (0, utilities_1.genCountFromLocalId)(localToDecompress) - 1));
|
|
864
317
|
}
|
|
865
|
-
return undefined;
|
|
866
318
|
}
|
|
867
|
-
|
|
868
|
-
const
|
|
869
|
-
if (
|
|
870
|
-
|
|
871
|
-
}
|
|
872
|
-
const [clusterBase, cluster] = possibleCluster;
|
|
873
|
-
if (finalId - clusterBase >= cluster.count) {
|
|
874
|
-
return undefined;
|
|
319
|
+
recompress(uncompressed) {
|
|
320
|
+
const recompressed = this.tryRecompress(uncompressed);
|
|
321
|
+
if (recompressed === undefined) {
|
|
322
|
+
throw new Error("Could not recompress.");
|
|
875
323
|
}
|
|
876
|
-
return
|
|
324
|
+
return recompressed;
|
|
877
325
|
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
this.
|
|
887
|
-
|
|
888
|
-
}
|
|
889
|
-
if (!this.localOverrides.equals(other.localOverrides, (a, b) => a === b)) {
|
|
890
|
-
return false;
|
|
891
|
-
}
|
|
892
|
-
if (!(0, utils_1.compareMaps)(this.sessions, other.sessions, (a, b) => IdCompressor.sessionDataEqual(a, b, true, compareLocalState))) {
|
|
893
|
-
return false;
|
|
894
|
-
}
|
|
895
|
-
if (!this.sessionIdNormalizer.equals(other.sessionIdNormalizer, (a, b) => IdCompressor.idClustersEqual(a, b, false, compareLocalState))) {
|
|
896
|
-
return false;
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
else {
|
|
900
|
-
for (const [keyA, valueA] of this.sessions) {
|
|
901
|
-
const valueB = other.sessions.get(keyA);
|
|
902
|
-
if (valueB === undefined) {
|
|
903
|
-
if (valueA.lastFinalizedLocalId !== undefined) {
|
|
904
|
-
return false;
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
else if (!IdCompressor.sessionDataEqual(valueA, valueB, true, compareLocalState)) {
|
|
908
|
-
return false;
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
for (const [keyB, valueB] of other.sessions) {
|
|
912
|
-
const valueA = this.sessions.get(keyB);
|
|
913
|
-
if (valueA === undefined) {
|
|
914
|
-
if (valueB.lastFinalizedLocalId !== undefined) {
|
|
915
|
-
return false;
|
|
916
|
-
}
|
|
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;
|
|
917
336
|
}
|
|
918
337
|
}
|
|
338
|
+
return undefined;
|
|
919
339
|
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
}
|
|
927
|
-
const missingInOne = (_, value) => {
|
|
928
|
-
if (!compareLocalState && IdCompressor.isUnfinalizedOverride(value)) {
|
|
929
|
-
return undefined;
|
|
930
|
-
}
|
|
931
|
-
return { break: true };
|
|
932
|
-
};
|
|
933
|
-
const compareCompressionMappings = (a, b) => {
|
|
934
|
-
const unfinalizedA = IdCompressor.isUnfinalizedOverride(a);
|
|
935
|
-
const unfinalizedB = IdCompressor.isUnfinalizedOverride(b);
|
|
936
|
-
if (unfinalizedA) {
|
|
937
|
-
if (unfinalizedB) {
|
|
938
|
-
return a === b;
|
|
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;
|
|
939
346
|
}
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
}
|
|
945
|
-
if (IdCompressor.isClusterInfo(a)) {
|
|
946
|
-
if (!IdCompressor.isClusterInfo(b) || a.clusterBase !== b.clusterBase) {
|
|
947
|
-
return false;
|
|
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);
|
|
948
351
|
}
|
|
949
352
|
}
|
|
950
353
|
else {
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
const
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
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);
|
|
967
402
|
});
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
if (a.currentClusterDetails === undefined || b.currentClusterDetails === undefined) {
|
|
976
|
-
if (a.currentClusterDetails !== b.currentClusterDetails) {
|
|
977
|
-
return false;
|
|
978
|
-
}
|
|
979
|
-
return true;
|
|
980
|
-
}
|
|
981
|
-
if (checkCluster &&
|
|
982
|
-
!IdCompressor.idClustersEqual(a.currentClusterDetails.cluster, b.currentClusterDetails.cluster, false, compareLocalState)) {
|
|
983
|
-
return false;
|
|
984
|
-
}
|
|
985
|
-
return true;
|
|
986
|
-
}
|
|
987
|
-
static idClustersEqual(a, b, checkSessionData = true, compareLocalState = true) {
|
|
988
|
-
const areEqual = (0, numericUuid_1.numericUuidEquals)(a.baseUuid, b.baseUuid) &&
|
|
989
|
-
a.capacity === b.capacity &&
|
|
990
|
-
a.count === b.count &&
|
|
991
|
-
(!checkSessionData ||
|
|
992
|
-
IdCompressor.sessionDataEqual(a.session, b.session, false, compareLocalState)) &&
|
|
993
|
-
(a.overrides === undefined) === (b.overrides === undefined) &&
|
|
994
|
-
(a.overrides === undefined ||
|
|
995
|
-
(0, utils_1.compareMaps)(a.overrides ?? (0, utils_1.fail)("Overrides must be defined"), b.overrides ?? (0, utils_1.fail)("Overrides must be defined"), (overrideA, overrideB) => {
|
|
996
|
-
if (compareLocalState) {
|
|
997
|
-
if (typeof overrideA === "string" || typeof overrideB === "string") {
|
|
998
|
-
return overrideA === overrideB;
|
|
999
|
-
}
|
|
1000
|
-
const overridesEqual = overrideA.override === overrideB.override &&
|
|
1001
|
-
overrideA.originalOverridingFinal ===
|
|
1002
|
-
overrideB.originalOverridingFinal &&
|
|
1003
|
-
(!compareLocalState ||
|
|
1004
|
-
overrideA.associatedLocalId === overrideB.associatedLocalId);
|
|
1005
|
-
return overridesEqual;
|
|
1006
|
-
}
|
|
1007
|
-
const uuidA = typeof overrideA === "string" ? overrideA : overrideA.override;
|
|
1008
|
-
const uuidB = typeof overrideB === "string" ? overrideB : overrideB.override;
|
|
1009
|
-
if (typeof overrideA !== "string" &&
|
|
1010
|
-
typeof overrideB !== "string" &&
|
|
1011
|
-
overrideA.originalOverridingFinal !== overrideB.originalOverridingFinal) {
|
|
1012
|
-
return false;
|
|
1013
|
-
}
|
|
1014
|
-
return uuidA === uuidB;
|
|
1015
|
-
}));
|
|
1016
|
-
return areEqual;
|
|
1017
|
-
}
|
|
1018
|
-
serialize(withSession) {
|
|
1019
|
-
const serializedSessions = [];
|
|
1020
|
-
const sessionIdToSessionIndex = new Map();
|
|
1021
|
-
for (const [sessionId, session] of this.sessions) {
|
|
1022
|
-
const isLocalSession = sessionId === this.localSessionId;
|
|
1023
|
-
const includeSession = sessionId !== reservedSessionId && // Ignore reserved clusters, but
|
|
1024
|
-
(session.lastFinalizedLocalId !== undefined || // always serialize sessions that made final IDs,
|
|
1025
|
-
(isLocalSession && withSession)); // include the un-acked local session if requested
|
|
1026
|
-
if (includeSession) {
|
|
1027
|
-
const sessionData = [sessionId];
|
|
1028
|
-
sessionIdToSessionIndex.set(sessionId, serializedSessions.length);
|
|
1029
|
-
serializedSessions.push(sessionData);
|
|
1030
|
-
}
|
|
1031
|
-
}
|
|
1032
|
-
const serializedClusters = [];
|
|
1033
|
-
for (const [baseFinalId, cluster] of this.finalIdToCluster.entries()) {
|
|
1034
|
-
const sessionId = (0, numericUuid_1.stableIdFromNumericUuid)(cluster.session.sessionUuid);
|
|
1035
|
-
if (sessionId !== reservedSessionId) {
|
|
1036
|
-
const sessionIndex = sessionIdToSessionIndex.get(sessionId) ??
|
|
1037
|
-
(0, utils_1.fail)("Session object contains wrong session numeric UUID");
|
|
1038
|
-
const serializedCluster = [
|
|
1039
|
-
sessionIndex,
|
|
1040
|
-
cluster.capacity,
|
|
1041
|
-
];
|
|
1042
|
-
if (cluster.count !== cluster.capacity) {
|
|
1043
|
-
serializedCluster.push(cluster.count);
|
|
1044
|
-
}
|
|
1045
|
-
if (cluster.overrides !== undefined) {
|
|
1046
|
-
const serializedOverrides = [];
|
|
1047
|
-
for (const [finalId, override] of cluster.overrides) {
|
|
1048
|
-
const finalIdIndex = finalId - baseFinalId;
|
|
1049
|
-
if (typeof override === "string") {
|
|
1050
|
-
serializedOverrides.push([finalIdIndex, override]);
|
|
1051
|
-
}
|
|
1052
|
-
else if (override.originalOverridingFinal === finalId) {
|
|
1053
|
-
serializedOverrides.push([finalIdIndex, override.override]);
|
|
1054
|
-
}
|
|
1055
|
-
else {
|
|
1056
|
-
serializedOverrides.push([
|
|
1057
|
-
finalIdIndex,
|
|
1058
|
-
override.override,
|
|
1059
|
-
override.originalOverridingFinal,
|
|
1060
|
-
]);
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
serializedCluster.push(serializedOverrides);
|
|
1064
|
-
}
|
|
1065
|
-
serializedClusters.push(serializedCluster);
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
// Reserved session not serialized, and local session is present but may not make IDs
|
|
1069
|
-
(0, common_utils_1.assert)(serializedSessions.length - this.sessions.size <= 2, 0x498 /* session not serialized */);
|
|
1070
|
-
const serializedIdCompressor = {
|
|
1071
|
-
version: currentWrittenVersion,
|
|
1072
|
-
clusterCapacity: this.clusterCapacity,
|
|
1073
|
-
sessions: serializedSessions,
|
|
1074
|
-
clusters: serializedClusters,
|
|
1075
|
-
};
|
|
1076
|
-
if (withSession) {
|
|
1077
|
-
const serializedWithSession = serializedIdCompressor;
|
|
1078
|
-
serializedWithSession.localSessionIndex = serializedWithSession.sessions.findIndex(([sessionId]) => sessionId === this.localSessionId);
|
|
1079
|
-
if (this.localIdCount > 0) {
|
|
1080
|
-
serializedWithSession.localState = {
|
|
1081
|
-
localIdCount: this.localIdCount,
|
|
1082
|
-
overrides: [...this.localOverrides.entries()].map((entry) => [...entry]),
|
|
1083
|
-
lastTakenLocalId: this.lastTakenLocalId,
|
|
1084
|
-
sessionNormalizer: this.sessionIdNormalizer.serialize(),
|
|
1085
|
-
};
|
|
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);
|
|
1086
410
|
}
|
|
1087
|
-
return serializedWithSession;
|
|
1088
411
|
}
|
|
412
|
+
(0, core_utils_1.assert)(index === totalSize, 0x75b /* Serialized size was incorrectly calculated. */);
|
|
1089
413
|
this.logger?.sendTelemetryEvent({
|
|
1090
414
|
eventName: "RuntimeIdCompressor:SerializedIdCompressorSize",
|
|
1091
|
-
size:
|
|
1092
|
-
clusterCount:
|
|
1093
|
-
sessionCount:
|
|
415
|
+
size: serializedFloat.byteLength,
|
|
416
|
+
clusterCount: finalSpace.clusters.length,
|
|
417
|
+
sessionCount: sessionIndexMap.size,
|
|
1094
418
|
});
|
|
1095
|
-
return
|
|
1096
|
-
}
|
|
1097
|
-
static deserialize(
|
|
1098
|
-
const
|
|
1099
|
-
const
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
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;
|
|
1108
443
|
}
|
|
1109
444
|
else {
|
|
1110
|
-
|
|
445
|
+
(0, core_utils_1.assert)(sessionId === undefined, 0x75e /* Local state should not exist in serialized form. */);
|
|
1111
446
|
}
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
if (serializedLocalState !== undefined) {
|
|
1116
|
-
// Do this part of local rehydration first since the cluster map population needs to query to local overrides
|
|
1117
|
-
compressor.localIdCount = serializedLocalState.localIdCount;
|
|
1118
|
-
compressor.lastTakenLocalId = serializedLocalState.lastTakenLocalId;
|
|
1119
|
-
if (serializedLocalState.overrides !== undefined) {
|
|
1120
|
-
for (const [localId, override] of serializedLocalState.overrides) {
|
|
1121
|
-
compressor.localOverrides.append(localId, override);
|
|
1122
|
-
localOverridesInverse.set(override, localId);
|
|
1123
|
-
compressor.clustersAndOverridesInversion.set(IdCompressor.createInversionKey(override), localId);
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
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)]);
|
|
1126
450
|
}
|
|
1127
|
-
const
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
const
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
const lastFinalizedNormalized = lastFinalizedLocalId ?? 0;
|
|
1151
|
-
const clusterBase = compressor.nextClusterBaseFinalId;
|
|
1152
|
-
session.lastFinalizedLocalId = (lastFinalizedNormalized - count);
|
|
1153
|
-
session.currentClusterDetails = { clusterBase, cluster };
|
|
1154
|
-
compressor.nextClusterBaseFinalId = (compressor.nextClusterBaseFinalId +
|
|
1155
|
-
capacity);
|
|
1156
|
-
compressor.finalIdToCluster.append(clusterBase, cluster);
|
|
1157
|
-
compressor.clustersAndOverridesInversion.set((0, numericUuid_1.stableIdFromNumericUuid)(cluster.baseUuid), {
|
|
1158
|
-
clusterBase,
|
|
1159
|
-
cluster,
|
|
1160
|
-
});
|
|
1161
|
-
if (overrides !== undefined) {
|
|
1162
|
-
cluster.overrides = new Map();
|
|
1163
|
-
for (const [finalIdIndex, override, originalOverridingFinal] of overrides) {
|
|
1164
|
-
const finalId = (clusterBase + finalIdIndex);
|
|
1165
|
-
if (originalOverridingFinal !== undefined) {
|
|
1166
|
-
const unifiedOverride = {
|
|
1167
|
-
override,
|
|
1168
|
-
originalOverridingFinal,
|
|
1169
|
-
};
|
|
1170
|
-
if (serializedLocalState !== undefined) {
|
|
1171
|
-
(0, utils_1.setPropertyIfDefined)(localOverridesInverse.get(override), unifiedOverride, "associatedLocalId");
|
|
1172
|
-
}
|
|
1173
|
-
cluster.overrides.set(finalId, unifiedOverride);
|
|
1174
|
-
}
|
|
1175
|
-
else {
|
|
1176
|
-
const associatedLocal = localOverridesInverse.get(override);
|
|
1177
|
-
if (associatedLocal !== undefined && sessionId !== localSessionId) {
|
|
1178
|
-
// In this case, there is a local ID associated with this override, but this is the first cluster to contain
|
|
1179
|
-
// that override (because only the first cluster will have the string serialized). In this case, the override
|
|
1180
|
-
// needs to hold that local value.
|
|
1181
|
-
cluster.overrides.set(finalId, {
|
|
1182
|
-
override,
|
|
1183
|
-
originalOverridingFinal: finalId,
|
|
1184
|
-
associatedLocalId: associatedLocal,
|
|
1185
|
-
});
|
|
1186
|
-
}
|
|
1187
|
-
else {
|
|
1188
|
-
cluster.overrides.set(finalId, override);
|
|
1189
|
-
}
|
|
1190
|
-
const finalizedOverride = {
|
|
1191
|
-
cluster,
|
|
1192
|
-
originalOverridingFinal: finalId,
|
|
1193
|
-
};
|
|
1194
|
-
if (serializedLocalState !== undefined) {
|
|
1195
|
-
(0, utils_1.setPropertyIfDefined)(associatedLocal, finalizedOverride, "associatedLocalId");
|
|
1196
|
-
}
|
|
1197
|
-
compressor.clustersAndOverridesInversion.set(IdCompressor.createInversionKey(override), finalizedOverride);
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
if (serializedLocalState !== undefined) {
|
|
1203
|
-
compressor.sessionIdNormalizer = sessionIdNormalizer_1.SessionIdNormalizer.deserialize(serializedLocalState.sessionNormalizer, (finalId) => {
|
|
1204
|
-
const [_, cluster] = compressor.finalIdToCluster.getPairOrNextLower(finalId) ??
|
|
1205
|
-
(0, utils_1.fail)("Final in serialized normalizer was never created.");
|
|
1206
|
-
return cluster;
|
|
1207
|
-
});
|
|
1208
|
-
}
|
|
1209
|
-
(0, common_utils_1.assert)(compressor.localSession.lastFinalizedLocalId === undefined ||
|
|
1210
|
-
compressor.localIdCount >= -compressor.localSession.lastFinalizedLocalId, 0x49a /* Inconsistent last finalized state when deserializing */);
|
|
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. */);
|
|
1211
474
|
return compressor;
|
|
1212
475
|
}
|
|
1213
|
-
|
|
1214
|
-
if (
|
|
1215
|
-
(
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
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;
|
|
1220
484
|
}
|
|
1221
|
-
return
|
|
485
|
+
return (this.newClusterCapacity === other.newClusterCapacity &&
|
|
486
|
+
this.sessions.equals(other.sessions, includeLocalState) &&
|
|
487
|
+
this.finalSpace.equals(other.finalSpace));
|
|
1222
488
|
}
|
|
1223
489
|
}
|
|
1224
490
|
exports.IdCompressor = IdCompressor;
|
|
1225
491
|
/**
|
|
1226
|
-
* Max allowed cluster size
|
|
492
|
+
* Max allowed initial cluster size.
|
|
1227
493
|
*/
|
|
1228
494
|
IdCompressor.maxClusterSize = 2 ** 20;
|
|
1229
|
-
/**
|
|
1230
|
-
* The version of `IdCompressor` that is currently persisted.
|
|
1231
|
-
*/
|
|
1232
|
-
const currentWrittenVersion = "0.0.1";
|
|
1233
|
-
/**
|
|
1234
|
-
* @returns whether or not the given serialized ID compressor has an ongoing session.
|
|
1235
|
-
*/
|
|
1236
|
-
function hasOngoingSession(serialized) {
|
|
1237
|
-
return (serialized.localSessionIndex !==
|
|
1238
|
-
undefined);
|
|
1239
|
-
}
|
|
1240
|
-
exports.hasOngoingSession = hasOngoingSession;
|
|
1241
|
-
function deserializeCluster(serializedCluster) {
|
|
1242
|
-
const [sessionIndex, capacity, countOrOverrides, overrides] = serializedCluster;
|
|
1243
|
-
const hasCount = typeof countOrOverrides === "number";
|
|
1244
|
-
return {
|
|
1245
|
-
sessionIndex,
|
|
1246
|
-
capacity,
|
|
1247
|
-
count: hasCount ? countOrOverrides : capacity,
|
|
1248
|
-
overrides: hasCount ? overrides : countOrOverrides,
|
|
1249
|
-
};
|
|
1250
|
-
}
|
|
1251
|
-
/**
|
|
1252
|
-
* Optimization used by the sorted-btree library to avoid allocating tuples every time a lookup method is called.
|
|
1253
|
-
* Lookup methods on BTree accept a pre-allocated array that it populates with the result of the lookup and retains no ownership
|
|
1254
|
-
* of after the call, so this array may be supplied to any of them. References to this array should not be retained elsewhere and
|
|
1255
|
-
* lookup results should be extracted from the tuple immediately after invocation.
|
|
1256
|
-
*/
|
|
1257
|
-
const reusedArray = [];
|
|
1258
495
|
//# sourceMappingURL=idCompressor.js.map
|