Skip to content

Commit

Permalink
Fix data race when batch.Reset. Fix blevesearch#1460
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Sep 8, 2020
1 parent a929f94 commit 86f4034
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
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

0 comments on commit 86f4034

Please sign in to comment.