getNodesHostingPIndex confirms the list of node UUIDs hosting the given pindex.
(uuids []string, pindex, authType string, nodeDefs *cbgt.NodeDefs)
| 209 | // getNodesHostingPIndex confirms the list of node UUIDs |
| 210 | // hosting the given pindex. |
| 211 | func getNodesHostingPIndex(uuids []string, |
| 212 | pindex, authType string, nodeDefs *cbgt.NodeDefs) []string { |
| 213 | if len(uuids) == 0 { |
| 214 | return nil |
| 215 | } |
| 216 | urlMap := getStatsUrls(uuids, authType, nodeDefs) |
| 217 | var wg sync.WaitGroup |
| 218 | size := len(urlMap) |
| 219 | |
| 220 | type statsReq struct { |
| 221 | uuid string |
| 222 | url string |
| 223 | } |
| 224 | |
| 225 | type statsResp struct { |
| 226 | uuid string |
| 227 | status bool |
| 228 | err error |
| 229 | } |
| 230 | |
| 231 | requestCh := make(chan *statsReq, size) |
| 232 | responseCh := make(chan *statsResp, size) |
| 233 | nWorkers := getWorkerCount(size) |
| 234 | // spawn the stats get workers |
| 235 | for i := 0; i < nWorkers; i++ { |
| 236 | wg.Add(1) |
| 237 | go func() { |
| 238 | for reqs := range requestCh { |
| 239 | ctx, cancel := context.WithTimeout(context.Background(), |
| 240 | 60*time.Second) |
| 241 | defer cancel() |
| 242 | req, _ := http.NewRequestWithContext(ctx, "GET", reqs.url, nil) |
| 243 | |
| 244 | httpClient := cbgt.HttpClient() |
| 245 | res, err := httpClient.Do(req) |
| 246 | if err != nil { |
| 247 | responseCh <- &statsResp{ |
| 248 | uuid: reqs.uuid, |
| 249 | status: false, |
| 250 | err: fmt.Errorf("pindex_copy_request:"+ |
| 251 | " getNodesHostingPIndex, get stats for pindex: %s,"+ |
| 252 | " err: %v", reqs.url, err), |
| 253 | } |
| 254 | continue |
| 255 | } |
| 256 | // parse the response to get the pindex status |
| 257 | pindexesData := struct { |
| 258 | PIndexes map[string]struct { |
| 259 | Partitions map[string]struct { |
| 260 | UUID string `json:"uuid"` |
| 261 | Seq uint64 `json:"seq"` |
| 262 | } `json:"partitions"` |
| 263 | Basic struct { |
| 264 | DocCount uint64 `json:"DocCount"` |
| 265 | } `json:"basic"` |
| 266 | } `json:"pindexes"` |
| 267 | }{} |
| 268 | data, derr := ioutil.ReadAll(res.Body) |
no test coverage detected