/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import { type IGarbageCollectionDetailsBase, type ISummarizeResult, type ITelemetryContext } from "@fluidframework/runtime-definitions/internal"; import { type ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal"; import type { IRefreshSummaryResult } from "../summary/index.js"; import { type GarbageCollectionMessage, type IGCMetadata, type IGCStats, type IGarbageCollector, type IGarbageCollectorCreateParams, type IGCNodeUpdatedProps } from "./gcDefinitions.js"; /** * The garbage collector for the container runtime. It consolidates the garbage collection functionality and maintains * its state across summaries. * * Node - represented as nodeId, it's a node on the GC graph * * Outbound Route - a path from one node to another node, think `nodeA` -\> `nodeB` * * Graph - all nodes with their respective routes * * ``` * GC Graph * * Node * NodeId = "datastore1" * / \\ * OutboundRoute OutboundRoute * / \\ * Node Node * NodeId = "dds1" NodeId = "dds2" * ``` */ export declare class GarbageCollector implements IGarbageCollector { static create(createParams: IGarbageCollectorCreateParams): IGarbageCollector; private readonly mc; private readonly configs; get serializedConfigs(): string; get shouldRunGC(): boolean; readonly sessionExpiryTimerStarted: number | undefined; private gcDataFromLastRun; private readonly newReferencesSinceLastRun; private tombstones; private deletedNodes; private readonly baseSnapshotDataP; private readonly initializeGCStateFromBaseSnapshotP; private readonly baseGCDetailsP; /** * Map of node ids to their unreferenced state tracker * NOTE: The set of keys in this map is considered as the set of unreferenced nodes * as of the last GC run. So in between runs, nothing should be added or removed. */ private readonly unreferencedNodesState; private sessionExpiryTimer; private completedRuns; private readonly runtime; private readonly isSummarizerClient; private readonly summaryStateTracker; private readonly telemetryTracker; /** * For a given node path, returns the node's package path. */ private readonly getNodePackagePath; /** * Returns the timestamp of the last summary generated for this container. */ private readonly getLastSummaryTimestampMs; private readonly submitMessage; /** * Returns the count of data stores whose GC state updated since the last summary. */ get updatedDSCountSinceLastSummary(): number; protected constructor(createParams: IGarbageCollectorCreateParams); /** * API for ensuring the correct auto-recovery mitigations */ private readonly autoRecovery; /** * Called during container initialization. Initializes the tombstone and deleted nodes state from the base snapshot. * Also, initializes the GC state including unreferenced nodes tracking if a current reference timestamp exists. * Note that if there is any GC state in the base snapshot, then there will definitely be a reference timestamp * to work with - The GC state would have been generated using a timestamp which is part of the snapshot. */ initializeBaseState(): Promise; /** * Initialize the GC state if not already initialized. If GC state is already initialized, update the unreferenced * state tracking as per the current reference timestamp. */ private initializeOrUpdateGCState; /** * Called when the connection state of the runtime changes, i.e., it connects or disconnects. GC subscribes to this * to initialize or update the unreference state tracking. * @param connected - Whether the runtime connected / disconnected. * @param clientId - The clientId of this runtime. */ setConnectionState(connected: boolean, clientId?: string | undefined): void; /** * Returns a the GC details generated from the base summary. This is used to initialize the GC state of the nodes * in the container. */ getBaseGCDetails(): Promise; /** * Runs garbage collection and updates the reference / used state of the nodes in the container. * @returns stats of the GC run or undefined if GC did not run. */ collectGarbage(options: { /** * Logger to use for logging GC events */ logger?: ITelemetryLoggerExt; /** * True to run GC sweep phase after the mark phase */ runSweep?: boolean; /** * True to generate full GC data */ fullGC?: boolean; }, telemetryContext?: ITelemetryContext): Promise; /** * Runs garbage collection. It does the following: * * 1. It generates / analyzes the runtime's reference graph. * * 2. Generates mark phase stats. * * 3. Runs Mark phase. * * 4. Runs Sweep phase. * * 5. Generates sweep phase stats. */ private runGC; /** * Runs the GC Mark phase. It does the following: * * 1. Marks all referenced nodes in this run by clearing tracking for them. * * 2. Marks unreferenced nodes in this run by starting tracking for them. * * 3. Calls the runtime to update nodes that were marked referenced. * * @param gcResult - The result of the GC run on the gcData. * @param allReferencedNodeIds - Nodes referenced in this GC run + referenced between previous and current GC run. * @param currentReferenceTimestampMs - The timestamp to be used for unreferenced nodes' timestamp. * @returns The sets of tombstone-ready and sweep-ready nodes, i.e., nodes that ready to be tombstoned or deleted. */ private runMarkPhase; /** * Runs the GC Sweep phase. It does the following: * * 1. Marks tombstone-ready nodes as tombstones. * * 2. Sends a sweep op to delete nodes that are sweep-ready. Once the op is ack'd, these nodes will be deleted. * * @param gcResult - The result of the GC run on the gcData. * @param tombstoneReadyNodes - List of nodes that are tombstone-ready. * @param sweepReadyNodes - List of nodes that are sweep-ready. */ private runSweepPhase; /** * Since GC runs periodically, the GC data that is generated only tells us the state of the world at that point in * time. There can be nodes that were referenced in between two runs and their unreferenced state needs to be * updated. For example, in the following scenarios not updating the unreferenced timestamp can lead to deletion of * these objects while there can be in-memory referenced to it: * 1. A node transitions from `unreferenced -> referenced -> unreferenced` between two runs. When the reference is * added, the object may have been accessed and in-memory reference to it added. * 2. A reference is added from one unreferenced node to one or more unreferenced nodes. Even though the node[s] were * unreferenced, they could have been accessed and in-memory reference to them added. * * This function identifies nodes that were referenced since the last run. * If these nodes are currently unreferenced, they will be assigned new unreferenced state by the current run. * * @returns A list of all nodes referenced from the last local summary until now. */ private findAllNodesReferencedBetweenGCs; /** * Summarizes the GC data and returns it as a summary tree. * We current write the entire GC state in a single blob. This can be modified later to write multiple * blobs. All the blob keys should start with `gcBlobPrefix`. */ summarize(fullTree: boolean, trackState: boolean, telemetryContext?: ITelemetryContext): ISummarizeResult | undefined; getMetadata(): IGCMetadata; /** * Called to refresh the latest summary state. This happens when either a pending summary is acked. */ refreshLatestSummary(result: IRefreshSummaryResult): Promise; /** * Process GC messages. * @param messageContents - The contents of the messages. * @param messageTimestampMs - The timestamp of the messages. * @param local - Whether it was send by this client. */ processMessages(messageContents: GarbageCollectionMessage[], messageTimestampMs: number, local: boolean): void; /** * Delete nodes that are sweep-ready. Call the runtime to delete these nodes and clear the unreferenced state * tracking for nodes that are actually deleted by the runtime. * * Note that this doesn't check any configuration around whether Sweep is enabled. * That happens before the op is submitted, and from that point, any client should execute the delete. * * @param sweepReadyNodeIds - The ids of nodes that are ready to be deleted. */ private deleteSweepReadyNodes; /** * Called when a node with the given id is updated. If the node is inactive or tombstoned, this will log an error * or throw an error if failing on incorrect usage is configured. * @param IGCNodeUpdatedProps - Details about the node and how it was updated */ nodeUpdated({ node, reason, timestampMs, packagePath, request, headerData, additionalProps, }: IGCNodeUpdatedProps): void; /** * The given node should have its unreferenced state reset in the next GC, * even if the true GC graph shows it is unreferenced. This will * prevent it from being deleted by Sweep (after the Grace Period). * * Submit a GC op indicating that the Tombstone with the given path has been loaded. * Broadcasting this information in the op stream allows the Summarizer to reset unreferenced state * before running GC next. */ private triggerAutoRecovery; /** * Called when an outbound reference is added to a node. This is used to identify all nodes that have been * referenced between summaries so that their unreferenced timestamp can be reset. * * @param fromNodePath - The node from which the reference is added. * @param toNodePath - The node to which the reference is added. * @param timestampMs - The timestamp of the message that added the reference. * @param autorecovery - This reference is added artificially, for autorecovery. Used for logging. */ addedOutboundReference(fromNodePath: string, toNodePath: string, timestampMs: number, autorecovery?: true): void; /** * Returns whether a node with the given path has been deleted or not. This can be used by the runtime to identify * cases where objects are used after they are deleted and throw / log errors accordingly. */ isNodeDeleted(nodePath: string): boolean; dispose(): void; /** * Generates the stats of a garbage collection mark phase run. * @param gcResult - The result of the current GC run. * @returns the stats of the mark phase run. */ private getMarkPhaseStats; /** * Generates the stats of a garbage collection sweep phase run. * @param deletedNodes - The nodes that have already been deleted even before this run. * @param sweepReadyNodes - The nodes that are sweep-ready in this GC run. These will be deleted but are not deleted yet, * due to either sweep not being enabled or the Sweep Op needing to roundtrip before the delete is executed. * @param markPhaseStats - The stats of the mark phase run. * @returns the stats of the sweep phase run. */ private getSweepPhaseStats; } //# sourceMappingURL=garbageCollection.d.ts.map