mirror of https://github.com/hak5/bolt.git
Call fdatasync/fsync after writing out non-meta pages
This avoids a case where writes can be reordered so meta page is written before a page it refers to, potentially causing a corrupt database after a power loss or kernel crash.master
parent
6d6303a0a2
commit
5ce378b046
|
@ -0,0 +1,10 @@
|
|||
package bolt
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func fdatasync(f *os.File) error {
|
||||
return syscall.Fdatasync(int(f.Fd()))
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
// +build !linux
|
||||
|
||||
package bolt
|
||||
|
||||
import "os"
|
||||
|
||||
// Fall back to syncing metadata too.
|
||||
func fdatasync(f *os.File) error {
|
||||
return f.Sync()
|
||||
}
|
Loading…
Reference in New Issue