Adds bytes and entries to chunk metadata in tsdb (#5414)

* adds bytes and entries to chunk metadata in tsdb

* removes comment
pull/5429/head
Owen Diehl 4 years ago committed by GitHub
parent 91b0bcf36a
commit 137a28d82b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      pkg/storage/tsdb/index/chunk.go
  2. 12
      pkg/storage/tsdb/index/index.go
  3. 12
      pkg/storage/tsdb/querier_test.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
}

@ -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()

@ -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,
},
},
},

Loading…
Cancel
Save