-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
121 lines (99 loc) · 2.67 KB
/
main.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// bulk_load_cnosdb loads an CnosDB daemon with data from stdin.
//
// The caller is responsible for assuring that the database is empty before
// bulk load.
package main
import (
"bufio"
"bytes"
"fmt"
"log"
"strings"
"sync"
"time"
"github.com/blagojts/viper"
"github.com/cnosdb/tsdb-comparisons/internal/utils"
"github.com/cnosdb/tsdb-comparisons/load"
"github.com/cnosdb/tsdb-comparisons/pkg/targets"
"github.com/cnosdb/tsdb-comparisons/pkg/targets/constants"
"github.com/cnosdb/tsdb-comparisons/pkg/targets/initializers"
"github.com/spf13/pflag"
)
// Program option vars:
var (
daemonURLs []string
replicationFactor int
backoff time.Duration
useGzip bool
doAbortOnExist bool
consistency string
)
// Global vars
var (
loader load.BenchmarkRunner
config load.BenchmarkRunnerConfig
bufPool sync.Pool
target targets.ImplementedTarget
)
var consistencyChoices = map[string]struct{}{
"any": {},
"one": {},
"quorum": {},
"all": {},
}
// allows for testing
var fatal = log.Fatalf
// Parse args:
func init() {
target = initializers.GetTarget(constants.FormatCnosDB)
config = load.BenchmarkRunnerConfig{}
config.AddToFlagSet(pflag.CommandLine)
target.TargetSpecificFlags("", pflag.CommandLine)
var csvDaemonURLs string
pflag.Parse()
err := utils.SetupConfigFile()
if err != nil {
panic(fmt.Errorf("fatal error config file: %s", err))
}
if err := viper.Unmarshal(&config); err != nil {
panic(fmt.Errorf("unable to decode config: %s", err))
}
csvDaemonURLs = viper.GetString("urls")
replicationFactor = viper.GetInt("replication-factor")
consistency = viper.GetString("consistency")
backoff = viper.GetDuration("backoff")
useGzip = viper.GetBool("gzip")
if _, ok := consistencyChoices[consistency]; !ok {
log.Fatalf("invalid consistency settings")
}
daemonURLs = strings.Split(csvDaemonURLs, ",")
if len(daemonURLs) == 0 {
log.Fatal("missing 'urls' flag")
}
config.HashWorkers = false
loader = load.GetBenchmarkRunner(config)
}
type benchmark struct{}
func (b *benchmark) GetDataSource() targets.DataSource {
return &fileDataSource{scanner: bufio.NewScanner(load.GetBufferedReader(config.FileName))}
}
func (b *benchmark) GetBatchFactory() targets.BatchFactory {
return &factory{}
}
func (b *benchmark) GetPointIndexer(_ uint) targets.PointIndexer {
return &targets.ConstantIndexer{}
}
func (b *benchmark) GetProcessor() targets.Processor {
return &processor{}
}
func (b *benchmark) GetDBCreator() targets.DBCreator {
return &dbCreator{}
}
func main() {
bufPool = sync.Pool{
New: func() interface{} {
return bytes.NewBuffer(make([]byte, 0, 4*1024*1024))
},
}
loader.RunBenchmark(&benchmark{})
}