|
|
@ -973,37 +973,69 @@ func TestMemPostingsStats(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestMemPostings_Delete(t *testing.T) { |
|
|
|
func TestMemPostings_Delete(t *testing.T) { |
|
|
|
p := NewMemPostings() |
|
|
|
t.Run("some postings", func(t *testing.T) { |
|
|
|
p.Add(1, labels.FromStrings("lbl1", "a")) |
|
|
|
p := NewMemPostings() |
|
|
|
p.Add(2, labels.FromStrings("lbl1", "b")) |
|
|
|
p.Add(1, labels.FromStrings("lbl1", "a")) |
|
|
|
p.Add(3, labels.FromStrings("lbl2", "a")) |
|
|
|
p.Add(2, labels.FromStrings("lbl1", "b")) |
|
|
|
|
|
|
|
p.Add(3, labels.FromStrings("lbl2", "a")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before := p.Get(allPostingsKey.Name, allPostingsKey.Value) |
|
|
|
|
|
|
|
deletedRefs := map[storage.SeriesRef]struct{}{ |
|
|
|
|
|
|
|
2: {}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
affectedLabels := map[labels.Label]struct{}{ |
|
|
|
|
|
|
|
{Name: "lbl1", Value: "b"}: {}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
p.Delete(deletedRefs, affectedLabels) |
|
|
|
|
|
|
|
after := p.Get(allPostingsKey.Name, allPostingsKey.Value) |
|
|
|
|
|
|
|
|
|
|
|
before := p.Get(allPostingsKey.Name, allPostingsKey.Value) |
|
|
|
// Make sure postings gotten before the delete have the old data when
|
|
|
|
deletedRefs := map[storage.SeriesRef]struct{}{ |
|
|
|
// iterated over.
|
|
|
|
2: {}, |
|
|
|
expanded, err := ExpandPostings(before) |
|
|
|
} |
|
|
|
require.NoError(t, err) |
|
|
|
affectedLabels := map[labels.Label]struct{}{ |
|
|
|
require.Equal(t, []storage.SeriesRef{1, 2, 3}, expanded) |
|
|
|
{Name: "lbl1", Value: "b"}: {}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
p.Delete(deletedRefs, affectedLabels) |
|
|
|
|
|
|
|
after := p.Get(allPostingsKey.Name, allPostingsKey.Value) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure postings gotten before the delete have the old data when
|
|
|
|
// Make sure postings gotten after the delete have the new data when
|
|
|
|
// iterated over.
|
|
|
|
// iterated over.
|
|
|
|
expanded, err := ExpandPostings(before) |
|
|
|
expanded, err = ExpandPostings(after) |
|
|
|
require.NoError(t, err) |
|
|
|
require.NoError(t, err) |
|
|
|
require.Equal(t, []storage.SeriesRef{1, 2, 3}, expanded) |
|
|
|
require.Equal(t, []storage.SeriesRef{1, 3}, expanded) |
|
|
|
|
|
|
|
|
|
|
|
// Make sure postings gotten after the delete have the new data when
|
|
|
|
deleted := p.Get("lbl1", "b") |
|
|
|
// iterated over.
|
|
|
|
expanded, err = ExpandPostings(deleted) |
|
|
|
expanded, err = ExpandPostings(after) |
|
|
|
require.NoError(t, err) |
|
|
|
require.NoError(t, err) |
|
|
|
require.Empty(t, expanded, "expected empty postings, got %v", expanded) |
|
|
|
require.Equal(t, []storage.SeriesRef{1, 3}, expanded) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
deleted := p.Get("lbl1", "b") |
|
|
|
t.Run("all postings", func(t *testing.T) { |
|
|
|
expanded, err = ExpandPostings(deleted) |
|
|
|
p := NewMemPostings() |
|
|
|
require.NoError(t, err) |
|
|
|
p.Add(1, labels.FromStrings("lbl1", "a")) |
|
|
|
require.Empty(t, expanded, "expected empty postings, got %v", expanded) |
|
|
|
p.Add(2, labels.FromStrings("lbl1", "b")) |
|
|
|
|
|
|
|
p.Add(3, labels.FromStrings("lbl2", "a")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deletedRefs := map[storage.SeriesRef]struct{}{1: {}, 2: {}, 3: {}} |
|
|
|
|
|
|
|
affectedLabels := map[labels.Label]struct{}{ |
|
|
|
|
|
|
|
{Name: "lbl1", Value: "a"}: {}, |
|
|
|
|
|
|
|
{Name: "lbl1", Value: "b"}: {}, |
|
|
|
|
|
|
|
{Name: "lbl1", Value: "c"}: {}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
p.Delete(deletedRefs, affectedLabels) |
|
|
|
|
|
|
|
after := p.Get(allPostingsKey.Name, allPostingsKey.Value) |
|
|
|
|
|
|
|
expanded, err := ExpandPostings(after) |
|
|
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
require.Empty(t, expanded) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("nothing on empty mempostings", func(t *testing.T) { |
|
|
|
|
|
|
|
p := NewMemPostings() |
|
|
|
|
|
|
|
deletedRefs := map[storage.SeriesRef]struct{}{} |
|
|
|
|
|
|
|
affectedLabels := map[labels.Label]struct{}{} |
|
|
|
|
|
|
|
p.Delete(deletedRefs, affectedLabels) |
|
|
|
|
|
|
|
after := p.Get(allPostingsKey.Name, allPostingsKey.Value) |
|
|
|
|
|
|
|
expanded, err := ExpandPostings(after) |
|
|
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
require.Empty(t, expanded) |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// BenchmarkMemPostings_Delete is quite heavy, so consider running it with
|
|
|
|
// BenchmarkMemPostings_Delete is quite heavy, so consider running it with
|
|
|
@ -1025,7 +1057,7 @@ func BenchmarkMemPostings_Delete(b *testing.B) { |
|
|
|
return s |
|
|
|
return s |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const total = 1e6 |
|
|
|
const total = 2e6 |
|
|
|
allSeries := [total]labels.Labels{} |
|
|
|
allSeries := [total]labels.Labels{} |
|
|
|
nameValues := make([]string, 0, 100) |
|
|
|
nameValues := make([]string, 0, 100) |
|
|
|
for i := 0; i < total; i++ { |
|
|
|
for i := 0; i < total; i++ { |
|
|
|