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
18 changes: 10 additions & 8 deletions index/scorch/scorch.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,17 @@ func (s *Scorch) Batch(batch *index.Batch) (err error) {

// FIXME could sort ids list concurrent with analysis?

go func() {
for _, doc := range batch.IndexOps {
if doc != nil {
aw := index.NewAnalysisWork(s, doc, resultChan)
// put the work on the queue
s.analysisQueue.Queue(aw)
if len(batch.IndexOps) > 0 {
go func() {
for _, doc := range batch.IndexOps {
if doc != nil {
aw := index.NewAnalysisWork(s, doc, resultChan)
// put the work on the queue
s.analysisQueue.Queue(aw)
}
}
}
}()
}()
}

// wait for analysis result
analysisResults := make([]*index.AnalysisResult, int(numUpdates))
Expand Down
18 changes: 10 additions & 8 deletions index/upsidedown/upsidedown.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,15 +810,17 @@ func (udc *UpsideDownCouch) Batch(batch *index.Batch) (err error) {
}
}

go func() {
for _, doc := range batch.IndexOps {
if doc != nil {
aw := index.NewAnalysisWork(udc, doc, resultChan)
// put the work on the queue
udc.analysisQueue.Queue(aw)
if len(batch.IndexOps) > 0 {
go func() {
for _, doc := range batch.IndexOps {
if doc != nil {
aw := index.NewAnalysisWork(udc, doc, resultChan)
// put the work on the queue
udc.analysisQueue.Queue(aw)
}
}
}
}()
}()
}

// retrieve back index rows concurrent with analysis
docBackIndexRowErr := error(nil)
Expand Down
35 changes: 35 additions & 0 deletions index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/blevesearch/bleve/analysis/analyzer/keyword"
"github.com/blevesearch/bleve/document"
"github.com/blevesearch/bleve/index"
"github.com/blevesearch/bleve/index/store/boltdb"
"github.com/blevesearch/bleve/index/store/null"
"github.com/blevesearch/bleve/mapping"
"github.com/blevesearch/bleve/search"
Expand Down Expand Up @@ -2149,3 +2150,37 @@ func TestBug1096(t *testing.T) {
t.Fatalf("expected only 2 hits '9' and '90', got %v", res)
}
}

func TestDataRaceBug1092(t *testing.T) {
defer func() {
rerr := os.RemoveAll("testidx")
if rerr != nil {
t.Fatal(rerr)
}
}()

// use default mapping
mapping := NewIndexMapping()

var idx Index
idx, err = NewUsing("testidx", mapping, upsidedown.Name, boltdb.Name, nil)
if err != nil {
log.Fatal(err)
}
defer func() {
cerr := idx.Close()
if cerr != nil {
t.Fatal(cerr)
}
}()

batch := idx.NewBatch()
for i := 0; i < 10; i++ {
err = idx.Batch(batch)
if err != nil {
t.Error(err)
}

batch.Reset()
}
}