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
This commit is contained in:
Márton Elek 2023-08-14 16:27:53 +02:00 committed by Storj Robot
parent baef654197
commit da08117fcd
6 changed files with 31 additions and 25 deletions

View File

@ -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{}

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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++

View File

@ -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
}

View File

@ -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 {