diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-09-11 12:52:17 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-09-11 12:52:17 -0400 |
commit | 73329a93a05648b46af5f54c2391579f60abfe99 (patch) | |
tree | 48034bfc75e8b87dd86ef662fa642563423f20c7 /db | |
parent | 378356ccbc018369fa7da6712ffd2091215f6a33 (diff) | |
download | mongo-73329a93a05648b46af5f54c2391579f60abfe99.tar.gz |
mongod side of client based errors for SHARDING-16
Diffstat (limited to 'db')
-rw-r--r-- | db/db.cpp | 4 | ||||
-rw-r--r-- | db/dbcommands.cpp | 27 | ||||
-rw-r--r-- | db/lasterror.cpp | 32 | ||||
-rw-r--r-- | db/lasterror.h | 12 |
4 files changed, 67 insertions, 8 deletions
diff --git a/db/db.cpp b/db/db.cpp index 42f3b621f6e..0ddac3f8c29 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -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; diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp index e9432b1096c..82ec3c44ad8 100644 --- a/db/dbcommands.cpp +++ b/db/dbcommands.cpp @@ -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() { diff --git a/db/lasterror.cpp b/db/lasterror.cpp index 27b72f46a55..598011c0439 100644 --- a/db/lasterror.cpp +++ b/db/lasterror.cpp @@ -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: diff --git a/db/lasterror.h b/db/lasterror.h index c7c866f4e6e..803bf0d19a9 100644 --- a/db/lasterror.h +++ b/db/lasterror.h @@ -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; |