diff --git a/src/mongo/db/s/create_collection_coordinator.cpp b/src/mongo/db/s/create_collection_coordinator.cpp index 85b2c655c37..a6ac9e1eb0e 100644 --- a/src/mongo/db/s/create_collection_coordinator.cpp +++ b/src/mongo/db/s/create_collection_coordinator.cpp @@ -63,6 +63,7 @@ #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding MONGO_FAIL_POINT_DEFINE(failAtCommitCreateCollectionCoordinator); +MONGO_FAIL_POINT_DEFINE(waitBeforeCreateIndex); namespace mongo { @@ -744,6 +745,9 @@ void CreateCollectionCoordinator::_createCollectionAndIndexes(OperationContext* boost::optional collation; std::tie(collation, _collationBSON) = getCollation(opCtx, nss(), _request.getCollation()); + if (waitBeforeCreateIndex.shouldFail()) { + waitBeforeCreateIndex.pauseWhileSet(); + } // We need to implicitly create a timeseries view and underlying bucket collection. if (_collectionEmpty && _request.getTimeseries()) { diff --git a/temp.js b/temp.js new file mode 100644 index 00000000000..1f7b7f326a5 --- /dev/null +++ b/temp.js @@ -0,0 +1,34 @@ +load('jstests/libs/fail_point_util.js'); // For configureFailPoint + +let st = ShardingTest({mongos: 1, shards: 2}) +let mongos = st.s; +let primaryShardConn = st.rs0.getPrimary(); +let primaryShardName = st.shard0.shardName; + +assert.commandWorked(mongos.adminCommand({enableSharding: "test", primaryShard: primaryShardName})); + +const fp = configureFailPoint(primaryShardConn, 'waitBeforeCreateIndex', {}, 'alwaysOn'); + +const shardCollectionShell = startParallelShell(() => { + assert.commandWorked( + db.adminCommand({shardCollection: "test.mycoll", key: {x: 1}, unique: false})); +}, mongos.port); + +// Create the capped collection before the shardCollection, but after any validation on the local +// catalog is completed. +fp.wait(); +assert.commandWorked(mongos.getDB("test").createCollection("mycoll", {capped: true, size: 5000})); +const res = primaryShardConn.getDB("test").runCommand({listCollections: 1.0}); +fp.off() + +// complete the shardCollection +shardCollectionShell() + +// find the collection in the sharding catalog. +assert.eq(st.config.collections.find({_id: "test.mycoll"}).count(), 1); + +// find the collection capped locally on the primary. +let res2 = primaryShardConn.getDB("test").runCommand({listCollections: 1}); +assert.eq(res2.cursor.firstBatch[0].options.capped, true); +st.stop();