/
pg2kafka2tidb.go
246 lines (208 loc) · 7.37 KB
/
pg2kafka2tidb.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
// 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 (
// "fmt"
"os"
"path"
"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 newPG2Kafka2TiDBCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "pg2kafka2tidb <sub_command>",
Short: "Run commands for syncing the data to tidb from pg through kafka",
}
cmd.AddCommand(
newPG2Kafka2TiDBDeploy(),
newListPG2Kafka2TiDBCmd(),
newDestroyPG2Kafka2TiDBCmd(),
newPG2Kafka2TiDBPerfCmd(),
)
return cmd
}
func newPG2Kafka2TiDBPerfCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "perf <sub_command>",
Short: "Run measure latency against postgres",
}
cmd.AddCommand(
newPerfPreparePG2Kafka2TiDB(),
newPerfPG2Kafka2TiDB(),
newPerfCleanPG2Kafka2TiDB(),
)
return cmd
}
func newPG2Kafka2TiDBDeploy() *cobra.Command {
opt := manager.TiDB2Kafka2PgDeployOptions{
IdentityFile: path.Join(utils.UserHome(), ".ssh", "id_rsa"),
}
cmd := &cobra.Command{
Use: "deploy <cluster-name> <topology.yaml>",
Short: "Deploy an Kafka Cluster on aws",
Long: "Deploy an Kafka Cluster for 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.TiDB2Kafka2PgDeploy(clusterName, "ohmytiup-tidb2kafka2pg", 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 newListPG2Kafka2TiDBCmd() *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.ListTiDB2Kafka2PgCluster(clusterName, "ohmytiup-tidb2kafka2pg", 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 newDestroyPG2Kafka2TiDBCmd() *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.DestroyTiDB2Kafka2PgCluster(clusterName, "ohmytiup-tidb2kafka2pg", 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 newPerfPreparePG2Kafka2TiDB() *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.PerfPreparePG2Kafka2TiDB(clusterName, "ohmytiup-tidb2kafka2pg", 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 newPerfPG2Kafka2TiDB() *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.PerfPG2Kafka2TiDB(clusterName, "ohmytiup-tidb2kafka2pg", perfOpt, gOpt)
},
}
cmd.Flags().IntVar(&perfOpt.NumOfRecords, "num-of-records", 100000, "The number of messages to be tested")
return cmd
}
func newPerfCleanPG2Kafka2TiDB() *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.PerfCleanPG2Kafka2TiDB(clusterName, "ohmytiup-tidb2kafka2pg", gOpt)
},
}
return cmd
}