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

Commit

Permalink
Don't export MemTombstones.
Browse files Browse the repository at this point in the history
Signed-off-by: Callum Styan <[email protected]>
  • Loading branch information
cstyan committed Jul 29, 2019
1 parent 476bbec commit 4b7a4fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
11 changes: 6 additions & 5 deletions querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ func TestBlockQuerierDelete(t *testing.T) {
exp SeriesSet
}

tstones := tombstones.NewMemTombstones()
tstones.AddInterval(1, tombstones.Interval{1, 3})
tstones.AddInterval(2, tombstones.Interval{1, 3}, tombstones.Interval{6, 10})
tstones.AddInterval(3, tombstones.Interval{6, 10})

cases := struct {
data []seriesSamples

Expand Down Expand Up @@ -461,11 +466,7 @@ func TestBlockQuerierDelete(t *testing.T) {
},
},
},
tombstones: &tombstones.MemTombstones{IntvlGroups: map[uint64]tombstones.Intervals{
1: tombstones.Intervals{{1, 3}},
2: tombstones.Intervals{{1, 3}, {6, 10}},
3: tombstones.Intervals{{6, 10}},
}},
tombstones: tstones,
queries: []query{
{
mint: 2,
Expand Down
26 changes: 13 additions & 13 deletions tombstones/tombstones.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,55 +199,55 @@ func ReadTombstones(dir string) (TombstoneReader, int64, error) {
return stonesMap, int64(len(b)), nil
}

type MemTombstones struct {
IntvlGroups map[uint64]Intervals
type memTombstones struct {
intvlGroups map[uint64]Intervals
mtx sync.RWMutex
}

// NewMemTombstones creates new in memory TombstoneReader
// that allows adding new intervals.
func NewMemTombstones() *MemTombstones {
return &MemTombstones{IntvlGroups: make(map[uint64]Intervals)}
func NewMemTombstones() *memTombstones {
return &memTombstones{intvlGroups: make(map[uint64]Intervals)}
}

func (t *MemTombstones) Get(ref uint64) (Intervals, error) {
func (t *memTombstones) Get(ref uint64) (Intervals, error) {
t.mtx.RLock()
defer t.mtx.RUnlock()
return t.IntvlGroups[ref], nil
return t.intvlGroups[ref], nil
}

func (t *MemTombstones) Iter(f func(uint64, Intervals) error) error {
func (t *memTombstones) Iter(f func(uint64, Intervals) error) error {
t.mtx.RLock()
defer t.mtx.RUnlock()
for ref, ivs := range t.IntvlGroups {
for ref, ivs := range t.intvlGroups {
if err := f(ref, ivs); err != nil {
return err
}
}
return nil
}

func (t *MemTombstones) Total() uint64 {
func (t *memTombstones) Total() uint64 {
t.mtx.RLock()
defer t.mtx.RUnlock()

total := uint64(0)
for _, ivs := range t.IntvlGroups {
for _, ivs := range t.intvlGroups {
total += uint64(len(ivs))
}
return total
}

// AddInterval to an existing MemTombstones
func (t *MemTombstones) AddInterval(ref uint64, itvs ...Interval) {
func (t *memTombstones) AddInterval(ref uint64, itvs ...Interval) {
t.mtx.Lock()
defer t.mtx.Unlock()
for _, itv := range itvs {
t.IntvlGroups[ref] = t.IntvlGroups[ref].Add(itv)
t.intvlGroups[ref] = t.intvlGroups[ref].Add(itv)
}
}

func (*MemTombstones) Close() error {
func (*memTombstones) Close() error {
return nil
}

Expand Down

0 comments on commit 4b7a4fb

Please sign in to comment.