Skip to content

Commit

Permalink
br: remove error when create the backup client to make caller easier (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
3AceShowHand authored Nov 22, 2022
1 parent f894d9b commit 6477e75
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 24 deletions.
4 changes: 2 additions & 2 deletions br/pkg/backup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ type Client struct {
}

// NewBackupClient returns a new backup client.
func NewBackupClient(ctx context.Context, mgr ClientMgr) (*Client, error) {
func NewBackupClient(ctx context.Context, mgr ClientMgr) *Client {
log.Info("new backup client")
pdClient := mgr.GetPDClient()
clusterID := pdClient.GetClusterID(ctx)
return &Client{
clusterID: clusterID,
mgr: mgr,
}, nil
}
}

// GetTS gets a new timestamp from PD.
Expand Down
3 changes: 1 addition & 2 deletions br/pkg/backup/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ func createBackupSuite(t *testing.T) *testBackup {
mockMgr := &conn.Mgr{PdController: &pdutil.PdController{}}
mockMgr.SetPDClient(s.mockPDClient)
mockMgr.SetHTTP([]string{"test"}, nil)
s.backupClient, err = backup.NewBackupClient(s.ctx, mockMgr)
require.NoError(t, err)
s.backupClient = backup.NewBackupClient(s.ctx, mockMgr)

s.cluster, err = mock.NewCluster()
require.NoError(t, err)
Expand Down
13 changes: 5 additions & 8 deletions br/pkg/task/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,7 @@ func RunBackup(c context.Context, g glue.Glue, cmdName string, cfg *BackupConfig
return errors.Trace(err)
}

client, err := backup.NewBackupClient(ctx, mgr)
if err != nil {
return errors.Trace(err)
}
client := backup.NewBackupClient(ctx, mgr)
opts := storage.ExternalStorageOptions{
NoCredentials: cfg.NoCreds,
SendCredentials: cfg.SendCreds,
Expand All @@ -348,8 +345,10 @@ func RunBackup(c context.Context, g glue.Glue, cmdName string, cfg *BackupConfig
TTL: client.GetGCTTL(),
ID: utils.MakeSafePointID(),
}

// use lastBackupTS as safePoint if exists
if cfg.LastBackupTS > 0 {
isIncrementalBackup := cfg.LastBackupTS > 0
if isIncrementalBackup {
sp.BackupTS = cfg.LastBackupTS
}

Expand All @@ -359,8 +358,6 @@ func RunBackup(c context.Context, g glue.Glue, cmdName string, cfg *BackupConfig
return errors.Trace(err)
}

isIncrementalBackup := cfg.LastBackupTS > 0

if cfg.RemoveSchedulers {
log.Debug("removing some PD schedulers")
restore, e := mgr.RemoveSchedulers(ctx)
Expand Down Expand Up @@ -422,7 +419,7 @@ func RunBackup(c context.Context, g glue.Glue, cmdName string, cfg *BackupConfig
}

// nothing to backup
if ranges == nil || len(ranges) <= 0 {
if len(ranges) == 0 {
pdAddress := strings.Join(cfg.PD, ",")
log.Warn("Nothing to backup, maybe connected to cluster for restoring",
zap.String("PD address", pdAddress))
Expand Down
5 changes: 1 addition & 4 deletions br/pkg/task/backup_ebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ func RunBackupEBS(c context.Context, g glue.Glue, cfg *BackupConfig) error {
return errors.Trace(err)
}
defer mgr.Close()
client, err := backup.NewBackupClient(ctx, mgr)
if err != nil {
return errors.Trace(err)
}
client := backup.NewBackupClient(ctx, mgr)

opts := storage.ExternalStorageOptions{
NoCredentials: cfg.NoCreds,
Expand Down
5 changes: 1 addition & 4 deletions br/pkg/task/backup_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ func RunBackupRaw(c context.Context, g glue.Glue, cmdName string, cfg *RawKvConf
}
defer mgr.Close()

client, err := backup.NewBackupClient(ctx, mgr)
if err != nil {
return errors.Trace(err)
}
client := backup.NewBackupClient(ctx, mgr)
opts := storage.ExternalStorageOptions{
NoCredentials: cfg.NoCreds,
SendCredentials: cfg.SendCreds,
Expand Down
5 changes: 1 addition & 4 deletions br/pkg/task/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,7 @@ func NewStreamMgr(ctx context.Context, cfg *StreamConfig, g glue.Glue, isStreamS
mgr: mgr,
}
if isStreamStart {
client, err := backup.NewBackupClient(ctx, mgr)
if err != nil {
return nil, errors.Trace(err)
}
client := backup.NewBackupClient(ctx, mgr)

backend, err := storage.ParseBackend(cfg.Storage, &cfg.BackendOptions)
if err != nil {
Expand Down

0 comments on commit 6477e75

Please sign in to comment.