Skip to content

Commit

Permalink
satellite/durability: avoid additional slice for nodes classification
Browse files Browse the repository at this point in the history
Change-Id: I106556e4c2f93135b7252cdce85a21eb61fba461
  • Loading branch information
mniewrzal committed Jan 2, 2024
1 parent 69431bf commit 4e06e75
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
18 changes: 6 additions & 12 deletions satellite/durability/observer.go
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/zeebo/errs"
"golang.org/x/exp/slices"

"storj.io/common/storj"
"storj.io/eventkit"
"storj.io/storj/satellite/metabase"
"storj.io/storj/satellite/metabase/rangedloop"
Expand Down Expand Up @@ -77,7 +76,7 @@ type Report struct {
busFactor HealthStat
classifier NodeClassifier
aliasMap *metabase.NodeAliasMap
nodes map[storj.NodeID]*nodeselection.SelectedNode
nodes []nodeselection.SelectedNode
db overlay.DB
metabaseDB *metabase.DB
reporter func(n time.Time, class string, value string, stat *HealthStat)
Expand Down Expand Up @@ -105,28 +104,23 @@ func NewDurability(db overlay.DB, metabaseDB *metabase.DB, class string, classif
reportThreshold: reportThreshold,
busFactorThreshold: busFactorThreshold,
asOfSystemInterval: asOfSystemInterval,
nodes: make(map[storj.NodeID]*nodeselection.SelectedNode),
healthStat: make(map[string]*HealthStat),
nodes: []nodeselection.SelectedNode{},
reporter: reportToEventkit,
maxPieceCount: maxPieceCount,
}
}

// Start implements rangedloop.Observer.
func (c *Report) Start(ctx context.Context, startTime time.Time) error {
nodes, err := c.db.GetParticipatingNodes(ctx, -12*time.Hour, c.asOfSystemInterval)
func (c *Report) Start(ctx context.Context, startTime time.Time) (err error) {
c.nodes, err = c.db.GetParticipatingNodes(ctx, -12*time.Hour, c.asOfSystemInterval)
if err != nil {
return errs.Wrap(err)
}
c.nodes = map[storj.NodeID]*nodeselection.SelectedNode{}
for ix := range nodes {
c.nodes[nodes[ix].ID] = &nodes[ix]
}
aliasMap, err := c.metabaseDB.LatestNodesAliasMap(ctx)
c.aliasMap, err = c.metabaseDB.LatestNodesAliasMap(ctx)
if err != nil {
return errs.Wrap(err)
}
c.aliasMap = aliasMap
c.resetStat()
c.classifyNodeAliases()
return nil
Expand All @@ -151,7 +145,7 @@ func (c *Report) classifyNodeAliases() {
continue
}

class := c.classifier(node)
class := c.classifier(&node)
id, ok := classes[class]
if !ok {
id = classID(len(classes))
Expand Down
5 changes: 2 additions & 3 deletions satellite/durability/observer_test.go
Expand Up @@ -70,7 +70,7 @@ func TestDurability(t *testing.T) {

c.aliasMap = metabase.NewNodeAliasMap(aliases)
for _, node := range storageNodes {
c.nodes[node.ID] = node
c.nodes = append(c.nodes, *node)
}

c.classifyNodeAliases()
Expand Down Expand Up @@ -136,9 +136,8 @@ func TestDurabilityUnknownNode(t *testing.T) {

c.aliasMap = metabase.NewNodeAliasMap(aliases)
for _, node := range storageNodes {
c.nodes[node.ID] = node
c.nodes = append(c.nodes, *node)
}

c.classifyNodeAliases()
fork, err := c.Fork(ctx)
require.NoError(t, err)
Expand Down

0 comments on commit 4e06e75

Please sign in to comment.