summaryrefslogtreecommitdiff
path: root/db/lasterror.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'db/lasterror.cpp')
-rw-r--r--db/lasterror.cpp134
1 files changed, 12 insertions, 122 deletions
diff --git a/db/lasterror.cpp b/db/lasterror.cpp
index ba52111..4643aa9 100644
--- a/db/lasterror.cpp
+++ b/db/lasterror.cpp
@@ -28,7 +28,6 @@ namespace mongo {
LastError LastError::noError;
LastErrorHolder lastError;
- mongo::mutex LastErrorHolder::_idsmutex("LastErrorHolder");
bool isShell = false;
void raiseError(int code , const char *msg) {
@@ -79,22 +78,9 @@ namespace mongo {
}
LastErrorHolder::~LastErrorHolder() {
- for ( IDMap::iterator i = _ids.begin(); i != _ids.end(); ++i ) {
- delete i->second.lerr;
- i->second.lerr = 0;
- }
- _ids.clear();
}
- void LastErrorHolder::setID( int id ) {
- _id.set( id );
- }
-
- int LastErrorHolder::getID() {
- return _id.get();
- }
-
LastError * LastErrorHolder::disableForCommand() {
LastError *le = _get();
assert( le );
@@ -111,77 +97,31 @@ namespace mongo {
}
LastError * LastErrorHolder::_get( bool create ) {
- int id = _id.get();
- if ( id == 0 ) {
- LastError * le = _tl.get();
- if ( ! le && create ) {
- le = new LastError();
- _tl.reset( le );
- }
- return le;
- }
-
- scoped_lock lock(_idsmutex);
- map<int,Status>::iterator i = _ids.find( id );
- if ( i == _ids.end() ) {
- if ( ! create )
- return 0;
-
- LastError * le = new LastError();
- Status s;
- s.time = time(0);
- s.lerr = le;
- _ids[id] = s;
- return le;
+ LastError * le = _tl.get();
+ if ( ! le && create ) {
+ le = new LastError();
+ _tl.reset( le );
}
-
- Status &status = i->second;
- status.time = time(0);
- return status.lerr;
- }
-
- void LastErrorHolder::remove( int id ) {
- scoped_lock lock(_idsmutex);
- map<int,Status>::iterator i = _ids.find( id );
- if ( i == _ids.end() )
- return;
-
- delete i->second.lerr;
- _ids.erase( i );
+ return le;
}
void LastErrorHolder::release() {
- int id = _id.get();
- if ( id == 0 ) {
- _tl.release();
- return;
- }
-
- remove( id );
+ _tl.release();
}
/** ok to call more than once. */
void LastErrorHolder::initThread() {
- if( _tl.get() ) return;
- assert( _id.get() == 0 );
- _tl.reset( new LastError() );
+ if( ! _tl.get() )
+ _tl.reset( new LastError() );
}
void LastErrorHolder::reset( LastError * le ) {
- int id = _id.get();
- if ( id == 0 ) {
- _tl.reset( le );
- return;
- }
-
- scoped_lock lock(_idsmutex);
- Status & status = _ids[id];
- status.time = time(0);
- status.lerr = le;
+ _tl.reset( le );
}
void prepareErrForNewRequest( Message &m, LastError * err ) {
// a killCursors message shouldn't affect last error
+ assert( err );
if ( m.operation() == dbKillCursors ) {
err->disabled = true;
}
@@ -191,60 +131,10 @@ namespace mongo {
}
}
- LastError * LastErrorHolder::startRequest( Message& m , int clientId ) {
- assert( clientId );
- setID( clientId );
-
- LastError * le = _get( true );
+ LastError * LastErrorHolder::startRequest( Message& m , LastError * le ) {
+ assert( le );
prepareErrForNewRequest( m, le );
return le;
}
- void LastErrorHolder::startRequest( Message& m , LastError * connectionOwned ) {
- prepareErrForNewRequest( m, connectionOwned );
- }
-
- void LastErrorHolder::disconnect( int clientId ) {
- if ( clientId )
- remove(clientId);
- }
-
- struct LastErrorHolderTest : public UnitTest {
- public:
-
- void test( int i ) {
- _tl.set( i );
- assert( _tl.get() == i );
- }
-
- void tlmaptest() {
- test( 1 );
- test( 12123123 );
- test( -123123 );
- test( numeric_limits<int>::min() );
- test( numeric_limits<int>::max() );
- }
-
- void run() {
- tlmaptest();
-
- LastError * a = new LastError();
- LastError * b = new LastError();
-
- LastErrorHolder holder;
- holder.reset( a );
- assert( a == holder.get() );
- holder.setID( 1 );
- assert( 0 == holder.get() );
- holder.reset( b );
- assert( b == holder.get() );
- holder.setID( 0 );
- assert( a == holder.get() );
-
- holder.remove( 1 );
- }
-
- ThreadLocalValue<int> _tl;
- } lastErrorHolderTest;
-
} // namespace mongo