diff --git a/ais/htrun.go b/ais/htrun.go index 594564c981c..dd8fec9a073 100644 --- a/ais/htrun.go +++ b/ais/htrun.go @@ -1787,7 +1787,7 @@ func (h *htrun) extractRevokedTokenList(payload msPayload, caller string) (*toke // - if these fails we try the candidates provided by the caller. // // ================================== Background ========================================= -func (h *htrun) join(query url.Values, htext htext, contactURLs ...string) (res *callResult) { +func (h *htrun) join(query url.Values, htext htext, contactURLs ...string) (res *callResult, err error) { var ( config = cmn.GCO.Get() candidates = make([]string, 0, 4+len(contactURLs)) @@ -1817,7 +1817,7 @@ func (h *htrun) join(query url.Values, htext htext, contactURLs ...string) (res for range 4 { // retry for _, candidateURL := range candidates { if nlog.Stopping() { - return + return res, errors.New(h.String() + " is stopping") } if resPrev != nil { freeCR(resPrev) @@ -1837,20 +1837,23 @@ func (h *htrun) join(query url.Values, htext htext, contactURLs ...string) (res } smap := h.owner.smap.get() - if smap.validate() != nil { - return + if err := smap.validate(); err != nil { + return res, fmt.Errorf("%s: invalid Smap, err: %v", h.si, err) } // Failed to join cluster using config, try getting primary URL using existing smap. nsti, _ := h.bcastHealth(smap, false /*checkAll*/) - if nsti == nil || nsti.Smap.Version < smap.version() { - return + if nsti == nil { + return res, fmt.Errorf("%s: failed to discover a new smap", h) + } + if nsti.Smap.Version < smap.version() { + return res, fmt.Errorf("%s: current %s version is newer than %d from the primary proxy (%s)", h, smap, nsti.Smap.Version, nsti.Smap.Primary.ID) } primaryURL = nsti.Smap.Primary.PubURL // Daemon is stopping skip register if nlog.Stopping() { - return + return res, errors.New(h.String() + " is stopping") } res = h.regTo(primaryURL, nil, apc.DefaultTimeout, query, htext, false /*keepalive*/) if res.err == nil { diff --git a/ais/proxy.go b/ais/proxy.go index 3a0cfa37763..9f50fb4a279 100644 --- a/ais/proxy.go +++ b/ais/proxy.go @@ -261,11 +261,13 @@ func (p *proxy) joinCluster(action string, primaryURLs ...string) (status int, e if cmn.GCO.Get().Proxy.NonElectable { query = url.Values{apc.QparamNonElectable: []string{"true"}} } - res := p.join(query, nil /*htext*/, primaryURLs...) + res, err := p.join(query, nil /*htext*/, primaryURLs...) + if err != nil { + return status, err + } defer freeCR(res) if res.err != nil { - status, err = res.status, res.err - return + return res.status, res.err } // not being sent at cluster startup and keepalive if len(res.bytes) == 0 { diff --git a/ais/tgtcp.go b/ais/tgtcp.go index 09a2213d41e..16c1e7d45ab 100644 --- a/ais/tgtcp.go +++ b/ais/tgtcp.go @@ -48,11 +48,13 @@ type delb struct { } func (t *target) joinCluster(action string, primaryURLs ...string) (status int, err error) { - res := t.join(nil, t, primaryURLs...) + res, err := t.join(nil, t, primaryURLs...) + if err != nil { + return status, err + } defer freeCR(res) if res.err != nil { - status, err = res.status, res.err - return + return res.status, res.err } // not being sent at cluster startup and keepalive if len(res.bytes) == 0 {