Skip to content

Commit f71b94c

Browse files
authored
Merge branch 'vitessio:main' into vtadmin-monitoring-integration
2 parents f210427 + 8ce3eb2 commit f71b94c

File tree

22 files changed

+2400
-441
lines changed

22 files changed

+2400
-441
lines changed

.github/workflows/codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ permissions: read-all
1616
jobs:
1717
test:
1818
name: Code Coverage
19-
runs-on: ubuntu-24.04
19+
runs-on: oracle-vm-8cpu-32gb-x86-64
2020

2121
steps:
2222
- name: Check out code

.github/workflows/upgrade_downgrade_test_query_serving_queries.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,6 @@ jobs:
142142
run: |
143143
find ./go/test/endtoend -name '*.go' -exec sed -i 's/ErrorContains/Error/g' {} +
144144
find ./go/test/endtoend -name '*.go' -exec sed -i 's/EqualError/Error/g' {} +
145-
# Relax TestSpecializedPlan for < v24 due to window functions error message change.
146-
# <= v23: "VT12001: unsupported: OVER CLAUSE with sharded keyspace"
147-
# >= v24: "VT12001: unsupported: window functions are only supported for single-shard queries"
148-
# Use Contains check to accept both versions.
149-
ref="${{ steps.output-previous-release-ref.outputs.previous_release_ref }}"
150-
version=$(echo "$ref" | sed 's/release-//' | cut -d. -f1)
151-
if [ "$version" -lt 24 ]; then
152-
sed -i 's/require\.EqualValues(t, "VT12001: unsupported: OVER CLAUSE with sharded keyspace", pm\["BaselineErr"\])/require.Contains(t, pm["BaselineErr"].(string), "VT12001: unsupported:")/' go/test/endtoend/preparestmt/stmt_methods_test.go
153-
fi
154145
155146
# Swap the binaries in the bin. Use vtgate version n-1 and keep vttablet at version n
156147
- name: Use last release's VTGate

go/cmd/vtbackup/cli/vtbackup.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,24 @@ import (
3535
"vitess.io/vitess/go/exit"
3636
"vitess.io/vitess/go/mysql/collations"
3737
"vitess.io/vitess/go/mysql/replication"
38+
"vitess.io/vitess/go/protoutil"
3839
"vitess.io/vitess/go/stats"
3940
"vitess.io/vitess/go/vt/dbconfigs"
4041
"vitess.io/vitess/go/vt/log"
4142
"vitess.io/vitess/go/vt/logutil"
4243
"vitess.io/vitess/go/vt/mysqlctl"
4344
"vitess.io/vitess/go/vt/mysqlctl/backupstats"
4445
"vitess.io/vitess/go/vt/mysqlctl/backupstorage"
45-
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
4646
"vitess.io/vitess/go/vt/servenv"
4747
"vitess.io/vitess/go/vt/topo"
4848
"vitess.io/vitess/go/vt/topo/topoproto"
4949
"vitess.io/vitess/go/vt/utils"
5050
"vitess.io/vitess/go/vt/vterrors"
5151
_ "vitess.io/vitess/go/vt/vttablet/grpctmclient"
5252
"vitess.io/vitess/go/vt/vttablet/tmclient"
53+
54+
tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
55+
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
5356
)
5457

