only set bits after the holder is completely setup

This should help prevent a data race. SetBit can, in some cases, cause an
asynchronous task to run which tries to update the stats counter.

But if that task runs while we are modifying the stats counter itself, we have a
data race.
This commit is contained in:
reesporte 2022-02-25 10:53:45 -06:00
parent 6b23925bd7
commit 45633e23a5

View file

@ -81,11 +81,6 @@ func TestStatsCount_TopN(t *testing.T) {
defer c.Close()
hldr := test.Holder{Holder: c.GetNode(0).Server.Holder()}
hldr.SetBit("d", "f", 0, 0)
hldr.SetBit("d", "f", 0, 1)
hldr.SetBit("d", "f", 0, pilosa.ShardWidth)
hldr.SetBit("d", "f", 0, pilosa.ShardWidth+2)
// Execute query.
called := false
hldr.Holder.Stats = &MockStats{
@ -101,6 +96,12 @@ func TestStatsCount_TopN(t *testing.T) {
called = true
},
}
hldr.SetBit("d", "f", 0, 0)
hldr.SetBit("d", "f", 0, 1)
hldr.SetBit("d", "f", 0, pilosa.ShardWidth)
hldr.SetBit("d", "f", 0, pilosa.ShardWidth+2)
if _, err := c.GetNode(0).API.Query(context.Background(), &pilosa.QueryRequest{Index: "d", Query: `TopN(field=f, n=2)`}); err != nil {
t.Fatal(err)
}