[SERVER-61252] TMDS and TMRS should use CancelableExecutors instead of explicitly checking for token cancellation Created: 04/Nov/21  Updated: 29/Sep/22  Resolved: 29/Sep/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Matt Broadstone Assignee: Didier Nadeau
Resolution: Won't Do Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Sprint: Server Serverless 2021-11-29
Participants:

 Description   

Both the TenantMigrationDonorService and TenantMigrationRecipientService do explicit checking for whether a local cancellation token has been aborted at the beginning of many (most?) stages of their run methods (example, example). These services can be changed to use a CancelableExecutor instead, which will do this check automatically before deciding to run a continuation.

this:

CancellationToken token;
return ExecutorFuture(**executor)
  .then([] {
    uassert(ErrorCodes::CallbackCanceled, "Donor service interrupted", !token.isCanceled());
    ...
  })
  .onError( ... )
  .onCompletion( ... )

becomes:

CancellationToken token;
return ExecutorFuture(**executor)
  .then([] {
    ...
  })
  .thenRunOn(CancelableExecutor::make(executor, token))
  .onError( ... )
  .onCompletion( ... )

(you can also just return ExecutorFuture(CancelableExecutor::make(executor, token)))

Note to whoever takes this ticket on, there might be nuanced reasons that a service might not want to cease execution if the abort token has been cancelled. For instance, the TMDS currently assumes the first stage (_enterDataSyncState) always completes a write of the initial state document to the database even if the token was cancelled. This can be overcome by moving the insertion to the error handler, or ensuring that the continuation is run on the raw executor (.thenRunOn(executor))


Generated at Thu Feb 08 05:51:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.