@@ -47,6 +47,8 @@ namespace mongo {
4747 using DBClientBase::update;
4848 using DBClientBase::remove;
4949
50+ class QueryHandler ;
51+
5052 /* *
5153 * @param commaSeparated should be 3 hosts comma separated
5254 */
@@ -116,6 +118,13 @@ namespace mongo {
116118 virtual void setRunCommandHook (DBClientWithCommands::RunCommandHookFunc func);
117119 virtual void setPostRunCommandHook (DBClientWithCommands::PostRunCommandHookFunc func);
118120
121+ /* *
122+ * Allow custom query processing through an external (e.g. mongos-only) service.
123+ *
124+ * Takes ownership of attached handler.
125+ */
126+ void attachQueryHandler ( QueryHandler* handler );
127+
119128 protected:
120129 virtual void _auth (const BSONObj& params);
121130
@@ -132,14 +141,47 @@ namespace mongo {
132141 string _address;
133142 vector<string> _connAddresses;
134143 vector<DBClientConnection*> _conns;
135- map<string,int > _lockTypes;
136- mongo::mutex _mutex;
137144
138145 vector<BSONObj> _lastErrors;
139146
147+ // Optionally attached by user
148+ scoped_ptr<QueryHandler> _customQueryHandler;
149+
150+ mongo::mutex _mutex;
151+ map<string,int > _lockTypes;
152+ // End mutex
153+
140154 double _socketTimeout;
141155 };
142156
157+ /* *
158+ * Interface for custom query processing for the SCC.
159+ * Allows plugging different host query behaviors for different types of queries.
160+ */
161+ class SyncClusterConnection ::QueryHandler {
162+ public:
163+
164+ virtual ~QueryHandler () {};
165+
166+ /* *
167+ * Returns true if the query can be processed using this handler.
168+ */
169+ virtual bool canHandleQuery ( const string& ns, Query query ) = 0;
170+
171+ /* *
172+ * Returns a cursor on one of the hosts with the desired results for the query.
173+ * May throw or return an empty auto_ptr on failure.
174+ */
175+ virtual auto_ptr<DBClientCursor> handleQuery ( const vector<string>& hosts,
176+ const string &ns,
177+ Query query,
178+ int nToReturn,
179+ int nToSkip,
180+ const BSONObj *fieldsToReturn,
181+ int queryOptions,
182+ int batchSize ) = 0;
183+ };
184+
143185 class MONGO_CLIENT_API UpdateNotTheSame : public UserException {
144186 public:
145187 UpdateNotTheSame ( int code , const string& msg , const vector<string>& addrs , const vector<BSONObj>& lastErrors )
0 commit comments