Skip to content

Commit

Permalink
storage: improve snapshot sideloading error
Browse files Browse the repository at this point in the history
  • Loading branch information
tbg committed Sep 10, 2017
1 parent adcb743 commit 31d6f93
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 3 additions & 2 deletions pkg/storage/replica_sideload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ func TestRaftSSTableSideloadingSnapshot(t *testing.T) {
tc.store.raftEntryCache.clearTo(tc.repl.RangeID, sideloadedIndex+1)

mockSender := &mockSender{}
if err := sendSnapshot(
err = sendSnapshot(
ctx,
tc.store.cfg.Settings,
mockSender,
Expand All @@ -801,7 +801,8 @@ func TestRaftSSTableSideloadingSnapshot(t *testing.T) {
failingOS,
tc.repl.store.Engine().NewBatch,
func() {},
); errors.Cause(err) != errMustRetrySnapshotDueToTruncation {
)
if _, ok := errors.Cause(err).(*errMustRetrySnapshotDueToTruncation); !ok {
t.Fatal(err)
}
}()
Expand Down
16 changes: 14 additions & 2 deletions pkg/storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3266,7 +3266,16 @@ func snapshotRateLimit(
}
}

var errMustRetrySnapshotDueToTruncation = errors.New("log truncation during snapshot removed sideloaded SSTable")
type errMustRetrySnapshotDueToTruncation struct {
index, term uint64
}

func (e *errMustRetrySnapshotDueToTruncation) Error() string {
return fmt.Sprintf(
"log truncation during snapshot removed sideloaded SSTable at index %d, term %d",
e.index, e.term,
)
}

// sendSnapshot sends an outgoing snapshot via a pre-opened GRPC stream.
func sendSnapshot(
Expand Down Expand Up @@ -3445,7 +3454,10 @@ func sendSnapshot(
// instance by pre-loading them into memory. Or we can make
// log truncation less aggressive about removing sideloaded
// files, by delaying trailing file deletion for a bit.
return errMustRetrySnapshotDueToTruncation
return &errMustRetrySnapshotDueToTruncation{
index: ent.Index,
term: ent.Term,
}
}
return err
}
Expand Down

0 comments on commit 31d6f93

Please sign in to comment.