Skip to content

Commit

Permalink
fix(table): always sync SST to disk (dgraph-io#1625)
Browse files Browse the repository at this point in the history
SST files were not sync'ed to disk by default. Machine crash may happen before the explicit sync (which happens at DB close), leading to an inconsistent state and badger not able to open. It is better to explicitly do a sync.
  • Loading branch information
NamanJain8 committed Dec 23, 2020
1 parent afaf022 commit c20628f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
1 change: 0 additions & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ func buildTableOptions(db *DB) table.Options {
dk, err := db.registry.LatestDataKey()
y.Check(err)
return table.Options{
SyncWrites: opt.SyncWrites,
ReadOnly: opt.ReadOnly,
TableSize: uint64(opt.BaseTableSize),
BlockSize: opt.BlockSize,
Expand Down
7 changes: 2 additions & 5 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const intSize = int(unsafe.Sizeof(int(0)))
type Options struct {
// Options for Opening/Building Table.

SyncWrites bool
// Open tables in read only mode.
ReadOnly bool

Expand Down Expand Up @@ -269,10 +268,8 @@ func CreateTable(fname string, builder *Builder) (*Table, error) {

written := bd.Copy(mf.Data)
y.AssertTrue(written == len(mf.Data))
if builder.opts.SyncWrites {
if err := z.Msync(mf.Data); err != nil {
return nil, y.Wrapf(err, "while calling msync on %s", fname)
}
if err := z.Msync(mf.Data); err != nil {
return nil, y.Wrapf(err, "while calling msync on %s", fname)
}
return OpenTable(mf, *builder.opts)
}
Expand Down

0 comments on commit c20628f

Please sign in to comment.