|
|
@ -352,15 +352,15 @@ type shardSeriesSet struct {
|
|
|
|
a, b SeriesSet
|
|
|
|
a, b SeriesSet
|
|
|
|
|
|
|
|
|
|
|
|
cur Series
|
|
|
|
cur Series
|
|
|
|
as, bs Series // peek ahead of each set
|
|
|
|
adone, bdone bool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func newShardSeriesSet(a, b SeriesSet) *shardSeriesSet {
|
|
|
|
func newShardSeriesSet(a, b SeriesSet) *shardSeriesSet {
|
|
|
|
s := &shardSeriesSet{a: a, b: b}
|
|
|
|
s := &shardSeriesSet{a: a, b: b}
|
|
|
|
// Initialize first elements of both sets as Next() needs
|
|
|
|
// Initialize first elements of both sets as Next() needs
|
|
|
|
// one element look-ahead.
|
|
|
|
// one element look-ahead.
|
|
|
|
s.advanceA()
|
|
|
|
s.adone = !s.a.Next()
|
|
|
|
s.advanceB()
|
|
|
|
s.bdone = !s.b.Next()
|
|
|
|
|
|
|
|
|
|
|
|
return s
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -377,50 +377,34 @@ func (s *shardSeriesSet) Err() error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *shardSeriesSet) compare() int {
|
|
|
|
func (s *shardSeriesSet) compare() int {
|
|
|
|
if s.as == nil {
|
|
|
|
if s.adone {
|
|
|
|
return 1
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if s.bs == nil {
|
|
|
|
if s.bdone {
|
|
|
|
return -1
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return labels.Compare(s.as.Labels(), s.bs.Labels())
|
|
|
|
return labels.Compare(s.a.Series().Labels(), s.a.Series().Labels())
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *shardSeriesSet) advanceA() {
|
|
|
|
|
|
|
|
if s.a.Next() {
|
|
|
|
|
|
|
|
s.as = s.a.Series()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
s.as = nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *shardSeriesSet) advanceB() {
|
|
|
|
|
|
|
|
if s.b.Next() {
|
|
|
|
|
|
|
|
s.bs = s.b.Series()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
s.bs = nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *shardSeriesSet) Next() bool {
|
|
|
|
func (s *shardSeriesSet) Next() bool {
|
|
|
|
if s.as == nil && s.bs == nil || s.Err() != nil {
|
|
|
|
if s.adone && s.bdone || s.Err() != nil {
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
d := s.compare()
|
|
|
|
d := s.compare()
|
|
|
|
// Both sets contain the current series. Chain them into a single one.
|
|
|
|
// Both sets contain the current series. Chain them into a single one.
|
|
|
|
if d > 0 {
|
|
|
|
if d > 0 {
|
|
|
|
s.cur = s.bs
|
|
|
|
s.cur = s.b.Series()
|
|
|
|
s.advanceB()
|
|
|
|
s.bdone = !s.b.Next()
|
|
|
|
|
|
|
|
|
|
|
|
} else if d < 0 {
|
|
|
|
} else if d < 0 {
|
|
|
|
s.cur = s.as
|
|
|
|
s.cur = s.a.Series()
|
|
|
|
s.advanceA()
|
|
|
|
s.adone = !s.a.Next()
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
s.cur = &chainedSeries{series: []Series{s.as, s.bs}}
|
|
|
|
s.cur = &chainedSeries{series: []Series{s.a.Series(), s.b.Series()}}
|
|
|
|
s.advanceA()
|
|
|
|
s.adone = !s.a.Next()
|
|
|
|
s.advanceB()
|
|
|
|
s.bdone = !s.b.Next()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|