Permalink
Browse files

really fix getLastError in mongos SERVER-1039

  • Loading branch information...
1 parent a634d54 commit e0d8e8541d2870a2280c9513ac742b5b1864c766 @erh erh committed Apr 28, 2010
Showing with 19 additions and 17 deletions.
  1. +8 −4 db/lasterror.cpp
  2. +1 −1 db/lasterror.h
  3. +4 −3 jstests/sharding/error1.js
  4. +1 −1 jstests/sharding/update1.js
  5. +2 −2 s/commands_admin.cpp
  6. +1 −2 s/request.cpp
  7. +2 −4 s/server.cpp
View
@@ -132,7 +132,7 @@ namespace mongo {
status.time = time(0);
status.lerr = le;
}
-
+
void prepareErrForNewRequest( Message &m, LastError * err ) {
// a killCursors message shouldn't affect last error
if ( m.data->operation() == dbKillCursors ) {
@@ -143,11 +143,15 @@ namespace mongo {
}
}
- void LastErrorHolder::startRequest( Message& m ) {
- int id = m.data->id & 0xFFFF0000;
- setID( id );
+ LastError * LastErrorHolder::startRequest( Message& m , int clientId ) {
+
+ if ( clientId == 0 )
+ clientId = m.data->id & 0xFFFF0000;
+ setID( clientId );
+
LastError * le = _get( true );
prepareErrForNewRequest( m, le );
+ return le;
}
void LastErrorHolder::startRequest( Message& m , LastError * connectionOwned ) {
View
@@ -87,7 +87,7 @@ namespace mongo {
/** when db receives a message/request, call this */
void startRequest( Message& m , LastError * connectionOwned );
- void startRequest( Message& m );
+ LastError * startRequest( Message& m , int clientId = 0 );
// used to disable lastError reporting while processing a killCursors message
// disable causes get() to return 0.
@@ -46,13 +46,14 @@ assert.eq( 5 , db.foo2.count() , "se5" );
// assert in mongos
s.adminCommand( { shardcollection : "test.foo3" , key : { num : 1 } } );
-assert.isnull(db.getLastError() , "mongos 1" );
+assert.isnull(db.getLastError() , "gle C1" );
db.foo3.insert({}); //this fails with no shard key error
-//assert(db.getLastError() , "mongos 2" );
+assert(db.getLastError() , "gle C2a" );
+assert(db.getLastError() , "gle C2b" );
db.foo3.insert({num:1});
-//assert.isnull(db.getLastError() , "mongos 3" );
+assert.isnull(db.getLastError() , "gle C3a" );
// ----
s.stop();
@@ -38,7 +38,7 @@ assert.eq(err.code, 13123, 'key error code 1');
assert.eq(err.code, 13123, 'key error code 2');
coll.update({_id:1, key:1}, {$set: {foo:2}});
-//assert.isnull(db.getLastError(), 'getLastError reset');
+assert.isnull(db.getLastError(), 'getLastError reset');
s.stop()
View
@@ -765,10 +765,10 @@ namespace mongo {
}
CmdShardingGetLastError() : Command("getlasterror") { }
virtual bool run(const char *nsraw, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) {
+ LastError *le = lastError.disableForCommand();
{
- LastError * le = lastError.get();
assert( le );
- if ( le->msg.size() ){
+ if ( le->msg.size() && le->nPrev == 1 ){
le->appendSelf( result );
return true;
}
View
@@ -77,7 +77,6 @@ namespace mongo {
}
void Request::process( int attempt ){
-
log(3) << "Request::process ns: " << getns() << " msg id:" << (int)(_m.data->id) << " attempt: " << attempt << endl;
int op = _m.data->operation();
@@ -92,7 +91,7 @@ namespace mongo {
s = SHARDED;
counter = &opsSharded;
}
-
+
bool iscmd = false;
if ( op == dbQuery ) {
iscmd = isCommand();
View
@@ -75,10 +75,8 @@ namespace mongo {
assert( p );
Request r( m , p );
- lastError.setID( r.getClientId() );
- LastError * le = lastError.get( true );
+ LastError * le = lastError.startRequest( m , r.getClientId() );
assert( le );
- lastError.startRequest( m );
if ( logLevel > 5 ){
log(5) << "client id: " << hex << r.getClientId() << "\t" << r.getns() << "\t" << dec << r.op() << endl;
@@ -89,7 +87,7 @@ namespace mongo {
}
catch ( DBException& e ){
le->raiseError( e.getCode() , e.what() );
-
+
m.data->id = r.id();
log() << "UserException: " << e.what() << endl;
if ( r.expectResponse() ){

0 comments on commit e0d8e85

Please sign in to comment.