From da08117fcd8cd9c61ccbd857eace4fb68583cba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Elek?= Date: Mon, 14 Aug 2023 16:27:53 +0200 Subject: [PATCH] satellite/~placement: do not ignore placement check for placement=0 There are cases when we would like to override the default placement=0 rule. For example when we would like to exclude tagged nodes from the selection (by default). Therefore we couldn't use a shortcut any more, we should always check the placement rules, even if we use placement=0. TODO: we need to update common, and rename `EveryCountry` to `DefaultPlacement`, just to avoid confusion. https://github.com/storj/storj/issues/6126 Change-Id: Iba6c655bd623e04351ea7ff91fd741785dc193e4 --- satellite/nodeselection/filter.go | 10 ++++++++++ satellite/orders/service.go | 10 ++++------ satellite/overlay/placement.go | 10 +++++----- satellite/repair/checker/observer.go | 2 +- satellite/repair/checker/online.go | 2 +- satellite/repair/repairer/segments.go | 22 ++++++++++------------ 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/satellite/nodeselection/filter.go b/satellite/nodeselection/filter.go index 9ff35260e..a625f0527 100644 --- a/satellite/nodeselection/filter.go +++ b/satellite/nodeselection/filter.go @@ -215,3 +215,13 @@ func NewExcludeFilter(filter NodeFilter) ExcludeFilter { } var _ NodeFilter = ExcludeFilter{} + +// AnyFilter matches all the nodes. +type AnyFilter struct{} + +// MatchInclude implements NodeFilter interface. +func (a AnyFilter) MatchInclude(node *SelectedNode) bool { + return true +} + +var _ NodeFilter = AnyFilter{} diff --git a/satellite/orders/service.go b/satellite/orders/service.go index 407eaac2f..8d7d051ed 100644 --- a/satellite/orders/service.go +++ b/satellite/orders/service.go @@ -147,12 +147,10 @@ func (service *Service) CreateGetOrderLimits(ctx context.Context, bucket metabas return nil, storj.PiecePrivateKey{}, Error.Wrap(err) } - if segment.Placement != storj.EveryCountry { - filter := service.placementRules(segment.Placement) - for id, node := range nodes { - if !filter.MatchInclude(node) { - delete(nodes, id) - } + filter := service.placementRules(segment.Placement) + for id, node := range nodes { + if !filter.MatchInclude(node) { + delete(nodes, id) } } diff --git a/satellite/overlay/placement.go b/satellite/overlay/placement.go index 9e9ad1656..db114db37 100644 --- a/satellite/overlay/placement.go +++ b/satellite/overlay/placement.go @@ -41,7 +41,9 @@ func (d *ConfigurablePlacementRule) String() string { // Set implements pflag.Value. func (d *ConfigurablePlacementRule) Set(s string) error { if d.placements == nil { - d.placements = make(map[storj.PlacementConstraint]nodeselection.NodeFilter) + d.placements = map[storj.PlacementConstraint]nodeselection.NodeFilter{ + storj.EveryCountry: nodeselection.AnyFilter{}, + } } d.AddLegacyStaticRules() return d.AddPlacementFromString(s) @@ -57,7 +59,8 @@ var _ pflag.Value = &ConfigurablePlacementRule{} // NewPlacementRules creates a fully initialized NewPlacementRules. func NewPlacementRules() *ConfigurablePlacementRule { return &ConfigurablePlacementRule{ - placements: make(map[storj.PlacementConstraint]nodeselection.NodeFilter), + placements: map[storj.PlacementConstraint]nodeselection.NodeFilter{ + storj.EveryCountry: nodeselection.AnyFilter{}}, } } @@ -152,9 +155,6 @@ func (d *ConfigurablePlacementRule) AddPlacementFromString(definitions string) e // CreateFilters implements PlacementCondition. func (d *ConfigurablePlacementRule) CreateFilters(constraint storj.PlacementConstraint) (filter nodeselection.NodeFilter) { - if constraint == storj.EveryCountry { - return nodeselection.NodeFilters{} - } if filters, found := d.placements[constraint]; found { return filters } diff --git a/satellite/repair/checker/observer.go b/satellite/repair/checker/observer.go index e942c8714..6abe7e612 100644 --- a/satellite/repair/checker/observer.go +++ b/satellite/repair/checker/observer.go @@ -355,7 +355,7 @@ func (fork *observerFork) process(ctx context.Context, segment *rangedloop.Segme } numOutOfPlacementPieces := 0 - if fork.doPlacementCheck && segment.Placement != storj.EveryCountry { + if fork.doPlacementCheck { outOfPlacementPieces, err := fork.nodesCache.OutOfPlacementPieces(ctx, segment.CreatedAt, segment.Pieces, segment.Placement) if err != nil { fork.totalStats.remoteSegmentsFailedToCheck++ diff --git a/satellite/repair/checker/online.go b/satellite/repair/checker/online.go index f4e5602a3..67de9572e 100644 --- a/satellite/repair/checker/online.go +++ b/satellite/repair/checker/online.go @@ -98,7 +98,7 @@ func (cache *ReliabilityCache) MissingPieces(ctx context.Context, created time.T func (cache *ReliabilityCache) OutOfPlacementPieces(ctx context.Context, created time.Time, pieces metabase.Pieces, placement storj.PlacementConstraint) (_ metabase.Pieces, err error) { defer mon.Task()(&ctx)(nil) - if len(pieces) == 0 || placement == storj.EveryCountry { + if len(pieces) == 0 { return metabase.Pieces{}, nil } diff --git a/satellite/repair/repairer/segments.go b/satellite/repair/repairer/segments.go index 813172418..5e90905b5 100644 --- a/satellite/repair/repairer/segments.go +++ b/satellite/repair/repairer/segments.go @@ -717,22 +717,20 @@ func (repairer *SegmentRepairer) classifySegmentPieces(ctx context.Context, segm } } - if repairer.doPlacementCheck && placement != storj.EveryCountry { - result.OutOfPlacementPiecesSet = map[uint16]bool{} + result.OutOfPlacementPiecesSet = map[uint16]bool{} - nodeFilters := repairer.placementRules(segment.Placement) - checkPlacement := func(reliable []nodeselection.SelectedNode) { - for _, node := range reliable { - if nodeFilters.MatchInclude(&node) { - continue - } - - result.OutOfPlacementPiecesSet[nodeIDPieceMap[node.ID]] = true + nodeFilters := repairer.placementRules(segment.Placement) + checkPlacement := func(reliable []nodeselection.SelectedNode) { + for _, node := range reliable { + if nodeFilters.MatchInclude(&node) { + continue } + + result.OutOfPlacementPiecesSet[nodeIDPieceMap[node.ID]] = true } - checkPlacement(online) - checkPlacement(offline) } + checkPlacement(online) + checkPlacement(offline) result.NumUnhealthyRetrievable = len(result.ClumpedPiecesSet) + len(result.OutOfPlacementPiecesSet) if len(result.ClumpedPiecesSet) != 0 && len(result.OutOfPlacementPiecesSet) != 0 {