@@ -23,6 +23,7 @@ package main
2323
2424import (
2525 "bytes"
26+ "flag"
2627 "fmt"
2728 "os"
2829 "strings"
@@ -31,24 +32,35 @@ import (
3132 binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
3233)
3334
35+ var onDdl string
36+
37+ func init () {
38+ flag .StringVar (& onDdl , "on_ddl" , "ignore" , "Set on_ddl value for replication stream - ignore, stop, exec, exec_ignore" )
39+ flag .Parse ()
40+ }
41+
3442func main () {
43+ argOffset := 0
44+ if (len (os .Args ) > 1 && strings .HasPrefix (os .Args [1 ], "-" )) {
45+ argOffset = 2
46+ }
47+
48+ if (len (os .Args ) < (7 + argOffset )) {
49+ fmt .Println ("Usage: /vreplgen [-on_ddl (ignore|stop|exec|exec_ignore)] <tablet_id> <src_keyspace> <src_shard> <dest_keyspace> <dest_table1> 'filter1' [<dest_table2> 'filter2']..." )
50+ os .Exit (1 )
51+ }
52+
3553 vtctl := os .Getenv ("VTCTLCLIENT" )
3654 if (vtctl == "" ) {
3755 vtctl = "vtctlclient -server localhost:15999"
3856 }
39- // TODO: DDL ignore or not
40- if (len (os .Args ) < 7 ) {
41- fmt .Println ("Usage: /vreplgen <tablet_id> <src_keyspace> <src_shard> <dest_keyspace> <dest_table1> 'filter1' [<dest_table2> 'filter2']..." )
42- os .Exit (1 )
43- }
44- tabletID := os .Args [1 ]
45- sourceKeyspace := os .Args [2 ]
46- sourceShard := os .Args [3 ]
47- destKeyspace := os .Args [4 ]
57+ tabletID := os .Args [1 + argOffset ]
58+ sourceKeyspace := os .Args [2 + argOffset ]
59+ sourceShard := os .Args [3 + argOffset ]
60+ destKeyspace := os .Args [4 + argOffset ]
4861 destDbName := "vt_" + destKeyspace
49- listSize := (len (os .Args ) - 5 )/ 2
50- rules := make ([]* binlogdatapb.Rule , listSize )
51- for i := 5 ; i < len (os .Args ); i = i + 2 {
62+ var rules []* binlogdatapb.Rule
63+ for i := 5 + argOffset ; i < len (os .Args ); i = i + 2 {
5264 destTable := os .Args [i ]
5365 destFilter := os .Args [i + 1 ]
5466 rule := new (binlogdatapb.Rule )
@@ -59,11 +71,24 @@ func main() {
5971 filter := & binlogdatapb.Filter {
6072 Rules : rules ,
6173 }
74+
75+ var onDdlAction binlogdatapb.OnDDLAction
76+ switch onDdl {
77+ case "ignore" :
78+ onDdlAction = binlogdatapb .OnDDLAction_IGNORE
79+ case "stop" :
80+ onDdlAction = binlogdatapb .OnDDLAction_STOP
81+ case "exec" :
82+ onDdlAction = binlogdatapb .OnDDLAction_EXEC
83+ case "exec_ignore" :
84+ onDdlAction = binlogdatapb .OnDDLAction_EXEC_IGNORE
85+ }
86+
6287 bls := & binlogdatapb.BinlogSource {
6388 Keyspace : sourceKeyspace ,
6489 Shard : sourceShard ,
6590 Filter : filter ,
66- OnDdl : binlogdatapb . OnDDLAction_IGNORE ,
91+ OnDdl : onDdlAction ,
6792 }
6893 val := sqltypes .NewVarBinary (fmt .Sprintf ("%v" , bls ))
6994 var sqlEscaped bytes.Buffer
0 commit comments