diff --git a/lib/log/index.js b/lib/log/index.js index 5d45622..e8d00b4 100644 --- a/lib/log/index.js +++ b/lib/log/index.js @@ -717,6 +717,7 @@ function Log(filename, opts) { const [err1] = await p(onOverwritesFlushed)() if (err1) return cb(err1) + const startCompactTimestamp = Date.now() compacting = true if (compactionProgress.value.done) { compactionProgress.set(COMPACTION_PROGRESS_START) @@ -724,7 +725,10 @@ function Log(filename, opts) { const filenameNew = filename + '.compacting' const [err2] = await p(fs.unlink.bind(fs))(filenameNew) - if (err2 && err2.code !== 'ENOENT') return cb(err2) + if (err2 && err2.code !== 'ENOENT') { + // prettier-ignore + return cb(new Error('Failed to get rid of previous compaction file when starting a new compact', {cause: err2})) + } const rafNew = RAF(filenameNew) @@ -834,6 +838,8 @@ function Log(filename, opts) { const sizeDiff = oldTotalBytes - getTotalBytes() lastRecOffset.set(nextSince) compacting = false + const duration = Date.now() - startCompactTimestamp + debug2('Completed in %d ms', duration) deletedBytes = 0 saveStats(function onSavedStatsAfterCompaction(err) { if (err) debug2('Failed to save stats file: %s', err.message) @@ -904,17 +910,17 @@ function Log(filename, opts) { return { // Public API: - scan: onLoad(scan), // TODO - del: onLoad(del), // TODO - append: onLoad(append), // TODO - overwrite: onLoad(overwrite), // TODO - close: onLoad(close), // TODO - onDrain: onLoad(onDrain), // TODO + scan: onLoad(scan), + del: onLoad(del), + append: onLoad(append), + overwrite: onLoad(overwrite), + close: onLoad(close), + onDrain: onLoad(onDrain), onOverwritesFlushed: onLoad(onOverwritesFlushed), - compact: onLoad(compact), // TODO + compact: onLoad(compact), compactionProgress, lastRecOffset, - stats, // TODO + stats, // Useful for tests _get: onLoad(get),