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

Critical section is not respected on create

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.1.0-rc0, 8.0.0-rc11
    • Affects Version/s: 8.1.0-rc0, 8.0.0-rc4
    • Component/s: None
    • None
    • Catalog and Routing
    • Fully Compatible
    • ALL
    • v8.0
    • Hide
      // IMPORTANT: This reproducible test has to be run with the
      // featureFlagTrackUnshardedCollectionsUponCreation disabled.
      
      import \{configureFailPoint} from "jstests/libs/fail_point_util.js";
      import \{funWithArgs} from "jstests/libs/parallel_shell_helpers.js";
      
      const kDbName = "test";
      const kCollName = "foo";
      
      const st = new ShardingTest(\{shards: 2});
      
      let db = st.s.getDB(kDbName);
      
      st.s.adminCommand(\{enableSharding: kDbName, primaryShard: st.shard0.shardName});
      
      jsTest.log("Set failpoint on primary.");
      let failpoint = configureFailPoint(st.rs0.getPrimary(), 'hangBeforeCreatingOnCoordinator');
      
      jsTest.log("Create a sharded collection.");
      let awaitShardCollection = startParallelShell(
          funWithArgs(function(ns) {
              assert.commandWorked(db.adminCommand(\{shardCollection: ns, key: {x: 1}, unique: false}));
          }, kDbName + '.' + kCollName), st.s.port);
      
      jsTest.log("Wait for failpoint.");
      failpoint.wait();
      
      jsTest.log("Create an unsharded collection.");
      jsTest.log("If the critical section is correctly honored, we should get blocked here.");
      assert.commandWorked(db.runCommand(\{create: kCollName}));
      
      jsTest.log("Disable failpoint.");
      failpoint.off();
      
      jsTest.log("Wait for the shard collection operation to finish.");
      awaitShardCollection();
      
      st.stop();
      
      diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp
      index a5065d64376..e076105622a 100644
      --- a/src/mongo/db/catalog/create_collection.cpp
      +++ b/src/mongo/db/catalog/create_collection.cpp
      @@ -111,6 +111,7 @@ MONGO_FAIL_POINT_DEFINE(failTimeseriesViewCreation);
       MONGO_FAIL_POINT_DEFINE(clusterAllCollectionsByDefault);
       MONGO_FAIL_POINT_DEFINE(skipIdIndex);
       MONGO_FAIL_POINT_DEFINE(useRegularCreatePathForTimeseriesBucketsCreations);
      +MONGO_FAIL_POINT_DEFINE(hangAfterCreatingBucketNamespace);
       
       using IndexVersion = IndexDescriptor::IndexVersion;
       
      @@ -611,6 +612,8 @@ Status _createTimeseries(OperationContext* opCtx,
               return Status::OK();
           });
       
      +    hangAfterCreatingBucketNamespace.pauseWhileSet();
      +
           const auto& bucketCreationStatus = ret;
           if (
               // If we could not create the bucket collection and the pre-existing bucket collection is
      diff --git a/src/mongo/db/s/create_collection_coordinator.cpp b/src/mongo/db/s/create_collection_coordinator.cpp
      index b5b58e9334a..9614964ad2d 100644
      --- a/src/mongo/db/s/create_collection_coordinator.cpp
      +++ b/src/mongo/db/s/create_collection_coordinator.cpp
      @@ -147,6 +147,7 @@
       #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding
       MONGO_FAIL_POINT_DEFINE(failAtCommitCreateCollectionCoordinator);
       MONGO_FAIL_POINT_DEFINE(hangBeforeCommitOnShardingCatalog);
      +MONGO_FAIL_POINT_DEFINE(hangBeforeCreatingOnCoordinator);
       
       namespace mongo {
       
      @@ -1182,6 +1183,8 @@ boost::optional<UUID> createCollectionAndIndexes(
           tassert(
               8679502, "Expecting translated request params to not be empty.", translatedRequestParams);
       
      +    hangBeforeCreatingOnCoordinator.pauseWhileSet();
      +
           // TODO (SERVER-77915): Remove once 8.0 becomes last LTS.
           boost::optional<OperationShardingState::ScopedAllowImplicitCollectionCreate_UNSAFE>
               allowCollectionCreation;
      diff --git a/src/mongo/db/s/shardsvr_create_collection_command.cpp b/src/mongo/db/s/shardsvr_create_collection_command.cpp
      index 84572252900..4ef6ca5da50 100644
      --- a/src/mongo/db/s/shardsvr_create_collection_command.cpp
      +++ b/src/mongo/db/s/shardsvr_create_collection_command.cpp
      @@ -308,9 +308,9 @@ public:
                   // access the collection outside of the critical section on the local
                   // catalog to check the options. We need to serialize any create
                   // collection/view to prevent wrong results
      -            static constexpr StringData lockReason{"CreateCollectionUntracked"_sd};
      -            const DDLLockManager::ScopedCollectionDDLLock collDDLLock{
      -                opCtx, ns(), lockReason, MODE_X};
      +            // static constexpr StringData lockReason{"CreateCollectionUntracked"_sd};
      +            // const DDLLockManager::ScopedCollectionDDLLock collDDLLock{
      +            //     opCtx, ns(), lockReason, MODE_X};
                   auto cmd = create_collection_util::makeCreateCommand(
                       opCtx, ns(), request().getShardsvrCreateCollectionRequest());
                   runCreateCommandDirectClient(opCtx, ns(), cmd);
      
      Show
      // IMPORTANT: This reproducible test has to be run with the // featureFlagTrackUnshardedCollectionsUponCreation disabled. import \{configureFailPoint} from "jstests/libs/fail_point_util.js"; import \{funWithArgs} from "jstests/libs/parallel_shell_helpers.js"; const kDbName = "test"; const kCollName = "foo"; const st = new ShardingTest(\{shards: 2}); let db = st.s.getDB(kDbName); st.s.adminCommand(\{enableSharding: kDbName, primaryShard: st.shard0.shardName}); jsTest.log("Set failpoint on primary."); let failpoint = configureFailPoint(st.rs0.getPrimary(), 'hangBeforeCreatingOnCoordinator'); jsTest.log("Create a sharded collection."); let awaitShardCollection = startParallelShell(     funWithArgs(function(ns) {         assert.commandWorked(db.adminCommand(\{shardCollection: ns, key: {x: 1}, unique: false}));     }, kDbName + '.' + kCollName), st.s.port); jsTest.log("Wait for failpoint."); failpoint.wait(); jsTest.log("Create an unsharded collection."); jsTest.log("If the critical section is correctly honored, we should get blocked here."); assert.commandWorked(db.runCommand(\{create: kCollName})); jsTest.log("Disable failpoint."); failpoint.off(); jsTest.log("Wait for the shard collection operation to finish."); awaitShardCollection(); st.stop(); diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp index a5065d64376..e076105622a 100644 --- a/src/mongo/db/catalog/create_collection.cpp +++ b/src/mongo/db/catalog/create_collection.cpp @@ -111,6 +111,7 @@ MONGO_FAIL_POINT_DEFINE(failTimeseriesViewCreation); MONGO_FAIL_POINT_DEFINE(clusterAllCollectionsByDefault); MONGO_FAIL_POINT_DEFINE(skipIdIndex); MONGO_FAIL_POINT_DEFINE(useRegularCreatePathForTimeseriesBucketsCreations); +MONGO_FAIL_POINT_DEFINE(hangAfterCreatingBucketNamespace); using IndexVersion = IndexDescriptor::IndexVersion; @@ -611,6 +612,8 @@ Status _createTimeseries(OperationContext* opCtx, return Status::OK(); }); + hangAfterCreatingBucketNamespace.pauseWhileSet(); + const auto& bucketCreationStatus = ret; if ( // If we could not create the bucket collection and the pre-existing bucket collection is diff --git a/src/mongo/db/s/create_collection_coordinator.cpp b/src/mongo/db/s/create_collection_coordinator.cpp index b5b58e9334a..9614964ad2d 100644 --- a/src/mongo/db/s/create_collection_coordinator.cpp +++ b/src/mongo/db/s/create_collection_coordinator.cpp @@ -147,6 +147,7 @@ #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding MONGO_FAIL_POINT_DEFINE(failAtCommitCreateCollectionCoordinator); MONGO_FAIL_POINT_DEFINE(hangBeforeCommitOnShardingCatalog); +MONGO_FAIL_POINT_DEFINE(hangBeforeCreatingOnCoordinator); namespace mongo { @@ -1182,6 +1183,8 @@ boost::optional<UUID> createCollectionAndIndexes( tassert( 8679502, "Expecting translated request params to not be empty.", translatedRequestParams); + hangBeforeCreatingOnCoordinator.pauseWhileSet(); + // TODO (SERVER-77915): Remove once 8.0 becomes last LTS. boost::optional<OperationShardingState::ScopedAllowImplicitCollectionCreate_UNSAFE> allowCollectionCreation; diff --git a/src/mongo/db/s/shardsvr_create_collection_command.cpp b/src/mongo/db/s/shardsvr_create_collection_command.cpp index 84572252900..4ef6ca5da50 100644 --- a/src/mongo/db/s/shardsvr_create_collection_command.cpp +++ b/src/mongo/db/s/shardsvr_create_collection_command.cpp @@ -308,9 +308,9 @@ public: // access the collection outside of the critical section on the local // catalog to check the options. We need to serialize any create // collection/view to prevent wrong results - static constexpr StringData lockReason{"CreateCollectionUntracked"_sd}; - const DDLLockManager::ScopedCollectionDDLLock collDDLLock{ - opCtx, ns(), lockReason, MODE_X}; + // static constexpr StringData lockReason{"CreateCollectionUntracked"_sd}; + // const DDLLockManager::ScopedCollectionDDLLock collDDLLock{ + // opCtx, ns(), lockReason, MODE_X}; auto cmd = create_collection_util::makeCreateCommand( opCtx, ns(), request().getShardsvrCreateCollectionRequest()); runCreateCommandDirectClient(opCtx, ns(), cmd);
    • CAR Team 2024-05-27, CAR Team 2024-06-10, CAR Team 2024-06-24, CAR Team 2024-07-08
    • 200

      The critical section is only checked when the ShardVersion of the namespace is attached to the OperationShardingState.

      On SERVER-88478 we stopped sending the ShardVersion for the create command, which means we stopped honoring the critical section on creation.

      The ShardVersion is not required for the create command (as explained on SERVER-88478), so we may find a way to check the critical section when the ShardVersion is not present.

            Assignee:
            silvia.surroca@mongodb.com Silvia Surroca
            Reporter:
            silvia.surroca@mongodb.com Silvia Surroca
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: