diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-14 14:26:38 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-14 14:26:38 -0300 |
| commit | 294bc6ecabf14c09c9bc8644704921dcf97cb44e (patch) | |
| tree | 279b1e0bab53901a1647ac63c1c724f0f789a663 /src/mongo/db/s/flush_database_cache_updates_command.cpp | |
| parent | 70be7c27a251621187a1de533462ae2bb1e3bd39 (diff) | |
| parent | 1e917fd798aa25b7066d4b414b51184f13d5a092 (diff) | |
Update upstream source from tag 'upstream/6.0.10'debian/6.0.10-1
Update to upstream version '6.0.10'
with Debian dir 2d176fa254eee97b139f712fec5709641335a8c3
Diffstat (limited to 'src/mongo/db/s/flush_database_cache_updates_command.cpp')
| -rw-r--r-- | src/mongo/db/s/flush_database_cache_updates_command.cpp | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/src/mongo/db/s/flush_database_cache_updates_command.cpp b/src/mongo/db/s/flush_database_cache_updates_command.cpp index de95a293333..729572272f6 100644 --- a/src/mongo/db/s/flush_database_cache_updates_command.cpp +++ b/src/mongo/db/s/flush_database_cache_updates_command.cpp @@ -38,6 +38,7 @@ #include "mongo/db/catalog_raii.h" #include "mongo/db/client.h" #include "mongo/db/commands.h" +#include "mongo/db/dbdirectclient.h" #include "mongo/db/operation_context.h" #include "mongo/db/repl/repl_client_info.h" #include "mongo/db/s/database_sharding_state.h" @@ -52,6 +53,29 @@ namespace mongo { namespace { +/** + * Inserts a database collection entry with fixed metadata for the `config` or `admin` database. If + * the entry key already exists, it's not updated. + */ +Status insertDatabaseEntryForBackwardCompatibility(OperationContext* opCtx, + const StringData& dbName) { + invariant(dbName == NamespaceString::kAdminDb || dbName == NamespaceString::kConfigDb); + + DBDirectClient client(opCtx); + auto commandResponse = client.runCommand([&] { + auto dbMetadata = + DatabaseType(dbName.toString(), ShardId::kConfigServerId, DatabaseVersion::makeFixed()); + dbMetadata.setSharded(true); + + write_ops::InsertCommandRequest insertOp(NamespaceString::kShardConfigDatabasesNamespace); + insertOp.setDocuments({dbMetadata.toBSON()}); + return insertOp.serialize({}); + }()); + + auto commandStatus = getStatusFromWriteCommandReply(commandResponse->getCommandReply()); + return commandStatus.code() == ErrorCodes::DuplicateKey ? Status::OK() : commandStatus; +} + template <typename Derived> class FlushDatabaseCacheUpdatesCmdBase : public TypedCommand<Derived> { public: @@ -117,6 +141,26 @@ public: "Can't call _flushDatabaseCacheUpdates if in read-only mode", !storageGlobalParams.readOnly); + if (_dbName() == NamespaceString::kAdminDb || _dbName() == NamespaceString::kConfigDb) { + // The admin and config databases have fixed metadata that does not need to be + // refreshed. + + if (Base::request().getSyncFromConfig()) { + // To ensure compatibility with old secondaries that still call the + // _flushDatabaseCacheUpdates command to get updated database metadata from + // primary, an entry with fixed metadata is inserted in the + // config.cache.databases collection. + + LOGV2_DEBUG(6910800, + 1, + "Inserting a database collection entry with fixed metadata", + "db"_attr = _dbName()); + uassertStatusOK(insertDatabaseEntryForBackwardCompatibility(opCtx, _dbName())); + } + + return; + } + boost::optional<SharedSemiFuture<void>> criticalSectionSignal; { @@ -129,8 +173,8 @@ public: // consistency guarantee. const auto dss = DatabaseShardingState::get(opCtx, _dbName()); auto dssLock = DatabaseShardingState::DSSLock::lockShared(opCtx, dss); - criticalSectionSignal = - dss->getCriticalSectionSignal(ShardingMigrationCriticalSection::kRead, dssLock); + criticalSectionSignal = dss->getCriticalSectionSignal( + ShardingMigrationCriticalSection::kWrite, dssLock); } if (criticalSectionSignal) |
