MCPcopy Create free account
hub / github.com/couchbase/cbft / Query

Method Query

pindex_bleve.go:1609–1692  ·  view source on GitHub ↗

---------------------------------------------------------

(pindex *cbgt.PIndex, req []byte, res io.Writer,
	parentCancelCh <-chan bool)

Source from the content-addressed store, hash-verified

1607// ---------------------------------------------------------
1608
1609func (t *BleveDest) Query(pindex *cbgt.PIndex, req []byte, res io.Writer,
1610 parentCancelCh <-chan bool) error {
1611 // phase 0 - parsing/validating query
1612 // could return err 400
1613 queryCtlParams := cbgt.QueryCtlParams{
1614 Ctl: cbgt.QueryCtl{
1615 Timeout: cbgt.QUERY_CTL_DEFAULT_TIMEOUT_MS,
1616 },
1617 }
1618 err := UnmarshalJSON(req, &queryCtlParams)
1619 if err != nil {
1620 return fmt.Errorf("bleve: BleveDest.Query"+
1621 " parsing queryCtlParams, err: %v", err)
1622 }
1623
1624 var sr *SearchRequest
1625 err = UnmarshalJSON(req, &sr)
1626 if err != nil {
1627 return fmt.Errorf("bleve: BleveDest.Query"+
1628 " parsing searchRequest, err: %v", err)
1629 }
1630 searchRequest, err := sr.ConvertToBleveSearchRequest()
1631 if err != nil {
1632 return fmt.Errorf("bleve: BleveDest.Query"+
1633 " parsing searchRequest, err: %v", err)
1634 }
1635
1636 // phase 1 - set up timeouts, wait to satisfy consistency requirements
1637 // could return err 412
1638
1639 // create a context with the appropriate timeout
1640 ctx, cancel, cancelCh := setupContextAndCancelCh(queryCtlParams, parentCancelCh)
1641 // defer a call to cancel, this ensures that goroutine from
1642 // setupContextAndCancelCh always exits
1643 defer cancel()
1644
1645 err = cbgt.ConsistencyWaitPIndex(pindex, t,
1646 queryCtlParams.Ctl.Consistency, cancelCh)
1647 if err != nil {
1648 if _, ok := err.(*cbgt.ErrorConsistencyWait); !ok {
1649 // not a consistency wait error
1650 // check to see if context error
1651 if ctx.Err() != nil {
1652 // return this as search response error
1653 sendSearchResultErr(searchRequest, res, []string{pindex.Name}, ctx.Err())
1654 return nil
1655 }
1656 }
1657 // some other error occurred return this as 400
1658 return err
1659 }
1660
1661 // phase 2 - execute query
1662 // always 200, possibly with errors inside status
1663 t.m.RLock()
1664 bindex := t.bindex
1665 t.m.RUnlock()
1666

Callers 1

QueryMethod · 0.45

Calls 7

UnmarshalJSONFunction · 0.85
setupContextAndCancelChFunction · 0.85
sendSearchResultErrFunction · 0.85
AddEntryMethod · 0.80
DeleteEntryMethod · 0.80
SearchInContextMethod · 0.45

Tested by

no test coverage detected