joinMembersBatch returns an error only if it couldn't successfully join any nodes or if ctx is cancelled.
(ctx context.Context, nodes []string)
| 903 | |
| 904 | // joinMembersBatch returns an error only if it couldn't successfully join any nodes or if ctx is cancelled. |
| 905 | func (m *KV) joinMembersBatch(ctx context.Context, nodes []string) (successfullyJoined int, lastErr error) { |
| 906 | for nodeIdx := range nodes { |
| 907 | if ctx.Err() != nil { |
| 908 | return successfullyJoined, fmt.Errorf("joining batch: %w", context.Cause(ctx)) |
| 909 | } |
| 910 | // Attempt to join a single node. |
| 911 | // The cost of calling Join shouldn't be different between passing all nodes in one invocation versus passing a single node per invocation. |
| 912 | reached, err := m.memberlist.Join(nodes[nodeIdx : nodeIdx+1]) |
| 913 | successfullyJoined += reached |
| 914 | if err != nil { |
| 915 | lastErr = err |
| 916 | } |
| 917 | } |
| 918 | if successfullyJoined > 0 { |
| 919 | lastErr = nil |
| 920 | } |
| 921 | return successfullyJoined, lastErr |
| 922 | } |
| 923 | |
| 924 | // Provides a dns-based member discovery to join a memberlist cluster w/o knowning members' addresses upfront. |
| 925 | // May both return some addresses and an error in case of a partial resolution. |
no test coverage detected