summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/vote_requester.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/repl/vote_requester.h')
-rw-r--r--src/mongo/db/repl/vote_requester.h143
1 files changed, 71 insertions, 72 deletions
diff --git a/src/mongo/db/repl/vote_requester.h b/src/mongo/db/repl/vote_requester.h
index a5102192ebd..8000d12ddb8 100644
--- a/src/mongo/db/repl/vote_requester.h
+++ b/src/mongo/db/repl/vote_requester.h
@@ -41,92 +41,91 @@
namespace mongo {
- class Status;
+class Status;
namespace repl {
- class ScatterGatherRunner;
- class ReplSetDeclareRequestVotesArgs;
+class ScatterGatherRunner;
+class ReplSetDeclareRequestVotesArgs;
- class VoteRequester {
- MONGO_DISALLOW_COPYING(VoteRequester);
- public:
+class VoteRequester {
+ MONGO_DISALLOW_COPYING(VoteRequester);
- enum VoteRequestResult {
- SuccessfullyElected,
- StaleTerm,
- InsufficientVotes,
- };
-
- class Algorithm : public ScatterGatherAlgorithm {
- public:
- Algorithm(const ReplicaSetConfig& rsConfig,
- long long candidateId,
- long long term,
- bool dryRun,
- OpTime lastOplogEntry);
- virtual ~Algorithm();
- virtual std::vector<RemoteCommandRequest> getRequests() const;
- virtual void processResponse(
- const RemoteCommandRequest& request,
- const ResponseStatus& response);
- virtual bool hasReceivedSufficientResponses() const;
-
- /**
- * Returns a VoteRequestResult indicating the result of the election.
- *
- * It is invalid to call this before hasReceivedSufficientResponses returns true.
- */
- VoteRequestResult getResult() const;
-
- private:
- const ReplicaSetConfig _rsConfig;
- const long long _candidateId;
- const long long _term;
- bool _dryRun = false; // this bool indicates this is a mock election when true
- const OpTime _lastOplogEntry;
- std::vector<HostAndPort> _targets;
- bool _staleTerm = false;
- long long _responsesProcessed = 0;
- long long _votes = 1;
- };
-
- VoteRequester();
- virtual ~VoteRequester();
+public:
+ enum VoteRequestResult {
+ SuccessfullyElected,
+ StaleTerm,
+ InsufficientVotes,
+ };
- /**
- * Begins the process of sending replSetRequestVotes commands to all non-DOWN nodes
- * in currentConfig, in attempt to receive sufficient votes to win the election.
- *
- * evh can be used to schedule a callback when the process is complete.
- * This function must be run in the executor, as it must be synchronous with the command
- * callbacks that it schedules.
- * If this function returns Status::OK(), evh is then guaranteed to be signaled.
- **/
- StatusWith<ReplicationExecutor::EventHandle> start(
- ReplicationExecutor* executor,
- const ReplicaSetConfig& rsConfig,
- long long candidateId,
- long long term,
- bool dryRun,
- OpTime lastOplogEntry,
- const stdx::function<void ()>& onCompletion = stdx::function<void ()>());
+ class Algorithm : public ScatterGatherAlgorithm {
+ public:
+ Algorithm(const ReplicaSetConfig& rsConfig,
+ long long candidateId,
+ long long term,
+ bool dryRun,
+ OpTime lastOplogEntry);
+ virtual ~Algorithm();
+ virtual std::vector<RemoteCommandRequest> getRequests() const;
+ virtual void processResponse(const RemoteCommandRequest& request,
+ const ResponseStatus& response);
+ virtual bool hasReceivedSufficientResponses() const;
/**
- * Informs the VoteRequester to cancel further processing. The "executor"
- * argument must point to the same executor passed to "start()".
+ * Returns a VoteRequestResult indicating the result of the election.
*
- * Like start(), this method must run in the executor context.
+ * It is invalid to call this before hasReceivedSufficientResponses returns true.
*/
- void cancel(ReplicationExecutor* executor);
-
VoteRequestResult getResult() const;
private:
- std::unique_ptr<Algorithm> _algorithm;
- std::unique_ptr<ScatterGatherRunner> _runner;
- bool _isCanceled = false;
+ const ReplicaSetConfig _rsConfig;
+ const long long _candidateId;
+ const long long _term;
+ bool _dryRun = false; // this bool indicates this is a mock election when true
+ const OpTime _lastOplogEntry;
+ std::vector<HostAndPort> _targets;
+ bool _staleTerm = false;
+ long long _responsesProcessed = 0;
+ long long _votes = 1;
};
+ VoteRequester();
+ virtual ~VoteRequester();
+
+ /**
+ * Begins the process of sending replSetRequestVotes commands to all non-DOWN nodes
+ * in currentConfig, in attempt to receive sufficient votes to win the election.
+ *
+ * evh can be used to schedule a callback when the process is complete.
+ * This function must be run in the executor, as it must be synchronous with the command
+ * callbacks that it schedules.
+ * If this function returns Status::OK(), evh is then guaranteed to be signaled.
+ **/
+ StatusWith<ReplicationExecutor::EventHandle> start(
+ ReplicationExecutor* executor,
+ const ReplicaSetConfig& rsConfig,
+ long long candidateId,
+ long long term,
+ bool dryRun,
+ OpTime lastOplogEntry,
+ const stdx::function<void()>& onCompletion = stdx::function<void()>());
+
+ /**
+ * Informs the VoteRequester to cancel further processing. The "executor"
+ * argument must point to the same executor passed to "start()".
+ *
+ * Like start(), this method must run in the executor context.
+ */
+ void cancel(ReplicationExecutor* executor);
+
+ VoteRequestResult getResult() const;
+
+private:
+ std::unique_ptr<Algorithm> _algorithm;
+ std::unique_ptr<ScatterGatherRunner> _runner;
+ bool _isCanceled = false;
+};
+
} // namespace repl
} // namespace mongo