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

137 lines
3.2 KiB
C
Raw Normal View History

// request.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/>.
*/
#pragma once
2009-02-06 20:25:06 +01:00
#include "../stdafx.h"
#include "../util/message.h"
#include "../db/dbmessage.h"
2009-02-13 03:03:46 +01:00
#include "config.h"
2009-11-03 16:35:48 +01:00
#include "util.h"
namespace mongo {
2009-09-14 17:33:42 +02:00
class ClientInfo;
2009-02-20 16:46:42 +01:00
class Request : boost::noncopyable {
public:
2009-03-02 05:43:00 +01:00
Request( Message& m, AbstractMessagingPort* p );
// ---- message info -----
const char * getns(){
return _d.getns();
}
2009-02-19 18:55:01 +01:00
int op(){
return _m.data->operation();
}
bool expectResponse(){
return op() == dbQuery || op() == dbGetMore;
}
MSGID id(){
return _id;
}
2009-02-06 21:44:21 +01:00
DBConfig * getConfig(){
return _config;
}
bool isShardingEnabled(){
return _config->isShardingEnabled();
}
ChunkManager * getChunkManager(){
return _chunkManager;
2009-02-20 16:46:42 +01:00
}
2009-09-14 17:33:42 +02:00
int getClientId(){
return _clientId;
}
ClientInfo * getClientInfo(){
return _clientInfo;
}
2009-02-20 16:46:42 +01:00
// ---- remote location info -----
2009-02-06 21:44:21 +01:00
string singleServerName();
2009-02-06 21:44:21 +01:00
const char * primaryName(){
return _config->getPrimary().c_str();
2009-02-06 21:44:21 +01:00
}
// ---- low level access ----
2009-02-17 17:41:34 +01:00
void reply( Message & response ){
2009-03-02 05:43:00 +01:00
_p->reply( _m , response , _id );
}
Message& m(){ return _m; }
DbMessage& d(){ return _d; }
2009-03-02 05:43:00 +01:00
AbstractMessagingPort* p(){ return _p; }
2009-04-07 21:19:27 +02:00
void process( int attempt = 0 );
private:
2009-04-07 21:19:27 +02:00
void reset( bool reload=false );
2009-04-07 21:19:27 +02:00
Message& _m;
DbMessage _d;
2009-03-02 05:43:00 +01:00
AbstractMessagingPort* _p;
MSGID _id;
2009-02-06 21:44:21 +01:00
DBConfig * _config;
ChunkManager * _chunkManager;
2009-09-14 17:33:42 +02:00
int _clientId;
ClientInfo * _clientInfo;
};
2009-09-14 17:33:42 +02:00
typedef map<int,ClientInfo*> ClientCache;
class ClientInfo {
public:
ClientInfo( int clientId );
~ClientInfo();
void addShard( const string& shard );
set<string> * getPrev() const { return _prev; };
void newRequest();
void disconnect();
static ClientInfo * get( int clientId = 0 , bool create = true );
private:
int _id;
set<string> _a;
set<string> _b;
set<string> * _cur;
set<string> * _prev;
int _lastAccess;
static boost::mutex _clientsLock;
2009-09-14 17:33:42 +02:00
static ClientCache _clients;
static boost::thread_specific_ptr<ClientInfo> _tlInfo;
2009-09-14 17:33:42 +02:00
};
}
2009-02-23 19:56:54 +01:00
#include "strategy.h"