Skip to content

another batch data race #1149

@mschoch

Description

@mschoch

Another corner case can lead to a race when resetting a batch, in this case it happens when batch just contains a delete (or more likely as it was found in the wild, when a batch contains ONLY deletes)

Here is the race with scorch:

=== RUN   TestBatchRaceBugXXX
==================
WARNING: DATA RACE
Write at 0x00c0003484a0 by goroutine 10:
  github.com/blevesearch/bleve.TestBatchRaceBugXXX()
      /home/mschoch/dev/go/src/github.com/blevesearch/bleve/index/index.go:310 +0x320
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:827 +0x162

Previous read at 0x00c0003484a0 by goroutine 15:
  github.com/blevesearch/bleve/index/scorch.(*Scorch).Batch.func2()
      /home/mschoch/dev/go/src/github.com/blevesearch/bleve/index/scorch/scorch.go:317 +0x52

Similar observation with upsidedown:

=== RUN   TestBatchRaceBugXXX
==================
WARNING: DATA RACE
Write at 0x00c000352440 by goroutine 10:
  github.com/blevesearch/bleve.TestBatchRaceBugXXX()
      /home/mschoch/dev/go/src/github.com/blevesearch/bleve/index/index.go:310 +0x2dc
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:827 +0x162

Previous read at 0x00c000352440 by goroutine 11:
  github.com/blevesearch/bleve/index/upsidedown.(*UpsideDownCouch).Batch.func1()
      /home/mschoch/dev/go/src/github.com/blevesearch/bleve/index/upsidedown/upsidedown.go:815 +0x52

The code to reproduce is:

func TestBatchRaceBugXXX(t *testing.T) {
	defer func() {
		err := os.RemoveAll("testidx")
		if err != nil {
			t.Fatal(err)
		}
	}()
	//i, err := New("testidx", NewIndexMapping())
	i, err := NewUsing("testidx", NewIndexMapping(), "scorch", "scorch", nil)
	if err != nil {
		t.Fatal(err)
	}
	defer func() {
		err := i.Close()
		if err != nil {
			t.Fatal(err)
		}
	}()
	b := i.NewBatch()
	b.Delete("1")
	err = i.Batch(b)
	if err != nil {
		t.Fatal(err)
	}
	b.Reset()
	err = i.Batch(b)
	if err != nil {
		t.Fatal(err)
	}
	b.Reset()
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions