Simplify series set Merge logic

pull/9316/head
Edd Robinson 2018-01-15 15:15:41 +00:00
parent e902998f4e
commit 338f284bc9
3 changed files with 18 additions and 8 deletions

View File

@ -73,11 +73,11 @@ func (p IndexFiles) buildSeriesIDSets() (seriesIDSet, tombstoneSeriesIDSet *tsdb
// Add tombstones and remove from old series existence set. // Add tombstones and remove from old series existence set.
seriesIDSet.Diff(ts) seriesIDSet.Diff(ts)
tombstoneSeriesIDSet.Merge(tombstoneSeriesIDSet, ts) tombstoneSeriesIDSet.Merge(ts)
// Add new series and remove from old series tombstone set. // Add new series and remove from old series tombstone set.
tombstoneSeriesIDSet.Diff(ss) tombstoneSeriesIDSet.Diff(ss)
seriesIDSet.Merge(seriesIDSet, ss) seriesIDSet.Merge(ss)
} }
return seriesIDSet, tombstoneSeriesIDSet, nil return seriesIDSet, tombstoneSeriesIDSet, nil

View File

@ -283,7 +283,7 @@ func (p *Partition) buildSeriesSet() error {
if err != nil { if err != nil {
return err return err
} }
p.seriesIDSet.Merge(p.seriesIDSet, ss) p.seriesIDSet.Merge(ss)
} }
return nil return nil
} }

View File

@ -59,18 +59,28 @@ func (s *SeriesIDSet) RemoveNoLock(id uint64) {
s.bitmap.Remove(uint32(id)) s.bitmap.Remove(uint32(id))
} }
// Merge merged the contents of others into s. // Merge merged the contents of others into s. The caller does not need to
// provide s as an argument, and the contents of s will always be present in s
// after Merge returns.
func (s *SeriesIDSet) Merge(others ...*SeriesIDSet) { func (s *SeriesIDSet) Merge(others ...*SeriesIDSet) {
bms := make([]*roaring.Bitmap, 0, len(others)) bms := make([]*roaring.Bitmap, 0, len(others)+1)
s.RLock()
bms = append(bms, s.bitmap) // Add ourself.
// Add other bitsets.
for _, other := range others { for _, other := range others {
other.RLock() other.RLock()
defer other.RUnlock() // Hold until we have merged all the bitmaps
bms = append(bms, other.bitmap) bms = append(bms, other.bitmap)
other.RUnlock()
} }
result := roaring.FastOr(bms...)
s.RUnlock()
s.Lock() s.Lock()
defer s.Unlock() s.bitmap = result
s.bitmap = roaring.FastOr(bms...) s.Unlock()
} }
// Equals returns true if other and s are the same set of ids. // Equals returns true if other and s are the same set of ids.