示例#1
0
 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
            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
int ManagedDatasource::grabLock(ExceptionSink *xsink) {
   if (grabLockIntern() < 0) {
      endDBActionIntern();
      const char *un = getUsername();
      const char *db = getDBName();
      xsink->raiseException("TRANSACTION-LOCK-TIMEOUT", "%s:%s@%s: TID %d timed out on datasource '%s@%s' after waiting %d millisecond%s on transaction lock held by TID %d",
			    getDriverName(), getUsernameStr().c_str(), getDBNameStr().c_str(), 
			    gettid(), un ? un : "<n/a>", db ? db : "<n/a>", tl_timeout_ms, 
			    tl_timeout_ms == 1 ? "" : "s", tid);
      return -1;
   }
   return 0;
}
示例#4
0
 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;
 }