[SERVER-34137] Transaction number of committed/aborted transaction can be reused for snapshot read Created: 26/Mar/18  Updated: 27/Oct/23  Resolved: 30/Mar/18

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

Type: Bug Priority: Major - P3
Reporter: Tess Avitabile (Inactive) Assignee: Backlog - Storage Execution Team
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Storage Execution
Operating System: ALL
Steps To Reproduce:

(function() {
    let session = db.getMongo().startSession({causalConsistency: false});
    let sessionDb = session.getDatabase("test");
 
    assert.commandWorked(sessionDb.createCollection("coll", {writeConcern: {w: "majority"}}));
 
    assert.commandWorked(sessionDb.runCommand({
        insert: "coll",
        documents: [{_id: "insert-1"}],
        readConcern: {level: "snapshot"},
        txnNumber: NumberLong(0),
        autocommit: false
    }));
 
    assert.commandWorked(sessionDb.runCommand({
        commitTransaction: 1,    // also passes with 'abortTransaction'
        txnNumber: NumberLong(0)
    }));
 
    assert.commandWorked(sessionDb.runCommand({
        find: "coll",    // also passes with any other command allowing snapshot readConcern
        readConcern: {level: "snapshot"},
        txnNumber: NumberLong(0)    // will fail if autocommit=false is specified, as expected
    }));
 
    session.endSession();
}());

Participants:

 Description   

If there is no _txnResourceStash, we are not in a multi-document transaction, and the readConcern level is snapshot, then we will start a new snapshot read. This allows us to incorrectly reuse a transaction number of a committed/aborted transaction for a snapshot read.



 Comments   
Comment by Ian Whalen (Inactive) [ 30/Mar/18 ]

Closing as Gone Away given the changes to snapshot reads + autocommit:false transactions but please reopen if you think that's incorrect.

Comment by Siyuan Zhou [ 26/Mar/18 ]

When figuring out the place to check reused txnNumber, I found we couldn't check it in unstash, because retryable commitTransaction needs to access the committed transaction with the same txnNumber, then I thought maybe checking in all other places where we access Session is a good option, e.g. adding operations to transaction, which is also needed for concurrency, but this ticket means snapshot read is missing in that approach.

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