diff options
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | bolt_unix.go | 2 | ||||
-rw-r--r-- | bolt_unix_solaris.go | 101 | ||||
-rw-r--r-- | cmd/bolt/main.go | 6 | ||||
-rw-r--r-- | db_test.go | 10 |
5 files changed, 117 insertions, 5 deletions
@@ -592,7 +592,7 @@ Here are a few things to note when evaluating and using Bolt: Below is a list of public, open source projects that use Bolt: * [Operation Go: A Routine Mission](http://gocode.io) - An online programming game for Golang using Bolt for user accounts and a leaderboard. -* [Bazil](https://github.com/bazillion/bazil) - A file system that lets your data reside where it is most convenient for it to reside. +* [Bazil](https://bazil.org/) - A file system that lets your data reside where it is most convenient for it to reside. * [DVID](https://github.com/janelia-flyem/dvid) - Added Bolt as optional storage engine and testing it against Basho-tuned leveldb. * [Skybox Analytics](https://github.com/skybox/skybox) - A standalone funnel analysis tool for web analytics. * [Scuttlebutt](https://github.com/benbjohnson/scuttlebutt) - Uses Bolt to store and process all Twitter mentions of GitHub projects. @@ -616,5 +616,6 @@ Below is a list of public, open source projects that use Bolt: * [Prometheus Annotation Server](https://github.com/oliver006/prom_annotation_server) - Annotation server for PromDash & Prometheus service monitoring system. * [Consul](https://github.com/hashicorp/consul) - Consul is service discovery and configuration made easy. Distributed, highly available, and datacenter-aware. * [Kala](https://github.com/ajvb/kala) - Kala is a modern job scheduler optimized to run on a single node. It is persistant, JSON over HTTP API, ISO 8601 duration notation, and dependent jobs. +* [drive](https://github.com/odeke-em/drive) - drive is an unofficial Google Drive command line client for \*NIX operating systems. If you are using Bolt in a project please send a pull request to add it to the list. diff --git a/bolt_unix.go b/bolt_unix.go index 17ca318..6eef6b2 100644 --- a/bolt_unix.go +++ b/bolt_unix.go @@ -1,4 +1,4 @@ -// +build !windows,!plan9 +// +build !windows,!plan9,!solaris package bolt diff --git a/bolt_unix_solaris.go b/bolt_unix_solaris.go new file mode 100644 index 0000000..f480ee7 --- /dev/null +++ b/bolt_unix_solaris.go @@ -0,0 +1,101 @@ + +package bolt + +import ( + "fmt" + "os" + "syscall" + "time" + "unsafe" + "golang.org/x/sys/unix" +) + +// flock acquires an advisory lock on a file descriptor. +func flock(f *os.File, exclusive bool, timeout time.Duration) error { + var t time.Time + for { + // If we're beyond our timeout then return an error. + // This can only occur after we've attempted a flock once. + if t.IsZero() { + t = time.Now() + } else if timeout > 0 && time.Since(t) > timeout { + return ErrTimeout + } + var lock syscall.Flock_t + lock.Start = 0 + lock.Len = 0 + lock.Pid = 0 + lock.Whence = 0 + lock.Pid = 0 + if exclusive { + lock.Type = syscall.F_WRLCK + } else { + lock.Type = syscall.F_RDLCK + } + err := syscall.FcntlFlock(f.Fd(), syscall.F_SETLK, &lock) + if err == nil { + return nil + } else if err != syscall.EAGAIN { + return err + } + + // Wait for a bit and try again. + time.Sleep(50 * time.Millisecond) + } +} + +// funlock releases an advisory lock on a file descriptor. +func funlock(f *os.File) error { + var lock syscall.Flock_t + lock.Start = 0 + lock.Len = 0 + lock.Type = syscall.F_UNLCK + lock.Whence = 0 + return syscall.FcntlFlock(uintptr(f.Fd()), syscall.F_SETLK, &lock) +} + +// mmap memory maps a DB's data file. +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 !db.NoGrowSync && !db.readOnly { + 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. + b, err := unix.Mmap(int(db.file.Fd()), 0, sz, syscall.PROT_READ, syscall.MAP_SHARED) + if err != nil { + return err + } + + // Advise the kernel that the mmap is accessed randomly. + if err := unix.Madvise(b, syscall.MADV_RANDOM); err != nil { + return fmt.Errorf("madvise: %s", err) + } + + // Save the original byte slice and convert to a byte array pointer. + db.dataref = b + db.data = (*[maxMapSize]byte)(unsafe.Pointer(&b[0])) + db.datasz = sz + return nil +} + +// munmap unmaps a DB's data file from memory. +func munmap(db *DB) error { + // Ignore the unmap if we have no mapped data. + if db.dataref == nil { + return nil + } + + // Unmap using the original byte slice. + err := unix.Munmap(db.dataref) + db.dataref = nil + db.data = nil + db.datasz = 0 + return err +} diff --git a/cmd/bolt/main.go b/cmd/bolt/main.go index a1f2ae8..c41ebe4 100644 --- a/cmd/bolt/main.go +++ b/cmd/bolt/main.go @@ -344,7 +344,7 @@ func (cmd *DumpCommand) Run(args ...string) error { for i, pageID := range pageIDs { // Print a separator. if i > 0 { - fmt.Fprintln(cmd.Stdout, "===============================================\n") + fmt.Fprintln(cmd.Stdout, "===============================================") } // Print page to stdout. @@ -465,7 +465,7 @@ func (cmd *PageCommand) Run(args ...string) error { for i, pageID := range pageIDs { // Print a separator. if i > 0 { - fmt.Fprintln(cmd.Stdout, "===============================================\n") + fmt.Fprintln(cmd.Stdout, "===============================================") } // Retrieve page info and page size. @@ -917,7 +917,7 @@ func (cmd *BenchCommand) Run(args ...string) error { // Write to the database. var results BenchResults if err := cmd.runWrites(db, options, &results); err != nil { - return fmt.Errorf("write: ", err) + return fmt.Errorf("write: %v", err) } // Read from the database. @@ -42,6 +42,9 @@ func TestOpen_Timeout(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("timeout not supported on windows") } + if runtime.GOOS == "solaris" { + t.Skip("solaris fcntl locks don't support intra-process locking") + } path := tempfile() defer os.Remove(path) @@ -66,6 +69,9 @@ func TestOpen_Wait(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("timeout not supported on windows") } + if runtime.GOOS == "solaris" { + t.Skip("solaris fcntl locks don't support intra-process locking") + } path := tempfile() defer os.Remove(path) @@ -228,6 +234,10 @@ func TestDB_Open_FileTooSmall(t *testing.T) { // and that a database can not be opened in read-write mode and in read-only // mode at the same time. func TestOpen_ReadOnly(t *testing.T) { + if runtime.GOOS == "solaris" { + t.Skip("solaris fcntl locks don't support intra-process locking") + } + bucket, key, value := []byte(`bucket`), []byte(`key`), []byte(`value`) path := tempfile() |