summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorJonathan Reams <jbreams@mongodb.com>2016-08-18 11:01:02 -0400
committerJonathan Reams <jbreams@mongodb.com>2016-08-24 10:40:28 -0400
commit29189fc922f8746060e83ba27e46ba249eb3b9e4 (patch)
treeb5c56518ccea864345d8185f2491bd3a8158ab9b /src/mongo/db
parent2b3da87372ddb61a2226a7c11ba8d0b41c12278e (diff)
downloadmongo-29189fc922f8746060e83ba27e46ba249eb3b9e4.tar.gz
SERVER-21757 ServerStatus advisoryHostFQDNs should be optional
Diffstat (limited to 'src/mongo/db')
-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
4 files changed, 52 insertions, 21 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()));