Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 28 additions & 31 deletions badger/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,40 +547,37 @@ type flushTask struct {
func (s *KV) flushMemtable(lc *y.LevelCloser) {
defer lc.Done()

for {
select {
case ft := <-s.flushChan:
if ft.mt == nil {
return
}
for ft := range s.flushChan {
if ft.mt == nil {
return
}

if ft.vptr.Fid > 0 || ft.vptr.Offset > 0 {
if s.opt.Verbose {
fmt.Printf("Storing offset: %+v\n", ft.vptr)
}
offset := make([]byte, 16)
s.Lock() // For vptr.
s.vptr.Encode(offset)
s.Unlock()
ft.mt.Put(head, y.ValueStruct{Value: offset}) // casCounter not needed.
if ft.vptr.Fid > 0 || ft.vptr.Offset > 0 {
if s.opt.Verbose {
fmt.Printf("Storing offset: %+v\n", ft.vptr)
}
fileID, _ := s.lc.reserveFileIDs(1)
fd, err := y.OpenSyncedFile(table.NewFilename(fileID, s.opt.Dir), true)
y.Check(err)
y.Check(writeLevel0Table(ft.mt, fd))

tbl, err := table.OpenTable(fd, s.opt.MapTablesTo)
defer tbl.DecrRef()

y.Check(err)
s.lc.addLevel0Table(tbl) // This will incrRef again.

// Update s.imm. Need a lock.
s.Lock()
y.AssertTrue(ft.mt == s.imm[0]) //For now, single threaded.
s.imm = s.imm[1:]
ft.mt.DecrRef() // Return memory.
offset := make([]byte, 16)
s.Lock() // For vptr.
s.vptr.Encode(offset)
s.Unlock()
ft.mt.Put(head, y.ValueStruct{Value: offset}) // casCounter not needed.
}
fileID, _ := s.lc.reserveFileIDs(1)
fd, err := y.OpenSyncedFile(table.NewFilename(fileID, s.opt.Dir), true)
y.Check(err)
y.Check(writeLevel0Table(ft.mt, fd))

tbl, err := table.OpenTable(fd, s.opt.MapTablesTo)
defer tbl.DecrRef()

y.Check(err)
s.lc.addLevel0Table(tbl) // This will incrRef again.

// Update s.imm. Need a lock.
s.Lock()
y.AssertTrue(ft.mt == s.imm[0]) //For now, single threaded.
s.imm = s.imm[1:]
ft.mt.DecrRef() // Return memory.
s.Unlock()
}
}
2 changes: 1 addition & 1 deletion badger/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func (l *valueLog) openOrCreateFiles() {
}

sort.Slice(l.files, func(i, j int) bool {
return l.files[i].fid < l.files[i].fid
return l.files[i].fid < l.files[j].fid
})

// Open all previous log files as read only. Open the last log file
Expand Down
2 changes: 0 additions & 2 deletions table/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ func (b *TableBuilder) blockIndex() []byte {
return out
}

var emptySlice = make([]byte, 100)

// Finish finishes the table by appending the index.
func (b *TableBuilder) Finish(metadata []byte) []byte {
bf := bbloom.New(float64(b.keyCount), 0.01)
Expand Down
8 changes: 3 additions & 5 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (t *Table) readIndex() error {
}(bo)
}

for _ = range t.blockIndex {
for range t.blockIndex {
err := <-che
if err != nil {
return err
Expand All @@ -291,10 +291,8 @@ func (t *Table) block(idx int) (Block, error) {
offset: ko.offset,
}
var err error
if block.data, err = t.read(block.offset, ko.len); err != nil {
return block, err
}
return block, nil
block.data, err = t.read(block.offset, ko.len)
return block, err
}

func (t *Table) Size() int64 { return int64(t.tableSize) }
Expand Down