~evarlast/ubuntu/trusty/mongodb/upstart-workaround-debian-bug-718702

« back to all changes in this revision

Viewing changes to src/mongo/db/repl/rs.h

  • Committer: Package Import Robot
  • Author(s): James Page, James Page, Robie Basak
  • Date: 2013-05-29 17:44:42 UTC
  • mfrom: (44.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20130529174442-z0a4qmoww4y0t458
Tags: 1:2.4.3-1ubuntu1
[ James Page ]
* Merge from Debian unstable, remaining changes:
  - Enable SSL support:
    + d/control: Add libssl-dev to BD's.
    + d/rules: Enabled --ssl option.
    + d/mongodb.conf: Add example SSL configuration options.
  - d/mongodb-server.mongodb.upstart: Add upstart configuration.
  - d/rules: Don't strip binaries during scons build for Ubuntu.
  - d/control: Add armhf to target archs.
  - d/p/SConscript.client.patch: fixup install of client libraries.
  - d/p/0010-install-libs-to-usr-lib-not-usr-lib64-Closes-588557.patch:
    Install libraries to lib not lib64.
* Dropped changes:
  - d/p/arm-support.patch: Included in Debian.
  - d/p/double-alignment.patch: Included in Debian.
  - d/rules,control: Debian also builds with avaliable system libraries
    now.
* Fix FTBFS due to gcc and boost upgrades in saucy:
  - d/p/0008-ignore-unused-local-typedefs.patch: Add -Wno-unused-typedefs
    to unbreak building with g++-4.8.
  - d/p/0009-boost-1.53.patch: Fixup signed/unsigned casting issue.

[ Robie Basak ]
* d/p/0011-Use-a-signed-char-to-store-BSONType-enumerations.patch: Fixup
  build failure on ARM due to missing signed'ness of char cast.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
 
48
48
namespace mongo {
49
49
 
 
50
    class Cloner;
 
51
    class DBClientConnection;
50
52
    struct HowToFixUp;
51
 
    struct Target;
52
 
    class DBClientConnection;
 
53
    class OplogReader;
53
54
    class ReplSetImpl;
54
 
    class OplogReader;
 
55
    struct Target;
55
56
    extern bool replSet; // true if using repl sets
56
57
    extern class ReplSet *theReplSet; // null until initialized
57
58
    extern Tee *rsLog;
76
77
 
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;
79
83
 
80
84
    private:
81
85
        friend class ReplSetImpl;
147
151
        void updateSlave(const mongo::OID& id, const OpTime& last);
148
152
    };
149
153
 
150
 
    struct Target;
151
 
 
152
154
    class Consensus {
153
155
        ReplSetImpl &rs;
154
156
        struct LastYea {
295
297
        SP sp;
296
298
    };
297
299
 
298
 
    void parseReplsetCmdLine(string cfgString, string& setname, vector<HostAndPort>& seeds, set<HostAndPort>& seedSet );
 
300
    void parseReplsetCmdLine(const std::string& cfgString,
 
301
                             string& setname,
 
302
                             vector<HostAndPort>& seeds,
 
303
                             set<HostAndPort>& seedSet);
299
304
 
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 {
304
309
    public:
305
 
        ReplSetCmdline(string cfgString) { parseReplsetCmdLine(cfgString, setname, seeds, seedSet); }
 
310
        ReplSetCmdline(const std::string& cfgString) { parseReplsetCmdLine(cfgString, setname, seeds, seedSet); }
306
311
        string setname;
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;
334
342
 
335
343
        /**
336
344
         * Find the closest member (using ping time) with a higher latest optime.
337
345
         */
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
370
378
    public:
371
 
        void sethbmsg(string s, int logLevel = 0);
 
379
        void sethbmsg(const std::string& s, int logLevel = 0);
372
380
 
373
381
        /**
374
382
         * Election with Priorities
427
435
        void _summarizeAsHtml(stringstream&) const;
428
436
        void _summarizeStatus(BSONObjBuilder&) const; // for replSetGetStatus command
429
437
 
430
 
        /* throws exception if a problem initializing. */
431
 
        ReplSetImpl(ReplSetCmdline&);
432
 
        // used for testing
433
 
        ReplSetImpl();
434
 
 
435
438
        /* call afer constructing to start - returns fairly quickly after launching its threads */
436
439
        void _go();
437
440
 
444
447
         * Finds the configuration with the highest version number and attempts
445
448
         * load it.
446
449
         */
447
 
        bool _loadConfigFinish(vector<ReplSetConfig>& v);
 
450
        bool _loadConfigFinish(vector<ReplSetConfig*>& v);
448
451
        /**
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
462
465
    protected:
463
466
        Member *_self;
464
467
        bool _buildIndexes;       // = _self->config().buildIndexes
 
468
 
 
469
        ReplSetImpl();
 
470
        /* throws exception if a problem initializing. */
 
471
        void init(ReplSetCmdline&);
 
472
 
465
473
        void setSelfTo(Member *); // use this as it sets buildIndexes var
466
474
    private:
467
475
        List1<Member> _members; // all members of the set EXCEPT _self.
485
493
        Member* head() const { return _members.head(); }
486
494
    public:
487
495
        const Member* findById(unsigned id) const;
 
496
        Member* findByName(const std::string& hostname) const;
488
497
    private:
489
498
        void _getTargets(list<Target>&, int &configVersion);
490
499
        void getTargets(list<Target>&, int &configVersion);
497
506
        friend class Consensus;
498
507
 
499
508
    private:
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; }
535
545
 
 
546
        static const int maxSyncSourceLagSecs;
536
547
 
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;
 
553
 
 
554
        /**
 
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 
 
558
         * completed.
 
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 
 
561
         * applied.
 
562
         */
542
563
        static void setMinValid(BSONObj obj);
543
 
        
 
564
        static OpTime getMinValid();
 
565
        static void clearInitialSyncFlag();
 
566
        static bool getInitialSyncFlag();
 
567
        static void setInitialSyncFlag();
 
568
 
544
569
        int oplogVersion;
545
570
    private:
546
571
        IndexPrefetchConfig _indexPrefetchConfig;
 
572
 
 
573
        static const char* _initialSyncFlagString;
 
574
        static const BSONObj _initialSyncFlag;
547
575
    };
548
576
 
549
577
    class ReplSet : public ReplSetImpl {
550
578
    public:
551
 
        ReplSet();
552
 
        ReplSet(ReplSetCmdline& replSetCmdline);
 
579
        static ReplSet* make(ReplSetCmdline& replSetCmdline);
553
580
        virtual ~ReplSet() {}
554
581
 
555
582
        // for the replSetStepDown command
605
632
            if( time(0)-_hbmsgTime > 120 ) return "";
606
633
            return _hbmsg;
607
634
        }
 
635
 
 
636
    protected:
 
637
        ReplSet();
608
638
    };
609
639
 
610
640
    /**
620
650
        virtual LockType locktype() const { return NONE; }
621
651
        virtual void help( stringstream &help ) const { help << "internal"; }
622
652
 
623
 
        /**
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.
627
 
         */
628
 
        bool checkAuth(string& errmsg, BSONObjBuilder& result) {
629
 
            if( !noauth ) {
630
 
                AuthenticationInfo *ai = cc().getAuthenticationInfo();
631
 
                if (!ai->isAuthorizedForLock("admin", locktype())) {
632
 
                    errmsg = "replSet command unauthorized";
633
 
                    return false;
634
 
                }
635
 
            }
636
 
            return true;
637
 
        }
638
 
 
639
653
        bool check(string& errmsg, BSONObjBuilder& result) {
640
654
            if( !replSet ) {
641
655
                errmsg = "not running with --replSet";
654
668
                return false;
655
669
            }
656
670
 
657
 
            return checkAuth(errmsg, result);
 
671
            return true;
658
672
        }
659
673
    };
660
674