Skip to content

Commit 9cd5de7

Browse files
committed
Fix compact tests.
1 parent 190972f commit 9cd5de7

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export interface MongoCompactOptions extends storage.CompactOptions {}
6161
const DEFAULT_CLEAR_BATCH_LIMIT = 5000;
6262
const DEFAULT_MOVE_BATCH_LIMIT = 2000;
6363
const DEFAULT_MOVE_BATCH_QUERY_LIMIT = 10_000;
64+
const DEFAULT_MIN_BUCKET_CHANGES = 10;
6465

6566
/** This default is primarily for tests. */
6667
const DEFAULT_MEMORY_LIMIT_MB = 64;
@@ -73,6 +74,7 @@ export class MongoCompactor {
7374
private moveBatchLimit: number;
7475
private moveBatchQueryLimit: number;
7576
private clearBatchLimit: number;
77+
private minBucketChanges: number;
7678
private maxOpId: bigint;
7779
private buckets: string[] | undefined;
7880
private signal?: AbortSignal;
@@ -88,6 +90,7 @@ export class MongoCompactor {
8890
this.moveBatchLimit = options?.moveBatchLimit ?? DEFAULT_MOVE_BATCH_LIMIT;
8991
this.moveBatchQueryLimit = options?.moveBatchQueryLimit ?? DEFAULT_MOVE_BATCH_QUERY_LIMIT;
9092
this.clearBatchLimit = options?.clearBatchLimit ?? DEFAULT_CLEAR_BATCH_LIMIT;
93+
this.minBucketChanges = options?.minBucketChanges ?? DEFAULT_MIN_BUCKET_CHANGES;
9194
this.maxOpId = options?.maxOpId ?? 0n;
9295
this.buckets = options?.compactBuckets;
9396
this.signal = options?.signal;
@@ -119,7 +122,10 @@ export class MongoCompactor {
119122
const TRACK_RECENTLY_COMPACTED_NUMBER = 100;
120123

121124
let recentlyCompacted: string[] = [];
122-
const buckets = await this.dirtyBucketBatch({ minBucketChanges: 10, exclude: recentlyCompacted });
125+
const buckets = await this.dirtyBucketBatch({
126+
minBucketChanges: this.minBucketChanges,
127+
exclude: recentlyCompacted
128+
});
123129
if (buckets.length == 0) {
124130
// All done
125131
break;

modules/module-mongodb-storage/test/src/storage_compacting.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ bucket_definitions:
6262
clearBatchLimit: 200,
6363
moveBatchLimit: 10,
6464
moveBatchQueryLimit: 10,
65+
minBucketChanges: 1,
6566
maxOpId: checkpoint,
6667
signal: null as any
6768
});

packages/service-core-tests/src/tests/register-compacting-tests.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ bucket_definitions:
8080
await bucketStorage.compact({
8181
clearBatchLimit: 2,
8282
moveBatchLimit: 1,
83-
moveBatchQueryLimit: 1
83+
moveBatchQueryLimit: 1,
84+
minBucketChanges: 1
8485
});
8586

8687
const batchAfter = await test_utils.oneFromAsync(
@@ -207,7 +208,8 @@ bucket_definitions:
207208
await bucketStorage.compact({
208209
clearBatchLimit: 2,
209210
moveBatchLimit: 1,
210-
moveBatchQueryLimit: 1
211+
moveBatchQueryLimit: 1,
212+
minBucketChanges: 1
211213
});
212214

213215
const batchAfter = await test_utils.oneFromAsync(
@@ -300,7 +302,8 @@ bucket_definitions:
300302
await bucketStorage.compact({
301303
clearBatchLimit: 2,
302304
moveBatchLimit: 1,
303-
moveBatchQueryLimit: 1
305+
moveBatchQueryLimit: 1,
306+
minBucketChanges: 1
304307
});
305308

306309
const batchAfter = await test_utils.oneFromAsync(
@@ -412,7 +415,8 @@ bucket_definitions:
412415
await bucketStorage.compact({
413416
clearBatchLimit: 100,
414417
moveBatchLimit: 100,
415-
moveBatchQueryLimit: 100 // Larger limit for a larger window of operations
418+
moveBatchQueryLimit: 100, // Larger limit for a larger window of operations
419+
minBucketChanges: 1
416420
});
417421

418422
const batchAfter = await test_utils.fromAsync(
@@ -498,7 +502,8 @@ bucket_definitions:
498502
await bucketStorage.compact({
499503
clearBatchLimit: 2,
500504
moveBatchLimit: 1,
501-
moveBatchQueryLimit: 1
505+
moveBatchQueryLimit: 1,
506+
minBucketChanges: 1
502507
});
503508

504509
const result2 = await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
@@ -572,7 +577,8 @@ bucket_definitions:
572577
await bucketStorage.compact({
573578
clearBatchLimit: 20,
574579
moveBatchLimit: 10,
575-
moveBatchQueryLimit: 10
580+
moveBatchQueryLimit: 10,
581+
minBucketChanges: 1
576582
});
577583

578584
const checkpoint2 = result2!.flushed_op;

packages/service-core/src/storage/SyncRulesBucketStorage.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ export interface CompactOptions {
217217
/** Minimum of 1 */
218218
moveBatchQueryLimit?: number;
219219

220+
/**
221+
* Minimof of 1, default of 10.
222+
*/
223+
minBucketChanges?: number;
224+
220225
/**
221226
* Internal/testing use: Cache size for compacting parameters.
222227
*/

0 commit comments

Comments
 (0)