Files
mongo/s/request.h

156 lines
3.8 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
2010-04-27 15:33:27 -04:00
#include "../pch.h"
#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"
namespace mongo {
2010-05-05 18:41:59 -04: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 {
public:
2009-03-01 23:43:00 -05:00
Request( Message& m, AbstractMessagingPort* p );
// ---- message info -----
const char * getns() const {
return _d.getns();
}
int op() const {
2010-05-12 15:26:00 -07:00
return _m.operation();
2009-02-19 12:55:01 -05:00
}
bool expectResponse() const {
2009-02-19 12:55:01 -05:00
return op() == dbQuery || op() == dbGetMore;
}
bool isCommand() const;
MSGID id() const {
return _id;
}
2010-05-28 14:18:51 -04:00
DBConfigPtr getConfig() const {
assert( _didInit );
2009-02-06 15:44:21 -05:00
return _config;
}
bool isShardingEnabled() const {
assert( _didInit );
return _config->isShardingEnabled();
}
ChunkManagerPtr getChunkManager() const {
assert( _didInit );
return _chunkManager;
2009-02-20 10:46:42 -05:00
}
2009-09-14 11:33:42 -04:00
int getClientId() const {
2009-09-14 11:33:42 -04:00
return _clientId;
}
ClientInfo * getClientInfo() const {
2009-09-14 11:33:42 -04:00
return _clientInfo;
}
2009-02-20 10:46:42 -05:00
// ---- remote location info -----
Shard primaryShard() const ;
// ---- 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 );
Message& m() { return _m; }
DbMessage& d() { return _d; }
AbstractMessagingPort* p() const { return _p; }
2009-04-07 15:19:27 -04:00
void process( int attempt = 0 );
2010-05-05 18:41:59 -04:00
void gotInsert();
void init();
void reset( bool reload=false );
2009-04-07 15:19:27 -04:00
private:
Message& _m;
DbMessage _d;
2009-03-01 23:43:00 -05:00
AbstractMessagingPort* _p;
MSGID _id;
2010-05-28 14:18:51 -04:00
DBConfigPtr _config;
ChunkManagerPtr _chunkManager;
2009-09-14 11:33:42 -04:00
int _clientId;
ClientInfo * _clientInfo;
2010-05-05 18:41:59 -04:00
OpCounters* _counter;
bool _didInit;
};
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
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;
set<string> _sinceLastGetError;
static mongo::mutex _clientsLock;
2010-05-26 21:47:02 -04:00
static ClientCache& _clients;
static boost::thread_specific_ptr<ClientInfo> _tlInfo;
2009-09-14 11:33:42 -04:00
};
}
2009-02-23 13:56:54 -05:00
#include "strategy.h"