summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/commands/SConscript2
-rw-r--r--src/mongo/db/commands/server_status.cpp40
-rw-r--r--src/mongo/db/commands/server_status.h28
-rw-r--r--src/mongo/db/db.cpp3
-rw-r--r--src/mongo/s/config_server_test_fixture.cpp6
-rw-r--r--src/mongo/s/server.cpp3
-rw-r--r--src/mongo/util/net/SConscript12
-rw-r--r--src/mongo/util/net/hostname_canonicalization_worker.cpp92
-rw-r--r--src/mongo/util/net/hostname_canonicalization_worker.h72
9 files changed, 52 insertions, 206 deletions
diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript
index 75c10c03af7..3a1a9f34b66 100644
--- a/src/mongo/db/commands/SConscript
+++ b/src/mongo/db/commands/SConscript
@@ -17,7 +17,7 @@ env.Library(
'server_status_metric.cpp',
],
LIBDEPS=[
- '$BUILD_DIR/mongo/util/net/hostname_canonicalization_worker',
+ '$BUILD_DIR/mongo/util/net/network',
'$BUILD_DIR/mongo/base'
]
)
diff --git a/src/mongo/db/commands/server_status.cpp b/src/mongo/db/commands/server_status.cpp
index ff0b1cbb376..dbbf5582323 100644
--- a/src/mongo/db/commands/server_status.cpp
+++ b/src/mongo/db/commands/server_status.cpp
@@ -50,7 +50,7 @@
#include "mongo/transport/message_compressor_registry.h"
#include "mongo/transport/transport_layer.h"
#include "mongo/util/log.h"
-#include "mongo/util/net/hostname_canonicalization_worker.h"
+#include "mongo/util/net/hostname_canonicalization.h"
#include "mongo/util/net/ssl_manager.h"
#include "mongo/util/processinfo.h"
#include "mongo/util/ramlog.h"
@@ -99,13 +99,10 @@ public:
BSONObjBuilder timeBuilder(256);
const auto authSession = AuthorizationSession::get(Client::getCurrent());
- auto canonicalizer = HostnameCanonicalizationWorker::get(service);
// --- basic fields that are global
result.append("host", prettyHostName());
- result.append("advisoryHostFQDNs", canonicalizer->getCanonicalizedFQDNs());
-
result.append("version", VersionInfoInterface::instance().version());
result.append("process", serverGlobalParams.binaryName);
result.append("pid", ProcessId::getCurrent().asLongLong());
@@ -129,20 +126,16 @@ public:
continue;
bool include = section->includeByDefault();
-
- BSONElement e = cmdObj[section->getSectionName()];
- if (e.type()) {
- include = e.trueValue();
+ const auto& elem = cmdObj[section->getSectionName()];
+ if (elem.type()) {
+ include = elem.trueValue();
}
- if (!include)
- continue;
-
- BSONObj data = section->generateSection(txn, e);
- if (data.isEmpty())
+ if (!include) {
continue;
+ }
- result.append(section->getSectionName(), data);
+ section->appendSection(txn, elem, &result);
timeBuilder.appendNumber(
static_cast<string>(str::stream() << "after " << section->getSectionName()),
durationCount<Milliseconds>(clock->now() - runStart));
@@ -332,6 +325,23 @@ public:
}
}
} memBase;
-}
+
+class AdvisoryHostFQDNs final : public ServerStatusSection {
+public:
+ AdvisoryHostFQDNs() : ServerStatusSection("advisoryHostFQDNs") {}
+
+ bool includeByDefault() const override {
+ return false;
+ }
+
+ void appendSection(OperationContext* txn,
+ const BSONElement& configElement,
+ BSONObjBuilder* out) const override {
+ out->append(
+ "advisoryHostFQDNs",
+ getHostFQDNs(getHostNameCached(), HostnameCanonicalizationMode::kForwardAndReverse));
+ }
+} advisoryHostFQDNs;
+} // namespace
} // namespace mongo
diff --git a/src/mongo/db/commands/server_status.h b/src/mongo/db/commands/server_status.h
index 862cf1960e9..b017688acf2 100644
--- a/src/mongo/db/commands/server_status.h
+++ b/src/mongo/db/commands/server_status.h
@@ -73,11 +73,35 @@ public:
/**
* actually generate the result
+ *
+ * You should either implement this function or appendSection below, but not both. In
+ * most cases you should just implement this function.
+ *
* @param configElement the element from the actual command related to this section
* so if the section is 'foo', this is cmdObj['foo']
*/
- virtual BSONObj generateSection(OperationContext* txn,
- const BSONElement& configElement) const = 0;
+ virtual BSONObj generateSection(OperationContext* txn, const BSONElement& configElement) const {
+ return BSONObj{};
+ };
+
+ /**
+ * This is what gets called by the serverStatus command to append the section to the
+ * command result.
+ *
+ * If you are just implementing a normal ServerStatusSection, then you don't need to
+ * implement this.
+ *
+ * If you are doing something a bit more complicated, you can implement this and have
+ * full control over what gets included in the command result.
+ */
+ virtual void appendSection(OperationContext* txn,
+ const BSONElement& configElement,
+ BSONObjBuilder* result) const {
+ const auto ret = generateSection(txn, configElement);
+ if (ret.isEmpty())
+ return;
+ result->append(getSectionName(), ret);
+ }
private:
const std::string _sectionName;
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp
index 68a60d4e2b5..6ac580e3d17 100644
--- a/src/mongo/db/db.cpp
+++ b/src/mongo/db/db.cpp
@@ -128,7 +128,6 @@
#include "mongo/util/exit.h"
#include "mongo/util/fast_clock_source_factory.h"
#include "mongo/util/log.h"
-#include "mongo/util/net/hostname_canonicalization_worker.h"
#include "mongo/util/net/listen.h"
#include "mongo/util/net/ssl_manager.h"
#include "mongo/util/ntservice.h"
@@ -719,8 +718,6 @@ static ExitCode _initAndListen(int listenPort) {
<< startupWarningsLog;
}
- HostnameCanonicalizationWorker::start(getGlobalServiceContext());
-
uassertStatusOK(ShardingState::get(startupOpCtx.get())
->initializeShardingAwarenessIfNeeded(startupOpCtx.get()));
diff --git a/src/mongo/s/config_server_test_fixture.cpp b/src/mongo/s/config_server_test_fixture.cpp
index 8cb106aefcc..ed0f4810307 100644
--- a/src/mongo/s/config_server_test_fixture.cpp
+++ b/src/mongo/s/config_server_test_fixture.cpp
@@ -74,7 +74,6 @@
#include "mongo/s/write_ops/batched_command_response.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/clock_source_mock.h"
-#include "mongo/util/net/hostname_canonicalization_worker.h"
#include "mongo/util/tick_source_mock.h"
namespace mongo {
@@ -222,11 +221,6 @@ void ConfigServerTestFixture::setUp() {
_catalogClient->startup();
_catalogManager->startup();
-
- // Needed if serverStatus gets called.
- if (!HostnameCanonicalizationWorker::get(getGlobalServiceContext())) {
- HostnameCanonicalizationWorker::start(getGlobalServiceContext());
- }
}
void ConfigServerTestFixture::tearDown() {
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp
index 52c0f22e5a9..874cee5929f 100644
--- a/src/mongo/s/server.cpp
+++ b/src/mongo/s/server.cpp
@@ -91,7 +91,6 @@
#include "mongo/util/exit.h"
#include "mongo/util/fast_clock_source_factory.h"
#include "mongo/util/log.h"
-#include "mongo/util/net/hostname_canonicalization_worker.h"
#include "mongo/util/net/message.h"
#include "mongo/util/net/socket_exception.h"
#include "mongo/util/net/ssl_manager.h"
@@ -291,8 +290,6 @@ static ExitCode runMongosServer() {
web.detach();
}
- HostnameCanonicalizationWorker::start(getGlobalServiceContext());
-
Status status = getGlobalAuthorizationManager()->initialize(NULL);
if (!status.isOK()) {
error() << "Initializing authorization data failed: " << status;
diff --git a/src/mongo/util/net/SConscript b/src/mongo/util/net/SConscript
index c9da1751462..440d6b9465c 100644
--- a/src/mongo/util/net/SConscript
+++ b/src/mongo/util/net/SConscript
@@ -84,18 +84,6 @@ env.CppUnitTest(
)
env.Library(
- target="hostname_canonicalization_worker",
- source=[
- "hostname_canonicalization_worker.cpp",
- ],
- LIBDEPS=[
- '$BUILD_DIR/mongo/base',
- '$BUILD_DIR/mongo/db/service_context',
- 'network',
- ],
-)
-
-env.Library(
target='miniwebserver',
source=[
'miniwebserver.cpp',
diff --git a/src/mongo/util/net/hostname_canonicalization_worker.cpp b/src/mongo/util/net/hostname_canonicalization_worker.cpp
deleted file mode 100644
index 9c9aae319a8..00000000000
--- a/src/mongo/util/net/hostname_canonicalization_worker.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * Copyright (C) 2015 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * 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 GNU Affero General 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::kNetwork
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/util/net/hostname_canonicalization_worker.h"
-
-#include "mongo/db/service_context.h"
-#include "mongo/stdx/memory.h"
-#include "mongo/util/concurrency/thread_name.h"
-#include "mongo/util/log.h"
-#include "mongo/util/net/hostname_canonicalization.h"
-#include "mongo/util/net/sock.h"
-#include "mongo/util/time_support.h"
-
-namespace mongo {
-
-namespace {
-const auto getCanonicalizerTask =
- ServiceContext::declareDecoration<std::unique_ptr<HostnameCanonicalizationWorker>>();
-} // namespace
-
-void HostnameCanonicalizationWorker::start(ServiceContext* service) {
- auto& task = getCanonicalizerTask(service);
- task = stdx::make_unique<HostnameCanonicalizationWorker>();
-}
-
-HostnameCanonicalizationWorker::HostnameCanonicalizationWorker() {
- _canonicalizationThread = stdx::thread(&HostnameCanonicalizationWorker::_doWork, this);
-}
-
-void HostnameCanonicalizationWorker::_doWork() {
- setThreadName("HostnameCanonicalizationWorker");
- log() << "Starting hostname canonicalization worker";
- try {
- while (true) {
- LOG(5) << "Hostname Canonicalizer is acquiring host FQDNs";
- auto fqdns =
- getHostFQDNs(getHostNameCached(), HostnameCanonicalizationMode::kForwardAndReverse);
- {
- stdx::lock_guard<stdx::mutex> lock(_canonicalizationMutex);
- _cachedFQDNs = std::move(fqdns);
- }
- LOG(5) << "Hostname Canonicalizer acquired FQDNs";
-
- sleepsecs(60);
- }
- } catch (...) {
- stdx::lock_guard<stdx::mutex> lock(_canonicalizationMutex);
- error() << "Unexpected fault has terminated hostname canonicalization worker: "
- << exceptionToStatus();
- error() << "serverStatus will not report FQDNs until next server restart";
- _cachedFQDNs.clear();
- }
-}
-
-std::vector<std::string> HostnameCanonicalizationWorker::getCanonicalizedFQDNs() const {
- stdx::lock_guard<stdx::mutex> lock(_canonicalizationMutex);
- return _cachedFQDNs;
-}
-
-HostnameCanonicalizationWorker* HostnameCanonicalizationWorker::get(ServiceContext* context) {
- return getCanonicalizerTask(context).get();
-}
-
-} // namespace mongo
diff --git a/src/mongo/util/net/hostname_canonicalization_worker.h b/src/mongo/util/net/hostname_canonicalization_worker.h
deleted file mode 100644
index e1934466ab8..00000000000
--- a/src/mongo/util/net/hostname_canonicalization_worker.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * Copyright (C) 2015 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * 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 GNU Affero General 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 <string>
-#include <vector>
-
-#include "mongo/stdx/mutex.h"
-#include "mongo/stdx/thread.h"
-
-namespace mongo {
-class ServiceContext;
-
-/** Provides access to system's FQDNs acquired via forward and reverse resolution of its hostname.
- * A backgrounded worker thread periodically acquires the most current results and stores them
- * in an interal cache.
- */
-class HostnameCanonicalizationWorker {
-public:
- /** Spawn a new worker thread to acquire FQDNs. */
- HostnameCanonicalizationWorker();
-
- /** Return a copy of the FQDNs currently in the cache. */
- std::vector<std::string> getCanonicalizedFQDNs() const;
-
- /** Obtain the HostnameCanonicalizationWorker for a provided ServiceContext. */
- static HostnameCanonicalizationWorker* get(ServiceContext* context);
-
- /** Spawn the worker thread. */
- static void start(ServiceContext* context);
-
-private:
- // This is the main loop of worker thread, which runs forever.
- void _doWork();
-
- // Protects _cachedFQDNs
- mutable stdx::mutex _canonicalizationMutex;
-
- // All FQDNs found in the last pass of the background thread
- std::vector<std::string> _cachedFQDNs;
-
- // Worker thread
- stdx::thread _canonicalizationThread;
-};
-
-} // namespace mongo