forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 2
/
legacy_split_clone_cmd.go
198 lines (178 loc) · 8.39 KB
/
legacy_split_clone_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
/*
Copyright 2017 Google 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,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package worker
// TODO(mberlin): Remove this file when SplitClone supports merge-sorting
// primary key columns based on the MySQL collation.
import (
"flag"
"fmt"
"html/template"
"net/http"
"strconv"
"strings"
"github.com/xsec-lab/go/vt/vterrors"
"github.com/xsec-lab/go/vt/topo/topoproto"
"github.com/xsec-lab/go/vt/wrangler"
"golang.org/x/net/context"
)
const legacySplitCloneHTML = `
<!DOCTYPE html>
<head>
<title>Legacy Split Clone Action</title>
</head>
<body>
<h1>Legacy Split Clone Action</h1>
<h2>Use this command only when the 'SplitClone' command told you so. Otherwise use the 'SplitClone' command.</h2>
{{if .Error}}
<b>Error:</b> {{.Error}}</br>
{{else}}
<p>Choose the destination keyspace for this action.</p>
<ul>
{{range $i, $si := .Choices}}
<li><a href="/Clones/LegacySplitClone?keyspace={{$si.Keyspace}}&shard={{$si.Shard}}">{{$si.Keyspace}}/{{$si.Shard}}</a></li>
{{end}}
</ul>
{{end}}
</body>
`
const legacySplitCloneHTML2 = `
<!DOCTYPE html>
<head>
<title>Legacy Split Clone Action</title>
</head>
<body>
<p>Shard involved: {{.Keyspace}}/{{.Shard}}</p>
<h1>Split Clone Action</h1>
<form action="/Clones/LegacySplitClone" method="post">
<LABEL for="excludeTables">Exclude Tables: </LABEL>
<INPUT type="text" id="excludeTables" name="excludeTables" value="/ignored/"></BR>
<LABEL for="sourceReaderCount">Source Reader Count: </LABEL>
<INPUT type="text" id="sourceReaderCount" name="sourceReaderCount" value="{{.DefaultSourceReaderCount}}"></BR>
<LABEL for="destinationPackCount">Destination Pack Count: </LABEL>
<INPUT type="text" id="destinationPackCount" name="destinationPackCount" value="{{.DefaultDestinationPackCount}}"></BR>
<LABEL for="destinationWriterCount">Destination Writer Count: </LABEL>
<INPUT type="text" id="destinationWriterCount" name="destinationWriterCount" value="{{.DefaultDestinationWriterCount}}"></BR>
<LABEL for="minHealthyRdonlyTablets">Minimum Number of required healthy RDONLY tablets: </LABEL>
<INPUT type="text" id="minHealthyRdonlyTablets" name="minHealthyRdonlyTablets" value="{{.DefaultMinHealthyRdonlyTablets}}"></BR>
<LABEL for="maxTPS">Maximum Write Transactions/second (If non-zero, writes on the destination will be throttled. Unlimited by default.): </LABEL>
<INPUT type="text" id="maxTPS" name="maxTPS" value="{{.DefaultMaxTPS}}"></BR>
<INPUT type="hidden" name="keyspace" value="{{.Keyspace}}"/>
<INPUT type="hidden" name="shard" value="{{.Shard}}"/>
<INPUT type="submit" value="Clone"/>
</form>
</body>
`
var legacySplitCloneTemplate = mustParseTemplate("splitClone", legacySplitCloneHTML)
var legacySplitCloneTemplate2 = mustParseTemplate("splitClone2", legacySplitCloneHTML2)
func commandLegacySplitClone(wi *Instance, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (Worker, error) {
excludeTables := subFlags.String("exclude_tables", "", "comma separated list of tables to exclude. Each is either an exact match, or a regular expression of the form /regexp/")
sourceReaderCount := subFlags.Int("source_reader_count", defaultSourceReaderCount, "number of concurrent streaming queries to use on the source")
destinationPackCount := subFlags.Int("destination_pack_count", defaultDestinationPackCount, "number of packets to pack in one destination insert")
destinationWriterCount := subFlags.Int("destination_writer_count", defaultDestinationWriterCount, "number of concurrent RPCs to execute on the destination")
minHealthyRdonlyTablets := subFlags.Int("min_healthy_rdonly_tablets", defaultMinHealthyRdonlyTablets, "minimum number of healthy RDONLY tablets before taking out one")
maxTPS := subFlags.Int64("max_tps", defaultMaxTPS, "if non-zero, limit copy to maximum number of (write) transactions/second on the destination (unlimited by default)")
if err := subFlags.Parse(args); err != nil {
return nil, err
}
if subFlags.NArg() != 1 {
subFlags.Usage()
return nil, fmt.Errorf("command LegacySplitClone requires <keyspace/shard>")
}
keyspace, shard, err := topoproto.ParseKeyspaceShard(subFlags.Arg(0))
if err != nil {
return nil, err
}
var excludeTableArray []string
if *excludeTables != "" {
excludeTableArray = strings.Split(*excludeTables, ",")
}
worker, err := NewLegacySplitCloneWorker(wr, wi.cell, keyspace, shard, excludeTableArray, *sourceReaderCount, *destinationPackCount, *destinationWriterCount, *minHealthyRdonlyTablets, *maxTPS)
if err != nil {
return nil, vterrors.Wrap(err, "cannot create split clone worker")
}
return worker, nil
}
func interactiveLegacySplitClone(ctx context.Context, wi *Instance, wr *wrangler.Wrangler, w http.ResponseWriter, r *http.Request) (Worker, *template.Template, map[string]interface{}, error) {
if err := r.ParseForm(); err != nil {
return nil, nil, nil, vterrors.Wrap(err, "cannot parse form")
}
keyspace := r.FormValue("keyspace")
shard := r.FormValue("shard")
if keyspace == "" || shard == "" {
// display the list of possible splits to choose from
// (just find all the overlapping guys)
result := make(map[string]interface{})
choices, err := keyspacesWithOverlappingShards(ctx, wr)
if err != nil {
result["Error"] = err.Error()
} else {
result["Choices"] = choices
}
return nil, legacySplitCloneTemplate, result, nil
}
sourceReaderCountStr := r.FormValue("sourceReaderCount")
if sourceReaderCountStr == "" {
// display the input form
result := make(map[string]interface{})
result["Keyspace"] = keyspace
result["Shard"] = shard
result["DefaultSourceReaderCount"] = fmt.Sprintf("%v", defaultSourceReaderCount)
result["DefaultDestinationPackCount"] = fmt.Sprintf("%v", defaultDestinationPackCount)
result["DefaultDestinationWriterCount"] = fmt.Sprintf("%v", defaultDestinationWriterCount)
result["DefaultMinHealthyRdonlyTablets"] = fmt.Sprintf("%v", defaultMinHealthyRdonlyTablets)
result["DefaultMaxTPS"] = fmt.Sprintf("%v", defaultMaxTPS)
return nil, legacySplitCloneTemplate2, result, nil
}
// get other parameters
destinationPackCountStr := r.FormValue("destinationPackCount")
excludeTables := r.FormValue("excludeTables")
var excludeTableArray []string
if excludeTables != "" {
excludeTableArray = strings.Split(excludeTables, ",")
}
sourceReaderCount, err := strconv.ParseInt(sourceReaderCountStr, 0, 64)
if err != nil {
return nil, nil, nil, vterrors.Wrap(err, "cannot parse sourceReaderCount")
}
destinationPackCount, err := strconv.ParseInt(destinationPackCountStr, 0, 64)
if err != nil {
return nil, nil, nil, vterrors.Wrap(err, "cannot parse destinationPackCount")
}
destinationWriterCountStr := r.FormValue("destinationWriterCount")
destinationWriterCount, err := strconv.ParseInt(destinationWriterCountStr, 0, 64)
if err != nil {
return nil, nil, nil, vterrors.Wrap(err, "cannot parse destinationWriterCount")
}
minHealthyRdonlyTabletsStr := r.FormValue("minHealthyRdonlyTablets")
minHealthyRdonlyTablets, err := strconv.ParseInt(minHealthyRdonlyTabletsStr, 0, 64)
if err != nil {
return nil, nil, nil, vterrors.Wrap(err, "cannot parse minHealthyRdonlyTablets")
}
maxTPSStr := r.FormValue("maxTPS")
maxTPS, err := strconv.ParseInt(maxTPSStr, 0, 64)
if err != nil {
return nil, nil, nil, vterrors.Wrap(err, "cannot parse maxTPS")
}
// start the clone job
wrk, err := NewLegacySplitCloneWorker(wr, wi.cell, keyspace, shard, excludeTableArray, int(sourceReaderCount), int(destinationPackCount), int(destinationWriterCount), int(minHealthyRdonlyTablets), maxTPS)
if err != nil {
return nil, nil, nil, vterrors.Wrap(err, "cannot create worker")
}
return wrk, nil, nil, nil
}
func init() {
AddCommand("Clones", Command{"LegacySplitClone",
commandLegacySplitClone, interactiveLegacySplitClone,
"[--exclude_tables=''] <keyspace/shard>",
"Old SplitClone code which supports VARCHAR primary key columns. Use this ONLY if SplitClone failed for you."})
}