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

Function StartRaftNodes

worker/groups.go:61–160  ·  view source on GitHub ↗

StartRaftNodes will read the WAL dir, create the RAFT groups, and either start or restart RAFT nodes. This function triggers RAFT nodes to be created, and is the entrance to the RAFT world from main.go.

(walStore *raftwal.DiskStorage, bindall bool)

Source from the content-addressed store, hash-verified

59// This function triggers RAFT nodes to be created, and is the entrance to the RAFT
60// world from main.go.
61func StartRaftNodes(walStore *raftwal.DiskStorage, bindall bool) {
62 if x.WorkerConfig.MyAddr == "" {
63 x.WorkerConfig.MyAddr = fmt.Sprintf("localhost:%d", workerPort())
64 } else {
65 // check if address is valid or not
66 x.Check(x.ValidateAddress(x.WorkerConfig.MyAddr))
67 if !bindall {
68 glog.Errorln("--my flag is provided without bindall, Did you forget to specify bindall?")
69 }
70 }
71
72 x.AssertTruef(len(x.WorkerConfig.ZeroAddr) > 0, "Providing dgraphzero address is mandatory.")
73 for _, zeroAddr := range x.WorkerConfig.ZeroAddr {
74 x.AssertTruef(zeroAddr != x.WorkerConfig.MyAddr,
75 "Dgraph Zero address %s and Dgraph address (IP:Port) %s can't be the same.",
76 zeroAddr, x.WorkerConfig.MyAddr)
77 }
78
79 raftIdx := x.WorkerConfig.Raft.GetUint64("idx")
80 if raftIdx == 0 {
81 raftIdx = walStore.Uint(raftwal.RaftId)
82
83 // If the w directory already contains raft information, ignore the proposed
84 // group ID stored inside the p directory.
85 if raftIdx > 0 {
86 x.WorkerConfig.ProposedGroupId = 0
87 }
88 }
89 glog.Infof("Current Raft Id: %#x\n", raftIdx)
90
91 if x.WorkerConfig.ProposedGroupId == 0 {
92 x.WorkerConfig.ProposedGroupId = x.WorkerConfig.Raft.GetUint32("group")
93 }
94 // Successfully connect with dgraphzero, before doing anything else.
95 // Connect with Zero leader and figure out what group we should belong to.
96 m := &pb.Member{
97 Id: raftIdx,
98 GroupId: x.WorkerConfig.ProposedGroupId,
99 Addr: x.WorkerConfig.MyAddr,
100 Learner: x.WorkerConfig.Raft.GetBool("learner"),
101 }
102 if m.GroupId > 0 {
103 m.ForceGroupId = true
104 }
105 glog.Infof("Sending member request to Zero: %+v\n", m)
106 var connState *pb.ConnectionState
107 var err error
108
109 for { // Keep on retrying. See: https://github.com/dgraph-io/dgraph/issues/2289
110 pl := gr.connToZeroLeader()
111 if pl == nil {
112 continue
113 }
114 zc := pb.NewZeroClient(pl.Get())
115 connState, err = zc.Connect(gr.Ctx(), m)
116 if err == nil || x.ShouldCrash(err) {
117 break
118 }

Callers 1

runFunction · 0.92

Calls 15

ConnectMethod · 0.95
GetMemberMethod · 0.95
GetStateMethod · 0.95
CheckFunction · 0.92
ValidateAddressFunction · 0.92
AssertTruefFunction · 0.92
NewZeroClientFunction · 0.92
ShouldCrashFunction · 0.92
CheckfNoTraceFunction · 0.92
FatalfFunction · 0.92
CheckfFunction · 0.92
LoadFromDbFunction · 0.92

Tested by

no test coverage detected