Skip to content

Commit 652f11e

Browse files
kv: handle some additional cases where we need to signal ambiguous result
These ones slipped through the cracks. One is the case of a missing range (because of rebalancing). We want to be careful not to say that the batch failed with the no range error when in fact it may have succeeded. The other is a re-proposal where submission to Raft fails. Again, since the original proposal may have succeeded, we must be careful to also return AmbiguousResultError where appropriate.
1 parent e465692 commit 652f11e

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

pkg/storage/replica.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ const (
174174
// so if the retry does not succeed, care must be taken to correctly inform
175175
// the caller via an AmbiguousResultError.
176176
proposalReproposed
177+
// proposalErrorReproposing indicates that re-proposal
178+
// failed. Because the original proposal may have succeeded, an
179+
// AmbiguousResultError must be returned. The command should not be
180+
// retried.
181+
proposalErrorReproposing
182+
// proposalRangeNoLongerExists indicates the proposal was for a
183+
// range that no longer exists. Because the original proposal may
184+
// have succeeded, an AmbiguousResultError must be returned. The
185+
// command should not be retried.
186+
proposalRangeNoLongerExists
177187
)
178188

179189
// proposalResult indicates the result of a proposal. Exactly one of
@@ -1705,10 +1715,12 @@ func (r *Replica) addWriteCmd(
17051715
br, pErr, retry := r.tryAddWriteCmd(ctx, ba)
17061716
switch retry {
17071717
case proposalIllegalLeaseIndex:
1708-
continue
1718+
continue // retry
17091719
case proposalReproposed:
17101720
ambiguousResult = true
1711-
continue
1721+
continue // retry
1722+
case proposalRangeNoLongerExists, proposalErrorReproposing:
1723+
ambiguousResult = true
17121724
}
17131725
if pErr != nil {
17141726
// If this isn't an end transaction with commit=true, return
@@ -2822,7 +2834,7 @@ func (r *Replica) refreshProposalsLocked(refreshAtDelta int, reason refreshRaftR
28222834
log.Eventf(p.Local.ctx, "re-submitting command %x to Raft: %s", p.Local.idKey, reason)
28232835
if err := r.submitProposalLocked(p); err != nil {
28242836
delete(r.mu.proposals, p.Local.idKey)
2825-
p.Local.finish(proposalResult{Err: roachpb.NewError(err)})
2837+
p.Local.finish(proposalResult{Err: roachpb.NewError(err), ProposalRetry: proposalErrorReproposing})
28262838
}
28272839
}
28282840
}

pkg/storage/store.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,8 +2021,9 @@ func (s *Store) removeReplicaImpl(
20212021
// Clear the pending command queue.
20222022
if len(rep.mu.proposals) > 0 {
20232023
resp := proposalResult{
2024-
Reply: &roachpb.BatchResponse{},
2025-
Err: roachpb.NewError(roachpb.NewRangeNotFoundError(rep.RangeID)),
2024+
Reply: &roachpb.BatchResponse{},
2025+
Err: roachpb.NewError(roachpb.NewRangeNotFoundError(rep.RangeID)),
2026+
ProposalRetry: proposalRangeNoLongerExists,
20262027
}
20272028
for _, p := range rep.mu.proposals {
20282029
p.Local.finish(resp)

0 commit comments

Comments
 (0)