MCPcopy
hub / github.com/dgraph-io/dgraph / getState

Method getState

dgraph/cmd/zero/http.go:208–235  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

206}
207
208func (st *state) getState(w http.ResponseWriter, r *http.Request) {
209 x.AddCorsHeaders(w)
210 w.Header().Set("Content-Type", "application/json")
211
212 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
213 defer cancel()
214 if err := st.node.WaitLinearizableRead(ctx); err != nil {
215 w.WriteHeader(http.StatusInternalServerError)
216 x.SetStatus(w, x.Error, err.Error())
217 return
218 }
219 mstate := st.zero.membershipState()
220 if mstate == nil {
221 x.SetStatus(w, x.ErrorNoData, "No membership state found.")
222 return
223 }
224
225 m := protojson.MarshalOptions{EmitUnpopulated: true}
226 buf, err := m.Marshal(mstate)
227 if err != nil {
228 x.SetStatus(w, x.ErrorNoData, err.Error())
229 return
230 }
231 if _, err := w.Write(buf); err != nil {
232 x.SetStatus(w, x.Error, err.Error())
233 return
234 }
235}
236
237func (s *Server) zeroHealth(ctx context.Context) (*api.Response, error) {
238 if ctx.Err() != nil {

Callers

nothing calls this directly

Calls 8

AddCorsHeadersFunction · 0.92
SetStatusFunction · 0.92
WaitLinearizableReadMethod · 0.80
membershipStateMethod · 0.80
SetMethod · 0.65
WriteHeaderMethod · 0.65
WriteMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected