diff options
author | daveh86 <howsdav@gmail.com> | 2014-05-28 17:04:13 -0400 |
---|---|---|
committer | Ramon Fernandez <ramon.fernandez@mongodb.com> | 2014-11-28 10:02:33 -0500 |
commit | 1bcd0d97e3f48bd1713f6e3905ac4fd603f09684 (patch) | |
tree | b5d53888bf1b14abfcaaaf636b6a066f88e13a88 | |
parent | b85c4e1ab64c7b99f8c6f3cb70ba2e73004dea96 (diff) | |
download | mongo-1bcd0d97e3f48bd1713f6e3905ac4fd603f09684.tar.gz |
SERVER-14080 Have migration result reported in the changelog correctly
Signed-off-by: Benety Goh <benety@mongodb.com>
(cherry picked from commit d68aacd27b7abb5981d312e858bf5c5cc3b971b2)
Conflicts:
src/mongo/s/d_migrate.cpp
-rw-r--r-- | src/mongo/s/d_migrate.cpp | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/src/mongo/s/d_migrate.cpp b/src/mongo/s/d_migrate.cpp index 8c9570d3d21..2c8cea21e79 100644 --- a/src/mongo/s/d_migrate.cpp +++ b/src/mongo/s/d_migrate.cpp @@ -95,9 +95,9 @@ namespace mongo { class MoveTimingHelper { public: - MoveTimingHelper( const string& where , const string& ns , BSONObj min , BSONObj max , int total , string& cmdErrmsg ) + MoveTimingHelper( const string& where , const string& ns , BSONObj min , BSONObj max , + int total , string* cmdErrmsg ) : _where( where ) , _ns( ns ) , _next( 0 ) , _total( total ) , _cmdErrmsg( cmdErrmsg ) { - _nextNote = 0; _b.append( "min" , min ); _b.append( "max" , max ); } @@ -107,13 +107,14 @@ namespace mongo { // sigh try { if ( _next != _total ) { - note( "aborted" ); + _b.append( "note" , "aborted" ); } - if ( _cmdErrmsg.size() ) { - note( _cmdErrmsg ); - warning() << "got error doing chunk migrate: " << _cmdErrmsg << endl; + else { + _b.append( "note" , "success" ); + } + if ( !_cmdErrmsg->empty() ) { + _b.append( "errmsg" , *_cmdErrmsg ); } - configServer.logChange( (string)"moveChunk." + _where , _ns, _b.obj() ); } catch ( const std::exception& e ) { @@ -147,19 +148,6 @@ namespace mongo { #endif } - - void note( const string& s ) { - string field = "note"; - if ( _nextNote > 0 ) { - StringBuilder buf; - buf << "note" << _nextNote; - field = buf.str(); - } - _nextNote++; - - _b.append( field , s ); - } - private: Timer _t; @@ -168,9 +156,8 @@ namespace mongo { int _next; int _total; // expected # of steps - int _nextNote; - string _cmdErrmsg; + const string* _cmdErrmsg; BSONObjBuilder _b; @@ -903,7 +890,7 @@ namespace mongo { ShardingState::initialize(configdb); } - MoveTimingHelper timing( "from" , ns , min , max , 6 /* steps */ , errmsg ); + MoveTimingHelper timing( "from" , ns , min , max , 6 /* steps */ , &errmsg ); // Make sure we're as up-to-date as possible with shard information // This catches the case where we had to previously changed a shard's host by @@ -926,6 +913,7 @@ namespace mongo { if ( migrateFromStatus.isActive() ) { errmsg = "migration already in progress"; + warning() << errmsg << endl; return false; } @@ -937,11 +925,13 @@ namespace mongo { } catch( LockException& e ){ errmsg = str::stream() << "error locking distributed lock for migration " << "migrate-" << min.toString() << causedBy( e ); + warning() << errmsg << endl; return false; } if ( ! dlk.got() ) { errmsg = str::stream() << "the collection metadata could not be locked with lock " << "migrate-" << min.toString(); + warning() << errmsg << endl; result.append( "who" , dlk.other() ); return false; } @@ -1054,20 +1044,23 @@ namespace mongo { BSONObj shardKeyPattern = origCollMetadata->getKeyPattern(); if ( shardKeyPattern.isEmpty() ){ errmsg = "no shard key found"; + warning() << errmsg << endl; return false; } MigrateStatusHolder statusHolder( ns , min , max , shardKeyPattern ); if (statusHolder.isAnotherMigrationActive()) { errmsg = "moveChunk is already in progress from this shard"; + warning() << errmsg << endl; return false; } { // this gets a read lock, so we know we have a checkpoint for mods - if ( ! migrateFromStatus.storeCurrentLocs( maxChunkSize , errmsg , result ) ) + if ( ! migrateFromStatus.storeCurrentLocs( maxChunkSize , errmsg , result ) ) { + warning() << errmsg << endl; return false; - + } ScopedDbConnection connTo(toShard.getConnString()); BSONObj res; bool ok; @@ -1631,7 +1624,7 @@ namespace mongo { << " at epoch " << epoch.toString() << endl; string errmsg; - MoveTimingHelper timing( "to" , ns , min , max , 5 /* steps */ , errmsg ); + MoveTimingHelper timing( "to" , ns , min , max , 5 /* steps */ , &errmsg ); ScopedDbConnection conn(from); conn->getLastError(); // just test connection @@ -1851,7 +1844,6 @@ namespace mongo { int i; for ( i=0;i<maxIterations; i++) { if ( state == ABORT ) { - timing.note( "aborted" ); return; } @@ -1917,7 +1909,6 @@ namespace mongo { continue; if ( state == ABORT ) { - timing.note( "aborted" ); return; } |