From bb840568d976f687fb8e0baa24e37a7827b06de4 Mon Sep 17 00:00:00 2001 From: Sergi Mateo Bellido Date: Mon, 23 Nov 2020 08:57:20 +0000 Subject: SERVER-52933 Add timestamp to the DatabaseVersion IDL PART 1 - Adding a new DatabaseVersion class that handles the underlying IDL implementation of a DatabaseVersion --- .../set_feature_compatibility_version_command.cpp | 1 - src/mongo/db/s/README.md | 2 +- src/mongo/db/s/balancer/migration_test_fixture.cpp | 2 +- src/mongo/db/s/balancer/migration_test_fixture.h | 1 - .../db/s/collection_metadata_filtering_test.cpp | 2 +- src/mongo/db/s/collection_metadata_test.cpp | 2 +- .../db/s/collection_sharding_runtime_test.cpp | 2 +- .../db/s/config/config_server_test_fixture.cpp | 4 +- .../sharding_catalog_manager_add_shard_test.cpp | 20 +++--- ...harding_catalog_manager_database_operations.cpp | 6 +- .../sharding_catalog_manager_shard_operations.cpp | 4 +- src/mongo/db/s/database_sharding_state.cpp | 4 +- src/mongo/db/s/database_sharding_state.h | 2 +- src/mongo/db/s/metadata_manager_test.cpp | 2 +- .../migration_chunk_cloner_source_legacy_test.cpp | 2 +- src/mongo/db/s/migration_util_test.cpp | 4 +- src/mongo/db/s/op_observer_sharding_test.cpp | 2 +- src/mongo/db/s/operation_sharding_state.cpp | 3 +- src/mongo/db/s/operation_sharding_state.h | 2 +- src/mongo/db/s/range_deletion_util_test.cpp | 2 +- .../resharding_donor_recipient_common_test.cpp | 2 +- .../s/resharding/resharding_oplog_applier_test.cpp | 2 +- .../resharding_recipient_service_test.cpp | 9 +-- .../db/s/resharding_destined_recipient_test.cpp | 4 +- src/mongo/db/s/shard_filtering_metadata_refresh.h | 2 +- src/mongo/db/s/type_shard_database.cpp | 18 ++---- src/mongo/db/s/type_shard_database.h | 2 +- src/mongo/s/SConscript | 2 +- ...versioned_requests_for_targeted_shards_test.cpp | 4 +- .../s/catalog/sharding_catalog_client_impl.cpp | 6 +- .../s/catalog/sharding_catalog_client_test.cpp | 18 +++--- src/mongo/s/catalog/type_database.cpp | 20 +++--- src/mongo/s/catalog/type_database.h | 2 +- src/mongo/s/catalog_cache.cpp | 2 +- src/mongo/s/catalog_cache_refresh_test.cpp | 4 +- src/mongo/s/catalog_cache_test.cpp | 22 +++---- src/mongo/s/catalog_cache_test_fixture.cpp | 6 +- src/mongo/s/chunk_manager.h | 2 +- src/mongo/s/chunk_manager_query_test.cpp | 2 +- src/mongo/s/chunk_manager_refresh_bm.cpp | 6 +- src/mongo/s/cluster_commands_helpers.cpp | 4 +- .../s/commands/cluster_get_shard_version_cmd.cpp | 2 +- src/mongo/s/comparable_database_version_test.cpp | 34 +++++----- src/mongo/s/config_server_catalog_cache_loader.cpp | 1 - src/mongo/s/database_version.cpp | 48 ++++++++++++++ src/mongo/s/database_version.h | 75 ++++++++++++++++++++++ src/mongo/s/database_version.idl | 5 +- src/mongo/s/database_version_helpers.cpp | 67 ------------------- src/mongo/s/database_version_helpers.h | 48 -------------- src/mongo/s/stale_exception.cpp | 13 ++-- src/mongo/s/stale_exception.h | 2 +- src/mongo/s/write_ops/batch_write_exec_test.cpp | 4 +- src/mongo/s/write_ops/batched_command_request.cpp | 4 +- src/mongo/s/write_ops/batched_command_request.h | 2 +- src/mongo/s/write_ops/chunk_manager_targeter.cpp | 9 ++- 55 files changed, 256 insertions(+), 266 deletions(-) create mode 100644 src/mongo/s/database_version.cpp create mode 100644 src/mongo/s/database_version.h delete mode 100644 src/mongo/s/database_version_helpers.cpp delete mode 100644 src/mongo/s/database_version_helpers.h diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp index 682f27f8e84..b89f52ff278 100644 --- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp +++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp @@ -60,7 +60,6 @@ #include "mongo/db/views/view_catalog.h" #include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" -#include "mongo/s/database_version_helpers.h" #include "mongo/stdx/unordered_set.h" #include "mongo/util/exit.h" #include "mongo/util/fail_point.h" diff --git a/src/mongo/db/s/README.md b/src/mongo/db/s/README.md index cf9315e6265..df38da29343 100644 --- a/src/mongo/db/s/README.md +++ b/src/mongo/db/s/README.md @@ -191,7 +191,7 @@ Admin database | UUID() | 0 | * [The chunk version class](https://github.com/mongodb/mongo/blob/master/src/mongo/s/chunk_version.h) * [The database version IDL](https://github.com/mongodb/mongo/blob/master/src/mongo/s/database_version.idl) -* [The database version helpers class](https://github.com/mongodb/mongo/blob/master/src/mongo/s/database_version_helpers.h) +* [The database version class](https://github.com/mongodb/mongo/blob/master/src/mongo/s/database_version.h) * [Where shard versions are stored in a routing table cache](https://github.com/mongodb/mongo/blob/1df41757d5d1e04c51eeeee786a17b005e025b93/src/mongo/s/catalog_cache.h#L499-L500) * [Where database versions are stored in a routing table cache](https://github.com/mongodb/mongo/blob/1df41757d5d1e04c51eeeee786a17b005e025b93/src/mongo/s/catalog_cache.h#L497-L498) * [Method used to attach the shard version to outbound requests](https://github.com/mongodb/mongo/blob/1df41757d5d1e04c51eeeee786a17b005e025b93/src/mongo/s/cluster_commands_helpers.h#L118-L121) diff --git a/src/mongo/db/s/balancer/migration_test_fixture.cpp b/src/mongo/db/s/balancer/migration_test_fixture.cpp index 30536ce36e3..4052d9ee15e 100644 --- a/src/mongo/db/s/balancer/migration_test_fixture.cpp +++ b/src/mongo/db/s/balancer/migration_test_fixture.cpp @@ -46,7 +46,7 @@ std::shared_ptr MigrationTestFixture::shardTargeterMo } void MigrationTestFixture::setUpDatabase(const std::string& dbName, const ShardId primaryShard) { - DatabaseType db(dbName, primaryShard, true, databaseVersion::makeNew()); + DatabaseType db(dbName, primaryShard, true, DatabaseVersion(UUID::gen())); ASSERT_OK(catalogClient()->insertConfigDocument( operationContext(), DatabaseType::ConfigNS, db.toBSON(), kMajorityWriteConcern)); } diff --git a/src/mongo/db/s/balancer/migration_test_fixture.h b/src/mongo/db/s/balancer/migration_test_fixture.h index dd79c96c175..d2fef72b513 100644 --- a/src/mongo/db/s/balancer/migration_test_fixture.h +++ b/src/mongo/db/s/balancer/migration_test_fixture.h @@ -43,7 +43,6 @@ #include "mongo/s/catalog/type_locks.h" #include "mongo/s/catalog/type_shard.h" #include "mongo/s/catalog/type_tags.h" -#include "mongo/s/database_version_helpers.h" namespace mongo { diff --git a/src/mongo/db/s/collection_metadata_filtering_test.cpp b/src/mongo/db/s/collection_metadata_filtering_test.cpp index 3d3763a5928..ce95b6b5a46 100644 --- a/src/mongo/db/s/collection_metadata_filtering_test.cpp +++ b/src/mongo/db/s/collection_metadata_filtering_test.cpp @@ -105,7 +105,7 @@ protected: }()); ChunkManager cm(ShardId("0"), - DatabaseVersion(UUID::gen(), 1), + DatabaseVersion(UUID::gen()), makeStandaloneRoutingTableHistory(std::move(rt)), boost::none); ASSERT_EQ(4, cm.numChunks()); diff --git a/src/mongo/db/s/collection_metadata_test.cpp b/src/mongo/db/s/collection_metadata_test.cpp index cacc3891236..fe0935fe41d 100644 --- a/src/mongo/db/s/collection_metadata_test.cpp +++ b/src/mongo/db/s/collection_metadata_test.cpp @@ -85,7 +85,7 @@ CollectionMetadata makeCollectionMetadataImpl( return CollectionMetadata( ChunkManager(kThisShard, - DatabaseVersion(UUID::gen(), 1), + DatabaseVersion(UUID::gen()), ShardingTestFixtureCommon::makeStandaloneRoutingTableHistory( RoutingTableHistory::makeNew(kNss, UUID::gen(), diff --git a/src/mongo/db/s/collection_sharding_runtime_test.cpp b/src/mongo/db/s/collection_sharding_runtime_test.cpp index 215dd006b95..9c4ce69c65d 100644 --- a/src/mongo/db/s/collection_sharding_runtime_test.cpp +++ b/src/mongo/db/s/collection_sharding_runtime_test.cpp @@ -55,7 +55,7 @@ protected: ChunkType(kTestNss, std::move(range), ChunkVersion(1, 0, epoch), ShardId("other")); ChunkManager cm( ShardId("0"), - DatabaseVersion(UUID::gen(), 1), + DatabaseVersion(UUID::gen()), makeStandaloneRoutingTableHistory(RoutingTableHistory::makeNew(kTestNss, uuid, kShardKeyPattern, 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 7aa957717c0..ab331cb2f4c 100644 --- a/src/mongo/db/s/config/config_server_test_fixture.cpp +++ b/src/mongo/db/s/config/config_server_test_fixture.cpp @@ -67,7 +67,7 @@ #include "mongo/s/chunk_version.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/config_server_catalog_cache_loader.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/s/query/cluster_cursor_manager.h" #include "mongo/s/request_types/set_shard_version_request.h" #include "mongo/s/shard_id.h" @@ -352,7 +352,7 @@ StatusWith ConfigServerTestFixture::getChunkDoc(OperationContext* opC void ConfigServerTestFixture::setupDatabase(const std::string& dbName, const ShardId primaryShard, const bool sharded) { - DatabaseType db(dbName, primaryShard, sharded, databaseVersion::makeNew()); + DatabaseType db(dbName, primaryShard, sharded, DatabaseVersion(UUID::gen())); ASSERT_OK(catalogClient()->insertConfigDocument(operationContext(), DatabaseType::ConfigNS, db.toBSON(), 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 2a5029f5e25..772d0621d76 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 @@ -52,7 +52,7 @@ #include "mongo/s/catalog/type_shard.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/cluster_identity_loader.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/s/write_ops/batched_command_response.h" #include "mongo/util/fail_point.h" #include "mongo/util/scopeguard.h" @@ -380,9 +380,9 @@ TEST_F(AddShardTest, StandaloneBasicSuccess) { expectedShard.setState(ShardType::ShardState::kShardAware); DatabaseType discoveredDB1( - "TestDB1", ShardId("StandaloneShard"), false, databaseVersion::makeNew()); + "TestDB1", ShardId("StandaloneShard"), false, DatabaseVersion(UUID::gen())); DatabaseType discoveredDB2( - "TestDB2", ShardId("StandaloneShard"), false, databaseVersion::makeNew()); + "TestDB2", ShardId("StandaloneShard"), false, DatabaseVersion(UUID::gen())); auto expectWriteConcern = ShardingCatalogClient::kMajorityWriteConcern; @@ -466,9 +466,9 @@ TEST_F(AddShardTest, StandaloneGenerateName) { expectedShard.setState(ShardType::ShardState::kShardAware); DatabaseType discoveredDB1( - "TestDB1", ShardId(expectedShardName), false, databaseVersion::makeNew()); + "TestDB1", ShardId(expectedShardName), false, DatabaseVersion(UUID::gen())); DatabaseType discoveredDB2( - "TestDB2", ShardId(expectedShardName), false, databaseVersion::makeNew()); + "TestDB2", ShardId(expectedShardName), false, DatabaseVersion(UUID::gen())); auto future = launchAsync([this, &expectedShardName, &shardTarget] { ThreadClient tc(getServiceContext()); @@ -810,7 +810,7 @@ TEST_F(AddShardTest, ShardContainsExistingDatabase) { std::string expectedShardName = "mySet"; DatabaseType existingDB( - "existing", ShardId("existingShard"), false, databaseVersion::makeNew()); + "existing", ShardId("existingShard"), false, DatabaseVersion(UUID::gen())); // Add a pre-existing database. ASSERT_OK(catalogClient()->insertConfigDocument(operationContext(), @@ -865,7 +865,7 @@ TEST_F(AddShardTest, SuccessfullyAddReplicaSet) { expectedShard.setState(ShardType::ShardState::kShardAware); DatabaseType discoveredDB( - "shardDB", ShardId(expectedShardName), false, databaseVersion::makeNew()); + "shardDB", ShardId(expectedShardName), false, DatabaseVersion(UUID::gen())); auto future = launchAsync([this, &expectedShardName, &connString] { ThreadClient tc(getServiceContext()); @@ -930,7 +930,7 @@ TEST_F(AddShardTest, ReplicaSetExtraHostsDiscovered) { expectedShard.setState(ShardType::ShardState::kShardAware); DatabaseType discoveredDB( - "shardDB", ShardId(expectedShardName), false, databaseVersion::makeNew()); + "shardDB", ShardId(expectedShardName), false, DatabaseVersion(UUID::gen())); auto future = launchAsync([this, &expectedShardName, &seedString] { ThreadClient tc(getServiceContext()); @@ -996,9 +996,9 @@ TEST_F(AddShardTest, AddShardSucceedsEvenIfAddingDBsFromNewShardFails) { expectedShard.setState(ShardType::ShardState::kShardAware); DatabaseType discoveredDB1( - "TestDB1", ShardId("StandaloneShard"), false, databaseVersion::makeNew()); + "TestDB1", ShardId("StandaloneShard"), false, DatabaseVersion(UUID::gen())); DatabaseType discoveredDB2( - "TestDB2", ShardId("StandaloneShard"), false, databaseVersion::makeNew()); + "TestDB2", ShardId("StandaloneShard"), false, DatabaseVersion(UUID::gen())); // 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 aeccf255c1e..760b5c96f02 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 @@ -43,7 +43,7 @@ #include "mongo/s/catalog/type_database.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/client/shard.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/s/grid.h" #include "mongo/s/shard_id.h" #include "mongo/s/shard_util.h" @@ -160,7 +160,7 @@ DatabaseType ShardingCatalogManager::createDatabase(OperationContext* opCtx, // Pick a primary shard for the new database. DatabaseType db( - dbName.toString(), shardPtr->getId(), false, databaseVersion::makeNew()); + dbName.toString(), shardPtr->getId(), false, DatabaseVersion(UUID::gen())); LOGV2(21938, "Registering new database {db} in sharding catalog", @@ -306,7 +306,7 @@ Status ShardingCatalogManager::commitMovePrimary(OperationContext* opCtx, auto const currentDatabaseVersion = dbType.getVersion(); - newDbType.setVersion(databaseVersion::makeIncremented(currentDatabaseVersion)); + newDbType.setVersion(currentDatabaseVersion.makeUpdated()); auto updateQueryBuilder = BSONObjBuilder(BSON(DatabaseType::name << dbname)); updateQueryBuilder.append(DatabaseType::version.name(), currentDatabaseVersion.toBSON()); 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 aba56f08fef..f63fbf08427 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 @@ -70,7 +70,7 @@ #include "mongo/s/client/shard.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/cluster_identity_loader.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/s/grid.h" #include "mongo/s/write_ops/batched_command_request.h" #include "mongo/s/write_ops/batched_command_response.h" @@ -736,7 +736,7 @@ StatusWith ShardingCatalogManager::addShard( // Add all databases which were discovered on the new shard for (const auto& dbName : dbNamesStatus.getValue()) { - DatabaseType dbt(dbName, shardType.getName(), false, databaseVersion::makeNew()); + DatabaseType dbt(dbName, shardType.getName(), false, DatabaseVersion(UUID::gen())); { const auto status = Grid::get(opCtx)->catalogClient()->updateConfigDocument( diff --git a/src/mongo/db/s/database_sharding_state.cpp b/src/mongo/db/s/database_sharding_state.cpp index f7c31837fcb..7d2f2c0ca44 100644 --- a/src/mongo/db/s/database_sharding_state.cpp +++ b/src/mongo/db/s/database_sharding_state.cpp @@ -36,7 +36,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/s/operation_sharding_state.h" #include "mongo/logv2/log.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/s/stale_exception.h" #include "mongo/util/fail_point.h" @@ -151,7 +151,7 @@ void DatabaseShardingState::checkDbVersion(OperationContext* opCtx, DSSLock&) co _dbVersion); uassert(StaleDbRoutingVersion(_dbName, *clientDbVersion, *_dbVersion), str::stream() << "dbVersion mismatch for database " << _dbName, - databaseVersion::equal(*clientDbVersion, *_dbVersion)); + *clientDbVersion == *_dbVersion); } MovePrimarySourceManager* DatabaseShardingState::getMovePrimarySourceManager(DSSLock&) { diff --git a/src/mongo/db/s/database_sharding_state.h b/src/mongo/db/s/database_sharding_state.h index 938431cbf8e..0a14b690484 100644 --- a/src/mongo/db/s/database_sharding_state.h +++ b/src/mongo/db/s/database_sharding_state.h @@ -32,7 +32,7 @@ #include "mongo/db/catalog/database.h" #include "mongo/db/s/sharding_migration_critical_section.h" #include "mongo/db/s/sharding_state_lock.h" -#include "mongo/s/database_version_gen.h" +#include "mongo/s/database_version.h" namespace mongo { diff --git a/src/mongo/db/s/metadata_manager_test.cpp b/src/mongo/db/s/metadata_manager_test.cpp index 4786c4a9c1f..a2391f2631f 100644 --- a/src/mongo/db/s/metadata_manager_test.cpp +++ b/src/mongo/db/s/metadata_manager_test.cpp @@ -90,7 +90,7 @@ protected: {ChunkType{kNss, range, ChunkVersion(1, 0, epoch), kOtherShard}}); return CollectionMetadata(ChunkManager(kThisShard, - DatabaseVersion(UUID::gen(), 1), + DatabaseVersion(UUID::gen()), makeStandaloneRoutingTableHistory(std::move(rt)), boost::none), kThisShard); diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp index 6ceedcb45af..40d63f60f3d 100644 --- a/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp +++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp @@ -168,7 +168,7 @@ protected: operationContext(), CollectionMetadata( ChunkManager(ShardId("dummyShardId"), - DatabaseVersion(UUID::gen(), 1), + DatabaseVersion(UUID::gen()), makeStandaloneRoutingTableHistory(std::move(rt)), boost::none), ShardId("dummyShardId"))); diff --git a/src/mongo/db/s/migration_util_test.cpp b/src/mongo/db/s/migration_util_test.cpp index 763b09a5fc6..6f329a120e4 100644 --- a/src/mongo/db/s/migration_util_test.cpp +++ b/src/mongo/db/s/migration_util_test.cpp @@ -42,7 +42,7 @@ #include "mongo/s/catalog/sharding_catalog_client_mock.h" #include "mongo/s/catalog/type_shard.h" #include "mongo/s/catalog_cache_loader_mock.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/util/future.h" namespace mongo { @@ -326,7 +326,7 @@ public: const UUID kDefaultUUID = UUID::gen(); const OID kEpoch = OID::gen(); const DatabaseType kDefaultDatabaseType = - DatabaseType(kNss.db().toString(), ShardId("0"), true, DatabaseVersion(kDefaultUUID, 1)); + DatabaseType(kNss.db().toString(), ShardId("0"), true, DatabaseVersion(kDefaultUUID)); const std::vector kShardList = {ShardType("0", "Host0:12345"), ShardType("1", "Host1:12345")}; diff --git a/src/mongo/db/s/op_observer_sharding_test.cpp b/src/mongo/db/s/op_observer_sharding_test.cpp index e95b45c99a3..bd4d1c03d7e 100644 --- a/src/mongo/db/s/op_observer_sharding_test.cpp +++ b/src/mongo/db/s/op_observer_sharding_test.cpp @@ -77,7 +77,7 @@ protected: {std::move(chunk)}); return CollectionMetadata(ChunkManager(ShardId("this"), - DatabaseVersion(UUID::gen(), 1), + DatabaseVersion(UUID::gen()), makeStandaloneRoutingTableHistory(std::move(rt)), Timestamp(100, 0)), ShardId("this")); diff --git a/src/mongo/db/s/operation_sharding_state.cpp b/src/mongo/db/s/operation_sharding_state.cpp index f8dc5077eae..8b17d7f2ade 100644 --- a/src/mongo/db/s/operation_sharding_state.cpp +++ b/src/mongo/db/s/operation_sharding_state.cpp @@ -92,8 +92,7 @@ void OperationShardingState::initializeClientRoutingVersionsFromCommand(Namespac << dbVersionElem, dbVersionElem.type() == BSONType::Object); - dbVersion = DatabaseVersion::parse(IDLParserErrorContext("initializeClientRoutingVersions"), - dbVersionElem.Obj()); + dbVersion = DatabaseVersion(dbVersionElem.Obj()); } initializeClientRoutingVersions(nss, shardVersion, dbVersion); diff --git a/src/mongo/db/s/operation_sharding_state.h b/src/mongo/db/s/operation_sharding_state.h index 41c158ba8fd..4b32fd637ce 100644 --- a/src/mongo/db/s/operation_sharding_state.h +++ b/src/mongo/db/s/operation_sharding_state.h @@ -33,7 +33,7 @@ #include "mongo/db/namespace_string.h" #include "mongo/s/chunk_version.h" -#include "mongo/s/database_version_gen.h" +#include "mongo/s/database_version.h" #include "mongo/util/future.h" #include "mongo/util/string_map.h" diff --git a/src/mongo/db/s/range_deletion_util_test.cpp b/src/mongo/db/s/range_deletion_util_test.cpp index c9e10579df7..a3d2cdc568e 100644 --- a/src/mongo/db/s/range_deletion_util_test.cpp +++ b/src/mongo/db/s/range_deletion_util_test.cpp @@ -109,7 +109,7 @@ public: ->setFilteringMetadata( operationContext(), CollectionMetadata(ChunkManager(ShardId("dummyShardId"), - DatabaseVersion(UUID::gen(), 1), + DatabaseVersion(UUID::gen()), makeStandaloneRoutingTableHistory(std::move(rt)), boost::none), ShardId("dummyShardId"))); diff --git a/src/mongo/db/s/resharding/resharding_donor_recipient_common_test.cpp b/src/mongo/db/s/resharding/resharding_donor_recipient_common_test.cpp index 1206f4f28f5..429dca541d2 100644 --- a/src/mongo/db/s/resharding/resharding_donor_recipient_common_test.cpp +++ b/src/mongo/db/s/resharding/resharding_donor_recipient_common_test.cpp @@ -97,7 +97,7 @@ protected: auto chunk = ChunkType(nss, std::move(range), ChunkVersion(1, 0, epoch), kShardTwo); ChunkManager cm( kShardOne, - DatabaseVersion(uuid, 1), + DatabaseVersion(uuid), makeStandaloneRoutingTableHistory(RoutingTableHistory::makeNew(nss, uuid, shardKeyPattern, diff --git a/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp b/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp index c20a32d2169..2b72d339904 100644 --- a/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp +++ b/src/mongo/db/s/resharding/resharding_oplog_applier_test.cpp @@ -156,7 +156,7 @@ public: chunks); return ChunkManager(_sourceId.getShardId(), - DatabaseVersion(UUID::gen(), 1), + DatabaseVersion(UUID::gen()), makeStandaloneRoutingTableHistory(std::move(rt)), boost::none); } diff --git a/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp b/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp index 341b8c96c26..b93ad20f007 100644 --- a/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp +++ b/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp @@ -43,7 +43,7 @@ #include "mongo/db/session_catalog_mongod.h" #include "mongo/logv2/log.h" #include "mongo/s/catalog_cache_test_fixture.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/s/stale_exception.h" namespace mongo { @@ -172,9 +172,10 @@ public: void expectStaleDbVersionError(const NamespaceString& nss, StringData expectedCmdName) { onCommand([&](const executor::RemoteCommandRequest& request) { ASSERT_EQ(request.cmdObj.firstElementFieldNameStringData(), expectedCmdName); - return createErrorCursorResponse(Status( - StaleDbRoutingVersion(nss.db().toString(), databaseVersion::makeNew(), boost::none), - "dummy stale db version error")); + return createErrorCursorResponse( + Status(StaleDbRoutingVersion( + nss.db().toString(), DatabaseVersion(UUID::gen()), boost::none), + "dummy stale db version error")); }); } diff --git a/src/mongo/db/s/resharding_destined_recipient_test.cpp b/src/mongo/db/s/resharding_destined_recipient_test.cpp index 4b627d3fb4b..ab9a81c876f 100644 --- a/src/mongo/db/s/resharding_destined_recipient_test.cpp +++ b/src/mongo/db/s/resharding_destined_recipient_test.cpp @@ -48,7 +48,7 @@ #include "mongo/s/catalog/sharding_catalog_client_mock.h" #include "mongo/s/catalog/type_shard.h" #include "mongo/s/catalog_cache_loader_mock.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/s/shard_id.h" #include "mongo/unittest/unittest.h" @@ -183,7 +183,7 @@ protected: ReshardingEnv env(CollectionCatalog::get(opCtx)->lookupUUIDByNSS(opCtx, kNss).value()); env.destShard = kShardList[1].getName(); env.version = ChunkVersion(1, 0, OID::gen()); - env.dbVersion = databaseVersion::makeNew(); + env.dbVersion = DatabaseVersion(UUID::gen()); env.tempNss = NamespaceString(kNss.db(), diff --git a/src/mongo/db/s/shard_filtering_metadata_refresh.h b/src/mongo/db/s/shard_filtering_metadata_refresh.h index 317fab32f37..c868109641b 100644 --- a/src/mongo/db/s/shard_filtering_metadata_refresh.h +++ b/src/mongo/db/s/shard_filtering_metadata_refresh.h @@ -32,7 +32,7 @@ #include "mongo/db/namespace_string.h" #include "mongo/db/s/collection_metadata.h" #include "mongo/s/chunk_version.h" -#include "mongo/s/database_version_gen.h" +#include "mongo/s/database_version.h" namespace mongo { diff --git a/src/mongo/db/s/type_shard_database.cpp b/src/mongo/db/s/type_shard_database.cpp index 30b3ce01a31..77e930f1daf 100644 --- a/src/mongo/db/s/type_shard_database.cpp +++ b/src/mongo/db/s/type_shard_database.cpp @@ -60,18 +60,14 @@ StatusWith ShardDatabaseType::fromBSON(const BSONObj& source) return status; } - DatabaseVersion dbVersion; - { - BSONObj versionField = source.getObjectField("version"); - if (versionField.isEmpty()) { - return Status{ErrorCodes::InternalError, - str::stream() - << "DatabaseVersion doesn't exist in database entry " << source - << " despite the shard being in binary version 4.2 or " - "later."}; - } - dbVersion = DatabaseVersion::parse(IDLParserErrorContext("DatabaseType"), versionField); + BSONObj versionField = source.getObjectField("version"); + if (versionField.isEmpty()) { + return Status{ErrorCodes::InternalError, + str::stream() << "DatabaseVersion doesn't exist in database entry " << source + << " despite the shard being in binary version 4.2 or " + "later."}; } + DatabaseVersion dbVersion(versionField); std::string dbPrimary; { diff --git a/src/mongo/db/s/type_shard_database.h b/src/mongo/db/s/type_shard_database.h index 4ef22753663..44e1afb6944 100644 --- a/src/mongo/db/s/type_shard_database.h +++ b/src/mongo/db/s/type_shard_database.h @@ -33,7 +33,7 @@ #include #include "mongo/db/jsobj.h" -#include "mongo/s/database_version_gen.h" +#include "mongo/s/database_version.h" #include "mongo/s/shard_id.h" namespace mongo { diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript index c134e762b5e..bf4fc8cc3a6 100644 --- a/src/mongo/s/SConscript +++ b/src/mongo/s/SConscript @@ -146,7 +146,7 @@ env.Library( 'catalog/type_tags.cpp', 'chunk_version.cpp', 'chunk_version.idl', - 'database_version_helpers.cpp', + 'database_version.cpp', 'database_version.idl', 'mongod_and_mongos_server_parameters.idl', 'request_types/add_shard_request_type.cpp', diff --git a/src/mongo/s/build_versioned_requests_for_targeted_shards_test.cpp b/src/mongo/s/build_versioned_requests_for_targeted_shards_test.cpp index 7a9c6636d9b..accbd515922 100644 --- a/src/mongo/s/build_versioned_requests_for_targeted_shards_test.cpp +++ b/src/mongo/s/build_versioned_requests_for_targeted_shards_test.cpp @@ -35,7 +35,7 @@ #include "mongo/s/async_requests_sender.h" #include "mongo/s/catalog_cache_test_fixture.h" #include "mongo/s/cluster_commands_helpers.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" namespace mongo { namespace { @@ -73,7 +73,7 @@ protected: void expectGetDatabaseUnsharded() { expectFindSendBSONObjVector(kConfigHostAndPort, [&]() { - DatabaseType db(kNss.db().toString(), {"0"}, false, databaseVersion::makeNew()); + DatabaseType db(kNss.db().toString(), {"0"}, false, DatabaseVersion(UUID::gen())); return std::vector{db.toBSON()}; }()); } diff --git a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp index e38321ecf28..44205a3c198 100644 --- a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp +++ b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp @@ -60,7 +60,7 @@ #include "mongo/s/catalog/type_shard.h" #include "mongo/s/catalog/type_tags.h" #include "mongo/s/client/shard.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/s/grid.h" #include "mongo/s/request_types/set_shard_version_request.h" #include "mongo/s/shard_key_pattern.h" @@ -188,14 +188,14 @@ DatabaseType ShardingCatalogClientImpl::getDatabase(OperationContext* opCtx, return DatabaseType(dbName.toString(), ShardRegistry::kConfigServerShardId, false, - databaseVersion::makeFixed()); + DatabaseVersion::makeFixed()); // The config database's primary shard is always config, and it is always sharded. if (dbName == NamespaceString::kConfigDb) return DatabaseType(dbName.toString(), ShardRegistry::kConfigServerShardId, true, - databaseVersion::makeFixed()); + DatabaseVersion::makeFixed()); auto result = _fetchDatabaseMetadata(opCtx, dbName.toString(), kConfigReadSelector, readConcernLevel); diff --git a/src/mongo/s/catalog/sharding_catalog_client_test.cpp b/src/mongo/s/catalog/sharding_catalog_client_test.cpp index a7918ecba42..199abd55751 100644 --- a/src/mongo/s/catalog/sharding_catalog_client_test.cpp +++ b/src/mongo/s/catalog/sharding_catalog_client_test.cpp @@ -52,7 +52,7 @@ #include "mongo/s/catalog/type_tags.h" #include "mongo/s/chunk_version.h" #include "mongo/s/client/shard_registry.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/s/sharding_router_test_fixture.h" #include "mongo/s/write_ops/batched_command_response.h" #include "mongo/stdx/future.h" @@ -164,7 +164,7 @@ TEST_F(ShardingCatalogClientTest, GetDatabaseInvalidName) { TEST_F(ShardingCatalogClientTest, GetDatabaseExisting) { configTargeter()->setFindHostReturnValue(HostAndPort("TestHost1")); - DatabaseType expectedDb("bigdata", ShardId("shard0000"), true, databaseVersion::makeNew()); + DatabaseType expectedDb("bigdata", ShardId("shard0000"), true, DatabaseVersion(UUID::gen())); const OpTime newOpTime(Timestamp(7, 6), 5); @@ -212,7 +212,7 @@ TEST_F(ShardingCatalogClientTest, GetDatabaseStaleSecondaryRetrySuccess) { HostAndPort secondHost{"TestHost2"}; configTargeter()->setFindHostReturnValue(firstHost); - DatabaseType expectedDb("bigdata", ShardId("shard0000"), true, databaseVersion::makeNew()); + DatabaseType expectedDb("bigdata", ShardId("shard0000"), true, DatabaseVersion(UUID::gen())); auto future = launchAsync([this, &expectedDb] { return catalogClient()->getDatabase( @@ -901,8 +901,8 @@ TEST_F(ShardingCatalogClientTest, GetCollectionsInvalidCollectionType) { TEST_F(ShardingCatalogClientTest, GetDatabasesForShardValid) { configTargeter()->setFindHostReturnValue(HostAndPort("TestHost1")); - DatabaseType dbt1("db1", ShardId("shard0000"), false, databaseVersion::makeNew()); - DatabaseType dbt2("db2", ShardId("shard0000"), false, databaseVersion::makeNew()); + DatabaseType dbt1("db1", ShardId("shard0000"), false, DatabaseVersion(UUID::gen())); + DatabaseType dbt2("db2", ShardId("shard0000"), false, DatabaseVersion(UUID::gen())); auto future = launchAsync([this] { return assertGet( @@ -945,7 +945,7 @@ TEST_F(ShardingCatalogClientTest, GetDatabasesForShardInvalidDoc) { }); onFindCommand([](const RemoteCommandRequest& request) { - DatabaseType dbt1("db1", {"shard0000"}, false, databaseVersion::makeNew()); + DatabaseType dbt1("db1", {"shard0000"}, false, DatabaseVersion(UUID::gen())); return vector{ dbt1.toBSON(), BSON(DatabaseType::name() << 0) // DatabaseType::name() should be a string @@ -1051,7 +1051,7 @@ TEST_F(ShardingCatalogClientTest, GetTagsForCollectionInvalidTag) { TEST_F(ShardingCatalogClientTest, UpdateDatabase) { configTargeter()->setFindHostReturnValue(HostAndPort("TestHost1")); - DatabaseType dbt("test", ShardId("shard0000"), true, databaseVersion::makeNew()); + DatabaseType dbt("test", ShardId("shard0000"), true, DatabaseVersion(UUID::gen())); auto future = launchAsync([this, dbt] { auto status = @@ -1098,7 +1098,7 @@ TEST_F(ShardingCatalogClientTest, UpdateConfigDocumentNonRetryableError) { HostAndPort host1("TestHost1"); configTargeter()->setFindHostReturnValue(host1); - DatabaseType dbt("test", ShardId("shard0001"), false, databaseVersion::makeNew()); + DatabaseType dbt("test", ShardId("shard0001"), false, DatabaseVersion(UUID::gen())); auto future = launchAsync([this, dbt] { auto status = @@ -1296,7 +1296,7 @@ TEST_F(ShardingCatalogClientTest, RetryOnFindCommandNetworkErrorSucceedsAtMaxRet } onFindCommand([](const RemoteCommandRequest& request) { - DatabaseType dbType("TestDB", ShardId("TestShard"), true, databaseVersion::makeNew()); + DatabaseType dbType("TestDB", ShardId("TestShard"), true, DatabaseVersion(UUID::gen())); return vector{dbType.toBSON()}; }); diff --git a/src/mongo/s/catalog/type_database.cpp b/src/mongo/s/catalog/type_database.cpp index 2caf60f308f..736fa3fe0ef 100644 --- a/src/mongo/s/catalog/type_database.cpp +++ b/src/mongo/s/catalog/type_database.cpp @@ -35,7 +35,7 @@ #include "mongo/bson/bsonobj.h" #include "mongo/bson/bsonobjbuilder.h" #include "mongo/bson/util/bson_extract.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/util/assert_util.h" namespace mongo { @@ -78,18 +78,14 @@ StatusWith DatabaseType::fromBSON(const BSONObj& source) { return status; } - DatabaseVersion dbtVersion; - { - BSONObj versionField = source.getObjectField("version"); - if (versionField.isEmpty()) { - return Status{ErrorCodes::InternalError, - str::stream() - << "DatabaseVersion doesn't exist in database entry " << source - << " despite the config server being in binary version 4.2 " - "or later."}; - } - dbtVersion = DatabaseVersion::parse(IDLParserErrorContext("DatabaseType"), versionField); + BSONObj versionField = source.getObjectField("version"); + if (versionField.isEmpty()) { + return Status{ErrorCodes::InternalError, + str::stream() << "DatabaseVersion doesn't exist in database entry " << source + << " despite the config server being in binary version 4.2 " + "or later."}; } + DatabaseVersion dbtVersion(versionField); return DatabaseType{ std::move(dbtName), std::move(dbtPrimary), dbtSharded, std::move(dbtVersion)}; diff --git a/src/mongo/s/catalog/type_database.h b/src/mongo/s/catalog/type_database.h index 6545db38979..4eba7b1f5ca 100644 --- a/src/mongo/s/catalog/type_database.h +++ b/src/mongo/s/catalog/type_database.h @@ -34,7 +34,7 @@ #include "mongo/db/jsobj.h" #include "mongo/db/namespace_string.h" -#include "mongo/s/database_version_gen.h" +#include "mongo/s/database_version.h" #include "mongo/s/shard_id.h" namespace mongo { diff --git a/src/mongo/s/catalog_cache.cpp b/src/mongo/s/catalog_cache.cpp index 6c934317216..1bd781bb674 100644 --- a/src/mongo/s/catalog_cache.cpp +++ b/src/mongo/s/catalog_cache.cpp @@ -44,7 +44,7 @@ #include "mongo/s/catalog/type_collection.h" #include "mongo/s/catalog/type_database.h" #include "mongo/s/client/shard_registry.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/s/grid.h" #include "mongo/s/is_mongos.h" #include "mongo/s/mongod_and_mongos_server_parameters_gen.h" diff --git a/src/mongo/s/catalog_cache_refresh_test.cpp b/src/mongo/s/catalog_cache_refresh_test.cpp index 50165ab3571..3ba23ed1085 100644 --- a/src/mongo/s/catalog_cache_refresh_test.cpp +++ b/src/mongo/s/catalog_cache_refresh_test.cpp @@ -38,7 +38,7 @@ #include "mongo/s/catalog/type_database.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/catalog_cache_test_fixture.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/unittest/death_test.h" namespace mongo { @@ -59,7 +59,7 @@ protected: void expectGetDatabase() { expectFindSendBSONObjVector(kConfigHostAndPort, [&]() { - DatabaseType db(kNss.db().toString(), {"0"}, true, databaseVersion::makeNew()); + DatabaseType db(kNss.db().toString(), {"0"}, true, DatabaseVersion(UUID::gen())); return std::vector{db.toBSON()}; }()); } diff --git a/src/mongo/s/catalog_cache_test.cpp b/src/mongo/s/catalog_cache_test.cpp index a1625740f9d..73b6e65cafc 100644 --- a/src/mongo/s/catalog_cache_test.cpp +++ b/src/mongo/s/catalog_cache_test.cpp @@ -177,7 +177,7 @@ protected: TEST_F(CatalogCacheTest, GetDatabase) { const auto dbName = "testDB"; - const auto dbVersion = DatabaseVersion(UUID::gen(), 1); + const auto dbVersion = DatabaseVersion(UUID::gen()); _catalogCacheLoader->setDatabaseRefreshReturnValue( DatabaseType(dbName, kShards[0], true, dbVersion)); @@ -193,7 +193,7 @@ TEST_F(CatalogCacheTest, GetDatabase) { TEST_F(CatalogCacheTest, GetCachedDatabase) { const auto dbName = "testDB"; - const auto dbVersion = DatabaseVersion(UUID::gen(), 1); + const auto dbVersion = DatabaseVersion(UUID::gen()); loadDatabases({DatabaseType(dbName, kShards[0], true, dbVersion)}); const auto swDatabase = _catalogCache->getDatabase(operationContext(), dbName); @@ -208,7 +208,7 @@ TEST_F(CatalogCacheTest, GetCachedDatabase) { TEST_F(CatalogCacheTest, InvalidateSingleDbOnShardRemoval) { const auto dbName = "testDB"; - const auto dbVersion = DatabaseVersion(UUID::gen(), 1); + const auto dbVersion = DatabaseVersion(UUID::gen()); loadDatabases({DatabaseType(dbName, kShards[0], true, dbVersion)}); _catalogCache->invalidateEntriesThatReferenceShard(kShards[0]); @@ -223,7 +223,7 @@ TEST_F(CatalogCacheTest, InvalidateSingleDbOnShardRemoval) { TEST_F(CatalogCacheTest, OnStaleDatabaseVersionNoVersion) { // onStaleDatabaseVesrsion must invalidate the database entry if invoked with no version - const auto dbVersion = DatabaseVersion(UUID::gen(), 1); + const auto dbVersion = DatabaseVersion(UUID::gen()); loadDatabases({DatabaseType(kNss.db().toString(), kShards[0], true, dbVersion)}); _catalogCache->onStaleDatabaseVersion(kNss.db(), boost::none); @@ -233,7 +233,7 @@ TEST_F(CatalogCacheTest, OnStaleDatabaseVersionNoVersion) { } TEST_F(CatalogCacheTest, OnStaleShardVersionWithSameVersion) { - const auto dbVersion = DatabaseVersion(UUID::gen(), 1); + const auto dbVersion = DatabaseVersion(UUID::gen()); const auto cachedCollVersion = ChunkVersion(1, 0, OID::gen()); loadDatabases({DatabaseType(kNss.db().toString(), kShards[0], true, dbVersion)}); @@ -244,7 +244,7 @@ TEST_F(CatalogCacheTest, OnStaleShardVersionWithSameVersion) { } TEST_F(CatalogCacheTest, OnStaleShardVersionWithNoVersion) { - const auto dbVersion = DatabaseVersion(UUID::gen(), 1); + const auto dbVersion = DatabaseVersion(UUID::gen()); const auto cachedCollVersion = ChunkVersion(1, 0, OID::gen()); loadDatabases({DatabaseType(kNss.db().toString(), kShards[0], true, dbVersion)}); @@ -257,7 +257,7 @@ TEST_F(CatalogCacheTest, OnStaleShardVersionWithNoVersion) { } TEST_F(CatalogCacheTest, OnStaleShardVersionWithGraterVersion) { - const auto dbVersion = DatabaseVersion(UUID::gen(), 1); + const auto dbVersion = DatabaseVersion(UUID::gen()); const auto cachedCollVersion = ChunkVersion(1, 0, OID::gen()); const auto wantedCollVersion = ChunkVersion(2, 0, cachedCollVersion.epoch()); @@ -285,7 +285,7 @@ TEST_F(CatalogCacheTest, CheckEpochNoDatabase) { } TEST_F(CatalogCacheTest, CheckEpochNoCollection) { - const auto dbVersion = DatabaseVersion(UUID::gen(), 1); + const auto dbVersion = DatabaseVersion(UUID::gen()); const auto collVersion = ChunkVersion(1, 0, OID::gen()); loadDatabases({DatabaseType(kNss.db().toString(), kShards[0], true, dbVersion)}); @@ -302,7 +302,7 @@ TEST_F(CatalogCacheTest, CheckEpochNoCollection) { } TEST_F(CatalogCacheTest, CheckEpochUnshardedCollection) { - const auto dbVersion = DatabaseVersion(UUID::gen(), 1); + const auto dbVersion = DatabaseVersion(UUID::gen()); const auto collVersion = ChunkVersion(1, 0, OID::gen()); loadDatabases({DatabaseType(kNss.db().toString(), kShards[0], true, dbVersion)}); @@ -320,7 +320,7 @@ TEST_F(CatalogCacheTest, CheckEpochUnshardedCollection) { } TEST_F(CatalogCacheTest, CheckEpochWithMismatch) { - const auto dbVersion = DatabaseVersion(UUID::gen(), 1); + const auto dbVersion = DatabaseVersion(UUID::gen()); const auto wantedCollVersion = ChunkVersion(1, 0, OID::gen()); const auto receivedCollVersion = ChunkVersion(1, 0, OID::gen()); @@ -342,7 +342,7 @@ TEST_F(CatalogCacheTest, CheckEpochWithMismatch) { } TEST_F(CatalogCacheTest, CheckEpochWithMatch) { - const auto dbVersion = DatabaseVersion(UUID::gen(), 1); + const auto dbVersion = DatabaseVersion(UUID::gen()); const auto collVersion = ChunkVersion(1, 0, OID::gen()); loadDatabases({DatabaseType(kNss.db().toString(), kShards[0], true, dbVersion)}); diff --git a/src/mongo/s/catalog_cache_test_fixture.cpp b/src/mongo/s/catalog_cache_test_fixture.cpp index ebfb61f81a1..0f17e230134 100644 --- a/src/mongo/s/catalog_cache_test_fixture.cpp +++ b/src/mongo/s/catalog_cache_test_fixture.cpp @@ -44,7 +44,7 @@ #include "mongo/s/catalog/type_database.h" #include "mongo/s/catalog/type_shard.h" #include "mongo/s/catalog_cache.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/s/grid.h" #include "mongo/unittest/unittest.h" #include "mongo/util/scopeguard.h" @@ -133,7 +133,7 @@ ChunkManager CatalogCacheTestFixture::makeChunkManager( ChunkVersion version(1, 0, OID::gen()); const BSONObj databaseBSON = [&]() { - DatabaseType db(nss.db().toString(), {"0"}, true, databaseVersion::makeNew()); + DatabaseType db(nss.db().toString(), {"0"}, true, DatabaseVersion(UUID::gen())); return db.toBSON(); }(); @@ -188,7 +188,7 @@ ChunkManager CatalogCacheTestFixture::makeChunkManager( void CatalogCacheTestFixture::expectGetDatabase(NamespaceString nss, std::string shardId) { expectFindSendBSONObjVector(kConfigHostAndPort, [&]() { - DatabaseType db(nss.db().toString(), {shardId}, true, databaseVersion::makeNew()); + DatabaseType db(nss.db().toString(), {shardId}, true, DatabaseVersion(UUID::gen())); return std::vector{db.toBSON()}; }()); } diff --git a/src/mongo/s/chunk_manager.h b/src/mongo/s/chunk_manager.h index 235c18e9121..48f8d478409 100644 --- a/src/mongo/s/chunk_manager.h +++ b/src/mongo/s/chunk_manager.h @@ -39,7 +39,7 @@ #include "mongo/s/chunk.h" #include "mongo/s/chunk_version.h" #include "mongo/s/client/shard.h" -#include "mongo/s/database_version_gen.h" +#include "mongo/s/database_version.h" #include "mongo/s/resharding/type_collection_fields_gen.h" #include "mongo/s/shard_key_pattern.h" #include "mongo/stdx/unordered_map.h" diff --git a/src/mongo/s/chunk_manager_query_test.cpp b/src/mongo/s/chunk_manager_query_test.cpp index 32c886a7366..f86119f95f4 100644 --- a/src/mongo/s/chunk_manager_query_test.cpp +++ b/src/mongo/s/chunk_manager_query_test.cpp @@ -531,7 +531,7 @@ TEST_F(ChunkManagerQueryTest, SnapshotQueryWithMoreShardsThanLatestMetadata) { ChunkManager chunkManager( ShardId("0"), - DatabaseVersion(UUID::gen(), 1), + DatabaseVersion(UUID::gen()), makeStandaloneRoutingTableHistory(oldRoutingTable.makeUpdated(boost::none, true, {chunk1})), Timestamp(5, 0)); diff --git a/src/mongo/s/chunk_manager_refresh_bm.cpp b/src/mongo/s/chunk_manager_refresh_bm.cpp index 9b3c39f83c7..9b0e05dc2cd 100644 --- a/src/mongo/s/chunk_manager_refresh_bm.cpp +++ b/src/mongo/s/chunk_manager_refresh_bm.cpp @@ -82,7 +82,7 @@ CollectionMetadata makeChunkManagerWithShardSelector(int nShards, auto rt = RoutingTableHistory::makeNew( kNss, UUID::gen(), shardKeyPattern, nullptr, true, collEpoch, boost::none, true, chunks); return CollectionMetadata(ChunkManager(ShardId("Shard0"), - DatabaseVersion(UUID::gen(), 1), + DatabaseVersion(UUID::gen()), makeStandaloneRoutingTableHistory(std::move(rt)), boost::none), ShardId("shard0")); @@ -113,7 +113,7 @@ MONGO_COMPILER_NOINLINE auto runIncrementalUpdate(const CollectionMetadata& cm, auto rt = cm.getChunkManager()->getRoutingTableHistory_ForTest().makeUpdated( boost::none, true, newChunks); return CollectionMetadata(ChunkManager(ShardId("shard0"), - DatabaseVersion(UUID::gen(), 1), + DatabaseVersion(UUID::gen()), makeStandaloneRoutingTableHistory(std::move(rt)), boost::none), ShardId("shard0")); @@ -171,7 +171,7 @@ auto BM_FullBuildOfChunkManager(benchmark::State& state, ShardSelectorFn selectS chunks); benchmark::DoNotOptimize( CollectionMetadata(ChunkManager(ShardId("shard0"), - DatabaseVersion(UUID::gen(), 1), + DatabaseVersion(UUID::gen()), makeStandaloneRoutingTableHistory(std::move(rt)), boost::none), ShardId("shard0"))); diff --git a/src/mongo/s/cluster_commands_helpers.cpp b/src/mongo/s/cluster_commands_helpers.cpp index 14c008bbaa3..1b51d3c04de 100644 --- a/src/mongo/s/cluster_commands_helpers.cpp +++ b/src/mongo/s/cluster_commands_helpers.cpp @@ -51,7 +51,7 @@ #include "mongo/s/catalog/type_collection.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/client/shard_registry.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/s/grid.h" #include "mongo/s/multi_statement_transaction_requests_sender.h" #include "mongo/s/request_types/create_database_gen.h" @@ -259,7 +259,7 @@ BSONObj appendDbVersionIfPresent(BSONObj cmdObj, const CachedDatabaseInfo& dbInf } BSONObj appendDbVersionIfPresent(BSONObj cmdObj, DatabaseVersion dbVersion) { - if (databaseVersion::isFixed(dbVersion)) { + if (dbVersion.isFixed()) { return cmdObj; } BSONObjBuilder cmdWithDbVersion(std::move(cmdObj)); diff --git a/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp b/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp index e83722c71e4..d10c008f3b6 100644 --- a/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp +++ b/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp @@ -38,7 +38,7 @@ #include "mongo/logv2/log.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/cluster_commands_helpers.h" -#include "mongo/s/database_version_gen.h" +#include "mongo/s/database_version.h" #include "mongo/s/grid.h" namespace mongo { diff --git a/src/mongo/s/comparable_database_version_test.cpp b/src/mongo/s/comparable_database_version_test.cpp index d4201d56564..c1aaceb0af4 100644 --- a/src/mongo/s/comparable_database_version_test.cpp +++ b/src/mongo/s/comparable_database_version_test.cpp @@ -30,21 +30,21 @@ #include "mongo/platform/basic.h" #include "mongo/s/catalog_cache.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/unittest/unittest.h" namespace mongo { namespace { TEST(ComparableDatabaseVersionTest, VersionsEqual) { - DatabaseVersion dbVersion{UUID::gen(), 1}; + DatabaseVersion dbVersion{UUID::gen()}; const auto version = ComparableDatabaseVersion::makeComparableDatabaseVersion(dbVersion); - ASSERT(databaseVersion::equal(version.getVersion(), dbVersion)); + ASSERT(version.getVersion() == dbVersion); ASSERT(version == version); } TEST(ComparableDatabaseVersionTest, VersionsEqualAfterCopy) { - DatabaseVersion dbVersion{UUID::gen(), 1}; + DatabaseVersion dbVersion{UUID::gen()}; const auto version1 = ComparableDatabaseVersion::makeComparableDatabaseVersion(dbVersion); const auto version2 = version1; ASSERT(version1 == version2); @@ -52,31 +52,31 @@ TEST(ComparableDatabaseVersionTest, VersionsEqualAfterCopy) { TEST(ComparableDatabaseVersionTest, CompareVersionDifferentUuids) { const auto version1 = - ComparableDatabaseVersion::makeComparableDatabaseVersion(DatabaseVersion(UUID::gen(), 2)); + ComparableDatabaseVersion::makeComparableDatabaseVersion(DatabaseVersion(UUID::gen())); const auto version2 = - ComparableDatabaseVersion::makeComparableDatabaseVersion(DatabaseVersion(UUID::gen(), 1)); + ComparableDatabaseVersion::makeComparableDatabaseVersion(DatabaseVersion(UUID::gen())); ASSERT(version2 != version1); ASSERT(version2 > version1); ASSERT_FALSE(version2 < version1); } TEST(ComparableDatabaseVersionTest, VersionGreaterSameUuid) { - const auto uuid = UUID::gen(); - const auto version1 = - ComparableDatabaseVersion::makeComparableDatabaseVersion(DatabaseVersion(uuid, 1)); - const auto version2 = - ComparableDatabaseVersion::makeComparableDatabaseVersion(DatabaseVersion(uuid, 2)); + DatabaseVersion dbVersion1{UUID::gen()}; + DatabaseVersion dbVersion2 = dbVersion1.makeUpdated(); + + const auto version1 = ComparableDatabaseVersion::makeComparableDatabaseVersion(dbVersion1); + const auto version2 = ComparableDatabaseVersion::makeComparableDatabaseVersion(dbVersion2); ASSERT(version2 != version1); ASSERT(version2 > version1); ASSERT_FALSE(version2 < version1); } TEST(ComparableDatabaseVersionTest, VersionLessSameUuid) { - const auto uuid = UUID::gen(); - const auto version1 = - ComparableDatabaseVersion::makeComparableDatabaseVersion(DatabaseVersion(uuid, 1)); - const auto version2 = - ComparableDatabaseVersion::makeComparableDatabaseVersion(DatabaseVersion(uuid, 2)); + DatabaseVersion dbVersion1{UUID::gen()}; + DatabaseVersion dbVersion2 = dbVersion1.makeUpdated(); + const auto version1 = ComparableDatabaseVersion::makeComparableDatabaseVersion(dbVersion1); + const auto version2 = ComparableDatabaseVersion::makeComparableDatabaseVersion(dbVersion2); + ASSERT(version1 != version2); ASSERT(version1 < version2); ASSERT_FALSE(version1 > version2); @@ -92,7 +92,7 @@ TEST(ComparableDatabaseVersionTest, DefaultConstructedVersionsAreEqual) { TEST(ComparableDatabaseVersionTest, DefaultConstructedVersionIsAlwaysLess) { const ComparableDatabaseVersion defaultVersion{}; const auto version1 = - ComparableDatabaseVersion::makeComparableDatabaseVersion(DatabaseVersion(UUID::gen(), 0)); + ComparableDatabaseVersion::makeComparableDatabaseVersion(DatabaseVersion(UUID::gen())); ASSERT(defaultVersion != version1); ASSERT(defaultVersion < version1); ASSERT_FALSE(defaultVersion > version1); diff --git a/src/mongo/s/config_server_catalog_cache_loader.cpp b/src/mongo/s/config_server_catalog_cache_loader.cpp index 6b21e8095ed..035c5b45dad 100644 --- a/src/mongo/s/config_server_catalog_cache_loader.cpp +++ b/src/mongo/s/config_server_catalog_cache_loader.cpp @@ -38,7 +38,6 @@ #include "mongo/db/client.h" #include "mongo/db/operation_context.h" #include "mongo/s/catalog/sharding_catalog_client.h" -#include "mongo/s/database_version_helpers.h" #include "mongo/s/grid.h" #include "mongo/util/fail_point.h" diff --git a/src/mongo/s/database_version.cpp b/src/mongo/s/database_version.cpp new file mode 100644 index 00000000000..53da1268f97 --- /dev/null +++ b/src/mongo/s/database_version.cpp @@ -0,0 +1,48 @@ +/** + * Copyright (C) 2018-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/s/database_version.h" + +namespace mongo { + +DatabaseVersion DatabaseVersion::makeFixed() { + DatabaseVersion dbVersion; + dbVersion.setLastMod(0); + dbVersion.setUuid(UUID::gen()); + return dbVersion; +} +DatabaseVersion DatabaseVersion::makeUpdated() const { + DatabaseVersion newVersion = *this; + newVersion.setLastMod(newVersion.getLastMod() + 1); + return newVersion; +} + +} // namespace mongo diff --git a/src/mongo/s/database_version.h b/src/mongo/s/database_version.h new file mode 100644 index 00000000000..f015bdff692 --- /dev/null +++ b/src/mongo/s/database_version.h @@ -0,0 +1,75 @@ +/** + * Copyright (C) 2018-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +#include "mongo/s/database_version_gen.h" + +namespace mongo { + +class DatabaseVersion : private DatabaseVersionBase { +public: + using DatabaseVersionBase::getLastMod; + using DatabaseVersionBase::toBSON; + + // It returns a new DatabaseVersion marked as fixed. A fixed database version is used to + // distinguish databases that do not have entries in the sharding catalog, such as 'config' and + // 'admin' + static DatabaseVersion makeFixed(); + + DatabaseVersion() = default; + + explicit DatabaseVersion(const BSONObj& obj) { + DatabaseVersionBase::parseProtected(IDLParserErrorContext("DatabaseVersion"), obj); + } + + explicit DatabaseVersion(mongo::UUID uuid) : DatabaseVersionBase(/* lastMod */ 1) { + setUuid(uuid); + } + + DatabaseVersion makeUpdated() const; + + bool operator==(const DatabaseVersion& other) const { + return getUuid() == other.getUuid() && getLastMod() == other.getLastMod(); + } + + bool operator!=(const DatabaseVersion& other) const { + return !(*this == other); + } + + bool isFixed() const { + return getLastMod() == 0; + } + + mongo::UUID getUuid() const { + return *DatabaseVersionBase::getUuid(); + } +}; + +} // namespace mongo diff --git a/src/mongo/s/database_version.idl b/src/mongo/s/database_version.idl index 8c5776f1ffe..f2401e77639 100644 --- a/src/mongo/s/database_version.idl +++ b/src/mongo/s/database_version.idl @@ -26,8 +26,6 @@ # it in the license file. # -# DatabaseVersion type - global: cpp_namespace: "mongo" @@ -35,7 +33,7 @@ imports: - "mongo/idl/basic_types.idl" structs: - DatabaseVersion: + DatabaseVersionBase: description: "A (UUID, int) pair that uniquely identifies an incarnation of a database in a cluster and reflects changes to the database's primary shard" # The generated comparison operators will do a field-wise lexicographic comparison, which # doesn't work because it's nonsensical to lexicographically compare UUIDs. @@ -45,6 +43,7 @@ structs: uuid: type: uuid description: "a unique identifier to distinguish different incarnations of this database" + optional: true lastMod: type: int description: "an integer which is bumped whenever the database's primary shard changes" diff --git a/src/mongo/s/database_version_helpers.cpp b/src/mongo/s/database_version_helpers.cpp deleted file mode 100644 index 4550ae446bb..00000000000 --- a/src/mongo/s/database_version_helpers.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/platform/basic.h" - -#include "mongo/s/database_version_helpers.h" - -namespace mongo { -namespace databaseVersion { - -DatabaseVersion makeNew() { - DatabaseVersion dbv; - dbv.setLastMod(1); - dbv.setUuid(UUID::gen()); - return dbv; -} - -DatabaseVersion makeIncremented(const DatabaseVersion& v) { - DatabaseVersion dbv; - dbv.setLastMod(v.getLastMod() + 1); - dbv.setUuid(v.getUuid()); - return dbv; -} - -DatabaseVersion makeFixed() { - DatabaseVersion dbv; - dbv.setLastMod(0); - dbv.setUuid(UUID::gen()); - return dbv; -} - -bool equal(const DatabaseVersion& dbv1, const DatabaseVersion& dbv2) { - return dbv1.getUuid() == dbv2.getUuid() && dbv1.getLastMod() == dbv2.getLastMod(); -} - -bool isFixed(const DatabaseVersion& dbv) { - return dbv.getLastMod() == 0; -} - -} // namespace databaseVersion -} // namespace mongo diff --git a/src/mongo/s/database_version_helpers.h b/src/mongo/s/database_version_helpers.h deleted file mode 100644 index 04607113847..00000000000 --- a/src/mongo/s/database_version_helpers.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -#include "mongo/s/database_version_gen.h" - -namespace mongo { -namespace databaseVersion { - -DatabaseVersion makeNew(); -DatabaseVersion makeIncremented(const DatabaseVersion& v); -/** - * makeFixed is only for databases that do not have entries in the sharding catalog, such as - * "config" and "admin". - */ -DatabaseVersion makeFixed(); -bool equal(const DatabaseVersion& dbv1, const DatabaseVersion& dbv2); -bool isFixed(const DatabaseVersion& dbv); - -} // namespace databaseVersion -} // namespace mongo diff --git a/src/mongo/s/stale_exception.cpp b/src/mongo/s/stale_exception.cpp index f68d7ee8d01..f1f5ccc9c03 100644 --- a/src/mongo/s/stale_exception.cpp +++ b/src/mongo/s/stale_exception.cpp @@ -33,6 +33,7 @@ #include "mongo/base/init.h" #include "mongo/util/assert_util.h" + namespace mongo { namespace { @@ -54,14 +55,10 @@ std::shared_ptr StaleDbRoutingVersion::parse(const BSONObj } StaleDbRoutingVersion StaleDbRoutingVersion::parseFromCommandError(const BSONObj& obj) { - return StaleDbRoutingVersion( - obj["db"].String(), - DatabaseVersion::parse(IDLParserErrorContext("StaleDbRoutingVersion-vReceived"), - obj["vReceived"].Obj()), - !obj["vWanted"].eoo() - ? DatabaseVersion::parse(IDLParserErrorContext("StaleDbRoutingVersion-vWanted"), - obj["vWanted"].Obj()) - : boost::optional{}); + return StaleDbRoutingVersion(obj["db"].String(), + DatabaseVersion(obj["vReceived"].Obj()), + !obj["vWanted"].eoo() ? DatabaseVersion(obj["vWanted"].Obj()) + : boost::optional{}); } } // namespace mongo diff --git a/src/mongo/s/stale_exception.h b/src/mongo/s/stale_exception.h index 7beb228b9eb..4a54666a4f1 100644 --- a/src/mongo/s/stale_exception.h +++ b/src/mongo/s/stale_exception.h @@ -31,7 +31,7 @@ #include "mongo/db/namespace_string.h" #include "mongo/s/chunk_version.h" -#include "mongo/s/database_version_gen.h" +#include "mongo/s/database_version.h" #include "mongo/s/shard_id.h" #include "mongo/util/concurrency/notification.h" diff --git a/src/mongo/s/write_ops/batch_write_exec_test.cpp b/src/mongo/s/write_ops/batch_write_exec_test.cpp index 61745ac4d64..447f82658b7 100644 --- a/src/mongo/s/write_ops/batch_write_exec_test.cpp +++ b/src/mongo/s/write_ops/batch_write_exec_test.cpp @@ -138,10 +138,10 @@ BSONObj expectInsertsReturnStaleDbVersionErrorsBase(const NamespaceString& nss, errorBuilder.append("index", i); errorBuilder.append("code", int(ErrorCodes::StaleDbVersion)); - auto dbVersion = databaseVersion::makeNew(); + auto dbVersion = DatabaseVersion(UUID::gen()); errorBuilder.append("db", nss.db()); errorBuilder.append("vReceived", dbVersion.toBSON()); - errorBuilder.append("vWanted", databaseVersion::makeIncremented(dbVersion).toBSON()); + errorBuilder.append("vWanted", dbVersion.makeUpdated().toBSON()); errorBuilder.append("errmsg", "mock stale db version"); diff --git a/src/mongo/s/write_ops/batched_command_request.cpp b/src/mongo/s/write_ops/batched_command_request.cpp index f4156cb8f4a..e0af154aa30 100644 --- a/src/mongo/s/write_ops/batched_command_request.cpp +++ b/src/mongo/s/write_ops/batched_command_request.cpp @@ -48,9 +48,7 @@ BatchedCommandRequest constructBatchedCommandRequest(const OpMsgRequest& request auto chunkVersion = ChunkVersion::parseFromCommand(request.body); if (chunkVersion != ErrorCodes::NoSuchKey) { if (chunkVersion == ChunkVersion::UNSHARDED()) { - auto dbVersion = DatabaseVersion::parse(IDLParserErrorContext("BatchedCommandRequest"), - request.body); - batchRequest.setDbVersion(std::move(dbVersion)); + batchRequest.setDbVersion(DatabaseVersion(request.body)); } batchRequest.setShardVersion(uassertStatusOK(std::move(chunkVersion))); } diff --git a/src/mongo/s/write_ops/batched_command_request.h b/src/mongo/s/write_ops/batched_command_request.h index 041a059fdda..620b71080d5 100644 --- a/src/mongo/s/write_ops/batched_command_request.h +++ b/src/mongo/s/write_ops/batched_command_request.h @@ -35,7 +35,7 @@ #include "mongo/db/ops/write_ops.h" #include "mongo/rpc/op_msg.h" #include "mongo/s/chunk_version.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/util/visit_helper.h" namespace mongo { diff --git a/src/mongo/s/write_ops/chunk_manager_targeter.cpp b/src/mongo/s/write_ops/chunk_manager_targeter.cpp index ea54832e63c..1189ef0636d 100644 --- a/src/mongo/s/write_ops/chunk_manager_targeter.cpp +++ b/src/mongo/s/write_ops/chunk_manager_targeter.cpp @@ -45,7 +45,7 @@ #include "mongo/logv2/log.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/cluster_commands_helpers.h" -#include "mongo/s/database_version_helpers.h" +#include "mongo/s/database_version.h" #include "mongo/s/grid.h" #include "mongo/s/shard_key_pattern.h" #include "mongo/s/write_ops/chunk_manager_targeter.h" @@ -331,7 +331,7 @@ bool isMetadataDifferent(const ChunkManager& managerA, return managerA.getVersion() != managerB.getVersion(); } - return !databaseVersion::equal(dbVersionA, dbVersionB); + return dbVersionA != dbVersionB; } } // namespace @@ -629,8 +629,7 @@ void ChunkManagerTargeter::noteStaleDbResponse(const ShardEndpoint& endpoint, DatabaseVersion remoteDbVersion; if (!staleInfo.getVersionWanted()) { // If the vWanted is not set, assume the wanted version is higher than our current version. - remoteDbVersion = _cm->dbVersion(); - remoteDbVersion = databaseVersion::makeIncremented(remoteDbVersion); + remoteDbVersion = _cm->dbVersion().makeUpdated(); } else { remoteDbVersion = *staleInfo.getVersionWanted(); } @@ -646,7 +645,7 @@ void ChunkManagerTargeter::noteStaleDbResponse(const ShardEndpoint& endpoint, uassert( ErrorCodes::InternalError, "Did not expect to get multiple StaleDbVersion errors with different vWanted versions", - databaseVersion::equal(*_remoteDbVersion, remoteDbVersion)); + *_remoteDbVersion == remoteDbVersion); return; } _remoteDbVersion = remoteDbVersion; -- cgit v1.2.1