|
MongoDB
2.1.1-pre-
|
00001 // @file syncclusterconnection.h 00002 00003 /* 00004 * Copyright 2010 10gen Inc. 00005 * 00006 * Licensed under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 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> &, double socketTimeout = 0); 00047 SyncClusterConnection( string commaSeparated, double socketTimeout = 0); 00048 SyncClusterConnection( string a , string b , string c, double socketTimeout = 0 ); 00049 ~SyncClusterConnection(); 00050 00054 bool prepare( string& errmsg ); 00055 00059 bool fsync( string& errmsg ); 00060 00061 // --- from DBClientInterface 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, int flags=0); 00071 00072 virtual void insert( const string &ns, const vector< BSONObj >& v, int flags=0); 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, bool isRetry = false , string * actualServer = 0 ); 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(bool fsync=false, bool j=false, int w=0, int wtimeout=0); 00089 00090 virtual bool callRead( Message& toSend , Message& response ); 00091 00092 virtual ConnectionString::ConnectionType type() const { return ConnectionString::SYNC; } 00093 00094 void setAllSoTimeouts( double socketTimeout ); 00095 double getSoTimeout() const { return _socketTimeout; } 00096 00097 virtual bool auth(const string &dbname, const string &username, const string &password_text, string& errmsg, bool digestPassword, Auth::Level* level=NULL); 00098 00099 virtual bool lazySupported() const { return false; } 00100 private: 00101 SyncClusterConnection( SyncClusterConnection& prev, double socketTimeout = 0 ); 00102 string _toString() const; 00103 bool _commandOnActive(const string &dbname, const BSONObj& cmd, BSONObj &info, int options=0); 00104 auto_ptr<DBClientCursor> _queryOnActive(const string &ns, Query query, int nToReturn, int nToSkip, 00105 const BSONObj *fieldsToReturn, int queryOptions, int batchSize ); 00106 int _lockType( const string& name ); 00107 void _checkLast(); 00108 void _connect( string host ); 00109 00110 string _address; 00111 vector<string> _connAddresses; 00112 vector<DBClientConnection*> _conns; 00113 map<string,int> _lockTypes; 00114 mongo::mutex _mutex; 00115 00116 vector<BSONObj> _lastErrors; 00117 00118 double _socketTimeout; 00119 }; 00120 00121 class UpdateNotTheSame : public UserException { 00122 public: 00123 UpdateNotTheSame( int code , const string& msg , const vector<string>& addrs , const vector<BSONObj>& lastErrors ) 00124 : UserException( code , msg ) , _addrs( addrs ) , _lastErrors( lastErrors ) { 00125 assert( _addrs.size() == _lastErrors.size() ); 00126 } 00127 00128 virtual ~UpdateNotTheSame() throw() { 00129 } 00130 00131 unsigned size() const { 00132 return _addrs.size(); 00133 } 00134 00135 pair<string,BSONObj> operator[](unsigned i) const { 00136 return make_pair( _addrs[i] , _lastErrors[i] ); 00137 } 00138 00139 private: 00140 00141 vector<string> _addrs; 00142 vector<BSONObj> _lastErrors; 00143 }; 00144 00145 }; 00146 00147 #include "undef_macros.h"
1.8.0