Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhall07 committed Dec 1, 2021
1 parent da75b53 commit aeb82ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/cmd/services/m3coordinator/downsample/id_pool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,22 @@ func (p *rollupIDProvider) reset(
newName []byte,
tagPairs []id.TagPair,
) {
p.index = 0
p.mergeTagsIdx = 0
p.newName = newName
p.tagPairs = tagPairs
p.currIdx = -1
p.Rewind()

var dups int
// precompute the length of the "combined" slice for the Len() method.
// mergeTags is small so it's fine to do n^2 instead of a more complicated O(n) merge scan.
for i := range p.tagPairs {
for j := range p.mergeTags {
for j := range p.mergeTags {
// update the name tag as well.
if bytes.Compare(p.mergeTags[j].Name, p.nameTagBytes) == 0 {
p.mergeTags[j].Value = newName
}
for i := range p.tagPairs {
if bytes.Compare(p.tagPairs[i].Name, p.mergeTags[j].Name) == 0 {
dups++
}
if bytes.Compare(p.mergeTags[j].Name, p.nameTagBytes) == 0 {
p.mergeTags[j].Value = newName
}
}
}
p.len = len(p.tagPairs) + len(p.mergeTags) - dups
Expand Down Expand Up @@ -221,7 +220,7 @@ func (p *rollupIDProvider) Len() int {
}

func (p *rollupIDProvider) Remaining() int {
return p.Len() - p.index - 1
return p.Len() - p.CurrentIndex() - 1
}

func (p *rollupIDProvider) Duplicate() ident.TagIterator {
Expand All @@ -231,7 +230,9 @@ func (p *rollupIDProvider) Duplicate() ident.TagIterator {
}

func (p *rollupIDProvider) Rewind() {
p.index = -1
p.index = 0
p.mergeTagsIdx = 0
p.currIdx = -1
}

type rollupIDProviderPool struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,13 @@ func TestRollupIdProvider(t *testing.T) {
p.reset([]byte(tc.metricName), tc.tags)
require.Equal(t, len(tc.expectedTags), p.Len())
curIdx := 0
for p.Next() {
require.Equal(t, curIdx, p.CurrentIndex())
curIdx++
require.Equal(t, p.Len()-curIdx, p.Remaining())
}
p.Rewind()
curIdx = 0
for p.Next() {
require.Equal(t, curIdx, p.CurrentIndex())
curIdx++
Expand Down

0 comments on commit aeb82ea

Please sign in to comment.