mirror of https://github.com/etcd-io/bbolt.git
Merge pull request #225 from benbjohnson/no-sync
Add DB.NoSync option for bulk loading.pull/34/head
commit
89f9735610
|
@ -46,6 +46,7 @@ func Bench(options *BenchOptions) {
|
|||
fatal(err)
|
||||
return
|
||||
}
|
||||
db.NoSync = options.NoSync
|
||||
db.FillPercent = options.FillPercent
|
||||
defer db.Close()
|
||||
|
||||
|
@ -363,6 +364,7 @@ type BenchOptions struct {
|
|||
BlockProfile string
|
||||
StatsInterval time.Duration
|
||||
FillPercent float64
|
||||
NoSync bool
|
||||
Clean bool
|
||||
}
|
||||
|
||||
|
|
|
@ -118,6 +118,7 @@ func NewApp() *cli.App {
|
|||
&cli.StringFlag{Name: "blockprofile", Usage: "Block profile output path"},
|
||||
&cli.StringFlag{Name: "stats-interval", Value: "0s", Usage: "Continuous stats interval"},
|
||||
&cli.Float64Flag{Name: "fill-percent", Value: bolt.DefaultFillPercent, Usage: "Fill percentage"},
|
||||
&cli.BoolFlag{Name: "no-sync", Usage: "Skip fsync on every commit"},
|
||||
&cli.BoolFlag{Name: "work", Usage: "Print the temp db and do not delete on exit"},
|
||||
},
|
||||
Action: func(c *cli.Context) {
|
||||
|
@ -139,6 +140,7 @@ func NewApp() *cli.App {
|
|||
BlockProfile: c.String("blockprofile"),
|
||||
StatsInterval: statsInterval,
|
||||
FillPercent: c.Float64("fill-percent"),
|
||||
NoSync: c.Bool("no-sync"),
|
||||
Clean: !c.Bool("work"),
|
||||
})
|
||||
},
|
||||
|
|
9
db.go
9
db.go
|
@ -47,6 +47,15 @@ type DB struct {
|
|||
// amount if you know that your write workloads are mostly append-only.
|
||||
FillPercent float64
|
||||
|
||||
// Setting the NoSync flag will cause the database to skip fsync()
|
||||
// calls after each commit. This can be useful when bulk loading data
|
||||
// into a database and you can restart the bulk load in the event of
|
||||
// a system failure or database corruption. Do not set this flag for
|
||||
// normal use.
|
||||
//
|
||||
// THIS IS UNSAFE. PLEASE USE WITH CAUTION.
|
||||
NoSync bool
|
||||
|
||||
path string
|
||||
file *os.File
|
||||
dataref []byte
|
||||
|
|
12
tx.go
12
tx.go
|
@ -425,8 +425,10 @@ func (tx *Tx) write() error {
|
|||
// Update statistics.
|
||||
tx.stats.Write++
|
||||
}
|
||||
if err := fdatasync(tx.db.file); err != nil {
|
||||
return err
|
||||
if !tx.db.NoSync {
|
||||
if err := fdatasync(tx.db.file); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Clear out page cache.
|
||||
|
@ -446,8 +448,10 @@ func (tx *Tx) writeMeta() error {
|
|||
if _, err := tx.db.ops.writeAt(buf, int64(p.id)*int64(tx.db.pageSize)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := fdatasync(tx.db.file); err != nil {
|
||||
return err
|
||||
if !tx.db.NoSync {
|
||||
if err := fdatasync(tx.db.file); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Update statistics.
|
||||
|
|
Loading…
Reference in New Issue