summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/check_quorum_for_config_change.h
diff options
context:
space:
mode:
authormatt dannenberg <matt.dannenberg@10gen.com>2014-09-26 13:18:30 -0400
committermatt dannenberg <matt.dannenberg@10gen.com>2014-10-03 05:52:03 -0400
commitf2d504cd0fcbcff26e74415978696d8218cccb6a (patch)
treeaa8ba5588b7acfcff849cffb8c95f727e85cbba6 /src/mongo/db/repl/check_quorum_for_config_change.h
parentd7a1df26287a4f0e0cfbf842a7c6257bc44e4567 (diff)
downloadmongo-f2d504cd0fcbcff26e74415978696d8218cccb6a.tar.gz
SERVER-15249 move QuorumCheck class declaration to header file for testing
Diffstat (limited to 'src/mongo/db/repl/check_quorum_for_config_change.h')
-rw-r--r--src/mongo/db/repl/check_quorum_for_config_change.h82
1 files changed, 78 insertions, 4 deletions
diff --git a/src/mongo/db/repl/check_quorum_for_config_change.h b/src/mongo/db/repl/check_quorum_for_config_change.h
index be824d3bf98..04f3f87b340 100644
--- a/src/mongo/db/repl/check_quorum_for_config_change.h
+++ b/src/mongo/db/repl/check_quorum_for_config_change.h
@@ -28,14 +28,88 @@
#pragma once
-namespace mongo {
-
- class Status;
+#include "mongo/base/status.h"
+#include "mongo/db/repl/replication_executor.h"
+#include "mongo/db/repl/scatter_gather_algorithm.h"
+namespace mongo {
namespace repl {
class ReplicaSetConfig;
- class ReplicationExecutor;
+
+ /**
+ * Quorum checking state machine.
+ *
+ * Usage: Construct a QuorumChecker, pass in a pointer to the configuration for which you're
+ * checking quorum, and the integer index of the member config representing the "executing"
+ * node. Use ScatterGatherRunner or otherwise execute a scatter-gather procedure as described
+ * in the class comment for the ScatterGatherAlgorithm class. After
+ * hasReceivedSufficientResponses() returns true, you may call getFinalStatus() to get the
+ * result of the quorum check.
+ */
+ class QuorumChecker : public ScatterGatherAlgorithm {
+ MONGO_DISALLOW_COPYING(QuorumChecker);
+ public:
+ /**
+ * Constructs a QuorumChecker that is used to confirm that sufficient nodes are up to accept
+ * "rsConfig". "myIndex" is the index of the local node, which is assumed to be up.
+ *
+ * "rsConfig" must stay in scope until QuorumChecker's destructor completes.
+ */
+ QuorumChecker(const ReplicaSetConfig* rsConfig, int myIndex);
+ virtual ~QuorumChecker();
+
+ virtual std::vector<ReplicationExecutor::RemoteCommandRequest> getRequests() const;
+ virtual void processResponse(
+ const ReplicationExecutor::RemoteCommandRequest& request,
+ const ResponseStatus& response);
+
+ virtual bool hasReceivedSufficientResponses() const;
+
+ Status getFinalStatus() const { return _finalStatus; }
+
+ private:
+ /**
+ * Callback that executes after _haveReceivedSufficientReplies() becomes true.
+ *
+ * Computes the quorum result based on responses received so far, stores it into
+ * _finalStatus, and enables QuorumChecker::run() to return.
+ */
+ void _onQuorumCheckComplete();
+
+ /**
+ * Updates the QuorumChecker state based on the data from a single heartbeat response.
+ */
+ void _tabulateHeartbeatResponse(
+ const ReplicationExecutor::RemoteCommandRequest& request,
+ const ResponseStatus& response);
+
+ // Pointer to the replica set configuration for which we're checking quorum.
+ const ReplicaSetConfig* const _rsConfig;
+
+ // Index of the local node's member configuration in _rsConfig.
+ const int _myIndex;
+
+ // List of nodes believed to be down.
+ std::vector<HostAndPort> _down;
+
+ // List of voting nodes that have responded affirmatively.
+ std::vector<HostAndPort> _voters;
+
+ // Total number of responses and timeouts processed.
+ int _numResponses;
+
+ // Number of electable nodes that have responded affirmatively.
+ int _numElectable;
+
+ // Set to a non-OK status if a response from a remote node indicates
+ // that the quorum check should definitely fail, such as because of
+ // a replica set name mismatch.
+ Status _vetoStatus;
+
+ // Final status of the quorum check, returned by run().
+ Status _finalStatus;
+ };
/**
* Performs a quorum call to determine if a sufficient number of nodes are up