diff options
author | Ben Caimano <ben.caimano@mongodb.com> | 2019-12-31 20:19:14 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-12-31 20:19:14 +0000 |
commit | aa7260c8f699c3c691f836bf2286606b2a8eac93 (patch) | |
tree | caf6ea5e64c1e7e74c05b13bfa2501d914de250f /src/mongo/db/operation_context.cpp | |
parent | dfc7fff94015eceac518170585fce0fe112619ad (diff) | |
download | mongo-aa7260c8f699c3c691f836bf2286606b2a8eac93.tar.gz |
SERVER-44167 Added ability to kill operations by key
There are two patches here really. One of which makes killOp fast to use
and visible. The other adds OperationKey to various places and maps it
to an internal OpId.
Diffstat (limited to 'src/mongo/db/operation_context.cpp')
-rw-r--r-- | src/mongo/db/operation_context.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/mongo/db/operation_context.cpp b/src/mongo/db/operation_context.cpp index 0a281d3b3ba..282612c54c8 100644 --- a/src/mongo/db/operation_context.cpp +++ b/src/mongo/db/operation_context.cpp @@ -34,6 +34,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/client.h" +#include "mongo/db/operation_key_manager.h" #include "mongo/db/service_context.h" #include "mongo/platform/mutex.h" #include "mongo/platform/random.h" @@ -79,13 +80,17 @@ const auto kNoWaiterThread = stdx::thread::id(); } // namespace -OperationContext::OperationContext(Client* client, unsigned int opId) +OperationContext::OperationContext(Client* client, OperationId opId) : _client(client), _opId(opId), _elapsedTime(client ? client->getServiceContext()->getTickSource() : SystemTickSource::get()) {} -OperationContext::~OperationContext() = default; +OperationContext::~OperationContext() { + if (_opKey) { + OperationKeyManager::get(_client).remove(*_opKey); + } +} void OperationContext::setDeadlineAndMaxTime(Date_t when, Microseconds maxTime, @@ -359,6 +364,14 @@ void OperationContext::setLogicalSessionId(LogicalSessionId lsid) { _lsid = std::move(lsid); } +void OperationContext::setOperationKey(OperationKey opKey) { + // Only set the opKey once + invariant(!_opKey); + + _opKey.emplace(std::move(opKey)); + OperationKeyManager::get(_client).add(*_opKey, _opId); +} + void OperationContext::setTxnNumber(TxnNumber txnNumber) { invariant(_lsid); _txnNumber = txnNumber; |