2019-07-15 20:58:39 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2023-06-29 14:26:52 +01:00
|
|
|
package checker_test
|
2019-07-15 20:58:39 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-12-22 19:07:07 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-07-15 20:58:39 +01:00
|
|
|
"go.uber.org/zap"
|
2022-06-28 12:53:39 +01:00
|
|
|
"golang.org/x/sync/errgroup"
|
2019-07-15 20:58:39 +01:00
|
|
|
|
2023-06-29 14:26:52 +01:00
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/storj/location"
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
2023-06-29 14:26:52 +01:00
|
|
|
"storj.io/storj/private/testplanet"
|
|
|
|
"storj.io/storj/satellite"
|
2021-04-21 13:42:57 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2022-10-31 21:33:17 +00:00
|
|
|
"storj.io/storj/satellite/nodeevents"
|
2023-07-07 09:31:58 +01:00
|
|
|
"storj.io/storj/satellite/nodeselection"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/overlay"
|
2023-06-29 14:26:52 +01:00
|
|
|
"storj.io/storj/satellite/repair/checker"
|
2019-07-15 20:58:39 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestReliabilityCache_Concurrent(t *testing.T) {
|
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
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
|
|
|
overlayCache, err := overlay.NewService(zap.NewNop(), fakeOverlayDB{}, fakeNodeEvents{}, overlay.NewPlacementDefinitions().CreateFilters, "", "", overlay.Config{
|
2022-06-28 12:53:39 +01:00
|
|
|
NodeSelectionCache: overlay.UploadSelectionCacheConfig{
|
|
|
|
Staleness: 2 * time.Nanosecond,
|
|
|
|
},
|
|
|
|
})
|
2020-12-22 19:07:07 +00:00
|
|
|
require.NoError(t, err)
|
2022-06-28 12:53:39 +01:00
|
|
|
cacheCtx, cacheCancel := context.WithCancel(ctx)
|
|
|
|
defer cacheCancel()
|
|
|
|
ctx.Go(func() error { return overlayCache.Run(cacheCtx) })
|
|
|
|
defer ctx.Check(overlayCache.Close)
|
2019-07-15 20:58:39 +01:00
|
|
|
|
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
|
|
|
cache := checker.NewReliabilityCache(overlayCache, time.Millisecond, overlay.NewPlacementDefinitions().CreateFilters, []string{})
|
2022-06-28 12:53:39 +01:00
|
|
|
var group errgroup.Group
|
2019-07-15 20:58:39 +01:00
|
|
|
for i := 0; i < 10; i++ {
|
2022-06-28 12:53:39 +01:00
|
|
|
group.Go(func() error {
|
2019-07-15 20:58:39 +01:00
|
|
|
for i := 0; i < 10000; i++ {
|
2020-12-14 17:33:03 +00:00
|
|
|
pieces := []metabase.Piece{{StorageNode: testrand.NodeID()}}
|
2022-06-28 12:53:39 +01:00
|
|
|
_, err := cache.MissingPieces(ctx, time.Now(), pieces)
|
2019-07-15 20:58:39 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
2022-06-28 12:53:39 +01:00
|
|
|
require.NoError(t, group.Wait())
|
2019-07-15 20:58:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type fakeOverlayDB struct{ overlay.DB }
|
2022-10-31 21:33:17 +00:00
|
|
|
type fakeNodeEvents struct{ nodeevents.DB }
|
2019-07-15 20:58:39 +01:00
|
|
|
|
2023-08-21 12:59:54 +01:00
|
|
|
func (fakeOverlayDB) GetParticipatingNodes(context.Context, time.Duration, time.Duration) ([]nodeselection.SelectedNode, error) {
|
2023-07-07 09:31:58 +01:00
|
|
|
return []nodeselection.SelectedNode{
|
2023-08-21 12:59:54 +01:00
|
|
|
{ID: testrand.NodeID(), Online: true},
|
|
|
|
{ID: testrand.NodeID(), Online: true},
|
|
|
|
{ID: testrand.NodeID(), Online: true},
|
|
|
|
{ID: testrand.NodeID(), Online: true},
|
|
|
|
}, nil
|
2019-07-15 20:58:39 +01:00
|
|
|
}
|
2023-06-29 14:26:52 +01:00
|
|
|
|
|
|
|
func TestReliabilityCache_OutOfPlacementPieces(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
|
|
|
|
config.Overlay.Node.AsOfSystemTime.Enabled = false
|
|
|
|
config.Overlay.Node.AsOfSystemTime.DefaultInterval = 0
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2023-07-06 13:35:26 +01:00
|
|
|
overlayService := planet.Satellites[0].Overlay.Service
|
2023-06-29 14:26:52 +01:00
|
|
|
config := planet.Satellites[0].Config.Checker
|
|
|
|
|
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
|
|
|
rules := overlay.NewPlacementDefinitions()
|
2023-07-06 13:35:26 +01:00
|
|
|
rules.AddLegacyStaticRules()
|
|
|
|
cache := checker.NewReliabilityCache(overlayService, config.ReliabilityCacheStaleness, rules.CreateFilters, []string{})
|
2023-06-29 14:26:52 +01:00
|
|
|
|
|
|
|
nodesPlacement := func(location location.CountryCode, nodes ...*testplanet.StorageNode) {
|
|
|
|
for _, node := range nodes {
|
2023-07-06 13:35:26 +01:00
|
|
|
err := overlayService.TestNodeCountryCode(ctx, node.ID(), location.String())
|
2023-06-29 14:26:52 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
require.NoError(t, cache.Refresh(ctx))
|
|
|
|
}
|
|
|
|
|
|
|
|
allPieces := metabase.Pieces{
|
|
|
|
metabase.Piece{Number: 0, StorageNode: planet.StorageNodes[0].ID()},
|
|
|
|
metabase.Piece{Number: 1, StorageNode: planet.StorageNodes[1].ID()},
|
|
|
|
metabase.Piece{Number: 2, StorageNode: planet.StorageNodes[2].ID()},
|
|
|
|
metabase.Piece{Number: 3, StorageNode: planet.StorageNodes[3].ID()},
|
|
|
|
}
|
|
|
|
|
|
|
|
pieces, err := cache.OutOfPlacementPieces(ctx, time.Now().Add(-time.Hour), metabase.Pieces{}, storj.EU)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Empty(t, pieces)
|
|
|
|
|
|
|
|
nodesPlacement(location.Poland, planet.StorageNodes...)
|
|
|
|
pieces, err = cache.OutOfPlacementPieces(ctx, time.Now().Add(-time.Hour), allPieces, storj.EU)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Empty(t, pieces)
|
|
|
|
|
|
|
|
pieces, err = cache.OutOfPlacementPieces(ctx, time.Now().Add(-time.Hour), allPieces, storj.US)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.ElementsMatch(t, allPieces, pieces)
|
|
|
|
|
|
|
|
nodesPlacement(location.UnitedStates, planet.StorageNodes[:2]...)
|
|
|
|
pieces, err = cache.OutOfPlacementPieces(ctx, time.Now().Add(-time.Hour), allPieces, storj.EU)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.ElementsMatch(t, allPieces[:2], pieces)
|
|
|
|
|
|
|
|
pieces, err = cache.OutOfPlacementPieces(ctx, time.Now().Add(-time.Hour), allPieces, storj.US)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.ElementsMatch(t, allPieces[2:], pieces)
|
|
|
|
})
|
|
|
|
}
|