diff --git a/satellite/nodeselection/state.go b/satellite/nodeselection/state.go index f030246d9..395159a51 100644 --- a/satellite/nodeselection/state.go +++ b/satellite/nodeselection/state.go @@ -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)) diff --git a/satellite/nodeselection/state_test.go b/satellite/nodeselection/state_test.go index 88c523cc7..6386014ad 100644 --- a/satellite/nodeselection/state_test.go +++ b/satellite/nodeselection/state_test.go @@ -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 diff --git a/satellite/overlay/service_test.go b/satellite/overlay/service_test.go index 99efb0d7d..75a59bc2c 100644 --- a/satellite/overlay/service_test.go +++ b/satellite/overlay/service_test.go @@ -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++ { diff --git a/satellite/overlay/uploadselection.go b/satellite/overlay/uploadselection.go index b3af0a41a..120711de4 100644 --- a/satellite/overlay/uploadselection.go +++ b/satellite/overlay/uploadselection.go @@ -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 -} diff --git a/satellite/overlay/uploadselection_test.go b/satellite/overlay/uploadselection_test.go index 4fe34522f..9d02a3cbf 100644 --- a/satellite/overlay/uploadselection_test.go +++ b/satellite/overlay/uploadselection_test.go @@ -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})