Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mutable stringset memory usage #6669

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/store/bucket_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ func TestBucketStore_LabelNamesSet_e2e(t *testing.T) {
for _, n := range []string{"a", "b", "c"} {
testutil.Assert(t, filter.Has(n), "expected filter to have %s", n)
}
testutil.Equals(t, 3, filter.Count())
})
}

Expand Down
18 changes: 17 additions & 1 deletion pkg/stringset/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
type Set interface {
Has(string) bool
HasAny([]string) bool
// Count returns the number of elements in the set.
// A value of -1 indicates infinite size and can be returned by a
// set representing all possible string values.
Count() int
}

type fixedSet struct {
Expand Down Expand Up @@ -38,6 +42,10 @@ func (f fixedSet) Has(s string) bool {
return f.cuckoo.Lookup([]byte(s))
}

func (f fixedSet) Count() int {
return int(f.cuckoo.Count())
}

type mutableSet struct {
cuckoo *cuckoo.ScalableCuckooFilter
}
Expand All @@ -54,7 +62,7 @@ func New() MutableSet {
}

func (e mutableSet) Insert(s string) {
e.cuckoo.Insert([]byte(s))
e.cuckoo.InsertUnique([]byte(s))
}

func (e mutableSet) Has(s string) bool {
Expand All @@ -70,6 +78,10 @@ func (e mutableSet) HasAny(strings []string) bool {
return false
}

func (e mutableSet) Count() int {
return int(e.cuckoo.Count())
}

type allStringsSet struct{}

func (e allStringsSet) HasAny(_ []string) bool {
Expand All @@ -83,3 +95,7 @@ func AllStrings() *allStringsSet {
func (e allStringsSet) Has(_ string) bool {
return true
}

func (e allStringsSet) Count() int {
return -1
}
Loading