@fluidframework/container-runtime 2.0.0-internal.8.0.0 → 2.0.0-internal.8.0.2
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/dist/containerRuntime.d.ts.map +1 -1
- package/dist/containerRuntime.js +0 -3
- package/dist/containerRuntime.js.map +1 -1
- package/dist/gc/garbageCollection.d.ts +8 -12
- package/dist/gc/garbageCollection.d.ts.map +1 -1
- package/dist/gc/garbageCollection.js +71 -103
- package/dist/gc/garbageCollection.js.map +1 -1
- package/dist/gc/gcDefinitions.d.ts +0 -1
- package/dist/gc/gcDefinitions.d.ts.map +1 -1
- package/dist/gc/gcDefinitions.js.map +1 -1
- package/dist/gc/gcSummaryStateTracker.d.ts +1 -1
- package/dist/gc/gcSummaryStateTracker.d.ts.map +1 -1
- package/dist/gc/gcSummaryStateTracker.js +3 -0
- package/dist/gc/gcSummaryStateTracker.js.map +1 -1
- package/dist/gc/gcTelemetry.d.ts.map +1 -1
- package/dist/gc/gcTelemetry.js +4 -14
- package/dist/gc/gcTelemetry.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/lib/containerRuntime.d.ts.map +1 -1
- package/lib/containerRuntime.js +0 -3
- package/lib/containerRuntime.js.map +1 -1
- package/lib/gc/garbageCollection.d.ts +8 -12
- package/lib/gc/garbageCollection.d.ts.map +1 -1
- package/lib/gc/garbageCollection.js +72 -104
- package/lib/gc/garbageCollection.js.map +1 -1
- package/lib/gc/gcDefinitions.d.ts +0 -1
- package/lib/gc/gcDefinitions.d.ts.map +1 -1
- package/lib/gc/gcDefinitions.js.map +1 -1
- package/lib/gc/gcSummaryStateTracker.d.ts +1 -1
- package/lib/gc/gcSummaryStateTracker.d.ts.map +1 -1
- package/lib/gc/gcSummaryStateTracker.js +3 -0
- package/lib/gc/gcSummaryStateTracker.js.map +1 -1
- package/lib/gc/gcTelemetry.d.ts.map +1 -1
- package/lib/gc/gcTelemetry.js +4 -14
- package/lib/gc/gcTelemetry.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/package.json +16 -16
- package/src/containerRuntime.ts +0 -3
- package/src/gc/garbageCollection.ts +92 -119
- package/src/gc/gcDefinitions.ts +0 -1
- package/src/gc/gcSummaryStateTracker.ts +5 -1
- package/src/gc/gcTelemetry.ts +4 -13
- package/src/packageVersion.ts +1 -1
|
@@ -60,30 +60,26 @@ export declare class GarbageCollector implements IGarbageCollector {
|
|
|
60
60
|
private readonly getNodePackagePath;
|
|
61
61
|
/** Returns the timestamp of the last summary generated for this container. */
|
|
62
62
|
private readonly getLastSummaryTimestampMs;
|
|
63
|
-
/** Returns true if connection is active, i.e. it's "write" connection and the runtime is connected. */
|
|
64
|
-
private readonly activeConnection;
|
|
65
63
|
private readonly submitMessage;
|
|
66
64
|
get summaryStateNeedsReset(): boolean;
|
|
67
65
|
/** Returns the count of data stores whose GC state updated since the last summary. */
|
|
68
66
|
get updatedDSCountSinceLastSummary(): number;
|
|
69
67
|
protected constructor(createParams: IGarbageCollectorCreateParams);
|
|
70
68
|
/**
|
|
71
|
-
* Called during container initialization.
|
|
72
|
-
*
|
|
69
|
+
* Called during container initialization. Initializes the tombstone and deleted nodes state from the base snapshot.
|
|
70
|
+
* Also, initializes the GC state including unreferenced nodes tracking if a current reference timestamp exists.
|
|
71
|
+
* Note that if there is any GC state in the base snapshot, then there will definitely be a reference timestamp
|
|
72
|
+
* to work with - The GC state would have been generated using a timestamp which is part of the snapshot.
|
|
73
73
|
*/
|
|
74
74
|
initializeBaseState(): Promise<void>;
|
|
75
75
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* @param snapshotData - The snapshot data to update state from. If this is undefined, all GC state and tracking
|
|
79
|
-
* is reset.
|
|
80
|
-
* @param currentReferenceTimestampMs - The current reference timestamp for marking unreferenced nodes' unreferenced
|
|
81
|
-
* timestamp.
|
|
76
|
+
* Initialize the GC state if not already initialized. If GC state is already initialized, update the unreferenced
|
|
77
|
+
* state tracking as per the current reference timestamp.
|
|
82
78
|
*/
|
|
83
|
-
private
|
|
79
|
+
private initializeOrUpdateGCState;
|
|
84
80
|
/**
|
|
85
81
|
* Called when the connection state of the runtime changes, i.e., it connects or disconnects. GC subscribes to this
|
|
86
|
-
* to initialize the
|
|
82
|
+
* to initialize or update the unreference state tracking.
|
|
87
83
|
* @param connected - Whether the runtime connected / disconnected.
|
|
88
84
|
* @param clientId - The clientId of this runtime.
|
|
89
85
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"garbageCollection.d.ts","sourceRoot":"","sources":["../../src/gc/garbageCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAGN,6BAA6B,EAC7B,gBAAgB,EAChB,iBAAiB,EACjB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAIN,mBAAmB,EAGnB,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"garbageCollection.d.ts","sourceRoot":"","sources":["../../src/gc/garbageCollection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAGN,6BAA6B,EAC7B,gBAAgB,EAChB,iBAAiB,EACjB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAIN,mBAAmB,EAGnB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAEN,iBAAiB,EAEjB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAwB,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EAEN,iBAAiB,EACjB,6BAA6B,EAG7B,QAAQ,EAER,WAAW,EAMX,M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AAW,CACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,QAAQ,GAAG,SAAS,EAC5B,WAAW,CAAC,EAAE,MAAM,EACpB,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,EAC/B,OAAO,CAAC,EAAE,QAAQ,EAClB,UAAU,CAAC,EAAE,iBAAiB;IAyD/B;;;;;;OAMG;IACI,sBAAsB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAqBtE;;;OAGG;IACI,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIxC,OAAO,IAAI,IAAI;IAKtB;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IA0DzB;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;CAkE1B"}
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { LazyPromise, Timer } from "@fluidframework/core-utils";
|
|
5
|
+
import { assert, LazyPromise, Timer } from "@fluidframework/core-utils";
|
|
6
6
|
import { gcTreeKey, } from "@fluidframework/runtime-definitions";
|
|
7
7
|
import { createResponseError, responseToException } from "@fluidframework/runtime-utils";
|
|
8
8
|
import { createChildLogger, createChildMonitoringContext, DataProcessingError, PerformanceEvent, } from "@fluidframework/telemetry-utils";
|
|
9
|
+
import { BlobManager } from "../blobManager";
|
|
9
10
|
import { InactiveResponseHeaderKey, TombstoneResponseHeaderKey, } from "../containerRuntime";
|
|
10
11
|
import { ClientSessionExpiredError } from "../error";
|
|
11
12
|
import { ContainerMessageType } from "../messageTypes";
|
|
@@ -80,7 +81,6 @@ export class GarbageCollector {
|
|
|
80
81
|
this.isSummarizerClient = createParams.isSummarizerClient;
|
|
81
82
|
this.getNodePackagePath = createParams.getNodePackagePath;
|
|
82
83
|
this.getLastSummaryTimestampMs = createParams.getLastSummaryTimestampMs;
|
|
83
|
-
this.activeConnection = createParams.activeConnection;
|
|
84
84
|
this.submitMessage = createParams.submitMessage;
|
|
85
85
|
const baseSnapshot = createParams.baseSnapshot;
|
|
86
86
|
const readAndParseBlob = createParams.readAndParseBlob;
|
|
@@ -141,28 +141,14 @@ export class GarbageCollector {
|
|
|
141
141
|
}
|
|
142
142
|
});
|
|
143
143
|
/**
|
|
144
|
-
* Set up the initializer which initializes the GC state from the data in base snapshot.
|
|
145
|
-
*
|
|
146
|
-
*
|
|
144
|
+
* Set up the initializer which initializes the GC state from the data in base snapshot. It sets up GC data
|
|
145
|
+
* from the base GC state and starts tracking the state of unreferenced nodes.
|
|
146
|
+
*
|
|
147
|
+
* Must only be called if there is a current reference timestamp.
|
|
147
148
|
*/
|
|
148
149
|
this.initializeGCStateFromBaseSnapshotP = new LazyPromise(async () => {
|
|
149
|
-
/**
|
|
150
|
-
* If there is no current reference timestamp, skip initialization. We need the current timestamp to track
|
|
151
|
-
* how long objects have been unreferenced and if they can be deleted.
|
|
152
|
-
*
|
|
153
|
-
* Note that the only scenario where there is no reference timestamp is when no ops have ever been processed
|
|
154
|
-
* for this container and it is in read mode. In this scenario, there is no point in running GC anyway
|
|
155
|
-
* because references in the container do not change without any ops, i.e., there is nothing to collect.
|
|
156
|
-
*/
|
|
157
150
|
const currentReferenceTimestampMs = this.runtime.getCurrentReferenceTimestampMs();
|
|
158
|
-
|
|
159
|
-
// Log an event so we can evaluate how often we run into this scenario.
|
|
160
|
-
this.mc.logger.sendErrorEvent({
|
|
161
|
-
eventName: "GarbageCollectorInitializedWithoutTimestamp",
|
|
162
|
-
gcConfigs: JSON.stringify(this.configs),
|
|
163
|
-
});
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
151
|
+
assert(currentReferenceTimestampMs !== undefined, "Trying to initialize GC state without current timestamp");
|
|
166
152
|
/**
|
|
167
153
|
* The base snapshot data will not be present if the container is loaded from:
|
|
168
154
|
* 1. The first summary created by the detached container.
|
|
@@ -170,11 +156,20 @@ export class GarbageCollector {
|
|
|
170
156
|
* 3. A summary that was generated before GC even existed.
|
|
171
157
|
*/
|
|
172
158
|
const baseSnapshotData = await this.baseSnapshotDataP;
|
|
173
|
-
|
|
159
|
+
this.summaryStateTracker.initializeBaseState(baseSnapshotData);
|
|
160
|
+
if (baseSnapshotData?.gcState === undefined) {
|
|
174
161
|
return;
|
|
175
162
|
}
|
|
176
|
-
|
|
177
|
-
|
|
163
|
+
// Update unreferenced state tracking as per the GC state in the snapshot data and update gcDataFromLastRun
|
|
164
|
+
// to the GC data from the snapshot data.
|
|
165
|
+
const gcNodes = {};
|
|
166
|
+
for (const [nodeId, nodeData] of Object.entries(baseSnapshotData.gcState.gcNodes)) {
|
|
167
|
+
if (nodeData.unreferencedTimestampMs !== undefined) {
|
|
168
|
+
this.unreferencedNodesState.set(nodeId, new UnreferencedStateTracker(nodeData.unreferencedTimestampMs, this.configs.inactiveTimeoutMs, currentReferenceTimestampMs, this.configs.sweepTimeoutMs, this.configs.sweepGracePeriodMs));
|
|
169
|
+
}
|
|
170
|
+
gcNodes[nodeId] = Array.from(nodeData.outboundRoutes);
|
|
171
|
+
}
|
|
172
|
+
this.gcDataFromLastRun = { gcNodes };
|
|
178
173
|
});
|
|
179
174
|
// Get the GC details from the GC state in the base summary. This is returned in getBaseGCDetails which is
|
|
180
175
|
// used to initialize the GC state of all the nodes in the container.
|
|
@@ -203,8 +198,10 @@ export class GarbageCollector {
|
|
|
203
198
|
});
|
|
204
199
|
}
|
|
205
200
|
/**
|
|
206
|
-
* Called during container initialization.
|
|
207
|
-
*
|
|
201
|
+
* Called during container initialization. Initializes the tombstone and deleted nodes state from the base snapshot.
|
|
202
|
+
* Also, initializes the GC state including unreferenced nodes tracking if a current reference timestamp exists.
|
|
203
|
+
* Note that if there is any GC state in the base snapshot, then there will definitely be a reference timestamp
|
|
204
|
+
* to work with - The GC state would have been generated using a timestamp which is part of the snapshot.
|
|
208
205
|
*/
|
|
209
206
|
async initializeBaseState() {
|
|
210
207
|
const baseSnapshotData = await this.baseSnapshotDataP;
|
|
@@ -229,98 +226,51 @@ export class GarbageCollector {
|
|
|
229
226
|
this.tombstones = Array.from(baseSnapshotData.tombstones);
|
|
230
227
|
this.runtime.updateTombstonedRoutes(this.tombstones);
|
|
231
228
|
}
|
|
229
|
+
await this.initializeOrUpdateGCState();
|
|
232
230
|
}
|
|
233
231
|
/**
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
* @param snapshotData - The snapshot data to update state from. If this is undefined, all GC state and tracking
|
|
237
|
-
* is reset.
|
|
238
|
-
* @param currentReferenceTimestampMs - The current reference timestamp for marking unreferenced nodes' unreferenced
|
|
239
|
-
* timestamp.
|
|
232
|
+
* Initialize the GC state if not already initialized. If GC state is already initialized, update the unreferenced
|
|
233
|
+
* state tracking as per the current reference timestamp.
|
|
240
234
|
*/
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
* its refreshing state from a summary that happened at seq#900. In this case, there may be references between
|
|
246
|
-
* seq#901 and seq#1000 that we don't want to reset.
|
|
247
|
-
* Unfortunately, there is no way to track the seq# of ops that add references, so we choose to not reset any
|
|
248
|
-
* references here. This should be fine because, in the worst case, we may end up updating the unreferenced
|
|
249
|
-
* timestamp of a node which will delay its deletion. Although not ideal, this will only happen in rare
|
|
250
|
-
* scenarios, so it should be okay.
|
|
251
|
-
*/
|
|
252
|
-
// Clear all existing unreferenced state tracking.
|
|
253
|
-
for (const [, nodeStateTracker] of this.unreferencedNodesState) {
|
|
254
|
-
nodeStateTracker.stopTracking();
|
|
255
|
-
}
|
|
256
|
-
this.unreferencedNodesState.clear();
|
|
257
|
-
// If running sweep, the tombstone state represents the list of nodes that have been deleted during sweep.
|
|
258
|
-
// If running in tombstone mode, the tombstone state represents the list of nodes that have been marked as
|
|
259
|
-
// tombstones.
|
|
260
|
-
// If this call is because we are refreshing from a snapshot due to an ack, it is likely that the GC state
|
|
261
|
-
// in the snapshot is newer than this client's. And so, the deleted / tombstone nodes need to be updated.
|
|
262
|
-
if (this.configs.shouldRunSweep) {
|
|
263
|
-
const snapshotDeletedNodes = snapshotData?.deletedNodes
|
|
264
|
-
? new Set(snapshotData.deletedNodes)
|
|
265
|
-
: undefined;
|
|
266
|
-
// If the snapshot contains deleted nodes that are not yet deleted by this client, ask the runtime to
|
|
267
|
-
// delete them.
|
|
268
|
-
if (snapshotDeletedNodes !== undefined) {
|
|
269
|
-
const newDeletedNodes = [];
|
|
270
|
-
for (const nodeId of snapshotDeletedNodes) {
|
|
271
|
-
if (!this.deletedNodes.has(nodeId)) {
|
|
272
|
-
newDeletedNodes.push(nodeId);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
if (newDeletedNodes.length > 0) {
|
|
276
|
-
// Call container runtime to delete these nodes and add deleted nodes to this.deletedNodes.
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
else if (this.configs.tombstoneMode) {
|
|
281
|
-
// The snapshot may contain more or fewer tombstone nodes than this client. Update tombstone state and
|
|
282
|
-
// notify the runtime to update its state as well.
|
|
283
|
-
this.tombstones = snapshotData?.tombstones ? Array.from(snapshotData.tombstones) : [];
|
|
284
|
-
this.runtime.updateTombstonedRoutes(this.tombstones);
|
|
235
|
+
async initializeOrUpdateGCState() {
|
|
236
|
+
const currentReferenceTimestampMs = this.runtime.getCurrentReferenceTimestampMs();
|
|
237
|
+
if (currentReferenceTimestampMs === undefined) {
|
|
238
|
+
return;
|
|
285
239
|
}
|
|
286
|
-
// If
|
|
287
|
-
if (
|
|
288
|
-
this.
|
|
240
|
+
// If the GC state hasn't been initialized yet, initialize it and return.
|
|
241
|
+
if (this.gcDataFromLastRun === undefined) {
|
|
242
|
+
await this.initializeGCStateFromBaseSnapshotP;
|
|
289
243
|
return;
|
|
290
244
|
}
|
|
291
|
-
//
|
|
292
|
-
//
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
if (nodeData.unreferencedTimestampMs !== undefined) {
|
|
296
|
-
this.unreferencedNodesState.set(nodeId, new UnreferencedStateTracker(nodeData.unreferencedTimestampMs, this.configs.inactiveTimeoutMs, currentReferenceTimestampMs, this.configs.sweepTimeoutMs, this.configs.sweepGracePeriodMs));
|
|
297
|
-
}
|
|
298
|
-
gcNodes[nodeId] = Array.from(nodeData.outboundRoutes);
|
|
245
|
+
// If the GC state has been initialized, update the tracking of unreferenced nodes as per the current
|
|
246
|
+
// reference timestamp.
|
|
247
|
+
for (const [, nodeStateTracker] of this.unreferencedNodesState) {
|
|
248
|
+
nodeStateTracker.updateTracking(currentReferenceTimestampMs);
|
|
299
249
|
}
|
|
300
|
-
this.gcDataFromLastRun = { gcNodes };
|
|
301
250
|
}
|
|
302
251
|
/**
|
|
303
252
|
* Called when the connection state of the runtime changes, i.e., it connects or disconnects. GC subscribes to this
|
|
304
|
-
* to initialize the
|
|
253
|
+
* to initialize or update the unreference state tracking.
|
|
305
254
|
* @param connected - Whether the runtime connected / disconnected.
|
|
306
255
|
* @param clientId - The clientId of this runtime.
|
|
307
256
|
*/
|
|
308
257
|
setConnectionState(connected, clientId) {
|
|
309
258
|
/**
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
* reference timestamp that will be used to update the state of unreferenced nodes. Also, all trailing ops which
|
|
313
|
-
* could affect the GC state will have been processed.
|
|
259
|
+
* When the client connects (or reconnects), attempt to initialize or update the GC state. This will keep
|
|
260
|
+
* the unreferenced state tracking updated as per the reference timestamp at the time of connection.
|
|
314
261
|
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
* Ideally, this initialization should only be done for summarizer client. However, we are currently rolling out
|
|
320
|
-
* sweep in phases and we want to track when inactive and sweep-ready objects are used in any client.
|
|
262
|
+
* During GC initialization and during connections in read mode, it is possible that either no ops are
|
|
263
|
+
* processed or only trailing ops are processed. This means that the GC state is not initialized or initialized
|
|
264
|
+
* with an older reference timestamp. So, doing this on every connection will keep the unreferenced state
|
|
265
|
+
* tracking up-to-date.
|
|
321
266
|
*/
|
|
322
|
-
if (
|
|
323
|
-
this.
|
|
267
|
+
if (connected && this.configs.shouldRunGC) {
|
|
268
|
+
this.initializeOrUpdateGCState().catch((error) => {
|
|
269
|
+
this.mc.logger.sendErrorEvent({
|
|
270
|
+
eventName: "GCInitializationOrUpdateFailed",
|
|
271
|
+
gcConfigs: JSON.stringify(this.configs),
|
|
272
|
+
}, error);
|
|
273
|
+
});
|
|
324
274
|
}
|
|
325
275
|
}
|
|
326
276
|
/**
|
|
@@ -377,8 +327,11 @@ export class GarbageCollector {
|
|
|
377
327
|
const gcStats = await this.runGC(fullGC, currentReferenceTimestampMs, logger);
|
|
378
328
|
event.end({
|
|
379
329
|
...gcStats,
|
|
380
|
-
|
|
381
|
-
|
|
330
|
+
details: {
|
|
331
|
+
timestamp: currentReferenceTimestampMs,
|
|
332
|
+
sweep: this.configs.shouldRunSweep,
|
|
333
|
+
tombstone: this.configs.throwOnTombstoneLoad,
|
|
334
|
+
},
|
|
382
335
|
});
|
|
383
336
|
/** Post-GC steps */
|
|
384
337
|
// Log pending unreferenced events such as a node being used after inactive. This is done after GC runs and
|
|
@@ -871,9 +824,24 @@ export class GarbageCollector {
|
|
|
871
824
|
deletedDataStoreCount: 0,
|
|
872
825
|
deletedAttachmentBlobCount: 0,
|
|
873
826
|
};
|
|
827
|
+
// The runtime can't reliably identify the type of deleted nodes. So, get the type here. This should
|
|
828
|
+
// be good enough because the only types that participate in GC today are data stores, DDSes and blobs.
|
|
829
|
+
const getDeletedNodeType = (nodeId) => {
|
|
830
|
+
const pathParts = nodeId.split("/");
|
|
831
|
+
if (pathParts[1] === BlobManager.basePath) {
|
|
832
|
+
return GCNodeType.Blob;
|
|
833
|
+
}
|
|
834
|
+
if (pathParts.length === 2) {
|
|
835
|
+
return GCNodeType.DataStore;
|
|
836
|
+
}
|
|
837
|
+
if (pathParts.length === 3) {
|
|
838
|
+
return GCNodeType.SubDataStore;
|
|
839
|
+
}
|
|
840
|
+
return GCNodeType.Other;
|
|
841
|
+
};
|
|
874
842
|
for (const nodeId of deletedNodes) {
|
|
875
843
|
sweepPhaseStats.deletedNodeCount++;
|
|
876
|
-
const nodeType =
|
|
844
|
+
const nodeType = getDeletedNodeType(nodeId);
|
|
877
845
|
if (nodeType === GCNodeType.DataStore) {
|
|
878
846
|
sweepPhaseStats.deletedDataStoreCount++;
|
|
879
847
|
}
|