@@ -145,7 +145,7 @@ public ServerTuple selectServer(final ServerSelector serverSelector, final Opera
145
145
ServerDeprioritization serverDeprioritization = operationContext .getServerDeprioritization ();
146
146
boolean selectionWaitingLogged = false ;
147
147
Timeout computedServerSelectionTimeout = operationContext .getTimeoutContext ().computeServerSelectionTimeout ();
148
- logServerSelectionStarted (clusterId , operationContext . getId () , serverSelector , description );
148
+ logServerSelectionStarted (operationContext , clusterId , serverSelector , description );
149
149
while (true ) {
150
150
CountDownLatch currentPhaseLatch = phase .get ();
151
151
ClusterDescription currentDescription = description ;
@@ -154,24 +154,19 @@ public ServerTuple selectServer(final ServerSelector serverSelector, final Opera
154
154
computedServerSelectionTimeout , operationContext .getTimeoutContext ());
155
155
156
156
if (!currentDescription .isCompatibleWithDriver ()) {
157
- logAndThrowIncompatibleException (operationContext . getId () , serverSelector , currentDescription );
157
+ logAndThrowIncompatibleException (operationContext , serverSelector , currentDescription );
158
158
}
159
159
if (serverTuple != null ) {
160
160
ServerAddress serverAddress = serverTuple .getServerDescription ().getAddress ();
161
- logServerSelectionSucceeded (
162
- clusterId ,
163
- operationContext .getId (),
164
- serverAddress ,
165
- serverSelector ,
166
- currentDescription );
161
+ logServerSelectionSucceeded (operationContext , clusterId , serverAddress , serverSelector , currentDescription );
167
162
serverDeprioritization .updateCandidate (serverAddress );
168
163
return serverTuple ;
169
164
}
170
165
computedServerSelectionTimeout .onExpired (() ->
171
166
logAndThrowTimeoutException (operationContext , serverSelector , currentDescription ));
172
167
173
168
if (!selectionWaitingLogged ) {
174
- logServerSelectionWaiting (clusterId , operationContext . getId () , computedServerSelectionTimeout , serverSelector , currentDescription );
169
+ logServerSelectionWaiting (operationContext , clusterId , computedServerSelectionTimeout , serverSelector , currentDescription );
175
170
selectionWaitingLogged = true ;
176
171
}
177
172
connect ();
@@ -197,11 +192,7 @@ public void selectServerAsync(final ServerSelector serverSelector, final Operati
197
192
CountDownLatch currentPhase = phase .get ();
198
193
ClusterDescription currentDescription = description ;
199
194
200
- logServerSelectionStarted (
201
- clusterId ,
202
- operationContext .getId (),
203
- serverSelector ,
204
- currentDescription );
195
+ logServerSelectionStarted (operationContext , clusterId , serverSelector , currentDescription );
205
196
206
197
if (!handleServerSelectionRequest (request , currentPhase , currentDescription )) {
207
198
notifyWaitQueueHandler (request );
@@ -290,12 +281,11 @@ private boolean handleServerSelectionRequest(
290
281
291
282
try {
292
283
OperationContext operationContext = request .getOperationContext ();
293
- long operationId = operationContext .getId ();
294
284
if (currentPhase != request .phase ) {
295
285
CountDownLatch prevPhase = request .phase ;
296
286
request .phase = currentPhase ;
297
287
if (!description .isCompatibleWithDriver ()) {
298
- logAndThrowIncompatibleException (operationId , request .originalSelector , description );
288
+ logAndThrowIncompatibleException (operationContext , request .originalSelector , description );
299
289
}
300
290
301
291
@@ -309,23 +299,13 @@ private boolean handleServerSelectionRequest(
309
299
310
300
if (serverTuple != null ) {
311
301
ServerAddress serverAddress = serverTuple .getServerDescription ().getAddress ();
312
- logServerSelectionSucceeded (
313
- clusterId ,
314
- operationId ,
315
- serverAddress ,
316
- request .originalSelector ,
317
- description );
302
+ logServerSelectionSucceeded (operationContext , clusterId , serverAddress , request .originalSelector , description );
318
303
serverDeprioritization .updateCandidate (serverAddress );
319
304
request .onResult (serverTuple , null );
320
305
return true ;
321
306
}
322
307
if (prevPhase == null ) {
323
- logServerSelectionWaiting (
324
- clusterId ,
325
- operationId ,
326
- request .getTimeout (),
327
- request .originalSelector ,
328
- description );
308
+ logServerSelectionWaiting (operationContext , clusterId , request .getTimeout (), request .originalSelector , description );
329
309
}
330
310
}
331
311
@@ -410,11 +390,11 @@ protected ClusterableServer createServer(final ServerAddress serverAddress) {
410
390
}
411
391
412
392
private void logAndThrowIncompatibleException (
413
- final long operationId ,
393
+ final OperationContext operationContext ,
414
394
final ServerSelector serverSelector ,
415
395
final ClusterDescription clusterDescription ) {
416
396
MongoIncompatibleDriverException exception = createIncompatibleException (clusterDescription );
417
- logServerSelectionFailed (clusterId , operationId , exception , serverSelector , clusterDescription );
397
+ logServerSelectionFailed (operationContext , clusterId , exception , serverSelector , clusterDescription );
418
398
throw exception ;
419
399
}
420
400
@@ -448,7 +428,7 @@ private void logAndThrowTimeoutException(
448
428
MongoTimeoutException exception = operationContext .getTimeoutContext ().hasTimeoutMS ()
449
429
? new MongoOperationTimeoutException (message ) : new MongoTimeoutException (message );
450
430
451
- logServerSelectionFailed (clusterId , operationContext . getId () , exception , serverSelector , clusterDescription );
431
+ logServerSelectionFailed (operationContext , clusterId , exception , serverSelector , clusterDescription );
452
432
throw exception ;
453
433
}
454
434
@@ -557,34 +537,34 @@ public void run() {
557
537
}
558
538
559
539
static void logServerSelectionStarted (
540
+ final OperationContext operationContext ,
560
541
final ClusterId clusterId ,
561
- final long operationId ,
562
542
final ServerSelector serverSelector ,
563
543
final ClusterDescription clusterDescription ) {
564
544
if (STRUCTURED_LOGGER .isRequired (DEBUG , clusterId )) {
565
545
STRUCTURED_LOGGER .log (new LogMessage (
566
546
SERVER_SELECTION , DEBUG , "Server selection started" , clusterId ,
567
547
asList (
568
- new Entry (OPERATION , null ),
569
- new Entry (OPERATION_ID , operationId ),
548
+ new Entry (OPERATION , operationContext . getOperationName () ),
549
+ new Entry (OPERATION_ID , operationContext . getId () ),
570
550
new Entry (SELECTOR , serverSelector .toString ()),
571
551
new Entry (TOPOLOGY_DESCRIPTION , clusterDescription .getShortDescription ())),
572
552
"Server selection started for operation[ {}] with ID {}. Selector: {}, topology description: {}" ));
573
553
}
574
554
}
575
555
576
556
private static void logServerSelectionWaiting (
557
+ final OperationContext operationContext ,
577
558
final ClusterId clusterId ,
578
- final long operationId ,
579
559
final Timeout timeout ,
580
560
final ServerSelector serverSelector ,
581
561
final ClusterDescription clusterDescription ) {
582
562
if (STRUCTURED_LOGGER .isRequired (INFO , clusterId )) {
583
563
STRUCTURED_LOGGER .log (new LogMessage (
584
564
SERVER_SELECTION , INFO , "Waiting for suitable server to become available" , clusterId ,
585
565
asList (
586
- new Entry (OPERATION , null ),
587
- new Entry (OPERATION_ID , operationId ),
566
+ new Entry (OPERATION , operationContext . getOperationName () ),
567
+ new Entry (OPERATION_ID , operationContext . getId () ),
588
568
timeout .call (MILLISECONDS ,
589
569
() -> new Entry (REMAINING_TIME_MS , "infinite" ),
590
570
(ms ) -> new Entry (REMAINING_TIME_MS , ms ),
@@ -597,8 +577,8 @@ private static void logServerSelectionWaiting(
597
577
}
598
578
599
579
private static void logServerSelectionFailed (
580
+ final OperationContext operationContext ,
600
581
final ClusterId clusterId ,
601
- final long operationId ,
602
582
final MongoException failure ,
603
583
final ServerSelector serverSelector ,
604
584
final ClusterDescription clusterDescription ) {
@@ -612,8 +592,8 @@ private static void logServerSelectionFailed(
612
592
STRUCTURED_LOGGER .log (new LogMessage (
613
593
SERVER_SELECTION , DEBUG , "Server selection failed" , clusterId ,
614
594
asList (
615
- new Entry (OPERATION , null ),
616
- new Entry (OPERATION_ID , operationId ),
595
+ new Entry (OPERATION , operationContext . getOperationName () ),
596
+ new Entry (OPERATION_ID , operationContext . getId () ),
617
597
new Entry (FAILURE , failureDescription ),
618
598
new Entry (SELECTOR , serverSelector .toString ()),
619
599
new Entry (TOPOLOGY_DESCRIPTION , clusterDescription .getShortDescription ())),
@@ -622,17 +602,17 @@ private static void logServerSelectionFailed(
622
602
}
623
603
624
604
static void logServerSelectionSucceeded (
605
+ final OperationContext operationContext ,
625
606
final ClusterId clusterId ,
626
- final long operationId ,
627
607
final ServerAddress serverAddress ,
628
608
final ServerSelector serverSelector ,
629
609
final ClusterDescription clusterDescription ) {
630
610
if (STRUCTURED_LOGGER .isRequired (DEBUG , clusterId )) {
631
611
STRUCTURED_LOGGER .log (new LogMessage (
632
612
SERVER_SELECTION , DEBUG , "Server selection succeeded" , clusterId ,
633
613
asList (
634
- new Entry (OPERATION , null ),
635
- new Entry (OPERATION_ID , operationId ),
614
+ new Entry (OPERATION , operationContext . getOperationName () ),
615
+ new Entry (OPERATION_ID , operationContext . getId () ),
636
616
new Entry (SERVER_HOST , serverAddress .getHost ()),
637
617
new Entry (SERVER_PORT , serverAddress instanceof UnixServerAddress ? null : serverAddress .getPort ()),
638
618
new Entry (SELECTOR , serverSelector .toString ()),
0 commit comments