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

Method GetZeroState

dgraphtest/zero_state.go:47–72  ·  view source on GitHub ↗

GetZeroState queries the /state endpoint on the specified Zero and returns the parsed membership snapshot.

(id int)

Source from the content-addressed store, hash-verified

45// GetZeroState queries the /state endpoint on the specified Zero and returns
46// the parsed membership snapshot.
47func (c *LocalCluster) GetZeroState(id int) (*ZeroState, error) {
48 stateURL, err := c.GetZeroStateURL(id)
49 if err != nil {
50 return nil, err
51 }
52
53 resp, err := http.Get(stateURL)
54 if err != nil {
55 return nil, errors.Wrapf(err, "GET %s", stateURL)
56 }
57 defer func() { _ = resp.Body.Close() }()
58
59 body, err := io.ReadAll(resp.Body)
60 if err != nil {
61 return nil, errors.Wrap(err, "reading /state body")
62 }
63 if resp.StatusCode != http.StatusOK {
64 return nil, fmt.Errorf("/state HTTP %d: %s", resp.StatusCode, body)
65 }
66
67 var state ZeroState
68 if err := json.Unmarshal(body, &state); err != nil {
69 return nil, errors.Wrapf(err, "unmarshal /state (body: %s)", string(body))
70 }
71 return &state, nil
72}
73
74// ZeroLocator identifies a Zero by its container index and Raft ID.
75type ZeroLocator struct {

Callers 3

GetZeroFollowersMethod · 0.95
findZeroMethod · 0.95
WaitForZeroAddressMethod · 0.95

Calls 4

GetZeroStateURLMethod · 0.95
GetMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected