summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Suarez <kyle.suarez@mongodb.com>2018-03-29 15:14:31 -0400
committerKyle Suarez <kyle.suarez@mongodb.com>2018-03-29 15:14:43 -0400
commite1cb7f58d887815ae696a824291fdfc59fc35861 (patch)
treeab75d7f0813842e7018d2667a9e39626274e6e4f
parentd36b450a82c5ce2022af56f73b40a223ab0b2328 (diff)
downloadmongo-e1cb7f58d887815ae696a824291fdfc59fc35861.tar.gz
SERVER-21693 add host and port to oplog interface
-rw-r--r--src/mongo/db/repl/SConscript1
-rw-r--r--src/mongo/db/repl/bgsync.cpp3
-rw-r--r--src/mongo/db/repl/oplog_interface.h6
-rw-r--r--src/mongo/db/repl/oplog_interface_local.cpp5
-rw-r--r--src/mongo/db/repl/oplog_interface_local.h1
-rw-r--r--src/mongo/db/repl/oplog_interface_mock.cpp5
-rw-r--r--src/mongo/db/repl/oplog_interface_mock.h1
-rw-r--r--src/mongo/db/repl/oplog_interface_remote.cpp9
-rw-r--r--src/mongo/db/repl/oplog_interface_remote.h6
-rw-r--r--src/mongo/db/repl/roll_back_local_operations_test.cpp3
-rw-r--r--src/mongo/db/repl/rollback_source_impl.cpp2
11 files changed, 37 insertions, 5 deletions
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript
index ab73473f5a4..18437a1a2c7 100644
--- a/src/mongo/db/repl/SConscript
+++ b/src/mongo/db/repl/SConscript
@@ -478,6 +478,7 @@ env.Library(
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
+ '$BUILD_DIR/mongo/util/net/host',
],
)
diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp
index d6d9ff8abb1..6a395d6faeb 100644
--- a/src/mongo/db/repl/bgsync.cpp
+++ b/src/mongo/db/repl/bgsync.cpp
@@ -647,7 +647,8 @@ void BackgroundSync::_runRollbackViaRecoverToCheckpoint(
StorageInterface* storageInterface,
OplogInterfaceRemote::GetConnectionFn getConnection) {
- OplogInterfaceRemote remoteOplog(getConnection, NamespaceString::kRsOplogNamespace.ns());
+ OplogInterfaceRemote remoteOplog(
+ source, getConnection, NamespaceString::kRsOplogNamespace.ns());
{
stdx::lock_guard<stdx::mutex> lock(_mutex);
diff --git a/src/mongo/db/repl/oplog_interface.h b/src/mongo/db/repl/oplog_interface.h
index f0390d0ddbe..79519107e07 100644
--- a/src/mongo/db/repl/oplog_interface.h
+++ b/src/mongo/db/repl/oplog_interface.h
@@ -36,6 +36,7 @@
#include "mongo/base/status_with.h"
#include "mongo/bson/bsonobj.h"
#include "mongo/db/record_id.h"
+#include "mongo/util/net/hostandport.h"
namespace mongo {
namespace repl {
@@ -58,6 +59,11 @@ public:
*/
virtual std::unique_ptr<Iterator> makeIterator() const = 0;
+ /**
+ * The host and port of the server.
+ */
+ virtual HostAndPort hostAndPort() const = 0;
+
protected:
OplogInterface() = default;
};
diff --git a/src/mongo/db/repl/oplog_interface_local.cpp b/src/mongo/db/repl/oplog_interface_local.cpp
index 3ab6e6413c3..d140063b6b1 100644
--- a/src/mongo/db/repl/oplog_interface_local.cpp
+++ b/src/mongo/db/repl/oplog_interface_local.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/query/internal_plans.h"
#include "mongo/db/query/plan_executor.h"
#include "mongo/util/mongoutils/str.h"
+#include "mongo/util/net/sock.h"
namespace mongo {
namespace repl {
@@ -99,5 +100,9 @@ std::unique_ptr<OplogInterface::Iterator> OplogInterfaceLocal::makeIterator() co
new OplogIteratorLocal(_opCtx, _collectionName));
}
+HostAndPort OplogInterfaceLocal::hostAndPort() const {
+ return {getHostNameCached(), serverGlobalParams.port};
+}
+
} // namespace repl
} // namespace mongo
diff --git a/src/mongo/db/repl/oplog_interface_local.h b/src/mongo/db/repl/oplog_interface_local.h
index 577dbe8d7fa..f3bf21a39e6 100644
--- a/src/mongo/db/repl/oplog_interface_local.h
+++ b/src/mongo/db/repl/oplog_interface_local.h
@@ -45,6 +45,7 @@ public:
OplogInterfaceLocal(OperationContext* opCtx, const std::string& collectionName);
std::string toString() const override;
std::unique_ptr<OplogInterface::Iterator> makeIterator() const override;
+ HostAndPort hostAndPort() const override;
private:
OperationContext* _opCtx;
diff --git a/src/mongo/db/repl/oplog_interface_mock.cpp b/src/mongo/db/repl/oplog_interface_mock.cpp
index 94950da6446..72a4dd67294 100644
--- a/src/mongo/db/repl/oplog_interface_mock.cpp
+++ b/src/mongo/db/repl/oplog_interface_mock.cpp
@@ -77,5 +77,10 @@ std::unique_ptr<OplogInterface::Iterator> OplogInterfaceMock::makeIterator() con
new OplogIteratorMock(_operations.begin(), _operations.end()));
}
+HostAndPort OplogInterfaceMock::hostAndPort() const {
+ // Returns a default-constructed HostAndPort, which has an empty hostname and an invalid port.
+ return {};
+}
+
} // namespace repl
} // namespace mongo
diff --git a/src/mongo/db/repl/oplog_interface_mock.h b/src/mongo/db/repl/oplog_interface_mock.h
index 6e5cf2e96f8..ed49eb97366 100644
--- a/src/mongo/db/repl/oplog_interface_mock.h
+++ b/src/mongo/db/repl/oplog_interface_mock.h
@@ -49,6 +49,7 @@ public:
void setOperations(const Operations& operations);
std::string toString() const override;
std::unique_ptr<OplogInterface::Iterator> makeIterator() const override;
+ HostAndPort hostAndPort() const override;
private:
Operations _operations;
diff --git a/src/mongo/db/repl/oplog_interface_remote.cpp b/src/mongo/db/repl/oplog_interface_remote.cpp
index 1463eb53390..49197e90d19 100644
--- a/src/mongo/db/repl/oplog_interface_remote.cpp
+++ b/src/mongo/db/repl/oplog_interface_remote.cpp
@@ -64,9 +64,10 @@ StatusWith<OplogInterface::Iterator::Value> OplogIteratorRemote::next() {
} // namespace
-OplogInterfaceRemote::OplogInterfaceRemote(GetConnectionFn getConnection,
+OplogInterfaceRemote::OplogInterfaceRemote(HostAndPort hostAndPort,
+ GetConnectionFn getConnection,
const std::string& collectionName)
- : _getConnection(getConnection), _collectionName(collectionName) {}
+ : _hostAndPort(hostAndPort), _getConnection(getConnection), _collectionName(collectionName) {}
std::string OplogInterfaceRemote::toString() const {
return _getConnection()->toString();
@@ -79,5 +80,9 @@ std::unique_ptr<OplogInterface::Iterator> OplogInterfaceRemote::makeIterator() c
_getConnection()->query(_collectionName, query, 0, 0, &fields, 0, 0)));
}
+HostAndPort OplogInterfaceRemote::hostAndPort() const {
+ return _hostAndPort;
+}
+
} // namespace repl
} // namespace mongo
diff --git a/src/mongo/db/repl/oplog_interface_remote.h b/src/mongo/db/repl/oplog_interface_remote.h
index 34a7987bbf8..50d812aa062 100644
--- a/src/mongo/db/repl/oplog_interface_remote.h
+++ b/src/mongo/db/repl/oplog_interface_remote.h
@@ -48,11 +48,15 @@ public:
*/
using GetConnectionFn = stdx::function<DBClientBase*()>;
- OplogInterfaceRemote(GetConnectionFn getConnection, const std::string& collectionName);
+ OplogInterfaceRemote(HostAndPort hostAndPort,
+ GetConnectionFn getConnection,
+ const std::string& collectionName);
std::string toString() const override;
std::unique_ptr<OplogInterface::Iterator> makeIterator() const override;
+ HostAndPort hostAndPort() const override;
private:
+ HostAndPort _hostAndPort;
GetConnectionFn _getConnection;
std::string _collectionName;
};
diff --git a/src/mongo/db/repl/roll_back_local_operations_test.cpp b/src/mongo/db/repl/roll_back_local_operations_test.cpp
index aa3462a7b4e..dd39fe23325 100644
--- a/src/mongo/db/repl/roll_back_local_operations_test.cpp
+++ b/src/mongo/db/repl/roll_back_local_operations_test.cpp
@@ -58,6 +58,9 @@ TEST(RollBackLocalOperationsTest, InvalidLocalOplogIterator) {
std::unique_ptr<Iterator> makeIterator() const override {
return std::unique_ptr<Iterator>();
}
+ HostAndPort hostAndPort() const override {
+ return {};
+ }
} invalidOplog;
ASSERT_THROWS_CODE(
RollBackLocalOperations(invalidOplog, [](const BSONObj&) { return Status::OK(); }),
diff --git a/src/mongo/db/repl/rollback_source_impl.cpp b/src/mongo/db/repl/rollback_source_impl.cpp
index 902892dd133..a14d806d306 100644
--- a/src/mongo/db/repl/rollback_source_impl.cpp
+++ b/src/mongo/db/repl/rollback_source_impl.cpp
@@ -47,7 +47,7 @@ RollbackSourceImpl::RollbackSourceImpl(GetConnectionFn getConnection,
: _getConnection(getConnection),
_source(source),
_collectionName(collectionName),
- _oplog(getConnection, collectionName) {}
+ _oplog(source, getConnection, collectionName) {}
const OplogInterface& RollbackSourceImpl::getOplog() const {
return _oplog;