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

Building the wrong shard key index when a dangling time-series buckets collection is present

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 8.1.0-rc0, 8.0.0-rc10
    • Component/s: None
    • Catalog and Routing
    • ALL
    • Hide
      const st = new ShardingTest({
          mongos: 1,
          shards: {nodes: 1},
          config: {nodes: 1},
          // keyFile: 'jstests/libs/key1',
      });
      
      const mongos = st.s;
      const dbName = jsTestName();
      const db = mongos.getDB(dbName);
      
      st.shard0.adminCommand({
          configureFailPoint: "failTimeseriesViewCreation",
          mode: "alwaysOn",
          data: {ns: dbName + ".test"}
      })
      
      db.createCollection("test", {timeseries: {timeField: "time"}});
      assert.commandWorked(db.createCollection("test"))
      assert.commandWorked(db.adminCommand({shardCollection: dbName + ".test", key: {time: 1}}))
      
      st.stop();
      
      diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp
      index a5065d64376..0281c5c3ddd 100644
      --- a/src/mongo/db/catalog/create_collection.cpp
      +++ b/src/mongo/db/catalog/create_collection.cpp
      @@ -313,7 +313,7 @@ Status _createView(OperationContext* opCtx,
                   LOGV2(5490200,
                         "failTimeseriesViewCreation fail point enabled. Failing creation of view "
                         "definition.");
      -            return Status{ErrorCodes::OperationFailed,
      +            return Status{ErrorCodes::NamespaceExists,
                                 str::stream() << "View definition " << nss.toStringForErrorMsg()
                                               << " creation failed due to 'failTimeseriesViewCreation' "
                                                  "fail point enabled."}; 
      Show
      const st = new ShardingTest({ mongos: 1, shards: {nodes: 1}, config: {nodes: 1}, // keyFile: 'jstests/libs/key1', }); const mongos = st.s; const dbName = jsTestName(); const db = mongos.getDB(dbName); st.shard0.adminCommand({ configureFailPoint: "failTimeseriesViewCreation", mode: "alwaysOn", data: {ns: dbName + ".test"} }) db.createCollection("test", {timeseries: {timeField: "time"}}); assert.commandWorked(db.createCollection("test")) assert.commandWorked(db.adminCommand({shardCollection: dbName + ".test", key: {time: 1}})) st.stop(); diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp index a5065d64376..0281c5c3ddd 100644 --- a/src/mongo/db/catalog/create_collection.cpp +++ b/src/mongo/db/catalog/create_collection.cpp @@ -313,7 +313,7 @@ Status _createView(OperationContext* opCtx,              LOGV2(5490200,                    "failTimeseriesViewCreation fail point enabled. Failing creation of view "                    "definition."); -            return Status{ErrorCodes::OperationFailed, +            return Status{ErrorCodes::NamespaceExists,                            str::stream() << "View definition " << nss.toStringForErrorMsg()                                          << " creation failed due to 'failTimeseriesViewCreation' "                                             "fail point enabled."};
    • CAR Team 2024-05-27, CAR Team 2024-06-10, CAR Team 2024-06-24
    • 200

      When an unsharded time-series collection was created but only with the buckets collection (this could be due to a stepdown before creating the view + a concurrent view creation on the same namespace), creating and sharding another regular collection with the same namespace will create the shard key index on the buckets collection. 

      Despite the unclear expected behavior when a dangling buckets collection exists in sharding, this should still be considered problematic since the now sharded collection is missing the shard key index. This fails the metadata check.

            Assignee:
            Unassigned Unassigned
            Reporter:
            yuhong.zhang@mongodb.com Yuhong Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: