00001 // client.h 00002 00003 /* 00004 * Copyright (C) 2010 10gen Inc. 00005 * 00006 * This program is free software: you can redistribute it and/or modify 00007 * it under the terms of the GNU Affero General Public License, version 3, 00008 * as published by the Free Software Foundation. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU Affero General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Affero General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #include "../pch.h" 00020 00021 namespace mongo { 00022 00028 class ClientInfo { 00029 public: 00030 ClientInfo(); 00031 ~ClientInfo(); 00032 00034 void newRequest( AbstractMessagingPort* p = 0 ); 00035 00037 void disconnect(); 00038 00042 HostAndPort getRemote() const { return _remote; } 00043 00048 void addShard( const string& shard ); 00049 00053 set<string> * getPrev() const { return _prev; }; 00054 00058 const set<string>& sinceLastGetError() const { return _sinceLastGetError; } 00059 00063 void clearSinceLastGetError() { _sinceLastGetError.clear(); } 00064 00065 00069 void clearCurrentShards(){ _cur->clear(); } 00070 00076 bool getLastError( const BSONObj& options , BSONObjBuilder& result , bool fromWriteBackListener = false ); 00077 00079 bool autoSplitOk() const { return _autoSplitOk; } 00080 00081 void noAutoSplit() { _autoSplitOk = false; } 00082 00083 static ClientInfo * get(); 00084 00085 private: 00086 00087 struct WBInfo { 00088 WBInfo( ConnectionId c , OID o ) : connectionId( c ) , id( o ) {} 00089 ConnectionId connectionId; 00090 OID id; 00091 }; 00092 00093 // for getLastError 00094 void _addWriteBack( vector<WBInfo>& all , const BSONObj& o ); 00095 vector<BSONObj> _handleWriteBacks( vector<WBInfo>& all , bool fromWriteBackListener ); 00096 00097 00098 int _id; // unique client id 00099 HostAndPort _remote; // server:port of remote socket end 00100 00101 // we use _a and _b to store shards we've talked to on the current request and the previous 00102 // we use 2 so we can flip for getLastError type operations 00103 00104 set<string> _a; // actual set for _cur or _prev 00105 set<string> _b; // " 00106 00107 set<string> * _cur; // pointer to _a or _b depending on state 00108 set<string> * _prev; // "" 00109 00110 00111 set<string> _sinceLastGetError; // all shards accessed since last getLastError 00112 00113 int _lastAccess; 00114 bool _autoSplitOk; 00115 00116 static boost::thread_specific_ptr<ClientInfo> _tlInfo; 00117 }; 00118 00119 00120 }