0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/s/cursors.h

102 lines
2.5 KiB
C
Raw Normal View History

2009-02-25 06:57:31 +01:00
// cursors.h
/*
* Copyright (C) 2010 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2009-02-25 06:57:31 +01:00
2011-01-04 06:40:41 +01:00
#pragma once
2009-02-25 06:57:31 +01:00
2010-04-27 21:33:27 +02:00
#include "../pch.h"
2009-02-25 06:57:31 +01:00
#include "../db/jsobj.h"
#include "../db/dbmessage.h"
#include "../client/dbclient.h"
2009-11-03 16:35:48 +01:00
#include "../client/parallel.h"
2009-02-25 06:57:31 +01:00
#include "request.h"
namespace mongo {
class ShardedClientCursor : boost::noncopyable {
2009-02-25 06:57:31 +01:00
public:
2009-11-03 16:35:48 +01:00
ShardedClientCursor( QueryMessage& q , ClusteredCursor * cursor );
virtual ~ShardedClientCursor();
2009-02-25 07:23:58 +01:00
long long getId();
2011-01-04 06:40:41 +01:00
2009-02-25 06:57:31 +01:00
/**
* @return whether there is more data left
*/
2011-01-04 06:40:41 +01:00
bool sendNextBatch( Request& r ) { return sendNextBatch( r , _ntoreturn ); }
2009-02-25 07:23:58 +01:00
bool sendNextBatch( Request& r , int ntoreturn );
2011-01-04 06:40:41 +01:00
2010-08-02 20:50:12 +02:00
void accessed();
/** @return idle time in ms */
long long idleTime( long long now );
2009-02-25 06:57:31 +01:00
protected:
2011-01-04 06:40:41 +01:00
2009-11-03 16:35:48 +01:00
ClusteredCursor * _cursor;
2011-01-04 06:40:41 +01:00
2009-02-25 06:57:31 +01:00
int _skip;
int _ntoreturn;
int _totalSent;
2009-02-25 07:23:58 +01:00
bool _done;
2009-02-25 06:57:31 +01:00
2009-11-03 16:35:48 +01:00
long long _id;
2010-08-02 20:50:12 +02:00
long long _lastAccessMillis; // 0 means no timeout
2009-02-25 06:57:31 +01:00
};
2010-05-29 01:29:44 +02:00
typedef boost::shared_ptr<ShardedClientCursor> ShardedClientCursorPtr;
2011-01-04 06:40:41 +01:00
2009-02-25 07:23:58 +01:00
class CursorCache {
public:
2011-01-04 06:40:41 +01:00
2010-08-02 20:50:12 +02:00
static long long TIMEOUT;
2010-05-29 01:29:44 +02:00
typedef map<long long,ShardedClientCursorPtr> MapSharded;
2010-05-28 20:23:37 +02:00
typedef map<long long,string> MapNormal;
2009-02-25 07:23:58 +01:00
CursorCache();
~CursorCache();
2011-01-04 06:40:41 +01:00
2010-05-29 01:29:44 +02:00
ShardedClientCursorPtr get( long long id );
void store( ShardedClientCursorPtr cursor );
2009-02-25 07:23:58 +01:00
void remove( long long id );
2010-05-28 20:23:37 +02:00
void storeRef( const string& server , long long id );
void gotKillCursors(Message& m );
2011-01-04 06:40:41 +01:00
2010-05-28 20:23:37 +02:00
void appendInfo( BSONObjBuilder& result );
2011-01-04 06:40:41 +01:00
long long genId();
2010-08-02 20:50:12 +02:00
void doTimeouts();
void startTimeoutThread();
2009-02-25 07:23:58 +01:00
private:
mongo::mutex _mutex;
2010-05-28 20:23:37 +02:00
MapSharded _cursors;
MapNormal _refs;
2011-01-04 06:40:41 +01:00
long long _shardedTotal;
2009-02-25 07:23:58 +01:00
};
2011-01-04 06:40:41 +01:00
2009-02-25 07:23:58 +01:00
extern CursorCache cursorCache;
2009-02-25 06:57:31 +01:00
}