-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcmd.go
233 lines (207 loc) · 5.27 KB
/
cmd.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
package proxysql
// proxysql admin commands
import (
"database/sql"
"github.com/juju/errors"
)
// define commands
const (
CmdProxyReadOnly = `PROXYSQL READONLY`
CmdProxyReadWrite = `PROXYSQL READWRITE`
CmdProxyStart = `PROXYSQL START`
CmdProxyRestart = `PROXYSQL RESTART`
CmdProxyStop = `PROXYSQL STOP`
CmdProxyPause = `PROXYSQL PAUSE`
CmdProxyResume = `PROXYSQL RESUME`
CmdProxyShutdown = `PROXYSQL SHUTDOWN`
CmdProxyFlushLogs = `PROXYSQL FLUSH LOGS`
CmdProxyKill = `PROXYSQL KILL`
CmdLoadUserToRuntime = `LOAD MYSQL USERS TO RUNTIME`
CmdSaveUserToDisk = `SAVE MYSQL USERS TO DISK`
CmdLoadServerToRuntime = `LOAD MYSQL SERVERS TO RUNTIME`
CmdSaveServerToDisk = `SAVE MYSQL SERVERS TO DISK`
CmdLoadQueryRulesToRuntime = `LOAD MYSQL QUERY RULES TO RUNTIME`
CmdSaveQueryRulesToDisk = `SAVE MYSQL QUERY RULES TO DISK`
CmdLoadSchedulerToRuntime = `LOAD SCHEDULER TO RUNTIME`
CmdSaveSchedulerToDisk = `SAVE SCHEDULER TO DISK`
CmdLoadMySQLVariablesToRuntime = `LOAD MYSQL VARIABLES TO RUNTIME`
CmdSaveMySQLVariablesToDisk = `SAVE MYSQL VARIABLES TO DISK`
CmdLoadAdminVariablesToRuntime = `LOAD ADMIN VARIABLES TO RUNTIME`
CmdSaveAdminVariablesToDisk = `SAVE ADMIN VARIABLES TO DISK`
)
//set proxysql to readonly mode.
func ProxyReadOnly(db *sql.DB) error {
_, err := db.Exec(CmdProxyReadOnly)
if err != nil {
return errors.Trace(err)
}
return nil
}
// set proxysql to readwrite mode.
func ProxyReadWrite(db *sql.DB) error {
_, err := db.Exec(CmdProxyReadWrite)
if err != nil {
return errors.Trace(err)
}
return nil
}
// start proxysql child process.
func ProxyStart(db *sql.DB) error {
_, err := db.Exec(CmdProxyStart)
if err != nil {
return errors.Trace(err)
}
return nil
}
// restart proxysql process.
func ProxyRestart(db *sql.DB) error {
_, err := db.Exec(CmdProxyRestart)
if err != nil {
return errors.Trace(err)
}
return nil
}
// stop proxysql child process.
func ProxyStop(db *sql.DB) error {
_, err := db.Exec(CmdProxyStop)
if err != nil {
return errors.Trace(err)
}
return nil
}
// pause proxysql
func ProxyPause(db *sql.DB) error {
_, err := db.Exec(CmdProxyPause)
if err != nil {
return errors.Trace(err)
}
return nil
}
// resume proxysql
func ProxyResume(db *sql.DB) error {
_, err := db.Exec(CmdProxyResume)
if err != nil {
return errors.Trace(err)
}
return nil
}
// shutdown proxysql
func ProxyShutdown(db *sql.DB) error {
_, err := db.Exec(CmdProxyShutdown)
if err != nil {
return errors.Trace(err)
}
return nil
}
// flush proxysql logs to file
func ProxyFlushLogs(db *sql.DB) error {
_, err := db.Exec(CmdProxyFlushLogs)
if err != nil {
return errors.Trace(err)
}
return nil
}
// kill child process.
func ProxyKill(db *sql.DB) error {
_, err := db.Exec(CmdProxyKill)
if err != nil {
return errors.Trace(err)
}
return nil
}
//execute load mysql users to runtime.
func LoadUserToRuntime(db *sql.DB) error {
_, err := db.Exec(CmdLoadUserToRuntime)
if err != nil {
return errors.Trace(err)
}
return nil
}
//execute save mysql users to disk.
func SaveUserToDisk(db *sql.DB) error {
_, err := db.Exec(CmdSaveUserToDisk)
if err != nil {
return errors.Trace(err)
}
return nil
}
// execute load mysql servers to runtime.
func LoadServerToRuntime(db *sql.DB) error {
_, err := db.Exec(CmdLoadServerToRuntime)
if err != nil {
return errors.Trace(err)
}
return nil
}
// execute save mysql servers to disk.
func SaveServerToDisk(db *sql.DB) error {
_, err := db.Exec(CmdSaveServerToDisk)
if err != nil {
return errors.Trace(err)
}
return nil
}
// execute load mysql query rules to runtime.
func LoadQueryRulesToRuntime(db *sql.DB) error {
_, err := db.Exec(CmdLoadQueryRulesToRuntime)
if err != nil {
return errors.Trace(err)
}
return nil
}
// execute save mysql query rules to disk.
func SaveQueryRulesToDisk(db *sql.DB) error {
_, err := db.Exec(CmdSaveQueryRulesToDisk)
if err != nil {
return errors.Trace(err)
}
return nil
}
// execute load schedulers to runtime.
func LoadSchedulerToRuntime(db *sql.DB) error {
_, err := db.Exec(CmdLoadSchedulerToRuntime)
if err != nil {
return errors.Trace(err)
}
return nil
}
// execute save schedulers to disk.
func SaveSchedulerToDisk(db *sql.DB) error {
_, err := db.Exec(CmdSaveSchedulerToDisk)
if err != nil {
return errors.Trace(err)
}
return nil
}
// execute load mysql variables to runtime.
func LoadMySQLVariablesToRuntime(db *sql.DB) error {
_, err := db.Exec(CmdLoadMySQLVariablesToRuntime)
if err != nil {
return errors.Trace(err)
}
return nil
}
// execute load admin variables to runtime.
func LoadAdminVariablesToRuntime(db *sql.DB) error {
_, err := db.Exec(CmdLoadAdminVariablesToRuntime)
if err != nil {
return errors.Trace(err)
}
return nil
}
// execute save mysql variables to runtime.
func SaveMySQLVariablesToDisk(db *sql.DB) error {
_, err := db.Exec(CmdSaveMySQLVariablesToDisk)
if err != nil {
return errors.Trace(err)
}
return nil
}
// execute save admin variables to disk.
func SaveAdminVariablesToDisk(db *sql.DB) error {
_, err := db.Exec(CmdSaveAdminVariablesToDisk)
if err != nil {
return errors.Trace(err)
}
return nil
}