Skip to content

Commit

Permalink
Add NoSync option
Browse files Browse the repository at this point in the history
Allow users to make a trade-off between performance and safety by
exposing an option to disable fsync on the database. Also add a
Sync call to allow explicit fsyncs.
  • Loading branch information
tylertreat committed Sep 6, 2017
1 parent df63155 commit e0cff12
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bolt_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ type Options struct {
// BoltOptions contains any specific BoltDB options you might
// want to specify [e.g. open timeout]
BoltOptions *bolt.Options

// NoSync causes the database to skip fsync calls after each
// write to the log. This is unsafe, so it should be used
// with caution.
NoSync bool
}

// readOnly returns true if the contained bolt options say to open
Expand All @@ -62,6 +67,7 @@ func New(options Options) (*BoltStore, error) {
if err != nil {
return nil, err
}
handle.NoSync = options.NoSync

// Create the new store
store := &BoltStore{
Expand Down Expand Up @@ -253,3 +259,10 @@ func (b *BoltStore) GetUint64(key []byte) (uint64, error) {
}
return bytesToUint64(val), nil
}

// Sync performs an fsync on the database file handle. This is not necessary
// under normal operation unless NoSync is enabled, in which this forces the
// database file to sync against the disk.
func (b *BoltStore) Sync() error {
return b.conn.Sync()
}

0 comments on commit e0cff12

Please sign in to comment.