diff options
author | Maria van Keulen <maria.vankeulen@mongodb.com> | 2020-02-06 19:58:42 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2020-02-06 19:58:42 +0000 |
commit | e9fadb78003810c3985edf33e60c618f4a2c2b3e (patch) | |
tree | 2829d62ea315f1de26912c3b10c6f5dcaf0f346c | |
parent | ea696eb7a27f18c21223a3ff94d9124f06698af5 (diff) | |
download | mongo-e9fadb78003810c3985edf33e60c618f4a2c2b3e.tar.gz |
SERVER-45368 Allow collection/index creation inside txns for sharding
This patch ensures unprepared transactions in a sharded cluster can
create new collections and indexes.
7 files changed, 13 insertions, 18 deletions
diff --git a/buildscripts/resmokeconfig/suites/sharded_causally_consistent_jscore_txns_passthrough.yml b/buildscripts/resmokeconfig/suites/sharded_causally_consistent_jscore_txns_passthrough.yml index c883203614a..4ed9f139ae1 100644 --- a/buildscripts/resmokeconfig/suites/sharded_causally_consistent_jscore_txns_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/sharded_causally_consistent_jscore_txns_passthrough.yml @@ -30,12 +30,6 @@ selector: # attached to statements in a transaction beyond the first one. - jstests/core/txns/non_transactional_operations_on_session_with_transaction.js - # TODO(SERVER-45368) re-enable once collection creation is permitted in cross-shard transactions. - - jstests/core/txns/create_collection.js - - jstests/core/txns/create_collection_parallel.js - - jstests/core/txns/create_indexes.js - - jstests/core/txns/create_indexes_parallel.js - exclude_with_any_tags: - assumes_against_mongod_not_mongos - does_not_support_causal_consistency diff --git a/buildscripts/resmokeconfig/suites/sharded_collections_causally_consistent_jscore_txns_passthrough.yml b/buildscripts/resmokeconfig/suites/sharded_collections_causally_consistent_jscore_txns_passthrough.yml index 9debf1e661b..7c899f771ec 100644 --- a/buildscripts/resmokeconfig/suites/sharded_collections_causally_consistent_jscore_txns_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/sharded_collections_causally_consistent_jscore_txns_passthrough.yml @@ -29,7 +29,9 @@ selector: # attached to statements in a transaction beyond the first one. - jstests/core/txns/non_transactional_operations_on_session_with_transaction.js - # TODO(SERVER-45368) re-enable once collection creation is permitted in cross-shard transactions. + # These workloads explicitly create collections inside multi-document transactions. These are + # non-idempotent operations, and the implicit collection sharding logic upon collection access + # results in premature collection creation, causing the workloads to fail. - jstests/core/txns/create_collection.js - jstests/core/txns/create_collection_parallel.js - jstests/core/txns/create_indexes.js diff --git a/buildscripts/resmokeconfig/suites/sharded_jscore_txns.yml b/buildscripts/resmokeconfig/suites/sharded_jscore_txns.yml index 1b5722b7eba..87ebb6eead4 100644 --- a/buildscripts/resmokeconfig/suites/sharded_jscore_txns.yml +++ b/buildscripts/resmokeconfig/suites/sharded_jscore_txns.yml @@ -26,13 +26,6 @@ selector: # Uses hangAfterCollectionInserts failpoint not available on mongos. - jstests/core/txns/speculative_snapshot_includes_all_writes.js - # TODO(SERVER-45368) re-enable once collection creation is permitted in cross-shard transactions. - - jstests/core/txns/create_collection.js - - jstests/core/txns/create_collection_parallel.js - - jstests/core/txns/create_indexes.js - - jstests/core/txns/create_indexes_parallel.js - - exclude_with_any_tags: - assumes_against_mongod_not_mongos # Transactions are not allowed to operate on capped collections. diff --git a/buildscripts/resmokeconfig/suites/sharded_jscore_txns_sharded_collections.yml b/buildscripts/resmokeconfig/suites/sharded_jscore_txns_sharded_collections.yml index d617ebc9504..f7f026c3be5 100644 --- a/buildscripts/resmokeconfig/suites/sharded_jscore_txns_sharded_collections.yml +++ b/buildscripts/resmokeconfig/suites/sharded_jscore_txns_sharded_collections.yml @@ -25,7 +25,9 @@ selector: # View tests aren't expected to work when collections are implicitly sharded. - jstests/core/txns/view_reads_in_transaction.js - # TODO(SERVER-45368) re-enable once collection creation is permitted in cross-shard transactions. + # These workloads explicitly create collections inside multi-document transactions. These are + # non-idempotent operations, and the implicit collection sharding logic upon collection access + # results in premature collection creation, causing the workloads to fail. - jstests/core/txns/create_collection.js - jstests/core/txns/create_collection_parallel.js - jstests/core/txns/create_indexes.js diff --git a/jstests/core/txns/create_collection.js b/jstests/core/txns/create_collection.js index ad1b7f14bc1..90ee9305c5e 100644 --- a/jstests/core/txns/create_collection.js +++ b/jstests/core/txns/create_collection.js @@ -28,6 +28,7 @@ session.commitTransaction(); assert.eq(sessionColl.find({}).itcount(), 1); sessionColl.drop({writeConcern: {w: "majority"}}); + jsTest.log("Testing multiple createCollections in a transaction"); session.startTransaction({writeConcern: {w: "majority"}}); createCollAndCRUDInTxn(sessionDB, collName); @@ -46,13 +47,13 @@ assert.commandWorked(session.abortTransaction_forTesting()); assert.eq(sessionColl.find({}).itcount(), 0); +jsTest.log("Testing createCollection on an existing collection in a transaction (SHOULD ABORT)"); assert.commandWorked(sessionDB.runCommand({create: collName, writeConcern: {w: "majority"}})); -jsTest.log( - "Testing createCollection on an existing collection in a transaction that aborts (SHOULD FAIL)"); session.startTransaction({writeConcern: {w: "majority"}}); createCollAndCRUDInTxn(sessionDB, secondCollName); assert.commandFailedWithCode(sessionDB.runCommand({create: collName}), ErrorCodes.NamespaceExists); assert.commandFailedWithCode(session.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction); + assert.eq(sessionColl.find({}).itcount(), 0); assert.eq(secondSessionColl.find({}).itcount(), 0); diff --git a/jstests/core/txns/create_collection_parallel.js b/jstests/core/txns/create_collection_parallel.js index a3ee0b94087..401606ef253 100644 --- a/jstests/core/txns/create_collection_parallel.js +++ b/jstests/core/txns/create_collection_parallel.js @@ -36,6 +36,7 @@ assert.eq(sessionColl.find({}).itcount(), 1); assert.commandFailedWithCode(secondSessionDB.runCommand({create: collName}), ErrorCodes.NamespaceExists); + assert.commandFailedWithCode(secondSession.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction); diff --git a/src/mongo/s/commands/cluster_create_cmd.cpp b/src/mongo/s/commands/cluster_create_cmd.cpp index d869ce626d1..d1a3fc792fc 100644 --- a/src/mongo/s/commands/cluster_create_cmd.cpp +++ b/src/mongo/s/commands/cluster_create_cmd.cpp @@ -138,7 +138,9 @@ public: uassertStatusOK(response.swResponse); const auto createStatus = mongo::getStatusFromCommandResult(response.swResponse.getValue().data); - if (createStatus == ErrorCodes::NamespaceExists) { + if (createStatus == ErrorCodes::NamespaceExists && !opCtx->inMultiDocumentTransaction()) { + // NamespaceExists will cause multi-document transactions to implicitly abort, so + // mongos should surface this error to the client. CollectionOptions options = uassertStatusOK(CollectionOptions::parse(cmdObj)); checkCollectionOptions(opCtx, nss, options); } else { |