// Returns a bleve.IndexAlias that represents all the PIndexes for the // index, including perhaps bleve remote client PIndexes. // // TODO: Perhaps need a tighter check around indexUUID, as the current // implementation might have a race where old pindexes with a matching // (but invalid) indexUUID might be hit. // // TODO: If this returns an error, perhaps the caller somewhere up the // chain should close the cancelCh to help stop any other inflight // activities. func bleveIndexAlias(mgr *cbgt.Manager, indexName, indexUUID string, ensureCanRead bool, consistencyParams *cbgt.ConsistencyParams, cancelCh <-chan bool) (bleve.IndexAlias, error) { planPIndexNodeFilter := cbgt.PlanPIndexNodeOk if ensureCanRead { planPIndexNodeFilter = cbgt.PlanPIndexNodeCanRead } localPIndexes, remotePlanPIndexes, err := mgr.CoveringPIndexes(indexName, indexUUID, planPIndexNodeFilter, "queries") if err != nil { return nil, fmt.Errorf("bleve: bleveIndexAlias, err: %v", err) } alias := bleve.NewIndexAlias() for _, remotePlanPIndex := range remotePlanPIndexes { baseURL := "http://" + remotePlanPIndex.NodeDef.HostPort + "/api/pindex/" + remotePlanPIndex.PlanPIndex.Name alias.Add(&IndexClient{ QueryURL: baseURL + "/query", CountURL: baseURL + "/count", Consistency: consistencyParams, // TODO: Propagate auth to remote client. }) } // TODO: Should kickoff remote queries concurrently before we wait. err = cbgt.ConsistencyWaitGroup(indexName, consistencyParams, cancelCh, localPIndexes, func(localPIndex *cbgt.PIndex) error { bindex, ok := localPIndex.Impl.(bleve.Index) if !ok || bindex == nil || !strings.HasPrefix(localPIndex.IndexType, "bleve") { return fmt.Errorf("bleve: wrong type, localPIndex: %#v", localPIndex) } alias.Add(bindex) return nil }) if err != nil { return nil, err } return alias, nil }
func bleveIndexTargets(mgr *cbgt.Manager, indexName, indexUUID string, ensureCanRead bool, consistencyParams *cbgt.ConsistencyParams, cancelCh <-chan bool, collector BleveIndexCollector) error { planPIndexNodeFilter := cbgt.PlanPIndexNodeOk if ensureCanRead { planPIndexNodeFilter = cbgt.PlanPIndexNodeCanRead } localPIndexes, remotePlanPIndexes, err := mgr.CoveringPIndexes(indexName, indexUUID, planPIndexNodeFilter, "queries") if err != nil { return fmt.Errorf("bleve: bleveIndexTargets, err: %v", err) } prefix := mgr.Options()["urlPrefix"] for _, remotePlanPIndex := range remotePlanPIndexes { baseURL := "http://" + remotePlanPIndex.NodeDef.HostPort + prefix + "/api/pindex/" + remotePlanPIndex.PlanPIndex.Name collector.Add(&IndexClient{ name: fmt.Sprintf("IndexClient - %s", baseURL), QueryURL: baseURL + "/query", CountURL: baseURL + "/count", Consistency: consistencyParams, // TODO: Propagate auth to remote client. }) } // TODO: Should kickoff remote queries concurrently before we wait. return cbgt.ConsistencyWaitGroup(indexName, consistencyParams, cancelCh, localPIndexes, func(localPIndex *cbgt.PIndex) error { bindex, ok := localPIndex.Impl.(bleve.Index) if !ok || bindex == nil || !strings.HasPrefix(localPIndex.IndexType, "fulltext-index") { return fmt.Errorf("bleve: wrong type, localPIndex: %#v", localPIndex) } collector.Add(bindex) return nil }) }