Skip to content

Commit

Permalink
leveldb: polish code
Browse files Browse the repository at this point in the history
  • Loading branch information
rjl493456442 committed Oct 27, 2020
1 parent 54c3321 commit f58fffa
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions leveldb/session_compaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,6 @@ func (s *session) pickCompactionByTable(level int, table *tFile, ctx *compaction
}

func (s *session) getFirstRange(v *version, ctx *compactionContext, sourceLevel int, umin, umax []byte, typ int, limit int64) (comp *compaction) {
defer func() {
if comp == nil {
v.release()
}
}()
t0 := v.levels[sourceLevel].getOverlaps(nil, s.icmp, umin, umax, sourceLevel == 0)
if len(t0) == 0 {
return nil
Expand All @@ -207,12 +202,6 @@ func (s *session) getFirstRange(v *version, ctx *compactionContext, sourceLevel
}

func (s *session) getMoreRange(v *version, ctx *compactionContext, sourceLevel int, umin, umax []byte, typ int, sourceLimit int64) (comp *compaction) {
defer func() {
if comp == nil {
v.release()
}
}()

// Determine the search space for next potential range compaction
cs := ctx.get(sourceLevel)
if len(cs) == 0 {
Expand Down Expand Up @@ -270,11 +259,14 @@ func (s *session) getMoreRange(v *version, ctx *compactionContext, sourceLevel i
}

// Create compaction from given level and range; need external synchronization.
func (s *session) getCompactionRange(ctx *compactionContext, sourceLevel int, umin, umax []byte) *compaction {
func (s *session) getCompactionRange(ctx *compactionContext, sourceLevel int, umin, umax []byte) (comp *compaction) {
v := s.version()

defer func() {
if comp == nil {
v.release()
}
}()
if sourceLevel >= len(v.levels) {
v.release()
return nil
}
typ := level0Compaction
Expand All @@ -286,7 +278,6 @@ func (s *session) getCompactionRange(ctx *compactionContext, sourceLevel int, um
return s.getFirstRange(v, ctx, sourceLevel, umin, umax, typ, limit)
}
if sourceLevel == 0 {
v.release()
return nil
}
return s.getMoreRange(v, ctx, sourceLevel, umin, umax, typ, limit)
Expand Down

0 comments on commit f58fffa

Please sign in to comment.