summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjannaerin <golden.janna@gmail.com>2023-02-10 17:44:01 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-02-11 00:22:04 +0000
commit6cb8d854a72cd36a93b7c10f82866275efb19434 (patch)
tree34da2ecc6fcb46ec9af0d50add15ed1b14d38341 /src
parenta69b0dfd32483e7dd092dbefe6d8034f28779aad (diff)
downloadmongo-6cb8d854a72cd36a93b7c10f82866275efb19434.tar.gz
SERVER-73880 Make DatabaseName constants
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/SConscript1
-rw-r--r--src/mongo/db/database_name.h77
-rw-r--r--src/mongo/db/database_name_reserved.def.h (renamed from src/mongo/db/database_name.cpp)24
-rw-r--r--src/mongo/db/namespace_string.h6
-rw-r--r--src/mongo/db/namespace_string_reserved.def.h126
-rw-r--r--src/mongo/db/repl/hello_auth.cpp2
-rw-r--r--src/mongo/db/tenant_id.cpp5
-rw-r--r--src/mongo/db/tenant_id.h12
8 files changed, 155 insertions, 98 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index 446611ce0d1..fec966a8bb5 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -63,7 +63,6 @@ env.Library(
'basic_types.idl',
'catalog_shard_feature_flag.idl',
'cluster_role.cpp',
- 'database_name.cpp',
'feature_compatibility_version_document.idl',
'feature_compatibility_version_parser.cpp',
'feature_flag.cpp',
diff --git a/src/mongo/db/database_name.h b/src/mongo/db/database_name.h
index 7be2276c7cb..39d16b5238c 100644
--- a/src/mongo/db/database_name.h
+++ b/src/mongo/db/database_name.h
@@ -36,6 +36,7 @@
#include "mongo/base/string_data.h"
#include "mongo/db/tenant_id.h"
#include "mongo/logv2/log_attr.h"
+#include "mongo/util/static_immortal.h"
namespace mongo {
@@ -47,6 +48,65 @@ namespace mongo {
class DatabaseName {
public:
/**
+ * Used to create `constexpr` reserved DatabaseName constants. See
+ * NamespaceString::ConstantProxy in namespace_string.h for more details.
+ */
+ class ConstantProxy {
+ public:
+ class SharedState {
+ public:
+ explicit constexpr SharedState(StringData db) : _db{db} {}
+
+ const DatabaseName& get() const {
+ std::call_once(_once, [this] {
+ _dbName = new DatabaseName{TenantId::systemTenantId(), _db};
+ });
+ return *_dbName;
+ }
+
+ private:
+ StringData _db;
+ mutable std::once_flag _once;
+ mutable const DatabaseName* _dbName = nullptr;
+ };
+
+ constexpr explicit ConstantProxy(const SharedState* sharedState)
+ : _sharedState{sharedState} {}
+
+ operator const DatabaseName&() const {
+ return _get();
+ }
+
+ decltype(auto) db() const {
+ return _get().db();
+ }
+ decltype(auto) tenantId() const {
+ return _get().tenantId();
+ }
+ decltype(auto) toString() const {
+ return _get().toString();
+ }
+
+ friend std::ostream& operator<<(std::ostream& stream, const ConstantProxy& dbName) {
+ return stream << dbName.toString();
+ }
+ friend StringBuilder& operator<<(StringBuilder& builder, const ConstantProxy& dbName) {
+ return builder << dbName.toString();
+ }
+
+ private:
+ const DatabaseName& _get() const {
+ return _sharedState->get();
+ }
+
+ const SharedState* _sharedState;
+ };
+
+#define DBNAME_CONSTANT(id, db) static const ConstantProxy id;
+#include "database_name_reserved.def.h"
+#undef DBNAME_CONSTANT
+
+ /**
* Constructs an empty DatabaseName.
*/
DatabaseName() = default;
@@ -74,8 +134,6 @@ public:
DatabaseName(StringData dbName, boost::optional<TenantId> tenantId = boost::none)
: DatabaseName(std::move(tenantId), dbName) {}
- static DatabaseName createSystemTenantDbName(StringData dbString);
-
const boost::optional<TenantId>& tenantId() const {
return _tenantId;
}
@@ -154,4 +212,19 @@ inline bool operator>=(const DatabaseName& lhs, const DatabaseName& rhs) {
return !(lhs < rhs);
}
+// The `constexpr` definitions for `DatabaseName::ConstantProxy` static data members are below. See
+// `constexpr` definitions for the `NamespaceString::ConstantProxy` static data members of NSS in
+// namespace_string.h for more details.
+namespace dbname_detail::const_proxy_shared_states {
+#define DBNAME_CONSTANT(id, db) constexpr inline DatabaseName::ConstantProxy::SharedState id{db};
+#include "database_name_reserved.def.h"
+#undef DBNAME_CONSTANT
+} // namespace dbname_detail::const_proxy_shared_states
+
+#define DBNAME_CONSTANT(id, db) \
+ constexpr inline DatabaseName::ConstantProxy DatabaseName::id{ \
+ &dbname_detail::const_proxy_shared_states::id};
+#include "database_name_reserved.def.h"
+#undef DBNAME_CONSTANT
+
} // namespace mongo
diff --git a/src/mongo/db/database_name.cpp b/src/mongo/db/database_name_reserved.def.h
index dd1cc4869ad..05eee932444 100644
--- a/src/mongo/db/database_name.cpp
+++ b/src/mongo/db/database_name_reserved.def.h
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2022-present MongoDB, Inc.
+ * Copyright (C) 2023-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,
@@ -27,13 +27,21 @@
* it in the license file.
*/
-#include "mongo/db/database_name.h"
+/**
+ * This file is included multiple times into `database_name.h`, in order to
+ * define DatabaseName constexpr values. The `DBNAME_CONSTANT` macro callback
+ * will be defined differently at each include. Lines here are of the form:
+ *
+ * DBNAME_CONSTANT(id, db)
+ *
+ * - `id` is the `ConstantProxy` data member of `DatabaseName` being defined.
+ * - `db` : must be a constexpr StringData expression.
+ */
+
+DBNAME_CONSTANT(kAdmin, "admin"_sd)
-namespace mongo {
+DBNAME_CONSTANT(kLocal, "local"_sd)
-DatabaseName DatabaseName::createSystemTenantDbName(StringData dbString) {
- // TODO SERVER-62491 Use kSystemTenantId
- return DatabaseName(boost::none, dbString);
-}
+DBNAME_CONSTANT(kConfig, "config"_sd)
-} // namespace mongo
+DBNAME_CONSTANT(kEmpty, ""_sd)
diff --git a/src/mongo/db/namespace_string.h b/src/mongo/db/namespace_string.h
index c815564e27e..6b90b1aa1a4 100644
--- a/src/mongo/db/namespace_string.h
+++ b/src/mongo/db/namespace_string.h
@@ -69,14 +69,16 @@ public:
*/
class SharedState {
public:
- constexpr SharedState(StringData db, StringData coll) : _db{db}, _coll{coll} {}
+ constexpr SharedState(DatabaseName::ConstantProxy dbName, StringData coll)
+ : _db{dbName}, _coll{coll} {}
const NamespaceString& get() const {
std::call_once(_once, [this] { _nss = new NamespaceString{_db, _coll}; });
return *_nss;
}
- StringData _db;
+ private:
+ DatabaseName::ConstantProxy _db;
StringData _coll;
mutable std::once_flag _once;
mutable const NamespaceString* _nss = nullptr;
diff --git a/src/mongo/db/namespace_string_reserved.def.h b/src/mongo/db/namespace_string_reserved.def.h
index 20e39384ee3..11705b8c415 100644
--- a/src/mongo/db/namespace_string_reserved.def.h
+++ b/src/mongo/db/namespace_string_reserved.def.h
@@ -35,7 +35,7 @@
* NSS_CONSTANT(id, db, coll)
*
* - `id` is the `ConstantProxy` data member of `NamespaceString` being defined.
- * - `db` : must be a constexpr StringData expression.
+ * - `db` : must be a constexpr DatabaseName::ConstantProxy expression.
* - `coll` must be a constexpr StringData expression.
*/
@@ -44,214 +44,198 @@
// state of the server, which needs to be recovered/consulted at startup. Each document in this
// namespace should have its _id set to some string, which meaningfully describes what it
// represents. For example, 'shardIdentity' and 'featureCompatibilityVersion'.
-NSS_CONSTANT(kServerConfigurationNamespace, NamespaceString::kAdminDb, "system.version"_sd)
+NSS_CONSTANT(kServerConfigurationNamespace, DatabaseName::kAdmin, "system.version"_sd)
// Namespace for storing the logical sessions information
-NSS_CONSTANT(kLogicalSessionsNamespace, NamespaceString::kConfigDb, "system.sessions"_sd)
+NSS_CONSTANT(kLogicalSessionsNamespace, DatabaseName::kConfig, "system.sessions"_sd)
// Namespace for storing databases information
-NSS_CONSTANT(kConfigDatabasesNamespace, NamespaceString::kConfigDb, "databases"_sd)
+NSS_CONSTANT(kConfigDatabasesNamespace, DatabaseName::kConfig, "databases"_sd)
// Namespace for storing the transaction information for each session
-NSS_CONSTANT(kSessionTransactionsTableNamespace, NamespaceString::kConfigDb, "transactions"_sd)
+NSS_CONSTANT(kSessionTransactionsTableNamespace, DatabaseName::kConfig, "transactions"_sd)
// Name for a shard's collections metadata collection, each document of which indicates the
// state of a specific collection
-NSS_CONSTANT(kShardConfigCollectionsNamespace, NamespaceString::kConfigDb, "cache.collections"_sd)
+NSS_CONSTANT(kShardConfigCollectionsNamespace, DatabaseName::kConfig, "cache.collections"_sd)
// Name for a shard's databases metadata collection, each document of which indicates the state
// of a specific database
-NSS_CONSTANT(kShardConfigDatabasesNamespace, NamespaceString::kConfigDb, "cache.databases"_sd)
+NSS_CONSTANT(kShardConfigDatabasesNamespace, DatabaseName::kConfig, "cache.databases"_sd)
// Namespace for storing keys for signing and validating cluster times created by the cluster
// that this node is in.
-NSS_CONSTANT(kKeysCollectionNamespace, NamespaceString::kAdminDb, "system.keys"_sd)
+NSS_CONSTANT(kKeysCollectionNamespace, DatabaseName::kAdmin, "system.keys"_sd)
// Namespace for storing keys for validating cluster times created by other clusters.
-NSS_CONSTANT(kExternalKeysCollectionNamespace,
- NamespaceString::kConfigDb,
- "external_validation_keys"_sd)
+NSS_CONSTANT(kExternalKeysCollectionNamespace, DatabaseName::kConfig, "external_validation_keys"_sd)
// Namespace of the the oplog collection.
-NSS_CONSTANT(kRsOplogNamespace, NamespaceString::kLocalDb, "oplog.rs"_sd)
+NSS_CONSTANT(kRsOplogNamespace, DatabaseName::kLocal, "oplog.rs"_sd)
// Namespace for storing the persisted state of transaction coordinators.
NSS_CONSTANT(kTransactionCoordinatorsNamespace,
- NamespaceString::kConfigDb,
+ DatabaseName::kConfig,
"transaction_coordinators"_sd)
// Namespace for storing the persisted state of migration coordinators.
-NSS_CONSTANT(kMigrationCoordinatorsNamespace,
- NamespaceString::kConfigDb,
- "migrationCoordinators"_sd)
+NSS_CONSTANT(kMigrationCoordinatorsNamespace, DatabaseName::kConfig, "migrationCoordinators"_sd)
// Namespace for storing the persisted state of migration recipients.
-NSS_CONSTANT(kMigrationRecipientsNamespace, NamespaceString::kConfigDb, "migrationRecipients"_sd)
+NSS_CONSTANT(kMigrationRecipientsNamespace, DatabaseName::kConfig, "migrationRecipients"_sd)
// Namespace for storing the persisted state of movePrimary operation recipients.
-NSS_CONSTANT(kMovePrimaryRecipientNamespace, NamespaceString::kConfigDb, "movePrimaryRecipients"_sd)
+NSS_CONSTANT(kMovePrimaryRecipientNamespace, DatabaseName::kConfig, "movePrimaryRecipients"_sd)
// Namespace for storing the persisted state of tenant migration donors.
-NSS_CONSTANT(kTenantMigrationDonorsNamespace,
- NamespaceString::kConfigDb,
- "tenantMigrationDonors"_sd)
+NSS_CONSTANT(kTenantMigrationDonorsNamespace, DatabaseName::kConfig, "tenantMigrationDonors"_sd)
// Namespace for storing the persisted state of tenant migration recipient service instances.
NSS_CONSTANT(kTenantMigrationRecipientsNamespace,
- NamespaceString::kConfigDb,
+ DatabaseName::kConfig,
"tenantMigrationRecipients"_sd)
// Namespace for view on local.oplog.rs for tenant migrations.
-NSS_CONSTANT(kTenantMigrationOplogView,
- NamespaceString::kLocalDb,
- "system.tenantMigration.oplogView"_sd)
+NSS_CONSTANT(kTenantMigrationOplogView, DatabaseName::kLocal, "system.tenantMigration.oplogView"_sd)
// Namespace for storing the persisted state of tenant split donors.
-NSS_CONSTANT(kShardSplitDonorsNamespace, NamespaceString::kConfigDb, "shardSplitDonors"_sd)
+NSS_CONSTANT(kShardSplitDonorsNamespace, DatabaseName::kConfig, "shardSplitDonors"_sd)
// Namespace for replica set configuration settings.
-NSS_CONSTANT(kSystemReplSetNamespace, NamespaceString::kLocalDb, "system.replset"_sd)
+NSS_CONSTANT(kSystemReplSetNamespace, DatabaseName::kLocal, "system.replset"_sd)
// Namespace for storing the last replica set election vote.
-NSS_CONSTANT(kLastVoteNamespace, NamespaceString::kLocalDb, "replset.election"_sd)
+NSS_CONSTANT(kLastVoteNamespace, DatabaseName::kLocal, "replset.election"_sd)
// Namespace for index build entries.
-NSS_CONSTANT(kIndexBuildEntryNamespace, NamespaceString::kConfigDb, "system.indexBuilds"_sd)
+NSS_CONSTANT(kIndexBuildEntryNamespace, DatabaseName::kConfig, "system.indexBuilds"_sd)
// Namespace for pending range deletions.
-NSS_CONSTANT(kRangeDeletionNamespace, NamespaceString::kConfigDb, "rangeDeletions"_sd)
+NSS_CONSTANT(kRangeDeletionNamespace, DatabaseName::kConfig, "rangeDeletions"_sd)
// Namespace containing pending range deletions snapshots for rename operations.
-NSS_CONSTANT(kRangeDeletionForRenameNamespace,
- NamespaceString::kConfigDb,
- "rangeDeletionsForRename"_sd)
+NSS_CONSTANT(kRangeDeletionForRenameNamespace, DatabaseName::kConfig, "rangeDeletionsForRename"_sd)
// Namespace for the coordinator's resharding operation state.
-NSS_CONSTANT(kConfigReshardingOperationsNamespace,
- NamespaceString::kConfigDb,
- "reshardingOperations"_sd)
+NSS_CONSTANT(kConfigReshardingOperationsNamespace, DatabaseName::kConfig, "reshardingOperations"_sd)
// Namespace for the donor shard's local resharding operation state.
NSS_CONSTANT(kDonorReshardingOperationsNamespace,
- NamespaceString::kConfigDb,
+ DatabaseName::kConfig,
"localReshardingOperations.donor"_sd)
// Namespace for the recipient shard's local resharding operation state.
NSS_CONSTANT(kRecipientReshardingOperationsNamespace,
- NamespaceString::kConfigDb,
+ DatabaseName::kConfig,
"localReshardingOperations.recipient"_sd)
// Namespace for persisting sharding DDL coordinators state documents
NSS_CONSTANT(kShardingDDLCoordinatorsNamespace,
- NamespaceString::kConfigDb,
+ DatabaseName::kConfig,
"system.sharding_ddl_coordinators"_sd)
// Namespace for persisting sharding DDL rename participant state documents
NSS_CONSTANT(kShardingRenameParticipantsNamespace,
- NamespaceString::kConfigDb,
+ DatabaseName::kConfig,
"localRenameParticipants"_sd)
// Namespace for balancer settings and default read and write concerns.
-NSS_CONSTANT(kConfigSettingsNamespace, NamespaceString::kConfigDb, "settings"_sd)
+NSS_CONSTANT(kConfigSettingsNamespace, DatabaseName::kConfig, "settings"_sd)
// Namespace for vector clock state.
-NSS_CONSTANT(kVectorClockNamespace, NamespaceString::kConfigDb, "vectorClock"_sd)
+NSS_CONSTANT(kVectorClockNamespace, DatabaseName::kConfig, "vectorClock"_sd)
// Namespace for storing oplog applier progress for resharding.
NSS_CONSTANT(kReshardingApplierProgressNamespace,
- NamespaceString::kConfigDb,
+ DatabaseName::kConfig,
"localReshardingOperations.recipient.progress_applier"_sd)
// Namespace for storing config.transactions cloner progress for resharding.
NSS_CONSTANT(kReshardingTxnClonerProgressNamespace,
- NamespaceString::kConfigDb,
+ DatabaseName::kConfig,
"localReshardingOperations.recipient.progress_txn_cloner"_sd)
// Namespace for storing config.collectionCriticalSections documents
NSS_CONSTANT(kCollectionCriticalSectionsNamespace,
- NamespaceString::kConfigDb,
+ DatabaseName::kConfig,
"collection_critical_sections"_sd)
// Dummy namespace used for forcing secondaries to handle an oplog entry on its own batch.
NSS_CONSTANT(kForceOplogBatchBoundaryNamespace,
- NamespaceString::kConfigDb,
+ DatabaseName::kConfig,
"system.forceOplogBatchBoundary"_sd)
// Namespace used for storing retryable findAndModify images.
-NSS_CONSTANT(kConfigImagesNamespace, NamespaceString::kConfigDb, "image_collection"_sd)
+NSS_CONSTANT(kConfigImagesNamespace, DatabaseName::kConfig, "image_collection"_sd)
// Namespace used for persisting ConfigsvrCoordinator state documents.
NSS_CONSTANT(kConfigsvrCoordinatorsNamespace,
- NamespaceString::kConfigDb,
+ DatabaseName::kConfig,
"sharding_configsvr_coordinators"_sd)
// Namespace for storing user write blocking critical section documents
NSS_CONSTANT(kUserWritesCriticalSectionsNamespace,
- NamespaceString::kConfigDb,
+ DatabaseName::kConfig,
"user_writes_critical_sections"_sd)
// Namespace used during the recovery procedure for the config server.
-NSS_CONSTANT(kConfigsvrRestoreNamespace,
- NamespaceString::kLocalDb,
- "system.collections_to_restore"_sd)
+NSS_CONSTANT(kConfigsvrRestoreNamespace, DatabaseName::kLocal, "system.collections_to_restore"_sd)
// Namespace used for CompactParticipantCoordinator service.
NSS_CONSTANT(kCompactStructuredEncryptionCoordinatorNamespace,
- NamespaceString::kConfigDb,
+ DatabaseName::kConfig,
"compact_structured_encryption_coordinator"_sd)
// Namespace used for storing cluster wide parameters on dedicated configurations.
-NSS_CONSTANT(kClusterParametersNamespace, NamespaceString::kConfigDb, "clusterParameters"_sd)
+NSS_CONSTANT(kClusterParametersNamespace, DatabaseName::kConfig, "clusterParameters"_sd)
// Namespace used for storing the list of shards on the CSRS.
-NSS_CONSTANT(kConfigsvrShardsNamespace, NamespaceString::kConfigDb, "shards"_sd)
+NSS_CONSTANT(kConfigsvrShardsNamespace, DatabaseName::kConfig, "shards"_sd)
// Namespace used for storing the list of sharded collections on the CSRS.
-NSS_CONSTANT(kConfigsvrCollectionsNamespace, NamespaceString::kConfigDb, "collections"_sd)
+NSS_CONSTANT(kConfigsvrCollectionsNamespace, DatabaseName::kConfig, "collections"_sd)
// Namespace used for storing the index catalog on the CSRS.
-NSS_CONSTANT(kConfigsvrIndexCatalogNamespace, NamespaceString::kConfigDb, "csrs.indexes"_sd)
+NSS_CONSTANT(kConfigsvrIndexCatalogNamespace, DatabaseName::kConfig, "csrs.indexes"_sd)
// Namespace used for storing the index catalog on the shards.
-NSS_CONSTANT(kShardIndexCatalogNamespace, NamespaceString::kConfigDb, "shard.indexes"_sd)
+NSS_CONSTANT(kShardIndexCatalogNamespace, DatabaseName::kConfig, "shard.indexes"_sd)
// Namespace used for storing the collection catalog on the shards.
-NSS_CONSTANT(kShardCollectionCatalogNamespace, NamespaceString::kConfigDb, "shard.collections"_sd)
+NSS_CONSTANT(kShardCollectionCatalogNamespace, DatabaseName::kConfig, "shard.collections"_sd)
// Namespace used for storing NamespacePlacementType docs on the CSRS.
-NSS_CONSTANT(kConfigsvrPlacementHistoryNamespace, NamespaceString::kConfigDb, "placementHistory"_sd)
+NSS_CONSTANT(kConfigsvrPlacementHistoryNamespace, DatabaseName::kConfig, "placementHistory"_sd)
// Namespace value used to identify the "fcv marker entry" of
// kConfigsvrPlacementHistoryNamespace collection which marks the start or the end of a FCV
// upgrade/downgrade.
-NSS_CONSTANT(kConfigsvrPlacementHistoryFcvMarkerNamespace, StringData{}, StringData{})
+NSS_CONSTANT(kConfigsvrPlacementHistoryFcvMarkerNamespace, DatabaseName::kEmpty, StringData{})
// TODO SERVER-68551: remove once 7.0 becomes last-lts
-NSS_CONSTANT(kLockpingsNamespace, NamespaceString::kConfigDb, "lockpings"_sd)
+NSS_CONSTANT(kLockpingsNamespace, DatabaseName::kConfig, "lockpings"_sd)
// TODO SERVER-68551: remove once 7.0 becomes last-lts
-NSS_CONSTANT(kDistLocksNamepsace, NamespaceString::kConfigDb, "locks"_sd)
+NSS_CONSTANT(kDistLocksNamepsace, DatabaseName::kConfig, "locks"_sd)
// Namespace used to store the state document of 'SetChangeStreamStateCoordinator'.
NSS_CONSTANT(kSetChangeStreamStateCoordinatorNamespace,
- NamespaceString::kConfigDb,
+ DatabaseName::kConfig,
"change_stream_coordinator"_sd)
// Namespace used for storing global index cloner state documents.
NSS_CONSTANT(kGlobalIndexClonerNamespace,
- NamespaceString::kConfigDb,
+ DatabaseName::kConfig,
"localGlobalIndexOperations.cloner"_sd)
// Namespace used for storing query analyzer settings.
-NSS_CONSTANT(kConfigQueryAnalyzersNamespace, NamespaceString::kConfigDb, "queryAnalyzers"_sd)
+NSS_CONSTANT(kConfigQueryAnalyzersNamespace, DatabaseName::kConfig, "queryAnalyzers"_sd)
// Namespace used for storing sampled queries.
-NSS_CONSTANT(kConfigSampledQueriesNamespace, NamespaceString::kConfigDb, "sampledQueries"_sd)
+NSS_CONSTANT(kConfigSampledQueriesNamespace, DatabaseName::kConfig, "sampledQueries"_sd)
// Namespace used for storing the diffs for sampled update queries.
-NSS_CONSTANT(kConfigSampledQueriesDiffNamespace,
- NamespaceString::kConfigDb,
- "sampledQueriesDiff"_sd)
+NSS_CONSTANT(kConfigSampledQueriesDiffNamespace, DatabaseName::kConfig, "sampledQueriesDiff"_sd)
// Namespace used for the health log.
-NSS_CONSTANT(kLocalHealthLogNamespace, NamespaceString::kLocalDb, "system.healthlog"_sd)
+NSS_CONSTANT(kLocalHealthLogNamespace, DatabaseName::kLocal, "system.healthlog"_sd)
diff --git a/src/mongo/db/repl/hello_auth.cpp b/src/mongo/db/repl/hello_auth.cpp
index ef3efef33e5..9ea72c57618 100644
--- a/src/mongo/db/repl/hello_auth.cpp
+++ b/src/mongo/db/repl/hello_auth.cpp
@@ -64,7 +64,7 @@ void handleHelloAuth(OperationContext* opCtx,
uassert(6656100,
"Cannot specify speculativeAuthenticate with a tenantId",
- !dbName.tenantId() || dbName.tenantId() == TenantId::kSystemTenantId);
+ !dbName.tenantId() || dbName.tenantId() == TenantId::systemTenantId());
uassert(ErrorCodes::BadValue,
str::stream() << "hello." << auth::kSpeculativeAuthenticate
diff --git a/src/mongo/db/tenant_id.cpp b/src/mongo/db/tenant_id.cpp
index ebef1dab3de..be33a88669e 100644
--- a/src/mongo/db/tenant_id.cpp
+++ b/src/mongo/db/tenant_id.cpp
@@ -33,11 +33,6 @@
namespace mongo {
-const TenantId TenantId::kSystemTenantId(
- OID("15650000" /* timestamp: 1981-05-17 */
- "0102030405" /* process id */
- "060708" /* counter */));
-
TenantId TenantId::parseFromBSON(const BSONElement& elem) {
if (elem.isNull()) {
uasserted(ErrorCodes::BadValue, "Could not deserialize TenantId from empty element");
diff --git a/src/mongo/db/tenant_id.h b/src/mongo/db/tenant_id.h
index c3eedb66053..5f23f104ecf 100644
--- a/src/mongo/db/tenant_id.h
+++ b/src/mongo/db/tenant_id.h
@@ -46,14 +46,10 @@ namespace mongo {
*/
class TenantId {
public:
- /**
- * kSystemTenantId must be unique across all possible tenant IDs.
- * Since the first four bytes of an OID are a unix epoch timestamp,
- * we can simply select a value prior to the inception of MongoDB,
- * and be guaranteed to never have a collision with a value
- * produced by OID::gen().
- */
- static const TenantId kSystemTenantId;
+ static const boost::optional<TenantId>& systemTenantId() {
+ static StaticImmortal<boost::optional<TenantId>> systemTenantId{};
+ return *systemTenantId;
+ }
explicit TenantId(const OID& oid) : _oid(oid) {}