summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWilliam Schultz <william.schultz@mongodb.com>2020-03-04 16:03:47 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-04 21:51:37 +0000
commita2eeeedb3e358f9a71042a2ff752b67844d4dcf7 (patch)
tree01e97adb4242c5a57028cbf09ab38f3703dfeea8 /src
parent10e8964486fa1c5216d2f021dec09af1fbdefe86 (diff)
downloadmongo-a2eeeedb3e358f9a71042a2ff752b67844d4dcf7.tar.gz
SERVER-46571 Give initial replica set configs a term of -1
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/repl/optime.h2
-rw-r--r--src/mongo/db/repl/repl_set_config.cpp2
-rw-r--r--src/mongo/db/repl/repl_set_config_checks.cpp11
-rw-r--r--src/mongo/db/repl/repl_set_config_checks_test.cpp18
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_test.cpp4
5 files changed, 19 insertions, 18 deletions
diff --git a/src/mongo/db/repl/optime.h b/src/mongo/db/repl/optime.h
index 9d045da574e..9cead491d25 100644
--- a/src/mongo/db/repl/optime.h
+++ b/src/mongo/db/repl/optime.h
@@ -56,7 +56,7 @@ public:
static const char kTermFieldName[];
// The term of an OpTime generated by old protocol version.
- static const long long kUninitializedTerm = -1;
+ static constexpr long long kUninitializedTerm = -1;
// The initial term after the first time upgrading from protocol version 0.
//
diff --git a/src/mongo/db/repl/repl_set_config.cpp b/src/mongo/db/repl/repl_set_config.cpp
index fe0c5ad1511..b1df2c829fb 100644
--- a/src/mongo/db/repl/repl_set_config.cpp
+++ b/src/mongo/db/repl/repl_set_config.cpp
@@ -101,7 +101,7 @@ Status ReplSetConfig::initialize(const BSONObj& cfg,
}
Status ReplSetConfig::initializeForInitiate(const BSONObj& cfg) {
- return _initialize(cfg, true, OpTime::kInitialTerm, OID());
+ return _initialize(cfg, true, OpTime::kUninitializedTerm, OID());
}
Status ReplSetConfig::_initialize(const BSONObj& cfg,
diff --git a/src/mongo/db/repl/repl_set_config_checks.cpp b/src/mongo/db/repl/repl_set_config_checks.cpp
index 384cabfc125..e55ab04f905 100644
--- a/src/mongo/db/repl/repl_set_config_checks.cpp
+++ b/src/mongo/db/repl/repl_set_config_checks.cpp
@@ -330,11 +330,12 @@ StatusWith<int> validateConfigForInitiate(ReplicationCoordinatorExternalState* e
<< newConfig.getConfigVersion());
}
- if (newConfig.getConfigTerm() != OpTime::kInitialTerm) {
- return StatusWith<int>(
- ErrorCodes::NewReplicaSetConfigurationIncompatible,
- str::stream() << "Configuration used to initiate a replica set must have term "
- << OpTime::kInitialTerm << ", but found " << newConfig.getConfigTerm());
+ if (newConfig.getConfigTerm() != OpTime::kUninitializedTerm) {
+ return StatusWith<int>(ErrorCodes::NewReplicaSetConfigurationIncompatible,
+ str::stream()
+ << "Configuration used to initiate a replica set must have term "
+ << OpTime::kUninitializedTerm << ", but found "
+ << newConfig.getConfigTerm());
}
return findSelfInConfigIfElectable(externalState, newConfig, ctx);
}
diff --git a/src/mongo/db/repl/repl_set_config_checks_test.cpp b/src/mongo/db/repl/repl_set_config_checks_test.cpp
index 63c33f7c1de..9654e9217e0 100644
--- a/src/mongo/db/repl/repl_set_config_checks_test.cpp
+++ b/src/mongo/db/repl/repl_set_config_checks_test.cpp
@@ -31,6 +31,7 @@
#include "mongo/base/status.h"
#include "mongo/db/jsobj.h"
+#include "mongo/db/repl/optime.h"
#include "mongo/db/repl/repl_set_config.h"
#include "mongo/db/repl/repl_set_config_checks.h"
#include "mongo/db/repl/replication_coordinator_external_state.h"
@@ -62,20 +63,19 @@ TEST_F(ServiceContextTest, ValidateConfigForInitiate_VersionMustBe1) {
validateConfigForInitiate(&rses, config, getGlobalServiceContext()).getStatus());
}
-TEST_F(ServiceContextTest, ValidateConfigForInitiate_TermIsAlwaysInitialTerm) {
+TEST_F(ServiceContextTest, ValidateConfigForInitiate_TermIsAlwaysUninitializedTerm) {
ReplicationCoordinatorExternalStateMock rses;
rses.addSelf(HostAndPort("h1"));
ReplSetConfig config;
- ASSERT_OK(
- config.initializeForInitiate(BSON("_id"
- << "rs0"
- << "version" << 1 << "term" << (OpTime::kInitialTerm + 1)
- << "protocolVersion" << 1 << "members"
- << BSON_ARRAY(BSON("_id" << 1 << "host"
- << "h1")))));
+ ASSERT_OK(config.initializeForInitiate(BSON("_id"
+ << "rs0"
+ << "version" << 1 << "term" << 999
+ << "protocolVersion" << 1 << "members"
+ << BSON_ARRAY(BSON("_id" << 1 << "host"
+ << "h1")))));
ASSERT_OK(validateConfigForInitiate(&rses, config, getGlobalServiceContext()).getStatus());
- ASSERT_EQUALS(config.getConfigTerm(), OpTime::kInitialTerm);
+ ASSERT_EQUALS(config.getConfigTerm(), OpTime::kUninitializedTerm);
}
TEST_F(ServiceContextTest, ValidateConfigForInitiate_MustFindSelf) {
diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
index 3eed301094a..4b76331c0e2 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
@@ -358,7 +358,7 @@ TEST_F(ReplCoordTest, NodeReturnsNodeNotFoundWhenQuorumCheckFailsWhileInitiating
ReplSetHeartbeatArgsV1 hbArgs;
hbArgs.setSetName("mySet");
hbArgs.setConfigVersion(1);
- hbArgs.setConfigTerm(0);
+ hbArgs.setConfigTerm(OpTime::kUninitializedTerm);
hbArgs.setCheckEmpty();
hbArgs.setSenderHost(HostAndPort("node1", 12345));
hbArgs.setSenderId(0);
@@ -392,7 +392,7 @@ TEST_F(ReplCoordTest, InitiateSucceedsWhenQuorumCheckPasses) {
ReplSetHeartbeatArgsV1 hbArgs;
hbArgs.setSetName("mySet");
hbArgs.setConfigVersion(1);
- hbArgs.setConfigTerm(0);
+ hbArgs.setConfigTerm(OpTime::kUninitializedTerm);
hbArgs.setCheckEmpty();
hbArgs.setSenderHost(HostAndPort("node1", 12345));
hbArgs.setSenderId(0);