aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-06-05 09:58:41 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-06-05 09:58:41 -0600
commit63373660bc2ef10ad6de3d3101cd8a9910692407 (patch)
tree0df145b27d723bde29cf7c851d12dde2a0f353fc
parentMerge pull request #181 from benbjohnson/split-merge (diff)
downloaddedo-63373660bc2ef10ad6de3d3101cd8a9910692407.tar.gz
dedo-63373660bc2ef10ad6de3d3101cd8a9910692407.tar.xz
Add fallback for O_DIRECT in Tx.Copy().
This commit adds the ability for Bolt to fallback to using a regular file open if Tx.Copy() errors while opening with O_DIRECT. This only affects Linux.
-rw-r--r--tx.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/tx.go b/tx.go
index cc2b13f..a9781f2 100644
--- a/tx.go
+++ b/tx.go
@@ -239,10 +239,15 @@ func (tx *Tx) close() {
// using the database while a copy is in progress.
// Copy will write exactly tx.Size() bytes into the writer.
func (tx *Tx) Copy(w io.Writer) error {
- // Open reader on the database.
- f, err := os.OpenFile(tx.db.path, os.O_RDONLY|odirect, 0)
- if err != nil {
- return err
+ var f *os.File
+ var err error
+
+ // Attempt to open reader directly.
+ if f, err = os.OpenFile(tx.db.path, os.O_RDONLY|odirect, 0); err != nil {
+ // Fallback to a regular open if that doesn't work.
+ if f, err = os.OpenFile(tx.db.path, os.O_RDONLY, 0); err != nil {
+ return err
+ }
}
// Copy the meta pages.