Skip to content
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 @@ -888,6 +888,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