(ctx context.Context, req *bleve.SearchRequest)
| 110 | } |
| 111 | |
| 112 | func (g *GrpcClient) SearchInContext(ctx context.Context, |
| 113 | req *bleve.SearchRequest) (*bleve.SearchResult, error) { |
| 114 | if req == nil { |
| 115 | return nil, fmt.Errorf("grpc_client: SearchInContext, no req provided") |
| 116 | } |
| 117 | |
| 118 | queryCtlParams := &cbgt.QueryCtlParams{ |
| 119 | Ctl: cbgt.QueryCtl{ |
| 120 | Consistency: g.Consistency, |
| 121 | }, |
| 122 | } |
| 123 | |
| 124 | queryPIndexes := &QueryPIndexes{ |
| 125 | PIndexNames: g.PIndexNames, |
| 126 | } |
| 127 | |
| 128 | // if timeout was set, compute time remaining |
| 129 | if deadline, ok := ctx.Deadline(); ok { |
| 130 | remaining := deadline.Sub(time.Now()) |
| 131 | // FIXME arbitrarily reducing the timeout, to increase the liklihood |
| 132 | // that a live system replies via HTTP round-trip before we give up |
| 133 | // on the request externally |
| 134 | remaining -= RemoteRequestOverhead |
| 135 | if remaining <= 0 { |
| 136 | // not enough time left |
| 137 | return nil, context.DeadlineExceeded |
| 138 | } |
| 139 | queryCtlParams.Ctl.Timeout = int64(remaining / time.Millisecond) |
| 140 | } |
| 141 | |
| 142 | sr := &scatterRequest{ |
| 143 | ctlParams: queryCtlParams, |
| 144 | onlyPIndexes: queryPIndexes, |
| 145 | searchRequest: req, |
| 146 | } |
| 147 | |
| 148 | resultCh := make(chan *bleve.SearchResult) |
| 149 | |
| 150 | go func() { |
| 151 | rv, err := g.Query(ctx, sr) |
| 152 | if err != nil { |
| 153 | log.Warnf("grpc_client: Query() returned error from host: %v,"+ |
| 154 | " err: %v", g.HostPort, err) |
| 155 | resultCh <- makeSearchResultErr(req, g.PIndexNames, err) |
| 156 | return |
| 157 | } |
| 158 | |
| 159 | resultCh <- rv |
| 160 | }() |
| 161 | |
| 162 | select { |
| 163 | case <-ctx.Done(): |
| 164 | log.Warnf("grpc_client: scatter-gather error while awaiting results"+ |
| 165 | " from host: %v, err: %v", g.HostPort, ctx.Err()) |
| 166 | return makeSearchResultErr(req, g.PIndexNames, ctx.Err()), nil |
| 167 | case rv := <-resultCh: |
| 168 | return rv, nil |
| 169 | } |
no test coverage detected