forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
55 lines (48 loc) · 1.05 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"bytes"
"encoding/binary"
"math/rand"
"time"
"code.google.com/p/goprotobuf/proto"
"github.com/influxdb/influxdb/datastore/storage"
"github.com/influxdb/influxdb/protocol"
)
type Config struct {
points int
batch int
series int
nextSeriesId int
nextSequence int64
now time.Time
path string
threads int
}
func (c *Config) MakeBatch() []storage.Write {
ws := make([]storage.Write, 0, c.batch)
for b := c.batch; b > 0; b-- {
key := bytes.NewBuffer(nil)
binary.Write(key, binary.BigEndian, int64(c.nextSeriesId))
binary.Write(key, binary.BigEndian, c.now.UnixNano()/1000)
binary.Write(key, binary.BigEndian, c.nextSequence)
v := rand.Int63()
fv := &protocol.FieldValue{
Int64Value: &v,
}
b, err := proto.Marshal(fv)
if err != nil {
panic(err)
}
ws = append(ws, storage.Write{
Key: key.Bytes(),
Value: b,
})
c.nextSeriesId++
if c.nextSeriesId >= c.series {
c.nextSeriesId = 0
}
c.nextSequence++
c.now = c.now.Add(time.Microsecond)
}
return ws
}