aboutsummaryrefslogtreecommitdiff
path: root/db.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-09-22 11:53:19 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-09-22 11:53:19 -0600
commitd285804df1760edf4c602ecd901be5d5e67bf982 (patch)
treea69b6978e0c1231f5f051aabe6d16c7e9744c2c6 /db.go
parentMerge pull request #258 from davecgh/davec_build (diff)
parentFix bolt on OpenBSD. (diff)
downloaddedo-d285804df1760edf4c602ecd901be5d5e67bf982.tar.gz
dedo-d285804df1760edf4c602ecd901be5d5e67bf982.tar.xz
Merge pull request #259 from davecgh/jrick_msync
Fix bolt on OpenBSD
Diffstat (limited to 'db.go')
-rw-r--r--db.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/db.go b/db.go
index 7364454..6c45736 100644
--- a/db.go
+++ b/db.go
@@ -4,6 +4,7 @@ import (
"fmt"
"hash/fnv"
"os"
+ "runtime"
"runtime/debug"
"strings"
"sync"
@@ -23,6 +24,12 @@ const version = 2
// Represents a marker value to indicate that a file is a Bolt DB.
const magic uint32 = 0xED0CDAED
+// IgnoreNoSync specifies whether the NoSync field of a DB is ignored when
+// syncing changes to a file. This is required as some operating systems,
+// such as OpenBSD, do not have a unified buffer cache (UBC) and writes
+// must be synchronzied using the msync(2) syscall.
+const IgnoreNoSync = runtime.GOOS == "openbsd"
+
// DB represents a collection of buckets persisted to a file on disk.
// All data access is performed through transactions which can be obtained through the DB.
// All the functions on DB will return a ErrDatabaseNotOpen if accessed before Open() is called.
@@ -39,6 +46,9 @@ type DB struct {
// a system failure or database corruption. Do not set this flag for
// normal use.
//
+ // If the package global IgnoreNoSync constant is true, this value is
+ // ignored. See the comment on that constant for more details.
+ //
// THIS IS UNSAFE. PLEASE USE WITH CAUTION.
NoSync bool
@@ -263,7 +273,7 @@ func (db *DB) init() error {
if _, err := db.ops.writeAt(buf, 0); err != nil {
return err
}
- if err := fdatasync(db.file); err != nil {
+ if err := fdatasync(db); err != nil {
return err
}