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

« back to all changes in this revision

Viewing changes to src/mongo/client/dbclient_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:
31
31
 
32
32
    class ReplicaSetMonitor;
33
33
    class TagSet;
 
34
    struct ReadPreferenceSetting;
34
35
    typedef shared_ptr<ReplicaSetMonitor> ReplicaSetMonitorPtr;
35
36
    typedef pair<set<string>,set<int> > NodeDiff;
36
37
 
38
39
     * manages state about a replica set for client
39
40
     * keeps tabs on whose master and what slaves are up
40
41
     * can hand a slave to someone for SLAVE_OK
41
 
     * one instace per process per replica set
 
42
     * one instance per process per replica set
42
43
     * TODO: we might be able to use a regular Node * to avoid _lock
43
44
     */
44
45
    class ReplicaSetMonitor {
45
46
    public:
46
 
 
47
47
        typedef boost::function1<void,const ReplicaSetMonitor*> ConfigChangeHook;
48
48
 
49
49
        /**
133
133
 
134
134
        };
135
135
 
 
136
        static const double SOCKET_TIMEOUT_SECS;
 
137
 
136
138
        /**
137
139
         * Selects the right node given the nodes to pick from and the preference.
138
140
         *
190
192
         */
191
193
        static ReplicaSetMonitorPtr get( const string& name, const bool createFromSeed = false );
192
194
 
 
195
        /**
 
196
         * Populates activeSets with all the currently tracked replica set names.
 
197
         */
 
198
        static void getAllTrackedSets(set<string>* activeSets);
193
199
 
194
200
        /**
195
201
         * checks all sets for current master and new secondaries
426
432
         */
427
433
        bool connect();
428
434
 
429
 
        /** Authorize.  Authorizes all nodes as needed
430
 
        */
431
 
        virtual bool auth(const string &dbname, const string &username, const string &pwd, string& errmsg, bool digestPassword = true, Auth::Level * level = NULL);
432
 
 
433
435
        /**
434
436
         * Logs out the connection for the given database.
435
437
         *
469
471
         * @return the reference to the address that points to the master connection.
470
472
         */
471
473
        DBClientConnection& masterConn();
 
474
 
 
475
        /**
 
476
         * WARNING: this method is very dangerous - this object can decide to free the
 
477
         *     returned master connection any time. This can also unpin the cached
 
478
         *     slaveOk/read preference connection.
 
479
         *
 
480
         * @return the reference to the address that points to a secondary connection.
 
481
         */
472
482
        DBClientConnection& slaveConn();
473
483
 
474
484
        // ---- callback pieces -------
507
517
 
508
518
 
509
519
    protected:
 
520
        /** Authorize.  Authorizes all nodes as needed
 
521
        */
 
522
        virtual void _auth(const BSONObj& params);
 
523
 
510
524
        virtual void sayPiggyBack( Message &toSend ) { checkMaster()->say( toSend ); }
511
525
 
512
526
    private:
525
539
         * Helper method for selecting a node based on the read preference. Will advance
526
540
         * the tag tags object if it cannot find a node that matches the current tag.
527
541
         *
528
 
         * @param preference the preference to use for selecting a node
529
 
         * @param tags pointer to the list of tags.
 
542
         * @param readPref the preference to use for selecting a node.
530
543
         *
531
544
         * @return a pointer to the new connection object if it can find a good connection.
532
545
         *     Otherwise it returns NULL.
534
547
         * @throws DBException when an error occurred either when trying to connect to
535
548
         *     a node that was thought to be ok or when an assertion happened.
536
549
         */
537
 
        DBClientConnection* selectNodeUsingTags(ReadPreference preference,
538
 
                                                TagSet* tags);
 
550
        DBClientConnection* selectNodeUsingTags(shared_ptr<ReadPreferenceSetting> readPref);
539
551
 
540
552
        /**
541
553
         * @return true if the last host used in the last slaveOk query is still in the
542
554
         * set and can be used for the given read preference.
543
555
         */
544
 
        bool checkLastHost( ReadPreference preference, const TagSet* tags );
 
556
        bool checkLastHost(const ReadPreferenceSetting* readPref);
545
557
 
546
558
        /**
547
559
         * Destroys all cached information about the last slaveOk operation.
574
586
        HostAndPort _lastSlaveOkHost;
575
587
        // Last used connection in a slaveOk query (can be a primary)
576
588
        boost::shared_ptr<DBClientConnection> _lastSlaveOkConn;
 
589
        boost::shared_ptr<ReadPreferenceSetting> _lastReadPref;
577
590
        
578
591
        double _so_timeout;
579
592
 
580
 
        /**
581
 
         * for storing authentication info
582
 
         * fields are exactly for DBClientConnection::auth
583
 
         */
584
 
        struct AuthInfo {
585
 
            // Default constructor provided only to make it compatible with std::map::operator[]
586
 
            AuthInfo(): digestPassword(false) { }
587
 
            AuthInfo( string d , string u , string p , bool di )
588
 
                : dbname( d ) , username( u ) , pwd( p ) , digestPassword( di ) {}
589
 
            string dbname;
590
 
            string username;
591
 
            string pwd;
592
 
            bool digestPassword;
593
 
        };
594
 
 
595
593
        // we need to store so that when we connect to a new node on failure
596
594
        // we can re-auth
597
595
        // this could be a security issue, as the password is stored in memory
598
596
        // not sure if/how we should handle
599
 
        std::map<string, AuthInfo> _auths; // dbName -> AuthInfo
 
597
        std::map<string, BSONObj> _auths; // dbName -> auth parameters
600
598
 
601
599
    protected:
602
600
 
619
617
     * A simple object for representing the list of tags. The initial state will
620
618
     * have a valid current tag as long as the list is not empty.
621
619
     */
622
 
    class TagSet : public boost::noncopyable { // because of BSONArrayIteratorSorted
 
620
    class TagSet {
623
621
    public:
624
622
        /**
625
623
         * Creates an empty tag list that is initially exhausted.
627
625
        TagSet();
628
626
 
629
627
        /**
 
628
         * Creates a copy of the given TagSet. The new copy will have the
 
629
         * iterator pointing at the initial position.
 
630
         */
 
631
        explicit TagSet(const TagSet& other);
 
632
 
 
633
        /**
630
634
         * Creates a tag set object that lazily iterates over the tag list.
631
635
         *
632
636
         * @param tags the list of tags associated with this option. This object
662
666
         */
663
667
        BSONObjIterator* getIterator() const;
664
668
 
 
669
        /**
 
670
         * @returns true if the other TagSet has the same tag set specification with
 
671
         *     this tag set, disregarding where the current iterator is pointing to.
 
672
         */
 
673
        bool equals(const TagSet& other) const;
 
674
 
665
675
    private:
 
676
        /**
 
677
         * This is purposely undefined as the semantics for assignment can be
 
678
         * confusing. This is because BSONArrayIteratorSorted shouldn't be
 
679
         * copied (because of how it manages internal buffer).
 
680
         */
 
681
        TagSet& operator=(const TagSet& other);
666
682
        BSONObj _currentTag;
667
683
        bool _isExhausted;
668
684
 
670
686
        BSONArray _tags;
671
687
        BSONArrayIteratorSorted _tagIterator;
672
688
    };
 
689
 
 
690
    struct ReadPreferenceSetting {
 
691
        /**
 
692
         * @parm pref the read preference mode.
 
693
         * @param tag the tag set. Note that this object will have the
 
694
         *     tag set will have this in a reset state (meaning, this
 
695
         *     object's copy of tag will have the iterator in the initial
 
696
         *     position).
 
697
         */
 
698
        ReadPreferenceSetting(ReadPreference pref, const TagSet& tag):
 
699
            pref(pref), tags(tag) {
 
700
        }
 
701
 
 
702
        inline bool equals(const ReadPreferenceSetting& other) const {
 
703
            return pref == other.pref && tags.equals(other.tags);
 
704
        }
 
705
 
 
706
        const ReadPreference pref;
 
707
        TagSet tags;
 
708
    };
673
709
}