Make writeHotBackupFile a method of VspDatabase.

No reason for this to be a standalone func with a param when it can be a method of VspDatabase. This will be useful later when VspDatabase contains its own logger.
This commit is contained in:
jholdstock 2022-03-31 09:30:51 +01:00 committed by Jamie Holdstock
parent d8dd02433c
commit d4b3d2fafb

View File

@ -62,15 +62,15 @@ var backupMtx sync.Mutex
// writeHotBackupFile writes a backup of the database file while the database // writeHotBackupFile writes a backup of the database file while the database
// is still open. // is still open.
func writeHotBackupFile(db *bolt.DB) error { func (vdb *VspDatabase) writeHotBackupFile() error {
backupMtx.Lock() backupMtx.Lock()
defer backupMtx.Unlock() defer backupMtx.Unlock()
backupPath := db.Path() + "-backup" backupPath := vdb.db.Path() + "-backup"
tempPath := backupPath + "~" tempPath := backupPath + "~"
// Write backup to temporary file. // Write backup to temporary file.
err := db.View(func(tx *bolt.Tx) error { err := vdb.db.View(func(tx *bolt.Tx) error {
return tx.CopyFile(tempPath, backupFileMode) return tx.CopyFile(tempPath, backupFileMode)
}) })
if err != nil { if err != nil {
@ -207,7 +207,7 @@ func Open(ctx context.Context, shutdownWg *sync.WaitGroup, dbFile string, backup
for { for {
select { select {
case <-time.After(backupInterval): case <-time.After(backupInterval):
err := writeHotBackupFile(db) err := vdb.writeHotBackupFile()
if err != nil { if err != nil {
log.Errorf("Failed to write database backup: %v", err) log.Errorf("Failed to write database backup: %v", err)
} }