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

Commit 0c895bd

Browse files
committed
Move tombstones to it's own package.
Signed-off-by: Callum Styan <[email protected]>
1 parent 3dc6155 commit 0c895bd

File tree

17 files changed

+173
-163
lines changed

17 files changed

+173
-163
lines changed

block.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
"github.com/prometheus/tsdb/fileutil"
3333
"github.com/prometheus/tsdb/index"
3434
"github.com/prometheus/tsdb/labels"
35-
"github.com/prometheus/tsdb/record"
35+
"github.com/prometheus/tsdb/tombstones"
3636
)
3737

3838
// IndexWriter serializes the index for a block of series data.
@@ -137,7 +137,7 @@ type BlockReader interface {
137137
Chunks() (ChunkReader, error)
138138

139139
// Tombstones returns a TombstoneReader over the block's deleted data.
140-
Tombstones() (record.TombstoneReader, error)
140+
Tombstones() (tombstones.TombstoneReader, error)
141141

142142
// MinTime returns the min time of the block.
143143
MinTime() int64
@@ -283,7 +283,7 @@ type Block struct {
283283

284284
chunkr ChunkReader
285285
indexr IndexReader
286-
tombstones record.TombstoneReader
286+
tombstones tombstones.TombstoneReader
287287

288288
logger log.Logger
289289
}
@@ -320,7 +320,7 @@ func OpenBlock(logger log.Logger, dir string, pool chunkenc.Pool) (pb *Block, er
320320
}
321321
closers = append(closers, ir)
322322

323-
tr, tsr, err := record.ReadTombstones(dir)
323+
tr, tsr, err := tombstones.ReadTombstones(dir)
324324
if err != nil {
325325
return nil, err
326326
}
@@ -424,7 +424,7 @@ func (pb *Block) Chunks() (ChunkReader, error) {
424424
}
425425

426426
// Tombstones returns a new TombstoneReader against the block data.
427-
func (pb *Block) Tombstones() (record.TombstoneReader, error) {
427+
func (pb *Block) Tombstones() (tombstones.TombstoneReader, error) {
428428
if err := pb.startRead(); err != nil {
429429
return nil, err
430430
}
@@ -488,7 +488,7 @@ func (r blockIndexReader) Close() error {
488488
}
489489

490490
type blockTombstoneReader struct {
491-
record.TombstoneReader
491+
tombstones.TombstoneReader
492492
b *Block
493493
}
494494

@@ -524,7 +524,7 @@ func (pb *Block) Delete(mint, maxt int64, ms ...labels.Matcher) error {
524524
ir := pb.indexr
525525

526526
// Choose only valid postings which have chunks in the time-range.
527-
stones := record.NewMemTombstones()
527+
stones := tombstones.NewMemTombstones()
528528

529529
var lset labels.Labels
530530
var chks []chunks.Meta
@@ -540,7 +540,7 @@ Outer:
540540
if chk.OverlapsClosedInterval(mint, maxt) {
541541
// Delete only until the current values and not beyond.
542542
tmin, tmax := clampInterval(mint, maxt, chks[0].MinTime, chks[len(chks)-1].MaxTime)
543-
stones.AddInterval(p.At(), record.Interval{tmin, tmax})
543+
stones.AddInterval(p.At(), tombstones.Interval{tmin, tmax})
544544
continue Outer
545545
}
546546
}
@@ -550,7 +550,7 @@ Outer:
550550
return p.Err()
551551
}
552552

553-
err = pb.tombstones.Iter(func(id uint64, ivs record.Intervals) error {
553+
err = pb.tombstones.Iter(func(id uint64, ivs tombstones.Intervals) error {
554554
for _, iv := range ivs {
555555
stones.AddInterval(id, iv)
556556
}
@@ -562,7 +562,7 @@ Outer:
562562
pb.tombstones = stones
563563
pb.meta.Stats.NumTombstones = pb.tombstones.Total()
564564

565-
if err := record.WriteTombstoneFile(pb.logger, pb.dir, pb.tombstones); err != nil {
565+
if err := tombstones.WriteTombstoneFile(pb.logger, pb.dir, pb.tombstones); err != nil {
566566
return err
567567
}
568568
return writeMetaFile(pb.logger, pb.dir, &pb.meta)
@@ -573,7 +573,7 @@ Outer:
573573
func (pb *Block) CleanTombstones(dest string, c Compactor) (*ulid.ULID, error) {
574574
numStones := 0
575575

576-
if err := pb.tombstones.Iter(func(id uint64, ivs record.Intervals) error {
576+
if err := pb.tombstones.Iter(func(id uint64, ivs tombstones.Intervals) error {
577577
numStones += len(ivs)
578578
return nil
579579
}); err != nil {
@@ -608,7 +608,7 @@ func (pb *Block) Snapshot(dir string) error {
608608
for _, fname := range []string{
609609
metaFilename,
610610
indexFilename,
611-
record.TombstoneFilename,
611+
tombstones.TombstoneFilename,
612612
} {
613613
if err := os.Link(filepath.Join(pb.dir, fname), filepath.Join(blockDir, fname)); err != nil {
614614
return errors.Wrapf(err, "create snapshot %s", fname)

compact.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
"github.com/prometheus/tsdb/fileutil"
3636
"github.com/prometheus/tsdb/index"
3737
"github.com/prometheus/tsdb/labels"
38-
"github.com/prometheus/tsdb/record"
38+
"github.com/prometheus/tsdb/tombstones"
3939
)
4040

4141
// ExponentialBlockRanges returns the time ranges based on the stepSize.
@@ -606,7 +606,7 @@ func (c *LeveledCompactor) write(dest string, meta *BlockMeta, blocks ...BlockRe
606606
}
607607

608608
// Create an empty tombstones file.
609-
if err := record.WriteTombstoneFile(c.logger, tmp, record.NewMemTombstones()); err != nil {
609+
if err := tombstones.WriteTombstoneFile(c.logger, tmp, tombstones.NewMemTombstones()); err != nil {
610610
return errors.Wrap(err, "write new tombstones file")
611611
}
612612

@@ -849,15 +849,15 @@ type compactionSeriesSet struct {
849849
p index.Postings
850850
index IndexReader
851851
chunks ChunkReader
852-
tombstones record.TombstoneReader
852+
tombstones tombstones.TombstoneReader
853853

854854
l labels.Labels
855855
c []chunks.Meta
856-
intervals record.Intervals
856+
intervals tombstones.Intervals
857857
err error
858858
}
859859

860-
func newCompactionSeriesSet(i IndexReader, c ChunkReader, t record.TombstoneReader, p index.Postings) *compactionSeriesSet {
860+
func newCompactionSeriesSet(i IndexReader, c ChunkReader, t tombstones.TombstoneReader, p index.Postings) *compactionSeriesSet {
861861
return &compactionSeriesSet{
862862
index: i,
863863
chunks: c,
@@ -887,7 +887,7 @@ func (c *compactionSeriesSet) Next() bool {
887887
if len(c.intervals) > 0 {
888888
chks := make([]chunks.Meta, 0, len(c.c))
889889
for _, chk := range c.c {
890-
if !(record.Interval{chk.MinTime, chk.MaxTime}.IsSubrange(c.intervals)) {
890+
if !(tombstones.Interval{chk.MinTime, chk.MaxTime}.IsSubrange(c.intervals)) {
891891
chks = append(chks, chk)
892892
}
893893
}
@@ -915,7 +915,7 @@ func (c *compactionSeriesSet) Err() error {
915915
return c.p.Err()
916916
}
917917

918-
func (c *compactionSeriesSet) At() (labels.Labels, []chunks.Meta, record.Intervals) {
918+
func (c *compactionSeriesSet) At() (labels.Labels, []chunks.Meta, tombstones.Intervals) {
919919
return c.l, c.c, c.intervals
920920
}
921921

@@ -925,7 +925,7 @@ type compactionMerger struct {
925925
aok, bok bool
926926
l labels.Labels
927927
c []chunks.Meta
928-
intervals record.Intervals
928+
intervals tombstones.Intervals
929929
}
930930

931931
func newCompactionMerger(a, b ChunkSeriesSet) (*compactionMerger, error) {
@@ -1002,6 +1002,6 @@ func (c *compactionMerger) Err() error {
10021002
return c.b.Err()
10031003
}
10041004

1005-
func (c *compactionMerger) At() (labels.Labels, []chunks.Meta, record.Intervals) {
1005+
func (c *compactionMerger) At() (labels.Labels, []chunks.Meta, tombstones.Intervals) {
10061006
return c.l, c.c, c.intervals
10071007
}

compact_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import (
3030
"github.com/prometheus/tsdb/chunks"
3131
"github.com/prometheus/tsdb/fileutil"
3232
"github.com/prometheus/tsdb/labels"
33-
"github.com/prometheus/tsdb/record"
3433
"github.com/prometheus/tsdb/testutil"
34+
"github.com/prometheus/tsdb/tombstones"
3535
)
3636

3737
func TestSplitByRange(t *testing.T) {
@@ -458,7 +458,7 @@ type erringBReader struct{}
458458

459459
func (erringBReader) Index() (IndexReader, error) { return nil, errors.New("index") }
460460
func (erringBReader) Chunks() (ChunkReader, error) { return nil, errors.New("chunks") }
461-
func (erringBReader) Tombstones() (record.TombstoneReader, error) {
461+
func (erringBReader) Tombstones() (tombstones.TombstoneReader, error) {
462462
return nil, errors.New("tombstones")
463463
}
464464
func (erringBReader) MinTime() int64 { return 0 }

db_test.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/prometheus/tsdb/labels"
3636
"github.com/prometheus/tsdb/record"
3737
"github.com/prometheus/tsdb/testutil"
38+
"github.com/prometheus/tsdb/tombstones"
3839
"github.com/prometheus/tsdb/tsdbutil"
3940
"github.com/prometheus/tsdb/wal"
4041
)
@@ -247,27 +248,27 @@ func TestDeleteSimple(t *testing.T) {
247248
numSamples := int64(10)
248249

249250
cases := []struct {
250-
intervals record.Intervals
251+
intervals tombstones.Intervals
251252
remaint []int64
252253
}{
253254
{
254-
intervals: record.Intervals{{0, 3}},
255+
intervals: tombstones.Intervals{{0, 3}},
255256
remaint: []int64{4, 5, 6, 7, 8, 9},
256257
},
257258
{
258-
intervals: record.Intervals{{1, 3}},
259+
intervals: tombstones.Intervals{{1, 3}},
259260
remaint: []int64{0, 4, 5, 6, 7, 8, 9},
260261
},
261262
{
262-
intervals: record.Intervals{{1, 3}, {4, 7}},
263+
intervals: tombstones.Intervals{{1, 3}, {4, 7}},
263264
remaint: []int64{0, 8, 9},
264265
},
265266
{
266-
intervals: record.Intervals{{1, 3}, {4, 700}},
267+
intervals: tombstones.Intervals{{1, 3}, {4, 700}},
267268
remaint: []int64{0},
268269
},
269270
{ // This case is to ensure that labels and symbols are deleted.
270-
intervals: record.Intervals{{0, 9}},
271+
intervals: tombstones.Intervals{{0, 9}},
271272
remaint: []int64{},
272273
},
273274
}
@@ -509,11 +510,11 @@ func TestDB_SnapshotWithDelete(t *testing.T) {
509510

510511
testutil.Ok(t, app.Commit())
511512
cases := []struct {
512-
intervals record.Intervals
513+
intervals tombstones.Intervals
513514
remaint []int64
514515
}{
515516
{
516-
intervals: record.Intervals{{1, 3}, {4, 7}},
517+
intervals: tombstones.Intervals{{1, 3}, {4, 7}},
517518
remaint: []int64{0, 8, 9},
518519
},
519520
}
@@ -836,11 +837,11 @@ func TestTombstoneClean(t *testing.T) {
836837

837838
testutil.Ok(t, app.Commit())
838839
cases := []struct {
839-
intervals record.Intervals
840+
intervals tombstones.Intervals
840841
remaint []int64
841842
}{
842843
{
843-
intervals: record.Intervals{{1, 3}, {4, 7}},
844+
intervals: tombstones.Intervals{{1, 3}, {4, 7}},
844845
remaint: []int64{0, 8, 9},
845846
},
846847
}
@@ -912,7 +913,7 @@ func TestTombstoneClean(t *testing.T) {
912913
}
913914

914915
for _, b := range db.Blocks() {
915-
testutil.Equals(t, record.NewMemTombstones(), b.tombstones)
916+
testutil.Equals(t, tombstones.NewMemTombstones(), b.tombstones)
916917
}
917918
}
918919
}
@@ -938,8 +939,8 @@ func TestTombstoneCleanFail(t *testing.T) {
938939
block, err := OpenBlock(nil, blockDir, nil)
939940
testutil.Ok(t, err)
940941
// Add some some fake tombstones to trigger the compaction.
941-
tomb := record.NewMemTombstones()
942-
tomb.AddInterval(0, record.Interval{0, 1})
942+
tomb := tombstones.NewMemTombstones()
943+
tomb.AddInterval(0, tombstones.Interval{0, 1})
943944
block.tombstones = tomb
944945

945946
db.blocks = append(db.blocks, block)
@@ -1092,7 +1093,7 @@ func dbDiskSize(dir string) int64 {
10921093
// Include only index,tombstone and chunks.
10931094
if filepath.Dir(path) == chunkDir(filepath.Dir(filepath.Dir(path))) ||
10941095
info.Name() == indexFilename ||
1095-
info.Name() == record.TombstoneFilename {
1096+
info.Name() == tombstones.TombstoneFilename {
10961097
statSize += info.Size()
10971098
}
10981099
return nil

head.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/prometheus/tsdb/index"
3434
"github.com/prometheus/tsdb/labels"
3535
"github.com/prometheus/tsdb/record"
36+
"github.com/prometheus/tsdb/tombstones"
3637
"github.com/prometheus/tsdb/wal"
3738
)
3839

@@ -43,7 +44,7 @@ var (
4344

4445
// emptyTombstoneReader is a no-op Tombstone Reader.
4546
// This is used by head to satisfy the Tombstones() function call.
46-
emptyTombstoneReader = record.NewMemTombstones()
47+
emptyTombstoneReader = tombstones.NewMemTombstones()
4748
)
4849

4950
// Head handles reads and writes of time series data within a time window.
@@ -335,8 +336,8 @@ func (h *Head) loadWAL(r *wal.Reader, multiRef map[uint64]uint64) error {
335336
dec record.RecordDecoder
336337
series []record.RefSeries
337338
samples []record.RefSample
338-
tstones []record.Stone
339-
allStones = record.NewMemTombstones()
339+
tstones []tombstones.Stone
340+
allStones = tombstones.NewMemTombstones()
340341
err error
341342
)
342343
defer allStones.Close()
@@ -360,7 +361,7 @@ func (h *Head) loadWAL(r *wal.Reader, multiRef map[uint64]uint64) error {
360361
if !created {
361362
// There's already a different ref for this series.
362363
multiRefLock.Lock()
363-
multiRef[s.Ref] = series.ref
364+
multiRef[s.Ref] = series.Ref
364365
multiRefLock.Unlock()
365366
}
366367

@@ -450,7 +451,7 @@ func (h *Head) loadWAL(r *wal.Reader, multiRef map[uint64]uint64) error {
450451
}
451452
wg.Wait()
452453

453-
if err := allStones.Iter(func(ref uint64, dranges record.Intervals) error {
454+
if err := allStones.Iter(func(ref uint64, dranges tombstones.Intervals) error {
454455
return h.chunkRewrite(ref, dranges)
455456
}); err != nil {
456457
return errors.Wrap(r.Err(), "deleting samples from tombstones")
@@ -657,7 +658,7 @@ func (h *rangeHead) Chunks() (ChunkReader, error) {
657658
return h.head.chunksRange(h.mint, h.maxt), nil
658659
}
659660

660-
func (h *rangeHead) Tombstones() (record.TombstoneReader, error) {
661+
func (h *rangeHead) Tombstones() (tombstones.TombstoneReader, error) {
661662
return emptyTombstoneReader, nil
662663
}
663664

@@ -913,7 +914,7 @@ func (h *Head) Delete(mint, maxt int64, ms ...labels.Matcher) error {
913914
return errors.Wrap(err, "select series")
914915
}
915916

916-
var stones []record.Stone
917+
var stones []tombstones.Stone
917918
dirty := false
918919
for p.Next() {
919920
series := h.series.getByID(p.At())
@@ -925,9 +926,9 @@ func (h *Head) Delete(mint, maxt int64, ms ...labels.Matcher) error {
925926
// Delete only until the current values and not beyond.
926927
t0, t1 = clampInterval(mint, maxt, t0, t1)
927928
if h.wal != nil {
928-
stones = append(stones, record.Stone{p.At(), record.Intervals{{t0, t1}}})
929+
stones = append(stones, tombstones.Stone{p.At(), tombstones.Intervals{{t0, t1}}})
929930
}
930-
if err := h.chunkRewrite(p.At(), record.Intervals{{t0, t1}}); err != nil {
931+
if err := h.chunkRewrite(p.At(), tombstones.Intervals{{t0, t1}}); err != nil {
931932
return errors.Wrap(err, "delete samples")
932933
}
933934
dirty = true
@@ -954,7 +955,7 @@ func (h *Head) Delete(mint, maxt int64, ms ...labels.Matcher) error {
954955
// chunkRewrite re-writes the chunks which overlaps with deleted ranges
955956
// and removes the samples in the deleted ranges.
956957
// Chunks is deleted if no samples are left at the end.
957-
func (h *Head) chunkRewrite(ref uint64, dranges record.Intervals) (err error) {
958+
func (h *Head) chunkRewrite(ref uint64, dranges tombstones.Intervals) (err error) {
958959
if len(dranges) == 0 {
959960
return nil
960961
}
@@ -1044,7 +1045,7 @@ func (h *Head) gc() {
10441045
}
10451046

10461047
// Tombstones returns a new reader over the head's tombstones
1047-
func (h *Head) Tombstones() (record.TombstoneReader, error) {
1048+
func (h *Head) Tombstones() (tombstones.TombstoneReader, error) {
10481049
return emptyTombstoneReader, nil
10491050
}
10501051

0 commit comments

Comments
 (0)