satellite/nodeselection: rename (NodeFilter).MatchInclude to Match

As I learned, the `Include` supposed to communicate that some internal change also "included" to the filters during the check -> filters might be stateful.

But it's not the case any more after 552242387, where we removed the only one stateful filter.

Change-Id: I7c36ddadb2defbfa3b6b67bcc115e4427ba9e083
This commit is contained in:
Márton Elek 2023-08-28 09:42:08 +02:00
parent dcc4bd0d10
commit c202929413
No known key found for this signature in database
9 changed files with 75 additions and 75 deletions

View File

@ -12,7 +12,7 @@ import (
// NodeFilter can decide if a Node should be part of the selection or not. // NodeFilter can decide if a Node should be part of the selection or not.
type NodeFilter interface { type NodeFilter interface {
MatchInclude(node *SelectedNode) bool Match(node *SelectedNode) bool
} }
// NodeFilterWithAnnotation is a NodeFilter with additional annotations. // NodeFilterWithAnnotation is a NodeFilter with additional annotations.
@ -27,8 +27,8 @@ type Annotation struct {
Value string Value string
} }
// MatchInclude implements NodeFilter. // Match implements NodeFilter.
func (a Annotation) MatchInclude(node *SelectedNode) bool { func (a Annotation) Match(node *SelectedNode) bool {
return true return true
} }
@ -61,9 +61,9 @@ func (a AnnotatedNodeFilter) GetAnnotation(name string) string {
return "" return ""
} }
// MatchInclude implements NodeFilter. // Match implements NodeFilter.
func (a AnnotatedNodeFilter) MatchInclude(node *SelectedNode) bool { func (a AnnotatedNodeFilter) Match(node *SelectedNode) bool {
return a.Filter.MatchInclude(node) return a.Filter.Match(node)
} }
// WithAnnotation adds annotations to a NodeFilter. // WithAnnotation adds annotations to a NodeFilter.
@ -95,21 +95,21 @@ type NodeFilters []NodeFilter
// NodeFilterFunc is helper to use func as NodeFilter. // NodeFilterFunc is helper to use func as NodeFilter.
type NodeFilterFunc func(node *SelectedNode) bool type NodeFilterFunc func(node *SelectedNode) bool
// MatchInclude implements NodeFilter interface. // Match implements NodeFilter interface.
func (n NodeFilterFunc) MatchInclude(node *SelectedNode) bool { func (n NodeFilterFunc) Match(node *SelectedNode) bool {
return n(node) return n(node)
} }
// ExcludeAllFilter will never select any node. // ExcludeAllFilter will never select any node.
type ExcludeAllFilter struct{} type ExcludeAllFilter struct{}
// MatchInclude implements NodeFilter interface. // Match implements NodeFilter interface.
func (ExcludeAllFilter) MatchInclude(node *SelectedNode) bool { return false } func (ExcludeAllFilter) Match(node *SelectedNode) bool { return false }
// MatchInclude implements NodeFilter interface. // Match implements NodeFilter interface.
func (n NodeFilters) MatchInclude(node *SelectedNode) bool { func (n NodeFilters) Match(node *SelectedNode) bool {
for _, filter := range n { for _, filter := range n {
if !filter.MatchInclude(node) { if !filter.Match(node) {
return false return false
} }
} }
@ -153,8 +153,8 @@ func NewCountryFilter(permit location.Set) NodeFilter {
} }
} }
// MatchInclude implements NodeFilter interface. // Match implements NodeFilter interface.
func (p *CountryFilter) MatchInclude(node *SelectedNode) bool { func (p *CountryFilter) Match(node *SelectedNode) bool {
return p.permit.Contains(node.CountryCode) return p.permit.Contains(node.CountryCode)
} }
@ -163,8 +163,8 @@ var _ NodeFilter = &CountryFilter{}
// ExcludedNetworks will exclude nodes with specified networks. // ExcludedNetworks will exclude nodes with specified networks.
type ExcludedNetworks []string type ExcludedNetworks []string
// MatchInclude implements NodeFilter interface. // Match implements NodeFilter interface.
func (e ExcludedNetworks) MatchInclude(node *SelectedNode) bool { func (e ExcludedNetworks) Match(node *SelectedNode) bool {
for _, id := range e { for _, id := range e {
if id == node.LastNet { if id == node.LastNet {
return false return false
@ -178,8 +178,8 @@ var _ NodeFilter = ExcludedNetworks{}
// ExcludedNodeNetworks exclude nodes which has same net as the one of the specified. // ExcludedNodeNetworks exclude nodes which has same net as the one of the specified.
type ExcludedNodeNetworks []*SelectedNode type ExcludedNodeNetworks []*SelectedNode
// MatchInclude implements NodeFilter interface. // Match implements NodeFilter interface.
func (e ExcludedNodeNetworks) MatchInclude(node *SelectedNode) bool { func (e ExcludedNodeNetworks) Match(node *SelectedNode) bool {
for _, n := range e { for _, n := range e {
if node.LastNet == n.LastNet { if node.LastNet == n.LastNet {
return false return false
@ -193,8 +193,8 @@ var _ NodeFilter = ExcludedNodeNetworks{}
// ExcludedIDs can blacklist NodeIDs. // ExcludedIDs can blacklist NodeIDs.
type ExcludedIDs []storj.NodeID type ExcludedIDs []storj.NodeID
// MatchInclude implements NodeFilter interface. // Match implements NodeFilter interface.
func (e ExcludedIDs) MatchInclude(node *SelectedNode) bool { func (e ExcludedIDs) Match(node *SelectedNode) bool {
for _, id := range e { for _, id := range e {
if id == node.ID { if id == node.ID {
return false return false
@ -221,8 +221,8 @@ func NewTagFilter(id storj.NodeID, name string, value []byte) TagFilter {
} }
} }
// MatchInclude implements NodeFilter interface. // Match implements NodeFilter interface.
func (t TagFilter) MatchInclude(node *SelectedNode) bool { func (t TagFilter) Match(node *SelectedNode) bool {
for _, tag := range node.Tags { for _, tag := range node.Tags {
if tag.Name == t.name && bytes.Equal(tag.Value, t.value) && tag.Signer == t.signer { if tag.Name == t.name && bytes.Equal(tag.Value, t.value) && tag.Signer == t.signer {
return true return true
@ -238,9 +238,9 @@ type ExcludeFilter struct {
matchToExclude NodeFilter matchToExclude NodeFilter
} }
// MatchInclude implements NodeFilter interface. // Match implements NodeFilter interface.
func (e ExcludeFilter) MatchInclude(node *SelectedNode) bool { func (e ExcludeFilter) Match(node *SelectedNode) bool {
return !e.matchToExclude.MatchInclude(node) return !e.matchToExclude.Match(node)
} }
// NewExcludeFilter creates filter, nodes matching the given filter will be excluded. // NewExcludeFilter creates filter, nodes matching the given filter will be excluded.
@ -255,8 +255,8 @@ var _ NodeFilter = ExcludeFilter{}
// AnyFilter matches all the nodes. // AnyFilter matches all the nodes.
type AnyFilter struct{} type AnyFilter struct{}
// MatchInclude implements NodeFilter interface. // Match implements NodeFilter interface.
func (a AnyFilter) MatchInclude(node *SelectedNode) bool { func (a AnyFilter) Match(node *SelectedNode) bool {
return true return true
} }

View File

@ -23,11 +23,11 @@ func TestCriteria_ExcludeNodeID(t *testing.T) {
criteria := NodeFilters{}.WithExcludedIDs([]storj.NodeID{excluded}) criteria := NodeFilters{}.WithExcludedIDs([]storj.NodeID{excluded})
assert.False(t, criteria.MatchInclude(&SelectedNode{ assert.False(t, criteria.Match(&SelectedNode{
ID: excluded, ID: excluded,
})) }))
assert.True(t, criteria.MatchInclude(&SelectedNode{ assert.True(t, criteria.Match(&SelectedNode{
ID: included, ID: included,
})) }))
} }
@ -42,15 +42,15 @@ func TestCriteria_ExcludedNodeNetworks(t *testing.T) {
}, },
}) })
assert.False(t, criteria.MatchInclude(&SelectedNode{ assert.False(t, criteria.Match(&SelectedNode{
LastNet: "192.168.1.0", LastNet: "192.168.1.0",
})) }))
assert.False(t, criteria.MatchInclude(&SelectedNode{ assert.False(t, criteria.Match(&SelectedNode{
LastNet: "192.168.2.0", LastNet: "192.168.2.0",
})) }))
assert.True(t, criteria.MatchInclude(&SelectedNode{ assert.True(t, criteria.Match(&SelectedNode{
LastNet: "192.168.3.0", LastNet: "192.168.3.0",
})) }))
} }
@ -113,7 +113,7 @@ func TestCriteria_Geofencing(t *testing.T) {
for _, c := range cases { for _, c := range cases {
t.Run(c.name, func(t *testing.T) { t.Run(c.name, func(t *testing.T) {
assert.Equal(t, c.expected, c.criteria.MatchInclude(&SelectedNode{ assert.Equal(t, c.expected, c.criteria.Match(&SelectedNode{
CountryCode: c.country, CountryCode: c.country,
})) }))
}) })
@ -146,7 +146,7 @@ func benchmarkFilter(b *testing.B, filters NodeFilters) {
c := 0 c := 0
for j := 0; j < b.N; j++ { for j := 0; j < b.N; j++ {
for n := 0; n < len(nodes); n++ { for n := 0; n < len(nodes); n++ {
if filters.MatchInclude(nodes[n]) { if filters.Match(nodes[n]) {
c++ c++
} }
} }

View File

@ -25,7 +25,7 @@ func (nodes SelectByID) Select(n int, nodeFilter NodeFilter) []*SelectedNode {
for _, idx := range mathrand.Perm(len(nodes)) { for _, idx := range mathrand.Perm(len(nodes)) {
node := nodes[idx] node := nodes[idx]
if !nodeFilter.MatchInclude(node) { if !nodeFilter.Match(node) {
continue continue
} }
@ -83,7 +83,7 @@ func (subnets SelectBySubnet) Select(n int, filter NodeFilter) []*SelectedNode {
rs := NewRandomOrder(len(subnet.Nodes)) rs := NewRandomOrder(len(subnet.Nodes))
for rs.Next() { for rs.Next() {
if filter.MatchInclude(subnet.Nodes[rs.At()]) { if filter.Match(subnet.Nodes[rs.At()]) {
selected = append(selected, subnet.Nodes[rs.At()].Clone()) selected = append(selected, subnet.Nodes[rs.At()].Clone())
break break
} }

View File

@ -149,7 +149,7 @@ func (service *Service) CreateGetOrderLimits(ctx context.Context, bucket metabas
filter := service.placementRules(segment.Placement) filter := service.placementRules(segment.Placement)
for id, node := range nodes { for id, node := range nodes {
if !filter.MatchInclude(node) { if !filter.Match(node) {
delete(nodes, id) delete(nodes, id)
} }
} }

View File

@ -147,7 +147,7 @@ func (state *DownloadSelectionCacheState) IPs(nodes []storj.NodeID) map[storj.No
func (state *DownloadSelectionCacheState) FilteredIPs(nodes []storj.NodeID, filter nodeselection.NodeFilter) map[storj.NodeID]string { func (state *DownloadSelectionCacheState) FilteredIPs(nodes []storj.NodeID, filter nodeselection.NodeFilter) map[storj.NodeID]string {
xs := make(map[storj.NodeID]string, len(nodes)) xs := make(map[storj.NodeID]string, len(nodes))
for _, nodeID := range nodes { for _, nodeID := range nodes {
if n, exists := state.byID[nodeID]; exists && filter.MatchInclude(n) { if n, exists := state.byID[nodeID]; exists && filter.Match(n) {
xs[nodeID] = n.LastIPPort xs[nodeID] = n.LastIPPort
} }
} }

View File

@ -33,12 +33,12 @@ func TestPlacementFromString(t *testing.T) {
filters := p.placements[storj.PlacementConstraint(11)] filters := p.placements[storj.PlacementConstraint(11)]
require.NotNil(t, filters) require.NotNil(t, filters)
for _, code := range shouldBeExcluded { for _, code := range shouldBeExcluded {
require.False(t, filters.MatchInclude(&nodeselection.SelectedNode{ require.False(t, filters.Match(&nodeselection.SelectedNode{
CountryCode: code, CountryCode: code,
}), "%s shouldn't be included in placement %s", code, placementDef) }), "%s shouldn't be included in placement %s", code, placementDef)
} }
for _, code := range shouldBeIncluded { for _, code := range shouldBeIncluded {
require.True(t, filters.MatchInclude(&nodeselection.SelectedNode{ require.True(t, filters.Match(&nodeselection.SelectedNode{
CountryCode: code, CountryCode: code,
}), "%s is not included in placement %s", code, placementDef) }), "%s is not included in placement %s", code, placementDef)
} }
@ -57,7 +57,7 @@ func TestPlacementFromString(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
filters := p.placements[storj.PlacementConstraint(11)] filters := p.placements[storj.PlacementConstraint(11)]
require.NotNil(t, filters) require.NotNil(t, filters)
require.True(t, filters.MatchInclude(&nodeselection.SelectedNode{ require.True(t, filters.Match(&nodeselection.SelectedNode{
Tags: nodeselection.NodeTags{ Tags: nodeselection.NodeTags{
{ {
Signer: signer, Signer: signer,
@ -66,7 +66,7 @@ func TestPlacementFromString(t *testing.T) {
}, },
}, },
})) }))
require.False(t, filters.MatchInclude(&nodeselection.SelectedNode{ require.False(t, filters.Match(&nodeselection.SelectedNode{
CountryCode: location.Germany, CountryCode: location.Germany,
})) }))
}) })
@ -76,7 +76,7 @@ func TestPlacementFromString(t *testing.T) {
err := p.AddPlacementFromString(`1:tag("12whfK1EDvHJtajBiAUeajQLYcWqxcQmdYQU5zX5cCf6bAxfgu4","foo","bar");2:exclude(placement(1))`) err := p.AddPlacementFromString(`1:tag("12whfK1EDvHJtajBiAUeajQLYcWqxcQmdYQU5zX5cCf6bAxfgu4","foo","bar");2:exclude(placement(1))`)
require.NoError(t, err) require.NoError(t, err)
require.True(t, p.placements[storj.PlacementConstraint(1)].MatchInclude(&nodeselection.SelectedNode{ require.True(t, p.placements[storj.PlacementConstraint(1)].Match(&nodeselection.SelectedNode{
Tags: nodeselection.NodeTags{ Tags: nodeselection.NodeTags{
{ {
Signer: signer, Signer: signer,
@ -87,7 +87,7 @@ func TestPlacementFromString(t *testing.T) {
})) }))
placement2 := p.placements[storj.PlacementConstraint(2)] placement2 := p.placements[storj.PlacementConstraint(2)]
require.False(t, placement2.MatchInclude(&nodeselection.SelectedNode{ require.False(t, placement2.Match(&nodeselection.SelectedNode{
Tags: nodeselection.NodeTags{ Tags: nodeselection.NodeTags{
{ {
Signer: signer, Signer: signer,
@ -96,7 +96,7 @@ func TestPlacementFromString(t *testing.T) {
}, },
}, },
})) }))
require.True(t, placement2.MatchInclude(&nodeselection.SelectedNode{ require.True(t, placement2.Match(&nodeselection.SelectedNode{
CountryCode: location.Germany, CountryCode: location.Germany,
})) }))
@ -112,7 +112,7 @@ func TestPlacementFromString(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
filters := p.placements[storj.PlacementConstraint(11)] filters := p.placements[storj.PlacementConstraint(11)]
require.NotNil(t, filters) require.NotNil(t, filters)
require.True(t, filters.MatchInclude(&nodeselection.SelectedNode{ require.True(t, filters.Match(&nodeselection.SelectedNode{
CountryCode: location.UnitedKingdom, CountryCode: location.UnitedKingdom,
Tags: nodeselection.NodeTags{ Tags: nodeselection.NodeTags{
{ {
@ -122,10 +122,10 @@ func TestPlacementFromString(t *testing.T) {
}, },
}, },
})) }))
require.False(t, filters.MatchInclude(&nodeselection.SelectedNode{ require.False(t, filters.Match(&nodeselection.SelectedNode{
CountryCode: location.UnitedKingdom, CountryCode: location.UnitedKingdom,
})) }))
require.False(t, filters.MatchInclude(&nodeselection.SelectedNode{ require.False(t, filters.Match(&nodeselection.SelectedNode{
CountryCode: location.Germany, CountryCode: location.Germany,
Tags: nodeselection.NodeTags{ Tags: nodeselection.NodeTags{
{ {
@ -150,19 +150,19 @@ func TestPlacementFromString(t *testing.T) {
filters := p.placements[storj.PlacementConstraint(11)] filters := p.placements[storj.PlacementConstraint(11)]
require.NotNil(t, filters) require.NotNil(t, filters)
require.True(t, filters.MatchInclude(&nodeselection.SelectedNode{ require.True(t, filters.Match(&nodeselection.SelectedNode{
CountryCode: location.UnitedKingdom, CountryCode: location.UnitedKingdom,
})) }))
require.False(t, filters.MatchInclude(&nodeselection.SelectedNode{ require.False(t, filters.Match(&nodeselection.SelectedNode{
CountryCode: location.Germany, CountryCode: location.Germany,
})) }))
filters = p.placements[storj.PlacementConstraint(12)] filters = p.placements[storj.PlacementConstraint(12)]
require.NotNil(t, filters) require.NotNil(t, filters)
require.False(t, filters.MatchInclude(&nodeselection.SelectedNode{ require.False(t, filters.Match(&nodeselection.SelectedNode{
CountryCode: location.UnitedKingdom, CountryCode: location.UnitedKingdom,
})) }))
require.True(t, filters.MatchInclude(&nodeselection.SelectedNode{ require.True(t, filters.Match(&nodeselection.SelectedNode{
CountryCode: location.Germany, CountryCode: location.Germany,
})) }))
@ -175,7 +175,7 @@ func TestPlacementFromString(t *testing.T) {
err := p.AddPlacementFromString(`11:annotated(country("GB"),annotation("autoExcludeSubnet","off"))`) err := p.AddPlacementFromString(`11:annotated(country("GB"),annotation("autoExcludeSubnet","off"))`)
require.NoError(t, err) require.NoError(t, err)
filters := p.placements[storj.PlacementConstraint(11)] filters := p.placements[storj.PlacementConstraint(11)]
require.True(t, filters.MatchInclude(&nodeselection.SelectedNode{ require.True(t, filters.Match(&nodeselection.SelectedNode{
CountryCode: location.UnitedKingdom, CountryCode: location.UnitedKingdom,
})) }))
@ -188,7 +188,7 @@ func TestPlacementFromString(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
filters := p.placements[storj.PlacementConstraint(11)] filters := p.placements[storj.PlacementConstraint(11)]
require.True(t, filters.MatchInclude(&nodeselection.SelectedNode{ require.True(t, filters.Match(&nodeselection.SelectedNode{
CountryCode: location.UnitedKingdom, CountryCode: location.UnitedKingdom,
})) }))
require.Equal(t, "bar", nodeselection.GetAnnotation(filters, "foo")) require.Equal(t, "bar", nodeselection.GetAnnotation(filters, "foo"))
@ -201,7 +201,7 @@ func TestPlacementFromString(t *testing.T) {
err := p.AddPlacementFromString(`11:annotated(annotated(country("GB"),annotation("foo","bar")),annotation("bar","foo"))`) err := p.AddPlacementFromString(`11:annotated(annotated(country("GB"),annotation("foo","bar")),annotation("bar","foo"))`)
require.NoError(t, err) require.NoError(t, err)
filters := p.placements[storj.PlacementConstraint(11)] filters := p.placements[storj.PlacementConstraint(11)]
require.True(t, filters.MatchInclude(&nodeselection.SelectedNode{ require.True(t, filters.Match(&nodeselection.SelectedNode{
CountryCode: location.UnitedKingdom, CountryCode: location.UnitedKingdom,
})) }))
@ -214,7 +214,7 @@ func TestPlacementFromString(t *testing.T) {
s := fmt.Sprintf(`11:annotated(annotated(country("GB"),annotation("%s","test-location")),annotation("%s","%s"))`, nodeselection.Location, nodeselection.AutoExcludeSubnet, nodeselection.AutoExcludeSubnetOFF) s := fmt.Sprintf(`11:annotated(annotated(country("GB"),annotation("%s","test-location")),annotation("%s","%s"))`, nodeselection.Location, nodeselection.AutoExcludeSubnet, nodeselection.AutoExcludeSubnetOFF)
require.NoError(t, p.AddPlacementFromString(s)) require.NoError(t, p.AddPlacementFromString(s))
filters := p.placements[storj.PlacementConstraint(11)] filters := p.placements[storj.PlacementConstraint(11)]
require.True(t, filters.MatchInclude(&nodeselection.SelectedNode{ require.True(t, filters.Match(&nodeselection.SelectedNode{
CountryCode: location.UnitedKingdom, CountryCode: location.UnitedKingdom,
})) }))
@ -228,10 +228,10 @@ func TestPlacementFromString(t *testing.T) {
err := p.AddPlacementFromString(`11:exclude(country("GB"))`) err := p.AddPlacementFromString(`11:exclude(country("GB"))`)
require.NoError(t, err) require.NoError(t, err)
filters := p.placements[storj.PlacementConstraint(11)] filters := p.placements[storj.PlacementConstraint(11)]
require.False(t, filters.MatchInclude(&nodeselection.SelectedNode{ require.False(t, filters.Match(&nodeselection.SelectedNode{
CountryCode: location.UnitedKingdom, CountryCode: location.UnitedKingdom,
})) }))
require.True(t, filters.MatchInclude(&nodeselection.SelectedNode{ require.True(t, filters.Match(&nodeselection.SelectedNode{
CountryCode: location.Germany, CountryCode: location.Germany,
})) }))
}) })
@ -242,25 +242,25 @@ func TestPlacementFromString(t *testing.T) {
t.Run("nr", func(t *testing.T) { t.Run("nr", func(t *testing.T) {
nr := p.placements[storj.NR] nr := p.placements[storj.NR]
require.True(t, nr.MatchInclude(&nodeselection.SelectedNode{ require.True(t, nr.Match(&nodeselection.SelectedNode{
CountryCode: location.UnitedKingdom, CountryCode: location.UnitedKingdom,
})) }))
require.False(t, nr.MatchInclude(&nodeselection.SelectedNode{ require.False(t, nr.Match(&nodeselection.SelectedNode{
CountryCode: location.Russia, CountryCode: location.Russia,
})) }))
require.False(t, nr.MatchInclude(&nodeselection.SelectedNode{ require.False(t, nr.Match(&nodeselection.SelectedNode{
CountryCode: 0, CountryCode: 0,
})) }))
}) })
t.Run("us", func(t *testing.T) { t.Run("us", func(t *testing.T) {
us := p.placements[storj.US] us := p.placements[storj.US]
require.True(t, us.MatchInclude(&nodeselection.SelectedNode{ require.True(t, us.Match(&nodeselection.SelectedNode{
CountryCode: location.UnitedStates, CountryCode: location.UnitedStates,
})) }))
require.False(t, us.MatchInclude(&nodeselection.SelectedNode{ require.False(t, us.Match(&nodeselection.SelectedNode{
CountryCode: location.Germany, CountryCode: location.Germany,
})) }))
require.False(t, us.MatchInclude(&nodeselection.SelectedNode{ require.False(t, us.Match(&nodeselection.SelectedNode{
CountryCode: 0, CountryCode: 0,
})) }))
}) })
@ -305,10 +305,10 @@ func TestPlacementFromString(t *testing.T) {
filter2 := rules2.CreateFilters(placement) filter2 := rules2.CreateFilters(placement)
for _, country := range testCountries { for _, country := range testCountries {
old := placement.AllowedCountry(country) old := placement.AllowedCountry(country)
result1 := filter1.MatchInclude(&nodeselection.SelectedNode{ result1 := filter1.Match(&nodeselection.SelectedNode{
CountryCode: country, CountryCode: country,
}) })
result2 := filter2.MatchInclude(&nodeselection.SelectedNode{ result2 := filter2.Match(&nodeselection.SelectedNode{
CountryCode: country, CountryCode: country,
}) })
assert.Equal(t, old, result1, "old placement doesn't match string based configuration for placement %d and country %s", placement, country) assert.Equal(t, old, result1, "old placement doesn't match string based configuration for placement %d and country %s", placement, country)
@ -317,8 +317,8 @@ func TestPlacementFromString(t *testing.T) {
} }
// make sure that new rules exclude location.None from NR // make sure that new rules exclude location.None from NR
assert.False(t, rules1.CreateFilters(storj.NR).MatchInclude(&nodeselection.SelectedNode{})) assert.False(t, rules1.CreateFilters(storj.NR).Match(&nodeselection.SelectedNode{}))
assert.False(t, rules2.CreateFilters(storj.NR).MatchInclude(&nodeselection.SelectedNode{})) assert.False(t, rules2.CreateFilters(storj.NR).Match(&nodeselection.SelectedNode{}))
// make sure tagged nodes (even from EU) matches only the special placement // make sure tagged nodes (even from EU) matches only the special placement
node := &nodeselection.SelectedNode{ node := &nodeselection.SelectedNode{
@ -333,9 +333,9 @@ func TestPlacementFromString(t *testing.T) {
} }
for _, placement := range []storj.PlacementConstraint{storj.EveryCountry, storj.EU, storj.EEA, storj.DE, storj.US, storj.NR} { for _, placement := range []storj.PlacementConstraint{storj.EveryCountry, storj.EU, storj.EEA, storj.DE, storj.US, storj.NR} {
assert.False(t, rules1.CreateFilters(placement).MatchInclude(node)) assert.False(t, rules1.CreateFilters(placement).Match(node))
} }
assert.False(t, rules1.CreateFilters(6).MatchInclude(node)) assert.False(t, rules1.CreateFilters(6).Match(node))
// check if annotation present on 11,12, but not on other // check if annotation present on 11,12, but not on other
for i := 0; i < 20; i++ { for i := 0; i < 20; i++ {

View File

@ -109,7 +109,7 @@ func (cache *ReliabilityCache) OutOfPlacementPieces(ctx context.Context, created
var outOfPlacementPieces metabase.Pieces var outOfPlacementPieces metabase.Pieces
nodeFilters := cache.placementRules(placement) nodeFilters := cache.placementRules(placement)
for _, p := range pieces { for _, p := range pieces {
if node, ok := state.reliableAll[p.StorageNode]; ok && !nodeFilters.MatchInclude(&node) { if node, ok := state.reliableAll[p.StorageNode]; ok && !nodeFilters.Match(&node) {
outOfPlacementPieces = append(outOfPlacementPieces, p) outOfPlacementPieces = append(outOfPlacementPieces, p)
} }
} }

View File

@ -694,7 +694,7 @@ func (repairer *SegmentRepairer) classifySegmentPiecesWithNodes(ctx context.Cont
for _, onlineNode := range online { for _, onlineNode := range online {
// count online nodes in excluded countries only if country is not excluded by segment // count online nodes in excluded countries only if country is not excluded by segment
// placement, those nodes will be counted with out of placement check // placement, those nodes will be counted with out of placement check
if _, excluded := repairer.excludedCountryCodes[onlineNode.CountryCode]; excluded && nodeFilters.MatchInclude(&onlineNode) { if _, excluded := repairer.excludedCountryCodes[onlineNode.CountryCode]; excluded && nodeFilters.Match(&onlineNode) {
result.NumHealthyInExcludedCountries++ result.NumHealthyInExcludedCountries++
} }
@ -736,7 +736,7 @@ func (repairer *SegmentRepairer) classifySegmentPiecesWithNodes(ctx context.Cont
if repairer.doPlacementCheck { if repairer.doPlacementCheck {
checkPlacement := func(reliable []nodeselection.SelectedNode) { checkPlacement := func(reliable []nodeselection.SelectedNode) {
for _, node := range reliable { for _, node := range reliable {
if nodeFilters.MatchInclude(&node) { if nodeFilters.Match(&node) {
continue continue
} }

View File

@ -522,7 +522,7 @@ func allPiecesInPlacement(ctx context.Context, overaly *overlay.Service, pieces
Tags: tags, Tags: tags,
} }
if !filter.MatchInclude(node) { if !filter.Match(node) {
return false, nil return false, nil
} }
} }