예제 #1
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();
        }
예제 #2
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 );
        }
예제 #3
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();
        }
예제 #4
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 );
        }