mirror of https://codeberg.org/pzp/pzp-db.git
log: show compaction duration in debugging
This commit is contained in:
parent
2b1de9bce7
commit
1f88d67116
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue