зеркало из https://github.com/github/vitess-gh.git
keep BackupHandle out of Params structs, document struct fiels, other minor edits
Signed-off-by: deepthi <deepthi@planetscale.com>
This commit is contained in:
Родитель
b557848d94
Коммит
06e5a5fc9f
|
@ -100,8 +100,6 @@ func Backup(ctx context.Context, dir, name string, params BackupParams) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return vterrors.Wrap(err, "StartBackup failed")
|
return vterrors.Wrap(err, "StartBackup failed")
|
||||||
}
|
}
|
||||||
// Set params.BackupHandle to the selected backup
|
|
||||||
params.BackupHandle = bh
|
|
||||||
|
|
||||||
be, err := GetBackupEngine()
|
be, err := GetBackupEngine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -109,7 +107,7 @@ func Backup(ctx context.Context, dir, name string, params BackupParams) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take the backup, and either AbortBackup or EndBackup.
|
// Take the backup, and either AbortBackup or EndBackup.
|
||||||
usable, err := be.ExecuteBackup(ctx, params)
|
usable, err := be.ExecuteBackup(ctx, params, bh)
|
||||||
logger := params.Logger
|
logger := params.Logger
|
||||||
var finishErr error
|
var finishErr error
|
||||||
if usable {
|
if usable {
|
||||||
|
@ -291,15 +289,13 @@ func Restore(ctx context.Context, params RestoreParams) (mysql.Position, error)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return rval, err
|
return rval, err
|
||||||
}
|
}
|
||||||
// Set params.BackupHandle to the selected backup
|
|
||||||
params.BackupHandle = bh
|
|
||||||
|
|
||||||
re, err := GetRestoreEngine(ctx, bh)
|
re, err := GetRestoreEngine(ctx, bh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return mysql.Position{}, vterrors.Wrap(err, "Failed to find restore engine")
|
return mysql.Position{}, vterrors.Wrap(err, "Failed to find restore engine")
|
||||||
}
|
}
|
||||||
|
|
||||||
if rval, err = re.ExecuteRestore(ctx, params); err != nil {
|
if rval, err = re.ExecuteRestore(ctx, params, bh); err != nil {
|
||||||
return rval, err
|
return rval, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,40 +40,51 @@ var (
|
||||||
|
|
||||||
// BackupEngine is the interface to take a backup with a given engine.
|
// BackupEngine is the interface to take a backup with a given engine.
|
||||||
type BackupEngine interface {
|
type BackupEngine interface {
|
||||||
ExecuteBackup(ctx context.Context, params BackupParams) (bool, error)
|
ExecuteBackup(ctx context.Context, params BackupParams, bh backupstorage.BackupHandle) (bool, error)
|
||||||
ShouldDrainForBackup() bool
|
ShouldDrainForBackup() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// BackupParams is the struct that holds all params passed to ExecuteBackup
|
// BackupParams is the struct that holds all params passed to ExecuteBackup
|
||||||
type BackupParams struct {
|
type BackupParams struct {
|
||||||
Cnf *Mycnf
|
Cnf *Mycnf
|
||||||
Mysqld MysqlDaemon
|
Mysqld MysqlDaemon
|
||||||
Logger logutil.Logger
|
Logger logutil.Logger
|
||||||
BackupHandle backupstorage.BackupHandle
|
// Concurrency is the value of -concurrency flag given to Backup command
|
||||||
Concurrency int
|
// It determines how many files are processed in parallel
|
||||||
|
Concurrency int
|
||||||
|
// Extra env variables for pre-backup and post-backup transform hooks
|
||||||
HookExtraEnv map[string]string
|
HookExtraEnv map[string]string
|
||||||
TopoServer *topo.Server
|
// TopoServer, Keyspace and Shard are used to discover master tablet
|
||||||
Keyspace string
|
TopoServer *topo.Server
|
||||||
Shard string
|
Keyspace string
|
||||||
|
Shard string
|
||||||
}
|
}
|
||||||
|
|
||||||
// RestoreParams is the struct that holds all params passed to ExecuteRestore
|
// RestoreParams is the struct that holds all params passed to ExecuteRestore
|
||||||
type RestoreParams struct {
|
type RestoreParams struct {
|
||||||
Cnf *Mycnf
|
Cnf *Mycnf
|
||||||
Mysqld MysqlDaemon
|
Mysqld MysqlDaemon
|
||||||
Logger logutil.Logger
|
Logger logutil.Logger
|
||||||
BackupHandle backupstorage.BackupHandle
|
// Concurrency is the value of -restore_concurrency flag (init restore parameter)
|
||||||
Concurrency int
|
// It determines how many files are processed in parallel
|
||||||
HookExtraEnv map[string]string
|
Concurrency int
|
||||||
LocalMetadata map[string]string
|
// Extra env variables for pre-restore and post-restore transform hooks
|
||||||
|
HookExtraEnv map[string]string
|
||||||
|
// Metadata to write into database after restore. See PopulateMetadataTables
|
||||||
|
LocalMetadata map[string]string
|
||||||
|
// DeleteBeforeRestore tells us whether existing data should be deleted before
|
||||||
|
// restoring. This is always set to false when starting a tablet with -restore_from_backup,
|
||||||
|
// but is set to true when executing a RestoreFromBackup command on an already running vttablet
|
||||||
DeleteBeforeRestore bool
|
DeleteBeforeRestore bool
|
||||||
DbName string
|
// Name of the managed database / schema
|
||||||
Dir string
|
DbName string
|
||||||
|
// Directory location to search for a usable backup
|
||||||
|
Dir string
|
||||||
}
|
}
|
||||||
|
|
||||||
// RestoreEngine is the interface to restore a backup with a given engine.
|
// RestoreEngine is the interface to restore a backup with a given engine.
|
||||||
type RestoreEngine interface {
|
type RestoreEngine interface {
|
||||||
ExecuteRestore(ctx context.Context, params RestoreParams) (mysql.Position, error)
|
ExecuteRestore(ctx context.Context, params RestoreParams, bh backupstorage.BackupHandle) (mysql.Position, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BackupRestoreEngine is a combination of BackupEngine and RestoreEngine.
|
// BackupRestoreEngine is a combination of BackupEngine and RestoreEngine.
|
||||||
|
|
|
@ -239,23 +239,18 @@ func findFilesToBackup(cnf *Mycnf) ([]FileEntry, error) {
|
||||||
|
|
||||||
// ExecuteBackup returns a boolean that indicates if the backup is usable,
|
// ExecuteBackup returns a boolean that indicates if the backup is usable,
|
||||||
// and an overall error.
|
// and an overall error.
|
||||||
func (be *BuiltinBackupEngine) ExecuteBackup(ctx context.Context, params BackupParams) (bool, error) {
|
func (be *BuiltinBackupEngine) ExecuteBackup(ctx context.Context, params BackupParams, bh backupstorage.BackupHandle) (bool, error) {
|
||||||
|
|
||||||
// extract all params from BackupParams
|
// extract all params from BackupParams
|
||||||
cnf := params.Cnf
|
cnf := params.Cnf
|
||||||
mysqld := params.Mysqld
|
mysqld := params.Mysqld
|
||||||
logger := params.Logger
|
logger := params.Logger
|
||||||
bh := params.BackupHandle
|
|
||||||
backupConcurrency := params.Concurrency
|
backupConcurrency := params.Concurrency
|
||||||
hookExtraEnv := params.HookExtraEnv
|
hookExtraEnv := params.HookExtraEnv
|
||||||
topoServer := params.TopoServer
|
topoServer := params.TopoServer
|
||||||
keyspace := params.Keyspace
|
keyspace := params.Keyspace
|
||||||
shard := params.Shard
|
shard := params.Shard
|
||||||
|
|
||||||
if bh == nil {
|
|
||||||
return false, vterrors.New(vtrpc.Code_INVALID_ARGUMENT, "ExecuteBackup must be called with a valid BackupHandle")
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.Infof("Hook: %v, Compress: %v", *backupStorageHook, *backupStorageCompress)
|
logger.Infof("Hook: %v, Compress: %v", *backupStorageHook, *backupStorageCompress)
|
||||||
|
|
||||||
// Save initial state so we can restore.
|
// Save initial state so we can restore.
|
||||||
|
@ -353,11 +348,12 @@ func (be *BuiltinBackupEngine) ExecuteBackup(ctx context.Context, params BackupP
|
||||||
return usable, vterrors.Wrap(err, "slave is not restarting")
|
return usable, vterrors.Wrap(err, "slave is not restarting")
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for reliable seconds behind master
|
// Wait for a reliable value for SecondsBehindMaster from SlaveStatus()
|
||||||
// we have replicationPosition where we stopped
|
|
||||||
// if MasterPosition is the same, that means no writes
|
// We know that we stopped at replicationPosition.
|
||||||
// have happened to master, so we are up-to-date
|
// If MasterPosition is the same, that means no writes
|
||||||
// otherwise, wait for replica's Position to change from
|
// have happened to master, so we are up-to-date.
|
||||||
|
// Otherwise, we wait for replica's Position to change from
|
||||||
// the saved replicationPosition before proceeding
|
// the saved replicationPosition before proceeding
|
||||||
tmc := tmclient.NewTabletManagerClient()
|
tmc := tmclient.NewTabletManagerClient()
|
||||||
defer tmc.Close()
|
defer tmc.Close()
|
||||||
|
@ -365,7 +361,7 @@ func (be *BuiltinBackupEngine) ExecuteBackup(ctx context.Context, params BackupP
|
||||||
defer remoteCancel()
|
defer remoteCancel()
|
||||||
|
|
||||||
masterPos, err := getMasterPosition(remoteCtx, tmc, topoServer, keyspace, shard)
|
masterPos, err := getMasterPosition(remoteCtx, tmc, topoServer, keyspace, shard)
|
||||||
// if we are unable to get master position, return error
|
// If we are unable to get master position, return error.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return usable, err
|
return usable, err
|
||||||
}
|
}
|
||||||
|
@ -560,22 +556,15 @@ func (be *BuiltinBackupEngine) backupFile(ctx context.Context, cnf *Mycnf, mysql
|
||||||
// ExecuteRestore restores from a backup. If the restore is successful
|
// ExecuteRestore restores from a backup. If the restore is successful
|
||||||
// we return the position from which replication should start
|
// we return the position from which replication should start
|
||||||
// otherwise an error is returned
|
// otherwise an error is returned
|
||||||
func (be *BuiltinBackupEngine) ExecuteRestore(
|
func (be *BuiltinBackupEngine) ExecuteRestore(ctx context.Context, params RestoreParams, bh backupstorage.BackupHandle) (mysql.Position, error) {
|
||||||
ctx context.Context,
|
|
||||||
params RestoreParams) (mysql.Position, error) {
|
|
||||||
|
|
||||||
cnf := params.Cnf
|
cnf := params.Cnf
|
||||||
mysqld := params.Mysqld
|
mysqld := params.Mysqld
|
||||||
logger := params.Logger
|
logger := params.Logger
|
||||||
bh := params.BackupHandle
|
|
||||||
restoreConcurrency := params.Concurrency
|
restoreConcurrency := params.Concurrency
|
||||||
hookExtraEnv := params.HookExtraEnv
|
hookExtraEnv := params.HookExtraEnv
|
||||||
|
|
||||||
zeroPosition := mysql.Position{}
|
zeroPosition := mysql.Position{}
|
||||||
if bh == nil {
|
|
||||||
return zeroPosition, vterrors.New(vtrpc.Code_INVALID_ARGUMENT, "ExecuteRestore must be called with a valid BackupHandle")
|
|
||||||
}
|
|
||||||
|
|
||||||
var bm builtinBackupManifest
|
var bm builtinBackupManifest
|
||||||
|
|
||||||
if err := getBackupManifestInto(ctx, bh, &bm); err != nil {
|
if err := getBackupManifestInto(ctx, bh, &bm); err != nil {
|
||||||
|
|
|
@ -121,16 +121,11 @@ func closeFile(wc io.WriteCloser, fileName string, logger logutil.Logger, finalE
|
||||||
|
|
||||||
// ExecuteBackup returns a boolean that indicates if the backup is usable,
|
// ExecuteBackup returns a boolean that indicates if the backup is usable,
|
||||||
// and an overall error.
|
// and an overall error.
|
||||||
func (be *XtrabackupEngine) ExecuteBackup(ctx context.Context, params BackupParams) (complete bool, finalErr error) {
|
func (be *XtrabackupEngine) ExecuteBackup(ctx context.Context, params BackupParams, bh backupstorage.BackupHandle) (complete bool, finalErr error) {
|
||||||
// extract all params from BackupParams
|
// extract all params from BackupParams
|
||||||
cnf := params.Cnf
|
cnf := params.Cnf
|
||||||
mysqld := params.Mysqld
|
mysqld := params.Mysqld
|
||||||
logger := params.Logger
|
logger := params.Logger
|
||||||
bh := params.BackupHandle
|
|
||||||
|
|
||||||
if bh == nil {
|
|
||||||
return false, vterrors.New(vtrpc.Code_INVALID_ARGUMENT, "ExecuteBackup must be called with a valid BackupHandle")
|
|
||||||
}
|
|
||||||
|
|
||||||
if *xtrabackupUser == "" {
|
if *xtrabackupUser == "" {
|
||||||
return false, vterrors.New(vtrpc.Code_INVALID_ARGUMENT, "xtrabackupUser must be specified.")
|
return false, vterrors.New(vtrpc.Code_INVALID_ARGUMENT, "xtrabackupUser must be specified.")
|
||||||
|
@ -372,20 +367,13 @@ func (be *XtrabackupEngine) backupFiles(ctx context.Context, cnf *Mycnf, logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExecuteRestore restores from a backup. Any error is returned.
|
// ExecuteRestore restores from a backup. Any error is returned.
|
||||||
func (be *XtrabackupEngine) ExecuteRestore(
|
func (be *XtrabackupEngine) ExecuteRestore(ctx context.Context, params RestoreParams, bh backupstorage.BackupHandle) (mysql.Position, error) {
|
||||||
ctx context.Context,
|
|
||||||
params RestoreParams) (mysql.Position, error) {
|
|
||||||
|
|
||||||
cnf := params.Cnf
|
cnf := params.Cnf
|
||||||
mysqld := params.Mysqld
|
mysqld := params.Mysqld
|
||||||
logger := params.Logger
|
logger := params.Logger
|
||||||
bh := params.BackupHandle
|
|
||||||
|
|
||||||
zeroPosition := mysql.Position{}
|
zeroPosition := mysql.Position{}
|
||||||
if bh == nil {
|
|
||||||
return zeroPosition, vterrors.New(vtrpc.Code_INVALID_ARGUMENT, "ExecuteRestore must be called with a valid BackupHandle")
|
|
||||||
}
|
|
||||||
|
|
||||||
var bm xtraBackupManifest
|
var bm xtraBackupManifest
|
||||||
|
|
||||||
if err := getBackupManifestInto(ctx, bh, &bm); err != nil {
|
if err := getBackupManifestInto(ctx, bh, &bm); err != nil {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче