Fail entire /schema/details request if one field query fails

This commit is contained in:
Alan Bernstein 2021-02-08 17:25:38 -06:00
parent 2773999190
commit dc6c92771b
2 changed files with 8 additions and 5 deletions

7
api.go
View file

@ -997,7 +997,7 @@ func (api *API) Schema(ctx context.Context) []*IndexInfo {
// SchemaDetails returns information about each index in Pilosa including which
// fields they contain, and additional field information such as cardinality
func (api *API) SchemaDetails(ctx context.Context) []*IndexInfo {
func (api *API) SchemaDetails(ctx context.Context) ([]*IndexInfo, error) {
span, _ := tracing.StartSpanFromContext(ctx, "API.Schema")
defer span.Finish()
schema := api.holder.Schema(false)
@ -1007,8 +1007,7 @@ func (api *API) SchemaDetails(ctx context.Context) []*IndexInfo {
req := QueryRequest{Index: index.Name, Query: q}
resp, err := api.query(ctx, &req)
if err != nil {
// TODO ?
continue
return schema, errors.Wrapf(err, "querying cardinality (%s/%s)", index.Name, field.Name)
}
if len(resp.Results) == 0 {
continue
@ -1018,7 +1017,7 @@ func (api *API) SchemaDetails(ctx context.Context) []*IndexInfo {
}
}
}
return schema
return schema, nil
}
// ApplySchema takes the given schema and applies it across the

View file

@ -681,7 +681,11 @@ func (h *Handler) handleGetSchemaDetails(w http.ResponseWriter, r *http.Request)
}
w.Header().Set("Content-Type", "application/json")
schema := h.api.SchemaDetails(r.Context())
schema, err := h.api.SchemaDetails(r.Context())
if err != nil {
h.logger.Printf("error getting detailed schema: %s", err)
return
}
if err := json.NewEncoder(w).Encode(pilosa.Schema{Indexes: schema}); err != nil {
h.logger.Printf("write schema response error: %s", err)
}