diff options
author | Eliot Horowitz <eliot@10gen.com> | 2013-06-05 13:55:40 -0400 |
---|---|---|
committer | Dan Pasette <dan@10gen.com> | 2013-06-19 20:30:14 -0400 |
commit | 3bc78e15f15a49df9c6506a41d87f3ee71865a3d (patch) | |
tree | f0bf70efac049affaaf17c2285a91bbc93dddae8 | |
parent | 9cd0092e07574b6cff5925ddfa6e68c56a8acd02 (diff) | |
download | mongo-3bc78e15f15a49df9c6506a41d87f3ee71865a3d.tar.gz |
SERVER-9864: make dbhash take a list of collections to hash and mongos check should use it
-rw-r--r-- | src/mongo/db/dbcommands.cpp | 40 | ||||
-rw-r--r-- | src/mongo/s/config.cpp | 6 |
2 files changed, 34 insertions, 12 deletions
diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp index 4e538e5e841..33b77f455d6 100644 --- a/src/mongo/db/dbcommands.cpp +++ b/src/mongo/db/dbcommands.cpp @@ -1703,6 +1703,21 @@ namespace mongo { out->push_back(Privilege(dbname, actions)); } virtual bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + Timer timer; + + set<string> desiredCollections; + if ( cmdObj["collections"].type() == Array ) { + BSONObjIterator i( cmdObj["collections"].Obj() ); + while ( i.more() ) { + BSONElement e = i.next(); + if ( e.type() != String ) { + errmsg = "collections entries have to be strings"; + return false; + } + desiredCollections.insert( e.String() ); + } + } + list<string> colls; Database* db = cc().database(); if ( db ) @@ -1717,20 +1732,26 @@ namespace mongo { BSONObjBuilder bb( result.subobjStart( "collections" ) ); for ( list<string>::iterator i=colls.begin(); i != colls.end(); i++ ) { - string c = *i; - if ( c.find( ".system.profile" ) != string::npos ) + string fullCollectionName = *i; + string shortCollectionName = fullCollectionName.substr( dbname.size() + 1 ); + + if ( shortCollectionName.find( "system." ) == 0 ) + continue; + + if ( desiredCollections.size() > 0 && + desiredCollections.count( shortCollectionName ) == 0 ) continue; shared_ptr<Cursor> cursor; - NamespaceDetails * nsd = nsdetails( c ); + NamespaceDetails * nsd = nsdetails( fullCollectionName ); // debug SERVER-761 NamespaceDetails::IndexIterator ii = nsd->ii(); while( ii.more() ) { const IndexDetails &idx = ii.next(); if ( !idx.head.isValid() || !idx.info.isValid() ) { - log() << "invalid index for ns: " << c << " " << idx.head << " " << idx.info; + log() << "invalid index for ns: " << fullCollectionName << " " << idx.head << " " << idx.info; if ( idx.info.isValid() ) log() << " " << idx.info.obj(); log() << endl; @@ -1746,14 +1767,11 @@ namespace mongo { false, 1 ) ); } - else if ( c.find( ".system." ) != string::npos ) { - continue; - } else if ( nsd->isCapped() ) { - cursor = findTableScan( c.c_str() , BSONObj() ); + cursor = findTableScan( fullCollectionName.c_str() , BSONObj() ); } else { - log() << "can't find _id index for: " << c << endl; + log() << "can't find _id index for: " << fullCollectionName << endl; continue; } @@ -1771,7 +1789,7 @@ namespace mongo { md5_finish(&st, d); string hash = digestToString( d ); - bb.append( c.c_str() + ( dbname.size() + 1 ) , hash ); + bb.append( shortCollectionName, hash ); md5_append( &globalState , (const md5_byte_t*)hash.c_str() , hash.size() ); } @@ -1782,7 +1800,7 @@ namespace mongo { string hash = digestToString( d ); result.append( "md5" , hash ); - + result.appendNumber( "timeMillis", timer.millis() ); return 1; } diff --git a/src/mongo/s/config.cpp b/src/mongo/s/config.cpp index 39d375f25a1..b8698a10687 100644 --- a/src/mongo/s/config.cpp +++ b/src/mongo/s/config.cpp @@ -781,7 +781,11 @@ namespace mongo { try { conn.reset( ScopedDbConnection::getInternalScopedDbConnection( _config[i], 30.0 ) ); - if ( ! conn->get()->simpleCommand( "config" , &result, "dbhash" ) ) { + if ( ! conn->get()->runCommand( "config", + BSON( "dbhash" << 1 << + "collections" << BSON_ARRAY( "chunks" << + "databases" ) ), + result ) ) { // TODO: Make this a helper error = result["errmsg"].eoo() ? "" : result["errmsg"].String(); |