Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions pbm/restore/physical.go
Original file line number Diff line number Diff line change
Expand Up @@ -1076,15 +1076,24 @@ func (r *PhysRestore) Snapshot(
}

var progress nodeStatus
var finalStat defs.Status
defer func() {
if err != nil && !errors.Is(err, ErrNoDataForShard) {
r.MarkFailed(err)
}

noerr := err == nil
err = r.close(noerr, progress)
if err != nil {
err = errors.Wrap(err, "snapshot close")
cerr := r.close(noerr, progress)

if cerr != nil && err == nil {
Copy link
Preview

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The error handling logic could be simplified. Consider using a more straightforward approach where you preserve the original error if it exists, otherwise use the close error.

Suggested change
if cerr != nil && err == nil {
if err == nil && cerr != nil {

Copilot uses AI. Check for mistakes.

err = errors.Wrap(cerr, "snapshot close")
}

if noerr && err == nil {
Copy link
Preview

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition noerr && err == nil is redundant since noerr is defined as err == nil. You can simplify this to just if noerr {.

Suggested change
if noerr && err == nil {
if err == nil {

Copilot uses AI. Check for mistakes.

r.log.Info("writing restore meta")
if derr := r.dumpMeta(meta, finalStat, ""); derr != nil {
r.log.Warning("writing restore meta to storage: %v", derr)
}
}
}()

Expand Down Expand Up @@ -1299,12 +1308,12 @@ func (r *PhysRestore) Snapshot(
// next.
progress |= restoreDone

stat, err := r.toState(defs.StatusDone)
finalStat, err = r.toState(defs.StatusDone)
if err != nil {
if r.nodeInfo.IsLeader() {
// before returning try to create meta
r.log.Info("writing restore meta")
merr := r.dumpMeta(meta, stat, "")
merr := r.dumpMeta(meta, finalStat, "")
if merr != nil {
r.log.Warning("writing restore meta to storage: %v", merr)
}
Expand All @@ -1317,12 +1326,6 @@ func (r *PhysRestore) Snapshot(
r.log.Warning("write download stat: %v", err)
}

r.log.Info("writing restore meta")
err = r.dumpMeta(meta, stat, "")
if err != nil {
return errors.Wrap(err, "writing restore meta to storage")
}

return nil
}

Expand Down
Loading