@fluidframework/container-runtime 2.0.0-internal.7.2.2 → 2.0.0-internal.7.4.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 +22 -0
- package/README.md +1 -2
- package/api-extractor-lint.json +13 -0
- package/api-extractor.json +9 -1
- package/api-report/container-runtime.api.md +124 -107
- package/dist/batchTracker.d.ts +1 -0
- package/dist/batchTracker.d.ts.map +1 -1
- package/dist/blobManager.d.ts +4 -4
- package/dist/blobManager.d.ts.map +1 -1
- package/dist/blobManager.js.map +1 -1
- package/dist/connectionTelemetry.js +1 -1
- package/dist/connectionTelemetry.js.map +1 -1
- package/dist/container-runtime-alpha.d.ts +1473 -0
- package/dist/container-runtime-beta.d.ts +300 -0
- package/dist/container-runtime-public.d.ts +300 -0
- package/dist/container-runtime-untrimmed.d.ts +1836 -0
- package/dist/containerRuntime.d.ts +34 -40
- package/dist/containerRuntime.d.ts.map +1 -1
- package/dist/containerRuntime.js +79 -67
- package/dist/containerRuntime.js.map +1 -1
- package/dist/dataStoreRegistry.d.ts +1 -1
- package/dist/dataStoreRegistry.js +1 -1
- package/dist/dataStoreRegistry.js.map +1 -1
- package/dist/dataStores.d.ts +10 -15
- package/dist/dataStores.d.ts.map +1 -1
- package/dist/dataStores.js +77 -40
- package/dist/dataStores.js.map +1 -1
- package/dist/gc/garbageCollection.d.ts +41 -13
- package/dist/gc/garbageCollection.d.ts.map +1 -1
- package/dist/gc/garbageCollection.js +215 -78
- package/dist/gc/garbageCollection.js.map +1 -1
- package/dist/gc/gcConfigs.d.ts.map +1 -1
- package/dist/gc/gcConfigs.js +34 -37
- package/dist/gc/gcConfigs.js.map +1 -1
- package/dist/gc/gcDefinitions.d.ts +121 -46
- package/dist/gc/gcDefinitions.d.ts.map +1 -1
- package/dist/gc/gcDefinitions.js +26 -18
- package/dist/gc/gcDefinitions.js.map +1 -1
- package/dist/gc/gcHelpers.d.ts +18 -25
- package/dist/gc/gcHelpers.d.ts.map +1 -1
- package/dist/gc/gcHelpers.js +29 -45
- package/dist/gc/gcHelpers.js.map +1 -1
- package/dist/gc/gcTelemetry.d.ts +0 -5
- package/dist/gc/gcTelemetry.d.ts.map +1 -1
- package/dist/gc/gcTelemetry.js +14 -42
- package/dist/gc/gcTelemetry.js.map +1 -1
- package/dist/gc/gcUnreferencedStateTracker.d.ts +11 -5
- package/dist/gc/gcUnreferencedStateTracker.d.ts.map +1 -1
- package/dist/gc/gcUnreferencedStateTracker.js +43 -19
- package/dist/gc/gcUnreferencedStateTracker.js.map +1 -1
- package/dist/gc/index.d.ts +1 -1
- package/dist/gc/index.d.ts.map +1 -1
- package/dist/gc/index.js +4 -5
- package/dist/gc/index.js.map +1 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -5
- package/dist/index.js.map +1 -1
- package/dist/messageTypes.d.ts +16 -11
- package/dist/messageTypes.d.ts.map +1 -1
- package/dist/messageTypes.js +6 -1
- package/dist/messageTypes.js.map +1 -1
- package/dist/metadata.d.ts +6 -0
- package/dist/metadata.d.ts.map +1 -1
- package/dist/metadata.js.map +1 -1
- package/dist/opLifecycle/definitions.d.ts +1 -1
- package/dist/opLifecycle/definitions.js.map +1 -1
- package/dist/opLifecycle/opGroupingManager.d.ts.map +1 -1
- package/dist/opLifecycle/opGroupingManager.js +10 -1
- package/dist/opLifecycle/opGroupingManager.js.map +1 -1
- package/dist/opLifecycle/outbox.d.ts +2 -0
- package/dist/opLifecycle/outbox.d.ts.map +1 -1
- package/dist/opLifecycle/outbox.js +21 -0
- package/dist/opLifecycle/outbox.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/pendingStateManager.d.ts +1 -1
- package/dist/pendingStateManager.d.ts.map +1 -1
- package/dist/pendingStateManager.js +2 -11
- package/dist/pendingStateManager.js.map +1 -1
- package/dist/scheduleManager.d.ts +1 -0
- package/dist/scheduleManager.d.ts.map +1 -1
- package/dist/summary/orderedClientElection.d.ts +1 -1
- package/dist/summary/orderedClientElection.js.map +1 -1
- package/dist/summary/runWhileConnectedCoordinator.d.ts +2 -2
- package/dist/summary/runWhileConnectedCoordinator.js +1 -1
- package/dist/summary/runWhileConnectedCoordinator.js.map +1 -1
- package/dist/summary/summarizer.d.ts +1 -1
- package/dist/summary/summarizer.js +1 -1
- package/dist/summary/summarizer.js.map +1 -1
- package/dist/summary/summarizerTypes.d.ts +30 -30
- package/dist/summary/summarizerTypes.js.map +1 -1
- package/dist/summary/summaryCollection.d.ts +10 -10
- package/dist/summary/summaryCollection.js +1 -1
- package/dist/summary/summaryCollection.js.map +1 -1
- package/dist/summary/summaryFormat.d.ts +3 -3
- package/dist/summary/summaryFormat.js.map +1 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/batchTracker.d.ts +1 -0
- package/lib/batchTracker.d.ts.map +1 -1
- package/lib/blobManager.d.ts +4 -4
- package/lib/blobManager.d.ts.map +1 -1
- package/lib/blobManager.js.map +1 -1
- package/lib/connectionTelemetry.js +1 -1
- package/lib/connectionTelemetry.js.map +1 -1
- package/lib/container-runtime-alpha.d.ts +1473 -0
- package/lib/container-runtime-beta.d.ts +300 -0
- package/lib/container-runtime-public.d.ts +300 -0
- package/lib/container-runtime-untrimmed.d.ts +1836 -0
- package/lib/containerRuntime.d.ts +34 -40
- package/lib/containerRuntime.d.ts.map +1 -1
- package/lib/containerRuntime.js +81 -69
- package/lib/containerRuntime.js.map +1 -1
- package/lib/dataStoreRegistry.d.ts +1 -1
- package/lib/dataStoreRegistry.js +1 -1
- package/lib/dataStoreRegistry.js.map +1 -1
- package/lib/dataStores.d.ts +10 -15
- package/lib/dataStores.d.ts.map +1 -1
- package/lib/dataStores.js +80 -43
- package/lib/dataStores.js.map +1 -1
- package/lib/gc/garbageCollection.d.ts +41 -13
- package/lib/gc/garbageCollection.d.ts.map +1 -1
- package/lib/gc/garbageCollection.js +217 -80
- package/lib/gc/garbageCollection.js.map +1 -1
- package/lib/gc/gcConfigs.d.ts.map +1 -1
- package/lib/gc/gcConfigs.js +37 -40
- package/lib/gc/gcConfigs.js.map +1 -1
- package/lib/gc/gcDefinitions.d.ts +121 -46
- package/lib/gc/gcDefinitions.d.ts.map +1 -1
- package/lib/gc/gcDefinitions.js +25 -17
- package/lib/gc/gcDefinitions.js.map +1 -1
- package/lib/gc/gcHelpers.d.ts +18 -25
- package/lib/gc/gcHelpers.d.ts.map +1 -1
- package/lib/gc/gcHelpers.js +27 -43
- package/lib/gc/gcHelpers.js.map +1 -1
- package/lib/gc/gcTelemetry.d.ts +0 -5
- package/lib/gc/gcTelemetry.d.ts.map +1 -1
- package/lib/gc/gcTelemetry.js +15 -43
- package/lib/gc/gcTelemetry.js.map +1 -1
- package/lib/gc/gcUnreferencedStateTracker.d.ts +11 -5
- package/lib/gc/gcUnreferencedStateTracker.d.ts.map +1 -1
- package/lib/gc/gcUnreferencedStateTracker.js +43 -19
- package/lib/gc/gcUnreferencedStateTracker.js.map +1 -1
- package/lib/gc/index.d.ts +1 -1
- package/lib/gc/index.d.ts.map +1 -1
- package/lib/gc/index.js +1 -1
- package/lib/gc/index.js.map +1 -1
- package/lib/index.d.ts +14 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +15 -1
- package/lib/index.js.map +1 -1
- package/lib/messageTypes.d.ts +16 -11
- package/lib/messageTypes.d.ts.map +1 -1
- package/lib/messageTypes.js +6 -1
- package/lib/messageTypes.js.map +1 -1
- package/lib/metadata.d.ts +6 -0
- package/lib/metadata.d.ts.map +1 -1
- package/lib/metadata.js.map +1 -1
- package/lib/opLifecycle/definitions.d.ts +1 -1
- package/lib/opLifecycle/definitions.js.map +1 -1
- package/lib/opLifecycle/opGroupingManager.d.ts.map +1 -1
- package/lib/opLifecycle/opGroupingManager.js +10 -1
- package/lib/opLifecycle/opGroupingManager.js.map +1 -1
- package/lib/opLifecycle/outbox.d.ts +2 -0
- package/lib/opLifecycle/outbox.d.ts.map +1 -1
- package/lib/opLifecycle/outbox.js +21 -0
- package/lib/opLifecycle/outbox.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/pendingStateManager.d.ts +1 -1
- package/lib/pendingStateManager.d.ts.map +1 -1
- package/lib/pendingStateManager.js +2 -11
- package/lib/pendingStateManager.js.map +1 -1
- package/lib/scheduleManager.d.ts +1 -0
- package/lib/scheduleManager.d.ts.map +1 -1
- package/lib/summary/orderedClientElection.d.ts +1 -1
- package/lib/summary/orderedClientElection.js.map +1 -1
- package/lib/summary/runWhileConnectedCoordinator.d.ts +2 -2
- package/lib/summary/runWhileConnectedCoordinator.js +1 -1
- package/lib/summary/runWhileConnectedCoordinator.js.map +1 -1
- package/lib/summary/summarizer.d.ts +1 -1
- package/lib/summary/summarizer.js +1 -1
- package/lib/summary/summarizer.js.map +1 -1
- package/lib/summary/summarizerTypes.d.ts +30 -30
- package/lib/summary/summarizerTypes.js.map +1 -1
- package/lib/summary/summaryCollection.d.ts +10 -10
- package/lib/summary/summaryCollection.js +1 -1
- package/lib/summary/summaryCollection.js.map +1 -1
- package/lib/summary/summaryFormat.d.ts +3 -3
- package/lib/summary/summaryFormat.js.map +1 -1
- package/package.json +56 -29
- package/src/blobManager.ts +5 -5
- package/src/connectionTelemetry.ts +1 -1
- package/src/containerRuntime.ts +113 -90
- package/src/dataStoreRegistry.ts +1 -1
- package/src/dataStores.ts +140 -69
- package/src/gc/garbageCollection.md +14 -15
- package/src/gc/garbageCollection.ts +256 -96
- package/src/gc/gcConfigs.ts +50 -52
- package/src/gc/gcDefinitions.ts +137 -52
- package/src/gc/gcHelpers.ts +31 -52
- package/src/gc/gcTelemetry.ts +16 -57
- package/src/gc/gcUnreferencedStateTracker.ts +61 -22
- package/src/gc/index.ts +6 -4
- package/src/index.ts +19 -1
- package/src/messageTypes.ts +21 -11
- package/src/metadata.ts +7 -0
- package/src/opLifecycle/definitions.ts +1 -1
- package/src/opLifecycle/opGroupingManager.ts +10 -1
- package/src/opLifecycle/outbox.ts +34 -0
- package/src/packageVersion.ts +1 -1
- package/src/pendingStateManager.ts +3 -13
- package/src/summary/orderedClientElection.ts +1 -1
- package/src/summary/runWhileConnectedCoordinator.ts +2 -2
- package/src/summary/summarizer.ts +1 -1
- package/src/summary/summarizerTypes.ts +30 -30
- package/src/summary/summaryCollection.ts +10 -10
- package/src/summary/summaryFormat.ts +3 -3
- package/dist/id-compressor/appendOnlySortedMap.d.ts +0 -124
- package/dist/id-compressor/appendOnlySortedMap.d.ts.map +0 -1
- package/dist/id-compressor/appendOnlySortedMap.js +0 -318
- package/dist/id-compressor/appendOnlySortedMap.js.map +0 -1
- package/dist/id-compressor/finalSpace.d.ts +0 -29
- package/dist/id-compressor/finalSpace.d.ts.map +0 -1
- package/dist/id-compressor/finalSpace.js +0 -62
- package/dist/id-compressor/finalSpace.js.map +0 -1
- package/dist/id-compressor/idCompressor.d.ts +0 -54
- package/dist/id-compressor/idCompressor.d.ts.map +0 -1
- package/dist/id-compressor/idCompressor.js +0 -495
- package/dist/id-compressor/idCompressor.js.map +0 -1
- package/dist/id-compressor/identifiers.d.ts +0 -32
- package/dist/id-compressor/identifiers.d.ts.map +0 -1
- package/dist/id-compressor/identifiers.js +0 -15
- package/dist/id-compressor/identifiers.js.map +0 -1
- package/dist/id-compressor/index.d.ts +0 -13
- package/dist/id-compressor/index.d.ts.map +0 -1
- package/dist/id-compressor/index.js +0 -32
- package/dist/id-compressor/index.js.map +0 -1
- package/dist/id-compressor/persistanceUtilities.d.ts +0 -22
- package/dist/id-compressor/persistanceUtilities.d.ts.map +0 -1
- package/dist/id-compressor/persistanceUtilities.js +0 -43
- package/dist/id-compressor/persistanceUtilities.js.map +0 -1
- package/dist/id-compressor/sessionSpaceNormalizer.d.ts +0 -46
- package/dist/id-compressor/sessionSpaceNormalizer.d.ts.map +0 -1
- package/dist/id-compressor/sessionSpaceNormalizer.js +0 -80
- package/dist/id-compressor/sessionSpaceNormalizer.js.map +0 -1
- package/dist/id-compressor/sessions.d.ts +0 -115
- package/dist/id-compressor/sessions.d.ts.map +0 -1
- package/dist/id-compressor/sessions.js +0 -305
- package/dist/id-compressor/sessions.js.map +0 -1
- package/dist/id-compressor/utilities.d.ts +0 -52
- package/dist/id-compressor/utilities.d.ts.map +0 -1
- package/dist/id-compressor/utilities.js +0 -169
- package/dist/id-compressor/utilities.js.map +0 -1
- package/lib/id-compressor/appendOnlySortedMap.d.ts +0 -124
- package/lib/id-compressor/appendOnlySortedMap.d.ts.map +0 -1
- package/lib/id-compressor/appendOnlySortedMap.js +0 -314
- package/lib/id-compressor/appendOnlySortedMap.js.map +0 -1
- package/lib/id-compressor/finalSpace.d.ts +0 -29
- package/lib/id-compressor/finalSpace.d.ts.map +0 -1
- package/lib/id-compressor/finalSpace.js +0 -58
- package/lib/id-compressor/finalSpace.js.map +0 -1
- package/lib/id-compressor/idCompressor.d.ts +0 -54
- package/lib/id-compressor/idCompressor.d.ts.map +0 -1
- package/lib/id-compressor/idCompressor.js +0 -491
- package/lib/id-compressor/idCompressor.js.map +0 -1
- package/lib/id-compressor/identifiers.d.ts +0 -32
- package/lib/id-compressor/identifiers.d.ts.map +0 -1
- package/lib/id-compressor/identifiers.js +0 -11
- package/lib/id-compressor/identifiers.js.map +0 -1
- package/lib/id-compressor/index.d.ts +0 -13
- package/lib/id-compressor/index.d.ts.map +0 -1
- package/lib/id-compressor/index.js +0 -13
- package/lib/id-compressor/index.js.map +0 -1
- package/lib/id-compressor/persistanceUtilities.d.ts +0 -22
- package/lib/id-compressor/persistanceUtilities.d.ts.map +0 -1
- package/lib/id-compressor/persistanceUtilities.js +0 -34
- package/lib/id-compressor/persistanceUtilities.js.map +0 -1
- package/lib/id-compressor/sessionSpaceNormalizer.d.ts +0 -46
- package/lib/id-compressor/sessionSpaceNormalizer.d.ts.map +0 -1
- package/lib/id-compressor/sessionSpaceNormalizer.js +0 -76
- package/lib/id-compressor/sessionSpaceNormalizer.js.map +0 -1
- package/lib/id-compressor/sessions.d.ts +0 -115
- package/lib/id-compressor/sessions.d.ts.map +0 -1
- package/lib/id-compressor/sessions.js +0 -290
- package/lib/id-compressor/sessions.js.map +0 -1
- package/lib/id-compressor/utilities.d.ts +0 -52
- package/lib/id-compressor/utilities.d.ts.map +0 -1
- package/lib/id-compressor/utilities.js +0 -151
- package/lib/id-compressor/utilities.js.map +0 -1
- package/src/id-compressor/README.md +0 -3
- package/src/id-compressor/appendOnlySortedMap.ts +0 -366
- package/src/id-compressor/finalSpace.ts +0 -67
- package/src/id-compressor/idCompressor.ts +0 -630
- package/src/id-compressor/identifiers.ts +0 -42
- package/src/id-compressor/index.ts +0 -26
- package/src/id-compressor/persistanceUtilities.ts +0 -58
- package/src/id-compressor/sessionSpaceNormalizer.ts +0 -83
- package/src/id-compressor/sessions.ts +0 -405
- package/src/id-compressor/utilities.ts +0 -190
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gcHelpers.d.ts","sourceRoot":"","sources":["../../src/gc/gcHelpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAIN,sBAAsB,EACtB,6BAA6B,EAC7B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAEN,8BAA8B,EAC9B,uBAAuB,EACvB,MAAM,wBAAwB,CAAC;AAEhC,wBAAgB,YAAY,CAAC,QAAQ,CAAC,EAAE,WAAW,GAAG,SAAS,CAM9D;AAED
|
|
1
|
+
{"version":3,"file":"gcHelpers.d.ts","sourceRoot":"","sources":["../../src/gc/gcHelpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,E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AAO,CAGT"}
|
package/dist/gc/gcHelpers.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.trimLeadingAndTrailingSlashes = exports.unpackChildNodesGCDetails = exports.getGCDataFromSnapshot = exports.concatGarbageCollectionData = exports.cloneGCData = exports.concatGarbageCollectionStates = exports.generateSortedGCState = exports.shouldAllowGcSweep = exports.
|
|
7
|
+
exports.compatBehaviorAllowsGCMessageType = exports.trimLeadingAndTrailingSlashes = exports.unpackChildNodesGCDetails = exports.getGCDataFromSnapshot = exports.concatGarbageCollectionData = exports.cloneGCData = exports.concatGarbageCollectionStates = exports.generateSortedGCState = exports.shouldAllowGcSweep = exports.getGCVersion = void 0;
|
|
8
8
|
const core_utils_1 = require("@fluidframework/core-utils");
|
|
9
9
|
const runtime_definitions_1 = require("@fluidframework/runtime-definitions");
|
|
10
10
|
function getGCVersion(metadata) {
|
|
@@ -16,54 +16,29 @@ function getGCVersion(metadata) {
|
|
|
16
16
|
}
|
|
17
17
|
exports.getGCVersion = getGCVersion;
|
|
18
18
|
/**
|
|
19
|
-
* Indicates whether
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* In order to protect old documents that were created at a time when known bugs exist that violate GC's invariants
|
|
23
|
-
* such that enforcing GC Tombstone (Failing on Tombstone load/usage) would cause legitimate data loss,
|
|
24
|
-
* the container author may increment the generation value for Tombstone such that containers created
|
|
25
|
-
* with a different value will not be subjected to GC enforcement.
|
|
26
|
-
*
|
|
27
|
-
* If no generation is provided at runtime, this defaults to return true to maintain expected default behavior
|
|
28
|
-
*
|
|
29
|
-
* @param persistedGeneration - The persisted tombstoneGeneration value
|
|
30
|
-
* @param currentGeneration - The current app-provided tombstoneGeneration value
|
|
31
|
-
* @returns true if GC Tombstone enforcement (Fail on Tombstone load/usage) should be allowed for this document
|
|
32
|
-
*/
|
|
33
|
-
function shouldAllowGcTombstoneEnforcement(persistedGeneration, currentGeneration) {
|
|
34
|
-
// If no Generation value is provided for this session, then we should default to letting Tombstone feature behave as intended.
|
|
35
|
-
if (currentGeneration === undefined) {
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
return persistedGeneration === currentGeneration;
|
|
39
|
-
}
|
|
40
|
-
exports.shouldAllowGcTombstoneEnforcement = shouldAllowGcTombstoneEnforcement;
|
|
41
|
-
/**
|
|
42
|
-
* Indicates whether Sweep is allowed for this document based on the GC Feature Matrix and current SweepGeneration
|
|
19
|
+
* Indicates whether Sweep is allowed for this document based on the persisted GC Feature Matrix and current gcGeneration.
|
|
20
|
+
* This applies to the entire Sweep Phase the same - both Tombstone Enforcement (i.e. should loading a Tombstone fail?) and Deletion.
|
|
43
21
|
*
|
|
44
22
|
* In order to protect old documents that were created at a time when known bugs exist that violate GC's invariants
|
|
45
23
|
* such that enforcing GC Sweep would cause legitimate data loss, the container author may increment the generation value for Sweep
|
|
46
24
|
* such that containers created with a different value will not be subjected to GC Sweep.
|
|
47
25
|
*
|
|
48
|
-
* If no generation is provided, Sweep will be
|
|
49
|
-
*
|
|
26
|
+
* If no generation is provided, Sweep will be enabled for all documents.
|
|
27
|
+
*
|
|
28
|
+
* For backwards compatibility, the current generation value is also compared against the persisted gcTombstoneGeneration if present.
|
|
50
29
|
*
|
|
51
|
-
* @param
|
|
52
|
-
* @param currentGeneration - The current app-provided
|
|
30
|
+
* @param featureMatrix - The GC Feature Matrix, containing the persisted generation value
|
|
31
|
+
* @param currentGeneration - The current app-provided gcGeneration value
|
|
53
32
|
* @returns true if GC Sweep should be allowed for this document
|
|
54
33
|
*/
|
|
55
|
-
function shouldAllowGcSweep(
|
|
56
|
-
// If no Generation value is provided for this session, default to
|
|
34
|
+
function shouldAllowGcSweep(featureMatrix, currentGeneration) {
|
|
35
|
+
// If no Generation value is provided for this session, default to true
|
|
57
36
|
if (currentGeneration === undefined) {
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
// 0 is a special case: It matches both SweepGeneration and TombstoneGeneration
|
|
61
|
-
// This is an optimistic measure to maximize coverage of GC Sweep if no bumps to TombstoneGeneration are needed before enabling Sweep.
|
|
62
|
-
if (currentGeneration === 0) {
|
|
63
|
-
return (persistedGenerations.sweepGeneration === 0 ||
|
|
64
|
-
persistedGenerations.tombstoneGeneration === 0);
|
|
37
|
+
return true;
|
|
65
38
|
}
|
|
66
|
-
|
|
39
|
+
// tombstoneGeneration is the predecessor and needs to be supported for back-compat reasons
|
|
40
|
+
const targetGeneration = featureMatrix.tombstoneGeneration ?? featureMatrix.gcGeneration;
|
|
41
|
+
return currentGeneration === targetGeneration;
|
|
67
42
|
}
|
|
68
43
|
exports.shouldAllowGcSweep = shouldAllowGcSweep;
|
|
69
44
|
/**
|
|
@@ -120,16 +95,12 @@ exports.concatGarbageCollectionStates = concatGarbageCollectionStates;
|
|
|
120
95
|
/**
|
|
121
96
|
* Helper function that clones the GC data.
|
|
122
97
|
* @param gcData - The GC data to clone.
|
|
123
|
-
* @param filter - Optional function to filter out node ids not to be included in the cloned GC data. Returns
|
|
124
|
-
* true to filter out nodes.
|
|
125
98
|
* @returns a clone of the given GC data.
|
|
126
99
|
*/
|
|
127
|
-
function cloneGCData(gcData
|
|
100
|
+
function cloneGCData(gcData) {
|
|
128
101
|
const clonedGCNodes = {};
|
|
129
102
|
for (const [id, outboundRoutes] of Object.entries(gcData.gcNodes)) {
|
|
130
|
-
|
|
131
|
-
clonedGCNodes[id] = Array.from(outboundRoutes);
|
|
132
|
-
}
|
|
103
|
+
clonedGCNodes[id] = Array.from(outboundRoutes);
|
|
133
104
|
}
|
|
134
105
|
return {
|
|
135
106
|
gcNodes: clonedGCNodes,
|
|
@@ -248,4 +219,17 @@ function trimLeadingAndTrailingSlashes(str) {
|
|
|
248
219
|
return str.replace(/^\/+|\/+$/g, "");
|
|
249
220
|
}
|
|
250
221
|
exports.trimLeadingAndTrailingSlashes = trimLeadingAndTrailingSlashes;
|
|
222
|
+
/**
|
|
223
|
+
* Utility to implement compat behaviors given an unknown message type
|
|
224
|
+
* The parameters are typed to support compile-time enforcement of handling all known types/behaviors
|
|
225
|
+
*
|
|
226
|
+
* @param _unknownGCMessageType - Typed as never to ensure all known types have been
|
|
227
|
+
* handled before calling this function (e.g. in a switch statement).
|
|
228
|
+
* @param compatBehavior - Typed redundantly with CompatModeBehavior to ensure handling is added when updating that type
|
|
229
|
+
*/
|
|
230
|
+
function compatBehaviorAllowsGCMessageType(_unknownGCMessageType, compatBehavior) {
|
|
231
|
+
// undefined defaults to same behavior as "FailToProcess"
|
|
232
|
+
return compatBehavior === "Ignore";
|
|
233
|
+
}
|
|
234
|
+
exports.compatBehaviorAllowsGCMessageType = compatBehaviorAllowsGCMessageType;
|
|
251
235
|
//# sourceMappingURL=gcHelpers.js.map
|
package/dist/gc/gcHelpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gcHelpers.js","sourceRoot":"","sources":["../../src/gc/gcHelpers.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2DAAoD;AAEpD,6EAM6C;AAQ7C,SAAgB,YAAY,CAAC,QAAsB;IAClD,IAAI,CAAC,QAAQ,EAAE;QACd,0CAA0C;QAC1C,OAAO,CAAC,CAAC;KACT;IACD,OAAO,QAAQ,CAAC,SAAS,IAAI,CAAC,CAAC;AAChC,CAAC;AAND,oCAMC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,iCAAiC,CAChD,mBAAuC,EACvC,iBAAqC;IAErC,+HAA+H;IAC/H,IAAI,iBAAiB,KAAK,SAAS,EAAE;QACpC,OAAO,IAAI,CAAC;KACZ;IACD,OAAO,mBAAmB,KAAK,iBAAiB,CAAC;AAClD,CAAC;AATD,8EASC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,kBAAkB,CACjC,oBAAsF,EACtF,iBAAqC;IAErC,wEAAwE;IACxE,IAAI,iBAAiB,KAAK,SAAS,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c,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAEvD,MAAM,cAAc,GAAG,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACtD,IAAA,mBAAM,EACL,cAAc,EAAE,UAAU,KAAK,SAAS,EACxC,KAAK,CAAC,kEAAkE,CACxE,CAAC;QAEF,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC/C,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;KAC/C;IACD,OAAO,iBAAiB,CAAC;AAC1B,CAAC;AA1DD,8DA0DC;AAED;;;;GAIG;AACH,SAAgB,6BAA6B,CAAC,GAAW;IACxD,OAAO,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;AACtC,CAAC;AAFD,sEAEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport { ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport {\n\tgcBlobPrefix,\n\tgcDeletedBlobKey,\n\tgcTombstoneBlobKey,\n\tIGarbageCollectionData,\n\tIGarbageCollectionDetailsBase,\n} from \"@fluidframework/runtime-definitions\";\nimport { GCFeatureMatrix, GCVersion, IGCMetadata } from \"./gcDefinitions\";\nimport {\n\tIGarbageCollectionNodeData,\n\tIGarbageCollectionSnapshotData,\n\tIGarbageCollectionState,\n} from \"./gcSummaryDefinitions\";\n\nexport function getGCVersion(metadata?: IGCMetadata): GCVersion {\n\tif (!metadata) {\n\t\t// Force to 0/disallowed in prior versions\n\t\treturn 0;\n\t}\n\treturn metadata.gcFeature ?? 0;\n}\n\n/**\n * Indicates whether Tombstone Enforcement is allowed for this document based on the current/persisted\n * TombstoneGeneration values\n *\n * In order to protect old documents that were created at a time when known bugs exist that violate GC's invariants\n * such that enforcing GC Tombstone (Failing on Tombstone load/usage) would cause legitimate data loss,\n * the container author may increment the generation value for Tombstone such that containers created\n * with a different value will not be subjected to GC enforcement.\n *\n * If no generation is provided at runtime, this defaults to return true to maintain expected default behavior\n *\n * @param persistedGeneration - The persisted tombstoneGeneration value\n * @param currentGeneration - The current app-provided tombstoneGeneration value\n * @returns true if GC Tombstone enforcement (Fail on Tombstone load/usage) should be allowed for this document\n */\nexport function shouldAllowGcTombstoneEnforcement(\n\tpersistedGeneration: number | undefined,\n\tcurrentGeneration: number | undefined,\n): boolean {\n\t// If no Generation value is provided for this session, then we should default to letting Tombstone feature behave as intended.\n\tif (currentGeneration === undefined) {\n\t\treturn true;\n\t}\n\treturn persistedGeneration === currentGeneration;\n}\n\n/**\n * Indicates whether Sweep is allowed for this document based on the GC Feature Matrix and current SweepGeneration\n *\n * In order to protect old documents that were created at a time when known bugs exist that violate GC's invariants\n * such that enforcing GC Sweep would cause legitimate data loss, the container author may increment the generation value for Sweep\n * such that containers created with a different value will not be subjected to GC Sweep.\n *\n * If no generation is provided, Sweep will be disabled.\n * Passing 0 is a special case: Sweep will be enabled for any document with gcSweepGeneration OR gcTombstoneGeneration as 0.\n *\n * @param persistedGenerations - The persisted sweep/tombstone generations from the GC Feature Matrix\n * @param currentGeneration - The current app-provided sweepGeneration value\n * @returns true if GC Sweep should be allowed for this document\n */\nexport function shouldAllowGcSweep(\n\tpersistedGenerations: Pick<GCFeatureMatrix, \"sweepGeneration\" | \"tombstoneGeneration\">,\n\tcurrentGeneration: number | undefined,\n): boolean {\n\t// If no Generation value is provided for this session, default to false\n\tif (currentGeneration === undefined) {\n\t\treturn false;\n\t}\n\n\t// 0 is a special case: It matches both SweepGeneration and TombstoneGeneration\n\t// This is an optimistic measure to maximize coverage of GC Sweep if no bumps to TombstoneGeneration are needed before enabling Sweep.\n\tif (currentGeneration === 0) {\n\t\treturn (\n\t\t\tpersistedGenerations.sweepGeneration === 0 ||\n\t\t\tpersistedGenerations.tombstoneGeneration === 0\n\t\t);\n\t}\n\n\treturn persistedGenerations.sweepGeneration === currentGeneration;\n}\n\n/**\n * Sorts the given GC state as per the id of the GC nodes. It also sorts the outbound routes array of each node.\n */\nexport function generateSortedGCState(gcState: IGarbageCollectionState): IGarbageCollectionState {\n\tconst sortableArray: [string, IGarbageCollectionNodeData][] = Object.entries(gcState.gcNodes);\n\tsortableArray.sort(([a], [b]) => a.localeCompare(b));\n\tconst sortedGCState: IGarbageCollectionState = { gcNodes: {} };\n\tfor (const [nodeId, nodeData] of sortableArray) {\n\t\tnodeData.outboundRoutes.sort();\n\t\tsortedGCState.gcNodes[nodeId] = nodeData;\n\t}\n\treturn sortedGCState;\n}\n\n/**\n * Concatenates the given GC states and returns the concatenated GC state.\n */\nexport function concatGarbageCollectionStates(\n\tgcState1: IGarbageCollectionState,\n\tgcState2: IGarbageCollectionState,\n): IGarbageCollectionState {\n\tconst combinedGCNodes: { [id: string]: IGarbageCollectionNodeData } = {};\n\tfor (const [nodeId, nodeData] of Object.entries(gcState1.gcNodes)) {\n\t\tcombinedGCNodes[nodeId] = {\n\t\t\toutboundRoutes: Array.from(nodeData.outboundRoutes),\n\t\t\tunreferencedTimestampMs: nodeData.unreferencedTimestampMs,\n\t\t};\n\t}\n\n\tfor (const [nodeId, nodeData] of Object.entries(gcState2.gcNodes)) {\n\t\tlet combineNodeData = combinedGCNodes[nodeId];\n\t\tif (combineNodeData === undefined) {\n\t\t\tcombineNodeData = {\n\t\t\t\toutboundRoutes: Array.from(nodeData.outboundRoutes),\n\t\t\t\tunreferencedTimestampMs: nodeData.unreferencedTimestampMs,\n\t\t\t};\n\t\t} else {\n\t\t\t// Validate that same node doesn't have different unreferenced timestamp.\n\t\t\tif (\n\t\t\t\tnodeData.unreferencedTimestampMs !== undefined &&\n\t\t\t\tcombineNodeData.unreferencedTimestampMs !== undefined\n\t\t\t) {\n\t\t\t\tassert(\n\t\t\t\t\tnodeData.unreferencedTimestampMs === combineNodeData.unreferencedTimestampMs,\n\t\t\t\t\t0x5d7 /* Two entries for the same GC node with different unreferenced timestamp */,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcombineNodeData = {\n\t\t\t\toutboundRoutes: [\n\t\t\t\t\t...new Set([...nodeData.outboundRoutes, ...combineNodeData.outboundRoutes]),\n\t\t\t\t],\n\t\t\t\tunreferencedTimestampMs:\n\t\t\t\t\tnodeData.unreferencedTimestampMs ?? combineNodeData.unreferencedTimestampMs,\n\t\t\t};\n\t\t}\n\t\tcombinedGCNodes[nodeId] = combineNodeData;\n\t}\n\treturn { gcNodes: combinedGCNodes };\n}\n\n/**\n * Helper function that clones the GC data.\n * @param gcData - The GC data to clone.\n * @param filter - Optional function to filter out node ids not to be included in the cloned GC data. Returns\n * true to filter out nodes.\n * @returns a clone of the given GC data.\n */\nexport function cloneGCData(\n\tgcData: IGarbageCollectionData,\n\tfilter?: (id: string) => boolean,\n): IGarbageCollectionData {\n\tconst clonedGCNodes: { [id: string]: string[] } = {};\n\tfor (const [id, outboundRoutes] of Object.entries(gcData.gcNodes)) {\n\t\tif (filter?.(id) !== true) {\n\t\t\tclonedGCNodes[id] = Array.from(outboundRoutes);\n\t\t}\n\t}\n\treturn {\n\t\tgcNodes: clonedGCNodes,\n\t};\n}\n\n/**\n * Concatenates the given GC data and returns the concatenated GC data.\n */\nexport function concatGarbageCollectionData(\n\tgcData1: IGarbageCollectionData,\n\tgcData2: IGarbageCollectionData,\n) {\n\tconst combinedGCData: IGarbageCollectionData = cloneGCData(gcData1);\n\tfor (const [id, routes] of Object.entries(gcData2.gcNodes)) {\n\t\tif (combinedGCData.gcNodes[id] === undefined) {\n\t\t\tcombinedGCData.gcNodes[id] = Array.from(routes);\n\t\t} else {\n\t\t\tconst combinedRoutes = [...routes, ...combinedGCData.gcNodes[id]];\n\t\t\tcombinedGCData.gcNodes[id] = [...new Set(combinedRoutes)];\n\t\t}\n\t}\n\treturn combinedGCData;\n}\n\n/**\n * Gets the base garbage collection state from the given snapshot tree. It contains GC state, deleted nodes and\n * tombstones. The GC state may be written into multiple blobs. Merge the GC state from all such blobs into one.\n */\nexport async function getGCDataFromSnapshot(\n\tgcSnapshotTree: ISnapshotTree,\n\treadAndParseBlob: <T>(id: string) => Promise<T>,\n): Promise<IGarbageCollectionSnapshotData> {\n\tlet rootGCState: IGarbageCollectionState = { gcNodes: {} };\n\tlet tombstones: string[] | undefined;\n\tlet deletedNodes: string[] | undefined;\n\tfor (const key of Object.keys(gcSnapshotTree.blobs)) {\n\t\t// Update deleted nodes blob.\n\t\tif (key === gcDeletedBlobKey) {\n\t\t\tdeletedNodes = await readAndParseBlob<string[]>(gcSnapshotTree.blobs[key]);\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Update tombstone blob.\n\t\tif (key === gcTombstoneBlobKey) {\n\t\t\ttombstones = await readAndParseBlob<string[]>(gcSnapshotTree.blobs[key]);\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Skip blobs that do not start with the GC prefix.\n\t\tif (!key.startsWith(gcBlobPrefix)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst blobId = gcSnapshotTree.blobs[key];\n\t\tif (blobId === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst gcState = await readAndParseBlob<IGarbageCollectionState>(blobId);\n\t\tassert(gcState !== undefined, 0x5d8 /* GC blob missing from snapshot */);\n\t\t// Merge the GC state of this blob into the root GC state.\n\t\trootGCState = concatGarbageCollectionStates(rootGCState, gcState);\n\t}\n\treturn { gcState: rootGCState, tombstones, deletedNodes };\n}\n\n/**\n * Helper function that unpacks the GC details of the children from a given node's GC details.\n * @param gcDetails - The GC details of a node.\n * @returns A map of GC details of each children of the the given node.\n */\nexport function unpackChildNodesGCDetails(gcDetails: IGarbageCollectionDetailsBase) {\n\tconst childGCDetailsMap: Map<string, IGarbageCollectionDetailsBase> = new Map();\n\n\t// If GC data is not available, bail out.\n\tif (gcDetails.gcData === undefined) {\n\t\treturn childGCDetailsMap;\n\t}\n\n\tconst gcNodes = gcDetails.gcData.gcNodes;\n\tfor (const [id, outboundRoutes] of Object.entries(gcNodes)) {\n\t\t// Skip self-node since only children GC data is to be generated.\n\t\tif (id === \"/\") {\n\t\t\tcontinue;\n\t\t}\n\n\t\tassert(id.startsWith(\"/\"), 0x5d9 /* node id should always be an absolute route */);\n\t\tconst childId = id.split(\"/\")[1];\n\t\tlet childGCNodeId = id.slice(childId.length + 1);\n\t\t// GC node id always begins with \"/\". Handle the special case where a child's id in the parent's GC nodes is\n\t\t// of format `/root`. In this case, the childId is root and childGCNodeId is \"\". Make childGCNodeId = \"/\".\n\t\tif (childGCNodeId === \"\") {\n\t\t\tchildGCNodeId = \"/\";\n\t\t}\n\n\t\tlet childGCDetails = childGCDetailsMap.get(childId);\n\t\tif (childGCDetails === undefined) {\n\t\t\tchildGCDetails = { gcData: { gcNodes: {} }, usedRoutes: [] };\n\t\t}\n\t\t// gcData should not undefined as its always at least initialized as empty above.\n\t\tassert(\n\t\t\tchildGCDetails.gcData !== undefined,\n\t\t\t0x5da /* Child GC data should have been initialized */,\n\t\t);\n\t\tchildGCDetails.gcData.gcNodes[childGCNodeId] = [...new Set(outboundRoutes)];\n\t\tchildGCDetailsMap.set(childId, childGCDetails);\n\t}\n\n\tif (gcDetails.usedRoutes === undefined) {\n\t\treturn childGCDetailsMap;\n\t}\n\n\t// Remove the node's self used route, if any, and generate the children used routes.\n\tconst usedRoutes = gcDetails.usedRoutes.filter((route) => route !== \"\" && route !== \"/\");\n\tfor (const route of usedRoutes) {\n\t\tassert(route.startsWith(\"/\"), 0x5db /* Used route should always be an absolute route */);\n\t\tconst childId = route.split(\"/\")[1];\n\t\tconst childUsedRoute = route.slice(childId.length + 1);\n\n\t\tconst childGCDetails = childGCDetailsMap.get(childId);\n\t\tassert(\n\t\t\tchildGCDetails?.usedRoutes !== undefined,\n\t\t\t0x5dc /* This should have be initialized when generate GC nodes above */,\n\t\t);\n\n\t\tchildGCDetails.usedRoutes.push(childUsedRoute);\n\t\tchildGCDetailsMap.set(childId, childGCDetails);\n\t}\n\treturn childGCDetailsMap;\n}\n\n/**\n * Trims the leading and trailing slashes from the given string.\n * @param str - A string that may contain leading and / or trailing slashes.\n * @returns A new string without leading and trailing slashes.\n */\nexport function trimLeadingAndTrailingSlashes(str: string) {\n\treturn str.replace(/^\\/+|\\/+$/g, \"\");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"gcHelpers.js","sourceRoot":"","sources":["../../src/gc/gcHelpers.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2DAAoD;AAEpD,6EAM6C;AAQ7C,SAAgB,YAAY,CAAC,QAAsB;IAClD,IAAI,CAAC,QAAQ,EAAE;QACd,0CAA0C;QAC1C,OAAO,CAAC,CAAC;KACT;IACD,OAAO,QAAQ,CAAC,SAAS,IAAI,CAAC,CAAC;AAChC,CAAC;AAND,oCAMC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,kBAAkB,CACjC,aAA8B,EAC9B,iBAAqC;IAErC,uEAAuE;IACvE,IAAI,iBAAiB,KAAK,SAAS,EAAE;QACpC,OAAO,IAAI,CAAC;KACZ;IAED,2FAA2F;IAC3F,MAAM,gBAAgB,GAAG,aAAa,CAAC,mBAAmB,IAAI,aAAa,CAAC,YAAY,CAAC;IAEzF,OAAO,iBAAiB,KAAK,gBAAgB,CAAC;AAC/C,CAAC;AAbD,gDAaC;AAED;;GAEG;AACH,SAAgB,qBAAqB,CAAC,OAAgC;IACrE,MAAM,aAAa,GAA2C,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9F,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IACrD,MAAM,aAAa,GAA4B,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAC/D,KAAK,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,aAAa,EAAE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U,KAAK,SAAS,EAAE;QACvC,OAAO,iBAAiB,CAAC;KACzB;IAED,oFAAoF;IACpF,MAAM,UAAU,GAAG,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC;IACzF,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE;QAC/B,IAAA,mBAAM,EAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACzF,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,cAAc,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAEvD,MAAM,cAAc,GAAG,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACtD,IAAA,mBAAM,EACL,cAAc,EAAE,UAAU,KAAK,SAAS,EACxC,KAAK,CAAC,kEAAkE,CACxE,CAAC;QAEF,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC/C,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;KAC/C;IACD,OAAO,iBAAiB,CAAC;AAC1B,CAAC;AA1DD,8DA0DC;AAED;;;;GAIG;AACH,SAAgB,6BAA6B,CAAC,GAAW;IACxD,OAAO,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;AACtC,CAAC;AAFD,sEAEC;AAED;;;;;;;GAOG;AACH,SAAgB,iCAAiC,CAChD,qBAA4B,EAC5B,cAAsD;IAEtD,yDAAyD;IACzD,OAAO,cAAc,KAAK,QAAQ,CAAC;AACpC,CAAC;AAND,8EAMC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport { ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport {\n\tgcBlobPrefix,\n\tgcDeletedBlobKey,\n\tgcTombstoneBlobKey,\n\tIGarbageCollectionData,\n\tIGarbageCollectionDetailsBase,\n} from \"@fluidframework/runtime-definitions\";\nimport { GCFeatureMatrix, GCVersion, IGCMetadata } from \"./gcDefinitions\";\nimport {\n\tIGarbageCollectionNodeData,\n\tIGarbageCollectionSnapshotData,\n\tIGarbageCollectionState,\n} from \"./gcSummaryDefinitions\";\n\nexport function getGCVersion(metadata?: IGCMetadata): GCVersion {\n\tif (!metadata) {\n\t\t// Force to 0/disallowed in prior versions\n\t\treturn 0;\n\t}\n\treturn metadata.gcFeature ?? 0;\n}\n\n/**\n * Indicates whether Sweep is allowed for this document based on the persisted GC Feature Matrix and current gcGeneration.\n * This applies to the entire Sweep Phase the same - both Tombstone Enforcement (i.e. should loading a Tombstone fail?) and Deletion.\n *\n * In order to protect old documents that were created at a time when known bugs exist that violate GC's invariants\n * such that enforcing GC Sweep would cause legitimate data loss, the container author may increment the generation value for Sweep\n * such that containers created with a different value will not be subjected to GC Sweep.\n *\n * If no generation is provided, Sweep will be enabled for all documents.\n *\n * For backwards compatibility, the current generation value is also compared against the persisted gcTombstoneGeneration if present.\n *\n * @param featureMatrix - The GC Feature Matrix, containing the persisted generation value\n * @param currentGeneration - The current app-provided gcGeneration value\n * @returns true if GC Sweep should be allowed for this document\n */\nexport function shouldAllowGcSweep(\n\tfeatureMatrix: GCFeatureMatrix,\n\tcurrentGeneration: number | undefined,\n): boolean {\n\t// If no Generation value is provided for this session, default to true\n\tif (currentGeneration === undefined) {\n\t\treturn true;\n\t}\n\n\t// tombstoneGeneration is the predecessor and needs to be supported for back-compat reasons\n\tconst targetGeneration = featureMatrix.tombstoneGeneration ?? featureMatrix.gcGeneration;\n\n\treturn currentGeneration === targetGeneration;\n}\n\n/**\n * Sorts the given GC state as per the id of the GC nodes. It also sorts the outbound routes array of each node.\n */\nexport function generateSortedGCState(gcState: IGarbageCollectionState): IGarbageCollectionState {\n\tconst sortableArray: [string, IGarbageCollectionNodeData][] = Object.entries(gcState.gcNodes);\n\tsortableArray.sort(([a], [b]) => a.localeCompare(b));\n\tconst sortedGCState: IGarbageCollectionState = { gcNodes: {} };\n\tfor (const [nodeId, nodeData] of sortableArray) {\n\t\tnodeData.outboundRoutes.sort();\n\t\tsortedGCState.gcNodes[nodeId] = nodeData;\n\t}\n\treturn sortedGCState;\n}\n\n/**\n * Concatenates the given GC states and returns the concatenated GC state.\n */\nexport function concatGarbageCollectionStates(\n\tgcState1: IGarbageCollectionState,\n\tgcState2: IGarbageCollectionState,\n): IGarbageCollectionState {\n\tconst combinedGCNodes: { [id: string]: IGarbageCollectionNodeData } = {};\n\tfor (const [nodeId, nodeData] of Object.entries(gcState1.gcNodes)) {\n\t\tcombinedGCNodes[nodeId] = {\n\t\t\toutboundRoutes: Array.from(nodeData.outboundRoutes),\n\t\t\tunreferencedTimestampMs: nodeData.unreferencedTimestampMs,\n\t\t};\n\t}\n\n\tfor (const [nodeId, nodeData] of Object.entries(gcState2.gcNodes)) {\n\t\tlet combineNodeData = combinedGCNodes[nodeId];\n\t\tif (combineNodeData === undefined) {\n\t\t\tcombineNodeData = {\n\t\t\t\toutboundRoutes: Array.from(nodeData.outboundRoutes),\n\t\t\t\tunreferencedTimestampMs: nodeData.unreferencedTimestampMs,\n\t\t\t};\n\t\t} else {\n\t\t\t// Validate that same node doesn't have different unreferenced timestamp.\n\t\t\tif (\n\t\t\t\tnodeData.unreferencedTimestampMs !== undefined &&\n\t\t\t\tcombineNodeData.unreferencedTimestampMs !== undefined\n\t\t\t) {\n\t\t\t\tassert(\n\t\t\t\t\tnodeData.unreferencedTimestampMs === combineNodeData.unreferencedTimestampMs,\n\t\t\t\t\t0x5d7 /* Two entries for the same GC node with different unreferenced timestamp */,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcombineNodeData = {\n\t\t\t\toutboundRoutes: [\n\t\t\t\t\t...new Set([...nodeData.outboundRoutes, ...combineNodeData.outboundRoutes]),\n\t\t\t\t],\n\t\t\t\tunreferencedTimestampMs:\n\t\t\t\t\tnodeData.unreferencedTimestampMs ?? combineNodeData.unreferencedTimestampMs,\n\t\t\t};\n\t\t}\n\t\tcombinedGCNodes[nodeId] = combineNodeData;\n\t}\n\treturn { gcNodes: combinedGCNodes };\n}\n\n/**\n * Helper function that clones the GC data.\n * @param gcData - The GC data to clone.\n * @returns a clone of the given GC data.\n */\nexport function cloneGCData(gcData: IGarbageCollectionData): IGarbageCollectionData {\n\tconst clonedGCNodes: { [id: string]: string[] } = {};\n\tfor (const [id, outboundRoutes] of Object.entries(gcData.gcNodes)) {\n\t\tclonedGCNodes[id] = Array.from(outboundRoutes);\n\t}\n\treturn {\n\t\tgcNodes: clonedGCNodes,\n\t};\n}\n\n/**\n * Concatenates the given GC data and returns the concatenated GC data.\n */\nexport function concatGarbageCollectionData(\n\tgcData1: IGarbageCollectionData,\n\tgcData2: IGarbageCollectionData,\n) {\n\tconst combinedGCData: IGarbageCollectionData = cloneGCData(gcData1);\n\tfor (const [id, routes] of Object.entries(gcData2.gcNodes)) {\n\t\tif (combinedGCData.gcNodes[id] === undefined) {\n\t\t\tcombinedGCData.gcNodes[id] = Array.from(routes);\n\t\t} else {\n\t\t\tconst combinedRoutes = [...routes, ...combinedGCData.gcNodes[id]];\n\t\t\tcombinedGCData.gcNodes[id] = [...new Set(combinedRoutes)];\n\t\t}\n\t}\n\treturn combinedGCData;\n}\n\n/**\n * Gets the base garbage collection state from the given snapshot tree. It contains GC state, deleted nodes and\n * tombstones. The GC state may be written into multiple blobs. Merge the GC state from all such blobs into one.\n */\nexport async function getGCDataFromSnapshot(\n\tgcSnapshotTree: ISnapshotTree,\n\treadAndParseBlob: <T>(id: string) => Promise<T>,\n): Promise<IGarbageCollectionSnapshotData> {\n\tlet rootGCState: IGarbageCollectionState = { gcNodes: {} };\n\tlet tombstones: string[] | undefined;\n\tlet deletedNodes: string[] | undefined;\n\tfor (const key of Object.keys(gcSnapshotTree.blobs)) {\n\t\t// Update deleted nodes blob.\n\t\tif (key === gcDeletedBlobKey) {\n\t\t\tdeletedNodes = await readAndParseBlob<string[]>(gcSnapshotTree.blobs[key]);\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Update tombstone blob.\n\t\tif (key === gcTombstoneBlobKey) {\n\t\t\ttombstones = await readAndParseBlob<string[]>(gcSnapshotTree.blobs[key]);\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Skip blobs that do not start with the GC prefix.\n\t\tif (!key.startsWith(gcBlobPrefix)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst blobId = gcSnapshotTree.blobs[key];\n\t\tif (blobId === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst gcState = await readAndParseBlob<IGarbageCollectionState>(blobId);\n\t\tassert(gcState !== undefined, 0x5d8 /* GC blob missing from snapshot */);\n\t\t// Merge the GC state of this blob into the root GC state.\n\t\trootGCState = concatGarbageCollectionStates(rootGCState, gcState);\n\t}\n\treturn { gcState: rootGCState, tombstones, deletedNodes };\n}\n\n/**\n * Helper function that unpacks the GC details of the children from a given node's GC details.\n * @param gcDetails - The GC details of a node.\n * @returns A map of GC details of each children of the the given node.\n */\nexport function unpackChildNodesGCDetails(gcDetails: IGarbageCollectionDetailsBase) {\n\tconst childGCDetailsMap: Map<string, IGarbageCollectionDetailsBase> = new Map();\n\n\t// If GC data is not available, bail out.\n\tif (gcDetails.gcData === undefined) {\n\t\treturn childGCDetailsMap;\n\t}\n\n\tconst gcNodes = gcDetails.gcData.gcNodes;\n\tfor (const [id, outboundRoutes] of Object.entries(gcNodes)) {\n\t\t// Skip self-node since only children GC data is to be generated.\n\t\tif (id === \"/\") {\n\t\t\tcontinue;\n\t\t}\n\n\t\tassert(id.startsWith(\"/\"), 0x5d9 /* node id should always be an absolute route */);\n\t\tconst childId = id.split(\"/\")[1];\n\t\tlet childGCNodeId = id.slice(childId.length + 1);\n\t\t// GC node id always begins with \"/\". Handle the special case where a child's id in the parent's GC nodes is\n\t\t// of format `/root`. In this case, the childId is root and childGCNodeId is \"\". Make childGCNodeId = \"/\".\n\t\tif (childGCNodeId === \"\") {\n\t\t\tchildGCNodeId = \"/\";\n\t\t}\n\n\t\tlet childGCDetails = childGCDetailsMap.get(childId);\n\t\tif (childGCDetails === undefined) {\n\t\t\tchildGCDetails = { gcData: { gcNodes: {} }, usedRoutes: [] };\n\t\t}\n\t\t// gcData should not undefined as its always at least initialized as empty above.\n\t\tassert(\n\t\t\tchildGCDetails.gcData !== undefined,\n\t\t\t0x5da /* Child GC data should have been initialized */,\n\t\t);\n\t\tchildGCDetails.gcData.gcNodes[childGCNodeId] = [...new Set(outboundRoutes)];\n\t\tchildGCDetailsMap.set(childId, childGCDetails);\n\t}\n\n\tif (gcDetails.usedRoutes === undefined) {\n\t\treturn childGCDetailsMap;\n\t}\n\n\t// Remove the node's self used route, if any, and generate the children used routes.\n\tconst usedRoutes = gcDetails.usedRoutes.filter((route) => route !== \"\" && route !== \"/\");\n\tfor (const route of usedRoutes) {\n\t\tassert(route.startsWith(\"/\"), 0x5db /* Used route should always be an absolute route */);\n\t\tconst childId = route.split(\"/\")[1];\n\t\tconst childUsedRoute = route.slice(childId.length + 1);\n\n\t\tconst childGCDetails = childGCDetailsMap.get(childId);\n\t\tassert(\n\t\t\tchildGCDetails?.usedRoutes !== undefined,\n\t\t\t0x5dc /* This should have be initialized when generate GC nodes above */,\n\t\t);\n\n\t\tchildGCDetails.usedRoutes.push(childUsedRoute);\n\t\tchildGCDetailsMap.set(childId, childGCDetails);\n\t}\n\treturn childGCDetailsMap;\n}\n\n/**\n * Trims the leading and trailing slashes from the given string.\n * @param str - A string that may contain leading and / or trailing slashes.\n * @returns A new string without leading and trailing slashes.\n */\nexport function trimLeadingAndTrailingSlashes(str: string) {\n\treturn str.replace(/^\\/+|\\/+$/g, \"\");\n}\n\n/**\n * Utility to implement compat behaviors given an unknown message type\n * The parameters are typed to support compile-time enforcement of handling all known types/behaviors\n *\n * @param _unknownGCMessageType - Typed as never to ensure all known types have been\n * handled before calling this function (e.g. in a switch statement).\n * @param compatBehavior - Typed redundantly with CompatModeBehavior to ensure handling is added when updating that type\n */\nexport function compatBehaviorAllowsGCMessageType(\n\t_unknownGCMessageType: never,\n\tcompatBehavior: \"Ignore\" | \"FailToProcess\" | undefined,\n): boolean {\n\t// undefined defaults to same behavior as \"FailToProcess\"\n\treturn compatBehavior === \"Ignore\";\n}\n"]}
|
package/dist/gc/gcTelemetry.d.ts
CHANGED
|
@@ -79,11 +79,6 @@ export declare class GCTelemetryTracker {
|
|
|
79
79
|
* so that the state of an unreferenced node is updated.
|
|
80
80
|
*/
|
|
81
81
|
logPendingEvents(logger: ITelemetryLoggerExt): Promise<void>;
|
|
82
|
-
/**
|
|
83
|
-
* For nodes that are ready to sweep, log an event for now. Until we start running sweep which deletes objects,
|
|
84
|
-
* this will give us a view into how much deleted content a container has.
|
|
85
|
-
*/
|
|
86
|
-
logSweepEvents(logger: ITelemetryLoggerExt, currentReferenceTimestampMs: number, unreferencedNodesState: Map<string, UnreferencedStateTracker>, completedGCRuns: number, lastSummaryTime?: number): void;
|
|
87
82
|
}
|
|
88
83
|
/**
|
|
89
84
|
* Consolidates info / logic for logging when we encounter unexpected usage of GC'd objects. For example, when a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gcTelemetry.d.ts","sourceRoot":"","sources":["../../src/gc/gcTelemetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAEN,mBAAmB,EACnB,iBAAiB,EAEjB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,M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 @@ class GCTelemetryTracker {
|
|
|
68
68
|
}
|
|
69
69
|
const nodeStateTracker = this.getNodeStateTracker(nodeUsageProps.id);
|
|
70
70
|
const nodeType = this.getNodeType(nodeUsageProps.id);
|
|
71
|
+
const timeout = (() => {
|
|
72
|
+
switch (nodeStateTracker?.state) {
|
|
73
|
+
case gcDefinitions_1.UnreferencedState.Inactive:
|
|
74
|
+
return this.configs.inactiveTimeoutMs;
|
|
75
|
+
case gcDefinitions_1.UnreferencedState.TombstoneReady:
|
|
76
|
+
return this.configs.sweepTimeoutMs;
|
|
77
|
+
case gcDefinitions_1.UnreferencedState.SweepReady:
|
|
78
|
+
return (this.configs.sweepTimeoutMs &&
|
|
79
|
+
this.configs.sweepTimeoutMs + this.configs.sweepGracePeriodMs);
|
|
80
|
+
default:
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
})();
|
|
71
84
|
const { usageType, currentReferenceTimestampMs, packagePath, id: untaggedId, fromId: untaggedFromId, ...propsToLog } = nodeUsageProps;
|
|
72
85
|
const { persistedGcFeatureMatrix, ...configs } = this.configs;
|
|
73
86
|
const unrefEventProps = {
|
|
@@ -77,9 +90,7 @@ class GCTelemetryTracker {
|
|
|
77
90
|
? nodeUsageProps.currentReferenceTimestampMs -
|
|
78
91
|
nodeStateTracker.unreferencedTimestampMs
|
|
79
92
|
: -1,
|
|
80
|
-
timeout
|
|
81
|
-
? this.configs.inactiveTimeoutMs
|
|
82
|
-
: this.configs.sweepTimeoutMs,
|
|
93
|
+
timeout,
|
|
83
94
|
...(0, telemetry_utils_1.tagCodeArtifacts)({ id: untaggedId, fromId: untaggedFromId }),
|
|
84
95
|
...propsToLog,
|
|
85
96
|
...this.createContainerMetadata,
|
|
@@ -275,45 +286,6 @@ class GCTelemetryTracker {
|
|
|
275
286
|
}
|
|
276
287
|
this.pendingEventsQueue = [];
|
|
277
288
|
}
|
|
278
|
-
/**
|
|
279
|
-
* For nodes that are ready to sweep, log an event for now. Until we start running sweep which deletes objects,
|
|
280
|
-
* this will give us a view into how much deleted content a container has.
|
|
281
|
-
*/
|
|
282
|
-
logSweepEvents(logger, currentReferenceTimestampMs, unreferencedNodesState, completedGCRuns, lastSummaryTime) {
|
|
283
|
-
if (this.mc.config.getBoolean(gcDefinitions_1.disableSweepLogKey) === true ||
|
|
284
|
-
this.configs.sweepTimeoutMs === undefined) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
const deletedNodeIds = [];
|
|
288
|
-
for (const [nodeId, nodeStateTracker] of unreferencedNodesState) {
|
|
289
|
-
if (nodeStateTracker.state !== gcDefinitions_1.UnreferencedState.SweepReady) {
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
const nodeType = this.getNodeType(nodeId);
|
|
293
|
-
if (nodeType !== gcDefinitions_1.GCNodeType.DataStore && nodeType !== gcDefinitions_1.GCNodeType.Blob) {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
// Log deleted event for each node only once to reduce noise in telemetry.
|
|
297
|
-
const uniqueEventId = `Deleted-${nodeId}`;
|
|
298
|
-
if (this.loggedUnreferencedEvents.has(uniqueEventId)) {
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
this.loggedUnreferencedEvents.add(uniqueEventId);
|
|
302
|
-
deletedNodeIds.push(nodeId);
|
|
303
|
-
}
|
|
304
|
-
if (deletedNodeIds.length > 0) {
|
|
305
|
-
logger.sendTelemetryEvent({
|
|
306
|
-
eventName: "GC_SweepReadyObjects_Delete",
|
|
307
|
-
details: JSON.stringify({
|
|
308
|
-
timeout: this.configs.sweepTimeoutMs,
|
|
309
|
-
completedGCRuns,
|
|
310
|
-
lastSummaryTime,
|
|
311
|
-
...this.createContainerMetadata,
|
|
312
|
-
}),
|
|
313
|
-
...(0, telemetry_utils_1.tagCodeArtifacts)({ id: JSON.stringify(deletedNodeIds) }),
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
289
|
}
|
|
318
290
|
exports.GCTelemetryTracker = GCTelemetryTracker;
|
|
319
291
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gcTelemetry.js","sourceRoot":"","sources":["../../src/gc/gcTelemetry.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,qEAKyC;AAGzC,mDAUyB;AA2CzB;;;;;;;;GAQG;AACH,MAAa,kBAAkB;IAO9B,YACkB,EAAqB,EACrB,OAAiC,EACjC,kBAA2B,EAC3B,uBAAiD,EACjD,WAA2C,EAC3C,mBAEwB,EACxB,kBAE0B;QAV1B,OAAE,GAAF,EAAE,CAAmB;QACrB,YAAO,GAAP,OAAO,CAA0B;QACjC,uBAAkB,GAAlB,kBAAkB,CAAS;QAC3B,4BAAuB,GAAvB,uBAAuB,CAA0B;QACjD,gBAAW,GAAX,WAAW,CAAgC;QAC3C,wBAAmB,GAAnB,mBAAmB,CAEK;QACxB,uBAAkB,GAAlB,kBAAkB,CAEQ;QAjB5C,iHAAiH;QACjH,sBAAsB;QACL,6BAAwB,GAAgB,IAAI,GAAG,EAAE,CAAC;QACnE,6EAA6E;QACrE,uBAAkB,GAA8B,EAAE,CAAC;IAcxD,CAAC;IAEJ;;;;;OAKG;IACK,uBAAuB,CAC9B,QAAoB,EACpB,SAAwB,EACxB,gBAA0C,EAC1C,aAAqB;QAErB,IAAI,gBAAgB,CAAC,KAAK,KAAK,iCAAiB,CAAC,MAAM,EAAE;YACxD,OAAO,KAAK,CAAC;SACb;QAED,IAAI,QAAQ,KAAK,0BAAU,CAAC,KAAK,EAAE;YAClC,OAAO,KAAK,CAAC;SACb;QAED,4FAA4F;QAC5F,oDAAoD;QACpD,IAAI,QAAQ,KAAK,0BAAU,CAAC,YAAY,IAAI,SAAS,KAAK,SAAS,EAAE;YACpE,OAAO,KAAK,CAAC;SACb;QAED,+FAA+F;QAC/F,yFAAyF;QACzF,IAAI,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;YACrD,OAAO,KAA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AU,CAAC,wCAAwB,CAAC;QACrE,oBAAoB,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,+CAA+B,CAAC;KAC3E,CAAC,CAAC;IACH,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC;QACjC,eAAe,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,2BAAW,CAAC;KAClD,CAAC,CAAC;IAEH,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC5C,CAAC;AApBD,gEAoBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryGenericEvent } from \"@fluidframework/core-interfaces\";\nimport { IGarbageCollectionData } from \"@fluidframework/runtime-definitions\";\nimport {\n\tgenerateStack,\n\tITelemetryLoggerExt,\n\tMonitoringContext,\n\ttagCodeArtifacts,\n} from \"@fluidframework/telemetry-utils\";\nimport { RuntimeHeaderData } from \"../containerRuntime\";\nimport { ICreateContainerMetadata } from \"../summary\";\nimport {\n\tdisableSweepLogKey,\n\tGCNodeType,\n\tUnreferencedState,\n\tIGarbageCollectorConfigs,\n\tdisableTombstoneKey,\n\tthrowOnTombstoneUsageKey,\n\tthrowOnTombstoneLoadOverrideKey,\n\trunSweepKey,\n\tGCFeatureMatrix,\n} from \"./gcDefinitions\";\nimport { UnreferencedStateTracker } from \"./gcUnreferencedStateTracker\";\n\ntype NodeUsageType = \"Changed\" | \"Loaded\" | \"Revived\";\n\n/** Properties that are common to IUnreferencedEventProps and INodeUsageProps */\ninterface ICommonProps {\n\tusageType: NodeUsageType;\n\tcompletedGCRuns: number;\n\tisTombstoned: boolean;\n\tlastSummaryTime?: number;\n\theaders?: RuntimeHeaderData;\n}\n\n/** The event that is logged when unreferenced node is used after a certain time. */\ninterface IUnreferencedEventProps extends ICreateContainerMetadata, ICommonProps {\n\tstate: UnreferencedState;\n\tid: {\n\t\tvalue: string;\n\t\ttag: string;\n\t};\n\ttype: GCNodeType;\n\tunrefTime: number;\n\tage: number;\n\t// Expanding GC feature matrix. Without doing this, the configs cannot be logged in telemetry directly.\n\tgcConfigs: Omit<IGarbageCollectorConfigs, \"persistedGcFeatureMatrix\"> & {\n\t\t[K in keyof GCFeatureMatrix]: GCFeatureMatrix[K];\n\t};\n\ttimeout?: number;\n\tfromId?: {\n\t\tvalue: string;\n\t\ttag: string;\n\t};\n}\n\n/** Properties passed to nodeUsed function when a node is used. */\ninterface INodeUsageProps extends ICommonProps {\n\tid: string;\n\tcurrentReferenceTimestampMs: number | undefined;\n\tpackagePath: readonly string[] | undefined;\n\tfromId?: string;\n}\n\n/**\n * Encapsulates the logic that tracks the various telemetry logged by the Garbage Collector. There are 4 types of\n * telemetry logged:\n * 1. inactiveObject telemetry - When an inactive node is used - A node that has been unreferenced for inactiveTimeoutMs.\n * 2. sweepReadyObject telemetry - When a sweep ready node is used - A node that has been unreferenced for sweepTimeoutMs.\n * 3. Tombstone telemetry - When a tombstoned node is used - A node that that has been marked as tombstone.\n * 4. Sweep / deleted telemetry - When a node is detected as sweep ready in the sweep phase.\n * 5. Unknown outbound reference telemetry - When a node is referenced but GC is not explicitly notified of it.\n */\nexport class GCTelemetryTracker {\n\t// Keeps track of unreferenced events that are logged for a node. This is used to limit the log generation to one\n\t// per event per node.\n\tprivate readonly loggedUnreferencedEvents: Set<string> = new Set();\n\t// Queue for unreferenced events that should be logged the next time GC runs.\n\tprivate pendingEventsQueue: IUnreferencedEventProps[] = [];\n\n\tconstructor(\n\t\tprivate readonly mc: MonitoringContext,\n\t\tprivate readonly configs: IGarbageCollectorConfigs,\n\t\tprivate readonly isSummarizerClient: boolean,\n\t\tprivate readonly createContainerMetadata: ICreateContainerMetadata,\n\t\tprivate readonly getNodeType: (nodeId: string) => GCNodeType,\n\t\tprivate readonly getNodeStateTracker: (\n\t\t\tnodeId: string,\n\t\t) => UnreferencedStateTracker | undefined,\n\t\tprivate readonly getNodePackagePath: (\n\t\t\tnodePath: string,\n\t\t) => Promise<readonly string[] | undefined>,\n\t) {}\n\n\t/**\n\t * Returns whether an event should be logged for a node that isn't active anymore. This does not apply to\n\t * tombstoned nodes for which an event is always logged. Some scenarios where we won't log:\n\t * 1. When a DDS is changed. The corresponding data store's event will be logged instead.\n\t * 2. An event is logged only once per container instance per event per node.\n\t */\n\tprivate shouldLogNonActiveEvent(\n\t\tnodeType: GCNodeType,\n\t\tusageType: NodeUsageType,\n\t\tnodeStateTracker: UnreferencedStateTracker,\n\t\tuniqueEventId: string,\n\t) {\n\t\tif (nodeStateTracker.state === UnreferencedState.Active) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (nodeType === GCNodeType.Other) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// For sub data store (DDS) nodes, if they are changed, its data store will also be changed,\n\t\t// so skip logging to make the telemetry less noisy.\n\t\tif (nodeType === GCNodeType.SubDataStore && usageType === \"Changed\") {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Non-tombstone events are logged once per event per node. A unique id is generated by joining\n\t\t// node state (inactive / sweep ready), node's id and usage (loaded / changed / revived).\n\t\tif (this.loggedUnreferencedEvents.has(uniqueEventId)) {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Called when a node is used. If the node is not active or tombstoned, log telemetry indicating object is used\n\t * when it should not have been.\n\t */\n\tpublic nodeUsed(nodeUsageProps: INodeUsageProps) {\n\t\t// If there is no reference timestamp to work with, no ops have been processed after creation. If so, skip\n\t\t// logging as nothing interesting would have happened worth logging.\n\t\tif (nodeUsageProps.currentReferenceTimestampMs === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst nodeStateTracker = this.getNodeStateTracker(nodeUsageProps.id);\n\t\tconst nodeType = this.getNodeType(nodeUsageProps.id);\n\t\tconst {\n\t\t\tusageType,\n\t\t\tcurrentReferenceTimestampMs,\n\t\t\tpackagePath,\n\t\t\tid: untaggedId,\n\t\t\tfromId: untaggedFromId,\n\t\t\t...propsToLog\n\t\t} = nodeUsageProps;\n\t\tconst { persistedGcFeatureMatrix, ...configs } = this.configs;\n\t\tconst unrefEventProps: Omit<IUnreferencedEventProps, \"state\" | \"usageType\"> = {\n\t\t\ttype: nodeType,\n\t\t\tunrefTime: nodeStateTracker?.unreferencedTimestampMs ?? -1,\n\t\t\tage:\n\t\t\t\tnodeStateTracker !== undefined\n\t\t\t\t\t? nodeUsageProps.currentReferenceTimestampMs -\n\t\t\t\t\t nodeStateTracker.unreferencedTimestampMs\n\t\t\t\t\t: -1,\n\t\t\ttimeout:\n\t\t\t\tnodeStateTracker?.state === UnreferencedState.Inactive\n\t\t\t\t\t? this.configs.inactiveTimeoutMs\n\t\t\t\t\t: this.configs.sweepTimeoutMs,\n\t\t\t...tagCodeArtifacts({ id: untaggedId, fromId: untaggedFromId }),\n\t\t\t...propsToLog,\n\t\t\t...this.createContainerMetadata,\n\t\t\tgcConfigs: { ...configs, ...persistedGcFeatureMatrix },\n\t\t};\n\n\t\t// If the node that is used is tombstoned, log a tombstone telemetry.\n\t\t// Note that this is done before checking if \"nodeStateTracker\" is undefined below because unreferenced\n\t\t// tracking may not have yet been enabled. That happens only after the client transitions to write mode.\n\t\tif (nodeUsageProps.isTombstoned) {\n\t\t\tthis.logTombstoneUsageTelemetry(nodeUsageProps, unrefEventProps, nodeType, usageType);\n\t\t}\n\n\t\t// After logging tombstone telemetry, if the node's unreferenced state is not tracked, there is nothing\n\t\t// else to log.\n\t\tif (nodeStateTracker === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst state = nodeStateTracker.state;\n\t\tconst uniqueEventId = `${state}-${nodeUsageProps.id}-${nodeUsageProps.usageType}`;\n\n\t\tif (\n\t\t\t!this.shouldLogNonActiveEvent(\n\t\t\t\tnodeType,\n\t\t\t\tnodeUsageProps.usageType,\n\t\t\t\tnodeStateTracker,\n\t\t\t\tuniqueEventId,\n\t\t\t)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Add the unique event id so that we don't generate a log for this event again in this session.\n\t\tthis.loggedUnreferencedEvents.add(uniqueEventId);\n\n\t\t// For summarizer client, queue the event so it is logged the next time GC runs if the event is still valid.\n\t\t// For non-summarizer client, log the event now since GC won't run on it. This may result in false positives\n\t\t// but it's a good signal nonetheless and we can consume it with a grain of salt.\n\t\t// Inactive errors are usages of Objects that are unreferenced for at least a period of 7 days.\n\t\t// SweepReady errors are usages of Objects that will be deleted by GC Sweep!\n\t\tif (this.isSummarizerClient) {\n\t\t\tthis.pendingEventsQueue.push({\n\t\t\t\t...unrefEventProps,\n\t\t\t\tusageType: nodeUsageProps.usageType,\n\t\t\t\tstate,\n\t\t\t});\n\t\t} else {\n\t\t\t// For non-summarizer clients, only log \"Loaded\" type events since these objects may not be loaded in the\n\t\t\t// summarizer clients if they are based off of user actions (such as scrolling to content for these objects)\n\t\t\t// Events generated:\n\t\t\t// InactiveObject_Loaded, SweepReadyObject_Loaded\n\t\t\tif (nodeUsageProps.usageType === \"Loaded\") {\n\t\t\t\tconst { id, fromId, headers, gcConfigs, ...detailedProps } = unrefEventProps;\n\t\t\t\tconst event = {\n\t\t\t\t\teventName: `${state}Object_${nodeUsageProps.usageType}`,\n\t\t\t\t\t...tagCodeArtifacts({ pkg: nodeUsageProps.packagePath?.join(\"/\") }),\n\t\t\t\t\tstack: generateStack(),\n\t\t\t\t\tid,\n\t\t\t\t\tfromId,\n\t\t\t\t\theaders: { ...headers },\n\t\t\t\t\tdetails: detailedProps,\n\t\t\t\t\tgcConfigs,\n\t\t\t\t};\n\n\t\t\t\t// Do not log the inactive object x events as error events as they are not the best signal for\n\t\t\t\t// detecting something wrong with GC either from the partner or from the runtime itself.\n\t\t\t\tif (state === UnreferencedState.Inactive) {\n\t\t\t\t\tthis.mc.logger.sendTelemetryEvent(event);\n\t\t\t\t} else {\n\t\t\t\t\tthis.mc.logger.sendErrorEvent(event);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Logs telemetry when a tombstoned object is changed, revived or loaded.\n\t */\n\tprivate logTombstoneUsageTelemetry(\n\t\tnodeUsageProps: INodeUsageProps,\n\t\tunrefEventProps: Omit<IUnreferencedEventProps, \"state\" | \"usageType\">,\n\t\tnodeType: GCNodeType,\n\t\tusageType: NodeUsageType,\n\t) {\n\t\t// This will log the following events:\n\t\t// GC_Tombstone_DataStore_Requested, GC_Tombstone_DataStore_Changed, GC_Tombstone_DataStore_Revived\n\t\t// GC_Tombstone_SubDataStore_Requested, GC_Tombstone_SubDataStore_Changed, GC_Tombstone_SubDataStore_Revived\n\t\t// GC_Tombstone_Blob_Requested, GC_Tombstone_Blob_Changed, GC_Tombstone_Blob_Revived\n\t\tconst { id, fromId, headers, gcConfigs, ...detailedProps } = unrefEventProps;\n\t\tconst eventUsageName = usageType === \"Loaded\" ? \"Requested\" : usageType;\n\t\tconst event = {\n\t\t\teventName: `GC_Tombstone_${nodeType}_${eventUsageName}`,\n\t\t\tpkg: tagCodeArtifacts({ pkg: nodeUsageProps.packagePath?.join(\"/\") }).pkg,\n\t\t\tstack: generateStack(),\n\t\t\tid,\n\t\t\tfromId,\n\t\t\theaders: { ...headers },\n\t\t\tdetails: detailedProps,\n\t\t\tgcConfigs,\n\t\t\ttombstoneFlags: {\n\t\t\t\tDisableTombstone: this.mc.config.getBoolean(disableTombstoneKey),\n\t\t\t\tThrowOnTombstoneUsage: this.mc.config.getBoolean(throwOnTombstoneUsageKey),\n\t\t\t\tThrowOnTombstoneLoad: this.mc.config.getBoolean(throwOnTombstoneLoadOverrideKey),\n\t\t\t},\n\t\t\tsweepFlags: {\n\t\t\t\tEnableSweepFlag: this.mc.config.getBoolean(runSweepKey),\n\t\t\t},\n\t\t};\n\n\t\tif (\n\t\t\t(usageType === \"Loaded\" &&\n\t\t\t\tthis.configs.throwOnTombstoneLoad &&\n\t\t\t\t!headers?.allowTombstone) ||\n\t\t\t(usageType === \"Changed\" && this.configs.throwOnTombstoneUsage)\n\t\t) {\n\t\t\tthis.mc.logger.sendErrorEvent(event);\n\t\t} else {\n\t\t\tthis.mc.logger.sendTelemetryEvent(event);\n\t\t}\n\t}\n\n\t/**\n\t * Log all new references or outbound routes in the current graph that haven't been explicitly notified to GC.\n\t * The principle is that every new reference or outbound route must be notified to GC via the\n\t * addedOutboundReference method. It it hasn't, its a bug and we want to identify these scenarios.\n\t *\n\t * In more simple terms:\n\t * Missing Explicit References = Current References - Previous References - Explicitly Added References;\n\t *\n\t * @param currentGCData - The GC data (reference graph) from the current GC run.\n\t * @param previousGCData - The GC data (reference graph) from the previous GC run.\n\t * @param explicitReferences - New references added explicity between the previous and the current run.\n\t */\n\tpublic logIfMissingExplicitReferences(\n\t\tcurrentGCData: IGarbageCollectionData,\n\t\tpreviousGCData: IGarbageCollectionData,\n\t\texplicitReferences: Map<string, string[]>,\n\t\tlogger: ITelemetryLoggerExt,\n\t) {\n\t\tfor (const [nodeId, currentOutboundRoutes] of Object.entries(currentGCData.gcNodes)) {\n\t\t\tconst previousRoutes = previousGCData.gcNodes[nodeId] ?? [];\n\t\t\tconst explicitRoutes = explicitReferences.get(nodeId) ?? [];\n\n\t\t\t/**\n\t\t\t * 1. For routes in the current GC data, routes that were not present in previous GC data and did not have\n\t\t\t * explicit references should be added to missing explicit routes list.\n\t\t\t * 2. Only include data store and blob routes since GC only works for these two.\n\t\t\t * Note: Due to a bug with de-duped blobs, only adding data store routes for now.\n\t\t\t * 3. Ignore DDS routes to their parent datastores since those were added implicitly. So, there won't be\n\t\t\t * explicit routes to them.\n\t\t\t */\n\t\t\tconst missingExplicitRoutes: string[] = [];\n\t\t\tfor (const route of currentOutboundRoutes) {\n\t\t\t\tconst nodeType = this.getNodeType(route);\n\t\t\t\tif (\n\t\t\t\t\t(nodeType === GCNodeType.DataStore || nodeType === GCNodeType.Blob) &&\n\t\t\t\t\t!nodeId.startsWith(route) &&\n\t\t\t\t\t!previousRoutes.includes(route) &&\n\t\t\t\t\t!explicitRoutes.includes(route)\n\t\t\t\t) {\n\t\t\t\t\tmissingExplicitRoutes.push(route);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (missingExplicitRoutes.length > 0) {\n\t\t\t\tlogger.sendErrorEvent({\n\t\t\t\t\teventName: \"gcUnknownOutboundReferences\",\n\t\t\t\t\t...tagCodeArtifacts({\n\t\t\t\t\t\tid: nodeId,\n\t\t\t\t\t\troutes: JSON.stringify(missingExplicitRoutes),\n\t\t\t\t\t}),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Log events that are pending in pendingEventsQueue. This is called after GC runs in the summarizer client\n\t * so that the state of an unreferenced node is updated.\n\t */\n\tpublic async logPendingEvents(logger: ITelemetryLoggerExt) {\n\t\t// Events sent come only from the summarizer client. In between summaries, events are pushed to a queue and at\n\t\t// summary time they are then logged.\n\t\t// Events generated:\n\t\t// InactiveObject_Loaded, InactiveObject_Changed, InactiveObject_Revived\n\t\t// SweepReadyObject_Loaded, SweepReadyObject_Changed, SweepReadyObject_Revived\n\t\tfor (const eventProps of this.pendingEventsQueue) {\n\t\t\t// const { usageType, state, id, fromId, ...propsToLog } = eventProps;\n\t\t\tconst { usageType, state, id, fromId, headers, gcConfigs, ...detailedProps } =\n\t\t\t\teventProps;\n\t\t\t/**\n\t\t\t * Revived event is logged only if the node is active. If the node is not active, the reference to it was\n\t\t\t * from another unreferenced node and this scenario is not interesting to log.\n\t\t\t * Loaded and Changed events are logged only if the node is not active. If the node is active, it was\n\t\t\t * revived and a Revived event will be logged for it.\n\t\t\t */\n\t\t\tconst nodeStateTracker = this.getNodeStateTracker(eventProps.id.value);\n\t\t\tconst active =\n\t\t\t\tnodeStateTracker === undefined ||\n\t\t\t\tnodeStateTracker.state === UnreferencedState.Active;\n\t\t\tif ((usageType === \"Revived\") === active) {\n\t\t\t\tconst pkg = await this.getNodePackagePath(eventProps.id.value);\n\t\t\t\tconst fromPkg = eventProps.fromId\n\t\t\t\t\t? await this.getNodePackagePath(eventProps.fromId.value)\n\t\t\t\t\t: undefined;\n\t\t\t\tconst event = {\n\t\t\t\t\teventName: `${state}Object_${usageType}`,\n\t\t\t\t\tid,\n\t\t\t\t\tfromId,\n\t\t\t\t\theaders: { ...headers },\n\t\t\t\t\tdetails: detailedProps,\n\t\t\t\t\tgcConfigs,\n\t\t\t\t\t...tagCodeArtifacts({\n\t\t\t\t\t\tpkg: pkg?.join(\"/\"),\n\t\t\t\t\t\tfromPkg: fromPkg?.join(\"/\"),\n\t\t\t\t\t}),\n\t\t\t\t};\n\n\t\t\t\tif (state === UnreferencedState.Inactive) {\n\t\t\t\t\tlogger.sendTelemetryEvent(event);\n\t\t\t\t} else {\n\t\t\t\t\tlogger.sendErrorEvent(event);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis.pendingEventsQueue = [];\n\t}\n\n\t/**\n\t * For nodes that are ready to sweep, log an event for now. Until we start running sweep which deletes objects,\n\t * this will give us a view into how much deleted content a container has.\n\t */\n\tpublic logSweepEvents(\n\t\tlogger: ITelemetryLoggerExt,\n\t\tcurrentReferenceTimestampMs: number,\n\t\tunreferencedNodesState: Map<string, UnreferencedStateTracker>,\n\t\tcompletedGCRuns: number,\n\t\tlastSummaryTime?: number,\n\t) {\n\t\tif (\n\t\t\tthis.mc.config.getBoolean(disableSweepLogKey) === true ||\n\t\t\tthis.configs.sweepTimeoutMs === undefined\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst deletedNodeIds: string[] = [];\n\t\tfor (const [nodeId, nodeStateTracker] of unreferencedNodesState) {\n\t\t\tif (nodeStateTracker.state !== UnreferencedState.SweepReady) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst nodeType = this.getNodeType(nodeId);\n\t\t\tif (nodeType !== GCNodeType.DataStore && nodeType !== GCNodeType.Blob) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Log deleted event for each node only once to reduce noise in telemetry.\n\t\t\tconst uniqueEventId = `Deleted-${nodeId}`;\n\t\t\tif (this.loggedUnreferencedEvents.has(uniqueEventId)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.loggedUnreferencedEvents.add(uniqueEventId);\n\t\t\tdeletedNodeIds.push(nodeId);\n\t\t}\n\n\t\tif (deletedNodeIds.length > 0) {\n\t\t\tlogger.sendTelemetryEvent({\n\t\t\t\teventName: \"GC_SweepReadyObjects_Delete\",\n\t\t\t\tdetails: JSON.stringify({\n\t\t\t\t\ttimeout: this.configs.sweepTimeoutMs,\n\t\t\t\t\tcompletedGCRuns,\n\t\t\t\t\tlastSummaryTime,\n\t\t\t\t\t...this.createContainerMetadata,\n\t\t\t\t}),\n\t\t\t\t...tagCodeArtifacts({ id: JSON.stringify(deletedNodeIds) }),\n\t\t\t});\n\t\t}\n\t}\n}\n\n/**\n * Consolidates info / logic for logging when we encounter unexpected usage of GC'd objects. For example, when a\n * tombstoned or deleted object is loaded.\n */\nexport function sendGCUnexpectedUsageEvent(\n\tmc: MonitoringContext,\n\tevent: ITelemetryGenericEvent & {\n\t\tcategory: \"error\" | \"generic\";\n\t\tgcTombstoneEnforcementAllowed: boolean | undefined;\n\t},\n\tpackagePath: readonly string[] | undefined,\n\terror?: unknown,\n) {\n\tevent.pkg = tagCodeArtifacts({ pkg: packagePath?.join(\"/\") })?.pkg;\n\tevent.tombstoneFlags = JSON.stringify({\n\t\tDisableTombstone: mc.config.getBoolean(disableTombstoneKey),\n\t\tThrowOnTombstoneUsage: mc.config.getBoolean(throwOnTombstoneUsageKey),\n\t\tThrowOnTombstoneLoad: mc.config.getBoolean(throwOnTombstoneLoadOverrideKey),\n\t});\n\tevent.sweepFlags = JSON.stringify({\n\t\tEnableSweepFlag: mc.config.getBoolean(runSweepKey),\n\t});\n\n\tmc.logger.sendTelemetryEvent(event, error);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"gcTelemetry.js","sourceRoot":"","sources":["../../src/gc/gcTelemetry.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,qEAKyC;AAGzC,mDASy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M,CAAC,UAAU,CAAC,mCAAmB,CAAC;QAC3D,qBAAqB,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,wCAAwB,CAAC;QACrE,oBAAoB,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,+CAA+B,CAAC;KAC3E,CAAC,CAAC;IACH,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC;QACjC,eAAe,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,2BAAW,CAAC;KAClD,CAAC,CAAC;IAEH,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC5C,CAAC;AApBD,gEAoBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryGenericEvent } from \"@fluidframework/core-interfaces\";\nimport { IGarbageCollectionData } from \"@fluidframework/runtime-definitions\";\nimport {\n\tgenerateStack,\n\tITelemetryLoggerExt,\n\tMonitoringContext,\n\ttagCodeArtifacts,\n} from \"@fluidframework/telemetry-utils\";\nimport { RuntimeHeaderData } from \"../containerRuntime\";\nimport { ICreateContainerMetadata } from \"../summary\";\nimport {\n\tGCNodeType,\n\tUnreferencedState,\n\tIGarbageCollectorConfigs,\n\tdisableTombstoneKey,\n\tthrowOnTombstoneUsageKey,\n\tthrowOnTombstoneLoadOverrideKey,\n\trunSweepKey,\n\tGCFeatureMatrix,\n} from \"./gcDefinitions\";\nimport { UnreferencedStateTracker } from \"./gcUnreferencedStateTracker\";\n\ntype NodeUsageType = \"Changed\" | \"Loaded\" | \"Revived\";\n\n/** Properties that are common to IUnreferencedEventProps and INodeUsageProps */\ninterface ICommonProps {\n\tusageType: NodeUsageType;\n\tcompletedGCRuns: number;\n\tisTombstoned: boolean;\n\tlastSummaryTime?: number;\n\theaders?: RuntimeHeaderData;\n}\n\n/** The event that is logged when unreferenced node is used after a certain time. */\ninterface IUnreferencedEventProps extends ICreateContainerMetadata, ICommonProps {\n\tstate: UnreferencedState;\n\tid: {\n\t\tvalue: string;\n\t\ttag: string;\n\t};\n\ttype: GCNodeType;\n\tunrefTime: number;\n\tage: number;\n\t// Expanding GC feature matrix. Without doing this, the configs cannot be logged in telemetry directly.\n\tgcConfigs: Omit<IGarbageCollectorConfigs, \"persistedGcFeatureMatrix\"> & {\n\t\t[K in keyof GCFeatureMatrix]: GCFeatureMatrix[K];\n\t};\n\ttimeout?: number;\n\tfromId?: {\n\t\tvalue: string;\n\t\ttag: string;\n\t};\n}\n\n/** Properties passed to nodeUsed function when a node is used. */\ninterface INodeUsageProps extends ICommonProps {\n\tid: string;\n\tcurrentReferenceTimestampMs: number | undefined;\n\tpackagePath: readonly string[] | undefined;\n\tfromId?: string;\n}\n\n/**\n * Encapsulates the logic that tracks the various telemetry logged by the Garbage Collector. There are 4 types of\n * telemetry logged:\n * 1. inactiveObject telemetry - When an inactive node is used - A node that has been unreferenced for inactiveTimeoutMs.\n * 2. sweepReadyObject telemetry - When a sweep ready node is used - A node that has been unreferenced for sweepTimeoutMs.\n * 3. Tombstone telemetry - When a tombstoned node is used - A node that that has been marked as tombstone.\n * 4. Sweep / deleted telemetry - When a node is detected as sweep ready in the sweep phase.\n * 5. Unknown outbound reference telemetry - When a node is referenced but GC is not explicitly notified of it.\n */\nexport class GCTelemetryTracker {\n\t// Keeps track of unreferenced events that are logged for a node. This is used to limit the log generation to one\n\t// per event per node.\n\tprivate readonly loggedUnreferencedEvents: Set<string> = new Set();\n\t// Queue for unreferenced events that should be logged the next time GC runs.\n\tprivate pendingEventsQueue: IUnreferencedEventProps[] = [];\n\n\tconstructor(\n\t\tprivate readonly mc: MonitoringContext,\n\t\tprivate readonly configs: IGarbageCollectorConfigs,\n\t\tprivate readonly isSummarizerClient: boolean,\n\t\tprivate readonly createContainerMetadata: ICreateContainerMetadata,\n\t\tprivate readonly getNodeType: (nodeId: string) => GCNodeType,\n\t\tprivate readonly getNodeStateTracker: (\n\t\t\tnodeId: string,\n\t\t) => UnreferencedStateTracker | undefined,\n\t\tprivate readonly getNodePackagePath: (\n\t\t\tnodePath: string,\n\t\t) => Promise<readonly string[] | undefined>,\n\t) {}\n\n\t/**\n\t * Returns whether an event should be logged for a node that isn't active anymore. This does not apply to\n\t * tombstoned nodes for which an event is always logged. Some scenarios where we won't log:\n\t * 1. When a DDS is changed. The corresponding data store's event will be logged instead.\n\t * 2. An event is logged only once per container instance per event per node.\n\t */\n\tprivate shouldLogNonActiveEvent(\n\t\tnodeType: GCNodeType,\n\t\tusageType: NodeUsageType,\n\t\tnodeStateTracker: UnreferencedStateTracker,\n\t\tuniqueEventId: string,\n\t) {\n\t\tif (nodeStateTracker.state === UnreferencedState.Active) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (nodeType === GCNodeType.Other) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// For sub data store (DDS) nodes, if they are changed, its data store will also be changed,\n\t\t// so skip logging to make the telemetry less noisy.\n\t\tif (nodeType === GCNodeType.SubDataStore && usageType === \"Changed\") {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Non-tombstone events are logged once per event per node. A unique id is generated by joining\n\t\t// node state (inactive / sweep ready), node's id and usage (loaded / changed / revived).\n\t\tif (this.loggedUnreferencedEvents.has(uniqueEventId)) {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Called when a node is used. If the node is not active or tombstoned, log telemetry indicating object is used\n\t * when it should not have been.\n\t */\n\tpublic nodeUsed(nodeUsageProps: INodeUsageProps) {\n\t\t// If there is no reference timestamp to work with, no ops have been processed after creation. If so, skip\n\t\t// logging as nothing interesting would have happened worth logging.\n\t\tif (nodeUsageProps.currentReferenceTimestampMs === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst nodeStateTracker = this.getNodeStateTracker(nodeUsageProps.id);\n\t\tconst nodeType = this.getNodeType(nodeUsageProps.id);\n\t\tconst timeout = (() => {\n\t\t\tswitch (nodeStateTracker?.state) {\n\t\t\t\tcase UnreferencedState.Inactive:\n\t\t\t\t\treturn this.configs.inactiveTimeoutMs;\n\t\t\t\tcase UnreferencedState.TombstoneReady:\n\t\t\t\t\treturn this.configs.sweepTimeoutMs;\n\t\t\t\tcase UnreferencedState.SweepReady:\n\t\t\t\t\treturn (\n\t\t\t\t\t\tthis.configs.sweepTimeoutMs &&\n\t\t\t\t\t\tthis.configs.sweepTimeoutMs + this.configs.sweepGracePeriodMs\n\t\t\t\t\t);\n\t\t\t\tdefault:\n\t\t\t\t\treturn undefined;\n\t\t\t}\n\t\t})();\n\t\tconst {\n\t\t\tusageType,\n\t\t\tcurrentReferenceTimestampMs,\n\t\t\tpackagePath,\n\t\t\tid: untaggedId,\n\t\t\tfromId: untaggedFromId,\n\t\t\t...propsToLog\n\t\t} = nodeUsageProps;\n\t\tconst { persistedGcFeatureMatrix, ...configs } = this.configs;\n\t\tconst unrefEventProps: Omit<IUnreferencedEventProps, \"state\" | \"usageType\"> = {\n\t\t\ttype: nodeType,\n\t\t\tunrefTime: nodeStateTracker?.unreferencedTimestampMs ?? -1,\n\t\t\tage:\n\t\t\t\tnodeStateTracker !== undefined\n\t\t\t\t\t? nodeUsageProps.currentReferenceTimestampMs -\n\t\t\t\t\t nodeStateTracker.unreferencedTimestampMs\n\t\t\t\t\t: -1,\n\t\t\ttimeout,\n\t\t\t...tagCodeArtifacts({ id: untaggedId, fromId: untaggedFromId }),\n\t\t\t...propsToLog,\n\t\t\t...this.createContainerMetadata,\n\t\t\tgcConfigs: { ...configs, ...persistedGcFeatureMatrix },\n\t\t};\n\n\t\t// If the node that is used is tombstoned, log a tombstone telemetry.\n\t\t// Note that this is done before checking if \"nodeStateTracker\" is undefined below because unreferenced\n\t\t// tracking may not have yet been enabled. That happens only after the client transitions to write mode.\n\t\tif (nodeUsageProps.isTombstoned) {\n\t\t\tthis.logTombstoneUsageTelemetry(nodeUsageProps, unrefEventProps, nodeType, usageType);\n\t\t}\n\n\t\t// After logging tombstone telemetry, if the node's unreferenced state is not tracked, there is nothing\n\t\t// else to log.\n\t\tif (nodeStateTracker === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst state = nodeStateTracker.state;\n\t\tconst uniqueEventId = `${state}-${nodeUsageProps.id}-${nodeUsageProps.usageType}`;\n\n\t\tif (\n\t\t\t!this.shouldLogNonActiveEvent(\n\t\t\t\tnodeType,\n\t\t\t\tnodeUsageProps.usageType,\n\t\t\t\tnodeStateTracker,\n\t\t\t\tuniqueEventId,\n\t\t\t)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Add the unique event id so that we don't generate a log for this event again in this session.\n\t\tthis.loggedUnreferencedEvents.add(uniqueEventId);\n\n\t\t// For summarizer client, queue the event so it is logged the next time GC runs if the event is still valid.\n\t\t// For non-summarizer client, log the event now since GC won't run on it. This may result in false positives\n\t\t// but it's a good signal nonetheless and we can consume it with a grain of salt.\n\t\t// Inactive errors are usages of Objects that are unreferenced for at least a period of 7 days.\n\t\t// SweepReady errors are usages of Objects that will be deleted by GC Sweep!\n\t\tif (this.isSummarizerClient) {\n\t\t\tthis.pendingEventsQueue.push({\n\t\t\t\t...unrefEventProps,\n\t\t\t\tusageType: nodeUsageProps.usageType,\n\t\t\t\tstate,\n\t\t\t});\n\t\t} else {\n\t\t\t// For non-summarizer clients, only log \"Loaded\" type events since these objects may not be loaded in the\n\t\t\t// summarizer clients if they are based off of user actions (such as scrolling to content for these objects)\n\t\t\t// Events generated:\n\t\t\t// InactiveObject_Loaded, SweepReadyObject_Loaded\n\t\t\tif (nodeUsageProps.usageType === \"Loaded\") {\n\t\t\t\tconst { id, fromId, headers, gcConfigs, ...detailedProps } = unrefEventProps;\n\t\t\t\tconst event = {\n\t\t\t\t\teventName: `${state}Object_${nodeUsageProps.usageType}`,\n\t\t\t\t\t...tagCodeArtifacts({ pkg: nodeUsageProps.packagePath?.join(\"/\") }),\n\t\t\t\t\tstack: generateStack(),\n\t\t\t\t\tid,\n\t\t\t\t\tfromId,\n\t\t\t\t\theaders: { ...headers },\n\t\t\t\t\tdetails: detailedProps,\n\t\t\t\t\tgcConfigs,\n\t\t\t\t};\n\n\t\t\t\t// Do not log the inactive object x events as error events as they are not the best signal for\n\t\t\t\t// detecting something wrong with GC either from the partner or from the runtime itself.\n\t\t\t\tif (state === UnreferencedState.Inactive) {\n\t\t\t\t\tthis.mc.logger.sendTelemetryEvent(event);\n\t\t\t\t} else {\n\t\t\t\t\tthis.mc.logger.sendErrorEvent(event);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Logs telemetry when a tombstoned object is changed, revived or loaded.\n\t */\n\tprivate logTombstoneUsageTelemetry(\n\t\tnodeUsageProps: INodeUsageProps,\n\t\tunrefEventProps: Omit<IUnreferencedEventProps, \"state\" | \"usageType\">,\n\t\tnodeType: GCNodeType,\n\t\tusageType: NodeUsageType,\n\t) {\n\t\t// This will log the following events:\n\t\t// GC_Tombstone_DataStore_Requested, GC_Tombstone_DataStore_Changed, GC_Tombstone_DataStore_Revived\n\t\t// GC_Tombstone_SubDataStore_Requested, GC_Tombstone_SubDataStore_Changed, GC_Tombstone_SubDataStore_Revived\n\t\t// GC_Tombstone_Blob_Requested, GC_Tombstone_Blob_Changed, GC_Tombstone_Blob_Revived\n\t\tconst { id, fromId, headers, gcConfigs, ...detailedProps } = unrefEventProps;\n\t\tconst eventUsageName = usageType === \"Loaded\" ? \"Requested\" : usageType;\n\t\tconst event = {\n\t\t\teventName: `GC_Tombstone_${nodeType}_${eventUsageName}`,\n\t\t\tpkg: tagCodeArtifacts({ pkg: nodeUsageProps.packagePath?.join(\"/\") }).pkg,\n\t\t\tstack: generateStack(),\n\t\t\tid,\n\t\t\tfromId,\n\t\t\theaders: { ...headers },\n\t\t\tdetails: detailedProps,\n\t\t\tgcConfigs,\n\t\t\ttombstoneFlags: {\n\t\t\t\tDisableTombstone: this.mc.config.getBoolean(disableTombstoneKey),\n\t\t\t\tThrowOnTombstoneUsage: this.mc.config.getBoolean(throwOnTombstoneUsageKey),\n\t\t\t\tThrowOnTombstoneLoad: this.mc.config.getBoolean(throwOnTombstoneLoadOverrideKey),\n\t\t\t},\n\t\t\tsweepFlags: {\n\t\t\t\tEnableSweepFlag: this.mc.config.getBoolean(runSweepKey),\n\t\t\t},\n\t\t};\n\n\t\tif (\n\t\t\t(usageType === \"Loaded\" &&\n\t\t\t\tthis.configs.throwOnTombstoneLoad &&\n\t\t\t\t!headers?.allowTombstone) ||\n\t\t\t(usageType === \"Changed\" && this.configs.throwOnTombstoneUsage)\n\t\t) {\n\t\t\tthis.mc.logger.sendErrorEvent(event);\n\t\t} else {\n\t\t\tthis.mc.logger.sendTelemetryEvent(event);\n\t\t}\n\t}\n\n\t/**\n\t * Log all new references or outbound routes in the current graph that haven't been explicitly notified to GC.\n\t * The principle is that every new reference or outbound route must be notified to GC via the\n\t * addedOutboundReference method. It it hasn't, its a bug and we want to identify these scenarios.\n\t *\n\t * In more simple terms:\n\t * Missing Explicit References = Current References - Previous References - Explicitly Added References;\n\t *\n\t * @param currentGCData - The GC data (reference graph) from the current GC run.\n\t * @param previousGCData - The GC data (reference graph) from the previous GC run.\n\t * @param explicitReferences - New references added explicity between the previous and the current run.\n\t */\n\tpublic logIfMissingExplicitReferences(\n\t\tcurrentGCData: IGarbageCollectionData,\n\t\tpreviousGCData: IGarbageCollectionData,\n\t\texplicitReferences: Map<string, string[]>,\n\t\tlogger: ITelemetryLoggerExt,\n\t) {\n\t\tfor (const [nodeId, currentOutboundRoutes] of Object.entries(currentGCData.gcNodes)) {\n\t\t\tconst previousRoutes = previousGCData.gcNodes[nodeId] ?? [];\n\t\t\tconst explicitRoutes = explicitReferences.get(nodeId) ?? [];\n\n\t\t\t/**\n\t\t\t * 1. For routes in the current GC data, routes that were not present in previous GC data and did not have\n\t\t\t * explicit references should be added to missing explicit routes list.\n\t\t\t * 2. Only include data store and blob routes since GC only works for these two.\n\t\t\t * Note: Due to a bug with de-duped blobs, only adding data store routes for now.\n\t\t\t * 3. Ignore DDS routes to their parent datastores since those were added implicitly. So, there won't be\n\t\t\t * explicit routes to them.\n\t\t\t */\n\t\t\tconst missingExplicitRoutes: string[] = [];\n\t\t\tfor (const route of currentOutboundRoutes) {\n\t\t\t\tconst nodeType = this.getNodeType(route);\n\t\t\t\tif (\n\t\t\t\t\t(nodeType === GCNodeType.DataStore || nodeType === GCNodeType.Blob) &&\n\t\t\t\t\t!nodeId.startsWith(route) &&\n\t\t\t\t\t!previousRoutes.includes(route) &&\n\t\t\t\t\t!explicitRoutes.includes(route)\n\t\t\t\t) {\n\t\t\t\t\tmissingExplicitRoutes.push(route);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (missingExplicitRoutes.length > 0) {\n\t\t\t\tlogger.sendErrorEvent({\n\t\t\t\t\teventName: \"gcUnknownOutboundReferences\",\n\t\t\t\t\t...tagCodeArtifacts({\n\t\t\t\t\t\tid: nodeId,\n\t\t\t\t\t\troutes: JSON.stringify(missingExplicitRoutes),\n\t\t\t\t\t}),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Log events that are pending in pendingEventsQueue. This is called after GC runs in the summarizer client\n\t * so that the state of an unreferenced node is updated.\n\t */\n\tpublic async logPendingEvents(logger: ITelemetryLoggerExt) {\n\t\t// Events sent come only from the summarizer client. In between summaries, events are pushed to a queue and at\n\t\t// summary time they are then logged.\n\t\t// Events generated:\n\t\t// InactiveObject_Loaded, InactiveObject_Changed, InactiveObject_Revived\n\t\t// SweepReadyObject_Loaded, SweepReadyObject_Changed, SweepReadyObject_Revived\n\t\tfor (const eventProps of this.pendingEventsQueue) {\n\t\t\t// const { usageType, state, id, fromId, ...propsToLog } = eventProps;\n\t\t\tconst { usageType, state, id, fromId, headers, gcConfigs, ...detailedProps } =\n\t\t\t\teventProps;\n\t\t\t/**\n\t\t\t * Revived event is logged only if the node is active. If the node is not active, the reference to it was\n\t\t\t * from another unreferenced node and this scenario is not interesting to log.\n\t\t\t * Loaded and Changed events are logged only if the node is not active. If the node is active, it was\n\t\t\t * revived and a Revived event will be logged for it.\n\t\t\t */\n\t\t\tconst nodeStateTracker = this.getNodeStateTracker(eventProps.id.value);\n\t\t\tconst active =\n\t\t\t\tnodeStateTracker === undefined ||\n\t\t\t\tnodeStateTracker.state === UnreferencedState.Active;\n\t\t\tif ((usageType === \"Revived\") === active) {\n\t\t\t\tconst pkg = await this.getNodePackagePath(eventProps.id.value);\n\t\t\t\tconst fromPkg = eventProps.fromId\n\t\t\t\t\t? await this.getNodePackagePath(eventProps.fromId.value)\n\t\t\t\t\t: undefined;\n\t\t\t\tconst event = {\n\t\t\t\t\teventName: `${state}Object_${usageType}`,\n\t\t\t\t\tid,\n\t\t\t\t\tfromId,\n\t\t\t\t\theaders: { ...headers },\n\t\t\t\t\tdetails: detailedProps,\n\t\t\t\t\tgcConfigs,\n\t\t\t\t\t...tagCodeArtifacts({\n\t\t\t\t\t\tpkg: pkg?.join(\"/\"),\n\t\t\t\t\t\tfromPkg: fromPkg?.join(\"/\"),\n\t\t\t\t\t}),\n\t\t\t\t};\n\n\t\t\t\tif (state === UnreferencedState.Inactive) {\n\t\t\t\t\tlogger.sendTelemetryEvent(event);\n\t\t\t\t} else {\n\t\t\t\t\tlogger.sendErrorEvent(event);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis.pendingEventsQueue = [];\n\t}\n}\n\n/**\n * Consolidates info / logic for logging when we encounter unexpected usage of GC'd objects. For example, when a\n * tombstoned or deleted object is loaded.\n */\nexport function sendGCUnexpectedUsageEvent(\n\tmc: MonitoringContext,\n\tevent: ITelemetryGenericEvent & {\n\t\tcategory: \"error\" | \"generic\";\n\t\tgcTombstoneEnforcementAllowed: boolean | undefined;\n\t},\n\tpackagePath: readonly string[] | undefined,\n\terror?: unknown,\n) {\n\tevent.pkg = tagCodeArtifacts({ pkg: packagePath?.join(\"/\") })?.pkg;\n\tevent.tombstoneFlags = JSON.stringify({\n\t\tDisableTombstone: mc.config.getBoolean(disableTombstoneKey),\n\t\tThrowOnTombstoneUsage: mc.config.getBoolean(throwOnTombstoneUsageKey),\n\t\tThrowOnTombstoneLoad: mc.config.getBoolean(throwOnTombstoneLoadOverrideKey),\n\t});\n\tevent.sweepFlags = JSON.stringify({\n\t\tEnableSweepFlag: mc.config.getBoolean(runSweepKey),\n\t});\n\n\tmc.logger.sendTelemetryEvent(event, error);\n}\n"]}
|
|
@@ -5,18 +5,22 @@
|
|
|
5
5
|
import { UnreferencedState } from "./gcDefinitions";
|
|
6
6
|
/**
|
|
7
7
|
* Helper class that tracks the state of an unreferenced node such as the time it was unreferenced and if it can
|
|
8
|
-
* be deleted by the sweep phase.
|
|
8
|
+
* be tombstoned or deleted by the sweep phase.
|
|
9
9
|
*/
|
|
10
10
|
export declare class UnreferencedStateTracker {
|
|
11
11
|
readonly unreferencedTimestampMs: number;
|
|
12
12
|
/** The time after which node transitions to Inactive state. */
|
|
13
13
|
private readonly inactiveTimeoutMs;
|
|
14
|
-
/** The time after which node transitions to
|
|
15
|
-
private readonly
|
|
14
|
+
/** The time after which node transitions to TombstoneReady state; undefined if session expiry is disabled. */
|
|
15
|
+
private readonly tombstoneTimeoutMs;
|
|
16
|
+
/** The delay from TombstoneReady to SweepReady (only applies if tombstoneTimeoutMs is defined) */
|
|
17
|
+
private readonly sweepGracePeriodMs;
|
|
16
18
|
private _state;
|
|
17
19
|
get state(): UnreferencedState;
|
|
18
20
|
/** Timer to indicate when an unreferenced object is considered Inactive */
|
|
19
21
|
private readonly inactiveTimer;
|
|
22
|
+
/** Timer to indicate when an unreferenced object is Tombstone-Ready */
|
|
23
|
+
private readonly tombstoneTimer;
|
|
20
24
|
/** Timer to indicate when an unreferenced object is Sweep-Ready */
|
|
21
25
|
private readonly sweepTimer;
|
|
22
26
|
constructor(unreferencedTimestampMs: number,
|
|
@@ -24,8 +28,10 @@ export declare class UnreferencedStateTracker {
|
|
|
24
28
|
inactiveTimeoutMs: number,
|
|
25
29
|
/** The current reference timestamp used to track how long this node has been unreferenced for. */
|
|
26
30
|
currentReferenceTimestampMs: number,
|
|
27
|
-
/** The time after which node transitions to
|
|
28
|
-
|
|
31
|
+
/** The time after which node transitions to TombstoneReady state; undefined if session expiry is disabled. */
|
|
32
|
+
tombstoneTimeoutMs: number | undefined,
|
|
33
|
+
/** The delay from TombstoneReady to SweepReady (only applies if tombstoneTimeoutMs is defined) */
|
|
34
|
+
sweepGracePeriodMs: number);
|
|
29
35
|
updateTracking(currentReferenceTimestampMs: number): void;
|
|
30
36
|
private clearTimers;
|
|
31
37
|
/** Stop tracking this node. Reset the unreferenced timers and state, if any. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gcUnreferencedStateTracker.d.ts","sourceRoot":"","sources":["../../src/gc/gcUnreferencedStateTracker.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"gcUnreferencedStateTracker.d.ts","sourceRoot":"","sources":["../../src/gc/gcUnreferencedStateTracker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAoBpD;;;GAGG;AACH,qBAAa,wBAAwB;aAcnB,uBAAuB,EAAE,MAAM;IAC/C,+DAA+D;IAC/D,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAGlC,8GAA8G;IAC9G,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,kGAAkG;IAClG,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IArBpC,OAAO,CAAC,MAAM,CAA+C;IAC7D,IAAW,KAAK,IAAI,iBAAiB,CAEpC;IAED,2EAA2E;IAC3E,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4B;IAC1D,uEAAuE;IACvE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA4B;IAC3D,mEAAmE;IACnE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA4B;gBAGtC,uBAAuB,EAAE,MAAM;IAC/C,+DAA+D;IAC9C,iBAAiB,EAAE,MAAM;IAC1C,kGAAkG;IAClG,2BAA2B,EAAE,MAAM;IACnC,8GAA8G;IAC7F,kBAAkB,EAAE,MAAM,GAAG,SAAS;IACvD,kGAAkG;IACjF,kBAAkB,EAAE,MAAM;IA4CrC,cAAc,CAAC,2BAA2B,EAAE,MAAM;IA4CzD,OAAO,CAAC,WAAW;IAMnB,gFAAgF;IACzE,YAAY;CAInB"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.UnreferencedStateTracker = void 0;
|
|
8
8
|
const core_utils_1 = require("@fluidframework/core-utils");
|
|
9
|
+
const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
|
|
9
10
|
const gcDefinitions_1 = require("./gcDefinitions");
|
|
10
11
|
/** A wrapper around common-utils Timer that requires the timeout when calling start/restart */
|
|
11
12
|
class TimerWithNoDefaultTimeout extends core_utils_1.Timer {
|
|
@@ -25,7 +26,7 @@ class TimerWithNoDefaultTimeout extends core_utils_1.Timer {
|
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
28
|
* Helper class that tracks the state of an unreferenced node such as the time it was unreferenced and if it can
|
|
28
|
-
* be deleted by the sweep phase.
|
|
29
|
+
* be tombstoned or deleted by the sweep phase.
|
|
29
30
|
*/
|
|
30
31
|
class UnreferencedStateTracker {
|
|
31
32
|
get state() {
|
|
@@ -36,24 +37,37 @@ class UnreferencedStateTracker {
|
|
|
36
37
|
inactiveTimeoutMs,
|
|
37
38
|
/** The current reference timestamp used to track how long this node has been unreferenced for. */
|
|
38
39
|
currentReferenceTimestampMs,
|
|
39
|
-
/** The time after which node transitions to
|
|
40
|
-
|
|
40
|
+
/** The time after which node transitions to TombstoneReady state; undefined if session expiry is disabled. */
|
|
41
|
+
tombstoneTimeoutMs,
|
|
42
|
+
/** The delay from TombstoneReady to SweepReady (only applies if tombstoneTimeoutMs is defined) */
|
|
43
|
+
sweepGracePeriodMs) {
|
|
41
44
|
this.unreferencedTimestampMs = unreferencedTimestampMs;
|
|
42
45
|
this.inactiveTimeoutMs = inactiveTimeoutMs;
|
|
43
|
-
this.
|
|
46
|
+
this.tombstoneTimeoutMs = tombstoneTimeoutMs;
|
|
47
|
+
this.sweepGracePeriodMs = sweepGracePeriodMs;
|
|
44
48
|
this._state = gcDefinitions_1.UnreferencedState.Active;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
49
|
+
(0, telemetry_utils_1.validatePrecondition)(this.tombstoneTimeoutMs === undefined ||
|
|
50
|
+
this.tombstoneTimeoutMs >= this.inactiveTimeoutMs, "inactiveTimeoutMs must not be greater than the tombstoneTimeoutMs");
|
|
48
51
|
this.sweepTimer = new TimerWithNoDefaultTimeout(() => {
|
|
49
52
|
this._state = gcDefinitions_1.UnreferencedState.SweepReady;
|
|
50
|
-
(0, core_utils_1.assert)(!this.inactiveTimer.hasTimer,
|
|
53
|
+
(0, core_utils_1.assert)(!this.inactiveTimer.hasTimer && !this.tombstoneTimer.hasTimer, 0x863 /* inactiveTimer or tombstoneTimer still running after sweepTimer fired! */);
|
|
54
|
+
});
|
|
55
|
+
this.tombstoneTimer = new TimerWithNoDefaultTimeout(() => {
|
|
56
|
+
this._state = gcDefinitions_1.UnreferencedState.TombstoneReady;
|
|
57
|
+
(0, core_utils_1.assert)(!this.inactiveTimer.hasTimer, 0x864 /* inactiveTimer still running after tombstoneTimer fired! */); // aka 0x3b1
|
|
58
|
+
if (this.sweepGracePeriodMs > 0) {
|
|
59
|
+
// After the node becomes tombstone ready, start the sweep timer after which the node will be ready for sweep.
|
|
60
|
+
this.sweepTimer.restart(this.sweepGracePeriodMs);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this._state = gcDefinitions_1.UnreferencedState.SweepReady;
|
|
64
|
+
}
|
|
51
65
|
});
|
|
52
66
|
this.inactiveTimer = new TimerWithNoDefaultTimeout(() => {
|
|
53
67
|
this._state = gcDefinitions_1.UnreferencedState.Inactive;
|
|
54
|
-
// After the node becomes inactive, start the
|
|
55
|
-
if (this.
|
|
56
|
-
this.
|
|
68
|
+
// After the node becomes inactive, start the tombstone timer after which the node will be ready for tombstone.
|
|
69
|
+
if (this.tombstoneTimeoutMs !== undefined) {
|
|
70
|
+
this.tombstoneTimer.restart(this.tombstoneTimeoutMs - this.inactiveTimeoutMs);
|
|
57
71
|
}
|
|
58
72
|
});
|
|
59
73
|
this.updateTracking(currentReferenceTimestampMs);
|
|
@@ -61,19 +75,28 @@ class UnreferencedStateTracker {
|
|
|
61
75
|
/* Updates the unreferenced state based on the provided timestamp. */
|
|
62
76
|
updateTracking(currentReferenceTimestampMs) {
|
|
63
77
|
const unreferencedDurationMs = currentReferenceTimestampMs - this.unreferencedTimestampMs;
|
|
64
|
-
//
|
|
65
|
-
|
|
78
|
+
// Below we will set the appropriate timer (or none). Any running timers are superceded by the new currentReferenceTimestampMs
|
|
79
|
+
this.clearTimers();
|
|
80
|
+
// If the node has been unreferenced long enough, update the state to SweepReady.
|
|
81
|
+
if (this.tombstoneTimeoutMs !== undefined &&
|
|
82
|
+
unreferencedDurationMs >= this.tombstoneTimeoutMs + this.sweepGracePeriodMs) {
|
|
66
83
|
this._state = gcDefinitions_1.UnreferencedState.SweepReady;
|
|
67
|
-
this.clearTimers();
|
|
68
84
|
return;
|
|
69
85
|
}
|
|
70
|
-
// If the node has been unreferenced
|
|
71
|
-
// Also, start a timer for the sweep
|
|
86
|
+
// If the node has been unreferenced long enough, update the state to TombstoneReady.
|
|
87
|
+
// Also, start a timer for the remainder of the sweep delay.
|
|
88
|
+
if (this.tombstoneTimeoutMs !== undefined &&
|
|
89
|
+
unreferencedDurationMs >= this.tombstoneTimeoutMs) {
|
|
90
|
+
this._state = gcDefinitions_1.UnreferencedState.TombstoneReady;
|
|
91
|
+
this.sweepTimer.restart(this.tombstoneTimeoutMs + this.sweepGracePeriodMs - unreferencedDurationMs);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
// If the node has been unreferenced for long enough, update the state to inactive.
|
|
95
|
+
// Also, start a timer for the remainder of the tombstone timeout.
|
|
72
96
|
if (unreferencedDurationMs >= this.inactiveTimeoutMs) {
|
|
73
97
|
this._state = gcDefinitions_1.UnreferencedState.Inactive;
|
|
74
|
-
this.
|
|
75
|
-
|
|
76
|
-
this.sweepTimer.restart(this.sweepTimeoutMs - unreferencedDurationMs);
|
|
98
|
+
if (this.tombstoneTimeoutMs !== undefined) {
|
|
99
|
+
this.tombstoneTimer.restart(this.tombstoneTimeoutMs - unreferencedDurationMs);
|
|
77
100
|
}
|
|
78
101
|
return;
|
|
79
102
|
}
|
|
@@ -82,6 +105,7 @@ class UnreferencedStateTracker {
|
|
|
82
105
|
}
|
|
83
106
|
clearTimers() {
|
|
84
107
|
this.inactiveTimer.clear();
|
|
108
|
+
this.tombstoneTimer.clear();
|
|
85
109
|
this.sweepTimer.clear();
|
|
86
110
|
}
|
|
87
111
|
/** Stop tracking this node. Reset the unreferenced timers and state, if any. */
|