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

WiredTigerIdIndex has write conflict when prepared transaction is aborted and immediately retried

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

      The error is reproducible. Diff:

      diff --git a/jstests/core/txns/commit_prepared_transaction_errors.js b/jstests/core/txns/commit_prepared_transaction_errors.js
      index 64b27f3c16c..9fee9fd7870 100644
      --- a/jstests/core/txns/commit_prepared_transaction_errors.js
      +++ b/jstests/core/txns/commit_prepared_transaction_errors.js
      @@ -23,6 +23,10 @@ const doc = {
           _id: 1
       };
       
      +const ITERS=1000;
      +for (var i=0; i<ITERS; i++) {
      +jsTestLog("ITERATION " + i);
      +
       jsTestLog("Test committing a prepared transaction with no 'commitTimestamp'.");
       session.startTransaction();
       assert.commandWorked(sessionColl.insert(doc));
      @@ -69,4 +73,6 @@ jsTestLog("Test committing an unprepared transaction with an invalid 'commitTime
       session.startTransaction();
       assert.commandWorked(sessionColl.insert(doc));
       assert.commandFailedWithCode(PrepareHelpers.commitTransaction(session, 5), ErrorCodes.TypeMismatch);
      +
      +}
       }());
      
      Show
      The error is reproducible. Diff: diff --git a/jstests/core/txns/commit_prepared_transaction_errors.js b/jstests/core/txns/commit_prepared_transaction_errors.js index 64b27f3c16c..9fee9fd7870 100644 --- a/jstests/core/txns/commit_prepared_transaction_errors.js +++ b/jstests/core/txns/commit_prepared_transaction_errors.js @@ -23,6 +23,10 @@ const doc = { _id: 1 }; + const ITERS=1000; + for ( var i=0; i<ITERS; i++) { +jsTestLog( "ITERATION " + i); + jsTestLog( "Test committing a prepared transaction with no 'commitTimestamp' ." ); session.startTransaction(); assert .commandWorked(sessionColl.insert(doc)); @@ -69,4 +73,6 @@ jsTestLog("Test committing an unprepared transaction with an invalid 'commitTime session.startTransaction(); assert .commandWorked(sessionColl.insert(doc)); assert .commandFailedWithCode(PrepareHelpers.commitTransaction(session, 5), ErrorCodes.TypeMismatch); + +} }());
    • 19

      The commit_prepared_transaction_errors.js test is reproducing the situation when a prepared transaction fails because it has no commitTimestamp and then is aborted with `abortTransaction_forTesting()`. The next transaction started for the same data entry fails in WiredTigerIdIndex::_insert with:

      "WiredTigerIdIndex::_insert: index: _id_; uri: table:index-161--1657325371758770379 :: caused by :: WriteConflict
      

      I verified that the conflict happens in the C-level code `__wt_cursor int __F(insert)(WT_CURSOR *cursor)`. I verified that the `WiredTigerItem keyItem` passed to both transactions is identical, so almost certainly it means the previous index key was not removed from WT table when the transaction abort already returned.

        1. test.js
          2 kB
        2. ok.json
          33 kB
        3. debug.diff
          12 kB
        4. bad.json
          37 kB

            Assignee:
            andrew.morton@mongodb.com Andrew Morton
            Reporter:
            andrew.shuvalov@mongodb.com Andrew Shuvalov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved: