proposeOrSend either proposes the mutation if the node serves the group gid or sends it to the leader of the group gid for proposing.
(ctx context.Context, gid uint32, m *pb.Mutations, chr chan res)
| 649 | // proposeOrSend either proposes the mutation if the node serves the group gid or sends it to |
| 650 | // the leader of the group gid for proposing. |
| 651 | func proposeOrSend(ctx context.Context, gid uint32, m *pb.Mutations, chr chan res) { |
| 652 | res := res{} |
| 653 | if groups().ServesGroup(gid) { |
| 654 | res.ctx = &api.TxnContext{} |
| 655 | res.err = (&grpcWorker{}).proposeAndWait(ctx, res.ctx, m) |
| 656 | chr <- res |
| 657 | return |
| 658 | } |
| 659 | |
| 660 | pl := groups().Leader(gid) |
| 661 | if pl == nil { |
| 662 | res.err = conn.ErrNoConnection |
| 663 | chr <- res |
| 664 | return |
| 665 | } |
| 666 | |
| 667 | var tc *api.TxnContext |
| 668 | c := pb.NewWorkerClient(pl.Get()) |
| 669 | |
| 670 | ch := make(chan error, 1) |
| 671 | go func() { |
| 672 | var err error |
| 673 | tc, err = c.Mutate(ctx, m) |
| 674 | ch <- err |
| 675 | }() |
| 676 | |
| 677 | select { |
| 678 | case <-ctx.Done(): |
| 679 | res.err = ctx.Err() |
| 680 | res.ctx = nil |
| 681 | case err := <-ch: |
| 682 | res.err = err |
| 683 | res.ctx = tc |
| 684 | } |
| 685 | chr <- res |
| 686 | } |
| 687 | |
| 688 | // populateMutationMap populates a map from group id to the mutation that |
| 689 | // should be sent to that group. |
no test coverage detected
searching dependent graphs…