summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2018-04-18 15:08:48 -0400
committerHenrik Edin <henrik.edin@mongodb.com>2018-04-19 11:02:57 -0400
commit536942635bd8d103e001d09afb9d1402c81d2345 (patch)
treea9a81eac6a7dd196b453f6da441188c828a0252e
parent548236bfee7646373e4e0a5f6d8f9733a558dd45 (diff)
downloadmongo-536942635bd8d103e001d09afb9d1402c81d2345.tar.gz
SERVER-34533 killOp available on embedded.
Added a unittest for embedded to test killOp
-rw-r--r--jstests/core/count10.js4
-rw-r--r--jstests/core/count_plan_summary.js4
-rw-r--r--jstests/core/killop_drop_collection.js3
-rw-r--r--src/mongo/client/embedded/SConscript1
-rw-r--r--src/mongo/client/embedded/libmongodbcapi_test.cpp53
-rw-r--r--src/mongo/db/commands/SConscript2
-rw-r--r--src/mongo/db/storage/encryption_hooks.cpp21
7 files changed, 70 insertions, 18 deletions
diff --git a/jstests/core/count10.js b/jstests/core/count10.js
index 252f1f597d9..007c4e6918b 100644
--- a/jstests/core/count10.js
+++ b/jstests/core/count10.js
@@ -7,8 +7,8 @@
// assumes_read_preference_unchanged,
// does_not_support_stepdowns,
//
-// # killop command is not yet available on embedded
-// incompatible_with_embedded_todo_investigate,
+// # Uses $where operator
+// requires_scripting,
// ]
t = db.count10;
diff --git a/jstests/core/count_plan_summary.js b/jstests/core/count_plan_summary.js
index 7d170a8ac8a..79c6712a7f9 100644
--- a/jstests/core/count_plan_summary.js
+++ b/jstests/core/count_plan_summary.js
@@ -7,8 +7,8 @@
// assumes_read_preference_unchanged,
// does_not_support_stepdowns,
//
-// # killop command is not yet available on embedded
-// incompatible_with_embedded_todo_investigate,
+// # Uses $where operator
+// requires_scripting,
// ]
var t = db.jstests_count_plan_summary;
diff --git a/jstests/core/killop_drop_collection.js b/jstests/core/killop_drop_collection.js
index d21b81fe600..ce263201ca0 100644
--- a/jstests/core/killop_drop_collection.js
+++ b/jstests/core/killop_drop_collection.js
@@ -5,9 +5,6 @@
* successfully.
*
* @tags: [
- * # killop command is not yet available on embedded
- * incompatible_with_embedded_todo_investigate,
- *
* # Uses index building in background
* requires_background_index,
* ]
diff --git a/src/mongo/client/embedded/SConscript b/src/mongo/client/embedded/SConscript
index 3025372251d..0a32620d1a0 100644
--- a/src/mongo/client/embedded/SConscript
+++ b/src/mongo/client/embedded/SConscript
@@ -158,6 +158,7 @@ capiTest = capiTestEnv.Program(
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
+ '$BUILD_DIR/mongo/db/commands/shell_protocol',
'$BUILD_DIR/mongo/unittest/unittest',
'$BUILD_DIR/mongo/util/net/network',
'mongo_embedded_capi',
diff --git a/src/mongo/client/embedded/libmongodbcapi_test.cpp b/src/mongo/client/embedded/libmongodbcapi_test.cpp
index 7e81e28bcfa..625c64a62f1 100644
--- a/src/mongo/client/embedded/libmongodbcapi_test.cpp
+++ b/src/mongo/client/embedded/libmongodbcapi_test.cpp
@@ -33,9 +33,11 @@
#include <yaml-cpp/yaml.h>
#include "mongo/bson/bsonobjbuilder.h"
+#include "mongo/db/commands/test_commands_enabled.h"
#include "mongo/db/json.h"
#include "mongo/db/server_options.h"
#include "mongo/stdx/memory.h"
+#include "mongo/stdx/thread.h"
#include "mongo/unittest/temp_dir.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/net/message.h"
@@ -280,6 +282,55 @@ TEST_F(MongodbCAPITest, InsertMultipleDocuments) {
ASSERT(outputBSON.getField("ok").numberDouble() == 1.0);
}
+TEST_F(MongodbCAPITest, KillOp) {
+ auto client = createClient();
+
+ mongo::stdx::thread killOpThread([this]() {
+ auto client = createClient();
+
+ mongo::BSONObj currentOpObj = mongo::fromjson("{currentOp: 1}");
+ auto currentOpMsg = mongo::OpMsgRequest::fromDBAndBody("admin", currentOpObj);
+ mongo::BSONObj outputBSON;
+
+ // Wait for the sleep command to start in the main test thread.
+ int opid = -1;
+ do {
+ outputBSON = performRpc(client, currentOpMsg);
+ auto inprog = outputBSON.getObjectField("inprog");
+
+ // See if we find the sleep command among the running commands
+ for (const auto& elt : inprog) {
+ auto inprogObj = inprog.getObjectField(elt.fieldNameStringData());
+ std::string ns = inprogObj.getStringField("ns");
+ if (ns == "admin.$cmd") {
+ opid = inprogObj.getIntField("opid");
+ break;
+ }
+ }
+ } while (opid == -1);
+
+ // Sleep command found, kill it.
+ std::stringstream ss;
+ ss << "{'killOp': 1, 'op': " << opid << "}";
+ mongo::BSONObj killOpObj = mongo::fromjson(ss.str());
+ auto killOpMsg = mongo::OpMsgRequest::fromDBAndBody("admin", killOpObj);
+ outputBSON = performRpc(client, killOpMsg);
+
+ ASSERT(outputBSON.hasField("ok"));
+ ASSERT(outputBSON.getField("ok").numberDouble() == 1.0);
+ });
+
+ mongo::BSONObj sleepObj = mongo::fromjson("{'sleep': {'secs': 1000}}");
+ auto sleepOpMsg = mongo::OpMsgRequest::fromDBAndBody("admin", sleepObj);
+ auto outputBSON = performRpc(client, sleepOpMsg);
+
+ ASSERT(outputBSON.hasField("ok"));
+ ASSERT(outputBSON.getField("ok").numberDouble() != 1.0);
+ ASSERT(outputBSON.getIntField("code") == mongo::ErrorCodes::Interrupted);
+
+ killOpThread.join();
+}
+
TEST_F(MongodbCAPITest, ReadDB) {
auto client = createClient();
@@ -467,6 +518,8 @@ int main(int argc, char** argv, char** envp) {
::mongo::serverGlobalParams.noUnixSocket = true;
::mongo::unittest::setupTestLogger();
+ mongo::setTestCommandsEnabled(true);
+
// Check so we can initialize the library without providing init params
int init = libmongodbcapi_init(nullptr);
if (init != LIBMONGODB_CAPI_SUCCESS) {
diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript
index 1dce82f94de..03dd3919180 100644
--- a/src/mongo/db/commands/SConscript
+++ b/src/mongo/db/commands/SConscript
@@ -196,6 +196,7 @@ env.Library(
"geo_near_cmd.cpp",
"getmore_cmd.cpp",
"index_filter_commands.cpp",
+ "kill_op.cpp",
"killcursors_cmd.cpp",
"lock_info.cpp",
"list_collections.cpp",
@@ -266,7 +267,6 @@ env.Library(
"get_last_error.cpp",
"group_cmd.cpp",
"haystack.cpp",
- "kill_op.cpp",
"mr.cpp",
"oplog_application_checks.cpp",
"oplog_note.cpp",
diff --git a/src/mongo/db/storage/encryption_hooks.cpp b/src/mongo/db/storage/encryption_hooks.cpp
index 8a81d20dd2d..bb5c60a29b8 100644
--- a/src/mongo/db/storage/encryption_hooks.cpp
+++ b/src/mongo/db/storage/encryption_hooks.cpp
@@ -41,13 +41,16 @@
namespace mongo {
/* Make a EncryptionHooks pointer a decoration on the global ServiceContext */
-MONGO_INITIALIZER(SetEncryptionHooks)
-(InitializerContext* context) {
- auto encryptionHooks = stdx::make_unique<EncryptionHooks>();
- EncryptionHooks::set(getGlobalServiceContext(), std::move(encryptionHooks));
-
- return Status::OK();
-}
+GlobalInitializerRegisterer encryptionHooksInitializer(
+ "SetEncryptionHooks",
+ [](InitializerContext* context) {
+ EncryptionHooks::set(context->serviceContext(), stdx::make_unique<EncryptionHooks>());
+ return Status::OK();
+ },
+ [](DeinitializerContext* context) {
+ EncryptionHooks::set(context->serviceContext(), nullptr);
+ return Status::OK();
+ });
namespace {
const auto getEncryptionHooks =
@@ -55,9 +58,7 @@ const auto getEncryptionHooks =
} // namespace
void EncryptionHooks::set(ServiceContext* service, std::unique_ptr<EncryptionHooks> custHooks) {
- auto& hooks = getEncryptionHooks(service);
- invariant(custHooks);
- hooks = std::move(custHooks);
+ getEncryptionHooks(service) = std::move(custHooks);
}
EncryptionHooks* EncryptionHooks::get(ServiceContext* service) {