diff options
Diffstat (limited to 's')
-rw-r--r-- | s/chunk.cpp | 5 | ||||
-rw-r--r-- | s/chunk.h | 5 | ||||
-rw-r--r-- | s/client.cpp | 111 | ||||
-rw-r--r-- | s/client.h | 18 | ||||
-rw-r--r-- | s/commands_public.cpp | 8 | ||||
-rw-r--r-- | s/d_split.cpp | 6 | ||||
-rw-r--r-- | s/request.cpp | 5 | ||||
-rw-r--r-- | s/request.h | 4 | ||||
-rw-r--r-- | s/server.cpp | 17 | ||||
-rw-r--r-- | s/shard_version.cpp | 7 | ||||
-rw-r--r-- | s/util.h | 2 | ||||
-rw-r--r-- | s/writeback_listener.cpp | 2 |
12 files changed, 95 insertions, 95 deletions
diff --git a/s/chunk.cpp b/s/chunk.cpp index 1c72535..b2ad03d 100644 --- a/s/chunk.cpp +++ b/s/chunk.cpp @@ -45,6 +45,8 @@ namespace mongo { string Chunk::chunkMetadataNS = "config.chunks"; int Chunk::MaxChunkSize = 1024 * 1024 * 64; + int Chunk::MaxObjectPerChunk = 250000; + Chunk::Chunk( ChunkManager * manager ) : _manager(manager), _lastmod(0) { _setDataWritten(); @@ -182,8 +184,7 @@ namespace mongo { if ( ! force ) { vector<BSONObj> candidates; const int maxPoints = 2; - const int maxObjs = 250000; - pickSplitVector( candidates , getManager()->getCurrentDesiredChunkSize() , maxPoints , maxObjs ); + pickSplitVector( candidates , getManager()->getCurrentDesiredChunkSize() , maxPoints , MaxObjectPerChunk ); if ( candidates.size() <= 1 ) { // no split points means there isn't enough data to split on // 1 split point means we have between half the chunk size to full chunk size @@ -174,7 +174,7 @@ namespace mongo { static string chunkMetadataNS; static int MaxChunkSize; - + static int MaxObjectPerChunk; // // accessors and helpers // @@ -189,10 +189,11 @@ namespace mongo { const char * getNS() { return "config.chunks"; } Shard getShard() const { return _shard; } const ChunkManager* getManager() const { return _manager; } + private: // main shard info - + ChunkManager * _manager; BSONObj _min; diff --git a/s/client.cpp b/s/client.cpp index b8559b6..95e3124 100644 --- a/s/client.cpp +++ b/s/client.cpp @@ -36,7 +36,7 @@ namespace mongo { - ClientInfo::ClientInfo( int clientId ) : _id( clientId ) { + ClientInfo::ClientInfo() { _cur = &_a; _prev = &_b; _autoSplitOk = true; @@ -44,13 +44,6 @@ namespace mongo { } ClientInfo::~ClientInfo() { - if ( _lastAccess ) { - scoped_lock lk( _clientsLock ); - Cache::iterator i = _clients.find( _id ); - if ( i != _clients.end() ) { - _clients.erase( i ); - } - } } void ClientInfo::addShard( const string& shard ) { @@ -79,49 +72,19 @@ namespace mongo { _cur->clear(); } - void ClientInfo::disconnect() { - _lastAccess = 0; - } - - ClientInfo * ClientInfo::get( int clientId , bool create ) { - - if ( ! clientId ) - clientId = getClientId(); - - if ( ! clientId ) { - ClientInfo * info = _tlInfo.get(); - if ( ! info ) { - info = new ClientInfo( 0 ); - _tlInfo.reset( info ); - } + ClientInfo * ClientInfo::get() { + ClientInfo * info = _tlInfo.get(); + if ( ! info ) { + info = new ClientInfo(); + _tlInfo.reset( info ); info->newRequest(); - return info; } - - scoped_lock lk( _clientsLock ); - Cache::iterator i = _clients.find( clientId ); - if ( i != _clients.end() ) - return i->second; - if ( ! create ) - return 0; - ClientInfo * info = new ClientInfo( clientId ); - _clients[clientId] = info; return info; } - void ClientInfo::disconnect( int clientId ) { - if ( ! clientId ) - return; - - scoped_lock lk( _clientsLock ); - Cache::iterator i = _clients.find( clientId ); - if ( i == _clients.end() ) - return; - - ClientInfo* ci = i->second; - ci->disconnect(); - delete ci; - _clients.erase( i ); + void ClientInfo::disconnect() { + // should be handled by TL cleanup + _lastAccess = 0; } void ClientInfo::_addWriteBack( vector<WBInfo>& all , const BSONObj& gle ) { @@ -142,14 +105,14 @@ namespace mongo { vector<BSONObj> ClientInfo::_handleWriteBacks( vector<WBInfo>& all , bool fromWriteBackListener ) { vector<BSONObj> res; + + if ( all.size() == 0 ) + return res; if ( fromWriteBackListener ) { LOG(1) << "not doing recusrive writeback" << endl; return res; } - - if ( all.size() == 0 ) - return res; for ( unsigned i=0; i<all.size(); i++ ) { res.push_back( WriteBackListener::waitFor( all[i].connectionId , all[i].id ) ); @@ -177,7 +140,21 @@ namespace mongo { ShardConnection conn( theShard , "" ); BSONObj res; - bool ok = conn->runCommand( "admin" , options , res ); + bool ok = false; + try{ + ok = conn->runCommand( "admin" , options , res ); + } + catch( std::exception &e ){ + + warning() << "Could not get last error." << e.what() << endl; + + // Catch everything that happens here, since we need to ensure we return our connection when we're + // finished. + conn.done(); + + return false; + } + res = res.getOwned(); conn.done(); @@ -205,6 +182,7 @@ namespace mongo { assert( v.size() == 1 ); result.appendElements( v[0] ); result.appendElementsUnique( res ); + result.append( "writebackGLE" , v[0] ); result.append( "initialGLEHost" , theShard ); } } @@ -217,8 +195,11 @@ namespace mongo { } BSONArrayBuilder bbb( result.subarrayStart( "shards" ) ); + BSONObjBuilder shardRawGLE; long long n = 0; + + int updatedExistingStat = 0; // 0 is none, -1 has but false, 1 has true // hit each shard vector<string> errors; @@ -228,7 +209,22 @@ namespace mongo { bbb.append( theShard ); ShardConnection conn( theShard , "" ); BSONObj res; - bool ok = conn->runCommand( "admin" , options , res ); + bool ok = false; + try { + ok = conn->runCommand( "admin" , options , res ); + shardRawGLE.append( theShard , res ); + } + catch( std::exception &e ){ + + // Safe to return here, since we haven't started any extra processing yet, just collecting + // responses. + + warning() << "Could not get last error." << e.what() << endl; + conn.done(); + + return false; + } + _addWriteBack( writebacks, res ); string temp = DBClientWithCommands::getLastErrorString( res ); @@ -236,13 +232,24 @@ namespace mongo { errors.push_back( temp ); errorObjects.push_back( res ); } + n += res["n"].numberLong(); + if ( res["updatedExisting"].type() ) { + if ( res["updatedExisting"].trueValue() ) + updatedExistingStat = 1; + else if ( updatedExistingStat == 0 ) + updatedExistingStat = -1; + } + conn.done(); } bbb.done(); + result.append( "shardRawGLE" , shardRawGLE.obj() ); result.appendNumber( "n" , n ); + if ( updatedExistingStat ) + result.appendBool( "updatedExisting" , updatedExistingStat > 0 ); // hit other machines just to block for ( set<string>::const_iterator i=sinceLastGetError().begin(); i!=sinceLastGetError().end(); ++i ) { @@ -285,8 +292,6 @@ namespace mongo { return true; } - ClientInfo::Cache& ClientInfo::_clients = *(new ClientInfo::Cache()); - mongo::mutex ClientInfo::_clientsLock("_clientsLock"); boost::thread_specific_ptr<ClientInfo> ClientInfo::_tlInfo; } // namespace mongo @@ -26,11 +26,8 @@ namespace mongo { * currently implemented with a thread local */ class ClientInfo { - - typedef map<int,ClientInfo*> Cache; - public: - ClientInfo( int clientId ); + ClientInfo(); ~ClientInfo(); /** new request from client, adjusts internal state */ @@ -54,7 +51,7 @@ namespace mongo { * gets shards used on the previous request */ set<string> * getPrev() const { return _prev; }; - + /** * gets all shards we've accessed since the last time we called clearSinceLastGetError */ @@ -65,6 +62,12 @@ namespace mongo { */ void clearSinceLastGetError() { _sinceLastGetError.clear(); } + + /** + * resets the list of shards using to process the current request + */ + void clearCurrentShards(){ _cur->clear(); } + /** * calls getLastError * resets shards since get last error @@ -77,8 +80,7 @@ namespace mongo { void noAutoSplit() { _autoSplitOk = false; } - static ClientInfo * get( int clientId = 0 , bool create = true ); - static void disconnect( int clientId ); + static ClientInfo * get(); private: @@ -111,8 +113,6 @@ namespace mongo { int _lastAccess; bool _autoSplitOk; - static mongo::mutex _clientsLock; - static Cache& _clients; static boost::thread_specific_ptr<ClientInfo> _tlInfo; }; diff --git a/s/commands_public.cpp b/s/commands_public.cpp index 02000a0..5b1ecaf 100644 --- a/s/commands_public.cpp +++ b/s/commands_public.cpp @@ -545,12 +545,8 @@ namespace mongo { bool ok = conn->runCommand( conf->getName() , cmdObj , res ); conn.done(); - if (ok || (strcmp(res["errmsg"].valuestrsafe(), "No matching object found") != 0)) { - result.appendElements(res); - return ok; - } - - return true; + result.appendElements(res); + return ok; } } findAndModifyCmd; diff --git a/s/d_split.cpp b/s/d_split.cpp index 0896803..66fe38e 100644 --- a/s/d_split.cpp +++ b/s/d_split.cpp @@ -269,7 +269,7 @@ namespace mongo { maxSplitPoints = maxSplitPointsElem.numberLong(); } - long long maxChunkObjects = 0; + long long maxChunkObjects = Chunk::MaxObjectPerChunk; BSONElement MaxChunkObjectsElem = jsobj[ "maxChunkObjects" ]; if ( MaxChunkObjectsElem.isNumber() ) { maxChunkObjects = MaxChunkObjectsElem.numberLong(); @@ -425,7 +425,8 @@ namespace mongo { currCount = 0; log() << "splitVector doing another cycle because of force, keyCount now: " << keyCount << endl; - c.reset( new BtreeCursor( d , d->idxNo(*idx) , *idx , min , max , false , 1 ) ); + bc = new BtreeCursor( d , d->idxNo(*idx) , *idx , min , max , false , 1 ); + c.reset( bc ); cc.reset( new ClientCursor( QueryOption_NoCursorTimeout , c , ns ) ); } @@ -442,6 +443,7 @@ namespace mongo { // Remove the sentinel at the beginning before returning and add fieldnames. splitKeys.erase( splitKeys.begin() ); + assert( c.get() ); for ( vector<BSONObj>::iterator it = splitKeys.begin(); it != splitKeys.end() ; ++it ) { *it = bc->prettyKey( *it ); } diff --git a/s/request.cpp b/s/request.cpp index 52f2e54..32c17cc 100644 --- a/s/request.cpp +++ b/s/request.cpp @@ -41,8 +41,7 @@ namespace mongo { assert( _d.getns() ); _id = _m.header()->id; - _clientId = p ? p->getClientId() : 0; - _clientInfo = ClientInfo::get( _clientId ); + _clientInfo = ClientInfo::get(); _clientInfo->newRequest( p ); } @@ -74,7 +73,7 @@ namespace mongo { } _m.header()->id = _id; - + _clientInfo->clearCurrentShards(); } Shard Request::primaryShard() const { diff --git a/s/request.h b/s/request.h index 5b4c228..7c51e5c 100644 --- a/s/request.h +++ b/s/request.h @@ -66,9 +66,6 @@ namespace mongo { return _chunkManager; } - int getClientId() const { - return _clientId; - } ClientInfo * getClientInfo() const { return _clientInfo; } @@ -103,7 +100,6 @@ namespace mongo { DBConfigPtr _config; ChunkManagerPtr _chunkManager; - int _clientId; ClientInfo * _clientInfo; OpCounters* _counter; diff --git a/s/server.cpp b/s/server.cpp index 9bdeede..51f30f1 100644 --- a/s/server.cpp +++ b/s/server.cpp @@ -77,19 +77,19 @@ namespace mongo { public: virtual ~ShardedMessageHandler() {} - virtual void process( Message& m , AbstractMessagingPort* p ) { + virtual void connected( AbstractMessagingPort* p ) { + assert( ClientInfo::get() ); + } + + virtual void process( Message& m , AbstractMessagingPort* p , LastError * le) { assert( p ); Request r( m , p ); - LastError * le = lastError.startRequest( m , r.getClientId() ); - assert( le ); + assert( le ); + lastError.startRequest( m , le ); - if ( logLevel > 5 ) { - log(5) << "client id: " << hex << r.getClientId() << "\t" << r.getns() << "\t" << dec << r.op() << endl; - } try { r.init(); - setClientId( r.getClientId() ); r.process(); } catch ( AssertionException & e ) { @@ -119,8 +119,7 @@ namespace mongo { } virtual void disconnected( AbstractMessagingPort* p ) { - ClientInfo::disconnect( p->getClientId() ); - lastError.disconnect( p->getClientId() ); + // all things are thread local } }; diff --git a/s/shard_version.cpp b/s/shard_version.cpp index 0f3e80f..043b9bd 100644 --- a/s/shard_version.cpp +++ b/s/shard_version.cpp @@ -142,9 +142,10 @@ namespace mongo { checkShardVersion( conn , ns , 1 , tryNumber + 1 ); return true; } - - log() << " setShardVersion failed: " << result << endl; - massert( 10429 , (string)"setShardVersion failed! " + result.jsonString() , 0 ); + + string errmsg = str::stream() << "setShardVersion failed host[" << conn.getServerAddress() << "] " << result; + log() << " " << errmsg << endl; + massert( 10429 , errmsg , 0 ); return true; } @@ -105,7 +105,7 @@ namespace mongo { _combined = 0; break; default: - assert(0); + massert( 13657 , str::stream() << "unknown type for ShardChunkVersion: " << elem , 0 ); } return *this; } diff --git a/s/writeback_listener.cpp b/s/writeback_listener.cpp index 21d59d0..3051013 100644 --- a/s/writeback_listener.cpp +++ b/s/writeback_listener.cpp @@ -159,7 +159,7 @@ namespace mongo { DBConfigPtr db = grid.getDBConfig( ns ); ShardChunkVersion needVersion( data["version"] ); - log(1) << "connectionId: " << cid << " writebackId: " << wid << " needVersion : " << needVersion.toString() + LOG(1) << "connectionId: " << cid << " writebackId: " << wid << " needVersion : " << needVersion.toString() << " mine : " << db->getChunkManager( ns )->getVersion().toString() << endl;// TODO change to log(3) if ( logLevel ) log(1) << debugString( m ) << endl; |