diff options
-rw-r--r-- | etc/backports_required_for_multiversion_tests.yml | 4 | ||||
-rw-r--r-- | jstests/sharding/collection_uuid_shard_capped_collection.js | 41 | ||||
-rw-r--r-- | src/mongo/db/s/create_collection_coordinator.cpp | 4 |
3 files changed, 47 insertions, 2 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml index 88da9483b32..f60da338137 100644 --- a/etc/backports_required_for_multiversion_tests.yml +++ b/etc/backports_required_for_multiversion_tests.yml @@ -272,6 +272,8 @@ last-continuous: test_file: jstests/aggregation/match_no_swap_rand.js - ticket: SERVER-67723 test_file: jstests/replsets/internal_sessions_reaping_basic.js + - ticket: SERVER-67885 + test_file: jstests/sharding/collection_uuid_shard_capped_collection.js # Tests that should only be excluded from particular suites should be listed under that suite. suites: @@ -677,6 +679,8 @@ last-lts: test_file: jstests/aggregation/match_no_swap_rand.js - ticket: SERVER-67723 test_file: jstests/replsets/internal_sessions_reaping_basic.js + - ticket: SERVER-67885 + test_file: jstests/sharding/collection_uuid_shard_capped_collection.js # Tests that should only be excluded from particular suites should be listed under that suite. suites: diff --git a/jstests/sharding/collection_uuid_shard_capped_collection.js b/jstests/sharding/collection_uuid_shard_capped_collection.js new file mode 100644 index 00000000000..880ee3cc208 --- /dev/null +++ b/jstests/sharding/collection_uuid_shard_capped_collection.js @@ -0,0 +1,41 @@ +/** + * Tests the collectionUUID parameter of the shardCollection command against capped collections. + */ +(function() { +'use strict'; + +const st = new ShardingTest({shards: 1}); +const mongos = st.s0; + +const db = mongos.getDB(jsTestName()); +const coll = db['cappedColl']; +const collName = coll.getName(); + +// Create a capped collection. +assert.commandWorked(db.createCollection(collName, {capped: true, size: 1024})); +assert.commandWorked(mongos.adminCommand({enableSharding: db.getName()})); + +// Ensure that we fail the shardCollection command with 'CollectionUUIDMismatch' when the UUID does +// not correspond to the collection. +const nonexistentUUID = UUID(); +let res = assert.commandFailedWithCode( + mongos.adminCommand( + {shardCollection: coll.getFullName(), key: {_id: 1}, collectionUUID: nonexistentUUID}), + ErrorCodes.CollectionUUIDMismatch); +assert.eq(res.db, db.getName()); +assert.eq(res.collectionUUID, nonexistentUUID); +assert.eq(res.expectedCollection, collName); +assert.eq(res.actualCollection, null); + +const uuid = assert.commandWorked(db.runCommand({listCollections: 1})) + .cursor.firstBatch.find(c => c.name === collName) + .info.uuid; + +// Ensure that we fail the shard command with 'InvalidOptions' when the UUID corresponds to the +// capped collection. +assert.commandFailedWithCode( + mongos.adminCommand({shardCollection: coll.getFullName(), collectionUUID: uuid, key: {_id: 1}}), + ErrorCodes.InvalidOptions); + +st.stop(); +})(); diff --git a/src/mongo/db/s/create_collection_coordinator.cpp b/src/mongo/db/s/create_collection_coordinator.cpp index 58f11c66e02..ae2f53f7399 100644 --- a/src/mongo/db/s/create_collection_coordinator.cpp +++ b/src/mongo/db/s/create_collection_coordinator.cpp @@ -412,6 +412,8 @@ ExecutorFuture<void> CreateCollectionCoordinator::_runImpl( // Log the start of the event only if we're not recovering. _logStartCreateCollection(opCtx); + _checkCollectionUUIDMismatch(opCtx); + // Quick check (without critical section) to see if another create collection // already succeeded. if (auto createCollectionResponseOpt = @@ -421,7 +423,6 @@ ExecutorFuture<void> CreateCollectionCoordinator::_runImpl( _shardKeyPattern->getKeyPattern().toBSON(), getCollation(opCtx, nss(), _request.getCollation()).second, _request.getUnique().value_or(false))) { - _checkCollectionUUIDMismatch(opCtx); // The critical section can still be held here if the node committed the // sharding of the collection but then it stepped down before it managed to @@ -463,7 +464,6 @@ ExecutorFuture<void> CreateCollectionCoordinator::_runImpl( } } - _checkCollectionUUIDMismatch(opCtx); _createPolicy(opCtx); _createCollectionAndIndexes(opCtx); |