Skip to content

Commit

Permalink
Merge pull request #7587 from planetscale/apply-schema-skip-preflight
Browse files Browse the repository at this point in the history
ApplySchema: -skip_preflight
  • Loading branch information
deepthi committed Mar 4, 2021
2 parents 7a5e4fe + 36e8794 commit fb9bc3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 9 additions & 0 deletions go/vt/schemamanager/tablet_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type TabletExecutor struct {
keyspace string
waitReplicasTimeout time.Duration
ddlStrategy string
skipPreflight bool
}

// NewTabletExecutor creates a new TabletExecutor instance
Expand Down Expand Up @@ -76,6 +77,11 @@ func (exec *TabletExecutor) SetDDLStrategy(ddlStrategy string) error {
return nil
}

// SkipPreflight disables preflight checks
func (exec *TabletExecutor) SkipPreflight() {
exec.skipPreflight = true
}

// Open opens a connection to the master for every shard.
func (exec *TabletExecutor) Open(ctx context.Context, keyspace string) error {
if !exec.isClosed {
Expand Down Expand Up @@ -212,6 +218,9 @@ func (exec *TabletExecutor) detectBigSchemaChanges(ctx context.Context, parsedDD
}

func (exec *TabletExecutor) preflightSchemaChanges(ctx context.Context, sqls []string) error {
if exec.skipPreflight {
return nil
}
_, err := exec.wr.TabletManagerClient().PreflightSchema(ctx, exec.tablets[0], sqls)
return err
}
Expand Down
8 changes: 6 additions & 2 deletions go/vt/vtctl/vtctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ var commands = []commandGroup{
"[-exclude_tables=''] [-include-views] [-skip-no-master] <keyspace name>",
"Validates that the master schema from shard 0 matches the schema on all of the other tablets in the keyspace."},
{"ApplySchema", commandApplySchema,
"[-allow_long_unavailability] [-wait_replicas_timeout=10s] [-ddl_strategy=<ddl_strategy>] {-sql=<sql> || -sql-file=<filename>} <keyspace>",
"Applies the schema change to the specified keyspace on every master, running in parallel on all shards. The changes are then propagated to replicas via replication. If -allow_long_unavailability is set, schema changes affecting a large number of rows (and possibly incurring a longer period of unavailability) will not be rejected. ddl_strategy is used to intruct migrations via gh-ost or pt-osc with optional parameters"},
"[-allow_long_unavailability] [-wait_replicas_timeout=10s] [-ddl_strategy=<ddl_strategy>] [-skip_preflight] {-sql=<sql> || -sql-file=<filename>} <keyspace>",
"Applies the schema change to the specified keyspace on every master, running in parallel on all shards. The changes are then propagated to replicas via replication. If -allow_long_unavailability is set, schema changes affecting a large number of rows (and possibly incurring a longer period of unavailability) will not be rejected. ddl_strategy is used to intruct migrations via gh-ost or pt-osc with optional parameters. If -skip_preflight, SQL goes directly to shards without going through sanity checks"},
{"CopySchemaShard", commandCopySchemaShard,
"[-tables=<table1>,<table2>,...] [-exclude_tables=<table1>,<table2>,...] [-include-views] [-skip-verify] [-wait_replicas_timeout=10s] {<source keyspace/shard> || <source tablet alias>} <destination keyspace/shard>",
"Copies the schema from a source shard's master (or a specific tablet) to a destination shard. The schema is applied directly on the master of the destination shard, and it is propagated to the replicas through binlogs."},
Expand Down Expand Up @@ -2853,6 +2853,7 @@ func commandApplySchema(ctx context.Context, wr *wrangler.Wrangler, subFlags *fl
sqlFile := subFlags.String("sql-file", "", "Identifies the file that contains the SQL commands")
ddlStrategy := subFlags.String("ddl_strategy", string(schema.DDLStrategyDirect), "Online DDL strategy, compatible with @@ddl_strategy session variable (examples: 'gh-ost', 'pt-osc', 'gh-ost --max-load=Threads_running=100'")
waitReplicasTimeout := subFlags.Duration("wait_replicas_timeout", wrangler.DefaultWaitReplicasTimeout, "The amount of time to wait for replicas to receive the schema change via replication.")
skipPreflight := subFlags.Bool("skip_preflight", false, "Skip pre-apply schema checks, and dircetly forward schema change query to shards")
if err := subFlags.Parse(args); err != nil {
return err
}
Expand All @@ -2874,6 +2875,9 @@ func commandApplySchema(ctx context.Context, wr *wrangler.Wrangler, subFlags *fl
if *allowLongUnavailability {
executor.AllowBigSchemaChange()
}
if *skipPreflight {
executor.SkipPreflight()
}
if err := executor.SetDDLStrategy(*ddlStrategy); err != nil {
return nil
}
Expand Down

0 comments on commit fb9bc3d

Please sign in to comment.