mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-07 03:17:50 +00:00
Adjust /status and /schema endpoints. Tried/failed to deprecate /slices/max (client is using it for backups).
This commit is contained in:
parent
2bd0677df9
commit
f49b2f9b99
4 changed files with 26 additions and 40 deletions
10
client.go
10
client.go
|
|
@ -100,9 +100,6 @@ func (c *Client) MaxInverseSliceByIndex(ctx context.Context) (map[string]uint64,
|
|||
func (c *Client) maxSliceByIndex(ctx context.Context, inverse bool) (map[string]uint64, error) {
|
||||
// Execute request against the host.
|
||||
u := uriPathToURL(c.host, "/slices/max")
|
||||
u.RawQuery = (&url.Values{
|
||||
"inverse": {strconv.FormatBool(inverse)},
|
||||
}).Encode()
|
||||
|
||||
// Build request.
|
||||
req, err := http.NewRequest("GET", u.String(), nil)
|
||||
|
|
@ -119,14 +116,17 @@ func (c *Client) maxSliceByIndex(ctx context.Context, inverse bool) (map[string]
|
|||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var rsp sliceMaxResponse
|
||||
var rsp getSlicesMaxResponse
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("http: status=%d", resp.StatusCode)
|
||||
} else if err := json.NewDecoder(resp.Body).Decode(&rsp); err != nil {
|
||||
return nil, fmt.Errorf("json decode: %s", err)
|
||||
}
|
||||
|
||||
return rsp.MaxSlices, nil
|
||||
if inverse {
|
||||
return rsp.Inverse, nil
|
||||
}
|
||||
return rsp.Standard, nil
|
||||
}
|
||||
|
||||
// Schema returns all index and frame schema information.
|
||||
|
|
|
|||
46
handler.go
46
handler.go
|
|
@ -132,7 +132,7 @@ func NewRouter(handler *Handler) *mux.Router {
|
|||
router.HandleFunc("/index/{index}/time-quantum", handler.handlePatchIndexTimeQuantum).Methods("PATCH")
|
||||
router.HandleFunc("/hosts", handler.handleGetHosts).Methods("GET")
|
||||
router.HandleFunc("/schema", handler.handleGetSchema).Methods("GET")
|
||||
//router.HandleFunc("/slices/max", handler.handleGetSliceMax).Methods("GET") // TODO: this is being used by the client (for backups)
|
||||
router.HandleFunc("/slices/max", handler.handleGetSlicesMax).Methods("GET") // TODO: deprecate, but it's being used by the client (for backups)
|
||||
router.HandleFunc("/status", handler.handleGetStatus).Methods("GET")
|
||||
router.HandleFunc("/version", handler.handleGetVersion).Methods("GET")
|
||||
router.HandleFunc("/recalculate-caches", handler.handleRecalculateCaches).Methods("POST")
|
||||
|
|
@ -216,13 +216,16 @@ func (h *Handler) handleGetSchema(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// handleGetStatus handles GET /status requests.
|
||||
func (h *Handler) handleGetStatus(w http.ResponseWriter, r *http.Request) {
|
||||
status, err := h.StatusHandler.ClusterStatus()
|
||||
pb, err := h.StatusHandler.ClusterStatus()
|
||||
if err != nil {
|
||||
h.logger().Printf("cluster status error: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
cs := pb.(*internal.ClusterStatus)
|
||||
if err := json.NewEncoder(w).Encode(getStatusResponse{
|
||||
Status: status,
|
||||
State: cs.State,
|
||||
URISet: decodeURIs(cs.URISet),
|
||||
}); err != nil {
|
||||
h.logger().Printf("write status response error: %s", err)
|
||||
}
|
||||
|
|
@ -233,7 +236,8 @@ type getSchemaResponse struct {
|
|||
}
|
||||
|
||||
type getStatusResponse struct {
|
||||
Status proto.Message `json:"status"`
|
||||
State string `json:"state"`
|
||||
URISet []URI `json:"uri-set"`
|
||||
}
|
||||
|
||||
// handlePostQuery handles /query requests.
|
||||
|
|
@ -305,33 +309,19 @@ func (h *Handler) handlePostQuery(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func (h *Handler) handleGetSliceMax(w http.ResponseWriter, r *http.Request) {
|
||||
var ms map[string]uint64
|
||||
if inverse, _ := strconv.ParseBool(r.URL.Query().Get("inverse")); inverse {
|
||||
ms = h.Holder.MaxInverseSlices()
|
||||
} else {
|
||||
ms = h.Holder.MaxSlices()
|
||||
// handleGetSlicesMax handles GET /schema requests.
|
||||
func (h *Handler) handleGetSlicesMax(w http.ResponseWriter, r *http.Request) {
|
||||
if err := json.NewEncoder(w).Encode(getSlicesMaxResponse{
|
||||
Standard: h.Holder.MaxSlices(),
|
||||
Inverse: h.Holder.MaxInverseSlices(),
|
||||
}); err != nil {
|
||||
h.logger().Printf("write slices-max response error: %s", err)
|
||||
}
|
||||
if strings.Contains(r.Header.Get("Accept"), "application/x-protobuf") {
|
||||
pb := &internal.MaxSlicesResponse{
|
||||
MaxSlices: ms,
|
||||
}
|
||||
if buf, err := proto.Marshal(pb); err != nil {
|
||||
h.logger().Printf("protobuf marshal error: %s", err)
|
||||
} else if _, err := w.Write(buf); err != nil {
|
||||
h.logger().Printf("stream write error: %s", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
json.NewEncoder(w).Encode(sliceMaxResponse{
|
||||
MaxSlices: ms,
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
type sliceMaxResponse struct {
|
||||
MaxSlices map[string]uint64 `json:"maxSlices"`
|
||||
type getSlicesMaxResponse struct {
|
||||
Standard map[string]uint64 `json:"standard"`
|
||||
Inverse map[string]uint64 `json:"inverse"`
|
||||
}
|
||||
|
||||
// handleGetIndexes handles GET /index request.
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ func TestHandler_Status(t *testing.T) {
|
|||
h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/status", nil))
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("unexpected status code: %d", w.Code)
|
||||
} else if body := w.Body.String(); body != `{"status":{"State":"NORMAL","URISet":[{"Scheme":"http","Host":"localhost","Port":10101}]}}`+"\n" {
|
||||
} else if body := w.Body.String(); body != `{"state":"NORMAL","uri-set":[{"scheme":"http","host":"localhost","port":10101}]}`+"\n" {
|
||||
t.Fatalf("unexpected body: %s", body)
|
||||
}
|
||||
}
|
||||
|
|
@ -172,7 +172,7 @@ func TestHandler_MaxSlices(t *testing.T) {
|
|||
h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/slices/max", nil))
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("unexpected status code: %d", w.Code)
|
||||
} else if body := w.Body.String(); body != `{"maxSlices":{"i0":3,"i1":0}}`+"\n" {
|
||||
} else if body := w.Body.String(); body != `{"standard":{"i0":3,"i1":0},"inverse":{"i0":0,"i1":0}}`+"\n" {
|
||||
t.Fatalf("unexpected body: %s", body)
|
||||
}
|
||||
}
|
||||
|
|
@ -213,7 +213,7 @@ func TestHandler_MaxSlices_Inverse(t *testing.T) {
|
|||
h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/slices/max?inverse=true", nil))
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("unexpected status code: %d", w.Code)
|
||||
} else if body := w.Body.String(); body != `{"maxSlices":{"i0":3,"i1":0}}`+"\n" {
|
||||
} else if body := w.Body.String(); body != `{"standard":{"i0":0,"i1":0},"inverse":{"i0":3,"i1":0}}`+"\n" {
|
||||
t.Fatalf("unexpected body: %s", body)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,10 +38,6 @@ message Cache {
|
|||
repeated uint64 IDs = 1;
|
||||
}
|
||||
|
||||
//message MaxSlicesResponse {
|
||||
// map<string, uint64> MaxSlices = 1;
|
||||
//}
|
||||
|
||||
message MaxSlices {
|
||||
map<string, uint64> Standard = 1;
|
||||
map<string, uint64> Inverse = 2;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue