summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/repl_set_request_votes_args.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/repl/repl_set_request_votes_args.cpp')
-rw-r--r--src/mongo/db/repl/repl_set_request_votes_args.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/mongo/db/repl/repl_set_request_votes_args.cpp b/src/mongo/db/repl/repl_set_request_votes_args.cpp
index 57256d71554..3c8538606ed 100644
--- a/src/mongo/db/repl/repl_set_request_votes_args.cpp
+++ b/src/mongo/db/repl/repl_set_request_votes_args.cpp
@@ -33,6 +33,7 @@
#include "mongo/bson/util/bson_extract.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/repl/bson_extract_optime.h"
+#include "mongo/db/server_options.h"
namespace mongo {
namespace repl {
@@ -41,6 +42,7 @@ namespace {
const std::string kCandidateIndexFieldName = "candidateIndex";
const std::string kCommandName = "replSetRequestVotes";
const std::string kConfigVersionFieldName = "configVersion";
+const std::string kConfigTermFieldName = "configTerm";
const std::string kDryRunFieldName = "dryRun";
// The underlying field name is inaccurate, but changing it requires a fair amount of cross
// compatibility work for no real benefit.
@@ -56,6 +58,7 @@ const std::string kLegalArgsFieldNames[] = {
kCandidateIndexFieldName,
kCommandName,
kConfigVersionFieldName,
+ kConfigTermFieldName,
kDryRunFieldName,
kLastDurableOpTimeFieldName,
kSetNameFieldName,
@@ -84,6 +87,13 @@ Status ReplSetRequestVotesArgs::initialize(const BSONObj& argsObj) {
if (!status.isOK())
return status;
+ // In order to be compatible with FCV 4.2, default the config term to -1 if we are unable
+ // parse a configTerm field from the args.
+ status = bsonExtractIntegerFieldWithDefault(
+ argsObj, kConfigTermFieldName, OpTime::kUninitializedTerm, &_cfgterm);
+ if (!status.isOK())
+ return status;
+
status = bsonExtractStringField(argsObj, kSetNameFieldName, &_setName);
if (!status.isOK())
return status;
@@ -115,6 +125,10 @@ long long ReplSetRequestVotesArgs::getConfigVersion() const {
return _cfgver;
}
+long long ReplSetRequestVotesArgs::getConfigTerm() const {
+ return _cfgterm;
+}
+
OpTime ReplSetRequestVotesArgs::getLastDurableOpTime() const {
return _lastDurableOpTime;
}
@@ -130,6 +144,12 @@ void ReplSetRequestVotesArgs::addToBSON(BSONObjBuilder* builder) const {
builder->append(kTermFieldName, _term);
builder->appendIntOrLL(kCandidateIndexFieldName, _candidateIndex);
builder->appendIntOrLL(kConfigVersionFieldName, _cfgver);
+ // Only append the config term field if we are in FCV 4.4
+ if (serverGlobalParams.featureCompatibility.isVersionInitialized() &&
+ serverGlobalParams.featureCompatibility.getVersion() ==
+ ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo44) {
+ builder->appendIntOrLL(kConfigTermFieldName, _cfgterm);
+ }
_lastDurableOpTime.append(builder, kLastDurableOpTimeFieldName);
}