summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2019-04-11 11:38:09 -0400
committerJason Carey <jcarey@argv.me>2019-04-24 15:34:24 -0400
commit4c145b45d0fc94833eafc62290e02fead049f629 (patch)
tree5b7d14bf10b1acf064cc23605294a7889e48ea06 /src/mongo
parent59b8237b04e3823265247585920e4639d51dcbaf (diff)
downloadmongo-4c145b45d0fc94833eafc62290e02fead049f629.tar.gz
SERVER-40580 add NonAuthTaskExecutor
Spin up a non-authing task executor for the service context for use in local communication to mongodb wire protocol speaking services
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/executor/SConscript27
-rw-r--r--src/mongo/executor/non_auth_task_executor.cpp75
-rw-r--r--src/mongo/executor/non_auth_task_executor.h50
-rw-r--r--src/mongo/executor/non_auth_task_executor_integration_test.cpp71
4 files changed, 223 insertions, 0 deletions
diff --git a/src/mongo/executor/SConscript b/src/mongo/executor/SConscript
index 364ff4772a4..2da4b4e18a6 100644
--- a/src/mongo/executor/SConscript
+++ b/src/mongo/executor/SConscript
@@ -300,3 +300,30 @@ env.CppUnitTest(
'thread_pool_task_executor_test_fixture',
],
)
+
+env.Library(
+ target='non_auth_task_executor',
+ source=[
+ 'non_auth_task_executor.cpp',
+ ],
+ LIBDEPS=[
+ 'task_executor_interface',
+ '$BUILD_DIR/mongo/executor/network_interface_factory',
+ '$BUILD_DIR/mongo/executor/network_interface_thread_pool',
+ '$BUILD_DIR/mongo/executor/thread_pool_task_executor',
+ '$BUILD_DIR/mongo/util/concurrency/thread_pool',
+ ],
+)
+
+env.CppIntegrationTest(
+ target='non_auth_task_executor_integration_test',
+ source=[
+ 'non_auth_task_executor_integration_test.cpp',
+ ],
+ LIBDEPS=[
+ 'non_auth_task_executor',
+ '$BUILD_DIR/mongo/db/wire_version',
+ '$BUILD_DIR/mongo/transport/transport_layer_egress_init',
+ '$BUILD_DIR/mongo/util/version_impl',
+ ],
+)
diff --git a/src/mongo/executor/non_auth_task_executor.cpp b/src/mongo/executor/non_auth_task_executor.cpp
new file mode 100644
index 00000000000..60471994a8d
--- /dev/null
+++ b/src/mongo/executor/non_auth_task_executor.cpp
@@ -0,0 +1,75 @@
+/**
+ * Copyright (C) 2019-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kExecutor
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/executor/non_auth_task_executor.h"
+
+#include "mongo/executor/network_interface_factory.h"
+#include "mongo/executor/network_interface_thread_pool.h"
+#include "mongo/executor/thread_pool_task_executor.h"
+
+namespace mongo {
+namespace executor {
+
+namespace {
+
+const auto getExecutor = ServiceContext::declareDecoration<std::unique_ptr<TaskExecutor>>();
+
+ServiceContext::ConstructorActionRegisterer nonAuthExecutorCAR{
+ "NonAuthTaskExecutor",
+ [](ServiceContext* service) {
+ std::shared_ptr<NetworkInterface> ni =
+ makeNetworkInterface("NonAuthExecutor", nullptr, nullptr, [] {
+ ConnectionPool::Options options;
+ options.skipAuthentication = true;
+ return options;
+ }());
+ auto tp = std::make_unique<NetworkInterfaceThreadPool>(ni.get());
+ auto exec = std::make_unique<ThreadPoolTaskExecutor>(std::move(tp), std::move(ni));
+
+ exec->startup();
+
+ getExecutor(service) = std::move(exec);
+ },
+ [](ServiceContext* service) {
+ // Destruction implicitly performs the needed shutdown and join()
+ getExecutor(service).reset();
+ }};
+
+} // namespace
+
+TaskExecutor* getNonAuthTaskExecutor(ServiceContext* svc) {
+ return getExecutor(svc).get();
+}
+
+} // namespace executor
+} // namespace mongo
diff --git a/src/mongo/executor/non_auth_task_executor.h b/src/mongo/executor/non_auth_task_executor.h
new file mode 100644
index 00000000000..30329dd6740
--- /dev/null
+++ b/src/mongo/executor/non_auth_task_executor.h
@@ -0,0 +1,50 @@
+/**
+ * Copyright (C) 2019-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#pragma once
+
+#include "mongo/executor/task_executor.h"
+
+namespace mongo {
+
+class ServiceContext;
+
+namespace executor {
+
+/**
+ * Provides access to a service context scoped task executor which does not perform authentication
+ * in its connection pool.
+ *
+ * This executor has a bounded thread pool and otherwise unspecified hooks. It should only be used
+ * for internal communication to local mongodb protocol speaking services.
+ */
+TaskExecutor* getNonAuthTaskExecutor(ServiceContext* svc);
+
+} // namespace executor
+} // namespace mongo
diff --git a/src/mongo/executor/non_auth_task_executor_integration_test.cpp b/src/mongo/executor/non_auth_task_executor_integration_test.cpp
new file mode 100644
index 00000000000..b1d29190a04
--- /dev/null
+++ b/src/mongo/executor/non_auth_task_executor_integration_test.cpp
@@ -0,0 +1,71 @@
+/**
+ * Copyright (C) 2019-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/executor/non_auth_task_executor.h"
+
+#include "mongo/db/service_context.h"
+#include "mongo/unittest/integration_test.h"
+#include "mongo/unittest/unittest.h"
+#include "mongo/util/future.h"
+
+namespace mongo {
+namespace executor {
+namespace {
+
+// Basic test that the non auth task executor is actually set up and works
+TEST(NonAuthTaskExecutor, Basic) {
+ ServiceContext::UniqueServiceContext svc = ServiceContext::make();
+ auto exec = getNonAuthTaskExecutor(svc.get());
+
+ RemoteCommandRequest rcr(unittest::getFixtureConnectionString().getServers().front(),
+ "admin",
+ BSON("isMaster" << 1),
+ BSONObj(),
+ nullptr);
+
+ auto pf = makePromiseFuture<void>();
+
+ ASSERT(exec->scheduleRemoteCommand(std::move(rcr),
+ [&](const TaskExecutor::RemoteCommandCallbackArgs& args) {
+ if (args.response.isOK()) {
+ pf.promise.emplaceValue();
+ } else {
+ pf.promise.setError(args.response.status);
+ }
+ })
+ .isOK());
+
+ ASSERT_OK(pf.future.getNoThrow());
+}
+
+} // namespace
+} // namespace executor
+} // namespace mongo