From 74d043b18e5423277c62481564b65c772e2b15b6 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Tue, 16 Mar 2021 09:25:59 +0200 Subject: [PATCH 1/3] vtgate to support -enable_online_ddl flag Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/vt/schema/online_ddl.go | 5 +++++ go/vt/vtgate/engine/ddl.go | 5 +++++ go/vt/vtgate/planbuilder/builder.go | 5 +++++ go/vt/vtgate/planbuilder/ddl.go | 12 +++++++----- go/vt/vtgate/planbuilder/migration.go | 7 +++++++ go/vt/vtgate/planbuilder/show.go | 5 +++++ 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/go/vt/schema/online_ddl.go b/go/vt/schema/online_ddl.go index 0cad7c3e3a3..9575ce4b4b1 100644 --- a/go/vt/schema/online_ddl.go +++ b/go/vt/schema/online_ddl.go @@ -19,6 +19,7 @@ package schema import ( "context" "encoding/json" + "errors" "fmt" "regexp" "strings" @@ -36,6 +37,10 @@ var ( ptOSCGeneratedTableNameRegexp = regexp.MustCompile(`^_.*_old$`) revertStatementRegexp = regexp.MustCompile(`(?i)^revert\s+(.*)$`) ) +var ( + // ErrOnlineDDLDisabled is returned when online DDL is disabled, and a user attempts to run an online DDL operation (submit, review, control) + ErrOnlineDDLDisabled = errors.New("online DDL is disabled") +) const ( SchemaMigrationsTableName = "schema_migrations" diff --git a/go/vt/vtgate/engine/ddl.go b/go/vt/vtgate/engine/ddl.go index 26b3e305b70..bb82ae6446f 100644 --- a/go/vt/vtgate/engine/ddl.go +++ b/go/vt/vtgate/engine/ddl.go @@ -37,6 +37,8 @@ type DDL struct { NormalDDL *Send OnlineDDL *OnlineDDL + OnlineDDLEnabled bool + CreateTempTable bool noTxNeeded @@ -98,6 +100,9 @@ func (ddl *DDL) Execute(vcursor VCursor, bindVars map[string]*query.BindVariable ddl.OnlineDDL.Options = options if ddl.isOnlineSchemaDDL() { + if !ddl.OnlineDDLEnabled { + return nil, schema.ErrOnlineDDLDisabled + } return ddl.OnlineDDL.Execute(vcursor, bindVars, wantfields) } diff --git a/go/vt/vtgate/planbuilder/builder.go b/go/vt/vtgate/planbuilder/builder.go index 27fcdb1026f..d21a12a6966 100644 --- a/go/vt/vtgate/planbuilder/builder.go +++ b/go/vt/vtgate/planbuilder/builder.go @@ -18,6 +18,7 @@ package planbuilder import ( "errors" + "flag" "sort" "vitess.io/vitess/go/sqltypes" @@ -35,6 +36,10 @@ import ( vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" ) +var ( + enableOnlineDDL = flag.Bool("enable_online_ddl", true, "Allow users to submit, review and control Online DDL") +) + // ContextVSchema defines the interface for this package to fetch // info about tables. type ContextVSchema interface { diff --git a/go/vt/vtgate/planbuilder/ddl.go b/go/vt/vtgate/planbuilder/ddl.go index 9c8e10ed6fc..b853661e50e 100644 --- a/go/vt/vtgate/planbuilder/ddl.go +++ b/go/vt/vtgate/planbuilder/ddl.go @@ -38,11 +38,13 @@ func buildGeneralDDLPlan(sql string, ddlStatement sqlparser.DDLStatement, vschem } return &engine.DDL{ - Keyspace: normalDDLPlan.Keyspace, - SQL: normalDDLPlan.Query, - DDL: ddlStatement, - NormalDDL: normalDDLPlan, - OnlineDDL: onlineDDLPlan, + Keyspace: normalDDLPlan.Keyspace, + SQL: normalDDLPlan.Query, + DDL: ddlStatement, + NormalDDL: normalDDLPlan, + OnlineDDL: onlineDDLPlan, + OnlineDDLEnabled: *enableOnlineDDL, + CreateTempTable: ddlStatement.IsTemporary(), }, nil } diff --git a/go/vt/vtgate/planbuilder/migration.go b/go/vt/vtgate/planbuilder/migration.go index 465699a2689..9b33ec42797 100644 --- a/go/vt/vtgate/planbuilder/migration.go +++ b/go/vt/vtgate/planbuilder/migration.go @@ -20,12 +20,16 @@ import ( "vitess.io/vitess/go/vt/key" topodatapb "vitess.io/vitess/go/vt/proto/topodata" vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" + "vitess.io/vitess/go/vt/schema" "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/vterrors" "vitess.io/vitess/go/vt/vtgate/engine" ) func buildAlterMigrationPlan(query string, stmt *sqlparser.AlterMigration, vschema ContextVSchema) (engine.Primitive, error) { + if !*enableOnlineDDL { + return nil, schema.ErrOnlineDDLDisabled + } dest, ks, tabletType, err := vschema.TargetDestination("") if err != nil { return nil, err @@ -50,6 +54,9 @@ func buildAlterMigrationPlan(query string, stmt *sqlparser.AlterMigration, vsche } func buildRevertMigrationPlan(query string, stmt *sqlparser.RevertMigration, vschema ContextVSchema) (engine.Primitive, error) { + if !*enableOnlineDDL { + return nil, schema.ErrOnlineDDLDisabled + } _, ks, tabletType, err := vschema.TargetDestination("") if err != nil { return nil, err diff --git a/go/vt/vtgate/planbuilder/show.go b/go/vt/vtgate/planbuilder/show.go index f9446b21093..ead9e4fe99c 100644 --- a/go/vt/vtgate/planbuilder/show.go +++ b/go/vt/vtgate/planbuilder/show.go @@ -29,6 +29,7 @@ import ( "vitess.io/vitess/go/vt/key" querypb "vitess.io/vitess/go/vt/proto/query" vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" + "vitess.io/vitess/go/vt/schema" "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/vterrors" "vitess.io/vitess/go/vt/vtgate/engine" @@ -178,6 +179,10 @@ func buildDBPlan(show *sqlparser.ShowBasic, vschema ContextVSchema) (engine.Prim // buildShowVMigrationsPlan serves `SHOW VITESS_MIGRATIONS ...` queries. It invokes queries on _vt.schema_migrations on all MASTER tablets on keyspace's shards. func buildShowVMigrationsPlan(show *sqlparser.ShowBasic, vschema ContextVSchema) (engine.Primitive, error) { + if !*enableOnlineDDL { + return nil, schema.ErrOnlineDDLDisabled + } + dest, ks, tabletType, err := vschema.TargetDestination(show.DbName) if err != nil { return nil, err From 27a2537c3f1dfe5a765ed9a5cc2bffb6db2c38e0 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Thu, 18 Mar 2021 16:31:47 +0200 Subject: [PATCH 2/3] sizegen Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/vt/vtgate/engine/cached_size.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/vt/vtgate/engine/cached_size.go b/go/vt/vtgate/engine/cached_size.go index 8b3cbaa1cc5..78696d6be37 100644 --- a/go/vt/vtgate/engine/cached_size.go +++ b/go/vt/vtgate/engine/cached_size.go @@ -90,7 +90,7 @@ func (cached *DDL) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(57) + size += int64(58) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) From 93fe937a7cb09db57008deda0ba24243322c993d Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Thu, 25 Mar 2021 17:53:50 +0200 Subject: [PATCH 3/3] SHOW VITESS_MIGRATIONS are unaffected by -enable_online_ddl Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/vt/vtgate/planbuilder/show.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/go/vt/vtgate/planbuilder/show.go b/go/vt/vtgate/planbuilder/show.go index ead9e4fe99c..f9446b21093 100644 --- a/go/vt/vtgate/planbuilder/show.go +++ b/go/vt/vtgate/planbuilder/show.go @@ -29,7 +29,6 @@ import ( "vitess.io/vitess/go/vt/key" querypb "vitess.io/vitess/go/vt/proto/query" vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" - "vitess.io/vitess/go/vt/schema" "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/vterrors" "vitess.io/vitess/go/vt/vtgate/engine" @@ -179,10 +178,6 @@ func buildDBPlan(show *sqlparser.ShowBasic, vschema ContextVSchema) (engine.Prim // buildShowVMigrationsPlan serves `SHOW VITESS_MIGRATIONS ...` queries. It invokes queries on _vt.schema_migrations on all MASTER tablets on keyspace's shards. func buildShowVMigrationsPlan(show *sqlparser.ShowBasic, vschema ContextVSchema) (engine.Primitive, error) { - if !*enableOnlineDDL { - return nil, schema.ErrOnlineDDLDisabled - } - dest, ks, tabletType, err := vschema.TargetDestination(show.DbName) if err != nil { return nil, err