Skip to content

Commit

Permalink
Merge pull request #72 from DataDog/cmasson/fix_merge_with_after_clear
Browse files Browse the repository at this point in the history
Fix merge after clear in the buffered paginated store
  • Loading branch information
CharlesMasson authored Apr 19, 2023
2 parents 8a1961c + c6dc109 commit 3b624d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ddsketch/store/buffered_paginated.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ func (s *BufferedPaginatedStore) MergeWith(other Store) {
if ok && s.pageLenLog2 == o.pageLenLog2 {
// Merge pages.
for oPageOffset, oPage := range o.pages {
if len(oPage) == 0 {
continue
}
oPageIndex := o.minPageIndex + oPageOffset
page := s.page(oPageIndex, true)
for i, oCount := range oPage {
Expand Down
17 changes: 17 additions & 0 deletions ddsketch/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,23 @@ func TestMergeFuzzy(t *testing.T) {
}
}

func TestMergeAfterClear(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
s1 := testCase.newStore()
s2 := testCase.newStore()

for i := 0; i < 1000; i++ {
s2.Add(i)
}
s2.Clear()

s1.MergeWith(s2)
s2.MergeWith(s1)
})
}
}

func testStore(t *testing.T, store Store, normalizedBins []Bin) {
assertEncodeBins(t, store, normalizedBins)
testCopy(t, store, normalizedBins)
Expand Down

0 comments on commit 3b624d1

Please sign in to comment.