/
tidb2kafka2redshift.go
293 lines (248 loc) · 9 KB
/
tidb2kafka2redshift.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
// Copyright 2020 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package command
import (
// "errors"
// "fmt"
"os"
"path"
// "github.com/luyomo/OhMyTiUP/embed"
"github.com/luyomo/OhMyTiUP/pkg/aws/manager"
operator "github.com/luyomo/OhMyTiUP/pkg/aws/operation"
"github.com/luyomo/OhMyTiUP/pkg/aws/spec"
"github.com/luyomo/OhMyTiUP/pkg/set"
"github.com/luyomo/OhMyTiUP/pkg/tui"
"github.com/luyomo/OhMyTiUP/pkg/utils"
perrs "github.com/pingcap/errors"
"github.com/spf13/cobra"
)
func newTiDB2Kafka2RedshiftCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "tidb2kafka2redshift <sub_command>",
Short: "Run commands for syncing the data to redshift from tidb through kafka",
}
cmd.AddCommand(
newTiDB2Kafka2RedshiftDeploy(),
newListTiDB2Kafka2RedshiftCmd(),
newDestroyTiDB2Kafka2RedshiftCmd(),
newTiDB2Kafka2RedshiftPerfCmd(),
newTiDB2Kafka2ESTplCmd(),
)
return cmd
}
func newTiDB2Kafka2RedshiftPerfCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "perf <sub_command>",
Short: "Run measure latency against tidb",
}
cmd.AddCommand(
newPerfPrepareTiDB2Kafka2Redshift(),
newPerfTiDB2Kafka2Redshift(),
newPerfCleanTiDB2Kafka2Redshift(),
)
return cmd
}
func newTiDB2Kafka2RedshiftDeploy() *cobra.Command {
opt := manager.TiDB2Kafka2PgDeployOptions{
IdentityFile: path.Join(utils.UserHome(), ".ssh", "id_rsa"),
}
cmd := &cobra.Command{
Use: "deploy <cluster-name> <topology.yaml>",
Short: "Deploy TiDB + kafka + Redshift",
Long: "Deploy an migration flow tidb - kafka - Redshift demo. SSH connection will be used to deploy files, as well as creating system users for running the service.",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
shouldContinue, err := tui.CheckCommandArgsAndMayPrintHelp(cmd, args, 2)
if err != nil {
return err
}
if !shouldContinue {
return nil
}
clusterName := args[0]
topoFile := args[1]
if data, err := os.ReadFile(topoFile); err == nil {
teleTopology = string(data)
}
return cm.TiDB2Kafka2RedshiftDeploy(clusterName, "ohmytiup-tidb2kafka2redshift", topoFile, opt, gOpt)
},
}
cmd.Flags().StringVarP(&opt.User, "user", "u", utils.CurrentUser(), "The user name to login via SSH. The user must has root (or sudo) privilege.")
return cmd
}
func newListTiDB2Kafka2RedshiftCmd() *cobra.Command {
opt := manager.DeployOptions{
IdentityFile: path.Join(utils.UserHome(), ".ssh", "id_rsa"),
}
cmd := &cobra.Command{
Use: "list <cluster-name>",
Short: "List all clusters or cluster of aurora db",
RunE: func(cmd *cobra.Command, args []string) error {
shouldContinue, err := tui.CheckCommandArgsAndMayPrintHelp(cmd, args, 1)
if err != nil {
return err
}
if !shouldContinue {
return nil
}
clusterName := args[0]
return cm.ListTiDB2Kafka2RedshiftCluster(clusterName, "ohmytiup-tidb2kafka2redshift", opt)
},
}
cmd.Flags().StringVarP(&opt.User, "user", "u", utils.CurrentUser(), "The user name to login via SSH. The user must has root (or sudo) privilege.")
return cmd
}
func newDestroyTiDB2Kafka2RedshiftCmd() *cobra.Command {
destroyOpt := operator.Options{}
cmd := &cobra.Command{
Use: "destroy <cluster-name>",
Short: "Destroy a specified cluster",
Long: `Destroy a specified cluster, which will clean the deployment binaries and data.
You can retain some nodes and roles data when destroy cluster, eg:
$ tiup cluster destroy <cluster-name> --retain-role-data prometheus
$ tiup cluster destroy <cluster-name> --retain-node-data 172.16.13.11:9000
$ tiup cluster destroy <cluster-name> --retain-node-data 172.16.13.12`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return cmd.Help()
}
clusterName := args[0]
clusterReport.ID = scrubClusterName(clusterName)
teleCommand = append(teleCommand, scrubClusterName(clusterName))
// Validate the retained roles to prevent unexpected deleting data
if len(destroyOpt.RetainDataRoles) > 0 {
validRoles := set.NewStringSet(spec.AllComponentNames()...)
for _, role := range destroyOpt.RetainDataRoles {
if !validRoles.Exist(role) {
return perrs.Errorf("role name `%s` invalid", role)
}
}
}
return cm.DestroyTiDB2Kafka2RedshiftCluster(clusterName, "ohmytiup-tidb2kafka2redshift", gOpt, destroyOpt, skipConfirm)
},
}
cmd.Flags().StringArrayVar(&destroyOpt.RetainDataNodes, "retain-node-data", nil, "Specify the nodes or hosts whose data will be retained")
cmd.Flags().StringArrayVar(&destroyOpt.RetainDataRoles, "retain-role-data", nil, "Specify the roles whose data will be retained")
cmd.Flags().BoolVar(&destroyOpt.Force, "force", false, "Force will ignore remote error while destroy the cluster")
return cmd
}
func newPerfPrepareTiDB2Kafka2Redshift() *cobra.Command {
perfOpt := manager.KafkaPerfOpt{
Partitions: 1,
NumOfRecords: 100000,
BytesOfRecord: 1024,
}
cmd := &cobra.Command{
Use: "prepare <cluster-name>",
Short: "perf performance test preparation",
Long: "Performance measurement against kafka cluster",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
shouldContinue, err := tui.CheckCommandArgsAndMayPrintHelp(cmd, args, 1)
if err != nil {
return err
}
if !shouldContinue {
return nil
}
clusterName := args[0]
return cm.PerfPrepareTiDB2Kafka2Redshift(clusterName, "ohmytiup-tidb2kafka2redshift", perfOpt, gOpt)
},
}
cmd.Flags().IntVar(&perfOpt.Partitions, "partitions", 16, "The partition number of the topic to be tested.")
cmd.Flags().IntVar(&perfOpt.NumOfRecords, "num-of-records", 100000, "The number of messages to be tested")
cmd.Flags().IntVar(&perfOpt.BytesOfRecord, "bytes-of-record", 1024, "Bytes of records to be tested")
cmd.Flags().StringArrayVar(&perfOpt.DataTypeDtr, "data-type", nil, "Specify all the data types to be tested")
return cmd
}
func newPerfTiDB2Kafka2Redshift() *cobra.Command {
perfOpt := manager.KafkaPerfOpt{
NumOfRecords: 100000,
}
cmd := &cobra.Command{
Use: "run <cluster-name>",
Short: "perf performance test",
Long: "Performance measurement against kafka cluster",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
shouldContinue, err := tui.CheckCommandArgsAndMayPrintHelp(cmd, args, 1)
if err != nil {
return err
}
if !shouldContinue {
return nil
}
clusterName := args[0]
return cm.PerfTiDB2Kafka2Redshift(clusterName, "ohmytiup-tidb2kafka2redshift", perfOpt, gOpt)
},
}
cmd.Flags().IntVar(&perfOpt.NumOfRecords, "num-of-records", 100000, "The number of messages to be tested")
return cmd
}
func newPerfCleanTiDB2Kafka2Redshift() *cobra.Command {
cmd := &cobra.Command{
Use: "clean <cluster-name>",
Short: "clean perf performance test",
Long: "Performance measurement against kafka cluster",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
shouldContinue, err := tui.CheckCommandArgsAndMayPrintHelp(cmd, args, 1)
if err != nil {
return err
}
if !shouldContinue {
return nil
}
clusterName := args[0]
return cm.PerfCleanTiDB2Kafka2Redshift(clusterName, "ohmytiup-tidb2kafka2redshift", gOpt)
},
}
return cmd
}
// type TemplateTiDB2ESOptions struct {
// OP bool // print template for On Premise
// Simple bool // print template for TiDB and ES only
// MSK bool // print template using MSK/Glue
// }
// func newTiDB2Kafka2ESTplCmd() *cobra.Command {
// opt := TemplateTiDB2ESOptions{}
// cmd := &cobra.Command{
// Use: "template",
// Short: "Print topology template",
// RunE: func(cmd *cobra.Command, args []string) error {
// if sumBool(opt.OP, opt.Simple, opt.MSK) > 1 {
// return errors.New("at most one of 'OP', 'Simple', or 'MSK' can be specified")
// }
// name := "aws-nodes-tidb2kafka2es.yaml"
// switch {
// case opt.OP:
// name = "aws-nodes-tidb2kafka2es.yaml"
// case opt.MSK:
// name = "aws-nodes-tidb2kafka2es.msk.yaml"
// case opt.Simple:
// name = "aws-nodes-tidb2kafka2es.simple.yaml"
// }
// fp := path.Join("examples", "aws", name)
// tpl, err := embed.ReadExample(fp)
// if err != nil {
// return err
// }
// fmt.Println(string(tpl))
// return nil
// },
// }
// cmd.Flags().BoolVar(&opt.OP, "op", false, "Print the op topology template for TiDB to ES cluster.")
// cmd.Flags().BoolVar(&opt.MSK, "msk", false, "Print the msk topology template for TiDB to ES cluster.")
// cmd.Flags().BoolVar(&opt.Simple, "simple", false, "Print template for deploying a TiDB and ES only.")
// return cmd
// }