Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
cherry pick #1036 to release-5.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <[email protected]>
  • Loading branch information
YuJuncen authored and ti-srebot committed Apr 20, 2021
1 parent b3bd549 commit 714d1ca
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions pkg/backup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,6 @@ func (bc *Client) handleFineGrained(
return 0, errors.Trace(pderr)
}
storeID := leader.GetStoreId()
max := 0

req := backuppb.BackupRequest{
ClusterId: bc.clusterID,
Expand All @@ -834,21 +833,27 @@ func (bc *Client) handleFineGrained(
log.Error("fail to connect store", zap.Uint64("StoreID", storeID))
return 0, errors.Annotatef(err, "failed to connect to store %d", storeID)
}
hasProgress := false
backoffMill := 0
err = SendBackup(
ctx, storeID, client, req,
// Handle responses with the same backoffer.
func(resp *backuppb.BackupResponse) error {
response, backoffMs, err1 :=
response, shouldBackoff, err1 :=
OnBackupResponse(storeID, bo, backupTS, lockResolver, resp)
if err1 != nil {
return err1
}
if max < backoffMs {
max = backoffMs
if backoffMill < shouldBackoff {
backoffMill = shouldBackoff
}
if response != nil {
respCh <- response
}
// When meet an error, we need to set hasProgress too, in case of
// overriding the backoffTime of original error.
// hasProgress would be false iff there is a early io.EOF from the stream.
hasProgress = true
return nil
},
func() (backuppb.BackupClient, error) {
Expand All @@ -866,7 +871,14 @@ func (bc *Client) handleFineGrained(
return 0, errors.Annotatef(err, "failed to send fine-grained backup [%s, %s)",
redact.Key(req.StartKey), redact.Key(req.EndKey))
}
return max, nil

// If no progress, backoff 10s for debouncing.
// 10s is the default interval of stores sending a heartbeat to the PD.
// And is the average new leader election timeout, which would be a reasonable back off time.
if !hasProgress {
backoffMill = 10000
}
return backoffMill, nil
}

// SendBackup send backup request to the given store.
Expand Down

0 comments on commit 714d1ca

Please sign in to comment.