diff options
author | Bernard Gorman <bernard.gorman@gmail.com> | 2018-05-25 15:33:02 -0400 |
---|---|---|
committer | Bernard Gorman <bernard.gorman@gmail.com> | 2018-05-25 23:13:41 -0400 |
commit | f0653f9963c2d2a597a4472aa065741f4ab17e57 (patch) | |
tree | d4d3f4def30a5535a25d74939ff0daa87df5d2d9 /src/mongo | |
parent | 25f72cf5f1d0d894680ef855f646e27f234ce6a3 (diff) | |
download | mongo-f0653f9963c2d2a597a4472aa065741f4ab17e57.tar.gz |
SERVER-34286 Ensure that operations never unexpectedly exceed the truncation threshold in currentop_query.js
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/commands/SConscript | 5 | ||||
-rw-r--r-- | src/mongo/db/commands/current_op_common.cpp | 23 |
2 files changed, 22 insertions, 6 deletions
diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript index a56c11d262f..cbf9fd55bd9 100644 --- a/src/mongo/db/commands/SConscript +++ b/src/mongo/db/commands/SConscript @@ -349,11 +349,14 @@ env.Library( ], LIBDEPS=[ '$BUILD_DIR/mongo/db/commands', + ], + LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/db/namespace_string', '$BUILD_DIR/mongo/db/pipeline/aggregation_request', '$BUILD_DIR/mongo/db/query/command_request_response', '$BUILD_DIR/mongo/db/service_context', - ] + 'test_commands_enabled' + ], ) env.Library( diff --git a/src/mongo/db/commands/current_op_common.cpp b/src/mongo/db/commands/current_op_common.cpp index de5af29560c..1dc87c4b0df 100644 --- a/src/mongo/db/commands/current_op_common.cpp +++ b/src/mongo/db/commands/current_op_common.cpp @@ -30,12 +30,20 @@ #include "mongo/db/commands/current_op_common.h" +#include <boost/container/flat_set.hpp> #include <string> #include "mongo/db/command_generic_argument.h" +#include "mongo/db/commands/test_commands_enabled.h" #include "mongo/db/namespace_string.h" namespace mongo { +namespace { +static constexpr auto kAll = "$all"_sd; +static constexpr auto kOwnOps = "$ownOps"_sd; +static constexpr auto kTruncateOps = "$truncateOps"_sd; +static const boost::container::flat_set<StringData> kCurOpCmdParams = {kAll, kOwnOps, kTruncateOps}; +} // namespace bool CurrentOpCommandBase::run(OperationContext* opCtx, const std::string& dbName, @@ -51,9 +59,15 @@ bool CurrentOpCommandBase::run(OperationContext* opCtx, BSONObjBuilder currentOpBuilder; BSONObjBuilder currentOpSpecBuilder(currentOpBuilder.subobjStart("$currentOp")); - currentOpSpecBuilder.append("idleConnections", cmdObj["$all"].trueValue()); - currentOpSpecBuilder.append("allUsers", !cmdObj["$ownOps"].trueValue()); - currentOpSpecBuilder.append("truncateOps", true); + // If test commands are enabled, then we allow the currentOp commands to specify whether or not + // to truncate long operations via the '$truncateOps' parameter. Otherwise, we always truncate + // operations to match the behaviour of the legacy currentOp command. + const bool truncateOps = + !getTestCommandsEnabled() || !cmdObj[kTruncateOps] || cmdObj[kTruncateOps].trueValue(); + + currentOpSpecBuilder.append("idleConnections", cmdObj[kAll].trueValue()); + currentOpSpecBuilder.append("allUsers", !cmdObj[kOwnOps].trueValue()); + currentOpSpecBuilder.append("truncateOps", truncateOps); currentOpSpecBuilder.doneFast(); pipeline.push_back(currentOpBuilder.obj()); @@ -66,8 +80,7 @@ bool CurrentOpCommandBase::run(OperationContext* opCtx, for (const auto& elt : cmdObj) { const auto fieldName = elt.fieldNameStringData(); - if (0 == idx++ || fieldName == "$all" || fieldName == "$ownOps" || - isGenericArgument(fieldName)) { + if (0 == idx++ || kCurOpCmdParams.count(fieldName) || isGenericArgument(fieldName)) { continue; } |