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

SessionsCollectionConfigServer does not check responses of scatterGatherVersionedTargetByRoutingTable() when creating indexes

    • Fully Compatible
    • ALL
    • Hide

      Apply the below git patch and run the given resmoke command after building.

      buildscripts/resmoke.py run --suite=sharding_auth jstests/sharding/configsvr_retries_createindex_on_stale_config.js
      
      Unable to find source-code formatter for language: diff. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      diff --git a/src/mongo/db/sessions_collection.cpp b/src/mongo/db/sessions_collection.cpp
      index 88c75302220..38d35720ca4 100644
      --- a/src/mongo/db/sessions_collection.cpp
      +++ b/src/mongo/db/sessions_collection.cpp
      @@ -43,8 +43,11 @@
       #include "mongo/db/repl/read_concern_args.h"
       #include "mongo/rpc/get_status_from_command_result.h"
       #include "mongo/s/write_ops/batched_command_response.h"
      +#include "mongo/util/fail_point.h"
       
       namespace mongo {
      +
      +MONGO_FAIL_POINT_DEFINE(sessionsCollectionMakeBadCreateIndexCommand);
       namespace {
       
       // This batch size is chosen to ensure that we don't form requests larger than the 16mb limit.
      @@ -276,7 +279,13 @@ BSONObj SessionsCollection::generateCreateIndexesCmd() {
           index.setExpireAfterSeconds(localLogicalSessionTimeoutMinutes * 60);
       
           CreateIndexesCommand createIndexes(NamespaceString::kLogicalSessionsNamespace);
      -    createIndexes.setIndexes({index.toBSON()});
      +    auto indexBson = index.toBSON();
      +    sessionsCollectionMakeBadCreateIndexCommand.execute([&](const BSONObj& data) {
      +        auto tmp = BSON("expireAfterSeconds"
      +                        << "badValue");
      +        indexBson = indexBson.addField(tmp.firstElement());
      +    });
      +    createIndexes.setIndexes({indexBson});
       
           return createIndexes.toBSON(BSON(WriteConcernOptions::kWriteConcernField
                                            << WriteConcernOptions::kInternalWriteDefault));
      diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js
      index dc55d3b0a5e..135fcadd430 100644
      --- a/src/mongo/shell/shardingtest.js
      +++ b/src/mongo/shell/shardingtest.js
      @@ -1916,7 +1916,10 @@ var ShardingTest = function(params) {
           // Ensure that the sessions collection exists so jstests can run things with
           // logical sessions and test them. We do this by forcing an immediate cache refresh
           // on the config server, which auto-shards the collection for the cluster.
      -    this.configRS.getPrimary().getDB("admin").runCommand({refreshLogicalSessionCacheNow: 1});
      +    assert.commandWorked(this.configRS.getPrimary().getDB("admin").runCommand(
      +        {configureFailPoint: "sessionsCollectionMakeBadCreateIndexCommand", mode: "alwaysOn"}));
      +    assert.commandWorked(
      +        this.configRS.getPrimary().getDB("admin").runCommand({refreshLogicalSessionCacheNow: 1}));
       
           // Ensure that all CSRS nodes are up to date. This is strictly needed for tests that use
           // multiple mongoses. In those cases, the first mongos initializes the contents of the 'config'
      
      Show
      Apply the below git patch and run the given resmoke command after building. buildscripts/resmoke.py run --suite=sharding_auth jstests/sharding/configsvr_retries_createindex_on_stale_config.js Unable to find source-code formatter for language: diff. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml diff --git a/src/mongo/db/sessions_collection.cpp b/src/mongo/db/sessions_collection.cpp index 88c75302220..38d35720ca4 100644 --- a/src/mongo/db/sessions_collection.cpp +++ b/src/mongo/db/sessions_collection.cpp @@ -43,8 +43,11 @@ #include "mongo/db/repl/read_concern_args.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/write_ops/batched_command_response.h" +#include "mongo/util/fail_point.h" namespace mongo { + +MONGO_FAIL_POINT_DEFINE(sessionsCollectionMakeBadCreateIndexCommand); namespace { // This batch size is chosen to ensure that we don't form requests larger than the 16mb limit. @@ -276,7 +279,13 @@ BSONObj SessionsCollection::generateCreateIndexesCmd() { index.setExpireAfterSeconds(localLogicalSessionTimeoutMinutes * 60); CreateIndexesCommand createIndexes(NamespaceString::kLogicalSessionsNamespace); - createIndexes.setIndexes({index.toBSON()}); + auto indexBson = index.toBSON(); + sessionsCollectionMakeBadCreateIndexCommand.execute([&]( const BSONObj& data) { + auto tmp = BSON( "expireAfterSeconds" + << "badValue" ); + indexBson = indexBson.addField(tmp.firstElement()); + }); + createIndexes.setIndexes({indexBson}); return createIndexes.toBSON(BSON(WriteConcernOptions::kWriteConcernField << WriteConcernOptions::kInternalWriteDefault)); diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js index dc55d3b0a5e..135fcadd430 100644 --- a/src/mongo/shell/shardingtest.js +++ b/src/mongo/shell/shardingtest.js @@ -1916,7 +1916,10 @@ var ShardingTest = function(params) { // Ensure that the sessions collection exists so jstests can run things with // logical sessions and test them. We do this by forcing an immediate cache refresh // on the config server, which auto-shards the collection for the cluster. - this .configRS.getPrimary().getDB( "admin" ).runCommand({refreshLogicalSessionCacheNow: 1}); + assert .commandWorked( this .configRS.getPrimary().getDB( "admin" ).runCommand( + {configureFailPoint: "sessionsCollectionMakeBadCreateIndexCommand" , mode: "alwaysOn" })); + assert .commandWorked( + this .configRS.getPrimary().getDB( "admin" ).runCommand({refreshLogicalSessionCacheNow: 1})); // Ensure that all CSRS nodes are up to date. This is strictly needed for tests that use // multiple mongoses. In those cases, the first mongos initializes the contents of the 'config'
    • Sharding 2022-05-02, Sharding NYC 2022-05-16
    • 70
    • 2

      SessionsCollectionConfigServer does not check responses of scatterGatherVersionedTargetByRoutingTable() when creating indexes. This can cause refreshLogicalSessionCacheNow to fail silently if it fails to create the indexes for some reason, leading to potentially surprising behavior if it is believed to have succeeded. An example of this can be see in BF-24691.

            Assignee:
            nandini.bhartiya@mongodb.com Nandini Bhartiya
            Reporter:
            brett.nawrocki@mongodb.com Brett Nawrocki
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: