diff options
author | Benety Goh <benety@mongodb.com> | 2020-04-06 12:03:24 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-04-10 12:01:54 +0000 |
commit | d3da6de558fc4fbd7bb20617ed5d1f34c2c58bb3 (patch) | |
tree | b10ed351ba09e52f0dd50f64c77d4c50f7d73e43 /jstests | |
parent | 64c84a7c9d0d6035e9d8794371de33baa79ef020 (diff) | |
download | mongo-d3da6de558fc4fbd7bb20617ed5d1f34c2c58bb3.tar.gz |
SERVER-47268 retry sharded transaction in noop__createIndexes_not_blocked_by_txn.js on snapshot errors
(cherry picked from commit a25168b6eae5af975581028175572997839b57e4)
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/core/txns/noop_createIndexes_not_blocked_by_txn.js | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/jstests/core/txns/noop_createIndexes_not_blocked_by_txn.js b/jstests/core/txns/noop_createIndexes_not_blocked_by_txn.js index 675db8b65f3..8caa0a65450 100644 --- a/jstests/core/txns/noop_createIndexes_not_blocked_by_txn.js +++ b/jstests/core/txns/noop_createIndexes_not_blocked_by_txn.js @@ -3,6 +3,10 @@ (function() { "use strict"; +// TODO(SERVER-39704): Remove the following load after SERVER-39704 is completed +// For withTxnAndAutoRetryOnMongos. +load('jstests/libs/auto_retry_transaction_in_sharding.js'); + const dbName = 'noop_createIndexes_not_blocked'; const collName = 'test'; const testDB = db.getSiblingDB(dbName); @@ -24,33 +28,43 @@ const createIndexesCommand = { }; assert.commandWorked(sessionDB.runCommand(createIndexesCommand)); -session.startTransaction(); -assert.commandWorked(sessionDB[collName].insert({a: 5, b: 6})); +// Default read concern level to use for transactions. Snapshot read concern is not supported in +// sharded transactions when majority reads are disabled. +if (!TestData.hasOwnProperty('defaultTransactionReadConcernLevel')) { + TestData.defaultTransactionReadConcernLevel = + TestData.enableMajorityReadConcern !== false ? 'snapshot' : 'local'; +} -// This should not block because an identical index exists. -let res = testDB.runCommand(createIndexesCommand); -assert.commandWorked(res); -assert.eq(res.numIndexesBefore, res.numIndexesAfter); +// TODO(SERVER-39704): We use the withTxnAndAutoRetryOnMongos +// function to handle how MongoS will propagate a StaleShardVersion error as a +// TransientTransactionError. After SERVER-39704 is completed the +// withTxnAndAutoRetryOnMongos function can be removed +withTxnAndAutoRetryOnMongos(session, () => { + assert.commandWorked(sessionDB[collName].insert({a: 5, b: 6})); -// This should not block but return an error because the index exists with different options. -res = testDB.runCommand({ - createIndexes: collName, - indexes: [{key: {a: 1}, name: "unique_a_1", unique: true}], -}); -assert.commandFailedWithCode(res, ErrorCodes.IndexOptionsConflict); + // This should not block because an identical index exists. + let res = testDB.runCommand(createIndexesCommand); + assert.commandWorked(res); + assert.eq(res.numIndexesBefore, res.numIndexesAfter); -// This should block and time out because the index does not already exist. -res = testDB.runCommand( - {createIndexes: collName, indexes: [{key: {b: 1}, name: "b_1"}], maxTimeMS: 500}); -assert.commandFailedWithCode(res, ErrorCodes.MaxTimeMSExpired); + // This should not block but return an error because the index exists with different options. + res = testDB.runCommand({ + createIndexes: collName, + indexes: [{key: {a: 1}, name: "unique_a_1", unique: true}], + }); + assert.commandFailedWithCode(res, ErrorCodes.IndexOptionsConflict); -// This should block and time out because one of the indexes does not already exist. -res = testDB.runCommand({ - createIndexes: collName, - indexes: [{key: {a: 1}, name: "a_1"}, {key: {b: 1}, name: "b_1"}], - maxTimeMS: 500 -}); -assert.commandFailedWithCode(res, ErrorCodes.MaxTimeMSExpired); + // This should block and time out because the index does not already exist. + res = testDB.runCommand( + {createIndexes: collName, indexes: [{key: {b: 1}, name: "b_1"}], maxTimeMS: 500}); + assert.commandFailedWithCode(res, ErrorCodes.MaxTimeMSExpired); -assert.commandWorked(session.commitTransaction_forTesting()); + // This should block and time out because one of the indexes does not already exist. + res = testDB.runCommand({ + createIndexes: collName, + indexes: [{key: {a: 1}, name: "a_1"}, {key: {b: 1}, name: "b_1"}], + maxTimeMS: 500 + }); + assert.commandFailedWithCode(res, ErrorCodes.MaxTimeMSExpired); +}); }()); |