Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-35677

Do not allow prepareTransaction to prepare transactions without operations

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.1.1
    • Affects Version/s: None
    • Component/s: None
    • Labels:
    • Fully Compatible
    • ALL
    • Hide

      ./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}));
      
      Show
      ./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 }));
    • 49

      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

            Assignee:
            judah.schvimer@mongodb.com Judah Schvimer
            Reporter:
            louis.williams@mongodb.com Louis Williams
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: