Skip to content

Commit

Permalink
satellite/nodeselection: rename (NodeFilter).MatchInclude to Match
Browse files Browse the repository at this point in the history
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 5522423, where we removed the only one stateful filter.

Change-Id: I7c36ddadb2defbfa3b6b67bcc115e4427ba9e083
  • Loading branch information
elek committed Aug 31, 2023
1 parent dcc4bd0 commit c202929
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 75 deletions.
56 changes: 28 additions & 28 deletions satellite/nodeselection/filter.go
Expand Up @@ -12,7 +12,7 @@ import (

// NodeFilter can decide if a Node should be part of the selection or not.
type NodeFilter interface {
MatchInclude(node *SelectedNode) bool
Match(node *SelectedNode) bool
}

// NodeFilterWithAnnotation is a NodeFilter with additional annotations.
Expand All @@ -27,8 +27,8 @@ type Annotation struct {
Value string
}

// MatchInclude implements NodeFilter.
func (a Annotation) MatchInclude(node *SelectedNode) bool {
// Match implements NodeFilter.
func (a Annotation) Match(node *SelectedNode) bool {
return true
}

Expand Down Expand Up @@ -61,9 +61,9 @@ func (a AnnotatedNodeFilter) GetAnnotation(name string) string {
return ""
}

// MatchInclude implements NodeFilter.
func (a AnnotatedNodeFilter) MatchInclude(node *SelectedNode) bool {
return a.Filter.MatchInclude(node)
// Match implements NodeFilter.
func (a AnnotatedNodeFilter) Match(node *SelectedNode) bool {
return a.Filter.Match(node)
}

// WithAnnotation adds annotations to a NodeFilter.
Expand Down Expand Up @@ -95,21 +95,21 @@ type NodeFilters []NodeFilter
// NodeFilterFunc is helper to use func as NodeFilter.
type NodeFilterFunc func(node *SelectedNode) bool

// MatchInclude implements NodeFilter interface.
func (n NodeFilterFunc) MatchInclude(node *SelectedNode) bool {
// Match implements NodeFilter interface.
func (n NodeFilterFunc) Match(node *SelectedNode) bool {
return n(node)
}

// ExcludeAllFilter will never select any node.
type ExcludeAllFilter struct{}

// MatchInclude implements NodeFilter interface.
func (ExcludeAllFilter) MatchInclude(node *SelectedNode) bool { return false }
// Match implements NodeFilter interface.
func (ExcludeAllFilter) Match(node *SelectedNode) bool { return false }

// MatchInclude implements NodeFilter interface.
func (n NodeFilters) MatchInclude(node *SelectedNode) bool {
// Match implements NodeFilter interface.
func (n NodeFilters) Match(node *SelectedNode) bool {
for _, filter := range n {
if !filter.MatchInclude(node) {
if !filter.Match(node) {
return false
}
}
Expand Down Expand Up @@ -153,8 +153,8 @@ func NewCountryFilter(permit location.Set) NodeFilter {
}
}

// MatchInclude implements NodeFilter interface.
func (p *CountryFilter) MatchInclude(node *SelectedNode) bool {
// Match implements NodeFilter interface.
func (p *CountryFilter) Match(node *SelectedNode) bool {
return p.permit.Contains(node.CountryCode)
}

Expand All @@ -163,8 +163,8 @@ var _ NodeFilter = &CountryFilter{}
// ExcludedNetworks will exclude nodes with specified networks.
type ExcludedNetworks []string

// MatchInclude implements NodeFilter interface.
func (e ExcludedNetworks) MatchInclude(node *SelectedNode) bool {
// Match implements NodeFilter interface.
func (e ExcludedNetworks) Match(node *SelectedNode) bool {
for _, id := range e {
if id == node.LastNet {
return false
Expand All @@ -178,8 +178,8 @@ var _ NodeFilter = ExcludedNetworks{}
// ExcludedNodeNetworks exclude nodes which has same net as the one of the specified.
type ExcludedNodeNetworks []*SelectedNode

// MatchInclude implements NodeFilter interface.
func (e ExcludedNodeNetworks) MatchInclude(node *SelectedNode) bool {
// Match implements NodeFilter interface.
func (e ExcludedNodeNetworks) Match(node *SelectedNode) bool {
for _, n := range e {
if node.LastNet == n.LastNet {
return false
Expand All @@ -193,8 +193,8 @@ var _ NodeFilter = ExcludedNodeNetworks{}
// ExcludedIDs can blacklist NodeIDs.
type ExcludedIDs []storj.NodeID

// MatchInclude implements NodeFilter interface.
func (e ExcludedIDs) MatchInclude(node *SelectedNode) bool {
// Match implements NodeFilter interface.
func (e ExcludedIDs) Match(node *SelectedNode) bool {
for _, id := range e {
if id == node.ID {
return false
Expand All @@ -221,8 +221,8 @@ func NewTagFilter(id storj.NodeID, name string, value []byte) TagFilter {
}
}

// MatchInclude implements NodeFilter interface.
func (t TagFilter) MatchInclude(node *SelectedNode) bool {
// Match implements NodeFilter interface.
func (t TagFilter) Match(node *SelectedNode) bool {
for _, tag := range node.Tags {
if tag.Name == t.name && bytes.Equal(tag.Value, t.value) && tag.Signer == t.signer {
return true
Expand All @@ -238,9 +238,9 @@ type ExcludeFilter struct {
matchToExclude NodeFilter
}

// MatchInclude implements NodeFilter interface.
func (e ExcludeFilter) MatchInclude(node *SelectedNode) bool {
return !e.matchToExclude.MatchInclude(node)
// Match implements NodeFilter interface.
func (e ExcludeFilter) Match(node *SelectedNode) bool {
return !e.matchToExclude.Match(node)
}

// NewExcludeFilter creates filter, nodes matching the given filter will be excluded.
Expand All @@ -255,8 +255,8 @@ var _ NodeFilter = ExcludeFilter{}
// AnyFilter matches all the nodes.
type AnyFilter struct{}

// MatchInclude implements NodeFilter interface.
func (a AnyFilter) MatchInclude(node *SelectedNode) bool {
// Match implements NodeFilter interface.
func (a AnyFilter) Match(node *SelectedNode) bool {
return true
}

Expand Down
14 changes: 7 additions & 7 deletions satellite/nodeselection/filter_test.go
Expand Up @@ -23,11 +23,11 @@ func TestCriteria_ExcludeNodeID(t *testing.T) {

criteria := NodeFilters{}.WithExcludedIDs([]storj.NodeID{excluded})

assert.False(t, criteria.MatchInclude(&SelectedNode{
assert.False(t, criteria.Match(&SelectedNode{
ID: excluded,
}))

assert.True(t, criteria.MatchInclude(&SelectedNode{
assert.True(t, criteria.Match(&SelectedNode{
ID: included,
}))
}
Expand All @@ -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",
}))

assert.False(t, criteria.MatchInclude(&SelectedNode{
assert.False(t, criteria.Match(&SelectedNode{
LastNet: "192.168.2.0",
}))

assert.True(t, criteria.MatchInclude(&SelectedNode{
assert.True(t, criteria.Match(&SelectedNode{
LastNet: "192.168.3.0",
}))
}
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestCriteria_Geofencing(t *testing.T) {

for _, c := range cases {
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,
}))
})
Expand Down Expand Up @@ -146,7 +146,7 @@ func benchmarkFilter(b *testing.B, filters NodeFilters) {
c := 0
for j := 0; j < b.N; j++ {
for n := 0; n < len(nodes); n++ {
if filters.MatchInclude(nodes[n]) {
if filters.Match(nodes[n]) {
c++
}
}
Expand Down
4 changes: 2 additions & 2 deletions satellite/nodeselection/selector.go
Expand Up @@ -25,7 +25,7 @@ func (nodes SelectByID) Select(n int, nodeFilter NodeFilter) []*SelectedNode {
for _, idx := range mathrand.Perm(len(nodes)) {
node := nodes[idx]

if !nodeFilter.MatchInclude(node) {
if !nodeFilter.Match(node) {
continue
}

Expand Down Expand Up @@ -83,7 +83,7 @@ func (subnets SelectBySubnet) Select(n int, filter NodeFilter) []*SelectedNode {

rs := NewRandomOrder(len(subnet.Nodes))
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())
break
}
Expand Down
2 changes: 1 addition & 1 deletion satellite/orders/service.go
Expand Up @@ -149,7 +149,7 @@ func (service *Service) CreateGetOrderLimits(ctx context.Context, bucket metabas

filter := service.placementRules(segment.Placement)
for id, node := range nodes {
if !filter.MatchInclude(node) {
if !filter.Match(node) {
delete(nodes, id)
}
}
Expand Down
2 changes: 1 addition & 1 deletion satellite/overlay/downloadselection.go
Expand Up @@ -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 {
xs := make(map[storj.NodeID]string, len(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
}
}
Expand Down

0 comments on commit c202929

Please sign in to comment.