From 53833d206c20cff449b6b3611ae164a2d96f8bab Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Wed, 11 Oct 2017 07:30:40 -0700 Subject: [PATCH] Serialize EXPLAIN ANALYZE traces from remote nodes --- query/internal/internal.pb.go | 111 ++++++++++++++++--------------- query/internal/internal.proto | 1 + query/iterator.gen.go | 80 ++++------------------- query/iterator.gen.go.tmpl | 67 ++----------------- query/iterator.go | 119 +++++++++++++++++++++++++++++++--- query/iterator_test.go | 2 +- query/point.gen.go | 71 +++++++++++++++++--- query/point.gen.go.tmpl | 15 ++++- 8 files changed, 260 insertions(+), 206 deletions(-) diff --git a/query/internal/internal.pb.go b/query/internal/internal.pb.go index cbf9b82bb65..9b9ae168cb9 100644 --- a/query/internal/internal.pb.go +++ b/query/internal/internal.pb.go @@ -1,6 +1,5 @@ -// Code generated by protoc-gen-gogo. +// Code generated by protoc-gen-gogo. DO NOT EDIT. // source: internal/internal.proto -// DO NOT EDIT! /* Package query is a generated protocol buffer package. @@ -48,6 +47,7 @@ type Point struct { BooleanValue *bool `protobuf:"varint,10,opt,name=BooleanValue" json:"BooleanValue,omitempty"` UnsignedValue *uint64 `protobuf:"varint,12,opt,name=UnsignedValue" json:"UnsignedValue,omitempty"` Stats *IteratorStats `protobuf:"bytes,11,opt,name=Stats" json:"Stats,omitempty"` + Trace []byte `protobuf:"bytes,13,opt,name=Trace" json:"Trace,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -140,6 +140,13 @@ func (m *Point) GetStats() *IteratorStats { return nil } +func (m *Point) GetTrace() []byte { + if m != nil { + return m.Trace + } + return nil +} + type Aux struct { DataType *int32 `protobuf:"varint,1,req,name=DataType" json:"DataType,omitempty"` FloatValue *float64 `protobuf:"fixed64,2,opt,name=FloatValue" json:"FloatValue,omitempty"` @@ -537,54 +544,54 @@ func init() { func init() { proto.RegisterFile("internal/internal.proto", fileDescriptorInternal) } var fileDescriptorInternal = []byte{ - // 769 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0xe1, 0x8e, 0xe3, 0x34, - 0x10, 0x56, 0x92, 0x4d, 0xb7, 0x71, 0xb7, 0xf4, 0x30, 0x65, 0xb1, 0xd0, 0x09, 0x45, 0x11, 0x48, - 0x11, 0xa0, 0x22, 0xed, 0x2f, 0x7e, 0x21, 0xf5, 0xd8, 0x5b, 0x54, 0xe9, 0xae, 0x7b, 0x72, 0x97, - 0xfd, 0x6f, 0x9a, 0xd9, 0xc8, 0x52, 0xea, 0x14, 0xc7, 0x41, 0xed, 0x03, 0xf0, 0x10, 0x3c, 0x16, - 0x4f, 0xc2, 0x2b, 0x20, 0x8f, 0x9d, 0x34, 0x5d, 0x81, 0xf6, 0x7e, 0x75, 0xbe, 0x6f, 0xa6, 0x63, - 0xcf, 0xcc, 0x37, 0x0e, 0xf9, 0x42, 0x2a, 0x03, 0x5a, 0x89, 0xea, 0x87, 0xce, 0x58, 0xec, 0x75, - 0x6d, 0x6a, 0x1a, 0xff, 0xde, 0x82, 0x3e, 0x66, 0xff, 0x84, 0x24, 0xfe, 0x50, 0x4b, 0x65, 0x28, - 0x25, 0x17, 0x6b, 0xb1, 0x03, 0x16, 0xa4, 0x61, 0x9e, 0x70, 0xb4, 0x2d, 0xf7, 0x20, 0xca, 0x86, - 0x85, 0x8e, 0xb3, 0x36, 0x72, 0x72, 0x07, 0x2c, 0x4a, 0xc3, 0x3c, 0xe2, 0x68, 0xd3, 0x57, 0x24, - 0x5a, 0xcb, 0x8a, 0x5d, 0xa4, 0x61, 0x3e, 0xe6, 0xd6, 0xa4, 0xaf, 0x49, 0xb4, 0x6c, 0x0f, 0x2c, - 0x4e, 0xa3, 0x7c, 0x72, 0x43, 0x16, 0x78, 0xd8, 0x62, 0xd9, 0x1e, 0xb8, 0xa5, 0xe9, 0x57, 0x84, - 0x2c, 0xcb, 0x52, 0x43, 0x29, 0x0c, 0x14, 0x6c, 0x94, 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0x87, 0xb2, 0x05, 0x19, 0xb9, - 0x8d, 0xb4, 0x2b, 0xfc, 0x28, 0x2a, 0xff, 0x95, 0xb0, 0x26, 0x7e, 0x10, 0xec, 0x23, 0x16, 0xba, - 0x35, 0xb0, 0xf6, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x55, 0x55, 0xec, 0xe3, 0x77, 0x06, 0x00, - 0x00, + // 780 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0xdb, 0x6e, 0xe3, 0x36, + 0x10, 0x05, 0xa5, 0xc8, 0xb1, 0xe8, 0xb8, 0xd9, 0xb2, 0x69, 0x4a, 0x14, 0x8b, 0x42, 0x10, 0x5a, + 0x40, 0x68, 0x8b, 0x14, 0xc8, 0x53, 0x9f, 0x0a, 0x78, 0x9b, 0x4d, 0x11, 0x60, 0x37, 0x59, 0xd0, + 0x6e, 0xde, 0x59, 0x6b, 0x22, 0x10, 0x90, 0x29, 0x97, 0xa2, 0x0a, 0xfb, 0x03, 0xf6, 0x23, 0xfa, + 0x59, 0xfd, 0xa3, 0x82, 0x43, 0x4a, 0x96, 0x83, 0x16, 0xd9, 0x27, 0xcf, 0x39, 0x33, 0xe6, 0xe5, + 0xcc, 0x19, 0x8a, 0x7e, 0xa5, 0xb4, 0x05, 0xa3, 0x65, 0xfd, 0x53, 0x1f, 0x5c, 0x6d, 0x4d, 0x63, + 0x1b, 0x96, 0xfc, 0xd9, 0x81, 0xd9, 0xe7, 0x1f, 0x63, 0x9a, 0x7c, 0x68, 0x94, 0xb6, 0x8c, 0xd1, + 0x93, 0x7b, 0xb9, 0x01, 0x4e, 0xb2, 0xa8, 0x48, 0x05, 0xc6, 0x8e, 0x5b, 0xc9, 0xaa, 0xe5, 0x91, + 0xe7, 0x5c, 0x8c, 0x9c, 0xda, 0x00, 0x8f, 0xb3, 0xa8, 0x88, 0x05, 0xc6, 0xec, 0x15, 0x8d, 0xef, + 0x55, 0xcd, 0x4f, 0xb2, 0xa8, 0x98, 0x0a, 0x17, 0xb2, 0xd7, 0x34, 0x5e, 0x74, 0x3b, 0x9e, 0x64, + 0x71, 0x31, 0xbb, 0xa6, 0x57, 0xb8, 0xd9, 0xd5, 0xa2, 0xdb, 0x09, 0x47, 0xb3, 0x6f, 0x28, 0x5d, + 0x54, 0x95, 0x81, 0x4a, 0x5a, 0x28, 0xf9, 0x24, 0x23, 0xc5, 0x5c, 0x8c, 0x18, 0x97, 0xbf, 0xad, + 0x1b, 0x69, 0x1f, 0x65, 0xdd, 0x01, 0x3f, 0xcd, 0x48, 0x41, 0xc4, 0x88, 0x61, 0x39, 0x3d, 0xbb, + 0xd3, 0x16, 0x2a, 0x30, 0xbe, 0x62, 0x9a, 0x91, 0x22, 0x16, 0x47, 0x1c, 0xcb, 0xe8, 0x6c, 0x69, + 0x8d, 0xd2, 0x95, 0x2f, 0x49, 0x33, 0x52, 0xa4, 0x62, 0x4c, 0xb9, 0x55, 0xde, 0x34, 0x4d, 0x0d, + 0x52, 0xfb, 0x12, 0x9a, 0x91, 0x62, 0x2a, 0x8e, 0x38, 0xf6, 0x2d, 0x9d, 0xff, 0xae, 0x5b, 0x55, + 0x69, 0x28, 0x7d, 0xd1, 0x59, 0x46, 0x8a, 0x13, 0x71, 0x4c, 0xb2, 0xef, 0x69, 0xb2, 0xb4, 0xd2, + 0xb6, 0x7c, 0x96, 0x91, 0x62, 0x76, 0x7d, 0x11, 0xee, 0x7b, 0x67, 0xc1, 0x48, 0xdb, 0x18, 0xcc, + 0x09, 0x5f, 0xc2, 0x2e, 0x68, 0xb2, 0x32, 0x72, 0x0d, 0x7c, 0x9e, 0x91, 0xe2, 0x4c, 0x78, 0x90, + 0xff, 0x43, 0x50, 0x30, 0xf6, 0x35, 0x9d, 0xde, 0x48, 0x2b, 0x57, 0xfb, 0xad, 0xef, 0x44, 0x22, + 0x06, 0xfc, 0x4c, 0x95, 0xe8, 0x45,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 0xe9, 0x81, 0xdb, 0xef, 0xae, 0x5d, 0x49, 0x53, 0x81, 0x0d, 0x73, 0x38, 0xe0, 0xfc, 0x97, + 0x83, 0x9d, 0xf1, 0x5c, 0x9d, 0xf1, 0xbd, 0x26, 0xa8, 0xcc, 0x80, 0x47, 0x7d, 0x8b, 0xc6, 0x7d, + 0xcb, 0x17, 0x74, 0x7e, 0xf4, 0x3e, 0x61, 0xc3, 0x82, 0xba, 0x24, 0x34, 0x2c, 0x48, 0x7b, 0x49, + 0x27, 0xf8, 0x8d, 0xb8, 0xef, 0x97, 0xf0, 0x28, 0xbf, 0xa2, 0x13, 0x3f, 0x91, 0x6e, 0x84, 0x1f, + 0x65, 0x1d, 0xbe, 0x1d, 0x2e, 0xc4, 0xcf, 0x84, 0x7b, 0xc4, 0x22, 0x3f, 0x06, 0x2e, 0xfe, 0x37, + 0x00, 0x00, 0xff, 0xff, 0x3d, 0xd1, 0x25, 0x7b, 0x8d, 0x06, 0x00, 0x00, } diff --git a/query/internal/internal.proto b/query/internal/internal.proto index 2bb2889e53f..8ebb0e5d232 100644 --- a/query/internal/internal.proto +++ b/query/internal/internal.proto @@ -16,6 +16,7 @@ message Point { optional uint64 UnsignedValue = 12; optional IteratorStats Stats = 11; + optional bytes Trace = 13; } message Aux { diff --git a/query/iterator.gen.go b/query/iterator.gen.go index f1963ecaf1c..159e6da2b25 100644 --- a/query/iterator.gen.go +++ b/query/iterator.gen.go @@ -8,8 +8,7 @@ package query import ( "container/heap" - "encoding/binary" - "fmt" + "context" "io" "sort" "sync" @@ -17,7 +16,6 @@ import ( "github.com/gogo/protobuf/proto" "github.com/influxdata/influxdb/influxql" - internal "github.com/influxdata/influxdb/query/internal" ) // DefaultStatsInterval is the default value for IteratorEncoder.StatsInterval. @@ -3384,8 +3382,8 @@ type floatReaderIterator struct { } // newFloatReaderIterator returns a new instance of floatReaderIterator. -func newFloatReaderIterator(r io.Reader, stats IteratorStats) *floatReaderIterator { - dec := NewFloatPointDecoder(r) +func newFloatReaderIterator(ctx context.Context, r io.Reader, stats IteratorStats) *floatReaderIterator { + dec := NewFloatPointDecoder(ctx, r) dec.stats = stats return &floatReaderIterator{ @@ -6777,8 +6775,8 @@ type integerReaderIterator struct { } // newIntegerReaderIterator returns a new instance of integerReaderIterator. -func newIntegerReaderIterator(r io.Reader, stats IteratorStats) *integerReaderIterator { - dec := NewIntegerPointDecoder(r) +func newIntegerReaderIterator(ctx context.Context, r io.Reader, stats IteratorStats) *integerReaderIterator { + dec := NewIntegerPointDecoder(ctx, r) dec.stats = stats return &integerReaderIterator{ @@ -10170,8 +10168,8 @@ type unsignedReaderIterator struct { } // newUnsignedReaderIterator returns a new instance of unsignedReaderIterator. -func newUnsignedReaderIterator(r io.Reader, stats IteratorStats) *unsignedReaderIterator { - dec := NewUnsignedPointDecoder(r) +func newUnsignedReaderIterator(ctx context.Context, r io.Reader, stats IteratorStats) *unsignedReaderIterator { + dec := NewUnsignedPointDecoder(ctx, r) dec.stats = stats return &unsignedReaderIterator{ @@ -13549,8 +13547,8 @@ type stringReaderIterator struct { } // newStringReaderIterator returns a new instance of stringReaderIterator. -func newStringReaderIterator(r io.Reader, stats IteratorStats) *stringReaderIterator { - dec := NewStringPointDecoder(r) +func newStringReaderIterator(ctx context.Context, r io.Reader, stats IteratorStats) *stringReaderIterator { + dec := NewStringPointDecoder(ctx, r) dec.stats = stats return &stringReaderIterator{ @@ -16928,8 +16926,8 @@ type booleanReaderIterator struct { } // newBooleanReaderIterator returns a new instance of booleanReaderIterator. -func newBooleanReaderIterator(r io.Reader, stats IteratorStats) *booleanReaderIterator { - dec := NewBooleanPointDecoder(r) +func newBooleanReaderIterator(ctx context.Context, r io.Reader, stats IteratorStats) *booleanReaderIterator { + dec := NewBooleanPointDecoder(ctx, r) dec.stats = stats return &booleanReaderIterator{ @@ -16963,39 +16961,6 @@ func (itr *booleanReaderIterator) Next() (*BooleanPoint, error) { return p, nil } -// IteratorEncoder is an encoder for encoding an iterator's points to w. -type IteratorEncoder struct { - w io.Writer - - // Frequency with which stats are emitted. - StatsInterval time.Duration -} - -// NewIteratorEncoder encodes an iterator's points to w. -func NewIteratorEncoder(w io.Writer) *IteratorEncoder { - return &IteratorEncoder{ - w: w, - - StatsInterval: DefaultStatsInterval, - } -} - -// EncodeIterator encodes and writes all of itr's points to the underlying writer. -func (enc *IteratorEncoder) EncodeIterator(itr Iterator) error { - switch itr := itr.(type) { - case FloatIterator: - return enc.encodeFloatIterator(itr) - case IntegerIterator: - return enc.encodeIntegerIterator(itr) - case StringIterator: - return enc.encodeStringIterator(itr) - case BooleanIterator: - return enc.encodeBooleanIterator(itr) - default: - panic(fmt.Sprintf("unsupported iterator for encoder: %T", itr)) - } -} - // encodeFloatIterator encodes all points from itr to the underlying writer. func (enc *IteratorEncoder) encodeFloatIterator(itr FloatIterator) error { ticker := time.NewTicker(enc.StatsInterval) @@ -17210,26 +17175,3 @@ func (enc *IteratorEncoder) encodeBooleanIterator(itr BooleanIterator) error { } return nil } - -// encode a stats object in the point stream. -func (enc *IteratorEncoder) encodeStats(stats IteratorStats) error { - buf, err := proto.Marshal(&internal.Point{ - Name: proto.String(""), - Tags: proto.String(""), - Time: proto.Int64(0), - Nil: proto.Bool(false), - - Stats: encodeIteratorStats(&stats), - }) - if err != nil { - return err - } - - if err := binary.Write(enc.w, binary.BigEndian, uint32(len(buf))); err != nil { - return err - } - if _, err := enc.w.Write(buf); err != nil { - return err - } - return nil -} diff --git a/query/iterator.gen.go.tmpl b/query/iterator.gen.go.tmpl index 3f54b3f43c5..feaf4fdc1ab 100644 --- a/query/iterator.gen.go.tmpl +++ b/query/iterator.gen.go.tmpl @@ -1,9 +1,8 @@ package query import ( + "context" "container/heap" - "encoding/binary" - "fmt" "io" "sort" "sync" @@ -11,7 +10,6 @@ import ( "github.com/gogo/protobuf/proto" "github.com/influxdata/influxdb/influxql" - internal "github.com/influxdata/influxdb/query/internal" ) // DefaultStatsInterval is the default value for IteratorEncoder.StatsInterval. @@ -1723,13 +1721,13 @@ type {{$k.name}}ReaderIterator struct { } // new{{$k.Name}}ReaderIterator returns a new instance of {{$k.name}}ReaderIterator. -func new{{$k.Name}}ReaderIterator(r io.Reader, stats IteratorStats) *{{$k.name}}ReaderIterator { - dec := New{{$k.Name}}PointDecoder(r) +func new{{$k.Name}}ReaderIterator(ctx context.Context, r io.Reader, stats IteratorStats) *{{$k.name}}ReaderIterator { + dec := New{{$k.Name}}PointDecoder(ctx, r) dec.stats = stats return &{{$k.name}}ReaderIterator{ r: r, - dec: dec, + dec: dec, } } @@ -1759,40 +1757,6 @@ func (itr *{{$k.name}}ReaderIterator) Next() (*{{$k.Name}}Point, error) { } {{end}} - -// IteratorEncoder is an encoder for encoding an iterator's points to w. -type IteratorEncoder struct { - w io.Writer - - // Frequency with which stats are emitted. - StatsInterval time.Duration -} - -// NewIteratorEncoder encodes an iterator's points to w. -func NewIteratorEncoder(w io.Writer) *IteratorEncoder { - return &IteratorEncoder{ - w: w, - - StatsInterval: DefaultStatsInterval, - } -} - -// EncodeIterator encodes and writes all of itr's points to the underlying writer. -func (enc *IteratorEncoder) EncodeIterator(itr Iterator) error { - switch itr := itr.(type) { - case FloatIterator: - return enc.encodeFloatIterator(itr) - case IntegerIterator: - return enc.encodeIntegerIterator(itr) - case StringIterator: - return enc.encodeStringIterator(itr) - case BooleanIterator: - return enc.encodeBooleanIterator(itr) - default: - panic(fmt.Sprintf("unsupported iterator for encoder: %T", itr)) - } -} - {{range .}} // encode{{.Name}}Iterator encodes all points from itr to the underlying writer. func (enc *IteratorEncoder) encode{{.Name}}Iterator(itr {{.Name}}Iterator) error { @@ -1839,27 +1803,4 @@ func (enc *IteratorEncoder) encode{{.Name}}Iterator(itr {{.Name}}Iterator) error {{end}} -// encode a stats object in the point stream. -func (enc *IteratorEncoder) encodeStats(stats IteratorStats) error { - buf, err := proto.Marshal(&internal.Point{ - Name: proto.String(""), - Tags: proto.String(""), - Time: proto.Int64(0), - Nil: proto.Bool(false), - - Stats: encodeIteratorStats(&stats), - }) - if err != nil { - return err - } - - if err := binary.Write(enc.w, binary.BigEndian, uint32(len(buf))); err != nil { - return err - } - if _, err := enc.w.Write(buf); err != nil { - return err - } - return nil -} - {{end}} diff --git a/query/iterator.go b/query/iterator.go index abe1993ef34..49756df3a25 100644 --- a/query/iterator.go +++ b/query/iterator.go @@ -1,16 +1,18 @@ package query import ( + "context" + "encoding/binary" "errors" "fmt" "io" + "regexp" "sync" "time" - "regexp" - "github.com/gogo/protobuf/proto" "github.com/influxdata/influxdb/influxql" + "github.com/influxdata/influxdb/pkg/tracing" internal "github.com/influxdata/influxdb/query/internal" ) @@ -640,18 +642,18 @@ func DrainIterators(itrs []Iterator) { } // NewReaderIterator returns an iterator that streams from a reader. -func NewReaderIterator(r io.Reader, typ influxql.DataType, stats IteratorStats) Iterator { +func NewReaderIterator(ctx context.Context, r io.Reader, typ influxql.DataType, stats IteratorStats) Iterator { switch typ { case influxql.Float: - return newFloatReaderIterator(r, stats) + return newFloatReaderIterator(ctx, r, stats) case influxql.Integer: - return newIntegerReaderIterator(r, stats) + return newIntegerReaderIterator(ctx, r, stats) case influxql.Unsigned: - return newUnsignedReaderIterator(r, stats) + return newUnsignedReaderIterator(ctx, r, stats) case influxql.String: - return newStringReaderIterator(r, stats) + return newStringReaderIterator(ctx, r, stats) case influxql.Boolean: - return newBooleanReaderIterator(r, stats) + return newBooleanReaderIterator(ctx, r, stats) default: return &nilFloatReaderIterator{r: r} } @@ -660,7 +662,7 @@ func NewReaderIterator(r io.Reader, typ influxql.DataType, stats IteratorStats) // IteratorCreator is an interface to create Iterators. type IteratorCreator interface { // Creates a simple iterator for use in an InfluxQL query. - CreateIterator(source *influxql.Measurement, opt IteratorOptions) (Iterator, error) + CreateIterator(ctx context.Context, source *influxql.Measurement, opt IteratorOptions) (Iterator, error) // Determines the potential cost for creating an iterator. IteratorCost(source *influxql.Measurement, opt IteratorOptions) (IteratorCost, error) @@ -1426,6 +1428,22 @@ func decodeIteratorStats(pb *internal.IteratorStats) IteratorStats { } } +func decodeIteratorTrace(ctx context.Context, data []byte) error { + pt := tracing.TraceFromContext(ctx) + if pt == nil { + return nil + } + + var ct tracing.Trace + if err := ct.UnmarshalBinary(data); err != nil { + return err + } + + pt.Merge(&ct) + + return nil +} + // IteratorCost contains statistics retrieved for explaining what potential // cost may be incurred by instantiating an iterator. type IteratorCost struct { @@ -1530,3 +1548,86 @@ func abs(v int64) int64 { } return v } + +// IteratorEncoder is an encoder for encoding an iterator's points to w. +type IteratorEncoder struct { + w io.Writer + + // Frequency with which stats are emitted. + StatsInterval time.Duration +} + +// NewIteratorEncoder encodes an iterator's points to w. +func NewIteratorEncoder(w io.Writer) *IteratorEncoder { + return &IteratorEncoder{ + w: w, + + StatsInterval: DefaultStatsInterval, + } +} + +// EncodeIterator encodes and writes all of itr's points to the underlying writer. +func (enc *IteratorEncoder) EncodeIterator(itr Iterator) error { + switch itr := itr.(type) { + case FloatIterator: + return enc.encodeFloatIterator(itr) + case IntegerIterator: + return enc.encodeIntegerIterator(itr) + case StringIterator: + return enc.encodeStringIterator(itr) + case BooleanIterator: + return enc.encodeBooleanIterator(itr) + default: + panic(fmt.Sprintf("unsupported iterator for encoder: %T", itr)) + } +} + +func (enc *IteratorEncoder) EncodeTrace(trace *tracing.Trace) error { + data, err := trace.MarshalBinary() + if err != nil { + return err + } + + buf, err := proto.Marshal(&internal.Point{ + Name: proto.String(""), + Tags: proto.String(""), + Time: proto.Int64(0), + Nil: proto.Bool(false), + + Trace: data, + }) + if err != nil { + return err + } + + if err = binary.Write(enc.w, binary.BigEndian, uint32(len(buf))); err != nil { + return err + } + if _, err = enc.w.Write(buf); err != nil { + return err + } + return nil +} + +// encode a stats object in the point stream. +func (enc *IteratorEncoder) encodeStats(stats IteratorStats) error { + buf, err := proto.Marshal(&internal.Point{ + Name: proto.String(""), + Tags: proto.String(""), + Time: proto.Int64(0), + Nil: proto.Bool(false), + + Stats: encodeIteratorStats(&stats), + }) + if err != nil { + return err + } + + if err = binary.Write(enc.w, binary.BigEndian, uint32(len(buf))); err != nil { + return err + } + if _, err = enc.w.Write(buf); err != nil { + return err + } + return nil +} diff --git a/query/iterator_test.go b/query/iterator_test.go index 3a5f8a83fc9..8c33d8ec4c3 100644 --- a/query/iterator_test.go +++ b/query/iterator_test.go @@ -1527,7 +1527,7 @@ func TestIterator_EncodeDecode(t *testing.T) { } // Decode from the buffer. - dec := query.NewReaderIterator(&buf, influxql.Float, itr.Stats()) + dec := query.NewReaderIterator(context.TODO(), &buf, influxql.Float, itr.Stats()) // Initial stats should exist immediately. fdec := dec.(query.FloatIterator) diff --git a/query/point.gen.go b/query/point.gen.go index 2e2cf648ca6..457ec9da086 100644 --- a/query/point.gen.go +++ b/query/point.gen.go @@ -7,6 +7,7 @@ package query import ( + "context" "encoding/binary" "io" @@ -181,11 +182,12 @@ func (enc *FloatPointEncoder) EncodeFloatPoint(p *FloatPoint) error { type FloatPointDecoder struct { r io.Reader stats IteratorStats + ctx context.Context } // NewFloatPointDecoder returns a new instance of FloatPointDecoder that reads from r. -func NewFloatPointDecoder(r io.Reader) *FloatPointDecoder { - return &FloatPointDecoder{r: r} +func NewFloatPointDecoder(ctx context.Context, r io.Reader) *FloatPointDecoder { + return &FloatPointDecoder{r: r, ctx: ctx} } // Stats returns iterator stats embedded within the stream. @@ -218,6 +220,15 @@ func (dec *FloatPointDecoder) DecodeFloatPoint(p *FloatPoint) error { continue } + if len(pb.Trace) > 0 { + var err error + err = decodeIteratorTrace(dec.ctx, pb.Trace) + if err != nil { + return err + } + continue + } + // Decode into point object. *p = *decodeFloatPoint(&pb) @@ -392,11 +403,12 @@ func (enc *IntegerPointEncoder) EncodeIntegerPoint(p *IntegerPoint) error { type IntegerPointDecoder struct { r io.Reader stats IteratorStats + ctx context.Context } // NewIntegerPointDecoder returns a new instance of IntegerPointDecoder that reads from r. -func NewIntegerPointDecoder(r io.Reader) *IntegerPointDecoder { - return &IntegerPointDecoder{r: r} +func NewIntegerPointDecoder(ctx context.Context, r io.Reader) *IntegerPointDecoder { + return &IntegerPointDecoder{r: r, ctx: ctx} } // Stats returns iterator stats embedded within the stream. @@ -429,6 +441,15 @@ func (dec *IntegerPointDecoder) DecodeIntegerPoint(p *IntegerPoint) error { continue } + if len(pb.Trace) > 0 { + var err error + err = decodeIteratorTrace(dec.ctx, pb.Trace) + if err != nil { + return err + } + continue + } + // Decode into point object. *p = *decodeIntegerPoint(&pb) @@ -601,11 +622,12 @@ func (enc *UnsignedPointEncoder) EncodeUnsignedPoint(p *UnsignedPoint) error { type UnsignedPointDecoder struct { r io.Reader stats IteratorStats + ctx context.Context } // NewUnsignedPointDecoder returns a new instance of UnsignedPointDecoder that reads from r. -func NewUnsignedPointDecoder(r io.Reader) *UnsignedPointDecoder { - return &UnsignedPointDecoder{r: r} +func NewUnsignedPointDecoder(ctx context.Context, r io.Reader) *UnsignedPointDecoder { + return &UnsignedPointDecoder{r: r, ctx: ctx} } // Stats returns iterator stats embedded within the stream. @@ -638,6 +660,15 @@ func (dec *UnsignedPointDecoder) DecodeUnsignedPoint(p *UnsignedPoint) error { continue } + if len(pb.Trace) > 0 { + var err error + err = decodeIteratorTrace(dec.ctx, pb.Trace) + if err != nil { + return err + } + continue + } + // Decode into point object. *p = *decodeUnsignedPoint(&pb) @@ -812,11 +843,12 @@ func (enc *StringPointEncoder) EncodeStringPoint(p *StringPoint) error { type StringPointDecoder struct { r io.Reader stats IteratorStats + ctx context.Context } // NewStringPointDecoder returns a new instance of StringPointDecoder that reads from r. -func NewStringPointDecoder(r io.Reader) *StringPointDecoder { - return &StringPointDecoder{r: r} +func NewStringPointDecoder(ctx context.Context, r io.Reader) *StringPointDecoder { + return &StringPointDecoder{r: r, ctx: ctx} } // Stats returns iterator stats embedded within the stream. @@ -849,6 +881,15 @@ func (dec *StringPointDecoder) DecodeStringPoint(p *StringPoint) error { continue } + if len(pb.Trace) > 0 { + var err error + err = decodeIteratorTrace(dec.ctx, pb.Trace) + if err != nil { + return err + } + continue + } + // Decode into point object. *p = *decodeStringPoint(&pb) @@ -1023,11 +1064,12 @@ func (enc *BooleanPointEncoder) EncodeBooleanPoint(p *BooleanPoint) error { type BooleanPointDecoder struct { r io.Reader stats IteratorStats + ctx context.Context } // NewBooleanPointDecoder returns a new instance of BooleanPointDecoder that reads from r. -func NewBooleanPointDecoder(r io.Reader) *BooleanPointDecoder { - return &BooleanPointDecoder{r: r} +func NewBooleanPointDecoder(ctx context.Context, r io.Reader) *BooleanPointDecoder { + return &BooleanPointDecoder{r: r, ctx: ctx} } // Stats returns iterator stats embedded within the stream. @@ -1060,6 +1102,15 @@ func (dec *BooleanPointDecoder) DecodeBooleanPoint(p *BooleanPoint) error { continue } + if len(pb.Trace) > 0 { + var err error + err = decodeIteratorTrace(dec.ctx, pb.Trace) + if err != nil { + return err + } + continue + } + // Decode into point object. *p = *decodeBooleanPoint(&pb) diff --git a/query/point.gen.go.tmpl b/query/point.gen.go.tmpl index f869918bb1b..c2c4ea3cf11 100644 --- a/query/point.gen.go.tmpl +++ b/query/point.gen.go.tmpl @@ -1,6 +1,7 @@ package query import ( + "context" "encoding/binary" "io" @@ -188,11 +189,12 @@ func (enc *{{.Name}}PointEncoder) Encode{{.Name}}Point(p *{{.Name}}Point) error type {{.Name}}PointDecoder struct { r io.Reader stats IteratorStats + ctx context.Context } // New{{.Name}}PointDecoder returns a new instance of {{.Name}}PointDecoder that reads from r. -func New{{.Name}}PointDecoder(r io.Reader) *{{.Name}}PointDecoder { - return &{{.Name}}PointDecoder{r: r} +func New{{.Name}}PointDecoder(ctx context.Context, r io.Reader) *{{.Name}}PointDecoder { + return &{{.Name}}PointDecoder{r: r, ctx: ctx} } // Stats returns iterator stats embedded within the stream. @@ -225,6 +227,15 @@ func (dec *{{.Name}}PointDecoder) Decode{{.Name}}Point(p *{{.Name}}Point) error continue } + if len(pb.Trace) > 0 { + var err error + err = decodeIteratorTrace(dec.ctx, pb.Trace) + if err != nil { + return err + } + continue + } + // Decode into point object. *p = *decode{{.Name}}Point(&pb)