[SERVER-35677] Do not allow prepareTransaction to prepare transactions without operations Created: 19/Jun/18  Updated: 29/Oct/23  Resolved: 22/Jun/18

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

Type: Bug Priority: Major - P3
Reporter: Louis Williams Assignee: Judah Schvimer
Resolution: Fixed Votes: 0
Labels: prepare_errors
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

./mongod --replSet rs --setParameter enableTestCommands=1

And in the shell:

rs.initiate();
 
let session = db.getMongo().startSession({causalConsistency: false});
let sessionDB = session.getDatabase('test');
 
db.test.insert({a: 1});
 
assert.commandWorked(sessionDB.runCommand({
 find: 'test',
 readConcern: {level: 'snapshot'},
 txnNumber: NumberLong(0),
 startTransaction: true,
 autocommit: false
 }));
 
assert.commandWorked(sessionDB.adminCommand(
 {prepareTransaction: 'test', txnNumber: NumberLong(0), autocommit: false}));

Participants:
Linked BF Score: 49

 Description   

The onTransactionPrepare opObserver early-returns when there are no statements in the transaction. If a "find" transaction is started, and later prepared, this should not be legal if there are no statements to prepare.

Session::prepareTransaction calls WriteUnitOfWork::prepare() regardless of whether or not a prepare optime was generated. This leads RecoveryUnit::prepareUnitOfWork to be called when no prepare timestamp has been set, causing this invariant failure

Prepare should either a) be a no-op or b) return an error when there are no operations to prepare



 Comments   
Comment by Githook User [ 22/Jun/18 ]

Author:

{'username': 'judahschvimer', 'name': 'Judah Schvimer', 'email': 'judah@mongodb.com'}

Message: SERVER-35677 always log a prepare oplog entry on prepareTransaction
Branch: master
https://github.com/mongodb/mongo/commit/d9d74f71d8689aca95934b5f18ce4e9586be7d5c

Comment by Judah Schvimer [ 19/Jun/18 ]

We have since decided that prepareTransaction should always log an oplog entry. I expect that to fix this.

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