Skip to content

Commit

Permalink
Lock round access to query results (grafana#1042)
Browse files Browse the repository at this point in the history
Now that QueryPages() runs across multiple goroutines, the callback
can be running in parallel so we need to lock round the single data
structure it is accessing.

Signed-off-by: Bryan Boreham <[email protected]>
  • Loading branch information
bboreham authored Sep 28, 2018
1 parent 08f101e commit 17ae17a
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions chunk_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"sort"
"sync"
"time"

"github.com/go-kit/kit/log/level"
Expand Down Expand Up @@ -347,9 +348,11 @@ func (c *store) lookupChunksByMetricName(ctx context.Context, from, through mode
}

func (c *store) lookupEntriesByQueries(ctx context.Context, queries []IndexQuery) ([]IndexEntry, error) {
var lock sync.Mutex
var entries []IndexEntry
err := c.storage.QueryPages(ctx, queries, func(query IndexQuery, resp ReadBatch) bool {
iter := resp.Iterator()
lock.Lock()
for iter.Next() {
entries = append(entries, IndexEntry{
TableName: query.TableName,
Expand All @@ -358,6 +361,7 @@ func (c *store) lookupEntriesByQueries(ctx context.Context, queries []IndexQuery
Value: iter.Value(),
})
}
lock.Unlock()
return true
})
if err != nil {
Expand Down

0 comments on commit 17ae17a

Please sign in to comment.