summaryrefslogtreecommitdiff
path: root/src/mongo/s/cursors.cpp
diff options
context:
space:
mode:
authorJason Rassi <rassi@10gen.com>2013-10-31 05:02:02 -0400
committerJason Rassi <rassi@10gen.com>2013-10-31 05:06:25 -0400
commit195c99e44a1483816b3be2a1f6f42bffed7ec18e (patch)
tree7f2ce8cc8e891f0c8e231a89acb8cc25549eb772 /src/mongo/s/cursors.cpp
parent5c26124ba4a9829a417a8f652ce009eef0b98a72 (diff)
downloadmongo-195c99e44a1483816b3be2a1f6f42bffed7ec18e.tar.gz
SERVER-2212 mongos tracks elapsed time for sharded cursors
If a maxTimeMS sharded query exceeds its time limit, the next request for a batch will fail with an error.
Diffstat (limited to 'src/mongo/s/cursors.cpp')
-rw-r--r--src/mongo/s/cursors.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/mongo/s/cursors.cpp b/src/mongo/s/cursors.cpp
index f38feba9048..cf80b8d6d0e 100644
--- a/src/mongo/s/cursors.cpp
+++ b/src/mongo/s/cursors.cpp
@@ -44,6 +44,7 @@
#include "mongo/client/connpool.h"
#include "mongo/db/commands.h"
#include "mongo/db/jsobj.h"
+#include "mongo/db/max_time.h"
#include "mongo/util/concurrency/task.h"
#include "mongo/util/net/listen.h"
@@ -204,17 +205,42 @@ namespace mongo {
return i->second;
}
- void CursorCache::store( ShardedClientCursorPtr cursor ) {
- LOG(_myLogLevel) << "CursorCache::store cursor " << " id: " << cursor->getId() << endl;
+ int CursorCache::getMaxTimeMS( long long id ) const {
+ verify( id );
+ scoped_lock lk( _mutex );
+ MapShardedInt::const_iterator i = _cursorsMaxTimeMS.find( id );
+ return ( i != _cursorsMaxTimeMS.end() ) ? i->second : 0;
+ }
+
+ void CursorCache::store( ShardedClientCursorPtr cursor, int maxTimeMS ) {
+ LOG(_myLogLevel) << "CursorCache::store cursor " << " id: " << cursor->getId()
+ << (maxTimeMS != kMaxTimeCursorNoTimeLimit ? str::stream() << "maxTimeMS: " << maxTimeMS
+ : string(""))
+ << endl;
verify( cursor->getId() );
+ verify( maxTimeMS == kMaxTimeCursorTimeLimitExpired
+ || maxTimeMS == kMaxTimeCursorNoTimeLimit
+ || maxTimeMS > 0 );
scoped_lock lk( _mutex );
_cursors[cursor->getId()] = cursor;
+ _cursorsMaxTimeMS[cursor->getId()] = maxTimeMS;
_shardedTotal++;
}
+
+ void CursorCache::updateMaxTimeMS( long long id, int maxTimeMS ) {
+ verify( id );
+ verify( maxTimeMS == kMaxTimeCursorTimeLimitExpired
+ || maxTimeMS == kMaxTimeCursorNoTimeLimit
+ || maxTimeMS > 0 );
+ scoped_lock lk( _mutex );
+ _cursorsMaxTimeMS[id] = maxTimeMS;
+ }
+
void CursorCache::remove( long long id ) {
verify( id );
scoped_lock lk( _mutex );
_cursors.erase( id );
+ _cursorsMaxTimeMS.erase( id );
}
void CursorCache::removeRef( long long id ) {
@@ -323,6 +349,7 @@ namespace mongo {
isAuthorized ? ErrorCodes::OK : ErrorCodes::Unauthorized);
if (isAuthorized) {
_cursors.erase( i );
+ _cursorsMaxTimeMS.erase( i->second->getId() );
}
continue;
}
@@ -377,6 +404,7 @@ namespace mongo {
}
log() << "killing old cursor " << i->second->getId() << " idle for: " << idleFor << "ms" << endl; // TODO: make LOG(1)
_cursors.erase( i );
+ _cursorsMaxTimeMS.erase( i->second->getId() );
i = _cursors.begin(); // possible 2nd entry will get skipped, will get on next pass
if ( i == _cursors.end() )
break;