diff options
Diffstat (limited to 'src/mongo/db')
14 files changed, 44 insertions, 62 deletions
diff --git a/src/mongo/db/s/balancer/migration_test_fixture.cpp b/src/mongo/db/s/balancer/migration_test_fixture.cpp index 1ff3dc71ccb..206e0d7737d 100644 --- a/src/mongo/db/s/balancer/migration_test_fixture.cpp +++ b/src/mongo/db/s/balancer/migration_test_fixture.cpp @@ -48,7 +48,7 @@ std::shared_ptr<RemoteCommandTargeterMock> MigrationTestFixture::shardTargeterMo } void MigrationTestFixture::setUpDatabase(const std::string& dbName, const ShardId primaryShard) { - DatabaseType db(dbName, primaryShard, true, DatabaseVersion(UUID::gen(), Timestamp())); + DatabaseType db(dbName, primaryShard, DatabaseVersion(UUID::gen(), Timestamp())); ASSERT_OK(catalogClient()->insertConfigDocument(operationContext(), NamespaceString::kConfigDatabasesNamespace, db.toBSON(), diff --git a/src/mongo/db/s/config/config_server_test_fixture.cpp b/src/mongo/db/s/config/config_server_test_fixture.cpp index 774739ec29d..85f64c4a95f 100644 --- a/src/mongo/db/s/config/config_server_test_fixture.cpp +++ b/src/mongo/db/s/config/config_server_test_fixture.cpp @@ -328,7 +328,7 @@ void ConfigServerTestFixture::setupCollection(const NamespaceString& nss, invariant(swShardDoc.isOK(), "At least one shard should be setup when initializing a collection"); auto shard = uassertStatusOK(ShardType::fromBSON(swShardDoc.getValue())); - setupDatabase(nss.db().toString(), ShardId(shard.getName()), true /* sharded */); + setupDatabase(nss.db().toString(), ShardId(shard.getName())); } CollectionType coll(nss, @@ -400,9 +400,8 @@ StatusWith<ChunkVersion> ConfigServerTestFixture::getCollectionVersion(Operation } void ConfigServerTestFixture::setupDatabase(const std::string& dbName, - const ShardId primaryShard, - const bool sharded) { - DatabaseType db(dbName, primaryShard, sharded, DatabaseVersion(UUID::gen(), Timestamp())); + const ShardId& primaryShard) { + DatabaseType db(dbName, primaryShard, DatabaseVersion(UUID::gen(), Timestamp())); ASSERT_OK(catalogClient()->insertConfigDocument(operationContext(), NamespaceString::kConfigDatabasesNamespace, db.toBSON(), diff --git a/src/mongo/db/s/config/config_server_test_fixture.h b/src/mongo/db/s/config/config_server_test_fixture.h index 821b8987406..f2d2d0a1ef0 100644 --- a/src/mongo/db/s/config/config_server_test_fixture.h +++ b/src/mongo/db/s/config/config_server_test_fixture.h @@ -136,7 +136,7 @@ protected: /** * Inserts a document for the database into the config.databases collection. */ - void setupDatabase(const std::string& dbName, ShardId primaryShard, bool sharded); + void setupDatabase(const std::string& dbName, const ShardId& primaryShard); /** * Returns the indexes definitions defined on a given collection. diff --git a/src/mongo/db/s/config/sharding_catalog_manager.h b/src/mongo/db/s/config/sharding_catalog_manager.h index b21b98f3265..9653a0ce6d3 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager.h +++ b/src/mongo/db/s/config/sharding_catalog_manager.h @@ -394,10 +394,12 @@ public: * exists, and if not, creates a new one that matches these prerequisites. If a database already * exists and matches all the prerequisites returns success, otherwise throws NamespaceNotFound. */ - DatabaseType createDatabase(OperationContext* opCtx, - StringData dbName, - const boost::optional<ShardId>& optPrimaryShard, - bool enableSharding); + DatabaseType createDatabase( + OperationContext* opCtx, + StringData dbName, + const boost::optional<ShardId>& optPrimaryShard, + // # TODO SERVER-63983: remove enableSharding paramter when 6.0 becomes lastLTS + bool enableSharding = false); // // Collection Operations diff --git a/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp index 2dfa0e75278..2cbec96bc9a 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp @@ -380,14 +380,10 @@ TEST_F(AddShardTest, StandaloneBasicSuccess) { expectedShard.setMaxSizeMB(100); expectedShard.setState(ShardType::ShardState::kShardAware); - DatabaseType discoveredDB1("TestDB1", - ShardId("StandaloneShard"), - false, - DatabaseVersion(UUID::gen(), Timestamp(1, 1))); - DatabaseType discoveredDB2("TestDB2", - ShardId("StandaloneShard"), - false, - DatabaseVersion(UUID::gen(), Timestamp(1, 1))); + DatabaseType discoveredDB1( + "TestDB1", ShardId("StandaloneShard"), DatabaseVersion(UUID::gen(), Timestamp(1, 1))); + DatabaseType discoveredDB2( + "TestDB2", ShardId("StandaloneShard"), DatabaseVersion(UUID::gen(), Timestamp(1, 1))); auto expectWriteConcern = ShardingCatalogClient::kMajorityWriteConcern; @@ -470,14 +466,10 @@ TEST_F(AddShardTest, StandaloneGenerateName) { expectedShard.setMaxSizeMB(100); expectedShard.setState(ShardType::ShardState::kShardAware); - DatabaseType discoveredDB1("TestDB1", - ShardId(expectedShardName), - false, - DatabaseVersion(UUID::gen(), Timestamp(1, 1))); - DatabaseType discoveredDB2("TestDB2", - ShardId(expectedShardName), - false, - DatabaseVersion(UUID::gen(), Timestamp(1, 1))); + DatabaseType discoveredDB1( + "TestDB1", ShardId(expectedShardName), DatabaseVersion(UUID::gen(), Timestamp(1, 1))); + DatabaseType discoveredDB2( + "TestDB2", ShardId(expectedShardName), DatabaseVersion(UUID::gen(), Timestamp(1, 1))); auto future = launchAsync([this, &expectedShardName, &shardTarget] { ThreadClient tc(getServiceContext()); @@ -819,7 +811,7 @@ TEST_F(AddShardTest, ShardContainsExistingDatabase) { std::string expectedShardName = "mySet"; DatabaseType existingDB( - "existing", ShardId("existingShard"), false, DatabaseVersion(UUID::gen(), Timestamp(1, 1))); + "existing", ShardId("existingShard"), DatabaseVersion(UUID::gen(), Timestamp(1, 1))); // Add a pre-existing database. ASSERT_OK(catalogClient()->insertConfigDocument(operationContext(), @@ -873,10 +865,8 @@ TEST_F(AddShardTest, SuccessfullyAddReplicaSet) { expectedShard.setMaxSizeMB(100); expectedShard.setState(ShardType::ShardState::kShardAware); - DatabaseType discoveredDB("shardDB", - ShardId(expectedShardName), - false, - DatabaseVersion(UUID::gen(), Timestamp(1, 1))); + DatabaseType discoveredDB( + "shardDB", ShardId(expectedShardName), DatabaseVersion(UUID::gen(), Timestamp(1, 1))); auto future = launchAsync([this, &expectedShardName, &connString] { ThreadClient tc(getServiceContext()); @@ -940,10 +930,8 @@ TEST_F(AddShardTest, ReplicaSetExtraHostsDiscovered) { expectedShard.setMaxSizeMB(100); expectedShard.setState(ShardType::ShardState::kShardAware); - DatabaseType discoveredDB("shardDB", - ShardId(expectedShardName), - false, - DatabaseVersion(UUID::gen(), Timestamp(1, 1))); + DatabaseType discoveredDB( + "shardDB", ShardId(expectedShardName), DatabaseVersion(UUID::gen(), Timestamp(1, 1))); auto future = launchAsync([this, &expectedShardName, &seedString] { ThreadClient tc(getServiceContext()); @@ -1008,14 +996,10 @@ TEST_F(AddShardTest, AddShardSucceedsEvenIfAddingDBsFromNewShardFails) { expectedShard.setMaxSizeMB(100); expectedShard.setState(ShardType::ShardState::kShardAware); - DatabaseType discoveredDB1("TestDB1", - ShardId("StandaloneShard"), - false, - DatabaseVersion(UUID::gen(), Timestamp(1, 1))); - DatabaseType discoveredDB2("TestDB2", - ShardId("StandaloneShard"), - false, - DatabaseVersion(UUID::gen(), Timestamp(1, 1))); + DatabaseType discoveredDB1( + "TestDB1", ShardId("StandaloneShard"), DatabaseVersion(UUID::gen(), Timestamp(1, 1))); + DatabaseType discoveredDB2( + "TestDB2", ShardId("StandaloneShard"), DatabaseVersion(UUID::gen(), Timestamp(1, 1))); // Enable fail point to cause all updates to fail. Since we add the databases detected from // the shard being added with upserts, but we add the shard document itself via insert, this 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 212e598bb67..934eca19e8e 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 @@ -90,7 +90,7 @@ DatabaseType ShardingCatalogManager::createDatabase(OperationContext* opCtx, bool enableSharding) { if (dbName == NamespaceString::kConfigDb) { return DatabaseType( - dbName.toString(), ShardId::kConfigServerId, true, DatabaseVersion::makeFixed()); + dbName.toString(), ShardId::kConfigServerId, DatabaseVersion::makeFixed()); } uassert(ErrorCodes::InvalidOptions, @@ -214,10 +214,12 @@ DatabaseType ShardingCatalogManager::createDatabase(OperationContext* opCtx, const auto clusterTime = now.clusterTime().asTimestamp(); // Pick a primary shard for the new database. - DatabaseType db(dbName.toString(), - shardPtr->getId(), - enableShardingOptional ? false : enableSharding, - DatabaseVersion(UUID::gen(), clusterTime)); + DatabaseType db( + dbName.toString(), shardPtr->getId(), DatabaseVersion(UUID::gen(), clusterTime)); + + if (!enableShardingOptional) { + db.setSharded(enableSharding); + } LOGV2(21938, "Registering new database {db} in sharding catalog", diff --git a/src/mongo/db/s/config/sharding_catalog_manager_remove_shard_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_remove_shard_test.cpp index aba7972018d..d760e1ce3d5 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_remove_shard_test.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_remove_shard_test.cpp @@ -216,7 +216,7 @@ TEST_F(RemoveShardTest, RemoveShardStillDrainingChunksRemaining) { chunk3.setJumbo(true); setupShards(std::vector<ShardType>{shard1, shard2}); - setupDatabase("testDB", shard1.getName(), true); + setupDatabase("testDB", shard1.getName()); setupCollection(NamespaceString("testDB.testColl"), kKeyPattern, std::vector<ChunkType>{chunk1, chunk2, chunk3}); @@ -252,7 +252,7 @@ TEST_F(RemoveShardTest, RemoveShardStillDrainingDatabasesRemaining) { shard2.setState(ShardType::ShardState::kShardAware); setupShards(std::vector<ShardType>{shard1, shard2}); - setupDatabase("testDB", shard1.getName(), false); + setupDatabase("testDB", shard1.getName()); auto startedResult = ShardingCatalogManager::get(operationContext()) ->removeShard(operationContext(), shard1.getName()); @@ -303,7 +303,7 @@ TEST_F(RemoveShardTest, RemoveShardCompletion) { std::vector<ChunkType> chunks{chunk1, chunk2, chunk3}; setupShards(std::vector<ShardType>{shard1, shard2}); - setupDatabase("testDB", shard2.getName(), false); + setupDatabase("testDB", shard2.getName()); setupCollection(NamespaceString("testDB.testColl"), kKeyPattern, std::vector<ChunkType>{chunk1, chunk2, chunk3}); diff --git a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp index fc000d17f14..cd97c57f44c 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp @@ -743,7 +743,7 @@ StatusWith<std::string> ShardingCatalogManager::addShard( const auto clusterTime = now.clusterTime().asTimestamp(); DatabaseType dbt( - dbName, shardType.getName(), false, DatabaseVersion(UUID::gen(), clusterTime)); + dbName, shardType.getName(), DatabaseVersion(UUID::gen(), clusterTime)); { const auto status = Grid::get(opCtx)->catalogClient()->updateConfigDocument( diff --git a/src/mongo/db/s/database_sharding_state_test.cpp b/src/mongo/db/s/database_sharding_state_test.cpp index 007da2b6568..f4516bb8d13 100644 --- a/src/mongo/db/s/database_sharding_state_test.cpp +++ b/src/mongo/db/s/database_sharding_state_test.cpp @@ -120,7 +120,7 @@ public: DatabaseType createDatabase(const UUID& uuid, const Timestamp& timestamp) { return DatabaseType( - kDbName.toString(), kShardList[0].getName(), true, DatabaseVersion(uuid, timestamp)); + kDbName.toString(), kShardList[0].getName(), DatabaseVersion(uuid, timestamp)); } protected: diff --git a/src/mongo/db/s/migration_util_test.cpp b/src/mongo/db/s/migration_util_test.cpp index 61d78b8359b..ac3f0cc4254 100644 --- a/src/mongo/db/s/migration_util_test.cpp +++ b/src/mongo/db/s/migration_util_test.cpp @@ -368,11 +368,8 @@ public: const UUID kDefaultUUID = UUID::gen(); const OID kEpoch = OID::gen(); const Timestamp kDefaultTimestamp = Timestamp(2, 0); - const DatabaseType kDefaultDatabaseType = - DatabaseType(kTestNss.db().toString(), - ShardId("0"), - true, - DatabaseVersion(kDefaultUUID, kDefaultTimestamp)); + const DatabaseType kDefaultDatabaseType = DatabaseType( + kTestNss.db().toString(), ShardId("0"), DatabaseVersion(kDefaultUUID, kDefaultTimestamp)); const std::vector<ShardType> kShardList = {ShardType("0", "Host0:12345"), ShardType("1", "Host1:12345")}; diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp b/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp index d402cbbfa26..2587b71dbfb 100644 --- a/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp +++ b/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp @@ -382,7 +382,6 @@ public: DatabaseType dbDoc(coordinatorDoc.getSourceNss().db().toString(), coordinatorDoc.getDonorShards().front().getId(), - true, DatabaseVersion{UUID::gen(), Timestamp(1, 1)}); client.insert(NamespaceString::kConfigDatabasesNamespace.ns(), dbDoc.toBSON()); diff --git a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp index bb7d48471dd..5e54ee87606 100644 --- a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp +++ b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp @@ -536,7 +536,7 @@ protected: // Create original collection's catalog entry as well as both config.chunks and config.tags // collections. { - setupDatabase("db", ShardId("shard0000"), true); + setupDatabase("db", ShardId("shard0000")); auto opCtx = operationContext(); DBDirectClient client(opCtx); diff --git a/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp b/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp index d8c0b8f8335..c41f4ce7db3 100644 --- a/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp +++ b/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp @@ -82,7 +82,6 @@ class ReshardingTxnClonerTest : public ShardServerTestFixture { mockLoader->setDatabaseRefreshReturnValue( DatabaseType{NamespaceString::kConfigDb.toString(), ShardId::kConfigServerId, - true, DatabaseVersion::makeFixed()}); // The config.transactions collection is always unsharded. diff --git a/src/mongo/db/s/resharding_destined_recipient_test.cpp b/src/mongo/db/s/resharding_destined_recipient_test.cpp index 34d56bbb70f..946dab13106 100644 --- a/src/mongo/db/s/resharding_destined_recipient_test.cpp +++ b/src/mongo/db/s/resharding_destined_recipient_test.cpp @@ -220,7 +220,7 @@ protected: coll.setAllowMigrations(false); _mockCatalogCacheLoader->setDatabaseRefreshReturnValue( - DatabaseType(kNss.db().toString(), kShardList[0].getName(), true, env.dbVersion)); + DatabaseType(kNss.db().toString(), kShardList[0].getName(), env.dbVersion)); _mockCatalogCacheLoader->setCollectionRefreshValues( kNss, coll, |