log: show compaction duration in debugging

This commit is contained in:
Andre Staltz 2023-11-23 16:49:23 +02:00
parent 2b1de9bce7
commit 1f88d67116
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
1 changed files with 15 additions and 9 deletions

View File

@ -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),