77
78
bool potentiallyHot() const { return _config.potentiallyHot(); } // not arbiter, not priority 0
78
79
void summarizeMember(stringstream& s) const;
80
// If we could sync from this member. This doesn't tell us anything about the quality of
81
// this member, just if they are a possible sync target.
82
bool syncable() const;
81
85
friend class ReplSetImpl;
298
void parseReplsetCmdLine(string cfgString, string& setname, vector<HostAndPort>& seeds, set<HostAndPort>& seedSet );
300
void parseReplsetCmdLine(const std::string& cfgString,
302
vector<HostAndPort>& seeds,
303
set<HostAndPort>& seedSet);
300
305
/** Parameter given to the --replSet command line option (parsed).
301
306
Syntax is "<setname>/<seedhost1>,<seedhost2>"
302
307
where setname is a name and seedhost is "<host>[:<port>]" */
303
308
class ReplSetCmdline {
305
ReplSetCmdline(string cfgString) { parseReplsetCmdLine(cfgString, setname, seeds, seedSet); }
310
ReplSetCmdline(const std::string& cfgString) { parseReplsetCmdLine(cfgString, setname, seeds, seedSet); }
307
312
vector<HostAndPort> seeds;
308
313
set<HostAndPort> seedSet;
331
336
OpTime lastOpTimeWritten;
332
337
long long lastH; // hash we use to make sure we are reading the right flow of ops and aren't on an out-of-date "fork"
333
338
bool forceSyncFrom(const string& host, string& errmsg, BSONObjBuilder& result);
339
// Check if the current sync target is suboptimal. This must be called while holding a mutex
340
// that prevents the sync source from changing.
341
bool shouldChangeSyncTarget(const OpTime& target) const;
336
344
* Find the closest member (using ping time) with a higher latest optime.
338
Member* getMemberToSyncTo();
346
const Member* getMemberToSyncTo();
339
347
void veto(const string& host, unsigned secs=10);
340
348
bool gotForceSync();
341
349
void goStale(const Member* m, const BSONObj& o);
368
376
char _hbmsg[256]; // we change this unlocked, thus not an stl::string
369
377
time_t _hbmsgTime; // when it was logged
371
void sethbmsg(string s, int logLevel = 0);
379
void sethbmsg(const std::string& s, int logLevel = 0);
374
382
* Election with Priorities
427
435
void _summarizeAsHtml(stringstream&) const;
428
436
void _summarizeStatus(BSONObjBuilder&) const; // for replSetGetStatus command
430
/* throws exception if a problem initializing. */
431
ReplSetImpl(ReplSetCmdline&);
435
438
/* call afer constructing to start - returns fairly quickly after launching its threads */
444
447
* Finds the configuration with the highest version number and attempts
447
bool _loadConfigFinish(vector<ReplSetConfig>& v);
450
bool _loadConfigFinish(vector<ReplSetConfig*>& v);
449
452
* Gather all possible configs (from command line seeds, our own config
450
453
* doc, and any hosts listed therein) and try to initiate from the most
464
467
bool _buildIndexes; // = _self->config().buildIndexes
470
/* throws exception if a problem initializing. */
471
void init(ReplSetCmdline&);
465
473
void setSelfTo(Member *); // use this as it sets buildIndexes var
467
475
List1<Member> _members; // all members of the set EXCEPT _self.
485
493
Member* head() const { return _members.head(); }
487
495
const Member* findById(unsigned id) const;
496
Member* findByName(const std::string& hostname) const;
489
498
void _getTargets(list<Target>&, int &configVersion);
490
499
void getTargets(list<Target>&, int &configVersion);
497
506
friend class Consensus;
500
bool _syncDoInitialSync_clone( const char *master, const list<string>& dbs , bool dataPass );
509
bool _syncDoInitialSync_clone(Cloner &cloner, const char *master,
510
const list<string>& dbs, bool dataPass);
501
511
bool _syncDoInitialSync_applyToHead( replset::SyncTail& syncer, OplogReader* r ,
502
512
const Member* source, const BSONObj& lastOp,
503
513
BSONObj& minValidOut);
533
543
threadpool::ThreadPool& getPrefetchPool() { return _prefetcherPool; }
534
544
threadpool::ThreadPool& getWriterPool() { return _writerPool; }
546
static const int maxSyncSourceLagSecs;
537
548
const ReplSetConfig::MemberCfg& myConfig() const { return _config; }
538
549
bool tryToGoLiveAsASecondary(OpTime&); // readlocks
539
550
void syncRollback(OplogReader& r);
540
551
void syncThread();
541
552
const OpTime lastOtherOpTime() const;
555
* When a member reaches its minValid optime it is in a consistent state. Thus, minValid is
556
* set as the last step in initial sync. At the beginning of initial sync, _initialSyncFlag
557
* is appended onto minValid to indicate that initial sync was started but has not yet
559
* minValid is also used during "normal" sync: the last op in each batch is used to set
560
* minValid, to indicate that we are in a consistent state when the batch has been fully
542
563
static void setMinValid(BSONObj obj);
564
static OpTime getMinValid();
565
static void clearInitialSyncFlag();
566
static bool getInitialSyncFlag();
567
static void setInitialSyncFlag();
544
569
int oplogVersion;
546
571
IndexPrefetchConfig _indexPrefetchConfig;
573
static const char* _initialSyncFlagString;
574
static const BSONObj _initialSyncFlag;
549
577
class ReplSet : public ReplSetImpl {
552
ReplSet(ReplSetCmdline& replSetCmdline);
579
static ReplSet* make(ReplSetCmdline& replSetCmdline);
553
580
virtual ~ReplSet() {}
555
582
// for the replSetStepDown command
620
650
virtual LockType locktype() const { return NONE; }
621
651
virtual void help( stringstream &help ) const { help << "internal"; }
624
* Some replica set commands call this and then call check(). This is
625
* intentional, as they might do things before theReplSet is initialized
626
* that still need to be checked for auth.
628
bool checkAuth(string& errmsg, BSONObjBuilder& result) {
630
AuthenticationInfo *ai = cc().getAuthenticationInfo();
631
if (!ai->isAuthorizedForLock("admin", locktype())) {
632
errmsg = "replSet command unauthorized";
639
653
bool check(string& errmsg, BSONObjBuilder& result) {
641
655
errmsg = "not running with --replSet";