diff options
author | Andy Schwerin <schwerin@mongodb.com> | 2016-05-27 10:18:32 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@mongodb.com> | 2016-05-27 11:45:14 -0400 |
commit | afbdaca2a1353c7a5103dc315d7d635acd437243 (patch) | |
tree | 4504b8a37dac62889c0b4b7d7d4bb46a9811df29 /src/mongo/db | |
parent | a47b34136b9952865e060a6126fffc2a8a252d6d (diff) | |
download | mongo-afbdaca2a1353c7a5103dc315d7d635acd437243.tar.gz |
SERVER-23905 Unify implementations of operation id assignment into ServiceContext.
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/operation_context_impl.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/operation_context_impl.h | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/service_context_repl_mock.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/repl/service_context_repl_mock.h | 2 | ||||
-rw-r--r-- | src/mongo/db/service_context.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/service_context.h | 5 | ||||
-rw-r--r-- | src/mongo/db/service_context_d.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/service_context_d.h | 2 | ||||
-rw-r--r-- | src/mongo/db/service_context_noop.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/service_context_noop.h | 5 |
10 files changed, 17 insertions, 20 deletions
diff --git a/src/mongo/db/operation_context_impl.cpp b/src/mongo/db/operation_context_impl.cpp index be8b74fd159..f20d0a4eab8 100644 --- a/src/mongo/db/operation_context_impl.cpp +++ b/src/mongo/db/operation_context_impl.cpp @@ -65,18 +65,15 @@ private: const auto clientOperationInfoDecoration = Client::declareDecoration<ClientOperationInfo>(); -AtomicUInt32 nextOpId{1}; } // namespace using std::string; -OperationContextImpl::OperationContextImpl() - : OperationContext( - &cc(), nextOpId.fetchAndAdd(1), clientOperationInfoDecoration(cc()).getLocker()) { +OperationContextImpl::OperationContextImpl(Client* client, unsigned opId) + : OperationContext(client, opId, clientOperationInfoDecoration(client).getLocker()) { StorageEngine* storageEngine = getServiceContext()->getGlobalStorageEngine(); setRecoveryUnit(storageEngine->newRecoveryUnit(), kNotInUnitOfWork); - auto client = getClient(); stdx::lock_guard<Client> lk(*client); client->setOperationContext(this); } diff --git a/src/mongo/db/operation_context_impl.h b/src/mongo/db/operation_context_impl.h index c168ad7c98b..c6069f01e8b 100644 --- a/src/mongo/db/operation_context_impl.h +++ b/src/mongo/db/operation_context_impl.h @@ -45,7 +45,7 @@ public: private: friend class ServiceContextMongoD; - OperationContextImpl(); + OperationContextImpl(Client* client, unsigned opId); }; } // namespace mongo diff --git a/src/mongo/db/repl/service_context_repl_mock.cpp b/src/mongo/db/repl/service_context_repl_mock.cpp index ddb2fcf7506..8b4e9ed2ee7 100644 --- a/src/mongo/db/repl/service_context_repl_mock.cpp +++ b/src/mongo/db/repl/service_context_repl_mock.cpp @@ -39,9 +39,9 @@ namespace mongo { namespace repl { -std::unique_ptr<OperationContext> ServiceContextReplMock::_newOpCtx(Client* client) { +std::unique_ptr<OperationContext> ServiceContextReplMock::_newOpCtx(Client* client, unsigned opId) { return std::unique_ptr<OperationContext>( - new OperationContextNoop(client, _nextOpId.fetchAndAdd(1), new MMAPV1LockerImpl())); + new OperationContextNoop(client, opId, new MMAPV1LockerImpl())); } } // namespace repl diff --git a/src/mongo/db/repl/service_context_repl_mock.h b/src/mongo/db/repl/service_context_repl_mock.h index 6f7a107d992..8ffb92a9da1 100644 --- a/src/mongo/db/repl/service_context_repl_mock.h +++ b/src/mongo/db/repl/service_context_repl_mock.h @@ -39,7 +39,7 @@ namespace repl { */ class ServiceContextReplMock : public ServiceContextNoop { private: - std::unique_ptr<OperationContext> _newOpCtx(Client* client) override; + std::unique_ptr<OperationContext> _newOpCtx(Client* client, unsigned opId) override; }; } // namespace repl diff --git a/src/mongo/db/service_context.cpp b/src/mongo/db/service_context.cpp index 894d08c3fd9..d34920f6704 100644 --- a/src/mongo/db/service_context.cpp +++ b/src/mongo/db/service_context.cpp @@ -191,7 +191,7 @@ void ServiceContext::ClientDeleter::operator()(Client* client) const { } ServiceContext::UniqueOperationContext ServiceContext::makeOperationContext(Client* client) { - auto opCtx = _newOpCtx(client); + auto opCtx = _newOpCtx(client, _nextOpId.fetchAndAdd(1)); auto observer = _clientObservers.begin(); try { for (; observer != _clientObservers.cend(); ++observer) { diff --git a/src/mongo/db/service_context.h b/src/mongo/db/service_context.h index a27a799efd2..bc7b91c296e 100644 --- a/src/mongo/db/service_context.h +++ b/src/mongo/db/service_context.h @@ -359,7 +359,7 @@ private: /** * Returns a new OperationContext. Private, for use by makeOperationContext. */ - virtual std::unique_ptr<OperationContext> _newOpCtx(Client* client) = 0; + virtual std::unique_ptr<OperationContext> _newOpCtx(Client* client, unsigned opId) = 0; /** * Kills the given operation. @@ -393,6 +393,9 @@ private: // protected by _mutex std::vector<KillOpListenerInterface*> _killOpListeners; + + // Counter for assigning operation ids. + AtomicUInt32 _nextOpId{1}; }; /** diff --git a/src/mongo/db/service_context_d.cpp b/src/mongo/db/service_context_d.cpp index aac7296a5a4..03d2f8ff7f1 100644 --- a/src/mongo/db/service_context_d.cpp +++ b/src/mongo/db/service_context_d.cpp @@ -252,9 +252,9 @@ const StorageEngine::Factory* StorageFactoriesIteratorMongoD::next() { return _curr++->second; } -std::unique_ptr<OperationContext> ServiceContextMongoD::_newOpCtx(Client* client) { +std::unique_ptr<OperationContext> ServiceContextMongoD::_newOpCtx(Client* client, unsigned opId) { invariant(&cc() == client); - return std::unique_ptr<OperationContextImpl>(new OperationContextImpl()); + return std::unique_ptr<OperationContextImpl>(new OperationContextImpl(client, opId)); } void ServiceContextMongoD::setOpObserver(std::unique_ptr<OpObserver> opObserver) { diff --git a/src/mongo/db/service_context_d.h b/src/mongo/db/service_context_d.h index a773fab2b61..6de44fe1503 100644 --- a/src/mongo/db/service_context_d.h +++ b/src/mongo/db/service_context_d.h @@ -66,7 +66,7 @@ public: OpObserver* getOpObserver() override; private: - std::unique_ptr<OperationContext> _newOpCtx(Client* client) override; + std::unique_ptr<OperationContext> _newOpCtx(Client* client, unsigned opId) override; std::unique_ptr<StorageEngineLockFile> _lockFile; diff --git a/src/mongo/db/service_context_noop.cpp b/src/mongo/db/service_context_noop.cpp index 0280d1b4742..2703edea8ff 100644 --- a/src/mongo/db/service_context_noop.cpp +++ b/src/mongo/db/service_context_noop.cpp @@ -67,8 +67,8 @@ StorageFactoriesIterator* ServiceContextNoop::makeStorageFactoriesIterator() { return new EmptySFI(); } -std::unique_ptr<OperationContext> ServiceContextNoop::_newOpCtx(Client* client) { - return stdx::make_unique<OperationContextNoop>(client, _nextOpId.fetchAndAdd(1)); +std::unique_ptr<OperationContext> ServiceContextNoop::_newOpCtx(Client* client, unsigned opId) { + return stdx::make_unique<OperationContextNoop>(client, opId); } void ServiceContextNoop::setOpObserver(std::unique_ptr<OpObserver> opObserver) {} diff --git a/src/mongo/db/service_context_noop.h b/src/mongo/db/service_context_noop.h index 8e80509df10..4fe7ef6e022 100644 --- a/src/mongo/db/service_context_noop.h +++ b/src/mongo/db/service_context_noop.h @@ -53,11 +53,8 @@ public: OpObserver* getOpObserver() override; -protected: - AtomicUInt32 _nextOpId{1}; - private: - std::unique_ptr<OperationContext> _newOpCtx(Client* client) override; + std::unique_ptr<OperationContext> _newOpCtx(Client* client, unsigned opId) override; }; } // namespace mongo |