93 lines
2.2 KiB
Cheetah
93 lines
2.2 KiB
Cheetah
package storage
|
|
|
|
import (
|
|
"github.com/influxdata/influxdb/tsdb"
|
|
)
|
|
|
|
|
|
{{range .}}
|
|
func (w *responseWriter) get{{.Name}}PointsFrame() *ReadResponse_Frame_{{.Name}}Points {
|
|
var res *ReadResponse_Frame_{{.Name}}Points
|
|
if len(w.buffer.{{.Name}}) > 0 {
|
|
i := len(w.buffer.{{.Name}}) - 1
|
|
res = w.buffer.{{.Name}}[i]
|
|
w.buffer.{{.Name}}[i] = nil
|
|
w.buffer.{{.Name}} = w.buffer.{{.Name}}[:i]
|
|
} else {
|
|
res = &ReadResponse_Frame_{{.Name}}Points{&ReadResponse_{{.Name}}PointsFrame{Timestamps: make([]int64, 0, batchSize), Values: make([]{{.Type}}, 0, batchSize)}}
|
|
}
|
|
|
|
return res
|
|
}
|
|
|
|
func (w *responseWriter) put{{.Name}}PointsFrame(f *ReadResponse_Frame_{{.Name}}Points) {
|
|
f.{{.Name}}Points.Timestamps = f.{{.Name}}Points.Timestamps[:0]
|
|
f.{{.Name}}Points.Values = f.{{.Name}}Points.Values[:0]
|
|
w.buffer.{{.Name}} = append(w.buffer.{{.Name}}, f)
|
|
}
|
|
|
|
func (w *responseWriter) stream{{.Name}}Series(cur tsdb.{{.Name}}BatchCursor) {
|
|
w.sf.DataType = DataType{{.Name}}
|
|
ss := len(w.res.Frames) - 1
|
|
ts, _ := cur.Next()
|
|
if len(ts) == 0 {
|
|
w.sz -= w.sf.Size()
|
|
w.putSeriesFrame(w.res.Frames[ss].Data.(*ReadResponse_Frame_Series))
|
|
w.res.Frames = w.res.Frames[:ss]
|
|
} else if w.sz > writeSize {
|
|
w.flushFrames()
|
|
}
|
|
}
|
|
|
|
func (w *responseWriter) stream{{.Name}}Points(cur tsdb.{{.Name}}BatchCursor) {
|
|
w.sf.DataType = DataType{{.Name}}
|
|
ss := len(w.res.Frames) - 1
|
|
|
|
p := w.get{{.Name}}PointsFrame()
|
|
frame := p.{{.Name}}Points
|
|
w.res.Frames = append(w.res.Frames, ReadResponse_Frame{p})
|
|
|
|
var (
|
|
seriesValueCount = 0
|
|
b = 0
|
|
)
|
|
|
|
for {
|
|
ts, vs := cur.Next()
|
|
if len(ts) == 0 {
|
|
break
|
|
}
|
|
|
|
frame.Timestamps = append(frame.Timestamps, ts...)
|
|
frame.Values = append(frame.Values, vs...)
|
|
|
|
b = len(frame.Timestamps)
|
|
if b >= batchSize {
|
|
seriesValueCount += b
|
|
b = 0
|
|
w.sz += frame.Size()
|
|
if w.sz >= writeSize {
|
|
w.flushFrames()
|
|
if w.err != nil {
|
|
break
|
|
}
|
|
}
|
|
|
|
p = w.get{{.Name}}PointsFrame()
|
|
frame = p.{{.Name}}Points
|
|
w.res.Frames = append(w.res.Frames, ReadResponse_Frame{p})
|
|
}
|
|
}
|
|
|
|
seriesValueCount += b
|
|
w.vc += seriesValueCount
|
|
if seriesValueCount == 0 {
|
|
w.sz -= w.sf.Size()
|
|
w.putSeriesFrame(w.res.Frames[ss].Data.(*ReadResponse_Frame_Series))
|
|
w.res.Frames = w.res.Frames[:ss]
|
|
} else if w.sz > writeSize {
|
|
w.flushFrames()
|
|
}
|
|
}
|
|
{{end}}
|