diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2018-05-21 18:32:48 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2018-05-24 13:22:15 -0400 |
commit | e55bf669726e91b21b45964b33f6cced1dcc515f (patch) | |
tree | f2adda3cd56b388ba38f6fd33ccaa397246cd3fe | |
parent | b919fb48eb611b3c8cbba9d7f03f6df1d25d4cd5 (diff) | |
download | mongo-e55bf669726e91b21b45964b33f6cced1dcc515f.tar.gz |
SERVER-32198 Move the sessions collection namespace constant to NamespaceString
-rw-r--r-- | src/mongo/db/catalog/database_impl.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/namespace_string.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/namespace_string.h | 3 | ||||
-rw-r--r-- | src/mongo/db/pipeline/document_source_list_sessions.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/s/config/configsvr_shard_collection_command.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/sessions_collection.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/sessions_collection.h | 2 | ||||
-rw-r--r-- | src/mongo/db/sessions_collection_config_server.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/sessions_collection_rs.cpp | 67 | ||||
-rw-r--r-- | src/mongo/db/sessions_collection_sharded.cpp | 16 | ||||
-rw-r--r-- | src/mongo/db/sessions_collection_standalone.cpp | 14 | ||||
-rw-r--r-- | src/mongo/db/transaction_reaper.cpp | 2 | ||||
-rw-r--r-- | src/mongo/dbtests/logical_sessions_tests.cpp | 9 |
14 files changed, 72 insertions, 71 deletions
diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp index 06a65e1c4d5..0055732ad54 100644 --- a/src/mongo/db/catalog/database_impl.cpp +++ b/src/mongo/db/catalog/database_impl.cpp @@ -63,7 +63,6 @@ #include "mongo/db/server_options.h" #include "mongo/db/server_parameters.h" #include "mongo/db/service_context.h" -#include "mongo/db/sessions_collection.h" #include "mongo/db/stats/top.h" #include "mongo/db/storage/recovery_unit.h" #include "mongo/db/storage/storage_engine.h" @@ -455,7 +454,7 @@ Status DatabaseImpl::dropCollection(OperationContext* opCtx, return Status(ErrorCodes::IllegalOperation, "turn off profiling before dropping system.profile collection"); } else if (!(nss.isSystemDotViews() || nss.isHealthlog() || - nss == SessionsCollection::kSessionsNamespaceString || + nss == NamespaceString::kLogicalSessionsNamespace || nss == NamespaceString::kSystemKeysNamespace)) { return Status(ErrorCodes::IllegalOperation, str::stream() << "can't drop system collection " << fullns); diff --git a/src/mongo/db/namespace_string.cpp b/src/mongo/db/namespace_string.cpp index 5f82119ea17..1ea72f8601f 100644 --- a/src/mongo/db/namespace_string.cpp +++ b/src/mongo/db/namespace_string.cpp @@ -52,6 +52,8 @@ constexpr StringData NamespaceString::kSystemDotViewsCollectionName; const NamespaceString NamespaceString::kServerConfigurationNamespace(NamespaceString::kAdminDb, "system.version"); +const NamespaceString NamespaceString::kLogicalSessionsNamespace(NamespaceString::kConfigDb, + "system.sessions"); const NamespaceString NamespaceString::kSessionTransactionsTableNamespace( NamespaceString::kConfigDb, "transactions"); const NamespaceString NamespaceString::kShardConfigCollectionsNamespace(NamespaceString::kConfigDb, diff --git a/src/mongo/db/namespace_string.h b/src/mongo/db/namespace_string.h index 8e5eaa5e460..ae4ac58e534 100644 --- a/src/mongo/db/namespace_string.h +++ b/src/mongo/db/namespace_string.h @@ -67,6 +67,9 @@ public: // represents. For example, 'shardIdentity' and 'featureCompatibilityVersion'. static const NamespaceString kServerConfigurationNamespace; + // Namespace for storing the logical sessions information + static const NamespaceString kLogicalSessionsNamespace; + // Namespace for storing the transaction information for each session static const NamespaceString kSessionTransactionsTableNamespace; diff --git a/src/mongo/db/pipeline/document_source_list_sessions.cpp b/src/mongo/db/pipeline/document_source_list_sessions.cpp index dba47ed9d1a..7d538ee1f3a 100644 --- a/src/mongo/db/pipeline/document_source_list_sessions.cpp +++ b/src/mongo/db/pipeline/document_source_list_sessions.cpp @@ -34,7 +34,6 @@ #include "mongo/db/matcher/extensions_callback_noop.h" #include "mongo/db/pipeline/document_source_list_sessions.h" #include "mongo/db/pipeline/document_sources_gen.h" -#include "mongo/db/sessions_collection.h" namespace mongo { @@ -50,8 +49,8 @@ boost::intrusive_ptr<DocumentSource> DocumentSourceListSessions::createFromBson( uassert(ErrorCodes::InvalidNamespace, str::stream() << kStageName << " may only be run against " - << SessionsCollection::kSessionsNamespaceString.ns(), - nss == SessionsCollection::kSessionsNamespaceString); + << NamespaceString::kLogicalSessionsNamespace.ns(), + nss == NamespaceString::kLogicalSessionsNamespace); const auto& spec = listSessionsParseSpec(kStageName, elem); if (spec.getAllUsers()) { diff --git a/src/mongo/db/s/config/configsvr_shard_collection_command.cpp b/src/mongo/db/s/config/configsvr_shard_collection_command.cpp index 2ff27c2b18f..bdaa4e5510f 100644 --- a/src/mongo/db/s/config/configsvr_shard_collection_command.cpp +++ b/src/mongo/db/s/config/configsvr_shard_collection_command.cpp @@ -48,7 +48,6 @@ #include "mongo/db/repl/repl_set_config.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/s/config/sharding_catalog_manager.h" -#include "mongo/db/sessions_collection.h" #include "mongo/s/balancer_configuration.h" #include "mongo/s/catalog/type_database.h" #include "mongo/s/catalog/type_shard.h" @@ -150,7 +149,7 @@ void validateAndDeduceFullRequestOptions(OperationContext* opCtx, // Ensure the namespace is valid. uassert(ErrorCodes::IllegalOperation, "can't shard system namespaces", - !nss.isSystem() || nss == SessionsCollection::kSessionsNamespaceString); + !nss.isSystem() || nss == NamespaceString::kLogicalSessionsNamespace); // Ensure the collation is valid. Currently we only allow the simple collation. bool simpleCollationSpecified = false; @@ -785,8 +784,7 @@ public: // Only whitelisted collections in config may be sharded (unless we are in test mode) uassert(ErrorCodes::IllegalOperation, "only special collections in the config db may be sharded", - nss == SessionsCollection::kSessionsNamespaceString || - getTestCommandsEnabled()); + nss == NamespaceString::kLogicalSessionsNamespace || getTestCommandsEnabled()); auto configShard = uassertStatusOK(shardRegistry->getShard(opCtx, dbType.getPrimary())); ScopedDbConnection configConn(configShard->getConnString()); 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 e6c68ba2f04..688b4f98de8 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 @@ -53,7 +53,6 @@ #include "mongo/db/repl/repl_set_config.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/s/type_shard_identity.h" -#include "mongo/db/sessions_collection.h" #include "mongo/db/wire_version.h" #include "mongo/executor/task_executor.h" #include "mongo/rpc/get_status_from_command_result.h" @@ -473,14 +472,14 @@ Status ShardingCatalogManager::_dropSessionsCollection( OperationContext* opCtx, std::shared_ptr<RemoteCommandTargeter> targeter) { BSONObjBuilder builder; - builder.append("drop", SessionsCollection::kSessionsNamespaceString.coll()); + builder.append("drop", NamespaceString::kLogicalSessionsNamespace.coll()); { BSONObjBuilder wcBuilder(builder.subobjStart("writeConcern")); wcBuilder.append("w", "majority"); } auto swCommandResponse = _runCommandForAddShard( - opCtx, targeter.get(), SessionsCollection::kSessionsNamespaceString.db(), builder.done()); + opCtx, targeter.get(), NamespaceString::kLogicalSessionsNamespace.db(), builder.done()); if (!swCommandResponse.isOK()) { return swCommandResponse.getStatus(); } diff --git a/src/mongo/db/sessions_collection.cpp b/src/mongo/db/sessions_collection.cpp index 72d7c7b2bea..2464bc0b47b 100644 --- a/src/mongo/db/sessions_collection.cpp +++ b/src/mongo/db/sessions_collection.cpp @@ -157,9 +157,6 @@ Status runBulkCmd(StringData label, } // namespace -const NamespaceString SessionsCollection::kSessionsNamespaceString = - NamespaceString(NamespaceString::kConfigDb, "system.sessions"); - SessionsCollection::~SessionsCollection() = default; SessionsCollection::SendBatchFn SessionsCollection::makeSendFnForBatchWrite( @@ -333,7 +330,7 @@ BSONObj SessionsCollection::generateCreateIndexesCmd() { indexes.push_back(std::move(index)); CreateIndexesCmd createIndexes; - createIndexes.setCreateIndexes(kSessionsNamespaceString.coll()); + createIndexes.setCreateIndexes(NamespaceString::kLogicalSessionsNamespace.coll()); createIndexes.setIndexes(std::move(indexes)); return createIndexes.toBSON(); diff --git a/src/mongo/db/sessions_collection.h b/src/mongo/db/sessions_collection.h index b45f1912e83..59440a5c755 100644 --- a/src/mongo/db/sessions_collection.h +++ b/src/mongo/db/sessions_collection.h @@ -47,8 +47,6 @@ class OperationContext; class SessionsCollection { public: - static const NamespaceString kSessionsNamespaceString; - virtual ~SessionsCollection(); /** diff --git a/src/mongo/db/sessions_collection_config_server.cpp b/src/mongo/db/sessions_collection_config_server.cpp index da1b6510b76..ca6d3fae01e 100644 --- a/src/mongo/db/sessions_collection_config_server.cpp +++ b/src/mongo/db/sessions_collection_config_server.cpp @@ -63,7 +63,7 @@ Status SessionsCollectionConfigServer::_shardCollectionIfNeeded(OperationContext // First, shard the sessions collection to create it. ConfigsvrShardCollectionRequest shardCollection; - shardCollection.set_configsvrShardCollection(SessionsCollection::kSessionsNamespaceString); + shardCollection.set_configsvrShardCollection(NamespaceString::kLogicalSessionsNamespace); shardCollection.setKey(BSON("_id" << 1)); DBDirectClient client(opCtx); @@ -79,7 +79,7 @@ Status SessionsCollectionConfigServer::_shardCollectionIfNeeded(OperationContext Status SessionsCollectionConfigServer::_generateIndexesIfNeeded(OperationContext* opCtx) { try { scatterGatherOnlyVersionIfUnsharded(opCtx, - SessionsCollection::kSessionsNamespaceString, + NamespaceString::kLogicalSessionsNamespace, SessionsCollection::generateCreateIndexesCmd(), ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kNoRetry); diff --git a/src/mongo/db/sessions_collection_rs.cpp b/src/mongo/db/sessions_collection_rs.cpp index 0e20c61cb9e..4f5c7a06905 100644 --- a/src/mongo/db/sessions_collection_rs.cpp +++ b/src/mongo/db/sessions_collection_rs.cpp @@ -93,7 +93,7 @@ auto runIfStandaloneOrPrimary(const NamespaceString& ns, { Lock::DBLock lk(opCtx, ns.db(), mode); Lock::CollectionLock lock( - opCtx->lockState(), SessionsCollection::kSessionsNamespaceString.ns(), mode); + opCtx->lockState(), NamespaceString::kLogicalSessionsNamespace.ns(), mode); auto coord = mongo::repl::ReplicationCoordinator::get(opCtx); @@ -145,7 +145,7 @@ auto dispatch(const NamespaceString& ns, Status SessionsCollectionRS::setupSessionsCollection(OperationContext* opCtx) { return dispatch( - kSessionsNamespaceString, + NamespaceString::kLogicalSessionsNamespace, MODE_IX, opCtx, [&] { @@ -153,7 +153,8 @@ Status SessionsCollectionRS::setupSessionsCollection(OperationContext* opCtx) { DBDirectClient client(opCtx); BSONObj info; auto cmd = generateCreateIndexesCmd(); - if (!client.runCommand(kSessionsNamespaceString.db().toString(), cmd, info)) { + if (!client.runCommand( + NamespaceString::kLogicalSessionsNamespace.db().toString(), cmd, info)) { return getStatusFromCommandResult(info); } @@ -168,56 +169,62 @@ Status SessionsCollectionRS::setupSessionsCollection(OperationContext* opCtx) { Status SessionsCollectionRS::refreshSessions(OperationContext* opCtx, const LogicalSessionRecordSet& sessions) { return dispatch( - kSessionsNamespaceString, + NamespaceString::kLogicalSessionsNamespace, MODE_IX, opCtx, [&] { DBDirectClient client(opCtx); - return doRefresh(kSessionsNamespaceString, - sessions, - makeSendFnForBatchWrite(kSessionsNamespaceString, &client)); + return doRefresh( + NamespaceString::kLogicalSessionsNamespace, + sessions, + makeSendFnForBatchWrite(NamespaceString::kLogicalSessionsNamespace, &client)); }, [&](DBClientBase* client) { - return doRefreshExternal(kSessionsNamespaceString, - sessions, - makeSendFnForCommand(kSessionsNamespaceString, client)); + return doRefreshExternal( + NamespaceString::kLogicalSessionsNamespace, + sessions, + makeSendFnForCommand(NamespaceString::kLogicalSessionsNamespace, client)); }); } Status SessionsCollectionRS::removeRecords(OperationContext* opCtx, const LogicalSessionIdSet& sessions) { - return dispatch(kSessionsNamespaceString, - MODE_IX, - opCtx, - [&] { - DBDirectClient client(opCtx); - return doRemove(kSessionsNamespaceString, - sessions, - makeSendFnForBatchWrite(kSessionsNamespaceString, &client)); - }, - [&](DBClientBase* client) { - return doRemoveExternal( - kSessionsNamespaceString, - sessions, - makeSendFnForCommand(kSessionsNamespaceString, client)); - }); + return dispatch( + NamespaceString::kLogicalSessionsNamespace, + MODE_IX, + opCtx, + [&] { + DBDirectClient client(opCtx); + return doRemove( + NamespaceString::kLogicalSessionsNamespace, + sessions, + makeSendFnForBatchWrite(NamespaceString::kLogicalSessionsNamespace, &client)); + }, + [&](DBClientBase* client) { + return doRemoveExternal( + NamespaceString::kLogicalSessionsNamespace, + sessions, + makeSendFnForCommand(NamespaceString::kLogicalSessionsNamespace, client)); + }); } StatusWith<LogicalSessionIdSet> SessionsCollectionRS::findRemovedSessions( OperationContext* opCtx, const LogicalSessionIdSet& sessions) { - return dispatch(kSessionsNamespaceString, + return dispatch(NamespaceString::kLogicalSessionsNamespace, MODE_IS, opCtx, [&] { DBDirectClient client(opCtx); - return doFetch(kSessionsNamespaceString, + return doFetch(NamespaceString::kLogicalSessionsNamespace, sessions, - makeFindFnForCommand(kSessionsNamespaceString, &client)); + makeFindFnForCommand( + NamespaceString::kLogicalSessionsNamespace, &client)); }, [&](DBClientBase* client) { - return doFetch(kSessionsNamespaceString, + return doFetch(NamespaceString::kLogicalSessionsNamespace, sessions, - makeFindFnForCommand(kSessionsNamespaceString, client)); + makeFindFnForCommand( + NamespaceString::kLogicalSessionsNamespace, client)); }); } diff --git a/src/mongo/db/sessions_collection_sharded.cpp b/src/mongo/db/sessions_collection_sharded.cpp index a82f8df1332..c7c7694daae 100644 --- a/src/mongo/db/sessions_collection_sharded.cpp +++ b/src/mongo/db/sessions_collection_sharded.cpp @@ -63,7 +63,7 @@ Status SessionsCollectionSharded::_checkCacheForSessionsCollection(OperationCont // If the collection doesn't exist, fail. Only the config servers generate it. auto res = Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh( - opCtx, SessionsCollection::kSessionsNamespaceString); + opCtx, NamespaceString::kLogicalSessionsNamespace); if (!res.isOK()) { return res.getStatus(); } @@ -84,7 +84,7 @@ Status SessionsCollectionSharded::refreshSessions(OperationContext* opCtx, const LogicalSessionRecordSet& sessions) { auto send = [&](BSONObj toSend) { auto opMsg = - OpMsgRequest::fromDBAndBody(SessionsCollection::kSessionsNamespaceString.db(), toSend); + OpMsgRequest::fromDBAndBody(NamespaceString::kLogicalSessionsNamespace.db(), toSend); auto request = BatchedCommandRequest::parseUpdate(opMsg); BatchedCommandResponse response; @@ -94,14 +94,14 @@ Status SessionsCollectionSharded::refreshSessions(OperationContext* opCtx, return response.toStatus(); }; - return doRefresh(kSessionsNamespaceString, sessions, send); + return doRefresh(NamespaceString::kLogicalSessionsNamespace, sessions, send); } Status SessionsCollectionSharded::removeRecords(OperationContext* opCtx, const LogicalSessionIdSet& sessions) { auto send = [&](BSONObj toSend) { auto opMsg = - OpMsgRequest::fromDBAndBody(SessionsCollection::kSessionsNamespaceString.db(), toSend); + OpMsgRequest::fromDBAndBody(NamespaceString::kLogicalSessionsNamespace.db(), toSend); auto request = BatchedCommandRequest::parseDelete(opMsg); BatchedCommandResponse response; @@ -111,7 +111,7 @@ Status SessionsCollectionSharded::removeRecords(OperationContext* opCtx, return response.toStatus(); }; - return doRemove(kSessionsNamespaceString, sessions, send); + return doRemove(NamespaceString::kLogicalSessionsNamespace, sessions, send); } StatusWith<LogicalSessionIdSet> SessionsCollectionSharded::findRemovedSessions( @@ -119,7 +119,7 @@ StatusWith<LogicalSessionIdSet> SessionsCollectionSharded::findRemovedSessions( auto send = [&](BSONObj toSend) -> StatusWith<BSONObj> { auto qr = QueryRequest::makeFromFindCommand( - SessionsCollection::kSessionsNamespaceString, toSend, false); + NamespaceString::kLogicalSessionsNamespace, toSend, false); if (!qr.isOK()) { return qr.getStatus(); } @@ -150,12 +150,12 @@ StatusWith<LogicalSessionIdSet> SessionsCollectionSharded::findRemovedSessions( for (const auto& obj : batch) { firstBatch.append(obj); } - firstBatch.done(cursorId, SessionsCollection::kSessionsNamespaceString.ns()); + firstBatch.done(cursorId, NamespaceString::kLogicalSessionsNamespace.ns()); return result.obj(); }; - return doFetch(kSessionsNamespaceString, sessions, send); + return doFetch(NamespaceString::kLogicalSessionsNamespace, sessions, send); } Status SessionsCollectionSharded::removeTransactionRecords(OperationContext* opCtx, diff --git a/src/mongo/db/sessions_collection_standalone.cpp b/src/mongo/db/sessions_collection_standalone.cpp index a7caf017fe1..ea980b86beb 100644 --- a/src/mongo/db/sessions_collection_standalone.cpp +++ b/src/mongo/db/sessions_collection_standalone.cpp @@ -49,7 +49,7 @@ Status SessionsCollectionStandalone::setupSessionsCollection(OperationContext* o DBDirectClient client(opCtx); auto cmd = generateCreateIndexesCmd(); BSONObj info; - if (!client.runCommand(kSessionsNamespaceString.db().toString(), cmd, info)) { + if (!client.runCommand(NamespaceString::kLogicalSessionsNamespace.db().toString(), cmd, info)) { return getStatusFromCommandResult(info); } @@ -59,25 +59,25 @@ Status SessionsCollectionStandalone::setupSessionsCollection(OperationContext* o Status SessionsCollectionStandalone::refreshSessions(OperationContext* opCtx, const LogicalSessionRecordSet& sessions) { DBDirectClient client(opCtx); - return doRefresh(kSessionsNamespaceString, + return doRefresh(NamespaceString::kLogicalSessionsNamespace, sessions, - makeSendFnForBatchWrite(kSessionsNamespaceString, &client)); + makeSendFnForBatchWrite(NamespaceString::kLogicalSessionsNamespace, &client)); } Status SessionsCollectionStandalone::removeRecords(OperationContext* opCtx, const LogicalSessionIdSet& sessions) { DBDirectClient client(opCtx); - return doRemove(kSessionsNamespaceString, + return doRemove(NamespaceString::kLogicalSessionsNamespace, sessions, - makeSendFnForBatchWrite(kSessionsNamespaceString, &client)); + makeSendFnForBatchWrite(NamespaceString::kLogicalSessionsNamespace, &client)); } StatusWith<LogicalSessionIdSet> SessionsCollectionStandalone::findRemovedSessions( OperationContext* opCtx, const LogicalSessionIdSet& sessions) { DBDirectClient client(opCtx); - return doFetch(kSessionsNamespaceString, + return doFetch(NamespaceString::kLogicalSessionsNamespace, sessions, - makeFindFnForCommand(kSessionsNamespaceString, &client)); + makeFindFnForCommand(NamespaceString::kLogicalSessionsNamespace, &client)); } Status SessionsCollectionStandalone::removeTransactionRecords(OperationContext* opCtx, diff --git a/src/mongo/db/transaction_reaper.cpp b/src/mongo/db/transaction_reaper.cpp index 02e003adae7..81273d384a6 100644 --- a/src/mongo/db/transaction_reaper.cpp +++ b/src/mongo/db/transaction_reaper.cpp @@ -231,7 +231,7 @@ public: bool initialize() { auto routingInfo = uassertStatusOK(Grid::get(_opCtx)->catalogCache()->getCollectionRoutingInfo( - _opCtx, SessionsCollection::kSessionsNamespaceString)); + _opCtx, NamespaceString::kLogicalSessionsNamespace)); _cm = routingInfo.cm(); return !!_cm; } diff --git a/src/mongo/dbtests/logical_sessions_tests.cpp b/src/mongo/dbtests/logical_sessions_tests.cpp index c1a3453a785..464491405cd 100644 --- a/src/mongo/dbtests/logical_sessions_tests.cpp +++ b/src/mongo/dbtests/logical_sessions_tests.cpp @@ -36,7 +36,6 @@ #include "mongo/db/logical_session_id.h" #include "mongo/db/logical_session_id_helpers.h" #include "mongo/db/operation_context.h" -#include "mongo/db/sessions_collection.h" #include "mongo/db/sessions_collection_standalone.h" #include "mongo/dbtests/dbtests.h" #include "mongo/stdx/memory.h" @@ -100,16 +99,16 @@ public: _opCtx.reset(); } - SessionsCollectionStandalone* collection() { + SessionsCollectionStandalone* collection() const { return _collection.get(); } - OperationContext* opCtx() { + OperationContext* opCtx() const { return _opCtx.get(); } - std::string ns() { - return SessionsCollection::kSessionsNamespaceString.toString(); + const std::string& ns() const { + return NamespaceString::kLogicalSessionsNamespace.ns(); } private: |