Add support for explicit Sync

This commit is contained in:
kevburnsjr 2023-03-22 04:54:09 -07:00
parent 71088bcabf
commit 69bc59c5bc
1 changed files with 14 additions and 0 deletions

View File

@ -628,6 +628,20 @@ func (db *DB) backgroundManager() {
}
}
// Sync will synchronously persist the database file to disk. This
// should only be used when [SyncPolicy] is set to [Never].
func (db *DB) Sync() error {
db.mu.Lock()
defer db.mu.Unlock()
if db.closed {
return ErrDatabaseClosed
}
if !db.persist {
return nil
}
return db.file.Sync()
}
// Shrink will make the database file smaller by removing redundant
// log entries. This operation does not block the database.
func (db *DB) Shrink() error {