18 #include <boost/shared_ptr.hpp>
22 #include "mongo/base/disallow_copying.h"
23 #include "mongo/base/string_data.h"
24 #include "mongo/stdx/functional.h"
25 #include "mongo/util/net/hostandport.h"
29 class ReplicaSetMonitor;
31 struct ReadPreferenceSetting;
32 typedef boost::shared_ptr<ReplicaSetMonitor> ReplicaSetMonitorPtr;
44 typedef stdx::function<void(const std::string& setName, const std::string& newConnectionString)>
134 static void createIfNeeded(
const std::string& name,
const std::set<HostAndPort>& servers);
141 static ReplicaSetMonitorPtr
get(
const std::string& name,
bool createFromSeed =
false);
153 static void remove(
const std::string& name,
bool clearSeedCache =
false);
200 typedef boost::shared_ptr<ScanState> ScanStatePtr;
201 typedef boost::shared_ptr<SetState> SetStatePtr;
220 const SetStatePtr _state;
243 return _refreshUntilMatches(&criteria);
253 _refreshUntilMatches(NULL);
266 explicit Refresher(
const SetStatePtr& setState);
276 : step(step), host(host) {}
305 return _startedNewScan;
330 void receivedIsMasterBeforeFoundMaster(
const IsMasterReply& reply);
342 bool _startedNewScan;
bool isKnownToHaveGoodPrimary() const
Returns true if the monitor knows a usable primary from it's interal view.
Wait on condition variable and try again.
Definition: replica_set_monitor.h:272
Definition: dbclient_rs.h:363
Refresher(const SetStatePtr &setState)
Any passed-in pointers are shared with caller.
Status represents an error state or the absence thereof.
Definition: status.h:50
static void createIfNeeded(const std::string &name, const std::set< HostAndPort > &servers)
Creates a new ReplicaSetMonitor, if it doesn't already exist.
Definition: replica_set_monitor.h:268
void refreshAll()
Refresh all hosts.
Definition: replica_set_monitor.h:252
static int maxConsecutiveFailedChecks
If a ReplicaSetMonitor has been refreshed more than this many times in a row without finding any live...
Definition: replica_set_monitor.h:191
HostAndPort getMasterOrUassert()
Returns the host we think is the current master or uasserts.
ReplicaSetMonitor(const SetStatePtr &initialState)
Allows tests to set initial conditions and introspect the current state.
Definition: replica_set_monitor.h:210
static Status initialize()
Starts the ReplicaSetMonitorWatcher.
StepKind
Definition: replica_set_monitor.h:269
A StringData object wraps a 'const string&' or a 'const char*' without copying its contents...
Definition: string_data.h:43
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
bool isHostUp(const HostAndPort &host) const
Returns true if host is part of this set and is considered up (meaning it can accept queries)...
std::string getServerAddress() const
Returns a string with the format name/server1,server2.
void failedHost(const HostAndPort &host)
Notifies this Monitor that a host has failed and should be considered down.
Definition: replica_set_monitor_internal.h:117
static bool useDeterministicHostSelection
Defaults to false, meaning that if multiple hosts meet a criteria we pick one at random.
Definition: replica_set_monitor.h:217
Contact the returned host.
Definition: replica_set_monitor.h:271
std::string getName() const
The name of the set.
int getConsecutiveFailedScans() const
How may times in a row have we tried to refresh without successfully contacting any hosts who claim t...
Utility for creating a BSONObj.
Definition: bsonobjbuilder.h:53
HostAndPort getHostOrRefresh(const ReadPreferenceSetting &criteria)
Returns a host matching criteria or an empty HostAndPort if no host matches.
Definition: replica_set_monitor_internal.h:223
static std::set< std::string > getAllTrackedSets()
Returns all the currently tracked replica set names.
bool startedNewScan() const
True if this Refresher started a new full scan rather than joining an existing one.
Definition: replica_set_monitor.h:304
bool contains(const HostAndPort &server) const
Is server part of this set? Uses only cached information.
Holds state about a replica set and provides a means to refresh the local view.
Definition: replica_set_monitor.h:38
bool isPrimary(const HostAndPort &host) const
Returns true if this node is the master based ONLY on local data.
Refresher startOrContinueRefresh()
Returns a refresher object that can be used to update our view of the set.
static ScanStatePtr startNewScan(const SetState *set)
Starts a new scan over the hosts in set.
Name of a process on the network.
Definition: hostandport.h:37
void receivedIsMaster(const HostAndPort &from, int64_t latencyMicros, const BSONObj &reply)
Call this if a host returned from getNextStep successfully replied to an isMaster call...
NextStep getNextStep()
Returns the next step to take.
void appendInfo(BSONObjBuilder &b) const
Writes information about our cached view of the set to a BSONObjBuilder.
static void setConfigChangeHook(ConfigChangeHook hook)
Sets the hook to be called whenever the config of any replica set changes.
ReplicaSetMonitor(StringData name, const std::set< HostAndPort > &seeds)
Initializes local state.
void failedHost(const HostAndPort &host)
Call this if a host returned from getNextStep failed to reply to an isMaster call.
Refreshes the local view of a replica set.
Definition: replica_set_monitor.h:234
static Status shutdown(int gracePeriodMillis=0)
Permanently stops all monitoring on replica sets and clears all cached information as well...
Definition: replica_set_monitor_internal.h:89
HostAndPort refreshUntilMatches(const ReadPreferenceSetting &criteria)
Contact hosts in the set to refresh our view, but stop once a host matches criteria.
Definition: replica_set_monitor.h:242
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary represent...
Definition: bsonobj.h:78