00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #pragma once
00020
00021 #include "../pch.h"
00022 #include "dbclient.h"
00023 #include "redef_macros.h"
00024
00025 namespace mongo {
00026
00041 class SyncClusterConnection : public DBClientBase {
00042 public:
00046 SyncClusterConnection( const list<HostAndPort> & );
00047 SyncClusterConnection( string commaSeparated );
00048 SyncClusterConnection( string a , string b , string c );
00049 ~SyncClusterConnection();
00050
00054 bool prepare( string& errmsg );
00055
00059 bool fsync( string& errmsg );
00060
00061
00062
00063 virtual BSONObj findOne(const string &ns, const Query& query, const BSONObj *fieldsToReturn, int queryOptions);
00064
00065 virtual auto_ptr<DBClientCursor> query(const string &ns, Query query, int nToReturn, int nToSkip,
00066 const BSONObj *fieldsToReturn, int queryOptions, int batchSize );
00067
00068 virtual auto_ptr<DBClientCursor> getMore( const string &ns, long long cursorId, int nToReturn, int options );
00069
00070 virtual void insert( const string &ns, BSONObj obj );
00071
00072 virtual void insert( const string &ns, const vector< BSONObj >& v );
00073
00074 virtual void remove( const string &ns , Query query, bool justOne );
00075
00076 virtual void update( const string &ns , Query query , BSONObj obj , bool upsert , bool multi );
00077
00078 virtual bool call( Message &toSend, Message &response, bool assertOk , string * actualServer );
00079 virtual void say( Message &toSend );
00080 virtual void sayPiggyBack( Message &toSend );
00081
00082 virtual void killCursor( long long cursorID );
00083
00084 virtual string getServerAddress() const { return _address; }
00085 virtual bool isFailed() const { return false; }
00086 virtual string toString() { return _toString(); }
00087
00088 virtual BSONObj getLastErrorDetailed();
00089
00090 virtual bool callRead( Message& toSend , Message& response );
00091
00092 virtual ConnectionString::ConnectionType type() const { return ConnectionString::SYNC; }
00093
00094 private:
00095 SyncClusterConnection( SyncClusterConnection& prev );
00096 string _toString() const;
00097 bool _commandOnActive(const string &dbname, const BSONObj& cmd, BSONObj &info, int options=0);
00098 auto_ptr<DBClientCursor> _queryOnActive(const string &ns, Query query, int nToReturn, int nToSkip,
00099 const BSONObj *fieldsToReturn, int queryOptions, int batchSize );
00100 int _lockType( const string& name );
00101 void _checkLast();
00102 void _connect( string host );
00103
00104 string _address;
00105 vector<string> _connAddresses;
00106 vector<DBClientConnection*> _conns;
00107 map<string,int> _lockTypes;
00108 mongo::mutex _mutex;
00109
00110 vector<BSONObj> _lastErrors;
00111 };
00112
00113 class UpdateNotTheSame : public UserException {
00114 public:
00115 UpdateNotTheSame( int code , const string& msg , const vector<string>& addrs , const vector<BSONObj>& lastErrors )
00116 : UserException( code , msg ) , _addrs( addrs ) , _lastErrors( lastErrors ) {
00117 assert( _addrs.size() == _lastErrors.size() );
00118 }
00119
00120 virtual ~UpdateNotTheSame() throw() {
00121 }
00122
00123 unsigned size() const {
00124 return _addrs.size();
00125 }
00126
00127 pair<string,BSONObj> operator[](unsigned i) const {
00128 return make_pair( _addrs[i] , _lastErrors[i] );
00129 }
00130
00131 private:
00132
00133 vector<string> _addrs;
00134 vector<BSONObj> _lastErrors;
00135 };
00136
00137 };
00138
00139 #include "undef_macros.h"