MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / findZero

Method findZero

dgraphtest/zero_state.go:114–134  ·  view source on GitHub ↗
(queryIdx int, wantLeader bool)

Source from the content-addressed store, hash-verified

112}
113
114func (c *LocalCluster) findZero(queryIdx int, wantLeader bool) (*ZeroLocator, error) {
115 state, err := c.GetZeroState(queryIdx)
116 if err != nil {
117 return nil, err
118 }
119 for id, z := range state.Zeros {
120 if z.Leader != wantLeader {
121 continue
122 }
123 idx, ok := containerIdxFromAddr(z.Addr)
124 if !ok {
125 return nil, fmt.Errorf("cannot map addr %q to container index", z.Addr)
126 }
127 return &ZeroLocator{ContainerIdx: idx, RaftID: id, Addr: z.Addr}, nil
128 }
129 role := "follower"
130 if wantLeader {
131 role = "leader"
132 }
133 return nil, fmt.Errorf("no %s found in /state from zero%d", role, queryIdx)
134}
135
136// WaitForZeroAddress polls /state until the member identified by raftID has
137// wantAddr. It first tries queryIdx; if that node's /state is unavailable

Callers 2

GetZeroLeaderMethod · 0.95
GetZeroFollowerMethod · 0.95

Calls 3

GetZeroStateMethod · 0.95
containerIdxFromAddrFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected