Skip to content

Commit

Permalink
fix(compaction): copy over the file ID when building tables #1713
Browse files Browse the repository at this point in the history
(cherry picked from commit e41ed97)
  • Loading branch information
NamanJain8 committed Jun 30, 2021
1 parent 0a407cb commit 2fada69
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions levels.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,34 +829,29 @@ func (s *levelsController) subcompact(it y.Iterator, kr keyRange, cd compactDef,
continue
}
numBuilds++
fileID := s.reserveFileID()
if err := inflightBuilders.Do(); err != nil {
// Can't return from here, until I decrRef all the tables that I built so far.
break
}
go func(builder *table.Builder) {
go func(builder *table.Builder, fileID uint64) {
var err error
defer inflightBuilders.Done(err)
defer builder.Close()

build := func(fileID uint64) (*table.Table, error) {
fname := table.NewFilename(fileID, s.kv.opt.Dir)
return table.CreateTable(fname, builder)
}

var tbl *table.Table
if s.kv.opt.InMemory {
tbl, err = table.OpenInMemoryTable(builder.Finish(), fileID, &bopts)
} else {
tbl, err = build(fileID)
fname := table.NewFilename(fileID, s.kv.opt.Dir)
tbl, err = table.CreateTable(fname, builder)
}

// If we couldn't build the table, return fast.
if err != nil {
return
}
res <- tbl
}(builder)
}(builder, s.reserveFileID())
}
s.kv.vlog.updateDiscardStats(discardStats)
s.kv.opt.Debugf("Discard stats: %v", discardStats)
Expand Down

0 comments on commit 2fada69

Please sign in to comment.