@@ -62,7 +62,7 @@ public DBTCPConnector( Mongo m , List<ServerAddress> all )
62
62
63
63
_createLogger .info ( all + " -> " + getAddress () );
64
64
}
65
-
65
+
66
66
public void start () {
67
67
if (_rsStatus != null )
68
68
_rsStatus .start ();
@@ -127,7 +127,7 @@ WriteResult _checkWriteError( DB db , MyPort mp , DBPort port , WriteConcern con
127
127
128
128
if ( ! e .hasErr () )
129
129
return new WriteResult ( e , concern );
130
-
130
+
131
131
e .throwOnError ();
132
132
return null ;
133
133
}
@@ -137,7 +137,7 @@ public WriteResult say( DB db , OutMessage m , WriteConcern concern )
137
137
throws MongoException {
138
138
return say ( db , m , concern , null );
139
139
}
140
-
140
+
141
141
@ Override
142
142
public WriteResult say ( DB db , OutMessage m , WriteConcern concern , ServerAddress hostNeeded )
143
143
throws MongoException {
@@ -164,7 +164,7 @@ public WriteResult say( DB db , OutMessage m , WriteConcern concern , ServerAddr
164
164
165
165
if ( concern .raiseNetworkErrors () )
166
166
throw new MongoException .Network ( "can't say something" , ioe );
167
-
167
+
168
168
CommandResult res = new CommandResult (port .serverAddress ());
169
169
res .put ( "ok" , false );
170
170
res .put ( "$err" , "NETWORK ERROR" );
@@ -182,7 +182,7 @@ public WriteResult say( DB db , OutMessage m , WriteConcern concern , ServerAddr
182
182
m .doneWithMessage ();
183
183
}
184
184
}
185
-
185
+
186
186
@ Override
187
187
public Response call ( DB db , DBCollection coll , OutMessage m , ServerAddress hostNeeded , DBDecoder decoder )
188
188
throws MongoException {
@@ -195,20 +195,22 @@ public Response call( DB db , DBCollection coll , OutMessage m , ServerAddress h
195
195
}
196
196
197
197
@ Override
198
- public Response call ( DB db , DBCollection coll , OutMessage m , ServerAddress hostNeeded , int retries , ReadPreference readPref , DBDecoder decoder ) throws MongoException {
198
+ public Response call ( DB db , DBCollection coll , OutMessage m , ServerAddress hostNeeded , int retries , ReadPreference readPref , DBDecoder decoder ) throws MongoException {
199
+
199
200
if (readPref == null )
200
201
readPref = ReadPreference .PRIMARY ;
202
+
201
203
if (readPref == ReadPreference .PRIMARY && m .hasOption ( Bytes .QUERYOPTION_SLAVEOK ))
202
204
readPref = ReadPreference .SECONDARY ;
203
205
204
206
boolean secondaryOk = !(readPref == ReadPreference .PRIMARY );
205
207
206
208
_checkClosed ();
207
209
checkMaster ( false , !secondaryOk );
208
-
210
+
209
211
final MyPort mp = _myPort .get ();
210
212
final DBPort port = mp .get ( false , readPref , hostNeeded );
211
-
213
+
212
214
Response res = null ;
213
215
boolean retry = false ;
214
216
try {
@@ -222,8 +224,8 @@ public Response call( DB db, DBCollection coll, OutMessage m, ServerAddress host
222
224
retry = retries > 0 && !coll ._name .equals ( "$cmd" )
223
225
&& !(ioe instanceof SocketTimeoutException ) && _error ( ioe , secondaryOk );
224
226
if ( !retry ){
225
- throw new MongoException .Network ( "can't call something : " + port .host () + "/" + db ,
226
- ioe );
227
+ throw new MongoException .Network ( "can't call something : " + port .host () + "/" + db ,
228
+ ioe );
227
229
}
228
230
}
229
231
catch ( RuntimeException re ){
@@ -237,15 +239,15 @@ public Response call( DB db, DBCollection coll, OutMessage m, ServerAddress host
237
239
return call ( db , coll , m , hostNeeded , retries - 1 , readPref , decoder );
238
240
239
241
ServerError err = res .getError ();
240
-
242
+
241
243
if ( err != null && err .isNotMasterError () ){
242
244
checkMaster ( true , true );
243
245
if ( retries <= 0 ){
244
246
throw new MongoException ( "not talking to master and retries used up" );
245
247
}
246
248
return call ( db , coll , m , hostNeeded , retries -1 , readPref , decoder );
247
249
}
248
-
250
+
249
251
m .doneWithMessage ();
250
252
return res ;
251
253
}
@@ -272,7 +274,7 @@ public List<ServerAddress> getServerAddressList() {
272
274
if (_rsStatus != null ) {
273
275
return _rsStatus .getServerAddressList ();
274
276
}
275
-
277
+
276
278
ServerAddress master = getAddress ();
277
279
if (master != null ) {
278
280
// single server
@@ -319,7 +321,7 @@ boolean _error( Throwable t, boolean secondaryOk )
319
321
class MyPort {
320
322
321
323
DBPort get ( boolean keep , ReadPreference readPref , ServerAddress hostNeeded ){
322
-
324
+
323
325
if ( hostNeeded != null ){
324
326
// asked for a specific host
325
327
return _portHolder .get ( hostNeeded ).get ();
@@ -338,7 +340,7 @@ DBPort get( boolean keep , ReadPreference readPref, ServerAddress hostNeeded ){
338
340
_requestPort .getPool ().done (_requestPort );
339
341
_requestPort = null ;
340
342
}
341
-
343
+
342
344
if ( !(readPref == ReadPreference .PRIMARY ) && _rsStatus != null ){
343
345
// if not a primary read set, try to use a secondary
344
346
// Do they want a Secondary, or a specific tag set?
@@ -373,7 +375,7 @@ DBPort get( boolean keep , ReadPreference readPref, ServerAddress hostNeeded ){
373
375
374
376
return p ;
375
377
}
376
-
378
+
377
379
void done ( DBPort p ){
378
380
// keep request port
379
381
if ( p != _requestPort ){
@@ -394,14 +396,14 @@ void error( DBPort p , Exception e ){
394
396
// depending on type of error, may need to close other connections in pool
395
397
p .getPool ().gotError (e );
396
398
}
397
-
399
+
398
400
void requestEnsureConnection (){
399
401
if ( ! _inRequest )
400
402
return ;
401
403
402
404
if ( _requestPort != null )
403
405
return ;
404
-
406
+
405
407
_requestPort = _masterPortPool .get ();
406
408
}
407
409
@@ -420,10 +422,10 @@ void requestDone(){
420
422
// DBPortPool _requestPool;
421
423
boolean _inRequest ;
422
424
}
423
-
425
+
424
426
void checkMaster ( boolean force , boolean failIfNoMaster )
425
427
throws MongoException {
426
-
428
+
427
429
if ( _rsStatus != null ){
428
430
if ( _masterPortPool == null || force ){
429
431
ReplicaSetStatus .Node n = _rsStatus .ensureMaster ();
@@ -470,7 +472,7 @@ int fetchMaxBsonObjectSize() {
470
472
471
473
void testMaster ()
472
474
throws MongoException {
473
-
475
+
474
476
DBPort p = null ;
475
477
try {
476
478
p = _masterPortPool .get ();
@@ -504,7 +506,7 @@ public String debugString(){
504
506
505
507
return buf .toString ();
506
508
}
507
-
509
+
508
510
public void close (){
509
511
_closed = true ;
510
512
if ( _portHolder != null ) {
0 commit comments