From 137a28d82b78ac0e1abc156d18e57b7efc08bb6e Mon Sep 17 00:00:00 2001 From: Owen Diehl Date: Thu, 17 Feb 2022 10:14:07 -0500 Subject: [PATCH] Adds bytes and entries to chunk metadata in tsdb (#5414) * adds bytes and entries to chunk metadata in tsdb * removes comment --- pkg/storage/tsdb/index/chunk.go | 11 +++++++++-- pkg/storage/tsdb/index/index.go | 12 ++++++++++++ pkg/storage/tsdb/querier_test.go | 12 ++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/pkg/storage/tsdb/index/chunk.go b/pkg/storage/tsdb/index/chunk.go index cb4cc3d45e..509b6fd4fb 100644 --- a/pkg/storage/tsdb/index/chunk.go +++ b/pkg/storage/tsdb/index/chunk.go @@ -4,7 +4,14 @@ package index type ChunkMeta struct { Checksum uint32 - // Time range the data covers. - // When MaxTime == math.MaxInt64 the chunk is still open and being appended to. MinTime, MaxTime int64 + + // Bytes use an uint64 as an uint32 can only hold [0,4GB) + // While this is well within current chunk guidelines (1.5MB being "standard"), + // I (owen-d) prefer to overallocate here + // Since TSDB accesses are seeked rather than scanned, this choice + // should have little effect as long as there is enough memory available + Bytes uint64 + + Entries uint32 } diff --git a/pkg/storage/tsdb/index/index.go b/pkg/storage/tsdb/index/index.go index 312a3fed9c..8e5a1d6e52 100644 --- a/pkg/storage/tsdb/index/index.go +++ b/pkg/storage/tsdb/index/index.go @@ -458,6 +458,8 @@ func (w *Writer) AddSeries(ref storage.SeriesRef, lset labels.Labels, chunks ... c := chunks[0] w.buf2.PutVarint64(c.MinTime) w.buf2.PutUvarint64(uint64(c.MaxTime - c.MinTime)) + w.buf2.PutUvarint64(c.Bytes) + w.buf2.PutUvarint32(c.Entries) w.buf2.PutBE32(c.Checksum) t0 := c.MaxTime @@ -466,6 +468,8 @@ func (w *Writer) AddSeries(ref storage.SeriesRef, lset labels.Labels, chunks ... // instead of uvarint because chunks may overlap w.buf2.PutVarint64(c.MinTime - t0) w.buf2.PutUvarint64(uint64(c.MaxTime - c.MinTime)) + w.buf2.PutUvarint64(c.Bytes) + w.buf2.PutUvarint32(c.Entries) t0 = c.MaxTime w.buf2.PutBE32(c.Checksum) @@ -1865,12 +1869,16 @@ func (dec *Decoder) Series(b []byte, lbls *labels.Labels, chks *[]ChunkMeta) err t0 := d.Varint64() maxt := int64(d.Uvarint64()) + t0 + nBytes := d.Uvarint64() + entries := uint32(d.Uvarint64()) checksum := d.Be32() *chks = append(*chks, ChunkMeta{ Checksum: checksum, MinTime: t0, MaxTime: maxt, + Bytes: nBytes, + Entries: entries, }) t0 = maxt @@ -1879,6 +1887,8 @@ func (dec *Decoder) Series(b []byte, lbls *labels.Labels, chks *[]ChunkMeta) err // instead of uvarint because chunks may overlap mint := d.Varint64() + t0 maxt := int64(d.Uvarint64()) + mint + nBytes := d.Uvarint64() + entries := uint32(d.Uvarint64()) checksum := d.Be32() t0 = maxt @@ -1890,6 +1900,8 @@ func (dec *Decoder) Series(b []byte, lbls *labels.Labels, chks *[]ChunkMeta) err Checksum: checksum, MinTime: mint, MaxTime: maxt, + Bytes: nBytes, + Entries: entries, }) } return d.Err() diff --git a/pkg/storage/tsdb/querier_test.go b/pkg/storage/tsdb/querier_test.go index e010bdb25c..27a63f74b7 100644 --- a/pkg/storage/tsdb/querier_test.go +++ b/pkg/storage/tsdb/querier_test.go @@ -33,11 +33,15 @@ func TestQueryIndex(t *testing.T) { Checksum: 1, MinTime: 1, MaxTime: 10, + Bytes: 10, + Entries: 10, }, { Checksum: 2, MinTime: 5, MaxTime: 15, + Bytes: 10, + Entries: 10, }, }, }, @@ -48,11 +52,15 @@ func TestQueryIndex(t *testing.T) { Checksum: 3, MinTime: 20, MaxTime: 30, + Bytes: 10, + Entries: 10, }, { Checksum: 4, MinTime: 40, MaxTime: 50, + Bytes: 10, + Entries: 10, }, }, }, @@ -63,11 +71,15 @@ func TestQueryIndex(t *testing.T) { Checksum: 1, MinTime: 1, MaxTime: 10, + Bytes: 10, + Entries: 10, }, { Checksum: 2, MinTime: 5, MaxTime: 15, + Bytes: 10, + Entries: 10, }, }, },