本文整理匯總了Golang中cluster.QueryProcessor.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang QueryProcessor.Close方法的具體用法?Golang QueryProcessor.Close怎麽用?Golang QueryProcessor.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cluster.QueryProcessor
的用法示例。
在下文中一共展示了QueryProcessor.Close方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runQuerySpec
func (self *CoordinatorImpl) runQuerySpec(querySpec *parser.QuerySpec, seriesWriter SeriesWriter) error {
shards := self.clusterConfiguration.GetShards(querySpec)
shouldAggregateLocally := true
var processor cluster.QueryProcessor
var responseChan chan *protocol.Response
var seriesClosed chan bool
for _, s := range shards {
// If the aggregation is done at the shard level, we don't need to
// do it here at the coordinator level.
if !s.ShouldAggregateLocally(querySpec) {
seriesClosed = make(chan bool)
shouldAggregateLocally = false
responseChan = make(chan *protocol.Response)
if querySpec.SelectQuery() != nil {
processor = engine.NewQueryEngine(querySpec.SelectQuery(), responseChan)
} else {
bufferSize := 100
processor = engine.NewPassthroughEngine(responseChan, bufferSize)
}
go func() {
for {
res := <-responseChan
if *res.Type == endStreamResponse || *res.Type == accessDeniedResponse {
seriesWriter.Close()
seriesClosed <- true
return
}
if res.Series != nil && len(res.Series.Points) > 0 {
seriesWriter.Write(res.Series)
}
}
}()
break
}
}
responses := make([]chan *protocol.Response, 0)
for _, shard := range shards {
responseChan := make(chan *protocol.Response, self.config.QueryShardBufferSize)
go shard.Query(querySpec, responseChan)
responses = append(responses, responseChan)
}
for i, responseChan := range responses {
log.Debug("READING: shard: ", shards[i].String())
for {
response := <-responseChan
log.Debug("GOT RESPONSE: ", response.Type, response.Series)
if *response.Type == endStreamResponse || *response.Type == accessDeniedResponse {
break
}
if shouldAggregateLocally {
log.Debug("WRITING: ", len(response.Series.Points))
seriesWriter.Write(response.Series)
log.Debug("WRITING (done)")
continue
}
// if the data wasn't aggregated at the shard level, aggregate
// the data here
log.Debug("YIELDING: ", len(response.Series.Points))
if response.Series != nil {
for _, p := range response.Series.Points {
processor.YieldPoint(response.Series.Name, response.Series.Fields, p)
}
}
}
log.Debug("DONE: shard: ", shards[i].String())
}
if !shouldAggregateLocally {
processor.Close()
<-seriesClosed
return nil
}
seriesWriter.Close()
return nil
}