Skip to content

Commit

Permalink
fix(storage): assumulate stats in arrayCursorIterator.Stats() call ac…
Browse files Browse the repository at this point in the history
…ross all observed cursors
  • Loading branch information
GeorgeMac committed Nov 4, 2019
1 parent 4af0c0a commit 34ee47a
Showing 1 changed file with 37 additions and 70 deletions.
107 changes: 37 additions & 70 deletions tsdb/tsm1/array_cursor_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import (
)

type arrayCursorIterator struct {
e *Engine
key []byte
id tsdb.SeriesIDTyped
isAsc bool
e *Engine
key []byte

asc struct {
Float *floatArrayAscendingCursor
Expand All @@ -36,9 +34,8 @@ type arrayCursorIterator struct {

func (q *arrayCursorIterator) Next(ctx context.Context, r *tsdb.CursorRequest) (tsdb.Cursor, error) {
q.key = tsdb.AppendSeriesKey(q.key[:0], r.Name, r.Tags)
q.isAsc = r.Ascending
q.id = q.e.sfile.SeriesIDTypedBySeriesKey(q.key)
if q.id.IsZero() {
id := q.e.sfile.SeriesIDTypedBySeriesKey(q.key)
if id.IsZero() {
return nil, nil
}

Expand All @@ -54,7 +51,7 @@ func (q *arrayCursorIterator) Next(ctx context.Context, r *tsdb.CursorRequest) (
opt.EndTime = r.EndTime

// Return appropriate cursor based on type.
switch typ := q.id.Type(); typ {
switch typ := id.Type(); typ {
case models.Float:
return q.buildFloatArrayCursor(ctx, r.Name, r.Tags, r.Field, opt), nil
case models.Integer:
Expand All @@ -78,67 +75,37 @@ func (q *arrayCursorIterator) seriesFieldKeyBytes(name []byte, tags models.Tags,
}

// Stats returns the cumulative stats for all cursors.
func (q *arrayCursorIterator) Stats() (stats cursors.CursorStats) {
// Return appropriate cursor based on type.
switch typ := q.id.Type(); typ {
case models.Float:
if q.isAsc {
if cur := q.asc.Float; cur != nil {
stats.Add(cur.Stats())
}
return
}

if cur := q.desc.Float; cur != nil {
stats.Add(cur.Stats())
}
case models.Integer:
if q.isAsc {
if cur := q.asc.Integer; cur != nil {
stats.Add(cur.Stats())
}
return
}

if cur := q.desc.Integer; cur != nil {
stats.Add(cur.Stats())
}
case models.Unsigned:
if q.isAsc {
if cur := q.asc.Unsigned; cur != nil {
stats.Add(cur.Stats())
}
return
}

if cur := q.desc.Unsigned; cur != nil {
stats.Add(cur.Stats())
}
case models.String:
if q.isAsc {
if cur := q.asc.String; cur != nil {
stats.Add(cur.Stats())
}
return
}

if cur := q.desc.String; cur != nil {
stats.Add(cur.Stats())
}
case models.Boolean:
if q.isAsc {
if cur := q.asc.Boolean; cur != nil {
stats.Add(cur.Stats())
}
return
}

if cur := q.desc.Boolean; cur != nil {
stats.Add(cur.Stats())
}
default:
panic(fmt.Sprintf("unreachable: %v", typ))
func (q *arrayCursorIterator) Stats() cursors.CursorStats {
var stats cursors.CursorStats
if cur := q.asc.Float; cur != nil {
stats.Add(cur.Stats())
}

return
if cur := q.asc.Integer; cur != nil {
stats.Add(cur.Stats())
}
if cur := q.asc.Unsigned; cur != nil {
stats.Add(cur.Stats())
}
if cur := q.asc.Boolean; cur != nil {
stats.Add(cur.Stats())
}
if cur := q.asc.String; cur != nil {
stats.Add(cur.Stats())
}
if cur := q.desc.Float; cur != nil {
stats.Add(cur.Stats())
}
if cur := q.desc.Integer; cur != nil {
stats.Add(cur.Stats())
}
if cur := q.desc.Unsigned; cur != nil {
stats.Add(cur.Stats())
}
if cur := q.desc.Boolean; cur != nil {
stats.Add(cur.Stats())
}
if cur := q.desc.String; cur != nil {
stats.Add(cur.Stats())
}
return stats
}

0 comments on commit 34ee47a

Please sign in to comment.