fix(table): always sync SST to disk (#1625)

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.
This commit is contained in:
Naman Jain
2020-12-23 13:44:11 +05:30
committed by GitHub
parent 47e6407800
commit 5d8aa51ead
2 changed files with 2 additions and 6 deletions
-1
View File
@@ -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,
+2 -5
View File
@@ -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
@@ -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)
}