コード例 #1
0
ファイル: commands_public.cpp プロジェクト: catap/mongo
 bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){
     
     string dbName = getDBName( ns );
     string collection = cmdObj.firstElement().valuestrsafe();
     string fullns = dbName + "." + collection;
     
     BSONObj filter = cmdObj["query"].embeddedObject();
     
     DBConfig * conf = grid.getDBConfig( dbName , false );
     
     if ( ! conf || ! conf->isShardingEnabled() || ! conf->isSharded( fullns ) ){
         ScopedDbConnection conn( conf->getPrimary() );
         result.append( "n" , (double)conn->count( fullns , filter ) );
         conn.done();
         result.append( "ok" , 1 );
         return true;
     }
     
     ChunkManager * cm = conf->getChunkManager( fullns );
     massert( "how could chunk manager be null!" , cm );
     
     vector<Chunk*> chunks;
     cm->getChunksForQuery( chunks , filter );
     
     unsigned long long total = 0;
     for ( vector<Chunk*>::iterator i = chunks.begin() ; i != chunks.end() ; i++ ){
         Chunk * c = *i;
         total += c->countObjects();
     }
     
     result.append( "n" , (double)total );
     result.append( "ok" , 1 );
     return true;
 }
コード例 #2
0
ファイル: commands_public.cpp プロジェクト: catap/mongo
            bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){

                string dbName = getDBName( ns );
                string collection = cmdObj.firstElement().valuestrsafe();
                string fullns = dbName + "." + collection;

                DBConfig * conf = grid.getDBConfig( dbName , false );
                
                if ( ! conf || ! conf->isShardingEnabled() || ! conf->isSharded( fullns ) ){
                    return passthrough( conf , cmdObj , result );
                }
                
                ChunkManager * cm = conf->getChunkManager( fullns );
                massert( "how could chunk manager be null!" , cm );
                
                vector<Chunk*> chunks;
                cm->getChunksForQuery( chunks , BSONObj() );
                
                set<BSONObj,BSONObjCmp> all;
                int size = 32;
                
                for ( vector<Chunk*>::iterator i = chunks.begin() ; i != chunks.end() ; i++ ){
                    Chunk * c = *i;

                    ScopedDbConnection conn( c->getShard() );
                    BSONObj res;
                    bool ok = conn->runCommand( conf->getName() , cmdObj , res );
                    conn.done();
                    
                    if ( ! ok ){
                        result.appendElements( res );
                        return false;
                    }
                    
                    BSONObjIterator it( res["values"].embeddedObjectUserCheck() );
                    while ( it.more() ){
                        BSONElement nxt = it.next();
                        BSONObjBuilder temp(32);
                        temp.appendAs( nxt , "x" );
                        all.insert( temp.obj() );
                    }

                }
                
                BSONObjBuilder b( size );
                int n=0;
                for ( set<BSONObj,BSONObjCmp>::iterator i = all.begin() ; i != all.end(); i++ ){
                    b.appendAs( i->firstElement() , b.numStr( n++ ).c_str() );
                }
                
                result.appendArray( "values" , b.obj() );
                result.append( "ok" , 1 );
                return true;
            }
コード例 #3
0
ファイル: grid.cpp プロジェクト: DavidAlphaFox/mongodb
void Grid::removeDBIfExists(const DBConfig& database) {
    scoped_lock l(_lock);

    map<string, DBConfigPtr>::iterator it = _databases.find(database.getName());
    if (it != _databases.end() && it->second.get() == &database) {
        _databases.erase(it);
        log() << "erased database " << database.getName() << " from local registry" << endl;
    } else {
        log() << database.getName() << "already erased from local registry" << endl;
    }
}
コード例 #4
0
ファイル: commands_public.cpp プロジェクト: catap/mongo
 virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){
     
     string dbName = getDBName( ns );
     string fullns = getFullNS( dbName , cmdObj );
     
     DBConfig * conf = grid.getDBConfig( dbName , false );
     
     if ( ! conf || ! conf->isShardingEnabled() || ! conf->isSharded( fullns ) ){
         return passthrough( conf , cmdObj , result );
     }
     errmsg = "can't do command: " + name + " on sharded collection";
     return false;
 }
コード例 #5
0
ファイル: config.cpp プロジェクト: jch/mongo
        void testInOut( DBConfig& c , BSONObj o ){
            c.unserialize( o );
            BSONObjBuilder b;
            c.serialize( b );

            BSONObj out = b.obj();
            
            if ( o.toString() == out.toString() )
                return;
            
            log() << "DBConfig serialization broken\n" 
                  << "in  : " << o.toString()  << '\n'
                  << "out : " << out.toString() 
                  << endl;
            assert(0);
        }
コード例 #6
0
ファイル: config.cpp プロジェクト: jch/mongo
        void b(){
            BSONObjBuilder b;
            b << "_id" << "abc";
            b.appendBool( "partitioned" , true );
            b << "primary" << "myserver";
            
            BSONObjBuilder a;
            a << "abc.foo" << fromjson( "{ 'key' : { 'a' : 1 } , 'unique' : false }" );
            a << "abc.bar" << fromjson( "{ 'key' : { 'kb' : -1 } , 'unique' : true }" );
            
            b.append( "sharded" , a.obj() );

            DBConfig c;
            testInOut( c , b.obj() );
            assert( c.isSharded( "abc.foo" ) );
            assert( ! c.isSharded( "abc.food" ) );
        }
コード例 #7
0
    void b() {
        BSONObjBuilder b;
        b << "name" << "abc";
        b.appendBool( "partitioned" , true );
        b << "primary" << "myserver";

        BSONObjBuilder a;
        a << "abc.foo" << BSON( "a" << 1 );
        a << "abc.bar" << BSON( "b" << -1 );

        b.appendArray( "sharded" , a.obj() );

        DBConfig c;
        testInOut( c , b.obj() );
        assert( c.sharded( "abc.foo" ) );
        assert( ! c.sharded( "abc.food" ) );
    }
コード例 #8
0
int main()
{
    DBConfig conf;

    if(conf.Init("127.0.0.1",
               3306,
              "atom",
              "atom",
              "ATOM") != true)
    {
        printf("Init Fail\n");
        return 0;
    }

    pthread_t   tid;

    for(int nLoop=0; nLoop < 30; nLoop++)
    {
        if(pthread_create(&tid, NULL, thr_fn, &conf) != 0)
        {
            printf("thread create fail\n");
            return 0;
        }

        pthread_detach(tid);

        printf("creat thread success [%d]\n", nLoop);
    }

    printf("i am going to sleep\n");

    sleep(10);

    printf("i am going to down\n");
    g_bInService = false;

    sleep(3);

    printf("terminated\n");
    return 0;
}