0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 09:06:21 +01:00

mongod side of client based errors for SHARDING-16

This commit is contained in:
Eliot Horowitz 2009-09-11 12:52:17 -04:00
parent 378356ccbc
commit 73329a93a0
4 changed files with 67 additions and 8 deletions

View File

@ -205,8 +205,8 @@ namespace mongo {
break;
}
le->nPrev++;
lastError.startRequest( m , le );
DbResponse dbresponse;
if ( !assembleResponse( m, dbresponse, dbMsgPort.farEnd.sa ) ) {
out() << curTimeMillis() % 10000 << " end msg " << dbMsgPort.farEnd.toString() << endl;

View File

@ -323,6 +323,33 @@ namespace mongo {
}
} cmdGetPrevError;
class CmdSwitchToClientErrors : public Command {
public:
virtual bool requiresAuth() { return false; }
virtual bool logTheOp() {
return false;
}
virtual void help( stringstream& help ) const {
help << "convert to id based errors rather than connection based";
}
virtual bool slaveOk() {
return true;
}
CmdSwitchToClientErrors() : Command("switchtoclienterrors") {}
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
if ( lastError.getID() ){
errmsg = "already in client id mode";
return false;
}
LastError *le = lastError.get();
assert( le );
le->nPrev--;
le->overridenById = true;
result << "ok" << 1;
return true;
}
} cmdSwitchToClientErrors;
class CmdDropDatabase : public Command {
public:
virtual bool logTheOp() {

View File

@ -3,6 +3,8 @@
#include "stdafx.h"
#include "../util/unittest.h"
#include "../util/message.h"
#include "lasterror.h"
#include "jsobj.h"
@ -31,14 +33,24 @@ namespace mongo {
_id.reset( id );
}
LastError * LastErrorHolder::get(){
int LastErrorHolder::getID(){
return _id.get();
}
LastError * LastErrorHolder::get( bool create ){
int id = _id.get();
if ( id == 0 )
return _tl.get();
LastErrorIDMap::iterator i = _ids.find( id );
if ( i == _ids.end() )
return 0;
if ( i == _ids.end() ){
if ( ! create )
return 0;
LastError * le = new LastError();
_ids[id] = make_pair( time(0) , le );
return le;
}
LastErrorStatus & status = i->second;
status.first = time(0);
@ -75,6 +87,20 @@ namespace mongo {
status.first = time(0);
status.second = le;
}
void LastErrorHolder::startRequest( Message& m , LastError * connectionOwned ){
if ( connectionOwned && ! connectionOwned->overridenById ){
connectionOwned->nPrev++;
return;
}
int id = m.data->id & 0xFFFF0000;
cout << "eliot id: " << id << endl;
setID( id );
LastError * le = get( true);
le->nPrev++;
}
struct LastErrorHolderTest : public UnitTest {
public:

View File

@ -24,13 +24,15 @@
namespace mongo {
class BSONObjBuilder;
class Message;
struct LastError {
string msg;
enum UpdatedExistingType { NotUpdate, True, False } updatedExisting;
int nObjects;
int nPrev;
bool valid;
bool overridenById;
void raiseError(const char *_msg) {
reset( true );
msg = _msg;
@ -45,6 +47,7 @@ namespace mongo {
nObjects = nDeleted;
}
LastError() {
overridenById = false;
reset();
}
void reset( bool _valid = false ) {
@ -68,16 +71,19 @@ namespace mongo {
LastErrorHolder() : _id( 0 ){}
LastError * get();
LastError * get( bool create = false );
void reset( LastError * le );
/**
* id of 0 means should use thread local management
*/
void setID( int id );
int getID();
void remove( int id );
void release();
void startRequest( Message& m , LastError * connectionOwned = 0 );
private:
ThreadLocalInt _id;