Add rbf.SyncEnabled

This commit is contained in:
Ben Johnson 2020-10-05 10:14:03 -06:00
parent cf208cfaa3
commit 265452cf3d
3 changed files with 15 additions and 3 deletions

View file

@ -302,7 +302,7 @@ func (db *DB) checkpoint(exclusive bool, mu sync.Locker) error {
}
// Ensure WAL pages are fully copied & synced to DB file.
if err := db.file.Sync(); err != nil {
if err := fsync(db.file); err != nil {
return fmt.Errorf("db file sync: %w", err)
}

View file

@ -91,6 +91,11 @@ var (
// Debug is just a temporary flag used for debugging.
var Debug bool
// Testing constants.
const (
SyncEnabled = true
)
// Magic32 returns the magic bytes as a big endian encoded uint32.
func Magic32() uint32 {
return binary.BigEndian.Uint32([]byte(Magic))
@ -659,8 +664,15 @@ func truncate(path string, sz int64) error {
if err := f.Truncate(sz); err != nil {
return fmt.Errorf("truncate: %w", err)
} else if err := f.Sync(); err != nil {
} else if err := fsync(f); err != nil {
return fmt.Errorf("sync: %w", err)
}
return f.Close()
}
func fsync(f *os.File) error {
if !SyncEnabled {
return nil
}
return f.Sync()
}

View file

@ -1610,7 +1610,7 @@ func (tx *Tx) flushWALWriter() error {
// Flush cache to writer.
if _, err := w.WriteAt(tx.wcache, int64(segment.PageN)*PageSize); err != nil {
return fmt.Errorf("write wal segment: %w", err)
} else if err := w.Sync(); err != nil {
} else if err := fsync(w); err != nil {
return fmt.Errorf("sync wal segment: %w", err)
} else if err := w.Close(); err != nil {
return fmt.Errorf("close wal segment: %w", err)