2020-04-14 21:50:02 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package overlay_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-06-30 11:13:18 +01:00
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
2020-04-14 21:50:02 +01:00
|
|
|
"strconv"
|
2023-06-30 11:13:18 +01:00
|
|
|
"strings"
|
2020-04-14 21:50:02 +01:00
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
|
2023-06-30 11:13:18 +01:00
|
|
|
"storj.io/common/identity/testidentity"
|
2020-04-14 21:50:02 +01:00
|
|
|
"storj.io/common/memory"
|
|
|
|
"storj.io/common/pb"
|
|
|
|
"storj.io/common/storj"
|
2023-06-30 11:13:18 +01:00
|
|
|
"storj.io/common/storj/location"
|
2020-04-14 21:50:02 +01:00
|
|
|
"storj.io/common/sync2"
|
|
|
|
"storj.io/common/testcontext"
|
2020-05-06 18:22:54 +01:00
|
|
|
"storj.io/common/testrand"
|
satellite/overlay: remove/deprecate NodeSelectionCache.Disabled
Once uppon a time, at the dawn of the implementation of Storj, when all the nodes are read from the database directly, every time.
After a while -- due to performance reasons -- it has been changed for upload and download: where all the nodes are read for a short period of time, and used from memory.
This is the version which was improved recently to support advanced node selections using placement.
But stil we have an old configuration value `service.config.NodeSelectionCache.Disabled`, and the db based implementation: `service.FindStorageNodesWithPreferences(ctx, req, &service.config.Node)`.
For safety, we need to remove this option, to make sure that we use the cache, which has the advanced features.
This patch was supposed to be a very small one (just removing a method and a config: https://review.dev.storj.io/c/storj/storj/+/11074/1/satellite/overlay/service.go), but it turned out that we need to update a lot of unit tests.
These unit tests used the old implementation (which is not used in production any more).
The tests which used both implementation are just updated to use only the new one
The tests which used only the old implementation are refactored (but keeping the test cases).
Using real unit tests (without DB, working on OSX, fast)
Closes https://github.com/storj/storj/issues/6217
Change-Id: I023f92c7e34235665cf8474513e67b2fcc4763eb
2023-08-28 09:56:45 +01:00
|
|
|
"storj.io/private/version"
|
2022-02-25 16:53:24 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
2020-04-14 21:50:02 +01:00
|
|
|
"storj.io/storj/satellite"
|
2023-07-07 09:31:58 +01:00
|
|
|
"storj.io/storj/satellite/nodeselection"
|
2020-04-14 21:50:02 +01:00
|
|
|
"storj.io/storj/satellite/overlay"
|
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
|
|
|
)
|
|
|
|
|
2020-05-06 18:22:54 +01:00
|
|
|
var nodeSelectionConfig = overlay.NodeSelectionConfig{
|
2020-04-14 21:50:02 +01:00
|
|
|
NewNodeFraction: 0.2,
|
|
|
|
MinimumVersion: "v1.0.0",
|
|
|
|
OnlineWindow: 4 * time.Hour,
|
|
|
|
DistinctIP: true,
|
|
|
|
MinimumDiskSpace: 100 * memory.MiB,
|
2021-06-15 11:49:56 +01:00
|
|
|
|
|
|
|
AsOfSystemTime: overlay.AsOfSystemTimeConfig{
|
|
|
|
Enabled: true,
|
|
|
|
DefaultInterval: -time.Microsecond,
|
|
|
|
},
|
2020-04-14 21:50:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
// staleness is how stale the cache can be before we sync with
|
2020-08-11 15:50:01 +01:00
|
|
|
// the database to refresh the cache.
|
2020-04-14 21:50:02 +01:00
|
|
|
|
2022-06-28 12:53:39 +01:00
|
|
|
// using a low time will force the cache to refresh every time.
|
|
|
|
lowStaleness = 2 * time.Nanosecond
|
2020-04-14 21:50:02 +01:00
|
|
|
|
|
|
|
// using a positive time will make it so that the cache is only refreshed when
|
2020-08-11 15:50:01 +01:00
|
|
|
// it hasn't been in the past hour.
|
2020-04-14 21:50:02 +01:00
|
|
|
highStaleness = time.Hour
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRefresh(t *testing.T) {
|
|
|
|
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
2022-06-28 12:53:39 +01:00
|
|
|
cache, err := overlay.NewUploadSelectionCache(zap.NewNop(),
|
2020-04-14 21:50:02 +01:00
|
|
|
db.OverlayCache(),
|
|
|
|
lowStaleness,
|
2020-05-06 18:22:54 +01:00
|
|
|
nodeSelectionConfig,
|
2023-07-07 09:31:58 +01:00
|
|
|
nodeselection.NodeFilters{},
|
satellite/overlay: fix placement selection config parsing
When we do `satellite run api --placement '...'`, the placement rules are not parsed well.
The problem is based on `viper.AllSettings()`, and the main logic is sg. like this (from a new unit test):
```
r := ConfigurablePlacementRule{}
err := r.Set(p)
require.NoError(t, err)
serialized := r.String()
r2 := ConfigurablePlacementRule{}
err = r2.Set(serialized)
require.NoError(t, err)
require.Equal(t, p, r2.String())
```
All settings evaluates the placement rules in `ConfigurablePlacementRules` and stores the string representation.
The problem is that we don't have proper `String()` implementation (it prints out the structs instead of the original definition.
There are two main solutions for this problem:
1. We can fix the `String()`. When we parse a placement rule, the `String()` method should print out the original definition
2. We can switch to use pure string as configuration parameter, and parse the rules only when required.
I feel that 1 is error prone, we can do it (and in this patch I added a lot of `String()` implementations, but it's hard to be sure that our `String()` logic is inline with the parsing logic.
Therefore I decided to make the configuration value of the placements a string (or a wrapper around string).
That's the main reason why this patch seems to be big, as I updated all the usages.
But the main part is in beginning of the `placement.go` (configuration parsing is not a pflag.Value implementation any more, but a separated step).
And `filter.go`, (a few more String implementation for filters.
https://github.com/storj/storj/issues/6248
Change-Id: I47c762d3514342b76a2e85683b1c891502a0756a
2023-09-06 10:40:22 +01:00
|
|
|
overlay.NewPlacementDefinitions().CreateFilters,
|
2020-04-14 21:50:02 +01:00
|
|
|
)
|
2022-06-28 12:53:39 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
cacheCtx, cacheCancel := context.WithCancel(ctx)
|
|
|
|
defer cacheCancel()
|
|
|
|
ctx.Go(func() error { return cache.Run(cacheCtx) })
|
|
|
|
|
2020-04-14 21:50:02 +01:00
|
|
|
// the cache should have no nodes to start
|
2022-06-28 12:53:39 +01:00
|
|
|
err = cache.Refresh(ctx)
|
|
|
|
require.NoError(t, err)
|
2020-04-14 21:50:02 +01:00
|
|
|
|
|
|
|
// add some nodes to the database
|
|
|
|
const nodeCount = 2
|
2020-07-08 15:28:49 +01:00
|
|
|
addNodesToNodesTable(ctx, t, db.OverlayCache(), nodeCount, 0)
|
2020-04-14 21:50:02 +01:00
|
|
|
|
|
|
|
// confirm nodes are in the cache once
|
|
|
|
err = cache.Refresh(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-28 14:33:53 +00:00
|
|
|
func addNodesToNodesTable(ctx context.Context, t *testing.T, db overlay.DB, count, makeReputable int) (ids []storj.NodeID) {
|
2020-04-14 21:50:02 +01:00
|
|
|
for i := 0; i < count; i++ {
|
2023-08-01 12:01:47 +01:00
|
|
|
subnet := strconv.Itoa(i/3) + ".1.2"
|
|
|
|
addr := fmt.Sprintf("%s.%d:8080", subnet, i%3+1)
|
2020-04-14 21:50:02 +01:00
|
|
|
n := overlay.NodeCheckInInfo{
|
|
|
|
NodeID: storj.NodeID{byte(i)},
|
|
|
|
Address: &pb.NodeAddress{
|
2023-01-24 15:59:47 +00:00
|
|
|
Address: addr,
|
2020-04-14 21:50:02 +01:00
|
|
|
},
|
|
|
|
LastNet: subnet,
|
|
|
|
LastIPPort: addr,
|
|
|
|
IsUp: true,
|
|
|
|
Capacity: &pb.NodeCapacity{
|
2020-07-08 15:28:49 +01:00
|
|
|
FreeDisk: 200 * memory.MiB.Int64(),
|
2020-04-14 21:50:02 +01:00
|
|
|
},
|
|
|
|
Version: &pb.NodeVersion{
|
|
|
|
Version: "v1.1.0",
|
|
|
|
CommitHash: "",
|
|
|
|
Timestamp: time.Time{},
|
|
|
|
Release: true,
|
|
|
|
},
|
2023-08-01 12:01:47 +01:00
|
|
|
CountryCode: location.Germany + location.CountryCode(i%2),
|
2020-04-14 21:50:02 +01:00
|
|
|
}
|
2020-05-06 18:22:54 +01:00
|
|
|
err := db.UpdateCheckIn(ctx, n, time.Now().UTC(), nodeSelectionConfig)
|
2020-04-14 21:50:02 +01:00
|
|
|
require.NoError(t, err)
|
2020-04-24 17:11:04 +01:00
|
|
|
|
2020-07-08 15:28:49 +01:00
|
|
|
// make designated nodes reputable
|
|
|
|
if i < makeReputable {
|
2021-07-07 20:20:23 +01:00
|
|
|
vettedAt, err := db.TestVetNode(ctx, storj.NodeID{byte(i)})
|
2020-04-24 17:11:04 +01:00
|
|
|
require.NoError(t, err)
|
2021-07-07 20:20:23 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, vettedAt)
|
2021-01-28 14:33:53 +00:00
|
|
|
ids = append(ids, storj.NodeID{byte(i)})
|
2020-04-24 17:11:04 +01:00
|
|
|
}
|
2020-04-14 21:50:02 +01:00
|
|
|
}
|
2021-01-28 14:33:53 +00:00
|
|
|
return ids
|
2020-04-14 21:50:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type mockdb struct {
|
|
|
|
mu sync.Mutex
|
|
|
|
callCount int
|
2023-07-07 09:31:58 +01:00
|
|
|
reputable []*nodeselection.SelectedNode
|
|
|
|
new []*nodeselection.SelectedNode
|
2020-04-14 21:50:02 +01:00
|
|
|
}
|
|
|
|
|
2023-07-07 09:31:58 +01:00
|
|
|
func (m *mockdb) SelectAllStorageNodesUpload(ctx context.Context, selectionCfg overlay.NodeSelectionConfig) (reputable, new []*nodeselection.SelectedNode, err error) {
|
2020-04-14 21:50:02 +01:00
|
|
|
m.mu.Lock()
|
|
|
|
defer m.mu.Unlock()
|
|
|
|
sync2.Sleep(ctx, 500*time.Millisecond)
|
|
|
|
m.callCount++
|
2020-05-06 18:00:07 +01:00
|
|
|
|
2023-07-07 09:31:58 +01:00
|
|
|
reputable = make([]*nodeselection.SelectedNode, len(m.reputable))
|
2020-05-06 18:00:07 +01:00
|
|
|
for i, n := range m.reputable {
|
|
|
|
reputable[i] = n.Clone()
|
|
|
|
}
|
2023-07-07 09:31:58 +01:00
|
|
|
new = make([]*nodeselection.SelectedNode, len(m.new))
|
2020-05-06 18:00:07 +01:00
|
|
|
for i, n := range m.new {
|
|
|
|
new[i] = n.Clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
return reputable, new, nil
|
2020-04-14 21:50:02 +01:00
|
|
|
}
|
2020-05-06 18:00:07 +01:00
|
|
|
|
2020-04-14 21:50:02 +01:00
|
|
|
func TestRefreshConcurrent(t *testing.T) {
|
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
|
|
|
// concurrent cache.Refresh with high staleness, where high staleness means the
|
|
|
|
// cache should only be refreshed the first time we call cache.Refresh
|
|
|
|
mockDB := mockdb{}
|
2022-06-28 12:53:39 +01:00
|
|
|
cache, err := overlay.NewUploadSelectionCache(zap.NewNop(),
|
2020-04-14 21:50:02 +01:00
|
|
|
&mockDB,
|
|
|
|
highStaleness,
|
2020-05-06 18:22:54 +01:00
|
|
|
nodeSelectionConfig,
|
2023-07-07 09:31:58 +01:00
|
|
|
nodeselection.NodeFilters{},
|
satellite/overlay: fix placement selection config parsing
When we do `satellite run api --placement '...'`, the placement rules are not parsed well.
The problem is based on `viper.AllSettings()`, and the main logic is sg. like this (from a new unit test):
```
r := ConfigurablePlacementRule{}
err := r.Set(p)
require.NoError(t, err)
serialized := r.String()
r2 := ConfigurablePlacementRule{}
err = r2.Set(serialized)
require.NoError(t, err)
require.Equal(t, p, r2.String())
```
All settings evaluates the placement rules in `ConfigurablePlacementRules` and stores the string representation.
The problem is that we don't have proper `String()` implementation (it prints out the structs instead of the original definition.
There are two main solutions for this problem:
1. We can fix the `String()`. When we parse a placement rule, the `String()` method should print out the original definition
2. We can switch to use pure string as configuration parameter, and parse the rules only when required.
I feel that 1 is error prone, we can do it (and in this patch I added a lot of `String()` implementations, but it's hard to be sure that our `String()` logic is inline with the parsing logic.
Therefore I decided to make the configuration value of the placements a string (or a wrapper around string).
That's the main reason why this patch seems to be big, as I updated all the usages.
But the main part is in beginning of the `placement.go` (configuration parsing is not a pflag.Value implementation any more, but a separated step).
And `filter.go`, (a few more String implementation for filters.
https://github.com/storj/storj/issues/6248
Change-Id: I47c762d3514342b76a2e85683b1c891502a0756a
2023-09-06 10:40:22 +01:00
|
|
|
overlay.NewPlacementDefinitions().CreateFilters,
|
2020-04-14 21:50:02 +01:00
|
|
|
)
|
2022-06-28 12:53:39 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
cacheCtx, cacheCancel := context.WithCancel(ctx)
|
|
|
|
defer cacheCancel()
|
|
|
|
ctx.Go(func() error { return cache.Run(cacheCtx) })
|
2020-04-14 21:50:02 +01:00
|
|
|
|
|
|
|
var group errgroup.Group
|
|
|
|
group.Go(func() error {
|
|
|
|
return cache.Refresh(ctx)
|
|
|
|
})
|
|
|
|
group.Go(func() error {
|
|
|
|
return cache.Refresh(ctx)
|
|
|
|
})
|
2022-06-28 12:53:39 +01:00
|
|
|
require.NoError(t, group.Wait())
|
2020-04-14 21:50:02 +01:00
|
|
|
|
|
|
|
require.Equal(t, 1, mockDB.callCount)
|
|
|
|
|
|
|
|
// concurrent cache.Refresh with low staleness, where low staleness
|
|
|
|
// means that the cache will refresh *every time* cache.Refresh is called
|
|
|
|
mockDB = mockdb{}
|
2022-06-28 12:53:39 +01:00
|
|
|
cache, err = overlay.NewUploadSelectionCache(zap.NewNop(),
|
2020-04-14 21:50:02 +01:00
|
|
|
&mockDB,
|
|
|
|
lowStaleness,
|
2020-05-06 18:22:54 +01:00
|
|
|
nodeSelectionConfig,
|
2023-07-07 09:31:58 +01:00
|
|
|
nodeselection.NodeFilters{},
|
satellite/overlay: fix placement selection config parsing
When we do `satellite run api --placement '...'`, the placement rules are not parsed well.
The problem is based on `viper.AllSettings()`, and the main logic is sg. like this (from a new unit test):
```
r := ConfigurablePlacementRule{}
err := r.Set(p)
require.NoError(t, err)
serialized := r.String()
r2 := ConfigurablePlacementRule{}
err = r2.Set(serialized)
require.NoError(t, err)
require.Equal(t, p, r2.String())
```
All settings evaluates the placement rules in `ConfigurablePlacementRules` and stores the string representation.
The problem is that we don't have proper `String()` implementation (it prints out the structs instead of the original definition.
There are two main solutions for this problem:
1. We can fix the `String()`. When we parse a placement rule, the `String()` method should print out the original definition
2. We can switch to use pure string as configuration parameter, and parse the rules only when required.
I feel that 1 is error prone, we can do it (and in this patch I added a lot of `String()` implementations, but it's hard to be sure that our `String()` logic is inline with the parsing logic.
Therefore I decided to make the configuration value of the placements a string (or a wrapper around string).
That's the main reason why this patch seems to be big, as I updated all the usages.
But the main part is in beginning of the `placement.go` (configuration parsing is not a pflag.Value implementation any more, but a separated step).
And `filter.go`, (a few more String implementation for filters.
https://github.com/storj/storj/issues/6248
Change-Id: I47c762d3514342b76a2e85683b1c891502a0756a
2023-09-06 10:40:22 +01:00
|
|
|
overlay.NewPlacementDefinitions().CreateFilters,
|
2020-04-14 21:50:02 +01:00
|
|
|
)
|
2022-06-28 12:53:39 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
ctx.Go(func() error { return cache.Run(cacheCtx) })
|
2020-04-14 21:50:02 +01:00
|
|
|
group.Go(func() error {
|
|
|
|
return cache.Refresh(ctx)
|
|
|
|
})
|
|
|
|
group.Go(func() error {
|
|
|
|
return cache.Refresh(ctx)
|
|
|
|
})
|
|
|
|
err = group.Wait()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-06-28 12:53:39 +01:00
|
|
|
require.True(t, 1 <= mockDB.callCount && mockDB.callCount <= 2, "calls %d", mockDB.callCount)
|
2020-04-14 21:50:02 +01:00
|
|
|
}
|
|
|
|
|
2023-08-21 12:59:54 +01:00
|
|
|
func TestSelectNodes(t *testing.T) {
|
2020-04-14 21:50:02 +01:00
|
|
|
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
2020-05-06 18:22:54 +01:00
|
|
|
var nodeSelectionConfig = overlay.NodeSelectionConfig{
|
2020-04-14 21:50:02 +01:00
|
|
|
NewNodeFraction: 0.2,
|
|
|
|
MinimumVersion: "v1.0.0",
|
|
|
|
OnlineWindow: 4 * time.Hour,
|
|
|
|
DistinctIP: true,
|
|
|
|
MinimumDiskSpace: 100 * memory.MiB,
|
|
|
|
}
|
satellite/overlay: fix placement selection config parsing
When we do `satellite run api --placement '...'`, the placement rules are not parsed well.
The problem is based on `viper.AllSettings()`, and the main logic is sg. like this (from a new unit test):
```
r := ConfigurablePlacementRule{}
err := r.Set(p)
require.NoError(t, err)
serialized := r.String()
r2 := ConfigurablePlacementRule{}
err = r2.Set(serialized)
require.NoError(t, err)
require.Equal(t, p, r2.String())
```
All settings evaluates the placement rules in `ConfigurablePlacementRules` and stores the string representation.
The problem is that we don't have proper `String()` implementation (it prints out the structs instead of the original definition.
There are two main solutions for this problem:
1. We can fix the `String()`. When we parse a placement rule, the `String()` method should print out the original definition
2. We can switch to use pure string as configuration parameter, and parse the rules only when required.
I feel that 1 is error prone, we can do it (and in this patch I added a lot of `String()` implementations, but it's hard to be sure that our `String()` logic is inline with the parsing logic.
Therefore I decided to make the configuration value of the placements a string (or a wrapper around string).
That's the main reason why this patch seems to be big, as I updated all the usages.
But the main part is in beginning of the `placement.go` (configuration parsing is not a pflag.Value implementation any more, but a separated step).
And `filter.go`, (a few more String implementation for filters.
https://github.com/storj/storj/issues/6248
Change-Id: I47c762d3514342b76a2e85683b1c891502a0756a
2023-09-06 10:40:22 +01:00
|
|
|
placementRules := overlay.NewPlacementDefinitions()
|
2023-08-01 12:01:47 +01:00
|
|
|
placementRules.AddPlacementRule(storj.PlacementConstraint(5), nodeselection.NodeFilters{}.WithCountryFilter(location.NewSet(location.Germany)))
|
2023-08-17 10:53:05 +01:00
|
|
|
placementRules.AddPlacementRule(storj.PlacementConstraint(6), nodeselection.WithAnnotation(nodeselection.NodeFilters{}.WithCountryFilter(location.NewSet(location.Germany)), nodeselection.AutoExcludeSubnet, nodeselection.AutoExcludeSubnetOFF))
|
2023-08-01 12:01:47 +01:00
|
|
|
|
2022-06-28 12:53:39 +01:00
|
|
|
cache, err := overlay.NewUploadSelectionCache(zap.NewNop(),
|
2020-04-14 21:50:02 +01:00
|
|
|
db.OverlayCache(),
|
|
|
|
lowStaleness,
|
2020-05-06 18:22:54 +01:00
|
|
|
nodeSelectionConfig,
|
2023-07-07 09:31:58 +01:00
|
|
|
nodeselection.NodeFilters{},
|
2023-08-01 12:01:47 +01:00
|
|
|
placementRules.CreateFilters,
|
2020-04-14 21:50:02 +01:00
|
|
|
)
|
2022-06-28 12:53:39 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
cacheCtx, cacheCancel := context.WithCancel(ctx)
|
|
|
|
defer cacheCancel()
|
|
|
|
ctx.Go(func() error { return cache.Run(cacheCtx) })
|
|
|
|
|
2023-08-01 12:01:47 +01:00
|
|
|
// add 10 nodes to the database and vet 8
|
|
|
|
// 4 subnets [A A A B B B C C C D]
|
|
|
|
// 2 countries [DE X DE x DE x DE x DE x]
|
|
|
|
// vetted [1 1 1 1 1 1 1 1 0 0]
|
|
|
|
const nodeCount = 10
|
|
|
|
nodeIds := addNodesToNodesTable(ctx, t, db.OverlayCache(), nodeCount, 8)
|
|
|
|
require.Len(t, nodeIds, 8)
|
|
|
|
|
|
|
|
t.Run("normal selection", func(t *testing.T) {
|
|
|
|
t.Run("get 2", func(t *testing.T) {
|
2023-08-01 12:50:22 +01:00
|
|
|
t.Parallel()
|
2023-08-01 12:01:47 +01:00
|
|
|
// confirm cache.GetNodes returns the correct nodes
|
|
|
|
selectedNodes, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{RequestedCount: 2})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, selectedNodes, 2)
|
|
|
|
|
|
|
|
for _, node := range selectedNodes {
|
|
|
|
require.NotEqual(t, node.ID, "")
|
|
|
|
require.NotEqual(t, node.Address.Address, "")
|
|
|
|
require.NotEqual(t, node.LastIPPort, "")
|
|
|
|
require.NotEqual(t, node.LastNet, "")
|
|
|
|
require.NotEqual(t, node.LastNet, "")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("too much", func(t *testing.T) {
|
2023-08-01 12:50:22 +01:00
|
|
|
t.Parallel()
|
2023-08-01 12:01:47 +01:00
|
|
|
// we have 5 subnets (1 new, 4 vetted), with two nodes in each
|
|
|
|
_, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{RequestedCount: 6})
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("using country filter", func(t *testing.T) {
|
|
|
|
t.Run("normal", func(t *testing.T) {
|
2023-08-01 12:50:22 +01:00
|
|
|
t.Parallel()
|
2023-08-01 12:01:47 +01:00
|
|
|
selectedNodes, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{
|
|
|
|
RequestedCount: 3,
|
|
|
|
Placement: 5,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, selectedNodes, 3)
|
|
|
|
})
|
|
|
|
t.Run("too much", func(t *testing.T) {
|
2023-08-01 12:50:22 +01:00
|
|
|
t.Parallel()
|
2023-08-01 12:01:47 +01:00
|
|
|
_, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{
|
|
|
|
RequestedCount: 4,
|
|
|
|
Placement: 5,
|
|
|
|
})
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
})
|
2020-04-14 21:50:02 +01:00
|
|
|
|
2023-08-01 12:50:22 +01:00
|
|
|
t.Run("using country without subnets", func(t *testing.T) {
|
|
|
|
t.Run("normal", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
// it's possible to get 5 only because we don't use subnet exclusions.
|
|
|
|
selectedNodes, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{
|
|
|
|
RequestedCount: 5,
|
|
|
|
Placement: 6,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, selectedNodes, 5)
|
|
|
|
})
|
|
|
|
t.Run("too much", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
_, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{
|
|
|
|
RequestedCount: 6,
|
|
|
|
Placement: 6,
|
|
|
|
})
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("using country without subnets and exclusions", func(t *testing.T) {
|
|
|
|
// DE nodes: 0 (subet:A), 2 (A), 4 (B) 6(C) 8(C, but not vetted)
|
|
|
|
// if everything works well, we can exclude 0, and got 3 (2,4,6)
|
|
|
|
// unless somebody removes the 2 (because it's in the same subnet as 0)
|
|
|
|
selectedNodes, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{
|
|
|
|
RequestedCount: 3,
|
|
|
|
Placement: 6,
|
|
|
|
ExcludedIDs: []storj.NodeID{
|
|
|
|
nodeIds[0],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, selectedNodes, 3)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("check subnet selection", func(t *testing.T) {
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
selectedNodes, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{
|
|
|
|
RequestedCount: 3,
|
|
|
|
Placement: 0,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
subnets := map[string]struct{}{}
|
|
|
|
for _, node := range selectedNodes {
|
|
|
|
subnets[node.LastNet] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Len(t, selectedNodes, 3)
|
|
|
|
require.Len(t, subnets, 3)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-04-14 21:50:02 +01:00
|
|
|
})
|
|
|
|
}
|
2020-05-06 18:00:07 +01:00
|
|
|
|
2022-02-25 16:53:24 +00:00
|
|
|
func TestGetNodesExcludeCountryCodes(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 2, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
err := planet.Satellites[0].Overlay.Service.TestNodeCountryCode(ctx, planet.StorageNodes[0].ID(), "FR")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
cache := planet.Satellites[0].Overlay.Service.UploadSelectionCache
|
|
|
|
|
|
|
|
// confirm cache.GetNodes returns the correct nodes
|
|
|
|
selectedNodes, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{RequestedCount: 2})
|
|
|
|
// we only expect one node to be returned, even though we requested two, so there will be an error
|
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-06 18:00:07 +01:00
|
|
|
func TestGetNodesConcurrent(t *testing.T) {
|
2020-04-14 21:50:02 +01:00
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
2023-07-07 09:31:58 +01:00
|
|
|
reputableNodes := []*nodeselection.SelectedNode{{
|
2020-05-06 18:00:07 +01:00
|
|
|
ID: storj.NodeID{1},
|
|
|
|
Address: &pb.NodeAddress{Address: "127.0.0.9"},
|
|
|
|
LastNet: "127.0.0",
|
|
|
|
LastIPPort: "127.0.0.9:8000",
|
|
|
|
}}
|
2023-07-07 09:31:58 +01:00
|
|
|
newNodes := []*nodeselection.SelectedNode{{
|
2020-05-06 18:00:07 +01:00
|
|
|
ID: storj.NodeID{1},
|
|
|
|
Address: &pb.NodeAddress{Address: "127.0.0.10"},
|
|
|
|
LastNet: "127.0.0",
|
|
|
|
LastIPPort: "127.0.0.10:8000",
|
|
|
|
}}
|
|
|
|
|
2020-04-14 21:50:02 +01:00
|
|
|
// concurrent GetNodes with high staleness, where high staleness means the
|
|
|
|
// cache should only be refreshed the first time we call cache.GetNodes
|
2020-05-06 18:00:07 +01:00
|
|
|
mockDB := mockdb{
|
|
|
|
reputable: reputableNodes,
|
|
|
|
new: newNodes,
|
|
|
|
}
|
2022-06-28 12:53:39 +01:00
|
|
|
cache, err := overlay.NewUploadSelectionCache(zap.NewNop(),
|
2020-04-14 21:50:02 +01:00
|
|
|
&mockDB,
|
|
|
|
highStaleness,
|
2020-05-06 18:22:54 +01:00
|
|
|
nodeSelectionConfig,
|
2023-07-07 09:31:58 +01:00
|
|
|
nodeselection.NodeFilters{},
|
satellite/overlay: fix placement selection config parsing
When we do `satellite run api --placement '...'`, the placement rules are not parsed well.
The problem is based on `viper.AllSettings()`, and the main logic is sg. like this (from a new unit test):
```
r := ConfigurablePlacementRule{}
err := r.Set(p)
require.NoError(t, err)
serialized := r.String()
r2 := ConfigurablePlacementRule{}
err = r2.Set(serialized)
require.NoError(t, err)
require.Equal(t, p, r2.String())
```
All settings evaluates the placement rules in `ConfigurablePlacementRules` and stores the string representation.
The problem is that we don't have proper `String()` implementation (it prints out the structs instead of the original definition.
There are two main solutions for this problem:
1. We can fix the `String()`. When we parse a placement rule, the `String()` method should print out the original definition
2. We can switch to use pure string as configuration parameter, and parse the rules only when required.
I feel that 1 is error prone, we can do it (and in this patch I added a lot of `String()` implementations, but it's hard to be sure that our `String()` logic is inline with the parsing logic.
Therefore I decided to make the configuration value of the placements a string (or a wrapper around string).
That's the main reason why this patch seems to be big, as I updated all the usages.
But the main part is in beginning of the `placement.go` (configuration parsing is not a pflag.Value implementation any more, but a separated step).
And `filter.go`, (a few more String implementation for filters.
https://github.com/storj/storj/issues/6248
Change-Id: I47c762d3514342b76a2e85683b1c891502a0756a
2023-09-06 10:40:22 +01:00
|
|
|
overlay.NewPlacementDefinitions().CreateFilters,
|
2020-04-14 21:50:02 +01:00
|
|
|
)
|
2022-06-28 12:53:39 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
cacheCtx, cacheCancel := context.WithCancel(ctx)
|
|
|
|
defer cacheCancel()
|
|
|
|
ctx.Go(func() error { return cache.Run(cacheCtx) })
|
2020-04-14 21:50:02 +01:00
|
|
|
|
|
|
|
var group errgroup.Group
|
|
|
|
group.Go(func() error {
|
2020-05-06 18:00:07 +01:00
|
|
|
nodes, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{
|
2020-05-07 12:54:48 +01:00
|
|
|
RequestedCount: 1,
|
2020-05-06 18:00:07 +01:00
|
|
|
})
|
|
|
|
for i := range nodes {
|
|
|
|
nodes[i].ID = storj.NodeID{byte(i)}
|
|
|
|
nodes[i].Address.Address = "123.123.123.123"
|
|
|
|
}
|
|
|
|
nodes[0] = nil
|
2020-04-14 21:50:02 +01:00
|
|
|
return err
|
|
|
|
})
|
|
|
|
group.Go(func() error {
|
2020-05-06 18:00:07 +01:00
|
|
|
nodes, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{
|
2020-05-07 12:54:48 +01:00
|
|
|
RequestedCount: 1,
|
2020-05-06 18:00:07 +01:00
|
|
|
})
|
|
|
|
for i := range nodes {
|
|
|
|
nodes[i].ID = storj.NodeID{byte(i)}
|
|
|
|
nodes[i].Address.Address = "123.123.123.123"
|
|
|
|
}
|
|
|
|
nodes[0] = nil
|
2020-04-14 21:50:02 +01:00
|
|
|
return err
|
|
|
|
})
|
2022-06-28 12:53:39 +01:00
|
|
|
|
|
|
|
require.NoError(t, group.Wait())
|
2020-04-14 21:50:02 +01:00
|
|
|
// expect only one call to the db via cache.GetNodes
|
|
|
|
require.Equal(t, 1, mockDB.callCount)
|
|
|
|
|
|
|
|
// concurrent get nodes with low staleness, where low staleness means that
|
|
|
|
// the cache will refresh each time cache.GetNodes is called
|
2020-05-06 18:00:07 +01:00
|
|
|
mockDB = mockdb{
|
|
|
|
reputable: reputableNodes,
|
|
|
|
new: newNodes,
|
|
|
|
}
|
2022-06-28 12:53:39 +01:00
|
|
|
cache, err = overlay.NewUploadSelectionCache(zap.NewNop(),
|
2020-04-14 21:50:02 +01:00
|
|
|
&mockDB,
|
|
|
|
lowStaleness,
|
2020-05-06 18:22:54 +01:00
|
|
|
nodeSelectionConfig,
|
2023-07-07 09:31:58 +01:00
|
|
|
nodeselection.NodeFilters{},
|
satellite/overlay: fix placement selection config parsing
When we do `satellite run api --placement '...'`, the placement rules are not parsed well.
The problem is based on `viper.AllSettings()`, and the main logic is sg. like this (from a new unit test):
```
r := ConfigurablePlacementRule{}
err := r.Set(p)
require.NoError(t, err)
serialized := r.String()
r2 := ConfigurablePlacementRule{}
err = r2.Set(serialized)
require.NoError(t, err)
require.Equal(t, p, r2.String())
```
All settings evaluates the placement rules in `ConfigurablePlacementRules` and stores the string representation.
The problem is that we don't have proper `String()` implementation (it prints out the structs instead of the original definition.
There are two main solutions for this problem:
1. We can fix the `String()`. When we parse a placement rule, the `String()` method should print out the original definition
2. We can switch to use pure string as configuration parameter, and parse the rules only when required.
I feel that 1 is error prone, we can do it (and in this patch I added a lot of `String()` implementations, but it's hard to be sure that our `String()` logic is inline with the parsing logic.
Therefore I decided to make the configuration value of the placements a string (or a wrapper around string).
That's the main reason why this patch seems to be big, as I updated all the usages.
But the main part is in beginning of the `placement.go` (configuration parsing is not a pflag.Value implementation any more, but a separated step).
And `filter.go`, (a few more String implementation for filters.
https://github.com/storj/storj/issues/6248
Change-Id: I47c762d3514342b76a2e85683b1c891502a0756a
2023-09-06 10:40:22 +01:00
|
|
|
overlay.NewPlacementDefinitions().CreateFilters,
|
2020-04-14 21:50:02 +01:00
|
|
|
)
|
2022-06-28 12:53:39 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
ctx.Go(func() error { return cache.Run(cacheCtx) })
|
2020-04-14 21:50:02 +01:00
|
|
|
|
|
|
|
group.Go(func() error {
|
2020-05-06 18:00:07 +01:00
|
|
|
nodes, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{
|
2020-05-07 12:54:48 +01:00
|
|
|
RequestedCount: 1,
|
2020-05-06 18:00:07 +01:00
|
|
|
})
|
|
|
|
for i := range nodes {
|
|
|
|
nodes[i].ID = storj.NodeID{byte(i)}
|
|
|
|
nodes[i].Address.Address = "123.123.123.123"
|
|
|
|
}
|
|
|
|
nodes[0] = nil
|
2020-04-14 21:50:02 +01:00
|
|
|
return err
|
|
|
|
})
|
|
|
|
group.Go(func() error {
|
2020-05-06 18:00:07 +01:00
|
|
|
nodes, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{
|
2020-05-07 12:54:48 +01:00
|
|
|
RequestedCount: 1,
|
2020-05-06 18:00:07 +01:00
|
|
|
})
|
|
|
|
for i := range nodes {
|
|
|
|
nodes[i].ID = storj.NodeID{byte(i)}
|
|
|
|
nodes[i].Address.Address = "123.123.123.123"
|
|
|
|
}
|
|
|
|
nodes[0] = nil
|
2020-04-14 21:50:02 +01:00
|
|
|
return err
|
|
|
|
})
|
|
|
|
err = group.Wait()
|
|
|
|
require.NoError(t, err)
|
2022-06-28 12:53:39 +01:00
|
|
|
// expect up to two calls to the db via cache.GetNodes
|
|
|
|
require.True(t, 1 <= mockDB.callCount && mockDB.callCount <= 2, "calls %d", mockDB.callCount)
|
2020-04-14 21:50:02 +01:00
|
|
|
}
|
|
|
|
|
2020-05-06 18:22:54 +01:00
|
|
|
func TestGetNodesDistinct(t *testing.T) {
|
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
2023-07-07 09:31:58 +01:00
|
|
|
reputableNodes := []*nodeselection.SelectedNode{{
|
2020-05-06 18:22:54 +01:00
|
|
|
ID: testrand.NodeID(),
|
|
|
|
Address: &pb.NodeAddress{Address: "127.0.0.9"},
|
|
|
|
LastNet: "127.0.0",
|
|
|
|
LastIPPort: "127.0.0.9:8000",
|
|
|
|
}, {
|
|
|
|
ID: testrand.NodeID(),
|
|
|
|
Address: &pb.NodeAddress{Address: "127.0.0.6"},
|
|
|
|
LastNet: "127.0.0",
|
|
|
|
LastIPPort: "127.0.0.6:8000",
|
|
|
|
}, {
|
|
|
|
ID: testrand.NodeID(),
|
|
|
|
Address: &pb.NodeAddress{Address: "127.0.1.7"},
|
|
|
|
LastNet: "127.0.1",
|
|
|
|
LastIPPort: "127.0.1.7:8000",
|
|
|
|
}, {
|
|
|
|
ID: testrand.NodeID(),
|
|
|
|
Address: &pb.NodeAddress{Address: "127.0.2.7"},
|
|
|
|
LastNet: "127.0.2",
|
|
|
|
LastIPPort: "127.0.2.7:8000",
|
|
|
|
}}
|
|
|
|
|
2023-07-07 09:31:58 +01:00
|
|
|
newNodes := []*nodeselection.SelectedNode{{
|
2020-05-06 18:22:54 +01:00
|
|
|
ID: testrand.NodeID(),
|
|
|
|
Address: &pb.NodeAddress{Address: "127.0.0.10"},
|
|
|
|
LastNet: "127.0.0",
|
|
|
|
LastIPPort: "127.0.0.10:8000",
|
|
|
|
}, {
|
|
|
|
ID: testrand.NodeID(),
|
|
|
|
Address: &pb.NodeAddress{Address: "127.0.1.8"},
|
|
|
|
LastNet: "127.0.1",
|
|
|
|
LastIPPort: "127.0.1.8:8000",
|
|
|
|
}, {
|
|
|
|
ID: testrand.NodeID(),
|
|
|
|
Address: &pb.NodeAddress{Address: "127.0.2.8"},
|
|
|
|
LastNet: "127.0.2",
|
|
|
|
LastIPPort: "127.0.2.8:8000",
|
|
|
|
}}
|
|
|
|
|
|
|
|
mockDB := mockdb{
|
|
|
|
reputable: reputableNodes,
|
|
|
|
new: newNodes,
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// test that distinct ip doesn't return same last net
|
|
|
|
config := nodeSelectionConfig
|
|
|
|
config.NewNodeFraction = 0.5
|
|
|
|
config.DistinctIP = true
|
2022-06-28 12:53:39 +01:00
|
|
|
cache, err := overlay.NewUploadSelectionCache(zap.NewNop(),
|
2020-05-06 18:22:54 +01:00
|
|
|
&mockDB,
|
|
|
|
highStaleness,
|
|
|
|
config,
|
2023-08-17 10:53:05 +01:00
|
|
|
nodeselection.NodeFilters{},
|
satellite/overlay: fix placement selection config parsing
When we do `satellite run api --placement '...'`, the placement rules are not parsed well.
The problem is based on `viper.AllSettings()`, and the main logic is sg. like this (from a new unit test):
```
r := ConfigurablePlacementRule{}
err := r.Set(p)
require.NoError(t, err)
serialized := r.String()
r2 := ConfigurablePlacementRule{}
err = r2.Set(serialized)
require.NoError(t, err)
require.Equal(t, p, r2.String())
```
All settings evaluates the placement rules in `ConfigurablePlacementRules` and stores the string representation.
The problem is that we don't have proper `String()` implementation (it prints out the structs instead of the original definition.
There are two main solutions for this problem:
1. We can fix the `String()`. When we parse a placement rule, the `String()` method should print out the original definition
2. We can switch to use pure string as configuration parameter, and parse the rules only when required.
I feel that 1 is error prone, we can do it (and in this patch I added a lot of `String()` implementations, but it's hard to be sure that our `String()` logic is inline with the parsing logic.
Therefore I decided to make the configuration value of the placements a string (or a wrapper around string).
That's the main reason why this patch seems to be big, as I updated all the usages.
But the main part is in beginning of the `placement.go` (configuration parsing is not a pflag.Value implementation any more, but a separated step).
And `filter.go`, (a few more String implementation for filters.
https://github.com/storj/storj/issues/6248
Change-Id: I47c762d3514342b76a2e85683b1c891502a0756a
2023-09-06 10:40:22 +01:00
|
|
|
overlay.NewPlacementDefinitions().CreateFilters,
|
2020-05-06 18:22:54 +01:00
|
|
|
)
|
2022-06-28 12:53:39 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
cacheCtx, cacheCancel := context.WithCancel(ctx)
|
|
|
|
defer cacheCancel()
|
|
|
|
ctx.Go(func() error { return cache.Run(cacheCtx) })
|
2020-05-06 18:22:54 +01:00
|
|
|
|
|
|
|
// selecting 3 should be possible
|
|
|
|
nodes, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{
|
2020-05-07 12:54:48 +01:00
|
|
|
RequestedCount: 3,
|
2020-05-06 18:22:54 +01:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
seen := make(map[string]bool)
|
|
|
|
for _, n := range nodes {
|
|
|
|
require.False(t, seen[n.LastNet])
|
|
|
|
seen[n.LastNet] = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// selecting 6 is impossible
|
|
|
|
_, err = cache.GetNodes(ctx, overlay.FindStorageNodesRequest{
|
2020-05-07 12:54:48 +01:00
|
|
|
RequestedCount: 6,
|
2020-05-06 18:22:54 +01:00
|
|
|
})
|
|
|
|
require.Error(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // test that distinctIP=true allows selecting 6 nodes
|
satellite/overlay: configurable meaning of last_net
Up to now, we have been implementing the DistinctIP preference with code
in two places:
1. On check-in, the last_net is determined by taking the /24 or /64
(in ResolveIPAndNetwork()) and we store it with the node record.
2. On node selection, a preference parameter defines whether to return
results that are distinct on last_net.
It can be observed that we have never yet had the need to switch from
DistinctIP to !DistinctIP, or from !DistinctIP to DistinctIP, on the
same satellite, and we will probably never need to do so in an automated
way. It can also be observed that this arrangement makes tests more
complicated, because we often have to arrange for test nodes to have IP
addresses in different /24 networks (a particular pain on macOS).
Those two considerations, plus some pending work on the repair framework
that will make repair take last_net into consideration, motivate this
change.
With this change, in the #2 place, we will _always_ return results that
are distinct on last_net. We implement the DistinctIP preference, then,
by making the #1 place (ResolveIPAndNetwork()) more flexible. When
DistinctIP is enabled, last_net will be calculated as it was before. But
when DistinctIP is _off_, last_net can be the same as address (IP and
port). That will effectively implement !DistinctIP because every
record will have a distinct last_net already.
As a side effect, this flexibility will allow us to change the rules
about last_net construction arbitrarily. We can do tests where last_net
is set to the source IP, or to a /30 prefix, or a /16 prefix, etc., and
be able to exercise the production logic without requiring a virtual
network bridge.
This change should be safe to make without any migration code, because
all known production satellite deployments use DistinctIP, and the
associated last_net values will not change for them. They will only
change for satellites with !DistinctIP, which are mostly test
deployments that can be recreated trivially. For those satellites which
are both permanent and !DistinctIP, node selection will suddenly start
acting as though DistinctIP is enabled, until the operator runs a single
SQL update "UPDATE nodes SET last_net = last_ip_port". That can be done
either before or after deploying software with this change.
I also assert that this will not hurt performance for production
deployments. It's true that adding the distinct requirement to node
selection makes things a little slower, but the distinct requirement is
already present for all production deployments, and they will see no
change.
Refs: https://github.com/storj/storj/issues/5391
Change-Id: I0e7e92498c3da768df5b4d5fb213dcd2d4862924
2023-02-28 22:57:39 +00:00
|
|
|
// emulate DistinctIP=false behavior by filling in LastNets with unique addresses
|
2023-07-07 09:31:58 +01:00
|
|
|
for _, nodeList := range [][]*nodeselection.SelectedNode{reputableNodes, newNodes} {
|
satellite/overlay: configurable meaning of last_net
Up to now, we have been implementing the DistinctIP preference with code
in two places:
1. On check-in, the last_net is determined by taking the /24 or /64
(in ResolveIPAndNetwork()) and we store it with the node record.
2. On node selection, a preference parameter defines whether to return
results that are distinct on last_net.
It can be observed that we have never yet had the need to switch from
DistinctIP to !DistinctIP, or from !DistinctIP to DistinctIP, on the
same satellite, and we will probably never need to do so in an automated
way. It can also be observed that this arrangement makes tests more
complicated, because we often have to arrange for test nodes to have IP
addresses in different /24 networks (a particular pain on macOS).
Those two considerations, plus some pending work on the repair framework
that will make repair take last_net into consideration, motivate this
change.
With this change, in the #2 place, we will _always_ return results that
are distinct on last_net. We implement the DistinctIP preference, then,
by making the #1 place (ResolveIPAndNetwork()) more flexible. When
DistinctIP is enabled, last_net will be calculated as it was before. But
when DistinctIP is _off_, last_net can be the same as address (IP and
port). That will effectively implement !DistinctIP because every
record will have a distinct last_net already.
As a side effect, this flexibility will allow us to change the rules
about last_net construction arbitrarily. We can do tests where last_net
is set to the source IP, or to a /30 prefix, or a /16 prefix, etc., and
be able to exercise the production logic without requiring a virtual
network bridge.
This change should be safe to make without any migration code, because
all known production satellite deployments use DistinctIP, and the
associated last_net values will not change for them. They will only
change for satellites with !DistinctIP, which are mostly test
deployments that can be recreated trivially. For those satellites which
are both permanent and !DistinctIP, node selection will suddenly start
acting as though DistinctIP is enabled, until the operator runs a single
SQL update "UPDATE nodes SET last_net = last_ip_port". That can be done
either before or after deploying software with this change.
I also assert that this will not hurt performance for production
deployments. It's true that adding the distinct requirement to node
selection makes things a little slower, but the distinct requirement is
already present for all production deployments, and they will see no
change.
Refs: https://github.com/storj/storj/issues/5391
Change-Id: I0e7e92498c3da768df5b4d5fb213dcd2d4862924
2023-02-28 22:57:39 +00:00
|
|
|
for i := range nodeList {
|
|
|
|
nodeList[i].LastNet = nodeList[i].LastIPPort
|
|
|
|
}
|
|
|
|
}
|
2020-05-06 18:22:54 +01:00
|
|
|
config := nodeSelectionConfig
|
|
|
|
config.NewNodeFraction = 0.5
|
|
|
|
config.DistinctIP = false
|
2022-06-28 12:53:39 +01:00
|
|
|
cache, err := overlay.NewUploadSelectionCache(zap.NewNop(),
|
2020-05-06 18:22:54 +01:00
|
|
|
&mockDB,
|
|
|
|
highStaleness,
|
|
|
|
config,
|
2023-07-07 09:31:58 +01:00
|
|
|
nodeselection.NodeFilters{},
|
satellite/overlay: fix placement selection config parsing
When we do `satellite run api --placement '...'`, the placement rules are not parsed well.
The problem is based on `viper.AllSettings()`, and the main logic is sg. like this (from a new unit test):
```
r := ConfigurablePlacementRule{}
err := r.Set(p)
require.NoError(t, err)
serialized := r.String()
r2 := ConfigurablePlacementRule{}
err = r2.Set(serialized)
require.NoError(t, err)
require.Equal(t, p, r2.String())
```
All settings evaluates the placement rules in `ConfigurablePlacementRules` and stores the string representation.
The problem is that we don't have proper `String()` implementation (it prints out the structs instead of the original definition.
There are two main solutions for this problem:
1. We can fix the `String()`. When we parse a placement rule, the `String()` method should print out the original definition
2. We can switch to use pure string as configuration parameter, and parse the rules only when required.
I feel that 1 is error prone, we can do it (and in this patch I added a lot of `String()` implementations, but it's hard to be sure that our `String()` logic is inline with the parsing logic.
Therefore I decided to make the configuration value of the placements a string (or a wrapper around string).
That's the main reason why this patch seems to be big, as I updated all the usages.
But the main part is in beginning of the `placement.go` (configuration parsing is not a pflag.Value implementation any more, but a separated step).
And `filter.go`, (a few more String implementation for filters.
https://github.com/storj/storj/issues/6248
Change-Id: I47c762d3514342b76a2e85683b1c891502a0756a
2023-09-06 10:40:22 +01:00
|
|
|
overlay.NewPlacementDefinitions().CreateFilters,
|
2020-05-06 18:22:54 +01:00
|
|
|
)
|
2022-06-28 12:53:39 +01:00
|
|
|
require.NoError(t, err)
|
2020-05-06 18:22:54 +01:00
|
|
|
|
2022-06-28 12:53:39 +01:00
|
|
|
cacheCtx, cacheCancel := context.WithCancel(ctx)
|
|
|
|
defer cacheCancel()
|
|
|
|
ctx.Go(func() error { return cache.Run(cacheCtx) })
|
|
|
|
|
|
|
|
_, err = cache.GetNodes(ctx, overlay.FindStorageNodesRequest{
|
2020-05-07 12:54:48 +01:00
|
|
|
RequestedCount: 6,
|
2020-05-06 18:22:54 +01:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-06 18:00:07 +01:00
|
|
|
func TestGetNodesError(t *testing.T) {
|
2020-04-14 21:50:02 +01:00
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
|
|
|
mockDB := mockdb{}
|
2022-06-28 12:53:39 +01:00
|
|
|
cache, err := overlay.NewUploadSelectionCache(zap.NewNop(),
|
2020-04-14 21:50:02 +01:00
|
|
|
&mockDB,
|
|
|
|
highStaleness,
|
2020-05-06 18:22:54 +01:00
|
|
|
nodeSelectionConfig,
|
2023-07-07 09:31:58 +01:00
|
|
|
nodeselection.NodeFilters{},
|
satellite/overlay: fix placement selection config parsing
When we do `satellite run api --placement '...'`, the placement rules are not parsed well.
The problem is based on `viper.AllSettings()`, and the main logic is sg. like this (from a new unit test):
```
r := ConfigurablePlacementRule{}
err := r.Set(p)
require.NoError(t, err)
serialized := r.String()
r2 := ConfigurablePlacementRule{}
err = r2.Set(serialized)
require.NoError(t, err)
require.Equal(t, p, r2.String())
```
All settings evaluates the placement rules in `ConfigurablePlacementRules` and stores the string representation.
The problem is that we don't have proper `String()` implementation (it prints out the structs instead of the original definition.
There are two main solutions for this problem:
1. We can fix the `String()`. When we parse a placement rule, the `String()` method should print out the original definition
2. We can switch to use pure string as configuration parameter, and parse the rules only when required.
I feel that 1 is error prone, we can do it (and in this patch I added a lot of `String()` implementations, but it's hard to be sure that our `String()` logic is inline with the parsing logic.
Therefore I decided to make the configuration value of the placements a string (or a wrapper around string).
That's the main reason why this patch seems to be big, as I updated all the usages.
But the main part is in beginning of the `placement.go` (configuration parsing is not a pflag.Value implementation any more, but a separated step).
And `filter.go`, (a few more String implementation for filters.
https://github.com/storj/storj/issues/6248
Change-Id: I47c762d3514342b76a2e85683b1c891502a0756a
2023-09-06 10:40:22 +01:00
|
|
|
overlay.NewPlacementDefinitions().CreateFilters,
|
2020-04-14 21:50:02 +01:00
|
|
|
)
|
2022-06-28 12:53:39 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
cacheCtx, cacheCancel := context.WithCancel(ctx)
|
|
|
|
defer cacheCancel()
|
|
|
|
ctx.Go(func() error { return cache.Run(cacheCtx) })
|
2020-04-14 21:50:02 +01:00
|
|
|
|
|
|
|
// since the cache has no nodes, we should not be able
|
|
|
|
// to get 2 storage nodes from it and we expect an error
|
2022-06-28 12:53:39 +01:00
|
|
|
_, err = cache.GetNodes(ctx, overlay.FindStorageNodesRequest{RequestedCount: 2})
|
2020-04-14 21:50:02 +01:00
|
|
|
require.Error(t, err)
|
|
|
|
}
|
2020-04-24 17:11:04 +01:00
|
|
|
|
|
|
|
func TestNewNodeFraction(t *testing.T) {
|
|
|
|
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
|
|
|
newNodeFraction := 0.2
|
2020-05-06 18:22:54 +01:00
|
|
|
var nodeSelectionConfig = overlay.NodeSelectionConfig{
|
2020-04-24 17:11:04 +01:00
|
|
|
NewNodeFraction: newNodeFraction,
|
|
|
|
MinimumVersion: "v1.0.0",
|
|
|
|
OnlineWindow: 4 * time.Hour,
|
|
|
|
DistinctIP: true,
|
|
|
|
MinimumDiskSpace: 10 * memory.MiB,
|
|
|
|
}
|
2022-06-28 12:53:39 +01:00
|
|
|
cache, err := overlay.NewUploadSelectionCache(zap.NewNop(),
|
2020-04-24 17:11:04 +01:00
|
|
|
db.OverlayCache(),
|
|
|
|
lowStaleness,
|
2020-05-06 18:22:54 +01:00
|
|
|
nodeSelectionConfig,
|
2023-07-07 09:31:58 +01:00
|
|
|
nodeselection.NodeFilters{},
|
satellite/overlay: fix placement selection config parsing
When we do `satellite run api --placement '...'`, the placement rules are not parsed well.
The problem is based on `viper.AllSettings()`, and the main logic is sg. like this (from a new unit test):
```
r := ConfigurablePlacementRule{}
err := r.Set(p)
require.NoError(t, err)
serialized := r.String()
r2 := ConfigurablePlacementRule{}
err = r2.Set(serialized)
require.NoError(t, err)
require.Equal(t, p, r2.String())
```
All settings evaluates the placement rules in `ConfigurablePlacementRules` and stores the string representation.
The problem is that we don't have proper `String()` implementation (it prints out the structs instead of the original definition.
There are two main solutions for this problem:
1. We can fix the `String()`. When we parse a placement rule, the `String()` method should print out the original definition
2. We can switch to use pure string as configuration parameter, and parse the rules only when required.
I feel that 1 is error prone, we can do it (and in this patch I added a lot of `String()` implementations, but it's hard to be sure that our `String()` logic is inline with the parsing logic.
Therefore I decided to make the configuration value of the placements a string (or a wrapper around string).
That's the main reason why this patch seems to be big, as I updated all the usages.
But the main part is in beginning of the `placement.go` (configuration parsing is not a pflag.Value implementation any more, but a separated step).
And `filter.go`, (a few more String implementation for filters.
https://github.com/storj/storj/issues/6248
Change-Id: I47c762d3514342b76a2e85683b1c891502a0756a
2023-09-06 10:40:22 +01:00
|
|
|
overlay.NewPlacementDefinitions().CreateFilters,
|
2020-04-24 17:11:04 +01:00
|
|
|
)
|
2022-06-28 12:53:39 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
cacheCtx, cacheCancel := context.WithCancel(ctx)
|
|
|
|
defer cacheCancel()
|
|
|
|
ctx.Go(func() error { return cache.Run(cacheCtx) })
|
|
|
|
|
2020-04-24 17:11:04 +01:00
|
|
|
// the cache should have no nodes to start
|
2022-06-28 12:53:39 +01:00
|
|
|
err = cache.Refresh(ctx)
|
|
|
|
require.NoError(t, err)
|
2020-04-24 17:11:04 +01:00
|
|
|
|
|
|
|
// add some nodes to the database, some are reputable and some are new nodes
|
2023-08-01 12:01:47 +01:00
|
|
|
// 3 nodes per net --> we need 4 net (* 3 node) reputable + 1 net (* 3 node) new to select 5 with 0.2 percentage new
|
|
|
|
const nodeCount = 15
|
|
|
|
repIDs := addNodesToNodesTable(ctx, t, db.OverlayCache(), nodeCount, 12)
|
|
|
|
require.Len(t, repIDs, 12)
|
2020-04-24 17:11:04 +01:00
|
|
|
// confirm nodes are in the cache once
|
|
|
|
err = cache.Refresh(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// select nodes and confirm correct new node fraction
|
|
|
|
n, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{RequestedCount: 5})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, len(n), 5)
|
|
|
|
var reputableCount int
|
|
|
|
for _, id := range repIDs {
|
|
|
|
for _, node := range n {
|
|
|
|
if id == node.ID {
|
|
|
|
reputableCount++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-08 15:28:49 +01:00
|
|
|
require.Equal(t, len(n)-reputableCount, int(5*newNodeFraction)) // 1, 1
|
2020-04-24 17:11:04 +01:00
|
|
|
})
|
|
|
|
}
|
2023-06-30 11:13:18 +01:00
|
|
|
|
|
|
|
func BenchmarkGetNodes(b *testing.B) {
|
|
|
|
newNodes := 2000
|
|
|
|
oldNodes := 18000
|
|
|
|
required := 110
|
|
|
|
if testing.Short() {
|
|
|
|
newNodes = 10
|
|
|
|
oldNodes = 50
|
|
|
|
required = 2
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(testcontext.New(b))
|
|
|
|
defer cancel()
|
|
|
|
log, err := zap.NewDevelopment()
|
|
|
|
require.NoError(b, err)
|
satellite/overlay: fix placement selection config parsing
When we do `satellite run api --placement '...'`, the placement rules are not parsed well.
The problem is based on `viper.AllSettings()`, and the main logic is sg. like this (from a new unit test):
```
r := ConfigurablePlacementRule{}
err := r.Set(p)
require.NoError(t, err)
serialized := r.String()
r2 := ConfigurablePlacementRule{}
err = r2.Set(serialized)
require.NoError(t, err)
require.Equal(t, p, r2.String())
```
All settings evaluates the placement rules in `ConfigurablePlacementRules` and stores the string representation.
The problem is that we don't have proper `String()` implementation (it prints out the structs instead of the original definition.
There are two main solutions for this problem:
1. We can fix the `String()`. When we parse a placement rule, the `String()` method should print out the original definition
2. We can switch to use pure string as configuration parameter, and parse the rules only when required.
I feel that 1 is error prone, we can do it (and in this patch I added a lot of `String()` implementations, but it's hard to be sure that our `String()` logic is inline with the parsing logic.
Therefore I decided to make the configuration value of the placements a string (or a wrapper around string).
That's the main reason why this patch seems to be big, as I updated all the usages.
But the main part is in beginning of the `placement.go` (configuration parsing is not a pflag.Value implementation any more, but a separated step).
And `filter.go`, (a few more String implementation for filters.
https://github.com/storj/storj/issues/6248
Change-Id: I47c762d3514342b76a2e85683b1c891502a0756a
2023-09-06 10:40:22 +01:00
|
|
|
placement := overlay.NewPlacementDefinitions()
|
2023-06-30 11:13:18 +01:00
|
|
|
placement.AddLegacyStaticRules()
|
2023-07-07 09:31:58 +01:00
|
|
|
defaultFilter := nodeselection.NodeFilters{}
|
2023-06-30 11:13:18 +01:00
|
|
|
|
|
|
|
db := NewMockUploadSelectionDb(
|
|
|
|
generatedSelectedNodes(b, oldNodes),
|
|
|
|
generatedSelectedNodes(b, newNodes),
|
|
|
|
)
|
|
|
|
cache, err := overlay.NewUploadSelectionCache(log, db, 10*time.Minute, overlay.NodeSelectionConfig{
|
|
|
|
NewNodeFraction: 0.1,
|
|
|
|
}, defaultFilter, placement.CreateFilters)
|
|
|
|
require.NoError(b, err)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
_ = cache.Run(ctx)
|
|
|
|
}()
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_, err := cache.GetNodes(ctx, overlay.FindStorageNodesRequest{
|
|
|
|
RequestedCount: required,
|
|
|
|
Placement: storj.US,
|
|
|
|
})
|
|
|
|
require.NoError(b, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MockUploadSelection implements overlay.UploadSelectionDB with a static list.
|
|
|
|
type MockUploadSelectionDB struct {
|
2023-07-07 09:31:58 +01:00
|
|
|
new []*nodeselection.SelectedNode
|
|
|
|
reputable []*nodeselection.SelectedNode
|
2023-06-30 11:13:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewMockUploadSelectionDb creates a MockUploadSelectionDB with the given reputable and new nodes.
|
2023-07-07 09:31:58 +01:00
|
|
|
func NewMockUploadSelectionDb(reputable, new []*nodeselection.SelectedNode) *MockUploadSelectionDB {
|
2023-06-30 11:13:18 +01:00
|
|
|
return &MockUploadSelectionDB{
|
|
|
|
new: new,
|
|
|
|
reputable: reputable,
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// SelectAllStorageNodesUpload implements overlay.UploadSelectionDB.
|
2023-07-07 09:31:58 +01:00
|
|
|
func (m MockUploadSelectionDB) SelectAllStorageNodesUpload(ctx context.Context, selectionCfg overlay.NodeSelectionConfig) (reputable, new []*nodeselection.SelectedNode, err error) {
|
2023-06-30 11:13:18 +01:00
|
|
|
return m.reputable, m.new, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ overlay.UploadSelectionDB = &MockUploadSelectionDB{}
|
|
|
|
|
2023-07-07 09:31:58 +01:00
|
|
|
func generatedSelectedNodes(b *testing.B, nodeNo int) []*nodeselection.SelectedNode {
|
|
|
|
nodes := make([]*nodeselection.SelectedNode, nodeNo)
|
2023-06-30 11:13:18 +01:00
|
|
|
ctx := testcontext.New(b)
|
|
|
|
for i := 0; i < nodeNo; i++ {
|
2023-07-07 09:31:58 +01:00
|
|
|
node := nodeselection.SelectedNode{}
|
2023-06-30 11:13:18 +01:00
|
|
|
identity, err := testidentity.NewTestIdentity(ctx)
|
|
|
|
require.NoError(b, err)
|
|
|
|
node.ID = identity.ID
|
|
|
|
|
|
|
|
// with 5% percentage chance, we re-use an existing IP address.
|
|
|
|
if rand.Intn(100) < 5 && i > 0 {
|
|
|
|
prevParts := strings.Split(nodes[rand.Intn(i)].LastIPPort, ":")
|
|
|
|
node.LastIPPort = fmt.Sprintf("%s:%d", prevParts[0], rand.Int31n(10000)+1000)
|
|
|
|
} else {
|
|
|
|
node.LastIPPort = fmt.Sprintf("%d.%d.%d.%d:%d", 10+i/256/256%256, i/256%256, i%256, 1, rand.Int31n(10000)+1000)
|
|
|
|
}
|
|
|
|
|
|
|
|
parts := strings.Split(node.LastIPPort, ".")
|
|
|
|
node.LastNet = fmt.Sprintf("%s.%s.%s.0", parts[0], parts[1], parts[2])
|
|
|
|
node.CountryCode = []location.CountryCode{location.None, location.UnitedStates, location.Germany, location.Hungary, location.Austria}[i%5]
|
|
|
|
nodes[i] = &node
|
|
|
|
}
|
|
|
|
return nodes
|
|
|
|
}
|
satellite/overlay: remove/deprecate NodeSelectionCache.Disabled
Once uppon a time, at the dawn of the implementation of Storj, when all the nodes are read from the database directly, every time.
After a while -- due to performance reasons -- it has been changed for upload and download: where all the nodes are read for a short period of time, and used from memory.
This is the version which was improved recently to support advanced node selections using placement.
But stil we have an old configuration value `service.config.NodeSelectionCache.Disabled`, and the db based implementation: `service.FindStorageNodesWithPreferences(ctx, req, &service.config.Node)`.
For safety, we need to remove this option, to make sure that we use the cache, which has the advanced features.
This patch was supposed to be a very small one (just removing a method and a config: https://review.dev.storj.io/c/storj/storj/+/11074/1/satellite/overlay/service.go), but it turned out that we need to update a lot of unit tests.
These unit tests used the old implementation (which is not used in production any more).
The tests which used both implementation are just updated to use only the new one
The tests which used only the old implementation are refactored (but keeping the test cases).
Using real unit tests (without DB, working on OSX, fast)
Closes https://github.com/storj/storj/issues/6217
Change-Id: I023f92c7e34235665cf8474513e67b2fcc4763eb
2023-08-28 09:56:45 +01:00
|
|
|
|
|
|
|
// GetOnlineNodesForAuditRepair satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) GetOnlineNodesForAuditRepair(ctx context.Context, nodeIDs []storj.NodeID, onlineWindow time.Duration) (map[storj.NodeID]*overlay.NodeReputation, error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// SelectStorageNodes satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) SelectStorageNodes(ctx context.Context, totalNeededNodes, newNodeCount int, criteria *overlay.NodeCriteria) ([]*nodeselection.SelectedNode, error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// SelectAllStorageNodesDownload satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) SelectAllStorageNodesDownload(ctx context.Context, onlineWindow time.Duration, asOf overlay.AsOfSystemTimeConfig) ([]*nodeselection.SelectedNode, error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) Get(ctx context.Context, nodeID storj.NodeID) (*overlay.NodeDossier, error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2023-08-21 12:59:54 +01:00
|
|
|
// GetNodes satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) GetNodes(ctx context.Context, nodeIDs storj.NodeIDList, onlineWindow, asOfSystemInterval time.Duration) (_ []nodeselection.SelectedNode, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetParticipatingNodes satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) GetParticipatingNodes(ctx context.Context, onlineWindow, asOfSystemInterval time.Duration) (_ []nodeselection.SelectedNode, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
satellite/overlay: remove/deprecate NodeSelectionCache.Disabled
Once uppon a time, at the dawn of the implementation of Storj, when all the nodes are read from the database directly, every time.
After a while -- due to performance reasons -- it has been changed for upload and download: where all the nodes are read for a short period of time, and used from memory.
This is the version which was improved recently to support advanced node selections using placement.
But stil we have an old configuration value `service.config.NodeSelectionCache.Disabled`, and the db based implementation: `service.FindStorageNodesWithPreferences(ctx, req, &service.config.Node)`.
For safety, we need to remove this option, to make sure that we use the cache, which has the advanced features.
This patch was supposed to be a very small one (just removing a method and a config: https://review.dev.storj.io/c/storj/storj/+/11074/1/satellite/overlay/service.go), but it turned out that we need to update a lot of unit tests.
These unit tests used the old implementation (which is not used in production any more).
The tests which used both implementation are just updated to use only the new one
The tests which used only the old implementation are refactored (but keeping the test cases).
Using real unit tests (without DB, working on OSX, fast)
Closes https://github.com/storj/storj/issues/6217
Change-Id: I023f92c7e34235665cf8474513e67b2fcc4763eb
2023-08-28 09:56:45 +01:00
|
|
|
// KnownReliable satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) KnownReliable(ctx context.Context, nodeIDs storj.NodeIDList, onlineWindow, asOfSystemInterval time.Duration) (online []nodeselection.SelectedNode, offline []nodeselection.SelectedNode, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reliable satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) Reliable(ctx context.Context, onlineWindow, asOfSystemInterval time.Duration) (online []nodeselection.SelectedNode, offline []nodeselection.SelectedNode, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateReputation satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) UpdateReputation(ctx context.Context, id storj.NodeID, request overlay.ReputationUpdate) error {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateNodeInfo satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) UpdateNodeInfo(ctx context.Context, node storj.NodeID, nodeInfo *overlay.InfoResponse) (stats *overlay.NodeDossier, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateCheckIn satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) UpdateCheckIn(ctx context.Context, node overlay.NodeCheckInInfo, timestamp time.Time, config overlay.NodeSelectionConfig) (err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNodeContained satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) SetNodeContained(ctx context.Context, node storj.NodeID, contained bool) (err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetAllContainedNodes satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) SetAllContainedNodes(ctx context.Context, containedNodes []storj.NodeID) (err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// AllPieceCounts satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) AllPieceCounts(ctx context.Context) (pieceCounts map[storj.NodeID]int64, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdatePieceCounts satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) UpdatePieceCounts(ctx context.Context, pieceCounts map[storj.NodeID]int64) (err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateExitStatus satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) UpdateExitStatus(ctx context.Context, request *overlay.ExitStatusRequest) (_ *overlay.NodeDossier, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetExitingNodes satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) GetExitingNodes(ctx context.Context) (exitingNodes []*overlay.ExitStatus, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetGracefulExitCompletedByTimeFrame satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) GetGracefulExitCompletedByTimeFrame(ctx context.Context, begin, end time.Time) (exitedNodes storj.NodeIDList, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetGracefulExitIncompleteByTimeFrame satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) GetGracefulExitIncompleteByTimeFrame(ctx context.Context, begin, end time.Time) (exitingNodes storj.NodeIDList, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetExitStatus satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) GetExitStatus(ctx context.Context, nodeID storj.NodeID) (exitStatus *overlay.ExitStatus, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetNodesNetwork satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) GetNodesNetwork(ctx context.Context, nodeIDs []storj.NodeID) (nodeNets []string, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetNodesNetworkInOrder satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) GetNodesNetworkInOrder(ctx context.Context, nodeIDs []storj.NodeID) (nodeNets []string, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// DisqualifyNode satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) DisqualifyNode(ctx context.Context, nodeID storj.NodeID, disqualifiedAt time.Time, reason overlay.DisqualificationReason) (email string, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetOfflineNodesForEmail satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) GetOfflineNodesForEmail(ctx context.Context, offlineWindow time.Duration, cutoff time.Duration, cooldown time.Duration, limit int) (nodes map[storj.NodeID]string, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateLastOfflineEmail satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) UpdateLastOfflineEmail(ctx context.Context, nodeIDs storj.NodeIDList, timestamp time.Time) (err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// DQNodesLastSeenBefore satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) DQNodesLastSeenBefore(ctx context.Context, cutoff time.Time, limit int) (nodeEmails map[storj.NodeID]string, count int, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestSuspendNodeUnknownAudit satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) TestSuspendNodeUnknownAudit(ctx context.Context, nodeID storj.NodeID, suspendedAt time.Time) (err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestUnsuspendNodeUnknownAudit satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) TestUnsuspendNodeUnknownAudit(ctx context.Context, nodeID storj.NodeID) (err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestVetNode satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) TestVetNode(ctx context.Context, nodeID storj.NodeID) (vettedTime *time.Time, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestUnvetNode satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) TestUnvetNode(ctx context.Context, nodeID storj.NodeID) (err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestSuspendNodeOffline satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) TestSuspendNodeOffline(ctx context.Context, nodeID storj.NodeID, suspendedAt time.Time) (err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestNodeCountryCode satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) TestNodeCountryCode(ctx context.Context, nodeID storj.NodeID, countryCode string) (err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestUpdateCheckInDirectUpdate satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) TestUpdateCheckInDirectUpdate(ctx context.Context, node overlay.NodeCheckInInfo, timestamp time.Time, semVer version.SemVer, walletFeatures string) (updated bool, err error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// OneTimeFixLastNets satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) OneTimeFixLastNets(ctx context.Context) error {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// IterateAllContactedNodes satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) IterateAllContactedNodes(ctx context.Context, f func(context.Context, *nodeselection.SelectedNode) error) error {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// IterateAllNodeDossiers satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) IterateAllNodeDossiers(ctx context.Context, f func(context.Context, *overlay.NodeDossier) error) error {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateNodeTags satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) UpdateNodeTags(ctx context.Context, tags nodeselection.NodeTags) error {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetNodeTags satisfies nodeevents.DB interface.
|
|
|
|
func (m *mockdb) GetNodeTags(ctx context.Context, id storj.NodeID) (nodeselection.NodeTags, error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|