Storage concurrently (#6770)

* Storage concurrently
Signed-off-by: fuling <fuling.lgz@alibaba-inc.com>
This commit is contained in:
李国忠 2020-02-12 01:19:34 +08:00 committed by GitHub
parent 1c321ed047
commit 40dd13b074
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 11 deletions

View File

@ -240,23 +240,39 @@ func (q *mergeQuerier) Select(params *SelectParams, matchers ...*labels.Matcher)
func (q *mergeQuerier) SelectSorted(params *SelectParams, matchers ...*labels.Matcher) (SeriesSet, Warnings, error) { func (q *mergeQuerier) SelectSorted(params *SelectParams, matchers ...*labels.Matcher) (SeriesSet, Warnings, error) {
seriesSets := make([]SeriesSet, 0, len(q.queriers)) seriesSets := make([]SeriesSet, 0, len(q.queriers))
var warnings Warnings var warnings Warnings
var priErr error = nil
type queryResult struct {
qr Querier
set SeriesSet
wrn Warnings
selectError error
}
queryResultChan := make(chan *queryResult)
for _, querier := range q.queriers { for _, querier := range q.queriers {
set, wrn, err := querier.SelectSorted(params, matchers...) go func(qr Querier) {
q.setQuerierMap[set] = querier set, wrn, err := qr.SelectSorted(params, matchers...)
if wrn != nil { queryResultChan <- &queryResult{qr: qr, set: set, wrn: wrn, selectError: err}
warnings = append(warnings, wrn...) }(querier)
} }
if err != nil { for i := 0; i < len(q.queriers); i++ {
q.failedQueriers[querier] = struct{}{} qryResult := <-queryResultChan
q.setQuerierMap[qryResult.set] = qryResult.qr
if qryResult.wrn != nil {
warnings = append(warnings, qryResult.wrn...)
}
if qryResult.selectError != nil {
q.failedQueriers[qryResult.qr] = struct{}{}
// If the error source isn't the primary querier, return the error as a warning and continue. // If the error source isn't the primary querier, return the error as a warning and continue.
if querier != q.primaryQuerier { if qryResult.qr != q.primaryQuerier {
warnings = append(warnings, err) warnings = append(warnings, qryResult.selectError)
continue
} else { } else {
return nil, nil, err priErr = qryResult.selectError
} }
} }
seriesSets = append(seriesSets, set) }
if priErr != nil {
return nil, nil, priErr
} }
return NewMergeSeriesSet(seriesSets, q), warnings, nil return NewMergeSeriesSet(seriesSets, q), warnings, nil
} }