Skip to content

Commit 1f73456

Browse files
committed
Update bucket counts after compact.
1 parent 48846ad commit 1f73456

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

modules/module-mongodb-storage/src/storage/implementation/MongoCompactor.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,12 @@ export class MongoCompactor {
314314
let lastOpId: BucketDataKey | null = null;
315315
let targetOp: bigint | null = null;
316316
let gotAnOp = false;
317+
let numberOfOpsToClear = 0;
317318
for await (let op of query.stream()) {
318319
if (op.op == 'MOVE' || op.op == 'REMOVE' || op.op == 'CLEAR') {
319320
checksum = utils.addChecksums(checksum, op.checksum);
320321
lastOpId = op._id;
322+
numberOfOpsToClear += 1;
321323
if (op.op != 'CLEAR') {
322324
gotAnOp = true;
323325
}
@@ -337,7 +339,7 @@ export class MongoCompactor {
337339
return;
338340
}
339341

340-
logger.info(`Flushing CLEAR at ${lastOpId?.o}`);
342+
logger.info(`Flushing CLEAR for ${numberOfOpsToClear} ops at ${lastOpId?.o}`);
341343
await this.db.bucket_data.deleteMany(
342344
{
343345
_id: {
@@ -362,6 +364,22 @@ export class MongoCompactor {
362364
},
363365
{ session }
364366
);
367+
368+
// Note: This does not update anything if there is no existing state
369+
await this.db.bucket_state.updateOne(
370+
{
371+
_id: {
372+
g: this.group_id,
373+
b: bucket
374+
}
375+
},
376+
{
377+
$inc: {
378+
op_count: 1 - numberOfOpsToClear
379+
}
380+
},
381+
{ session }
382+
);
365383
},
366384
{
367385
writeConcern: { w: 'majority' },

modules/module-mongodb-storage/src/storage/implementation/MongoSyncBucketStorage.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -903,11 +903,6 @@ export class MongoSyncBucketStorage
903903
invalidateDataBuckets: invalidateDataBuckets,
904904
updatedDataBuckets: invalidateDataBuckets ? [] : buckets
905905
};
906-
907-
// return {
908-
// invalidateDataBuckets: true,
909-
// updatedDataBuckets: []
910-
// };
911906
}
912907

913908
private async getParameterBucketChanges(

0 commit comments

Comments
 (0)