5558
const (
@@ -79,6 +82,10 @@ var (
7982
allowFirstBackup bool
8083
restartBeforeBackup bool
8184
upgradeSafe bool
85+
initSQLQueries []string
86+
initSQLTabletTypes []topodatapb.TabletType
87+
initSQLTimeout time.Duration
88+
initSQLFailOnError bool
8289

8390
// vttablet-like flags
8491
initDbNameOverride string
@@ -208,6 +215,10 @@ func init() {
208215
utils.SetFlagBoolVar(Main.Flags(), &allowFirstBackup, "allow-first-backup", allowFirstBackup, "Allow this job to take the first backup of an existing shard.")
209216
utils.SetFlagBoolVar(Main.Flags(), &restartBeforeBackup, "restart-before-backup", restartBeforeBackup, "Perform a mysqld clean/full restart after applying binlogs, but before taking the backup. Only makes sense to work around xtrabackup bugs.")
210217
Main.Flags().BoolVar(&upgradeSafe, "upgrade-safe", upgradeSafe, "Whether to use innodb_fast_shutdown=0 for the backup so it is safe to use for MySQL upgrades.")
218+
Main.Flags().StringSliceVar(&initSQLQueries, "init-backup-sql-queries", nil, "Queries to execute before initializing the backup")
219+
Main.Flags().Var((*topoproto.TabletTypeListFlag)(&initSQLTabletTypes), "init-backup-tablet-types", "Tablet types used for the backup where the init SQL queries (--init-backup-sql-queries) will be executed before initializing the backup")
220+
Main.Flags().DurationVar(&initSQLTimeout, "init-backup-sql-timeout", initSQLTimeout, "At what point should we time out the init SQL query (--init-backup-sql-queries) work and either fail the backup job (--init-backup-sql-fail-on-error) or continue on with the backup")
221+
Main.Flags().BoolVar(&initSQLFailOnError, "init-backup-sql-fail-on-error", false, "Whether or not to fail the backup if the init SQL queries (--init-backup-sql-queries) fail, which includes if they fail to complete before the specified timeout (--init-backup-sql-timeout)")
211222

212223
// vttablet-like flags
213224
utils.SetFlagStringVar(Main.Flags(), &initDbNameOverride, "init-db-name-override", initDbNameOverride, "(init parameter) override the name of the db used by vttablet")
@@ -394,9 +405,16 @@ func takeBackup(ctx, backgroundCtx context.Context, topoServer *topo.Server, bac
394405
Keyspace: initKeyspace,
395406
Shard: initShard,
396407
TabletAlias: topoproto.TabletAliasString(tabletAlias),
408+
TabletType: topodatapb.TabletType_BACKUP,
397409
Stats: backupstats.BackupStats(),
398410
UpgradeSafe: upgradeSafe,
399411
MysqlShutdownTimeout: mysqlShutdownTimeout,
412+
InitSQL: &tabletmanagerdatapb.BackupRequest_InitSQL{
413+
Queries: initSQLQueries,
414+
TabletTypes: initSQLTabletTypes,
415+
Timeout: protoutil.DurationToProto(initSQLTimeout),
416+
FailOnError: initSQLFailOnError,
417+
},
400418
}
401419
// In initial_backup mode, just take a backup of this empty database.
402420
if initialBackup {
@@ -489,6 +507,11 @@ func takeBackup(ctx, backgroundCtx context.Context, topoServer *topo.Server, bac
489507
}
490508
}
491509

510+
// Perform any requested pre backup initialization queries.
511+
if err := mysqlctl.ExecuteBackupInitSQL(ctx, &backupParams); err != nil {
512+
return vterrors.Wrap(err, "failed to execute backup init SQL queries")
513+
}
514+
492515
// We have restored a backup. Now start replication.
493516
if err := resetReplication(ctx, restorePos, mysqld); err != nil {
494517
return fmt.Errorf("error resetting replication: %v", err)

go/cmd/vtctldclient/command/backups.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
"vitess.io/vitess/go/vt/mysqlctl"
3131
"vitess.io/vitess/go/vt/topo/topoproto"
3232

33+
tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
34+
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
3335
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
3436
)
3537

@@ -86,14 +88,33 @@ var backupOptions = struct {
8688
IncrementalFromPos string
8789
UpgradeSafe bool
8890
MysqlShutdownTimeout time.Duration
91+
InitSQLQueries []string
92+
InitSQLTabletTypes []topodatapb.TabletType
93+
InitSQLTimeout time.Duration
94+
InitSQLFailOnError bool
8995
}{}
9096

97+
func validateBackupOptions() error {
98+
if len(backupOptions.InitSQLQueries) > 0 {
99+
if len(backupOptions.InitSQLTabletTypes) == 0 {
100+
return errors.New("backup init SQL queries provided but no tablet types on which to run them")
101+
}
102+
if backupOptions.InitSQLTimeout == 0 {
103+
return errors.New("backup init SQL queries provided but no timeout provided -- this is dangerous and not allowed")
104+
}
105+
}
106+
return nil
107+
}
108+
91109
func commandBackup(cmd *cobra.Command, args []string) error {
92110
tabletAlias, err := topoproto.ParseTabletAlias(cmd.Flags().Arg(0))
93111
if err != nil {
94112
return err
95113
}
96114

115+
if err := validateBackupOptions(); err != nil {
116+
return err
117+
}
97118
cli.FinishedParsing(cmd)
98119

99120
req := &vtctldatapb.BackupRequest{
@@ -103,6 +124,12 @@ func commandBackup(cmd *cobra.Command, args []string) error {
103124
IncrementalFromPos: backupOptions.IncrementalFromPos,
104125
UpgradeSafe: backupOptions.UpgradeSafe,
105126
MysqlShutdownTimeout: protoutil.DurationToProto(backupOptions.MysqlShutdownTimeout),
127+
InitSql: &tabletmanagerdatapb.BackupRequest_InitSQL{
128+
Queries: backupOptions.InitSQLQueries,
129+
TabletTypes: backupOptions.InitSQLTabletTypes,
130+
Timeout: protoutil.DurationToProto(backupOptions.InitSQLTimeout),
131+
FailOnError: backupOptions.InitSQLFailOnError,
132+
},
106133
}
107134

108135
if backupOptions.BackupEngine != "" {
@@ -141,6 +168,9 @@ func commandBackupShard(cmd *cobra.Command, args []string) error {
141168
return err
142169
}
143170

171+
if err := validateBackupOptions(); err != nil {
172+
return err
173+
}
144174
cli.FinishedParsing(cmd)
145175

146176
stream, err := client.BackupShard(commandCtx, &vtctldatapb.BackupShardRequest{
@@ -151,6 +181,12 @@ func commandBackupShard(cmd *cobra.Command, args []string) error {
151181
IncrementalFromPos: backupShardOptions.IncrementalFromPos,
152182
UpgradeSafe: backupShardOptions.UpgradeSafe,
153183
MysqlShutdownTimeout: protoutil.DurationToProto(backupShardOptions.MysqlShutdownTimeout),
184+
InitSql: &tabletmanagerdatapb.BackupRequest_InitSQL{
185+
Queries: backupOptions.InitSQLQueries,
186+
TabletTypes: backupOptions.InitSQLTabletTypes,
187+
Timeout: protoutil.DurationToProto(backupOptions.InitSQLTimeout),
188+
FailOnError: backupOptions.InitSQLFailOnError,
189+
},
154190
})
155191
if err != nil {
156192
return err
@@ -300,13 +336,15 @@ func init() {
300336

301337
Backup.Flags().BoolVar(&backupOptions.UpgradeSafe, "upgrade-safe", false, "Whether to use innodb_fast_shutdown=0 for the backup so it is safe to use for MySQL upgrades.")
302338
Backup.Flags().DurationVar(&backupOptions.MysqlShutdownTimeout, "mysql-shutdown-timeout", mysqlctl.DefaultShutdownTimeout, "Timeout to use when MySQL is being shut down.")
339+
addInitSQLFlags(Backup)
303340
Root.AddCommand(Backup)
304341

305342
BackupShard.Flags().BoolVar(&backupShardOptions.AllowPrimary, "allow-primary", false, "Allow the primary of a shard to be used for the backup. WARNING: If using the builtin backup engine, this will shutdown mysqld on the primary and stop writes for the duration of the backup.")
306343
BackupShard.Flags().Int32Var(&backupShardOptions.Concurrency, "concurrency", 4, "Specifies the number of compression/checksum jobs to run simultaneously.")
307344
BackupShard.Flags().StringVar(&backupShardOptions.IncrementalFromPos, "incremental-from-pos", "", "Position, or name of backup from which to create an incremental backup. Default: empty. If given, then this backup becomes an incremental backup from given position or given backup. If value is 'auto', this backup will be taken from the last successful backup position.")
308345
BackupShard.Flags().BoolVar(&backupShardOptions.UpgradeSafe, "upgrade-safe", false, "Whether to use innodb_fast_shutdown=0 for the backup so it is safe to use for MySQL upgrades.")
309346
BackupShard.Flags().DurationVar(&backupShardOptions.MysqlShutdownTimeout, "mysql-shutdown-timeout", mysqlctl.DefaultShutdownTimeout, "Timeout to use when MySQL is being shut down.")
347+
addInitSQLFlags(BackupShard)
310348
Root.AddCommand(BackupShard)
311349

312350
GetBackups.Flags().Uint32VarP(&getBackupsOptions.Limit, "limit", "l", 0, "Retrieve only the most recent N backups.")
@@ -322,3 +360,10 @@ func init() {
322360
RestoreFromBackup.Flags().BoolVar(&restoreFromBackupOptions.DryRun, "dry-run", false, "Only validate restore steps, do not actually restore data")
323361
Root.AddCommand(RestoreFromBackup)
324362
}
363+
364+
func addInitSQLFlags(cmd *cobra.Command) {
365+
cmd.Flags().StringSliceVar(&backupOptions.InitSQLQueries, "init-backup-sql-queries", nil, "Queries to execute before initializing the backup")
366+
cmd.Flags().Var((*topoproto.TabletTypeListFlag)(&backupOptions.InitSQLTabletTypes), "init-backup-tablet-types", "Tablet types used for the backup where the init SQL queries (--init-backup-sql-queries) will be executed before initializing the backup")
367+
cmd.Flags().DurationVar(&backupOptions.InitSQLTimeout, "init-backup-sql-timeout", backupOptions.InitSQLTimeout, "At what point should we time out the init SQL query (--init-backup-sql-queries) work and either fail the backup job (--init-backup-sql-fail-on-error) or continue on with the backup")
368+
cmd.Flags().BoolVar(&backupOptions.InitSQLFailOnError, "init-backup-sql-fail-on-error", false, "Whether or not to fail the backup if the init SQL queries (--init-backup-sql-queries) fail, which includes if they fail to complete before the specified timeout (--init-backup-sql-timeout)")
369+
}

0 commit comments

Comments
 (0)