Skip to content

Commit a4e387c

Browse files
add progress logs to MongoDB initial snapshot (#199)
1 parent 4b43cdb commit a4e387c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

.changeset/forty-doors-deliver.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/service-module-mongodb': minor
3+
---
4+
5+
Added progress logs to initial snapshot

modules/module-mongodb/src/replication/ChangeStream.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export class ChangeStream {
164164

165165
async estimatedCount(table: storage.SourceTable): Promise<string> {
166166
const db = this.client.db(table.schema);
167-
const count = db.collection(table.table).estimatedDocumentCount();
167+
const count = await db.collection(table.table).estimatedDocumentCount();
168168
return `~${count}`;
169169
}
170170

@@ -298,6 +298,7 @@ export class ChangeStream {
298298
logger.info(`Replicating ${table.qualifiedName}`);
299299
const estimatedCount = await this.estimatedCount(table);
300300
let at = 0;
301+
let lastLogIndex = 0;
301302

302303
const db = this.client.db(table.schema);
303304
const collection = db.collection(table.table);
@@ -310,8 +311,6 @@ export class ChangeStream {
310311
throw new ReplicationAbortedError(`Aborted initial replication`);
311312
}
312313

313-
at += 1;
314-
315314
const record = constructAfterRecord(document);
316315

317316
// This auto-flushes when the batch reaches its size limit
@@ -325,6 +324,10 @@ export class ChangeStream {
325324
});
326325

327326
at += 1;
327+
if (at - lastLogIndex >= 5000) {
328+
logger.info(`[${this.group_id}] Replicating ${table.qualifiedName} ${at}/${estimatedCount}`);
329+
lastLogIndex = at;
330+
}
328331
Metrics.getInstance().rows_replicated_total.add(1);
329332

330333
await touch();

0 commit comments

Comments
 (0)