diff options
author | Esha Maharishi <esha.maharishi@mongodb.com> | 2019-07-11 16:44:37 -0400 |
---|---|---|
committer | Esha Maharishi <esha.maharishi@mongodb.com> | 2019-07-11 17:04:06 -0400 |
commit | 8c51287e54f87d0a32e5d1eb59bb94af16917011 (patch) | |
tree | 6e74c1f9c6ebec132be850ef1cd5178e26e62591 /src | |
parent | 95d6412f4d1d150e3027048b27eca07c5dec27be (diff) | |
download | mongo-8c51287e54f87d0a32e5d1eb59bb94af16917011.tar.gz |
SERVER-41950 Flush database cache on primary shard when creating a database in the sharding catalog
Diffstat (limited to 'src')
3 files changed, 27 insertions, 0 deletions
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_create_database_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_create_database_test.cpp index f27765268c5..fac498f768c 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_create_database_test.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_create_database_test.cpp @@ -148,6 +148,14 @@ TEST_F(CreateDatabaseTest, createDatabaseSuccess) { return BSON("ok" << 1 << "totalSize" << 100); }); + // Return OK for _flushDatabaseCacheUpdates + onCommand([&](const RemoteCommandRequest& request) { + std::string cmdName = request.cmdObj.firstElement().fieldName(); + ASSERT_EQUALS("_flushDatabaseCacheUpdates", cmdName); + + return BSON("ok" << 1); + }); + future.default_timed_get(); } diff --git a/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp index f66e29f6f74..f486825ffd2 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp @@ -120,6 +120,17 @@ DatabaseType ShardingCatalogManager::createDatabase(OperationContext* opCtx, uassertStatusOK(Grid::get(opCtx)->catalogClient()->insertConfigDocument( opCtx, DatabaseType::ConfigNS, db.toBSON(), ShardingCatalogClient::kLocalWriteConcern)); + // Send _flushDatabaseCacheUpdates to the primary shard + const auto shard = + uassertStatusOK(Grid::get(opCtx)->shardRegistry()->getShard(opCtx, db.getPrimary())); + auto cmdResponse = uassertStatusOK( + shard->runCommandWithFixedRetryAttempts(opCtx, + ReadPreferenceSetting{ReadPreference::PrimaryOnly}, + "admin", + BSON("_flushDatabaseCacheUpdates" << dbName), + Shard::RetryPolicy::kIdempotent)); + // TODO SERVER-42112: uassert on the cmdResponse. + return db; } diff --git a/src/mongo/db/s/config/sharding_catalog_manager_enable_sharding_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_enable_sharding_test.cpp index 7452b250f14..8cd076b9c28 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_enable_sharding_test.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_enable_sharding_test.cpp @@ -100,6 +100,14 @@ TEST_F(EnableShardingTest, noDBExists) { })"); }); + // Return OK for _flushDatabaseCacheUpdates + onCommand([&](const RemoteCommandRequest& request) { + std::string cmdName = request.cmdObj.firstElement().fieldName(); + ASSERT_EQUALS("_flushDatabaseCacheUpdates", cmdName); + + return BSON("ok" << 1); + }); + future.default_timed_get(); } |