Skip to content

Commit

Permalink
Retry when dataset is busy
Browse files Browse the repository at this point in the history
  • Loading branch information
corny committed May 13, 2024
1 parent 78ecf4a commit 7389f81
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions zfs/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os/exec"
"strings"
"sync"
"time"

pb "gopkg.in/cheggaaa/pb.v1"
)
Expand Down Expand Up @@ -59,8 +60,26 @@ func (t *Transfer) sendSize() (int64, error) {
return parseTransferSize(out)
}

func (t *Transfer) RunWithRetry() error {
retries := 0
var err error

for {
err = t.run()
if err == nil || retries > 2 || !strings.Contains(err.Error(), "dataset is busy") {
break
}

retries++
log.Printf("dataset is busy, retrying in %d seconds", retries)
time.Sleep(time.Second * time.Duration(retries))
}

return err
}

// Run performs sync
func (t *Transfer) Run() error {
func (t *Transfer) run() error {
var err error
var size int64

Expand Down Expand Up @@ -168,7 +187,7 @@ func DoSync(from, to *Fs, flags Flags) error {
transfer.PreviousSnapshot = previous
transfer.CurrentSnapshot = current

if err := transfer.Run(); err != nil {
if err := transfer.RunWithRetry(); err != nil {
return err
}
previous = current
Expand Down

0 comments on commit 7389f81

Please sign in to comment.