diff options
Diffstat (limited to 'src/mongo/db/repl/topology_coordinator.h')
-rw-r--r-- | src/mongo/db/repl/topology_coordinator.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/mongo/db/repl/topology_coordinator.h b/src/mongo/db/repl/topology_coordinator.h index d61ef4502bf..797f1beecb5 100644 --- a/src/mongo/db/repl/topology_coordinator.h +++ b/src/mongo/db/repl/topology_coordinator.h @@ -31,6 +31,7 @@ #include <functional> #include <iosfwd> +#include <queue> #include <string> #include "mongo/client/read_preference.h" @@ -76,6 +77,37 @@ class TopologyCoordinator { public: /** + * RecentSyncSourceChanges stores the times that recent sync source changes happened. It will + * maintain a max size of maxSyncSourceChangesPerHour. If any additional entries are added, + * older entries will be removed. It is used to restrict the number of sync source changes that + * happen per hour when the node already has a valid sync source. + */ + class RecentSyncSourceChanges { + public: + /** + * Checks if all the entries occurred within the last hour or not. It will remove additional + * entries if it sees that there are more than maxSyncSourceChangesPerHour entries. If there + * are fewer than maxSyncSourceChangesPerHour entries, it returns false. + */ + bool changedTooOftenRecently(Date_t now); + + /** + * Adds a new entry. It will remove additional entries if it sees that there are more than + * maxSyncSourceChangesPerHour entries. This should only be called if the sync source was + * changed to another node, not if the sync source was cleared. + */ + void addNewEntry(Date_t now); + + /** + * Return the underlying queue. Used for testing purposes only. + */ + std::queue<Date_t> getChanges_forTest(); + + private: + std::queue<Date_t> _recentChanges; + }; + + /** * Type that denotes the role of a node in the replication protocol. * * The role is distinct from MemberState, in that it only deals with the @@ -784,6 +816,13 @@ public: const Timestamp& electionTime = Timestamp(0, 0)); /** + * Get a raw pointer to the list of recent sync source changes. It is the caller's + * responsibility to not use this pointer beyond the lifetime of the object. Used for testing + * only. + */ + RecentSyncSourceChanges* getRecentSyncSourceChanges_forTest(); + + /** * Change config (version, term) of each member in the initial test config so that * it will be majority replicated without having to mock heartbeats. */ @@ -1076,6 +1115,8 @@ private: // Whether or not the storage engine supports read committed. ReadCommittedSupport _storageEngineSupportsReadCommitted{ReadCommittedSupport::kUnknown}; + + RecentSyncSourceChanges _recentSyncSourceChanges; }; /** |