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

Method Connect

dgraph/cmd/zero/zero.go:501–671  ·  view source on GitHub ↗

Connect is used by Alpha nodes to connect the very first time with group zero.

(ctx context.Context,
	m *pb.Member)

Source from the content-addressed store, hash-verified

499
500// Connect is used by Alpha nodes to connect the very first time with group zero.
501func (s *Server) Connect(ctx context.Context,
502 m *pb.Member) (resp *pb.ConnectionState, err error) {
503 // Ensures that connect requests are always serialized
504 s.connectLock.Lock()
505 defer s.connectLock.Unlock()
506 glog.Infof("Got connection request: %+v\n", m)
507 defer glog.Infof("Connected: %+v\n", m)
508
509 if ctx.Err() != nil {
510 err := errors.Errorf("Context has error: %v\n", ctx.Err())
511 return &emptyConnectionState, err
512 }
513 ms, err := s.latestMembershipState(ctx)
514 if err != nil {
515 return nil, err
516 }
517
518 // Ensure this Zero's own address in MembershipState reflects the current
519 // --my flag, even before ConfChangeUpdateNode has been committed through
520 // Raft. This prevents Alphas from receiving a stale address during the
521 // brief window between restart and reconciliation.
522 myAddr := s.Node.RaftContext.Addr
523 if myId := s.Node.Id; myAddr != "" {
524 if z, ok := ms.GetZeros()[myId]; ok && z.GetAddr() != myAddr {
525 z.Addr = myAddr
526 }
527 }
528
529 if m.ClusterInfoOnly {
530 // This request only wants to access the membership state, and nothing else. Most likely
531 // from our clients.
532 cs := &pb.ConnectionState{
533 State: ms,
534 MaxPending: s.orc.MaxPending(),
535 }
536 return cs, err
537 }
538 if m.Addr == "" {
539 return &emptyConnectionState, errors.Errorf("NO_ADDR: No address provided: %+v", m)
540 }
541
542 for _, member := range ms.Removed {
543 // It is not recommended to reuse RAFT ids.
544 if member.GroupId != 0 && m.Id == member.Id {
545 return &emptyConnectionState, errors.Errorf(
546 "REUSE_RAFTID: Duplicate Raft ID %d to removed member: %+v", m.Id, member)
547 }
548 }
549
550 numberOfNodes := len(ms.Zeros)
551 for _, group := range ms.Groups {
552 for _, member := range group.Members {
553 switch {
554 case member.Addr == m.Addr && m.Id == 0:
555 glog.Infof("Found a member with the same address. Returning: %+v", member)
556 conn.GetPools().Connect(m.Addr, s.tlsClientConfig)
557 return &pb.ConnectionState{
558 State: ms,

Callers

nothing calls this directly

Calls 14

latestMembershipStateMethod · 0.95
membershipStateMethod · 0.95
GetPoolsFunction · 0.92
InfofMethod · 0.80
GetZerosMethod · 0.80
MaxPendingMethod · 0.80
IsHealthyMethod · 0.80
ConnectMethod · 0.65
GetMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected