Skip to content

Commit

Permalink
Remove Evict() API and call Close(). (#2382)
Browse files Browse the repository at this point in the history
  • Loading branch information
notbdu authored Jun 1, 2020
1 parent 63f5a1a commit c415cbc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/dbnode/storage/index/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ func (b *block) EvictMutableSegments() error {
return fmt.Errorf("unable to evict mutable segments, block must be sealed, found: %v", b.state)
}

b.mutableSegments.Evict()
b.mutableSegments.Close()

// Close any other mutable segments that was added.
multiErr := xerrors.NewMultiError()
Expand Down Expand Up @@ -1046,7 +1046,7 @@ func (b *block) EvictColdMutableSegments() error {
// Evict/remove all but the most recent cold mutable segment (That is the one we are actively writing to).
for i, coldSeg := range b.coldMutableSegments {
if i < len(b.coldMutableSegments)-1 {
coldSeg.Evict()
coldSeg.Close()
b.coldMutableSegments[i] = nil
}
}
Expand Down
27 changes: 7 additions & 20 deletions src/dbnode/storage/index/mutable_segments.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ const (
type mutableSegments struct {
sync.RWMutex

state mutableSegmentsState
hasEvictedAnyTimes bool
state mutableSegmentsState

foregroundSegments []*readableSeg
backgroundSegments []*readableSeg
Expand Down Expand Up @@ -243,13 +242,6 @@ func (m *mutableSegments) NeedsEviction() bool {
return needsEviction
}

func (m *mutableSegments) Evict() {
m.Lock()
defer m.Unlock()
m.hasEvictedAnyTimes = true
m.cleanupCompactWithLock()
}

func (m *mutableSegments) NumSegmentsAndDocs() (int64, int64) {
var (
numSegments, numDocs int64
Expand Down Expand Up @@ -334,12 +326,7 @@ func (m *mutableSegments) maybeBackgroundCompactWithLock() {
}

func (m *mutableSegments) shouldEvictCompactedSegmentsWithLock() bool {
// NB(r): The frozen/compacted segments are derived segments of the
// active mutable segment, if we ever evict that segment then
// we don't need the frozen/compacted segments either and should
// shed them from memory.
return m.state == mutableSegmentsStateClosed ||
m.hasEvictedAnyTimes
return m.state == mutableSegmentsStateClosed
}

func (m *mutableSegments) cleanupBackgroundCompactWithLock() {
Expand All @@ -350,12 +337,12 @@ func (m *mutableSegments) cleanupBackgroundCompactWithLock() {
}

// Check if need to close all the compacted segments due to
// having evicted mutable segments or the block being closed.
// mutableSegments being closed.
if !m.shouldEvictCompactedSegmentsWithLock() {
return
}

// Evict compacted segments.
// Close compacted segments.
m.closeCompactedSegments(m.backgroundSegments)
m.backgroundSegments = nil

Expand Down Expand Up @@ -685,13 +672,13 @@ func (m *mutableSegments) foregroundCompactWithTask(
}

func (m *mutableSegments) cleanupForegroundCompactWithLock() {
// Check if we need to close all the compacted segments due to
// having evicted mutable segments or the block being closed.
// Check if need to close all the compacted segments due to
// mutableSegments being closed.
if !m.shouldEvictCompactedSegmentsWithLock() {
return
}

// Evict compacted segments.
// Close compacted segments.
m.closeCompactedSegments(m.foregroundSegments)
m.foregroundSegments = nil

Expand Down

0 comments on commit c415cbc

Please sign in to comment.