diff options
author | Spencer T Brody <spencer@mongodb.com> | 2014-11-11 14:52:58 -0500 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2014-11-12 17:44:15 -0500 |
commit | 6e7f0bd5b2b36f292fc2e3ee72f4b4b0ee504a06 (patch) | |
tree | c0e7a03fc3e3ca8cb31e837efb83b73a119df573 /src/mongo/db/repl/member_config.cpp | |
parent | be5c5eb936844926384c53ca0b5be0cd83438dc9 (diff) | |
download | mongo-6e7f0bd5b2b36f292fc2e3ee72f4b4b0ee504a06.tar.gz |
SERVER-16079 Invalid number of votes is a validation error not a parse error
Diffstat (limited to 'src/mongo/db/repl/member_config.cpp')
-rw-r--r-- | src/mongo/db/repl/member_config.cpp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/mongo/db/repl/member_config.cpp b/src/mongo/db/repl/member_config.cpp index 3a090b88dde..6f3bcf40501 100644 --- a/src/mongo/db/repl/member_config.cpp +++ b/src/mongo/db/repl/member_config.cpp @@ -117,23 +117,17 @@ namespace { // Parse votes field. // BSONElement votesElement = mcfg[kVotesFieldName]; - int votes; if (votesElement.eoo()) { - votes = kVotesFieldDefault; + _votes = kVotesFieldDefault; } else if (votesElement.isNumber()) { - votes = votesElement.numberInt(); + _votes = votesElement.numberInt(); } else { return Status(ErrorCodes::TypeMismatch, str::stream() << kVotesFieldName << " field value has non-numeric type " << typeName(votesElement.type())); } - if (votes != 0 && votes != 1) { - return Status(ErrorCodes::BadValue, str::stream() << kVotesFieldName << - " field value is " << votesElement.numberInt() << " but must be 0 or 1"); - } - _isVoter = bool(votes); // // Parse priority field. @@ -224,7 +218,7 @@ namespace { // Add a voter tag if this non-arbiter member votes; use _id for uniquity. const std::string id = str::stream() << _id; - if (_isVoter && !_arbiterOnly) { + if (isVoter() && !_arbiterOnly) { _tags.push_back(tagConfig->makeTag(kInternalVoterTagName, id)); } @@ -251,11 +245,15 @@ namespace { return Status(ErrorCodes::BadValue, str::stream() << kPriorityFieldName << " field value of " << _priority << " is out of range"); } + if (_votes != 0 && _votes != 1) { + return Status(ErrorCodes::BadValue, str::stream() << kVotesFieldName << + " field value is " << _votes << " but must be 0 or 1"); + } if (_arbiterOnly) { if (!_tags.empty()) { return Status(ErrorCodes::BadValue, "Cannot set tags on arbiters."); } - if (!_isVoter) { + if (!isVoter()) { return Status(ErrorCodes::BadValue, "Arbiter must vote (cannot have 0 votes)"); } } |