Skip to content
This repository was archived by the owner on Aug 13, 2019. It is now read-only.

Commit 0861a9b

Browse files
naivewongcodesome
authored andcommitted
[bugfix] update 'last' variable in chunks.MergeOverlappingChunks() (#539)
* update Signed-off-by: naivewong <[email protected]> * update comment Signed-off-by: naivewong <[email protected]> * Update failing test. Signed-off-by: naivewong <[email protected]> * Update comment Signed-off-by: naivewong <[email protected]> * Add changelog entry. Signed-off-by: naivewong <[email protected]> * Update CHANGELOG.md Signed-off-by: Ganesh Vernekar <[email protected]>
1 parent 08af7bb commit 0861a9b

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## master / unreleased
2+
- [BUGFIX] Update `last` after appending a non-overlapping chunk in `chunks.MergeOverlappingChunks`. [#539](https://github.com/prometheus/tsdb/pull/539)
23

34
## 0.6.0
45
- [CHANGE] `AllowOverlappingBlock` is now `AllowOverlappingBlocks`.

Diff for: chunks/chunks.go

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ func MergeOverlappingChunks(chks []Meta) ([]Meta, error) {
213213
// So never overlaps with newChks[last-1] or anything before that.
214214
if c.MinTime > newChks[last].MaxTime {
215215
newChks = append(newChks, c)
216+
last += 1
216217
continue
217218
}
218219
nc := &newChks[last]

Diff for: compact_test.go

+49-2
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,8 @@ func TestCompaction_populateBlock(t *testing.T) {
653653
expErr: errors.New("found chunk with minTime: 10 maxTime: 20 outside of compacted minTime: 0 maxTime: 10"),
654654
},
655655
{
656-
// No special deduplication expected.
656+
// Deduplication expected.
657+
// Introduced by pull/370 and pull/539.
657658
title: "Populate from two blocks containing duplicated chunk.",
658659
inputSeriesSamples: [][]seriesSamples{
659660
{
@@ -672,7 +673,53 @@ func TestCompaction_populateBlock(t *testing.T) {
672673
expSeriesSamples: []seriesSamples{
673674
{
674675
lset: map[string]string{"a": "b"},
675-
chunks: [][]sample{{{t: 1}, {t: 2}}, {{t: 10}, {t: 20}}, {{t: 10}, {t: 20}}},
676+
chunks: [][]sample{{{t: 1}, {t: 2}}, {{t: 10}, {t: 20}}},
677+
},
678+
},
679+
},
680+
{
681+
// Introduced by https://github.com/prometheus/tsdb/pull/539.
682+
title: "Populate from three blocks that the last two are overlapping.",
683+
inputSeriesSamples: [][]seriesSamples{
684+
{
685+
{
686+
lset: map[string]string{"before": "fix"},
687+
chunks: [][]sample{{{t: 0}, {t: 10}, {t: 11}, {t: 20}}},
688+
},
689+
{
690+
lset: map[string]string{"after": "fix"},
691+
chunks: [][]sample{{{t: 0}, {t: 10}, {t: 11}, {t: 20}}},
692+
},
693+
},
694+
{
695+
{
696+
lset: map[string]string{"before": "fix"},
697+
chunks: [][]sample{{{t: 19}, {t: 30}}},
698+
},
699+
{
700+
lset: map[string]string{"after": "fix"},
701+
chunks: [][]sample{{{t: 21}, {t: 30}}},
702+
},
703+
},
704+
{
705+
{
706+
lset: map[string]string{"before": "fix"},
707+
chunks: [][]sample{{{t: 27}, {t: 35}}},
708+
},
709+
{
710+
lset: map[string]string{"after": "fix"},
711+
chunks: [][]sample{{{t: 27}, {t: 35}}},
712+
},
713+
},
714+
},
715+
expSeriesSamples: []seriesSamples{
716+
{
717+
lset: map[string]string{"after": "fix"},
718+
chunks: [][]sample{{{t: 0}, {t: 10}, {t: 11}, {t: 20}}, {{t: 21}, {t: 27}, {t: 30}, {t: 35}}},
719+
},
720+
{
721+
lset: map[string]string{"before": "fix"},
722+
chunks: [][]sample{{{t: 0}, {t: 10}, {t: 11}, {t: 19}, {t: 20}, {t: 27}, {t: 30}, {t: 35}}},
676723
},
677724
},
678725
},

0 commit comments

Comments
 (0)