Skip to content

Commit

Permalink
Send error event when sending ZFS fails
Browse files Browse the repository at this point in the history
  • Loading branch information
vansante committed Jan 20, 2025
1 parent 1064b6e commit 12342e9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions job/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const (
StartSendingSnapshotEvent eventemitter.EventType = "start-sending-snapshot"
SnapshotSendingProgressEvent eventemitter.EventType = "snapshot-sending-progress"
ResumeSendingSnapshotEvent eventemitter.EventType = "resume-sending-snapshot"
SendSnapshotErrorEvent eventemitter.EventType = "send-snapshot-error"
SentSnapshotEvent eventemitter.EventType = "sent-snapshot"
MarkSnapshotDeletionEvent eventemitter.EventType = "mark-snapshot-deletion"
DeletedSnapshotEvent eventemitter.EventType = "deleted-snapshot"
Expand Down
4 changes: 4 additions & 0 deletions job/snapshots_send.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ func (r *Runner) resumeSendSnapshot(client *zfshttp.Client, ds *zfs.Dataset, rem
)
return true, nil
case err != nil:
r.EmitEvent(SendSnapshotErrorEvent, fullSnapName, client.Server(), err)

return false, fmt.Errorf("error resuming send of %s (sent %d bytes in %s): %w",
fullSnapName, result.BytesSent, result.TimeTaken, err,
)
Expand Down Expand Up @@ -326,6 +328,8 @@ func (r *Runner) sendSnapshot(client *zfshttp.Client, send zfshttp.SnapshotSendO
)
return nil
case err != nil:
r.EmitEvent(SendSnapshotErrorEvent, send.Snapshot.Name, client.Server(), err)

return fmt.Errorf("error sending %s@%s (sent %d bytes in %s): %w",
send.DatasetName, send.SnapshotName, result.BytesSent, result.TimeTaken, err,
)
Expand Down
13 changes: 13 additions & 0 deletions job/snapshots_send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,21 @@ func TestRunner_sendCancelSnapshots(t *testing.T) {
sends[0].CancelSend()
})

gotErr := false
runner.AddListener(SendSnapshotErrorEvent, func(args ...interface{}) {
require.Len(t, args, 3)

require.Equal(t, sendSnaps[0], args[0])
require.Equal(t, "server", args[1])
require.Error(t, args[2].(error))

t.Logf("got error: %#v", args[2])
gotErr = true
})

err := runner.sendSnapshots(1)
require.ErrorIs(t, err, context.Canceled)
require.True(t, gotErr)
})
}

Expand Down

0 comments on commit 12342e9

Please sign in to comment.