summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/current_op_common.cpp
diff options
context:
space:
mode:
authorBernard Gorman <bernard.gorman@gmail.com>2018-05-25 15:33:02 -0400
committerBernard Gorman <bernard.gorman@gmail.com>2018-05-25 23:13:41 -0400
commitf0653f9963c2d2a597a4472aa065741f4ab17e57 (patch)
treed4d3f4def30a5535a25d74939ff0daa87df5d2d9 /src/mongo/db/commands/current_op_common.cpp
parent25f72cf5f1d0d894680ef855f646e27f234ce6a3 (diff)
downloadmongo-f0653f9963c2d2a597a4472aa065741f4ab17e57.tar.gz
SERVER-34286 Ensure that operations never unexpectedly exceed the truncation threshold in currentop_query.js
Diffstat (limited to 'src/mongo/db/commands/current_op_common.cpp')
-rw-r--r--src/mongo/db/commands/current_op_common.cpp23
1 files changed, 18 insertions, 5 deletions
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;
}