-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
144 lines (119 loc) · 2.58 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"fmt"
"os"
"ptor/cli"
"ptor/db"
"ptor/global"
"ptor/locks"
"ptor/pool"
"ptor/repo"
"ptor/task"
"ptor/util"
"github.com/alexflint/go-arg"
"github.com/gammazero/workerpool"
)
var args cli.CliArgs
var Version string
var GitCommit string
var CommitDate string
func init() {
arg.MustParse(&args)
global.CliOpts = args
if args.About {
fmt.Println("Version: ", Version)
fmt.Println("Git Commit: ", GitCommit)
fmt.Println("Git Commit Date: ", CommitDate)
os.Exit(0)
}
if args.Init {
err := db.InitSchema()
if err != nil {
fmt.Println(err)
}
err = repo.InitSchema()
if err != nil {
fmt.Println(err)
}
os.Exit(0)
}
if args.Reset {
err := db.DropSchema()
if err != nil {
fmt.Println(err)
}
err = repo.DropSchema()
if err != nil {
fmt.Println(err)
}
os.Exit(0)
}
//Create lock map
locks.CreatePrimaryRelLocks()
locks.CreateRepoRelLocks()
//Create connection pool for the primary
pool.PrimaryPool = new(pool.Pool)
err := pool.PrimaryPool.InitPrimaryPool()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
//Create connection pool for the repo
pool.RepoPool = new(pool.Pool)
err = pool.RepoPool.InitRepoPool()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
util.HandleCntrlC(func() {
util.QuitNice()
})
// Check the percentages of ins,upd and del
if args.InsertPercent+args.DeletePercent+args.UpdatePercent != 100 {
fmt.Println("Insert, Update and Delete percentages should add up to 100")
os.Exit(1)
}
}
func bootstrapChecks() {
// Check repo and primary connections
fmt.Println("Trying to connect to primary instance ...")
err := db.CheckConnection()
if err != nil {
fmt.Println("Error connecting to primary instance: ", err)
os.Exit(1)
}
fmt.Println("Trying to connect to repo instance ...")
err = repo.CheckConnection()
if err != nil {
fmt.Println("Error connecting to repo instance: ", err)
os.Exit(1)
}
// Check if schema present
fmt.Println("Checking for ptor schema on primary instance ...")
err = db.CheckPtorSchema()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Checking for ptor schema on repo instance ...")
err = repo.CheckPtorSchema()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func main() {
global.PrimaryWorkerPool = workerpool.New(global.CliOpts.ParallelWorkers)
global.RepoWorkerPool = workerpool.New(1)
bootstrapChecks()
if global.CliOpts.CheckPrimaryLatency {
duration, err := task.CheckPrimaryLatency()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Primary latency: ", duration)
os.Exit(0)
}
task.Run()
}