@@ -196,50 +196,50 @@ func (b *BatchCaretaker) Cancel() error {
196196 switch batchState {
197197 // In the pending state, the batch seedlings have not sprouted yet.
198198 case BatchStatePending , BatchStateFrozen :
199- finalBatchState := BatchStateSeedlingCancelled
200199 err := b .cfg .Log .UpdateBatchState (
201200 ctx , b .cfg .Batch .BatchKey .PubKey ,
202- finalBatchState ,
201+ BatchStateSeedlingCancelled ,
203202 )
204203 if err != nil {
205204 err = fmt .Errorf ("BatchCaretaker(%x), batch state(%v), " +
206205 "cancel failed: %w" , batchKey , batchState , err )
207206 }
208207
209- cancelResp = CancelResp {& finalBatchState , err }
208+ cancelResp = CancelResp {true , err }
210209
211210 case BatchStateCommitted :
212- finalBatchState := BatchStateSproutCancelled
213211 err := b .cfg .Log .UpdateBatchState (
214212 ctx , b .cfg .Batch .BatchKey .PubKey ,
215- finalBatchState ,
213+ BatchStateSproutCancelled ,
216214 )
217215 if err != nil {
218216 err = fmt .Errorf ("BatchCaretaker(%x), batch state(%v), " +
219217 "cancel failed: %w" , batchKey , batchState , err )
220218 }
221219
222- cancelResp = CancelResp {& finalBatchState , err }
220+ cancelResp = CancelResp {true , err }
223221
224222 default :
225223 err := fmt .Errorf ("BatchCaretaker(%x), batch not cancellable" ,
226224 b .cfg .Batch .BatchKey .PubKey .SerializeCompressed ())
227- cancelResp = CancelResp {nil , err }
225+ cancelResp = CancelResp {false , err }
228226 }
229227
230228 b .cfg .CancelRespChan <- cancelResp
231229
232- // If the batch was cancellable, the finalState of the cancel response
233- // will be non-nil. If the cancellation failed, that error will be
234- // handled by the planter. At this point, the caretaker should always
235- // shut down gracefully .
236- if cancelResp .finalState != nil {
230+ // If the batch was cancellable, the final write of the cancelled batch
231+ // may still have failed. That error will be handled by the planter. At
232+ // this point, the caretaker should shut down gracefully if cancellation
233+ // was attempted .
234+ if cancelResp .cancelAttempted {
237235 log .Infof ("BatchCaretaker(%x), attempted batch cancellation, " +
238236 "shutting down" , b .batchKey [:])
239237
240238 return nil
241239 }
242240
241+ // If the cancellation failed, that error will be handled by the
242+ // planter.
243243 return fmt .Errorf ("BatchCaretaker(%x) cancellation failed" ,
244244 b .batchKey [:])
245245}
0 commit comments