mirror of https://github.com/etcd-io/bbolt.git
Avoid trashing page cache on Tx.Copy().
This commit change the database copy to use O_DIRECT so that the Linux page cache is not trashed during a backup. This is only available on Linux.pull/34/head
parent
7432bc341f
commit
bfccbb2cb5
6
bolt.go
6
bolt.go
|
@ -2,7 +2,11 @@
|
||||||
|
|
||||||
package bolt
|
package bolt
|
||||||
|
|
||||||
import "os"
|
import (
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
var odirect int
|
||||||
|
|
||||||
func fdatasync(f *os.File) error {
|
func fdatasync(f *os.File) error {
|
||||||
return f.Sync()
|
return f.Sync()
|
||||||
|
|
|
@ -5,6 +5,8 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var odirect = syscall.O_DIRECT
|
||||||
|
|
||||||
func fdatasync(f *os.File) error {
|
func fdatasync(f *os.File) error {
|
||||||
return syscall.Fdatasync(int(f.Fd()))
|
return syscall.Fdatasync(int(f.Fd()))
|
||||||
}
|
}
|
||||||
|
|
2
tx.go
2
tx.go
|
@ -240,7 +240,7 @@ func (tx *Tx) close() {
|
||||||
// Copy will write exactly tx.Size() bytes into the writer.
|
// Copy will write exactly tx.Size() bytes into the writer.
|
||||||
func (tx *Tx) Copy(w io.Writer) error {
|
func (tx *Tx) Copy(w io.Writer) error {
|
||||||
// Open reader on the database.
|
// Open reader on the database.
|
||||||
f, err := os.Open(tx.db.path)
|
f, err := os.OpenFile(tx.db.path, os.O_RDONLY|odirect, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = tx.Rollback()
|
_ = tx.Rollback()
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue