Skip to content

Commit

Permalink
core: in cluster map, export node's 'id_digest' field
Browse files Browse the repository at this point in the history
Co-Authored-By: Abhishek Gaikwad <[email protected]>
Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman and gaikwadabhishek committed Jan 28, 2025
1 parent 20a119e commit 99690b6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 61 deletions.
3 changes: 2 additions & 1 deletion ais/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion ais/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
51 changes: 3 additions & 48 deletions ais/test/multiproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package integration_test

import (
"context"
"errors"
"fmt"
"math"
"net/http"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down
13 changes: 6 additions & 7 deletions core/meta/hrw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions core/meta/smap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 99690b6

Please sign in to comment.