Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shutdown executor goroutines #5130

Merged
merged 5 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions worker/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,9 @@ func (n *node) checkpointAndClose(done chan struct{}) {
}
n.Raft().Stop()
close(done)
if x.WorkerConfig.LudicrousMode {
n.ex.closer.SignalAndWait()
}
return
}
}
Expand Down
26 changes: 18 additions & 8 deletions worker/background_mutation.go → worker/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"sync"

"github.com/dgraph-io/badger/v2/y"
"github.com/dgraph-io/dgraph/posting"
"github.com/dgraph-io/dgraph/protos/pb"
"github.com/golang/glog"
Expand All @@ -36,24 +37,23 @@ type subMutation struct {
type executor struct {
sync.RWMutex
predChan map[string]chan *subMutation
closer *y.Closer
}

func newExecutor() *executor {
return &executor{
ex := &executor{
predChan: make(map[string]chan *subMutation),
closer: y.NewCloser(0),
}
go ex.shutdown()
return ex
}

func (e *executor) processMutationCh(ch chan *subMutation) {
defer e.closer.Done()

writer := posting.NewTxnWriter(pstore)
for payload := range ch {
select {
case <-ShutdownCh:
// Ignore all the unfinished mutation after shutdown signal.
glog.Infof("Ignoring further unfinished mutations")
return
default:
}
ptxn := posting.NewTxn(payload.startTs)
for _, edge := range payload.edges {
for {
Expand All @@ -77,6 +77,15 @@ func (e *executor) processMutationCh(ch chan *subMutation) {
}
}

func (e *executor) shutdown() {
<-e.closer.HasBeenClosed()
e.RLock()
defer e.RUnlock()
for _, ch := range e.predChan {
close(ch)
}
}

func (e *executor) getChannel(pred string) (ch chan *subMutation) {
e.RLock()
ch, ok := e.predChan[pred]
Expand All @@ -94,6 +103,7 @@ func (e *executor) getChannel(pred string) (ch chan *subMutation) {
}
ch = make(chan *subMutation, 1000)
e.predChan[pred] = ch
e.closer.AddRunning(1)
go e.processMutationCh(ch)
return ch
}
Expand Down