diff --git a/src/database/standalone-sqlite.ts b/src/database/standalone-sqlite.ts index 9aa48b54..91df613e 100644 --- a/src/database/standalone-sqlite.ts +++ b/src/database/standalone-sqlite.ts @@ -2347,8 +2347,10 @@ export class StandaloneSqliteDatabaseWorker { }); } - cleanupWal(dbName: 'core' | 'bundles' | 'data' | 'moderation'): void { - this.dbs[dbName].pragma('wal_checkpoint(TRUNCATE)'); + cleanupWal(dbName: 'core' | 'bundles' | 'data' | 'moderation') { + const walCheckpoint = this.dbs[dbName].pragma('wal_checkpoint(TRUNCATE)'); + + return walCheckpoint[0]; } } @@ -2971,7 +2973,27 @@ export class StandaloneSqliteDatabase } async cleanupWal(dbName: WorkerPoolName): Promise { - return this.queueWrite(dbName, 'cleanupWal', [dbName]); + return this.queueWrite(dbName, 'cleanupWal', [dbName]).then( + (walCheckpoint) => { + this.log.info('WAL checkpoint', { + dbName, + walCheckpoint, + }); + + metrics.sqliteWalCheckpointPages.set( + { db: dbName, type: 'busy' }, + walCheckpoint.busy, + ); + metrics.sqliteWalCheckpointPages.set( + { db: dbName, type: 'log' }, + walCheckpoint.log, + ); + metrics.sqliteWalCheckpointPages.set( + { db: dbName, type: 'checkpointed' }, + walCheckpoint.checkpointed, + ); + }, + ); } } @@ -3114,8 +3136,8 @@ if (!isMainThread) { parentPort?.postMessage(null); break; case 'cleanupWal': - worker.cleanupWal(args[0]); - parentPort?.postMessage(undefined); + const walCheckpoint = worker.cleanupWal(args[0]); + parentPort?.postMessage(walCheckpoint); break; case 'terminate': parentPort?.postMessage(null); diff --git a/src/metrics.ts b/src/metrics.ts index f4ab855c..99fd5463 100644 --- a/src/metrics.ts +++ b/src/metrics.ts @@ -130,6 +130,12 @@ export const saveMethodsDuplicateCounter = new promClient.Counter({ labelNames: ['method'], }); +export const sqliteWalCheckpointPages = new promClient.Gauge({ + name: 'sqlite_wal_checkpoint_pages', + help: 'Number of pages in the WAL', + labelNames: ['db', 'type'], +}); + // // Block importer metrics //