forked from vitessio/vitess
/
vtctl.go
1905 lines (1717 loc) · 74.3 KB
/
vtctl.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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"bufio"
"flag"
"fmt"
"io/ioutil"
"log/syslog"
"net"
"os"
"os/signal"
"sort"
"strings"
"syscall"
"time"
log "github.com/golang/glog"
"github.com/youtube/vitess/go/exit"
"github.com/youtube/vitess/go/flagutil"
"github.com/youtube/vitess/go/jscfg"
"github.com/youtube/vitess/go/vt/client2"
hk "github.com/youtube/vitess/go/vt/hook"
"github.com/youtube/vitess/go/vt/key"
"github.com/youtube/vitess/go/vt/logutil"
myproto "github.com/youtube/vitess/go/vt/mysqlctl/proto"
"github.com/youtube/vitess/go/vt/tabletmanager/actionnode"
"github.com/youtube/vitess/go/vt/tabletmanager/initiator"
"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/wrangler"
)
var (
noWaitForAction = flag.Bool("no-wait", false, "don't wait for action completion, detach")
waitTime = flag.Duration("wait-time", 24*time.Hour, "time to wait on an action")
lockWaitTimeout = flag.Duration("lock-wait-timeout", 0, "time to wait for a lock before starting an action")
)
type command struct {
name string
method func(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error)
params string
help string // if help is empty, won't list the command
}
type commandGroup struct {
name string
commands []command
}
var commands = []commandGroup{
commandGroup{
"Tablets", []command{
command{"InitTablet", commandInitTablet,
"[-force] [-parent] [-update] [-db-name-override=<db name>] [-hostname=<hostname>] [-mysql_port=<port>] [-port=<port>] [-vts_port=<port>] [-keyspace=<keyspace>] [-shard=<shard>] [-parent_alias=<parent alias>] <tablet alias> <tablet type>]",
"Initializes a tablet in the topology.\n" +
"Valid <tablet type>:\n" +
" " + strings.Join(topo.MakeStringTypeList(topo.AllTabletTypes), " ")},
command{"GetTablet", commandGetTablet,
"<tablet alias|zk tablet path>",
"Outputs the json version of Tablet to stdout."},
command{"UpdateTabletAddrs", commandUpdateTabletAddrs,
"[-hostname <hostname>] [-ip-addr <ip addr>] [-mysql-port <mysql port>] [-vt-port <vt port>] [-vts-port <vts port>] <tablet alias|zk tablet path> ",
"Updates the addresses of a tablet."},
command{"ScrapTablet", commandScrapTablet,
"[-force] [-skip-rebuild] <tablet alias|zk tablet path>",
"Scraps a tablet."},
command{"DeleteTablet", commandDeleteTablet,
"<tablet alias|zk tablet path> ...",
"Deletes scrapped tablet(s) from the topology."},
command{"SetReadOnly", commandSetReadOnly,
"[<tablet alias|zk tablet path>]",
"Sets the tablet as ReadOnly."},
command{"SetReadWrite", commandSetReadWrite,
"[<tablet alias|zk tablet path>]",
"Sets the tablet as ReadWrite."},
command{"SetBlacklistedTables", commandSetBlacklistedTables,
"[<tablet alias|zk tablet path>] [table1,table2,...]",
"Sets the list of blacklisted tables for a tablet. Use no tables to clear the list."},
command{"ChangeSlaveType", commandChangeSlaveType,
"[-force] [-dry-run] <tablet alias|zk tablet path> <tablet type>",
"Change the db type for this tablet if possible. This is mostly for arranging replicas - it will not convert a master.\n" +
"NOTE: This will automatically update the serving graph.\n" +
"Valid <tablet type>:\n" +
" " + strings.Join(topo.MakeStringTypeList(topo.SlaveTabletTypes), " ")},
command{"Ping", commandPing,
"<tablet alias|zk tablet path>",
"Check that the agent is awake and responding - can be blocked by other in-flight operations."},
command{"RpcPing", commandRpcPing,
"<tablet alias|zk tablet path>",
"Check that the agent is awake and responding to RPCs."},
command{"Query", commandQuery,
"<cell> <keyspace> <query>",
"Send a SQL query to a tablet."},
command{"Sleep", commandSleep,
"<tablet alias|zk tablet path> <duration>",
"Block the action queue for the specified duration (mostly for testing)."},
command{"Snapshot", commandSnapshot,
"[-force] [-server-mode] [-concurrency=4] <tablet alias|zk tablet path>",
"Stop mysqld and copy compressed data aside."},
command{"SnapshotSourceEnd", commandSnapshotSourceEnd,
"[-slave-start] [-read-write] <tablet alias|zk tablet path> <original tablet type>",
"Restart Mysql and restore original server type." +
"Valid <tablet type>:\n" +
" " + strings.Join(topo.MakeStringTypeList(topo.AllTabletTypes), " ")},
command{"Restore", commandRestore,
"[-fetch-concurrency=3] [-fetch-retry-count=3] [-dont-wait-for-slave-start] <src tablet alias|zk src tablet path> <src manifest file> <dst tablet alias|zk dst tablet path> [<zk new master path>]",
"Copy the given snaphot from the source tablet and restart replication to the new master path (or uses the <src tablet path> if not specified). If <src manifest file> is 'default', uses the default value.\n" +
"NOTE: This does not wait for replication to catch up. The destination tablet must be 'idle' to begin with. It will transition to 'spare' once the restore is complete."},
command{"Clone", commandClone,
"[-force] [-concurrency=4] [-fetch-concurrency=3] [-fetch-retry-count=3] [-server-mode] <src tablet alias|zk src tablet path> <dst tablet alias|zk dst tablet path> ...",
"This performs Snapshot and then Restore on all the targets in parallel. The advantage of having separate actions is that one snapshot can be used for many restores, and it's then easier to spread them over time."},
command{"MultiSnapshot", commandMultiSnapshot,
"[-force] [-concurrency=8] [-skip-slave-restart] [-maximum-file-size=134217728] -spec='-' [-tables=''] [-exclude_tables=''] <tablet alias|zk tablet path>",
"Locks mysqld and copy compressed data aside."},
command{"MultiRestore", commandMultiRestore,
"[-force] [-concurrency=4] [-fetch-concurrency=4] [-insert-table-concurrency=4] [-fetch-retry-count=3] [-strategy=] <dst tablet alias|destination zk path> <source zk path>...",
"Restores a snapshot from multiple hosts."},
command{"ExecuteHook", commandExecuteHook,
"<tablet alias|zk tablet path> <hook name> [<param1=value1> <param2=value2> ...]",
"This runs the specified hook on the given tablet."},
command{"ReadTabletAction", commandReadTabletAction,
"<action path>)",
"Displays the action node as json."},
command{"ExecuteFetch", commandExecuteFetch,
"[--max_rows=10000] [--want_fields] [--disable_binlogs] <tablet alias|zk tablet path> <sql command>",
"Runs the given sql command as a DBA on the remote tablet"},
},
},
commandGroup{
"Shards", []command{
command{"CreateShard", commandCreateShard,
"[-force] [-parent] <keyspace/shard|zk shard path>",
"Creates the given shard"},
command{"GetShard", commandGetShard,
"<keyspace/shard|zk shard path>",
"Outputs the json version of Shard to stdout."},
command{"RebuildShardGraph", commandRebuildShardGraph,
"[-cells=a,b] <zk shard path> ... (/zk/global/vt/keyspaces/<keyspace>/shards/<shard>)",
"Rebuild the replication graph and shard serving data in zk. This may trigger an update to all connected clients."},
command{"ShardExternallyReparented", commandShardExternallyReparented,
"<keyspace/shard|zk shard path> <tablet alias|zk tablet path>",
"Changes metadata to acknowledge a shard master change performed by an external tool."},
command{"ValidateShard", commandValidateShard,
"[-ping-tablets] <keyspace/shard|zk shard path>",
"Validate all nodes reachable from this shard are consistent."},
command{"ShardReplicationPositions", commandShardReplicationPositions,
"<keyspace/shard|zk shard path>",
"Show slave status on all machines in the shard graph."},
command{"ListShardTablets", commandListShardTablets,
"<keyspace/shard|zk shard path>)",
"List all tablets in a given shard."},
command{"SetShardServedTypes", commandSetShardServedTypes,
"<keyspace/shard|zk shard path> [<served type1>,<served type2>,...]",
"Sets a given shard's served types. Does not rebuild any serving graph."},
command{"ShardMultiRestore", commandShardMultiRestore,
"[-force] [-concurrency=4] [-fetch-concurrency=4] [-insert-table-concurrency=4] [-fetch-retry-count=3] [-strategy=] [-tables=<table1>,<table2>,...] <keyspace/shard|zk shard path> <source zk path>...",
"Restore multi-snapshots on all the tablets of a shard."},
command{"ShardReplicationAdd", commandShardReplicationAdd,
"<keyspace/shard|zk shard path> <tablet alias|zk tablet path> <parent tablet alias|zk parent tablet path>",
"HIDDEN Adds an entry to the replication graph in the given cell"},
command{"ShardReplicationRemove", commandShardReplicationRemove,
"<keyspace/shard|zk shard path> <tablet alias|zk tablet path>",
"HIDDEN Removes an entry to the replication graph in the given cell"},
command{"ShardReplicationFix", commandShardReplicationFix,
"<cell> <keyspace/shard|zk shard path>",
"Walks through a ShardReplication object and fixes the first error it encrounters"},
command{"RemoveShardCell", commandRemoveShardCell,
"[-force] <keyspace/shard|zk shard path> <cell>",
"Removes the cell in the shard's Cells list."},
command{"DeleteShard", commandDeleteShard,
"<keyspace/shard|zk shard path> ...",
"Deletes the given shard(s)"},
},
},
commandGroup{
"Keyspaces", []command{
command{"CreateKeyspace", commandCreateKeyspace,
"[-sharding_column_name=name] [-sharding_column_type=type] [-served-from=tablettype1:ks1,tablettype2,ks2,...] [-force] <keyspace name|zk keyspace path>",
"Creates the given keyspace"},
command{"GetKeyspace", commandGetKeyspace,
"<keyspace|zk keyspace path>",
"Outputs the json version of Keyspace to stdout."},
command{"SetKeyspaceShardingInfo", commandSetKeyspaceShardingInfo,
"[-force] <keyspace name|zk keyspace path> [<column name>] [<column type>]",
"Updates the sharding info for a keyspace"},
command{"RebuildKeyspaceGraph", commandRebuildKeyspaceGraph,
"[-cells=a,b] <zk keyspace path> ... (/zk/global/vt/keyspaces/<keyspace>)",
"Rebuild the serving data for all shards in this keyspace. This may trigger an update to all connected clients."},
command{"ValidateKeyspace", commandValidateKeyspace,
"[-ping-tablets] <keyspace name|zk keyspace path>",
"Validate all nodes reachable from this keyspace are consistent."},
command{"MigrateServedTypes", commandMigrateServedTypes,
"[-reverse] <source keyspace/shard|zk source shard path> <served type>",
"Migrates a serving type from the source shard to the shards it replicates to. Will also rebuild the serving graph."},
command{"MigrateServedFrom", commandMigrateServedFrom,
"[-reverse] <destination keyspace/shard|zk destination shard path> <served type>",
"Makes the destination keyspace/shard serve the given type. Will also rebuild the serving graph."},
},
},
commandGroup{
"Generic", []command{
command{"WaitForAction", commandWaitForAction,
"<action path>",
"Watch an action node, printing updates, until the action is complete."},
command{"Resolve", commandResolve,
"<keyspace>.<shard>.<db type>:<port name>",
"Read a list of addresses that can answer this query. The port name is usually _mysql or _vtocc."},
command{"Validate", commandValidate,
"[-ping-tablets]",
"Validate all nodes reachable from global replication graph and all tablets in all discoverable cells are consistent."},
command{"RebuildReplicationGraph", commandRebuildReplicationGraph,
"<cell1|zk local vt path1>,<cell2|zk local vt path2>... <keyspace1>,<keyspace2>,...",
"HIDDEN This takes the Thor's hammer approach of recovery and should only be used in emergencies. cell1,cell2,... are the canonical source of data for the system. This function uses that canonical data to recover the replication graph, at which point further auditing with Validate can reveal any remaining issues."},
command{"ListAllTablets", commandListAllTablets,
"<cell name|zk local vt path>",
"List all tablets in an awk-friendly way."},
command{"ListTablets", commandListTablets,
"<tablet alias|zk tablet path> ...",
"List specified tablets in an awk-friendly way."},
},
},
commandGroup{
"Schema, Version, Permissions", []command{
command{"GetSchema", commandGetSchema,
"[-tables=<table1>,<table2>,...] [-exclude_tables=<table1>,<table2>,...] [-include-views] <tablet alias|zk tablet path>",
"Display the full schema for a tablet, or just the schema for the provided tables."},
command{"ReloadSchema", commandReloadSchema,
"<tablet alias|zk tablet path>",
"Asks a remote tablet to reload its schema."},
command{"ValidateSchemaShard", commandValidateSchemaShard,
"[-exclude_tables=''] [-include-views] <keyspace/shard|zk shard path>",
"Validate the master schema matches all the slaves."},
command{"ValidateSchemaKeyspace", commandValidateSchemaKeyspace,
"[-exclude_tables=''] [-include-views] <keyspace name|zk keyspace path>",
"Validate the master schema from shard 0 matches all the other tablets in the keyspace."},
command{"PreflightSchema", commandPreflightSchema,
"{-sql=<sql> || -sql-file=<filename>} <tablet alias|zk tablet path>",
"Apply the schema change to a temporary database to gather before and after schema and validate the change. The sql can be inlined or read from a file."},
command{"ApplySchema", commandApplySchema,
"[-force] {-sql=<sql> || -sql-file=<filename>} [-skip-preflight] [-stop-replication] <tablet alias|zk tablet path>",
"Apply the schema change to the specified tablet (allowing replication by default). The sql can be inlined or read from a file. Note this doesn't change any tablet state (doesn't go into 'schema' type)."},
command{"ApplySchemaShard", commandApplySchemaShard,
"[-force] {-sql=<sql> || -sql-file=<filename>} [-simple] [-new-parent=<zk tablet path>] <keyspace/shard|zk shard path>",
"Apply the schema change to the specified shard. If simple is specified, we just apply on the live master. Otherwise we will need to do the shell game. So we will apply the schema change to every single slave. if new_parent is set, we will also reparent (otherwise the master won't be touched at all). Using the force flag will cause a bunch of checks to be ignored, use with care."},
command{"ApplySchemaKeyspace", commandApplySchemaKeyspace,
"[-force] {-sql=<sql> || -sql-file=<filename>} [-simple] <keyspace|zk keyspace path>",
"Apply the schema change to the specified keyspace. If simple is specified, we just apply on the live masters. Otherwise we will need to do the shell game on each shard. So we will apply the schema change to every single slave (running in parallel on all shards, but on one host at a time in a given shard). We will not reparent at the end, so the masters won't be touched at all. Using the force flag will cause a bunch of checks to be ignored, use with care."},
command{"ValidateVersionShard", commandValidateVersionShard,
"<keyspace/shard|zk shard path>",
"Validate the master version matches all the slaves."},
command{"ValidateVersionKeyspace", commandValidateVersionKeyspace,
"<keyspace name|zk keyspace path>",
"Validate the master version from shard 0 matches all the other tablets in the keyspace."},
command{"GetPermissions", commandGetPermissions,
"<tablet alias|zk tablet path>",
"Display the permissions for a tablet."},
command{"ValidatePermissionsShard", commandValidatePermissionsShard,
"<keyspace/shard|zk shard path>",
"Validate the master permissions match all the slaves."},
command{"ValidatePermissionsKeyspace", commandValidatePermissionsKeyspace,
"<keyspace name|zk keyspace path>",
"Validate the master permissions from shard 0 match all the other tablets in the keyspace."},
},
},
commandGroup{
"Serving Graph", []command{
command{"GetSrvKeyspace", commandGetSrvKeyspace,
"<cell> <keyspace>",
"Outputs the json version of SrvKeyspace to stdout."},
command{"GetSrvShard", commandGetSrvShard,
"<cell> <keyspace/shard|zk shard path>",
"Outputs the json version of SrvShard to stdout."},
command{"GetEndPoints", commandGetEndPoints,
"<cell> <keyspace/shard|zk shard path> <tablet type>",
"Outputs the json version of EndPoints to stdout."},
},
},
commandGroup{
"Replication Graph", []command{
command{"GetShardReplication", commandGetShardReplication,
"<cell> <keyspace/shard|zk shard path>",
"Outputs the json version of ShardReplication to stdout."},
},
},
}
func addCommand(groupName string, c command) {
for i, group := range commands {
if group.name == groupName {
commands[i].commands = append(commands[i].commands, c)
return
}
}
panic(fmt.Errorf("Trying to add to missing group %v", groupName))
}
var stdin *bufio.Reader
var resolveWildcards = func(wr *wrangler.Wrangler, args []string) ([]string, error) {
return args, nil
}
func init() {
// FIXME(msolomon) need to send all of this to stdout
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [global parameters] command [command parameters]\n", os.Args[0])
fmt.Fprintf(os.Stderr, "\nThe global optional parameters are:\n")
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "\nThe commands are listed below, sorted by group. Use '%s <command> -h' for more help.\n\n", os.Args[0])
for _, group := range commands {
fmt.Fprintf(os.Stderr, "%s:\n", group.name)
for _, cmd := range group.commands {
if strings.HasPrefix(cmd.help, "HIDDEN") {
continue
}
fmt.Fprintf(os.Stderr, " %s %s\n", cmd.name, cmd.params)
}
fmt.Fprintf(os.Stderr, "\n")
}
}
stdin = bufio.NewReader(os.Stdin)
}
func confirm(prompt string, force bool) bool {
if force {
return true
}
fmt.Fprintf(os.Stderr, prompt+" [NO/yes] ")
line, _ := stdin.ReadString('\n')
return strings.ToLower(strings.TrimSpace(line)) == "yes"
}
func fmtMapAwkable(m map[string]string) string {
pairs := make([]string, len(m))
i := 0
for k, v := range m {
pairs[i] = fmt.Sprintf("%v: %q", k, v)
i++
}
sort.Strings(pairs)
return "[" + strings.Join(pairs, " ") + "]"
}
func fmtTabletAwkable(ti *topo.TabletInfo) string {
keyspace := ti.Keyspace
shard := ti.Shard
if keyspace == "" {
keyspace = "<null>"
}
if shard == "" {
shard = "<null>"
}
return fmt.Sprintf("%v %v %v %v %v %v %v", ti.Alias, keyspace, shard, ti.Type, ti.Addr(), ti.MysqlAddr(), fmtMapAwkable(ti.Tags))
}
func fmtAction(action *actionnode.ActionNode) string {
state := string(action.State)
// FIXME(msolomon) The default state should really just have the value "queued".
if action.State == actionnode.ACTION_STATE_QUEUED {
state = "queued"
}
return fmt.Sprintf("%v %v %v %v %v", action.Path, action.Action, state, action.ActionGuid, action.Error)
}
func listTabletsByShard(ts topo.Server, keyspace, shard string) error {
tabletAliases, err := topo.FindAllTabletAliasesInShard(ts, keyspace, shard)
if err != nil {
return err
}
return dumpTablets(ts, tabletAliases)
}
func dumpAllTablets(ts topo.Server, zkVtPath string) error {
tablets, err := wrangler.GetAllTablets(ts, zkVtPath)
if err != nil {
return err
}
for _, ti := range tablets {
fmt.Println(fmtTabletAwkable(ti))
}
return nil
}
func dumpTablets(ts topo.Server, tabletAliases []topo.TabletAlias) error {
tabletMap, err := topo.GetTabletMap(ts, tabletAliases)
if err != nil {
return err
}
for _, tabletAlias := range tabletAliases {
ti, ok := tabletMap[tabletAlias]
if !ok {
log.Warningf("failed to load tablet %v", tabletAlias)
} else {
fmt.Println(fmtTabletAwkable(ti))
}
}
return nil
}
func kquery(ts topo.Server, cell, keyspace, query string) error {
sconn, err := client2.Dial(ts, cell, keyspace, "master", false, 5*time.Second)
if err != nil {
return err
}
rows, err := sconn.Exec(query, nil)
if err != nil {
return err
}
cols := rows.Columns()
fmt.Println(strings.Join(cols, "\t"))
rowStrs := make([]string, len(cols)+1)
for row := rows.Next(); row != nil; row = rows.Next() {
for i, value := range row {
switch value.(type) {
case []byte:
rowStrs[i] = fmt.Sprintf("%q", value)
default:
rowStrs[i] = fmt.Sprintf("%v", value)
}
}
fmt.Println(strings.Join(rowStrs, "\t"))
}
return nil
}
// getFileParam returns a string containing either flag is not "",
// or the content of the file named flagFile
func getFileParam(flag, flagFile, name string) string {
if flag != "" {
if flagFile != "" {
log.Fatalf("action requires only one of " + name + " or " + name + "-file")
}
return flag
}
if flagFile == "" {
log.Fatalf("action requires one of " + name + " or " + name + "-file")
}
data, err := ioutil.ReadFile(flagFile)
if err != nil {
log.Fatalf("Cannot read file %v: %v", flagFile, err)
}
return string(data)
}
func keyspaceParamToKeyspace(param string) string {
if param[0] == '/' {
// old zookeeper path, convert to new-style string keyspace
zkPathParts := strings.Split(param, "/")
if len(zkPathParts) != 6 || zkPathParts[0] != "" || zkPathParts[1] != "zk" || zkPathParts[2] != "global" || zkPathParts[3] != "vt" || zkPathParts[4] != "keyspaces" {
log.Fatalf("Invalid keyspace path: %v", param)
}
return zkPathParts[5]
}
return param
}
// keyspaceParamsToKeyspaces builds a list of keyspaces.
// It supports topology-based wildcards, and plain wildcards.
// For instance:
// /zk/global/vt/keyspaces/one // using plugin_zktopo
// /zk/global/vt/keyspaces/* // using plugin_zktopo
// us* // using plain matching
// * // using plain matching
func keyspaceParamsToKeyspaces(wr *wrangler.Wrangler, params []string) []string {
result := make([]string, 0, len(params))
for _, param := range params {
if param[0] == '/' {
// this is a topology-specific path
zkPaths, err := resolveWildcards(wr, params)
if err != nil {
log.Fatalf("Failed to resolve wildcard: %v", err)
}
for _, zkPath := range zkPaths {
result = append(result, keyspaceParamToKeyspace(zkPath))
}
} else {
// this is not a path, so assume a keyspace name,
// possibly with wildcards
keyspaces, err := topo.ResolveKeyspaceWildcard(wr.TopoServer(), param)
if err != nil {
log.Fatalf("Failed to resolve keyspace wildcard %v: %v", param, err)
}
result = append(result, keyspaces...)
}
}
return result
}
func shardParamToKeyspaceShard(param string) (string, string) {
if param[0] == '/' {
// old zookeeper path, convert to new-style
zkPathParts := strings.Split(param, "/")
if len(zkPathParts) != 8 || zkPathParts[0] != "" || zkPathParts[1] != "zk" || zkPathParts[2] != "global" || zkPathParts[3] != "vt" || zkPathParts[4] != "keyspaces" || zkPathParts[6] != "shards" {
log.Fatalf("Invalid shard path: %v", param)
}
return zkPathParts[5], zkPathParts[7]
}
zkPathParts := strings.Split(param, "/")
if len(zkPathParts) != 2 {
log.Fatalf("Invalid shard path: %v", param)
}
return zkPathParts[0], zkPathParts[1]
}
// shardParamsToKeyspaceShards builds a list of keyspace/shard pairs.
// It supports topology-based wildcards, and plain wildcards.
// For instance:
// /zk/global/vt/keyspaces/*/shards/* // using plugin_zktopo
// user/* // using plain matching
// */0 // using plain matching
func shardParamsToKeyspaceShards(wr *wrangler.Wrangler, params []string) []topo.KeyspaceShard {
result := make([]topo.KeyspaceShard, 0, len(params))
for _, param := range params {
if param[0] == '/' {
// this is a topology-specific path
zkPaths, err := resolveWildcards(wr, params)
if err != nil {
log.Fatalf("Failed to resolve wildcard: %v", err)
}
for _, zkPath := range zkPaths {
keyspace, shard := shardParamToKeyspaceShard(zkPath)
result = append(result, topo.KeyspaceShard{keyspace, shard})
}
} else {
// this is not a path, so assume a keyspace
// name / shard name, each possibly with wildcards
keyspaceShards, err := topo.ResolveShardWildcard(wr.TopoServer(), param)
if err != nil {
log.Fatalf("Failed to resolve keyspace/shard wildcard %v: %v", param, err)
}
result = append(result, keyspaceShards...)
}
}
return result
}
// tabletParamToTabletAlias takes either an old style ZK tablet path or a
// new style tablet alias as a string, and returns a TabletAlias.
func tabletParamToTabletAlias(param string) topo.TabletAlias {
if param[0] == '/' {
// old zookeeper path, convert to new-style string tablet alias
zkPathParts := strings.Split(param, "/")
if len(zkPathParts) != 6 || zkPathParts[0] != "" || zkPathParts[1] != "zk" || zkPathParts[3] != "vt" || zkPathParts[4] != "tablets" {
log.Fatalf("Invalid tablet path: %v", param)
}
param = zkPathParts[2] + "-" + zkPathParts[5]
}
result, err := topo.ParseTabletAliasString(param)
if err != nil {
log.Fatalf("Invalid tablet alias %v: %v", param, err)
}
return result
}
// tabletParamsToTabletAliases takes multiple params and converts them
// to tablet aliases.
func tabletParamsToTabletAliases(params []string) []topo.TabletAlias {
result := make([]topo.TabletAlias, len(params))
for i, param := range params {
result[i] = tabletParamToTabletAlias(param)
}
return result
}
// tabletRepParamToTabletAlias takes either an old style ZK tablet replication
// path or a new style tablet alias as a string, and returns a
// TabletAlias.
func tabletRepParamToTabletAlias(param string) topo.TabletAlias {
if param[0] == '/' {
// old zookeeper replication path, e.g.
// /zk/global/vt/keyspaces/ruser/shards/10-20/nyc-0000200278
// convert to new-style string tablet alias
zkPathParts := strings.Split(param, "/")
if len(zkPathParts) != 9 || zkPathParts[0] != "" || zkPathParts[1] != "zk" || zkPathParts[2] != "global" || zkPathParts[3] != "vt" || zkPathParts[4] != "keyspaces" || zkPathParts[6] != "shards" {
log.Fatalf("Invalid tablet replication path: %v", param)
}
param = zkPathParts[8]
}
result, err := topo.ParseTabletAliasString(param)
if err != nil {
log.Fatalf("Invalid tablet alias %v: %v", param, err)
}
return result
}
// vtPathToCell takes either an old style ZK vt path /zk/<cell>/vt or
// a new style cell and returns the cell name
func vtPathToCell(param string) string {
if param[0] == '/' {
// old zookeeper replication path like /zk/<cell>/vt
zkPathParts := strings.Split(param, "/")
if len(zkPathParts) != 4 || zkPathParts[0] != "" || zkPathParts[1] != "zk" || zkPathParts[3] != "vt" {
log.Fatalf("Invalid vt path: %v", param)
}
return zkPathParts[2]
}
return param
}
// parseTabletType parses the string tablet type and verifies
// it is an accepted one
func parseTabletType(param string, types []topo.TabletType) topo.TabletType {
tabletType := topo.TabletType(param)
if !topo.IsTypeInList(tabletType, types) {
log.Fatalf("Type %v is not one of: %v", tabletType, strings.Join(topo.MakeStringTypeList(types), " "))
}
return tabletType
}
func commandInitTablet(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
var (
dbNameOverride = subFlags.String("db-name-override", "", "override the name of the db used by vttablet")
force = subFlags.Bool("force", false, "will overwrite the node if it already exists")
parent = subFlags.Bool("parent", false, "will create the parent shard and keyspace if they don't exist yet")
update = subFlags.Bool("update", false, "perform update if a tablet with provided alias exists")
hostname = subFlags.String("hostname", "", "server the tablet is running on")
mysqlPort = subFlags.Int("mysql_port", 0, "mysql port for the mysql daemon")
port = subFlags.Int("port", 0, "main port for the vttablet process")
vtsPort = subFlags.Int("vts_port", 0, "encrypted port for the vttablet process")
keyspace = subFlags.String("keyspace", "", "keyspace this tablet belongs to")
shard = subFlags.String("shard", "", "shard this tablet belongs to")
parentAlias = subFlags.String("parent_alias", "", "alias of the mysql parent tablet for this tablet")
tags flagutil.StringMapValue
)
subFlags.Var(&tags, "tags", "comma separated list of key:value pairs used to tag the tablet")
subFlags.Parse(args)
if subFlags.NArg() != 2 {
log.Fatalf("action InitTablet requires <tablet alias> <tablet type>")
}
tabletAlias := tabletParamToTabletAlias(subFlags.Arg(0))
tabletType := parseTabletType(subFlags.Arg(1), topo.AllTabletTypes)
// create tablet record
tablet := &topo.Tablet{
Alias: tabletAlias,
Hostname: *hostname,
Portmap: make(map[string]int),
Keyspace: *keyspace,
Shard: *shard,
Type: tabletType,
DbNameOverride: *dbNameOverride,
Tags: tags,
}
if *port != 0 {
tablet.Portmap["vt"] = *port
}
if *mysqlPort != 0 {
tablet.Portmap["mysql"] = *mysqlPort
}
if *vtsPort != 0 {
tablet.Portmap["vts"] = *vtsPort
}
if *parentAlias != "" {
tablet.Parent = tabletRepParamToTabletAlias(*parentAlias)
}
return "", wr.InitTablet(tablet, *force, *parent, *update)
}
func commandGetTablet(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
subFlags.Parse(args)
if subFlags.NArg() != 1 {
log.Fatalf("action GetTablet requires <tablet alias|zk tablet path>")
}
tabletAlias := tabletParamToTabletAlias(subFlags.Arg(0))
tabletInfo, err := wr.TopoServer().GetTablet(tabletAlias)
if err == nil {
fmt.Println(jscfg.ToJson(tabletInfo))
}
return "", err
}
func commandUpdateTabletAddrs(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
hostname := subFlags.String("hostname", "", "fully qualified host name")
ipAddr := subFlags.String("ip-addr", "", "IP address")
mysqlPort := subFlags.Int("mysql-port", 0, "mysql port")
vtPort := subFlags.Int("vt-port", 0, "vt port")
vtsPort := subFlags.Int("vts-port", 0, "vts port")
subFlags.Parse(args)
if subFlags.NArg() != 1 {
log.Fatalf("action UpdateTabletAddrs requires <tablet alias|zk tablet path>")
}
if *ipAddr != "" && net.ParseIP(*ipAddr) == nil {
log.Fatalf("malformed address: %v", *ipAddr)
}
tabletAlias := tabletParamToTabletAlias(subFlags.Arg(0))
return "", wr.TopoServer().UpdateTabletFields(tabletAlias, func(tablet *topo.Tablet) error {
if *hostname != "" {
tablet.Hostname = *hostname
}
if *ipAddr != "" {
tablet.IPAddr = *ipAddr
}
if *vtPort != 0 || *vtsPort != 0 || *mysqlPort != 0 {
if tablet.Portmap == nil {
tablet.Portmap = make(map[string]int)
}
if *vtPort != 0 {
tablet.Portmap["vt"] = *vtPort
}
if *vtsPort != 0 {
tablet.Portmap["vts"] = *vtsPort
}
if *mysqlPort != 0 {
tablet.Portmap["mysql"] = *mysqlPort
}
}
return nil
})
}
func commandScrapTablet(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
force := subFlags.Bool("force", false, "writes the scrap state in to zk, no questions asked, if a tablet is offline")
skipRebuild := subFlags.Bool("skip-rebuild", false, "do not rebuild the shard and keyspace graph after scrapping")
subFlags.Parse(args)
if subFlags.NArg() != 1 {
log.Fatalf("action ScrapTablet requires <tablet alias|zk tablet path>")
}
tabletAlias := tabletParamToTabletAlias(subFlags.Arg(0))
return wr.Scrap(tabletAlias, *force, *skipRebuild)
}
func commandDeleteTablet(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
subFlags.Parse(args)
if subFlags.NArg() == 0 {
log.Fatalf("action DeleteTablet requires at least one <tablet alias|zk tablet path> ...")
}
tabletAliases := tabletParamsToTabletAliases(subFlags.Args())
for _, tabletAlias := range tabletAliases {
if err := wr.DeleteTablet(tabletAlias); err != nil {
return "", err
}
}
return "", nil
}
func commandSetReadOnly(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
subFlags.Parse(args)
if subFlags.NArg() != 1 {
log.Fatalf("action SetReadOnly requires <tablet alias|zk tablet path>")
}
tabletAlias := tabletParamToTabletAlias(subFlags.Arg(0))
return wr.ActionInitiator().SetReadOnly(tabletAlias)
}
func commandSetReadWrite(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
subFlags.Parse(args)
if subFlags.NArg() != 1 {
log.Fatalf("action SetReadWrite requires <tablet alias|zk tablet path>")
}
tabletAlias := tabletParamToTabletAlias(subFlags.Arg(0))
return wr.ActionInitiator().SetReadWrite(tabletAlias)
}
func commandSetBlacklistedTables(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
subFlags.Parse(args)
if subFlags.NArg() != 1 && subFlags.NArg() != 2 {
log.Fatalf("action SetBlacklistedTables requires <tablet alias|zk tablet path> [table1,table2,...]")
}
tabletAlias := tabletParamToTabletAlias(subFlags.Arg(0))
var tables []string
if subFlags.NArg() == 2 {
tables = strings.Split(subFlags.Arg(1), ",")
}
ti, err := wr.TopoServer().GetTablet(tabletAlias)
if err != nil {
log.Fatalf("failed reading tablet %v: %v", tabletAlias, err)
}
return "", wr.ActionInitiator().SetBlacklistedTables(ti, tables, *waitTime)
}
func commandChangeSlaveType(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
force := subFlags.Bool("force", false, "will change the type in zookeeper, and not run hooks")
dryRun := subFlags.Bool("dry-run", false, "just list the proposed change")
subFlags.Parse(args)
if subFlags.NArg() != 2 {
log.Fatalf("action ChangeSlaveType requires <zk tablet path> <db type>")
}
tabletAlias := tabletParamToTabletAlias(subFlags.Arg(0))
newType := parseTabletType(subFlags.Arg(1), topo.AllTabletTypes)
if *dryRun {
ti, err := wr.TopoServer().GetTablet(tabletAlias)
if err != nil {
log.Fatalf("failed reading tablet %v: %v", tabletAlias, err)
}
if !topo.IsTrivialTypeChange(ti.Type, newType) || !topo.IsValidTypeChange(ti.Type, newType) {
log.Fatalf("invalid type transition %v: %v -> %v", tabletAlias, ti.Type, newType)
}
fmt.Printf("- %v\n", fmtTabletAwkable(ti))
ti.Type = newType
fmt.Printf("+ %v\n", fmtTabletAwkable(ti))
return "", nil
}
return "", wr.ChangeType(tabletAlias, newType, *force)
}
func commandPing(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
subFlags.Parse(args)
if subFlags.NArg() != 1 {
log.Fatalf("action Ping requires <tablet alias|zk tablet path>")
}
tabletAlias := tabletParamToTabletAlias(subFlags.Arg(0))
return wr.ActionInitiator().Ping(tabletAlias)
}
func commandRpcPing(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
subFlags.Parse(args)
if subFlags.NArg() != 1 {
log.Fatalf("action Ping requires <tablet alias|zk tablet path>")
}
tabletAlias := tabletParamToTabletAlias(subFlags.Arg(0))
return "", wr.ActionInitiator().RpcPing(tabletAlias, *waitTime)
}
func commandQuery(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
subFlags.Parse(args)
if subFlags.NArg() != 3 {
log.Fatalf("action Query requires 3")
}
return "", kquery(wr.TopoServer(), subFlags.Arg(0), subFlags.Arg(1), subFlags.Arg(2))
}
func commandSleep(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
subFlags.Parse(args)
if subFlags.NArg() != 2 {
log.Fatalf("action Sleep requires <tablet alias|zk tablet path> <duration>")
}
tabletAlias := tabletParamToTabletAlias(subFlags.Arg(0))
duration, err := time.ParseDuration(subFlags.Arg(1))
if err != nil {
return "", err
}
return wr.ActionInitiator().Sleep(tabletAlias, duration)
}
func commandSnapshotSourceEnd(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
slaveStartRequired := subFlags.Bool("slave-start", false, "will restart replication")
readWrite := subFlags.Bool("read-write", false, "will make the server read-write")
subFlags.Parse(args)
if subFlags.NArg() != 2 {
log.Fatalf("action SnapshotSourceEnd requires <tablet alias|zk tablet path> <original server type>")
}
tabletAlias := tabletParamToTabletAlias(subFlags.Arg(0))
tabletType := parseTabletType(subFlags.Arg(1), topo.AllTabletTypes)
return "", wr.SnapshotSourceEnd(tabletAlias, *slaveStartRequired, !(*readWrite), tabletType)
}
func commandSnapshot(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
force := subFlags.Bool("force", false, "will force the snapshot for a master, and turn it into a backup")
serverMode := subFlags.Bool("server-mode", false, "will symlink the data files and leave mysqld stopped")
concurrency := subFlags.Int("concurrency", 4, "how many compression/checksum jobs to run simultaneously")
subFlags.Parse(args)
if subFlags.NArg() != 1 {
log.Fatalf("action Snapshot requires <tablet alias|zk src tablet path>")
}
tabletAlias := tabletParamToTabletAlias(subFlags.Arg(0))
filename, parentAlias, slaveStartRequired, readOnly, originalType, err := wr.Snapshot(tabletAlias, *force, *concurrency, *serverMode)
if err == nil {
log.Infof("Manifest: %v", filename)
log.Infof("ParentAlias: %v", parentAlias)
if *serverMode {
log.Infof("SlaveStartRequired: %v", slaveStartRequired)
log.Infof("ReadOnly: %v", readOnly)
log.Infof("OriginalType: %v", originalType)
}
}
return "", err
}
func commandRestore(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
dontWaitForSlaveStart := subFlags.Bool("dont-wait-for-slave-start", false, "won't wait for replication to start (useful when restoring from snapshot source that is the replication master)")
fetchConcurrency := subFlags.Int("fetch-concurrency", 3, "how many files to fetch simultaneously")
fetchRetryCount := subFlags.Int("fetch-retry-count", 3, "how many times to retry a failed transfer")
subFlags.Parse(args)
if subFlags.NArg() != 3 && subFlags.NArg() != 4 {
log.Fatalf("action Restore requires <src tablet alias|zk src tablet path> <src manifest path> <dst tablet alias|zk dst tablet path> [<zk new master path>]")
}
srcTabletAlias := tabletParamToTabletAlias(subFlags.Arg(0))
dstTabletAlias := tabletParamToTabletAlias(subFlags.Arg(2))
parentAlias := srcTabletAlias
if subFlags.NArg() == 4 {
parentAlias = tabletParamToTabletAlias(subFlags.Arg(3))
}
return "", wr.Restore(srcTabletAlias, subFlags.Arg(1), dstTabletAlias, parentAlias, *fetchConcurrency, *fetchRetryCount, false, *dontWaitForSlaveStart)
}
func commandClone(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
force := subFlags.Bool("force", false, "will force the snapshot for a master, and turn it into a backup")
concurrency := subFlags.Int("concurrency", 4, "how many compression/checksum jobs to run simultaneously")
fetchConcurrency := subFlags.Int("fetch-concurrency", 3, "how many files to fetch simultaneously")
fetchRetryCount := subFlags.Int("fetch-retry-count", 3, "how many times to retry a failed transfer")
serverMode := subFlags.Bool("server-mode", false, "will keep the snapshot server offline to serve DB files directly")
subFlags.Parse(args)
if subFlags.NArg() < 2 {
log.Fatalf("action Clone requires <src tablet alias|zk src tablet path> <dst tablet alias|zk dst tablet path> ...")
}
srcTabletAlias := tabletParamToTabletAlias(subFlags.Arg(0))
dstTabletAliases := make([]topo.TabletAlias, subFlags.NArg()-1)
for i := 1; i < subFlags.NArg(); i++ {
dstTabletAliases[i-1] = tabletParamToTabletAlias(subFlags.Arg(i))
}
return "", wr.Clone(srcTabletAlias, dstTabletAliases, *force, *concurrency, *fetchConcurrency, *fetchRetryCount, *serverMode)
}
func commandMultiRestore(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (status string, err error) {
fetchRetryCount := subFlags.Int("fetch-retry-count", 3, "how many times to retry a failed transfer")
concurrency := subFlags.Int("concurrency", 8, "how many concurrent jobs to run simultaneously")
fetchConcurrency := subFlags.Int("fetch-concurrency", 4, "how many files to fetch simultaneously")
insertTableConcurrency := subFlags.Int("insert-table-concurrency", 4, "how many tables to load into a single destination table simultaneously")
strategy := subFlags.String("strategy", "", "which strategy to use for restore, use 'mysqlctl multirestore -help' for more info")
subFlags.Parse(args)
if subFlags.NArg() < 2 {
log.Fatalf("MultiRestore requires <dst tablet alias|destination zk path> <source tablet alias|source zk path>... %v", args)
}
destination := tabletParamToTabletAlias(subFlags.Arg(0))
sources := make([]topo.TabletAlias, subFlags.NArg()-1)
for i := 1; i < subFlags.NArg(); i++ {
sources[i-1] = tabletParamToTabletAlias(subFlags.Arg(i))
}
err = wr.MultiRestore(destination, sources, *concurrency, *fetchConcurrency, *insertTableConcurrency, *fetchRetryCount, *strategy)
return
}
func commandMultiSnapshot(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
force := subFlags.Bool("force", false, "will force the snapshot for a master, and turn it into a backup")
concurrency := subFlags.Int("concurrency", 8, "how many compression jobs to run simultaneously")
spec := subFlags.String("spec", "-", "shard specification")
tablesString := subFlags.String("tables", "", "dump only this comma separated list of table regexp")
excludeTablesString := subFlags.String("exclude_tables", "", "comma separated list of regexps for tables to exclude")
skipSlaveRestart := subFlags.Bool("skip-slave-restart", false, "after the snapshot is done, do not restart slave replication")
maximumFilesize := subFlags.Uint64("maximum-file-size", 128*1024*1024, "the maximum size for an uncompressed data file")
subFlags.Parse(args)
if subFlags.NArg() != 1 {
log.Fatalf("action MultiSnapshot requires <src tablet alias|zk src tablet path>")
}
shards, err := key.ParseShardingSpec(*spec)
if err != nil {
log.Fatalf("multisnapshot failed: %v", err)
}
var tables []string
if *tablesString != "" {
tables = strings.Split(*tablesString, ",")
}
var excludeTables []string
if *excludeTablesString != "" {
excludeTables = strings.Split(*excludeTablesString, ",")
}
source := tabletParamToTabletAlias(subFlags.Arg(0))
filenames, parentAlias, err := wr.MultiSnapshot(shards, source, *concurrency, tables, excludeTables, *force, *skipSlaveRestart, *maximumFilesize)
if err == nil {
log.Infof("manifest locations: %v", filenames)
log.Infof("ParentAlias: %v", parentAlias)
}
return "", err
}
func commandReadTabletAction(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {
subFlags.Parse(args)
if subFlags.NArg() != 1 {
log.Fatalf("action ReadTabletAction requires <action path>")
}
actionPath := subFlags.Arg(0)
_, data, _, err := wr.TopoServer().ReadTabletActionPath(actionPath)
if err == nil {
actionNode, err := actionnode.ActionNodeFromJson(data, actionPath)
if err == nil {
fmt.Println(jscfg.ToJson(actionNode))
}
}
return "", err
}
func commandExecuteFetch(wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) (string, error) {