satellite/nodeselection: remove stats/size from nodeselection state

stats/size/count is not used by any production code, and it's not required, as we can assert the state with other checks.

real motivation: next commits will make the Selector of the State configurable, therefore we won't have one single Stat, it depends on the request parameters.

(we plan to support both network and id based randomization)

Change-Id: I631828fc0046d2fef5b7a674fc0268a0446e9655
This commit is contained in:
Márton Elek 2023-08-01 13:30:30 +02:00 committed by Storj Robot
parent 7c65c0cea5
commit f7b39aaed4
5 changed files with 0 additions and 74 deletions

View File

@ -19,7 +19,6 @@ var ErrNotEnoughNodes = errs.Class("not enough nodes")
type State struct {
mu sync.RWMutex
stats Stats
// netByID returns subnet based on storj.NodeID
netByID map[storj.NodeID]string
// distinct contains selectors for distinct selection.
@ -37,8 +36,6 @@ type Stats struct {
// Selector defines interface for selecting nodes.
type Selector interface {
// Count returns the number of maximum number of nodes that it can return.
Count() int
// Select selects up-to n nodes which are included by the criteria.
// empty criteria includes all the nodes
Select(n int, nodeFilter NodeFilter) []*SelectedNode
@ -59,11 +56,6 @@ func NewState(reputableNodes, newNodes []*SelectedNode) *State {
state.distinct.Reputable = SelectBySubnetFromNodes(reputableNodes)
state.distinct.New = SelectBySubnetFromNodes(newNodes)
state.stats = Stats{
New: state.distinct.New.Count(),
Reputable: state.distinct.Reputable.Count(),
}
return state
}
@ -108,14 +100,6 @@ func (state *State) Select(ctx context.Context, request Request) (_ []*SelectedN
return selected, nil
}
// Stats returns state information.
func (state *State) Stats() Stats {
state.mu.RLock()
defer state.mu.RUnlock()
return state.stats
}
// ExcludeNetworksBasedOnNodes will create a NodeFilter which exclude all nodes which shares subnet with the specified ones.
func (state *State) ExcludeNetworksBasedOnNodes(ds []storj.NodeID) NodeFilter {
uniqueExcludedNet := make(map[string]struct{}, len(ds))

View File

@ -29,10 +29,6 @@ func TestState_SelectNonDistinct(t *testing.T) {
)
state := nodeselection.NewState(reputableNodes, newNodes)
require.Equal(t, nodeselection.Stats{
New: 5,
Reputable: 5,
}, state.Stats())
{ // select 5 non-distinct subnet reputable nodes
const selectCount = 5
@ -85,10 +81,6 @@ func TestState_SelectDistinct(t *testing.T) {
)
state := nodeselection.NewState(reputableNodes, newNodes)
require.Equal(t, nodeselection.Stats{
New: 2,
Reputable: 2,
}, state.Stats())
{ // select 2 distinct subnet reputable nodes
const selectCount = 2

View File

@ -277,7 +277,6 @@ func TestRandomizedSelectionCache(t *testing.T) {
uploadSelectionCache := satellite.Overlay.Service.UploadSelectionCache
allIDs := make(storj.NodeIDList, totalNodes)
nodeCounts := make(map[storj.NodeID]int)
expectedNewCount := int(float64(totalNodes) * satellite.Config.Overlay.Node.NewNodeFraction)
// put nodes in cache
for i := 0; i < totalNodes; i++ {
@ -319,10 +318,6 @@ func TestRandomizedSelectionCache(t *testing.T) {
err := uploadSelectionCache.Refresh(ctx)
require.NoError(t, err)
reputable, new, err := uploadSelectionCache.Size(ctx)
require.NoError(t, err)
require.Equal(t, totalNodes-expectedNewCount, reputable)
require.Equal(t, expectedNewCount, new)
// select numNodesToSelect nodes selectIterations times
for i := 0; i < selectIterations; i++ {

View File

@ -114,13 +114,3 @@ func (cache *UploadSelectionCache) GetNodes(ctx context.Context, req FindStorage
}
return selected, err
}
// Size returns how many reputable nodes and new nodes are in the cache.
func (cache *UploadSelectionCache) Size(ctx context.Context) (reputableNodeCount int, newNodeCount int, _ error) {
state, err := cache.cache.Get(ctx, time.Now())
if err != nil {
return 0, 0, Error.Wrap(err)
}
stats := state.Stats()
return stats.Reputable, stats.New, nil
}

View File

@ -75,10 +75,6 @@ func TestRefresh(t *testing.T) {
// the cache should have no nodes to start
err = cache.Refresh(ctx)
require.NoError(t, err)
reputable, new, err := cache.Size(ctx)
require.NoError(t, err)
require.Equal(t, 0, reputable)
require.Equal(t, 0, new)
// add some nodes to the database
const nodeCount = 2
@ -87,10 +83,6 @@ func TestRefresh(t *testing.T) {
// confirm nodes are in the cache once
err = cache.Refresh(ctx)
require.NoError(t, err)
reputable, new, err = cache.Size(ctx)
require.NoError(t, err)
require.Equal(t, 2, new)
require.Equal(t, 0, reputable)
})
}
@ -233,12 +225,6 @@ func TestGetNodes(t *testing.T) {
defer cacheCancel()
ctx.Go(func() error { return cache.Run(cacheCtx) })
// the cache should have no nodes to start
reputable, new, err := cache.Size(ctx)
require.NoError(t, err)
require.Equal(t, 0, reputable)
require.Equal(t, 0, new)
// add 4 nodes to the database and vet 2
const nodeCount = 4
nodeIds := addNodesToNodesTable(ctx, t, db.OverlayCache(), nodeCount, 2)
@ -247,10 +233,6 @@ func TestGetNodes(t *testing.T) {
// confirm cache.GetNodes returns the correct nodes
selectedNodes, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{RequestedCount: 2})
require.NoError(t, err)
reputable, new, err = cache.Size(ctx)
require.NoError(t, err)
require.Equal(t, 2, new)
require.Equal(t, 2, reputable)
require.Equal(t, 2, len(selectedNodes))
for _, node := range selectedNodes {
require.NotEqual(t, node.ID, "")
@ -276,9 +258,6 @@ func TestGetNodesExcludeCountryCodes(t *testing.T) {
// we only expect one node to be returned, even though we requested two, so there will be an error
require.Error(t, err)
_, new, err := cache.Size(ctx)
require.NoError(t, err)
require.Equal(t, 2, new)
require.Equal(t, 1, len(selectedNodes))
// the node that was returned should be the one that does not have the "FR" country code
require.Equal(t, planet.StorageNodes[1].ID(), selectedNodes[0].ID)
@ -526,12 +505,6 @@ func TestGetNodesError(t *testing.T) {
defer cacheCancel()
ctx.Go(func() error { return cache.Run(cacheCtx) })
// there should be 0 nodes in the cache
reputable, new, err := cache.Size(ctx)
require.NoError(t, err)
require.Equal(t, 0, reputable)
require.Equal(t, 0, new)
// since the cache has no nodes, we should not be able
// to get 2 storage nodes from it and we expect an error
_, err = cache.GetNodes(ctx, overlay.FindStorageNodesRequest{RequestedCount: 2})
@ -564,10 +537,6 @@ func TestNewNodeFraction(t *testing.T) {
// the cache should have no nodes to start
err = cache.Refresh(ctx)
require.NoError(t, err)
reputable, new, err := cache.Size(ctx)
require.NoError(t, err)
require.Equal(t, 0, reputable)
require.Equal(t, 0, new)
// add some nodes to the database, some are reputable and some are new nodes
const nodeCount = 10
@ -576,10 +545,6 @@ func TestNewNodeFraction(t *testing.T) {
// confirm nodes are in the cache once
err = cache.Refresh(ctx)
require.NoError(t, err)
reputable, new, err = cache.Size(ctx)
require.NoError(t, err)
require.Equal(t, 6, new)
require.Equal(t, 4, reputable)
// select nodes and confirm correct new node fraction
n, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{RequestedCount: 5})