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

Fix data race when batch.Reset. Fix #1460 #1461

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions index/scorch/scorch.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,17 @@ func (s *Scorch) Batch(batch *index.Batch) (err error) {
// FIXME could sort ids list concurrent with analysis?

if numUpdates > 0 {
go func() {
for _, doc := range batch.IndexOps {
// batch.IndexOps maybe reseted when the goroutine is running, so
// we should send a copy of it.
go func(ops map[string]*document.Document) {
for _, doc := range ops {
if doc != nil {
aw := index.NewAnalysisWork(s, doc, resultChan)
// put the work on the queue
s.analysisQueue.Queue(aw)
}
}
}()
}(batch.IndexOps)
}

// wait for analysis result
Expand Down
10 changes: 6 additions & 4 deletions index/upsidedown/upsidedown.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,16 +819,18 @@ func (udc *UpsideDownCouch) Batch(batch *index.Batch) (err error) {
}

if numUpdates > 0 {
go func() {
for k := range batch.IndexOps {
doc := batch.IndexOps[k]
// batch.IndexOps maybe reseted when the goroutine is running, so
// we should send a copy of it.
go func(ops map[string]*document.Document) {
for k := range ops {
doc := ops[k]
if doc != nil {
aw := index.NewAnalysisWork(udc, doc, resultChan)
// put the work on the queue
udc.analysisQueue.Queue(aw)
}
}
}()
}(batch.IndexOps)
}

// retrieve back index rows concurrent with analysis
Expand Down