2009-02-06 14:11:31 -05:00
|
|
|
// request.h
|
2010-02-09 16:48:21 -05:00
|
|
|
/*
|
|
|
|
|
* 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-06 14:11:31 -05:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2010-04-27 15:33:27 -04:00
|
|
|
#include "../pch.h"
|
2009-02-06 14:11:31 -05:00
|
|
|
#include "../util/message.h"
|
|
|
|
|
#include "../db/dbmessage.h"
|
2009-02-12 21:03:46 -05:00
|
|
|
#include "config.h"
|
2009-11-03 10:35:48 -05:00
|
|
|
#include "util.h"
|
2009-02-06 14:11:31 -05:00
|
|
|
|
|
|
|
|
namespace mongo {
|
2010-05-05 18:41:59 -04:00
|
|
|
|
2009-02-06 14:11:31 -05:00
|
|
|
|
2010-05-05 18:41:59 -04:00
|
|
|
class OpCounters;
|
2009-09-14 11:33:42 -04:00
|
|
|
class ClientInfo;
|
|
|
|
|
|
2009-02-20 10:46:42 -05:00
|
|
|
class Request : boost::noncopyable {
|
2009-02-06 14:11:31 -05:00
|
|
|
public:
|
2009-03-01 23:43:00 -05:00
|
|
|
Request( Message& m, AbstractMessagingPort* p );
|
2009-02-06 14:11:31 -05:00
|
|
|
|
2009-02-19 13:26:25 -05:00
|
|
|
// ---- message info -----
|
2010-07-22 15:39:20 -04:00
|
|
|
|
2009-02-19 13:26:25 -05:00
|
|
|
|
2010-04-20 12:58:04 -04:00
|
|
|
const char * getns() const {
|
2009-02-06 14:11:31 -05:00
|
|
|
return _d.getns();
|
|
|
|
|
}
|
2010-04-20 12:58:04 -04:00
|
|
|
int op() const {
|
2010-05-12 15:26:00 -07:00
|
|
|
return _m.operation();
|
2009-02-19 12:55:01 -05:00
|
|
|
}
|
2010-04-20 12:58:04 -04:00
|
|
|
bool expectResponse() const {
|
2009-02-19 12:55:01 -05:00
|
|
|
return op() == dbQuery || op() == dbGetMore;
|
|
|
|
|
}
|
2010-04-20 12:58:04 -04:00
|
|
|
bool isCommand() const;
|
|
|
|
|
|
|
|
|
|
MSGID id() const {
|
2009-02-06 14:11:31 -05:00
|
|
|
return _id;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-28 14:18:51 -04:00
|
|
|
DBConfigPtr getConfig() const {
|
2010-07-22 15:39:20 -04:00
|
|
|
assert( _didInit );
|
2009-02-06 15:44:21 -05:00
|
|
|
return _config;
|
|
|
|
|
}
|
2010-04-20 12:58:04 -04:00
|
|
|
bool isShardingEnabled() const {
|
2010-07-22 15:39:20 -04:00
|
|
|
assert( _didInit );
|
2009-09-01 16:30:20 -04:00
|
|
|
return _config->isShardingEnabled();
|
|
|
|
|
}
|
2009-02-19 13:26:25 -05:00
|
|
|
|
2010-05-26 12:40:46 -04:00
|
|
|
ChunkManagerPtr getChunkManager() const {
|
2010-07-22 15:39:20 -04:00
|
|
|
assert( _didInit );
|
2009-09-01 16:30:20 -04:00
|
|
|
return _chunkManager;
|
2009-02-20 10:46:42 -05:00
|
|
|
}
|
2009-09-14 11:33:42 -04:00
|
|
|
|
2010-04-20 12:58:04 -04:00
|
|
|
int getClientId() const {
|
2009-09-14 11:33:42 -04:00
|
|
|
return _clientId;
|
|
|
|
|
}
|
2010-04-20 12:58:04 -04:00
|
|
|
ClientInfo * getClientInfo() const {
|
2009-09-14 11:33:42 -04:00
|
|
|
return _clientInfo;
|
|
|
|
|
}
|
2009-02-20 10:46:42 -05:00
|
|
|
|
2009-02-19 13:26:25 -05:00
|
|
|
// ---- remote location info -----
|
|
|
|
|
|
2010-04-27 12:32:59 -04:00
|
|
|
|
|
|
|
|
Shard primaryShard() const ;
|
2009-02-19 13:26:25 -05:00
|
|
|
|
|
|
|
|
// ---- low level access ----
|
2009-02-17 11:41:34 -05:00
|
|
|
|
2010-05-28 14:23:37 -04:00
|
|
|
void reply( Message & response , const string& fromServer );
|
2009-02-06 14:11:31 -05:00
|
|
|
|
2010-04-20 12:58:04 -04:00
|
|
|
Message& m() { return _m; }
|
|
|
|
|
DbMessage& d() { return _d; }
|
|
|
|
|
AbstractMessagingPort* p() const { return _p; }
|
2009-02-06 14:11:31 -05:00
|
|
|
|
2009-04-07 15:19:27 -04:00
|
|
|
void process( int attempt = 0 );
|
2010-05-05 18:41:59 -04:00
|
|
|
|
|
|
|
|
void gotInsert();
|
2010-07-02 01:49:27 -04:00
|
|
|
|
2010-07-22 15:39:20 -04:00
|
|
|
void init();
|
|
|
|
|
|
2010-07-02 01:49:27 -04:00
|
|
|
void reset( bool reload=false );
|
2009-04-07 15:19:27 -04:00
|
|
|
|
2009-02-06 14:11:31 -05:00
|
|
|
private:
|
|
|
|
|
Message& _m;
|
|
|
|
|
DbMessage _d;
|
2009-03-01 23:43:00 -05:00
|
|
|
AbstractMessagingPort* _p;
|
2009-02-19 13:26:25 -05:00
|
|
|
|
2009-02-06 14:11:31 -05:00
|
|
|
MSGID _id;
|
2010-05-28 14:18:51 -04:00
|
|
|
DBConfigPtr _config;
|
2010-05-26 12:40:46 -04:00
|
|
|
ChunkManagerPtr _chunkManager;
|
2009-09-14 11:33:42 -04:00
|
|
|
|
|
|
|
|
int _clientId;
|
|
|
|
|
ClientInfo * _clientInfo;
|
2010-05-05 18:41:59 -04:00
|
|
|
|
|
|
|
|
OpCounters* _counter;
|
2010-07-22 15:39:20 -04:00
|
|
|
|
|
|
|
|
bool _didInit;
|
2009-02-06 14:11:31 -05:00
|
|
|
};
|
2009-09-14 11:33:42 -04:00
|
|
|
|
|
|
|
|
typedef map<int,ClientInfo*> ClientCache;
|
|
|
|
|
|
|
|
|
|
class ClientInfo {
|
|
|
|
|
public:
|
|
|
|
|
ClientInfo( int clientId );
|
|
|
|
|
~ClientInfo();
|
|
|
|
|
|
2010-04-27 16:49:22 -04:00
|
|
|
string getRemote() const { return _remote; }
|
|
|
|
|
|
2009-09-14 11:33:42 -04:00
|
|
|
void addShard( const string& shard );
|
|
|
|
|
set<string> * getPrev() const { return _prev; };
|
|
|
|
|
|
2010-04-27 16:49:22 -04:00
|
|
|
void newRequest( AbstractMessagingPort* p = 0 );
|
2009-09-14 11:33:42 -04:00
|
|
|
void disconnect();
|
2010-04-27 16:49:22 -04:00
|
|
|
|
2009-09-14 11:33:42 -04:00
|
|
|
static ClientInfo * get( int clientId = 0 , bool create = true );
|
2010-05-28 17:07:18 -04:00
|
|
|
static void disconnect( int clientId );
|
2009-09-14 11:33:42 -04:00
|
|
|
|
2010-06-02 12:30:08 -04:00
|
|
|
const set<string>& sinceLastGetError() const { return _sinceLastGetError; }
|
|
|
|
|
void clearSinceLastGetError(){
|
|
|
|
|
_sinceLastGetError.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-14 11:33:42 -04:00
|
|
|
private:
|
|
|
|
|
int _id;
|
2010-04-27 16:49:22 -04:00
|
|
|
string _remote;
|
|
|
|
|
|
2009-09-14 11:33:42 -04:00
|
|
|
set<string> _a;
|
|
|
|
|
set<string> _b;
|
|
|
|
|
set<string> * _cur;
|
|
|
|
|
set<string> * _prev;
|
|
|
|
|
int _lastAccess;
|
|
|
|
|
|
2010-06-02 12:30:08 -04:00
|
|
|
set<string> _sinceLastGetError;
|
|
|
|
|
|
2010-03-15 09:42:01 -07:00
|
|
|
static mongo::mutex _clientsLock;
|
2010-05-26 21:47:02 -04:00
|
|
|
static ClientCache& _clients;
|
2009-09-14 14:32:24 -04:00
|
|
|
static boost::thread_specific_ptr<ClientInfo> _tlInfo;
|
2009-09-14 11:33:42 -04:00
|
|
|
};
|
2009-02-06 14:11:31 -05:00
|
|
|
}
|
2009-02-23 13:56:54 -05:00
|
|
|
|
|
|
|
|
#include "strategy.h"
|