vtctl support for vschema ddls#4385
Conversation
rafael
left a comment
There was a problem hiding this comment.
This looks good to me. Added couple comments.
go/vt/topotools/vschema_ddl.go
Outdated
There was a problem hiding this comment.
I was thinking that it would make sense this to be driven by a flag. That way we can be explicit with the intent. If the flag is not provided and the Vindexes len is 0, adding a vindex should fail.
There was a problem hiding this comment.
By definition, vindexes are only present in Sharded keyspaces, so I think the act of creating a vindex expresses the intent of whether we want
I have ideas about how we can extend the vschema ddl syntax to support unsharded keyspaces, but even then we won't have vindexes and I think above will hold.
go/vt/topotools/vschema_ddl.go
Outdated
There was a problem hiding this comment.
I think a nice feature here is to delete the vindex altogether if no other tables are using it.
There was a problem hiding this comment.
I think it's better to add an explicit syntax for dropping the vindex rather than implicit by dropping the last reference
brirams
left a comment
There was a problem hiding this comment.
this all seems reasonable to me but I don't know anything yet so take my review with a grain of salt.
provided some nits for consideration but no showstoppers
go/vt/vtctl/vtctl.go
Outdated
There was a problem hiding this comment.
there seems to be a convention for a similarly named option(sql-file) in other spots. should we maintain that?
There was a problem hiding this comment.
I was trying to be consistent with vschema_file but you're right we have this inconsistency unfortunately:
[SFO-M-MDEMMER03] -> vtctl --help | grep -- -file
-db-credentials-file string
-file_backup_storage_root string
ApplySchema [-allow_long_unavailability] [-wait_slave_timeout=10s] {-sql=<sql> || -sql-file=<filename>} <keyspace>
[SFO-M-MDEMMER03] -> vtctl --help | grep -- _file
-consul_auth_static_file string
-grpc_auth_static_password_file string
-mysql_auth_server_static_file string
-pid_file string
ApplyVSchema {-vschema=<vschema> || -vschema_file=<vschema file> || -sql=<sql> || -sql_file=<sql file>} [-cells=c1,c2,...] [-skip_rebuild] <keyspace>
go/vt/vtctl/vtctl.go
Outdated
There was a problem hiding this comment.
There was a problem hiding this comment.
Ah good point. This one I will change.
go/vt/vtctl/vtctl.go
Outdated
There was a problem hiding this comment.
do you need to add these options to the commands slice here?
There was a problem hiding this comment.
Yes I do. Thanks for pointing this out.
go/vt/vtctl/vtctl.go
Outdated
There was a problem hiding this comment.
could you squash these two lines:
vs = &vschemapb.Keyspace{}
go/vt/vtctl/vtctl.go
Outdated
There was a problem hiding this comment.
nit: rm : after parsing to match error format above.
go/vt/vtctl/vtctl.go
Outdated
There was a problem hiding this comment.
TIOLI. big if/else blocks make my eyes cross:
// apparently golang doesn't have an xor operator
ddlMode := (*sql != "") != (*sqlFile != "")
vschemaMode := (*vschema != "") != (*vschemaFile != "")
switch {
case ddlMode && vschemaMode:
// both specified. return err
case !ddlMode && !vschemaMode:
// neither specified, return err
}
if ddlMode {
}
if vschemaMode {
}
There was a problem hiding this comment.
good suggestion. changed the names a bit but this is a much more readable cleanup
03758b8 to
6f48f91
Compare
Pull in the topotools.RebuildVschema implementation into the vtgate VschemaManager to share the same helper function that vtctl uses to find all cells and propagate the changed vschema to all of them. This changes the UpdateVschema interface to take in a single modified keyspace and not the whole SrvVschema. Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
Abstract out the execution of the vschema ddl statements into a new function in topotools. Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
Add new flags to ApplyVschema to be able to take a sql ddl statement either on the command line or in a file to enable vschema changes without having to edit the whole json file. Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
Make sure to set the Sharded bit to true when creating the first vindex in a keyspace, otherwise the vschema ddl statements can't be used to bootstrap a new sharded keyspace. Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
The fact that the vschema ddl needs to go through the normal srvtopo interface to get to the underlying topo server when applying vschema ddl operations doesn't play well with the SandboxTopo used in some of the unit tests. So restore the previous implementation which edits the SrvVschema in place and then reapplies it to all cells, rather than trying to reuse topotools.RebuildVschema from the executor. Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
6f48f91 to
e47bed0
Compare
rafael
left a comment
There was a problem hiding this comment.
All comments have been addressed. This change looks good to me.
Description
Add support for vschema DDL statements to be executed as vtctl commands.
Motivation
Making vschema changes through the DDL interface is safer and more granular than hand-editing the vschema json file. As such it is less likely that operators run into problems like #4288.
However, there are cases in which it is useful for these statements to be executed at vtctl / vtctld, so it would be beneficial to have the DDL syntax supported both at vtgate and as a vtctl command.
Details
The crux of the change adds new options to the
ApplyVschemacommand to take a sql statement instead of the json specification, e.g.:To implement this support, refactor the vschema ddl operations out of the vtgate executor and into a new topotools utility function to share it with vtctl.
Also add a
-dry_runoption to theApplyVschemacommand to be able to see what the change will do to the vschema without applying it.Finally, add a feature to set the
Sharded: trueflag on the vschema the first time a vindex is added to address a bootstrapping problem for new keyspaces. At some point we will want vschema ddl support for unsharded keyspaces, but that would necessarily involve a different syntax so we can cross that bridge later.