diff --git a/ais/proxy.go b/ais/proxy.go index ec7a6d7b87..016875ed08 100644 --- a/ais/proxy.go +++ b/ais/proxy.go @@ -96,7 +96,8 @@ func (p *proxy) init(config *cmn.Config) { memsys.Init(p.SID(), p.SID(), config) - cos.InitShortID(p.si.Digest()) + debug.Assert(p.si.IDDigest != 0) + cos.InitShortID(p.si.IDDigest) if network, err := _parseCIDR(env.AisLocalRedirectCIDR, ""); err != nil { cos.ExitLog(err) // FATAL diff --git a/ais/target.go b/ais/target.go index 87a7838e50..b472af38f9 100644 --- a/ais/target.go +++ b/ais/target.go @@ -215,7 +215,8 @@ func (t *target) init(config *cmn.Config) { } t.si.Init(tid, apc.Target) - cos.InitShortID(t.si.Digest()) + debug.Assert(t.si.IDDigest != 0) + cos.InitShortID(t.si.IDDigest) memsys.Init(t.SID(), t.SID(), config) diff --git a/ais/test/multiproxy_test.go b/ais/test/multiproxy_test.go index c554193520..33554db97d 100644 --- a/ais/test/multiproxy_test.go +++ b/ais/test/multiproxy_test.go @@ -6,7 +6,6 @@ package integration_test import ( "context" - "errors" "fmt" "math" "net/http" @@ -32,7 +31,6 @@ import ( "github.com/NVIDIA/aistore/tools/tlog" "github.com/NVIDIA/aistore/tools/trand" "github.com/NVIDIA/aistore/xact" - "github.com/OneOfOne/xxhash" jsoniter "github.com/json-iterator/go" ) @@ -1018,13 +1016,11 @@ func setPrimaryTo(t *testing.T, proxyURL string, smap *meta.Smap, directURL, toI return } -func chooseNextProxy(smap *meta.Smap) (proxyid, proxyURL string, err error) { - pid, err := hrwProxyTest(smap, smap.Primary.ID()) - pi := smap.Pmap[pid] +func chooseNextProxy(smap *meta.Smap) (string, string, error) { + pi, err := smap.HrwProxy(smap.Primary.ID()) if err != nil { - return + return "", "", err } - return pi.ID(), pi.URL(cmn.NetPublic), nil } @@ -1066,47 +1062,6 @@ func primarySetToRand(t *testing.T) *meta.Smap { return setPrimaryTo(t, proxyURL, smap, "", psi.ID()) } -// This is duplicated in the tests because the `idDigest` of `daemonInfo` is not -// exported. As a result of this, ais.HrwProxy will not return the correct -// proxy since the `idDigest` will be initialized to 0. To avoid this, we -// compute the checksum directly in this method. -func hrwProxyTest(smap *meta.Smap, idToSkip string) (pi string, err error) { - if smap.CountActivePs() == 0 { - err = errors.New("AIStore cluster map is empty: no proxies") - return - } - var ( - maxH uint64 - skipped int - ) - for id, snode := range smap.Pmap { - if id == idToSkip { - skipped++ - continue - } - if smap.NonElectable(snode) { - skipped++ - continue - } - - if smap.InMaintOrDecomm(snode) { - skipped++ - continue - } - - cs := xxhash.Checksum64S(cos.UnsafeB(snode.ID()), cos.MLCG32) - if cs > maxH { - maxH = cs - pi = id - } - } - if pi == "" { - err = fmt.Errorf("cannot HRW-select proxy: current count=%d, skipped=%d", - smap.CountActivePs(), skipped) - } - return -} - func networkFailureTarget(t *testing.T) { proxyURL := tools.RandomProxyURL(t) smap := tools.GetClusterMap(t, proxyURL) diff --git a/core/meta/hrw.go b/core/meta/hrw.go index 80bf4cad25..afedfc440e 100644 --- a/core/meta/hrw.go +++ b/core/meta/hrw.go @@ -43,7 +43,7 @@ func (smap *Smap) HrwHash2T(digest uint64) (si *Snode, err error) { if tsi.InMaintOrDecomm() { // always skipping targets 'in maintenance mode' continue } - cs := xoshiro256.Hash(tsi.Digest() ^ digest) + cs := xoshiro256.Hash(tsi.digest() ^ digest) if cs >= maxH { maxH = cs si = tsi @@ -59,7 +59,7 @@ func (smap *Smap) HrwHash2T(digest uint64) (si *Snode, err error) { func (smap *Smap) HrwHash2Tall(digest uint64) (si *Snode, err error) { var maxH uint64 for _, tsi := range smap.Tmap { - cs := xoshiro256.Hash(tsi.Digest() ^ digest) + cs := xoshiro256.Hash(tsi.digest() ^ digest) if cs >= maxH { maxH = cs si = tsi @@ -83,7 +83,7 @@ func (smap *Smap) HrwProxy(idToSkip string) (pi *Snode, err error) { if psi.InMaintOrDecomm() { continue } - if d := psi.Digest(); d >= maxH { + if d := psi.digest(); d >= maxH { maxH = d pi = psi } @@ -103,7 +103,7 @@ func (smap *Smap) HrwIC(uuid string) (pi *Snode, err error) { if psi.InMaintOrDecomm() || !psi.IsIC() { continue } - cs := xoshiro256.Hash(psi.Digest() ^ digest) + cs := xoshiro256.Hash(psi.digest() ^ digest) if cs >= maxH { maxH = cs pi = psi @@ -126,8 +126,7 @@ func (smap *Smap) HrwTargetTask(uuid string) (si *Snode, err error) { if tsi.InMaintOrDecomm() { continue } - // Assumes that sinfo.idDigest is initialized - cs := xoshiro256.Hash(tsi.Digest() ^ digest) + cs := xoshiro256.Hash(tsi.digest() ^ digest) if cs >= maxH { maxH = cs si = tsi @@ -166,7 +165,7 @@ func (smap *Smap) HrwTargetList(uname *string, count int) (sis Nodes, err error) hlist := newHrwList(count) for _, tsi := range smap.Tmap { - cs := xoshiro256.Hash(tsi.Digest() ^ digest) + cs := xoshiro256.Hash(tsi.digest() ^ digest) if tsi.InMaintOrDecomm() { continue } diff --git a/core/meta/smap.go b/core/meta/smap.go index 1e2d170051..0e5bf05f06 100644 --- a/core/meta/smap.go +++ b/core/meta/smap.go @@ -78,7 +78,7 @@ type ( name string PubExtra []NetInfo `json:"pub_extra,omitempty"` Flags cos.BitFlags `json:"flags"` // enum { SnodeNonElectable, SnodeIC, ... } - idDigest uint64 + IDDigest uint64 `json:"id_digest"` } Nodes []*Snode // slice of Snodes @@ -109,11 +109,11 @@ func (d *Snode) Init(id, daeType string) { d.setDigest() } -func (d *Snode) Digest() uint64 { return d.idDigest } +func (d *Snode) digest() uint64 { return d.IDDigest } func (d *Snode) setDigest() { - if d.idDigest == 0 { - d.idDigest = xxhash.Checksum64S(cos.UnsafeB(d.ID()), cos.MLCG32) + if d.IDDigest == 0 { + d.IDDigest = xxhash.Checksum64S(cos.UnsafeB(d.ID()), cos.MLCG32) } }