From b107b35f197faa782ddd569e7649ccdd70f987f3 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Mon, 4 May 2015 14:10:25 -0600 Subject: Add DB.NoGrowSync flag. This commit adds the DB.NoGrowSync flag to optionally revert mmap() calls to how they were implemented before the ext3/ext4 fix. When NoGrowSync is true, remapping the data file will not force the file system to resize it immediately. This works for non-ext3/4 file systems. The default value of NoGrowSync is false so it is still safe for ext3/ext4 file systems by default. See also: https://github.com/boltdb/bolt/issues/284 --- bolt_unix.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'bolt_unix.go') diff --git a/bolt_unix.go b/bolt_unix.go index e222cfd..35dce08 100644 --- a/bolt_unix.go +++ b/bolt_unix.go @@ -44,11 +44,13 @@ func funlock(f *os.File) error { func mmap(db *DB, sz int) error { // Truncate and fsync to ensure file size metadata is flushed. // https://github.com/boltdb/bolt/issues/284 - if err := db.file.Truncate(int64(sz)); err != nil { - return fmt.Errorf("file resize error: %s", err) - } - if err := db.file.Sync(); err != nil { - return fmt.Errorf("file sync error: %s", err) + if !db.NoGrowSync { + if err := db.file.Truncate(int64(sz)); err != nil { + return fmt.Errorf("file resize error: %s", err) + } + if err := db.file.Sync(); err != nil { + return fmt.Errorf("file sync error: %s", err) + } } // Map the data file to memory. -- cgit v1.2.3