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

Method reconcileZeroAddresses

dgraph/cmd/zero/raft.go:734–802  ·  view source on GitHub ↗

reconcileZeroAddresses detects mismatches between the current --my address (or transport-layer peer addresses) and what is stored in MembershipState, then proposes a ConfChangeUpdateNode through Raft to correct them. This ensures that stale addresses baked into the WAL at initial bootstrap are repla

()

Source from the content-addressed store, hash-verified

732// replaced with the current addresses after a restart. Only the leader can
733// propose, so this function is a no-op on followers.
734func (n *node) reconcileZeroAddresses() {
735 if !n.AmLeader() {
736 return
737 }
738
739 state := n.server.membershipState()
740 if state == nil {
741 return
742 }
743
744 for id, zero := range state.GetZeros() {
745 var correctAddr string
746
747 if id == n.Id {
748 correctAddr = n.RaftContext.Addr
749 } else if peerAddr, ok := n.Peer(id); ok {
750 correctAddr = peerAddr
751 } else {
752 continue
753 }
754
755 if correctAddr == zero.GetAddr() {
756 continue
757 }
758
759 // Validate: ensure no other Zero already claims this address.
760 duplicate := false
761 for otherId, otherZero := range state.GetZeros() {
762 if otherId != id && otherZero.GetAddr() == correctAddr {
763 glog.Warningf("Skipping address reconciliation for Zero %#x: "+
764 "address %q already used by Zero %#x", id, correctAddr, otherId)
765 duplicate = true
766 break
767 }
768 }
769 if duplicate {
770 continue
771 }
772
773 glog.Infof("Zero %#x address mismatch: MembershipState has %q, expected %q. "+
774 "Proposing ConfChangeUpdateNode.", id, zero.GetAddr(), correctAddr)
775
776 rc := &pb.RaftContext{
777 Id: id,
778 Addr: correctAddr,
779 Group: 0,
780 }
781 data, err := proto.Marshal(rc)
782 if err != nil {
783 glog.Errorf("Error marshalling RaftContext for address update: %v", err)
784 continue
785 }
786
787 cc := raftpb.ConfChange{
788 Type: raftpb.ConfChangeUpdateNode,
789 NodeID: id,
790 Context: data,
791 }

Callers 2

RunMethod · 0.95

Calls 9

AmLeaderMethod · 0.95
membershipStateMethod · 0.80
GetZerosMethod · 0.80
PeerMethod · 0.80
WarningfMethod · 0.80
InfofMethod · 0.80
ProposeConfChangeMethod · 0.80
GetAddrMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected