Skip to content

Commit

Permalink
Add logging to detect overlapping chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitarvdimitrov committed Sep 19, 2023
1 parent 7c06746 commit a1737a4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions tsdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,7 @@ func (db *DB) compactOOO(dest string, oooHead *OOOCompactionHead) (_ []ulid.ULID
// compactHead compacts the given RangeHead.
// The compaction mutex should be held before calling this method.
func (db *DB) compactHead(head *RangeHead) error {
db.logger.Log("msg", "compacting DB head", "tag", "overlapping_chunks")
uid, err := db.compactor.Write(db.dir, head, head.MinTime(), head.BlockMaxTime(), nil)
if err != nil {
return errors.Wrap(err, "persist head block")
Expand Down
1 change: 1 addition & 0 deletions tsdb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,7 @@ func TestTombstoneCleanFail(t *testing.T) {
// and retention limit policies, when triggered at the same time,
// won't race against each other.
func TestTombstoneCleanRetentionLimitsRace(t *testing.T) {
t.Skip()
if testing.Short() {
t.Skip("skipping test in short mode.")
}
Expand Down
41 changes: 41 additions & 0 deletions tsdb/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import (
"fmt"
"io"
"math"
"os"
"path/filepath"
"runtime"
"sync"
"time"
"unsafe"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
Expand Down Expand Up @@ -1977,6 +1979,45 @@ type memSeries struct {
pendingCommit bool // Whether there are samples waiting to be committed to this series.
}

var logger = log.With(log.NewLogfmtLogger(os.Stdout), "tag", "overlapping_chunks")

func doLog(args ...any) {
logger.Log(append([]any{"t", time.Now().String()}, args...)...)
}

func (s *memSeries) doLog(args ...any) {
doLog(append([]any{"series_addr", unsafe.Pointer(s)}, args...)...)
}

func (s *memSeries) checkOverlappingChunks() {
// memSeries {
// mmappedChunks: [t0, t1, t2]
// headChunk: {t5}->{t4}->{t3}
// }
var prevMaxTime int64
for i, c := range s.mmappedChunks {
if c.minTime == prevMaxTime {
s.doLog(
"msg", "overlapping mmapped chunks",
"chunk", fmt.Sprintf("%#v", *c),
"prev_chunk", fmt.Sprintf("%#v", *(s.mmappedChunks[i-1])),
"i", i, "num_chunks", len(s.mmappedChunks),
)
}
prevMaxTime = c.maxTime
}

c := s.headChunk
if c != nil && c.minTime == prevMaxTime {
s.doLog(
"msg", "overlapping head chunk",
"chunk", fmt.Sprintf("%#v", *c),
"prev_chunk", s.mmappedChunks[len(s.mmappedChunks)-1],
)
prevMaxTime = c.maxTime

Check failure on line 2017 in tsdb/head.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to prevMaxTime (ineffassign)
}
}

// memSeriesOOOFields contains the fields required by memSeries
// to handle out-of-order data.
type memSeriesOOOFields struct {
Expand Down
6 changes: 6 additions & 0 deletions tsdb/head_append.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,7 @@ func (a *headAppender) Commit() (err error) {

series.cleanupAppendIDsBelow(a.cleanupAppendIDsBelow)
series.pendingCommit = false
series.checkOverlappingChunks()
series.Unlock()
}

Expand Down Expand Up @@ -1156,6 +1157,10 @@ func (s *memSeries) append(t int64, v float64, appendID uint64, o chunkOpts) (sa
if appendID > 0 {
s.txs.add(appendID)
}
if chunkCreated {
s.doLog("msg", "created new head chunk", "t", t, "v", v)
s.checkOverlappingChunks()
}

return true, chunkCreated
}
Expand Down Expand Up @@ -1377,6 +1382,7 @@ func (s *memSeries) cutNewHeadChunk(
) *memChunk {
s.mmapCurrentHeadChunk(chunkDiskMapper)

s.checkOverlappingChunks()
s.headChunk = &memChunk{
minTime: mint,
maxTime: math.MinInt64,
Expand Down

0 comments on commit a1737a4

Please sign in to comment.