Skip to content

Commit

Permalink
leveldb: optimize pickCompaction (#317)
Browse files Browse the repository at this point in the history
* leveldb: optimize pickCompaction

using binary search to find next table

* leveldb: remove unnecessary code for picking L0 table
  • Loading branch information
qianbin authored Aug 15, 2020
1 parent d415f1b commit a38fa22
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions leveldb/session_compaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package leveldb

import (
"sort"
"sync/atomic"

"github.com/syndtr/goleveldb/leveldb/iterator"
Expand Down Expand Up @@ -62,10 +63,12 @@ func (s *session) pickCompaction() *compaction {
sourceLevel = v.cLevel
cptr := s.getCompPtr(sourceLevel)
tables := v.levels[sourceLevel]
for _, t := range tables {
if cptr == nil || s.icmp.Compare(t.imax, cptr) > 0 {
t0 = append(t0, t)
break
if cptr != nil && sourceLevel > 0 {
n := len(tables)
if i := sort.Search(n, func(i int) bool {
return s.icmp.Compare(tables[i].imax, cptr) > 0
}); i < n {
t0 = append(t0, tables[i])
}
}
if len(t0) == 0 {
Expand Down

0 comments on commit a38fa22

Please sign in to comment.