Esempio n. 1
0
        void checkVersions( const string& ns ) {

            vector<Shard> all;
            Shard::getAllShards( all );

            // Don't report exceptions here as errors in GetLastError
            LastError::Disabled ignoreForGLE(lastError.get(false));

            // Now only check top-level shard connections
            for ( unsigned i=0; i<all.size(); i++ ) {

                Shard& shard = all[i];
                try {
                    string sconnString = shard.getConnString();
                    Status* s = _getStatus( sconnString );

                    if( ! s->avail ) {
                        s->avail = shardConnectionPool.get( sconnString );
                        s->created++; // After, so failed creation doesn't get counted
                    }

                    versionManager.checkShardVersionCB( s->avail, ns, false, 1 );
                }
                catch ( const DBException& ex ) {

                    warning() << "problem while initially checking shard versions on" << " "
                              << shard.getName() << causedBy( ex ) << endl;

                    // NOTE: This is only a heuristic, to avoid multiple stale version retries
                    // across multiple shards, and does not affect correctness.
                }
            }
        }
Esempio n. 2
0
        void checkVersions( const string& ns ) {

            vector<Shard> all;
            Shard::getAllShards( all );

            // Now only check top-level shard connections
            for ( unsigned i=0; i<all.size(); i++ ) {

                Shard& shard = all[i];
                try {
                    string sconnString = shard.getConnString();
                    Status* s = _getStatus( sconnString );

                    if( ! s->avail ) {
                        s->avail = shardConnectionPool.get( sconnString );
                        s->created++; // After, so failed creation doesn't get counted
                    }

                    versionManager.checkShardVersionCB( s->avail, ns, false, 1 );
                }
                catch ( const std::exception& e ) {

                    warning() << "problem while initially checking shard versions on"
                              << " " << shard.getName() << causedBy(e) << endl;
                    throw;
                }
            }
        }
Esempio n. 3
0
        void checkVersions( const string& ns ) {

            vector<Shard> all;
            Shard::getAllShards( all );

            // Now only check top-level shard connections
            for ( unsigned i=0; i<all.size(); i++ ) {

                Shard& shard = all[i];
                try {
                    string sconnString = shard.getConnString();
                    Status* &s = _hosts[sconnString];

                    if ( ! s ){
                        s = new Status();
                    }

                    if( ! s->avail )
                        s->avail = shardConnectionPool.get( sconnString );

                    versionManager.checkShardVersionCB( s->avail, ns, false, 1 );
                } catch(...) { 
                    LOGATMOST(2) << "exception in checkAllVersions shard:" << shard.getName() << endl;
                    throw;
                }
            }
        }
Esempio n. 4
0
        DBClientBase * get( const string& addr , const string& ns ) {
            _check( ns );

            Status* s = _getStatus( addr );

            auto_ptr<DBClientBase> c; // Handles cleanup if there's an exception thrown
            if ( s->avail ) {
                c.reset( s->avail );
                s->avail = 0;
                shardConnectionPool.onHandedOut( c.get() ); // May throw an exception
            } else {
                c.reset( shardConnectionPool.get( addr ) );
                s->created++; // After, so failed creation doesn't get counted
            }
            return c.release();
        }
Esempio n. 5
0
        DBClientBase * get( const string& addr , const string& ns, bool ignoreDirect = false ) {
            _check( ns );

            // Determine if non-shard conn is RS member for warning
            // All shards added to _hosts if not present in _check()
            if( ( logLevel >= 1 || ! printedShardConnWarning ) && ! ignoreDirect && _hosts.find( addr ) == _hosts.end() ){

                vector<Shard> all;
                Shard::getAllShards( all );

                bool isRSMember = false;
                string parentShard;
                for ( unsigned i = 0; i < all.size(); i++ ) {
                    string connString = all[i].getConnString();
                    if( connString.find( addr ) != string::npos && connString.find( '/' ) != string::npos ){
                        isRSMember = true;
                        parentShard = connString;
                        break;
                    }
                }

                if( isRSMember ){
                    printedShardConnWarning = true;
                    warning() << "adding shard sub-connection " << addr << " (parent " << parentShard << ") as sharded, this is safe but unexpected" << endl;
                    printStackTrace();
                }
            }


            Status* &s = _hosts[addr];
            if ( ! s )
                s = new Status();

            if ( s->avail ) {
                DBClientBase* c = s->avail;
                s->avail = 0;
                shardConnectionPool.onHandedOut( c );
                return c;
            }

            s->created++;
            return shardConnectionPool.get( addr );
        }
Esempio n. 6
0
        void checkVersions( const string& ns ) {

            vector<Shard> all;
            Shard::getAllShards( all );

            // Now only check top-level shard connections
            for ( unsigned i=0; i<all.size(); i++ ) {

                string sconnString = all[i].getConnString();
                Status* &s = _hosts[sconnString];

                if ( ! s ){
                    s = new Status();
                }

                if( ! s->avail )
                    s->avail = shardConnectionPool.get( sconnString );

                versionManager.checkShardVersionCB( s->avail, ns, false, 1 );

            }
        }
Esempio n. 7
0
        DBClientBase * get( const string& addr , const string& ns ) {
            _check( ns );

            Status* &s = _hosts[addr];
            if ( ! s )
                s = new Status();

            auto_ptr<DBClientBase> c; // Handles cleanup if there's an exception thrown
            if ( s->avail ) {
                c.reset( s->avail );
                s->avail = 0;
                shardConnectionPool.onHandedOut( c.get() ); // May throw an exception
            } else {
                s->created++;
                c.reset( shardConnectionPool.get( addr ) );
            }
            if ( !noauth ) {
                c->setAuthenticationTable( ClientBasic::getCurrent()->getAuthenticationInfo()->
                                           getAuthTable() );
            }
            return c.release();
        }
Esempio n. 8
0
        DBClientBase * get( const string& addr , const string& ns ) {
            _check( ns );

            Status* &s = _hosts[addr];
            if ( ! s )
                s = new Status();

            if ( s->avail ) {
                DBClientBase* c = s->avail;
                s->avail = 0;
                try {
                    shardConnectionPool.onHandedOut( c );
                }
                catch ( std::exception& e ) {
                    delete c;
                    throw;
                }
                return c;
            }

            s->created++;
            return shardConnectionPool.get( addr );
        }
Esempio n. 9
0
 ScopedDbConnection::ScopedDbConnection(const Shard* shard, double socketTimeout )
     : _host( shard->getConnString() ) , _conn( pool.get(_host, socketTimeout) ), _socketTimeout( socketTimeout ) {
     _setSocketTimeout();
 }
Esempio n. 10
0
 ScopedDbConnection::ScopedDbConnection(const Shard* shard )
     : _host( shard->getConnString() ) , _conn( pool.get(_host) ){
 }