Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions go/vt/schema/online_ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package schema
import (
"context"
"encoding/json"
"errors"
"fmt"
"regexp"
"strings"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/engine/cached_size.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions go/vt/vtgate/engine/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type DDL struct {
NormalDDL *Send
OnlineDDL *OnlineDDL

OnlineDDLEnabled bool

CreateTempTable bool

noTxNeeded
Expand Down Expand Up @@ -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)
}

Expand Down
5 changes: 5 additions & 0 deletions go/vt/vtgate/planbuilder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package planbuilder

import (
"errors"
"flag"
"sort"

"vitess.io/vitess/go/sqltypes"
Expand All @@ -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")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to have flags all the way in here. Most vtgate flags live here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@systay right! I began that way, but then got into a circular import error, since vtgate package imports planbuilder package, thus I can't reference vtgate package back from planbuilder. Any ideas are welcome.

)

// ContextVSchema defines the interface for this package to fetch
// info about tables.
type ContextVSchema interface {
Expand Down
12 changes: 7 additions & 5 deletions go/vt/vtgate/planbuilder/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ func buildGeneralDDLPlan(sql string, ddlStatement sqlparser.DDLStatement, reserv
}

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
}
Expand Down
7 changes: 7 additions & 0 deletions go/vt/vtgate/planbuilder/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, vschema ContextVSchema) (engine.Primitive, error) {
if !*enableOnlineDDL {
return nil, schema.ErrOnlineDDLDisabled
}
dest, ks, tabletType, err := vschema.TargetDestination("")
if err != nil {
return nil, err
Expand All @@ -50,6 +54,9 @@ func buildAlterMigrationPlan(query string, vschema ContextVSchema) (engine.Primi
}

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
Expand Down