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

« back to all changes in this revision

Viewing changes to src/mongo/db/d_concurrency.cpp

  • 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
#include "server.h"
32
32
#include "dur.h"
33
33
#include "lockstat.h"
 
34
#include "mongo/db/commands/server_status.h"
34
35
 
35
36
// oplog locking
36
37
// no top level read locks
60
61
 
61
62
    class DBTryLockTimeoutException : public std::exception {
62
63
    public:
63
 
        DBTryLockTimeoutException() {}
64
 
        virtual ~DBTryLockTimeoutException() throw() { }
 
64
        DBTryLockTimeoutException() {}
 
65
        virtual ~DBTryLockTimeoutException() throw() { }
65
66
    };
66
67
 
67
68
    namespace dur { 
82
83
       in different directories with the same name, it will be ok but they are sharing a lock 
83
84
       then.
84
85
    */
85
 
    static mapsf<string,WrapperForRWLock*> dblocks;
 
86
    typedef mapsf< StringMap<WrapperForRWLock*> > DBLocksMap;
 
87
    static DBLocksMap dblocks;
86
88
 
87
89
    /* we don't want to touch dblocks too much as a mutex is involved.  thus party for that, 
88
90
       this is here...
200
202
        return &qlk.stats;
201
203
    }
202
204
    
203
 
    void reportLockStats(BSONObjBuilder& result) {
204
 
        BSONObjBuilder b;
205
 
        b.append(".", qlk.stats.report());
206
 
        b.append("admin", nestableLocks[Lock::admin]->stats.report());
207
 
        b.append("local", nestableLocks[Lock::local]->stats.report());
208
 
        {
209
 
            mapsf<string,WrapperForRWLock*>::ref r(dblocks);
210
 
            for( map<string,WrapperForRWLock*>::const_iterator i = r.r.begin(); i != r.r.end(); i++ ) {
211
 
                b.append(i->first, i->second->stats.report());
212
 
            }
213
 
        }
214
 
        result.append("locks", b.obj());
215
 
    }
216
 
 
217
205
    int Lock::isLocked() {
218
206
        return threadState();
219
207
    }
520
508
        }
521
509
    }
522
510
 
523
 
    void Lock::DBWrite::lockOther(const string& db) {
 
511
    void Lock::DBWrite::lockOther(const StringData& db) {
524
512
        fassert( 16252, !db.empty() );
525
513
        LockState& ls = lockState();
526
514
 
537
525
 
538
526
        if( db != ls.otherName() )
539
527
        {
540
 
            mapsf<string,WrapperForRWLock*>::ref r(dblocks);
 
528
            DBLocksMap::ref r(dblocks);
541
529
            WrapperForRWLock*& lock = r[db];
542
530
            if( lock == 0 )
543
 
                lock = new WrapperForRWLock(db.c_str());
 
531
                lock = new WrapperForRWLock(db);
544
532
            ls.lockedOther( db , 1 , lock );
545
533
        }
546
534
        else { 
553
541
        _weLocked = ls.otherLock();
554
542
    }
555
543
 
556
 
    static Lock::Nestable n(const char *db) { 
557
 
        if( str::equals(db, "local") )
 
544
    static Lock::Nestable n(const StringData& db) { 
 
545
        if( db == "local" )
558
546
            return Lock::local;
559
 
        if( str::equals(db, "admin") )
 
547
        if( db == "admin" )
560
548
            return Lock::admin;
561
549
        return Lock::notnestable;
562
550
    }
576
564
            return;
577
565
 
578
566
        if (DB_LEVEL_LOCKING_ENABLED) {
579
 
            char db[MaxDatabaseNameLen];
580
 
            nsToDatabase(ns.data(), db);
 
567
            StringData db = nsToDatabaseSubstring( ns );
581
568
            Nestable nested = n(db);
582
569
            if( nested == admin ) { 
583
570
                // we can't nestedly lock both admin and local as implemented. so lock_W.
608
595
        if ( ls.isRW() )
609
596
            return;
610
597
        if (DB_LEVEL_LOCKING_ENABLED) {
611
 
            char db[MaxDatabaseNameLen];
612
 
            nsToDatabase(ns.data(), db);
 
598
            StringData db = nsToDatabaseSubstring(ns);
613
599
            Nestable nested = n(db);
614
600
            if( !nested )
615
601
                lockOther(db);
623
609
        }
624
610
    }
625
611
 
626
 
    Lock::DBWrite::DBWrite( const StringData& ns ) 
627
 
        : ScopedLock( 'w' ), _what(ns.data()), _nested(false) {
 
612
    Lock::DBWrite::DBWrite( const StringData& ns )
 
613
        : ScopedLock( 'w' ), _what(ns.toString()), _nested(false) {
628
614
        lockDB( _what );
629
615
    }
630
616
 
631
 
    Lock::DBRead::DBRead( const StringData& ns )   
632
 
        : ScopedLock( 'r' ), _what(ns.data()), _nested(false) {
 
617
    Lock::DBRead::DBRead( const StringData& ns )
 
618
        : ScopedLock( 'r' ), _what(ns.toString()), _nested(false) {
633
619
        lockDB( _what );
634
620
    }
635
621
 
712
698
        }
713
699
    }
714
700
 
715
 
    void Lock::DBRead::lockOther(const string& db) {
 
701
    void Lock::DBRead::lockOther(const StringData& db) {
716
702
        fassert( 16255, !db.empty() );
717
703
        LockState& ls = lockState();
718
704
 
729
715
 
730
716
        if( db != ls.otherName() )
731
717
        {
732
 
            mapsf<string,WrapperForRWLock*>::ref r(dblocks);
 
718
            DBLocksMap::ref r(dblocks);
733
719
            WrapperForRWLock*& lock = r[db];
734
720
            if( lock == 0 )
735
 
                lock = new WrapperForRWLock(db.c_str());
 
721
                lock = new WrapperForRWLock(db);
736
722
            ls.lockedOther( db , -1 , lock );
737
723
        }
738
724
        else { 
813
799
        dur::releasingWriteLock();
814
800
    }
815
801
 
 
802
    class GlobalLockServerStatusSection : public ServerStatusSection {
 
803
    public:
 
804
        GlobalLockServerStatusSection() : ServerStatusSection( "globalLock" ){
 
805
            _started = curTimeMillis64();
 
806
        }
 
807
 
 
808
        virtual bool includeByDefault() const { return true; }
 
809
 
 
810
        virtual BSONObj generateSection( const BSONElement& configElement ) const {
 
811
            BSONObjBuilder t;
 
812
 
 
813
            t.append( "totalTime" , (long long)(1000 * ( curTimeMillis64() - _started ) ) );
 
814
            t.append( "lockTime" , Lock::globalLockStat()->getTimeLocked( 'W' ) );
 
815
 
 
816
            {
 
817
                BSONObjBuilder ttt( t.subobjStart( "currentQueue" ) );
 
818
                int w=0, r=0;
 
819
                Client::recommendedYieldMicros( &w , &r, true );
 
820
                ttt.append( "total" , w + r );
 
821
                ttt.append( "readers" , r );
 
822
                ttt.append( "writers" , w );
 
823
                ttt.done();
 
824
            }
 
825
 
 
826
            {
 
827
                BSONObjBuilder ttt( t.subobjStart( "activeClients" ) );
 
828
                int w=0, r=0;
 
829
                Client::getActiveClientCount( w , r );
 
830
                ttt.append( "total" , w + r );
 
831
                ttt.append( "readers" , r );
 
832
                ttt.append( "writers" , w );
 
833
                ttt.done();
 
834
            }
 
835
 
 
836
            return t.obj();
 
837
        }
 
838
 
 
839
    private:
 
840
        unsigned long long _started;
 
841
 
 
842
    } globalLockServerStatusSection;
 
843
 
 
844
    class LockStatsServerStatusSection : public ServerStatusSection {
 
845
    public:
 
846
        LockStatsServerStatusSection() : ServerStatusSection( "locks" ){}
 
847
        virtual bool includeByDefault() const { return true; }
 
848
 
 
849
        BSONObj generateSection( const BSONElement& configElement ) const {
 
850
            BSONObjBuilder b;
 
851
            b.append(".", qlk.stats.report());
 
852
            b.append("admin", nestableLocks[Lock::admin]->stats.report());
 
853
            b.append("local", nestableLocks[Lock::local]->stats.report());
 
854
            {
 
855
                DBLocksMap::ref r(dblocks);
 
856
                for( DBLocksMap::const_iterator i = r.r.begin(); i != r.r.end(); ++i ) {
 
857
                    b.append(i->first, i->second->stats.report());
 
858
                }
 
859
            }
 
860
            return b.obj();
 
861
        }
 
862
 
 
863
    } lockStatsServerStatusSection;
 
864
 
816
865
}