Skip to content

Commit

Permalink
mvcc: HashKV gets keep from kvindex.Keep
Browse files Browse the repository at this point in the history
  • Loading branch information
fanminshi committed Jul 31, 2017
1 parent c49e300 commit f2dcbdf
Showing 1 changed file with 5 additions and 25 deletions.
30 changes: 5 additions & 25 deletions mvcc/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,6 @@ type store struct {
fifoSched schedule.Scheduler

stopc chan struct{}

// keepMu protects keep
keepMu sync.RWMutex
// keep contains all revisions <= compactMainRev to be kept for the
// ongoing compaction; nil otherwise.
keep map[revision]struct{}
}

// NewStore returns a new store. It is useful to create a store inside
Expand Down Expand Up @@ -170,33 +164,25 @@ func (s *store) Hash() (hash uint32, revision int64, err error) {
}

func (s *store) HashByRev(rev int64) (hash uint32, currentRev int64, compactRev int64, err error) {
s.mu.Lock()
s.mu.RLock()
s.revMu.RLock()
compactRev, currentRev = s.compactMainRev, s.currentRev
s.revMu.RUnlock()

if rev > 0 && rev <= compactRev {
s.mu.Unlock()
s.mu.RUnlock()
return 0, 0, compactRev, ErrCompacted
} else if rev > 0 && rev > currentRev {
s.mu.Unlock()
s.mu.RUnlock()
return 0, currentRev, 0, ErrFutureRev
}

s.keepMu.Lock()
if s.keep == nil {
// ForceCommit ensures that txnRead begins after backend
// has committed all the changes from the prev completed compaction.
s.b.ForceCommit()
s.keep = emptyKeep
}
keep := s.keep
s.keepMu.Unlock()
keep := s.kvindex.Keep(rev)

tx := s.b.ReadTx()
tx.Lock()
defer tx.Unlock()
s.mu.Unlock()
s.mu.RUnlock()

if rev == 0 {
rev = currentRev
Expand Down Expand Up @@ -257,9 +243,6 @@ func (s *store) Compact(rev int64) (<-chan struct{}, error) {
s.b.ForceCommit()

keep := s.kvindex.Compact(rev)
s.keepMu.Lock()
s.keep = keep
s.keepMu.Unlock()
ch := make(chan struct{})
var j = func(ctx context.Context) {
if ctx.Err() != nil {
Expand All @@ -271,9 +254,6 @@ func (s *store) Compact(rev int64) (<-chan struct{}, error) {
return
}
close(ch)
s.keepMu.Lock()
s.keep = nil
s.keepMu.Unlock()
}

s.fifoSched.Schedule(j)
Expand Down

0 comments on commit f2dcbdf

Please sign in to comment.