summaryrefslogtreecommitdiff
path: root/src/mongo/rpc
diff options
context:
space:
mode:
authorBen Caimano <ben.caimano@mongodb.com>2019-12-31 20:19:14 +0000
committerevergreen <evergreen@mongodb.com>2019-12-31 20:19:14 +0000
commitaa7260c8f699c3c691f836bf2286606b2a8eac93 (patch)
treecaf6ea5e64c1e7e74c05b13bfa2501d914de250f /src/mongo/rpc
parentdfc7fff94015eceac518170585fce0fe112619ad (diff)
downloadmongo-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/rpc')
-rw-r--r--src/mongo/rpc/SConscript1
-rw-r--r--src/mongo/rpc/metadata.cpp15
2 files changed, 15 insertions, 1 deletions
diff --git a/src/mongo/rpc/SConscript b/src/mongo/rpc/SConscript
index aa2cf7ea5f2..1dd4f810414 100644
--- a/src/mongo/rpc/SConscript
+++ b/src/mongo/rpc/SConscript
@@ -107,6 +107,7 @@ env.Library(
'$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/bson/util/bson_extract',
'$BUILD_DIR/mongo/client/read_preference',
+ '$BUILD_DIR/mongo/db/commands/test_commands_enabled',
'$BUILD_DIR/mongo/db/logical_time_validator',
'$BUILD_DIR/mongo/db/repl/optime',
'$BUILD_DIR/mongo/db/signed_logical_time',
diff --git a/src/mongo/rpc/metadata.cpp b/src/mongo/rpc/metadata.cpp
index e3ed093a693..ab65025a725 100644
--- a/src/mongo/rpc/metadata.cpp
+++ b/src/mongo/rpc/metadata.cpp
@@ -33,6 +33,7 @@
#include "mongo/client/read_preference.h"
#include "mongo/db/auth/authorization_session.h"
+#include "mongo/db/commands/test_commands_enabled.h"
#include "mongo/db/dbmessage.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/logical_clock.h"
@@ -59,6 +60,7 @@ void readRequestMetadata(OperationContext* opCtx, const BSONObj& metadataObj, bo
BSONElement clientElem;
BSONElement logicalTimeElem;
BSONElement impersonationElem;
+ BSONElement clientOperationKeyElem;
for (const auto& metadataElem : metadataObj) {
auto fieldName = metadataElem.fieldNameStringData();
@@ -74,9 +76,21 @@ void readRequestMetadata(OperationContext* opCtx, const BSONObj& metadataObj, bo
logicalTimeElem = metadataElem;
} else if (fieldName == kImpersonationMetadataSectionName) {
impersonationElem = metadataElem;
+ } else if (fieldName == "clientOperationKey"_sd) {
+ clientOperationKeyElem = metadataElem;
}
}
+ AuthorizationSession* authSession = AuthorizationSession::get(opCtx->getClient());
+
+ if (clientOperationKeyElem &&
+ (getTestCommandsEnabled() ||
+ authSession->isAuthorizedForActionsOnResource(ResourcePattern::forClusterResource(),
+ ActionType::internal))) {
+ auto opKey = uassertStatusOK(UUID::parse(clientOperationKeyElem));
+ opCtx->setOperationKey(std::move(opKey));
+ }
+
if (readPreferenceElem) {
ReadPreferenceSetting::get(opCtx) =
uassertStatusOK(ReadPreferenceSetting::fromInnerBSON(readPreferenceElem));
@@ -103,7 +117,6 @@ void readRequestMetadata(OperationContext* opCtx, const BSONObj& metadataObj, bo
AuthorizationManager::get(opCtx->getServiceContext())->isAuthEnabled() &&
(!signedTime.getProof() || *signedTime.getProof() == TimeProofService::TimeProof())) {
- AuthorizationSession* authSession = AuthorizationSession::get(opCtx->getClient());
// The client is not authenticated and is not using localhost auth bypass.
if (authSession && !authSession->isAuthenticated() &&
!authSession->isUsingLocalhostBypass()) {