summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/elect_cmd_runner.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/repl/elect_cmd_runner.h')
-rw-r--r--src/mongo/db/repl/elect_cmd_runner.h151
1 files changed, 77 insertions, 74 deletions
diff --git a/src/mongo/db/repl/elect_cmd_runner.h b/src/mongo/db/repl/elect_cmd_runner.h
index 2a9a7bab435..21295991f26 100644
--- a/src/mongo/db/repl/elect_cmd_runner.h
+++ b/src/mongo/db/repl/elect_cmd_runner.h
@@ -38,88 +38,91 @@
namespace mongo {
- class Status;
+class Status;
namespace repl {
- class ReplicaSetConfig;
- class ScatterGatherRunner;
+class ReplicaSetConfig;
+class ScatterGatherRunner;
- class ElectCmdRunner {
- MONGO_DISALLOW_COPYING(ElectCmdRunner);
+class ElectCmdRunner {
+ MONGO_DISALLOW_COPYING(ElectCmdRunner);
+
+public:
+ class Algorithm : public ScatterGatherAlgorithm {
public:
- class Algorithm : public ScatterGatherAlgorithm {
- public:
- Algorithm(const ReplicaSetConfig& rsConfig,
- int selfIndex,
- const std::vector<HostAndPort>& targets,
- OID round);
-
- virtual ~Algorithm();
- virtual std::vector<RemoteCommandRequest> getRequests() const;
- virtual void processResponse(
- const RemoteCommandRequest& request,
- const ResponseStatus& response);
- virtual bool hasReceivedSufficientResponses() const;
-
- int getReceivedVotes() const { return _receivedVotes; }
-
- private:
- // Tally of the number of received votes for this election.
- int _receivedVotes;
-
- // Number of responses received so far.
- size_t _actualResponses;
-
- bool _sufficientResponsesReceived;
-
- const ReplicaSetConfig _rsConfig;
- const int _selfIndex;
- const std::vector<HostAndPort> _targets;
- const OID _round;
- };
-
- ElectCmdRunner();
- ~ElectCmdRunner();
-
- /**
- * Begins the process of sending replSetElect commands to all non-DOWN nodes
- * in currentConfig.
- *
- * Returned handle can be used to schedule a callback when the process is complete.
- */
- StatusWith<ReplicationExecutor::EventHandle> start(
- ReplicationExecutor* executor,
- const ReplicaSetConfig& currentConfig,
- int selfIndex,
- const std::vector<HostAndPort>& targets,
- const stdx::function<void ()>& onCompletion = stdx::function<void ()>());
-
- /**
- * Informs the ElectCmdRunner 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);
-
- /**
- * Returns the number of received votes. Only valid to call after
- * the event handle returned from start() has been signaled, which guarantees that
- * the vote count will no longer be touched by callbacks.
- */
- int getReceivedVotes() const;
-
- /**
- * Returns true if cancel() was called on this instance.
- */
- bool isCanceled() const { return _isCanceled; }
+ Algorithm(const ReplicaSetConfig& rsConfig,
+ int selfIndex,
+ const std::vector<HostAndPort>& targets,
+ OID round);
+
+ virtual ~Algorithm();
+ virtual std::vector<RemoteCommandRequest> getRequests() const;
+ virtual void processResponse(const RemoteCommandRequest& request,
+ const ResponseStatus& response);
+ virtual bool hasReceivedSufficientResponses() const;
+
+ int getReceivedVotes() const {
+ return _receivedVotes;
+ }
private:
- std::unique_ptr<Algorithm> _algorithm;
- std::unique_ptr<ScatterGatherRunner> _runner;
- bool _isCanceled;
+ // Tally of the number of received votes for this election.
+ int _receivedVotes;
+
+ // Number of responses received so far.
+ size_t _actualResponses;
+
+ bool _sufficientResponsesReceived;
+
+ const ReplicaSetConfig _rsConfig;
+ const int _selfIndex;
+ const std::vector<HostAndPort> _targets;
+ const OID _round;
};
+ ElectCmdRunner();
+ ~ElectCmdRunner();
+
+ /**
+ * Begins the process of sending replSetElect commands to all non-DOWN nodes
+ * in currentConfig.
+ *
+ * Returned handle can be used to schedule a callback when the process is complete.
+ */
+ StatusWith<ReplicationExecutor::EventHandle> start(
+ ReplicationExecutor* executor,
+ const ReplicaSetConfig& currentConfig,
+ int selfIndex,
+ const std::vector<HostAndPort>& targets,
+ const stdx::function<void()>& onCompletion = stdx::function<void()>());
+
+ /**
+ * Informs the ElectCmdRunner 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);
+
+ /**
+ * Returns the number of received votes. Only valid to call after
+ * the event handle returned from start() has been signaled, which guarantees that
+ * the vote count will no longer be touched by callbacks.
+ */
+ int getReceivedVotes() const;
+
+ /**
+ * Returns true if cancel() was called on this instance.
+ */
+ bool isCanceled() const {
+ return _isCanceled;
+ }
+
+private:
+ std::unique_ptr<Algorithm> _algorithm;
+ std::unique_ptr<ScatterGatherRunner> _runner;
+ bool _isCanceled;
+};
}
}