[SERVER-41190] Convert CommitType enum in TransactionRouter to generic State enum Created: 16/May/19  Updated: 27/Oct/23  Resolved: 29/May/19

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

Type: Improvement Priority: Major - P3
Reporter: Jack Mulrow Assignee: Alexander Taskov (Inactive)
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-41127 TransactionRouter should not assert t... Closed
Sprint: Sharding 2019-06-03
Participants:

 Description   

TransactionRouter uses a CommitType enum to track if a commit has been started and which commit path was taken (e.g. twoPhase vs. singleShard). This enum could be extended to track when a transaction has initiated abort as well, which would simplify some of its logic, especially around retries of commit/abort and handling statements after receiving a commit/abort. This could also replace the TerminationCause enum used for logging slow transactions on mongos.



 Comments   
Comment by Esha Maharishi (Inactive) [ 29/May/19 ]

There are currently two similar enums in the TransactionRouter:

1. CommitType

    enum class CommitType {
        kNotInitiated,
        kNoShards,
        kSingleShard,
        kSingleWriteShard,
        kReadOnly,
        kTwoPhaseCommit,
        kRecoverWithToken,
    };

2. TerminationCause

    enum class TerminationCause {
        kCommitted,
        kAborted,
    };

We had thought it made sense to combine these into a single state machine for the router and add a state for "aborting", but then we realized that the client can manipulate the router's state in an arbitrary way (for example, a misbehaving client can call abort after commit or commit after abort). Today, the router will simply execute the misbehaving client's request.

Since "has commit or abort been initiated" is determined by client requests but the termination cause is determined by participant responses, we decided to track them separately. We also left the CommitType enum separate, since it is orthogonal to both.

As it stands today, a misbehaving client can corrupt a transaction by causing the router to send abort concurrently with the coordinator sending commit. We could prevent this in the future by making the router assert if the client sends commit after abort or abort after commit.

Comment by Alexander Taskov (Inactive) [ 29/May/19 ]

Addressed in https://jira.mongodb.org/browse/SERVER-41127

Comment by Alexander Taskov (Inactive) [ 29/May/19 ]

After discussion with Esha and Matthew, it was decided to represent the states where termination states are being initiated with a separate flag. This was done as part of https://jira.mongodb.org/browse/SERVER-41127 which depends on tracking the initiation states.

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