Skip to content

Commit

Permalink
store: Don't do any seek operation after store closed.
Browse files Browse the repository at this point in the history
  • Loading branch information
ngaut committed Dec 18, 2015
1 parent 9030ba8 commit 1f9964c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions store/localstore/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func (s *dbStore) CommitTxn(txn *dbTxn) error {
return errors.Trace(err)
}

func (s *dbStore) seekWorker(seekCh chan *command) {
func (s *dbStore) seekWorker(wg *sync.WaitGroup, seekCh chan *command) {
defer wg.Done()
for {
var pending []*command
select {
Expand Down Expand Up @@ -131,8 +132,10 @@ func (s *dbStore) seekWorker(seekCh chan *command) {
func (s *dbStore) scheduler() {
closed := false
seekCh := make(chan *command, 1000)
wgSeekWorkers := &sync.WaitGroup{}
wgSeekWorkers.Add(maxSeekWorkers)
for i := 0; i < maxSeekWorkers; i++ {
go s.seekWorker(seekCh)
go s.seekWorker(wgSeekWorkers, seekCh)
}

for {
Expand All @@ -150,9 +153,10 @@ func (s *dbStore) scheduler() {
}
case <-s.closeCh:
closed = true
s.wg.Done()
// notify seek worker to exit
close(seekCh)
wgSeekWorkers.Wait()
s.wg.Done()
}
}
}
Expand Down

0 comments on commit 1f9964c

Please sign in to comment.