MCPcopy
hub / github.com/etcd-io/etcd / checkVersion

Method checkVersion

client/v3/client.go:518–560  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

516}
517
518func (c *Client) checkVersion() (err error) {
519 var wg sync.WaitGroup
520
521 eps := c.Endpoints()
522 errc := make(chan error, len(eps))
523 ctx, cancel := context.WithCancel(c.ctx)
524 if c.cfg.DialTimeout > 0 {
525 cancel()
526 ctx, cancel = context.WithTimeout(c.ctx, c.cfg.DialTimeout)
527 }
528
529 wg.Add(len(eps))
530 for _, ep := range eps {
531 // if cluster is current, any endpoint gives a recent version
532 go func(e string) {
533 defer wg.Done()
534 resp, rerr := c.Status(ctx, e)
535 if rerr != nil {
536 errc <- rerr
537 return
538 }
539 vs, serr := semver.NewVersion(resp.Version)
540 if serr != nil {
541 errc <- serr
542 return
543 }
544
545 if vs.LessThan(*minSupportedVersion()) {
546 rerr = ErrOldCluster
547 }
548 errc <- rerr
549 }(ep)
550 }
551 // wait for success
552 for range eps {
553 if err = <-errc; err != nil {
554 break
555 }
556 }
557 cancel()
558 wg.Wait()
559 return err
560}
561
562// ActiveConnection returns the current in-use connection
563func (c *Client) ActiveConnection() *grpc.ClientConn { return c.conn }

Callers 2

newClientFunction · 0.95

Calls 6

EndpointsMethod · 0.95
StatusMethod · 0.95
minSupportedVersionFunction · 0.85
AddMethod · 0.65
DoneMethod · 0.65
WaitMethod · 0.65

Tested by 1