@@ -145,7 +145,7 @@ public ServerTuple selectServer(final ServerSelector serverSelector, final Opera
145145 ServerDeprioritization serverDeprioritization = operationContext .getServerDeprioritization ();
146146 boolean selectionWaitingLogged = false ;
147147 Timeout computedServerSelectionTimeout = operationContext .getTimeoutContext ().computeServerSelectionTimeout ();
148- logServerSelectionStarted (clusterId , operationContext . getId () , serverSelector , description );
148+ logServerSelectionStarted (operationContext , clusterId , serverSelector , description );
149149 while (true ) {
150150 CountDownLatch currentPhaseLatch = phase .get ();
151151 ClusterDescription currentDescription = description ;
@@ -154,24 +154,19 @@ public ServerTuple selectServer(final ServerSelector serverSelector, final Opera
154154 computedServerSelectionTimeout , operationContext .getTimeoutContext ());
155155
156156 if (!currentDescription .isCompatibleWithDriver ()) {
157- logAndThrowIncompatibleException (operationContext . getId () , serverSelector , currentDescription );
157+ logAndThrowIncompatibleException (operationContext , serverSelector , currentDescription );
158158 }
159159 if (serverTuple != null ) {
160160 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 );
167162 serverDeprioritization .updateCandidate (serverAddress );
168163 return serverTuple ;
169164 }
170165 computedServerSelectionTimeout .onExpired (() ->
171166 logAndThrowTimeoutException (operationContext , serverSelector , currentDescription ));
172167
173168 if (!selectionWaitingLogged ) {
174- logServerSelectionWaiting (clusterId , operationContext . getId () , computedServerSelectionTimeout , serverSelector , currentDescription );
169+ logServerSelectionWaiting (operationContext , clusterId , computedServerSelectionTimeout , serverSelector , currentDescription );
175170 selectionWaitingLogged = true ;
176171 }
177172 connect ();
@@ -197,11 +192,7 @@ public void selectServerAsync(final ServerSelector serverSelector, final Operati
197192 CountDownLatch currentPhase = phase .get ();
198193 ClusterDescription currentDescription = description ;
199194
200- logServerSelectionStarted (
201- clusterId ,
202- operationContext .getId (),
203- serverSelector ,
204- currentDescription );
195+ logServerSelectionStarted (operationContext , clusterId , serverSelector , currentDescription );
205196
206197 if (!handleServerSelectionRequest (request , currentPhase , currentDescription )) {
207198 notifyWaitQueueHandler (request );
@@ -290,12 +281,11 @@ private boolean handleServerSelectionRequest(
290281
291282 try {
292283 OperationContext operationContext = request .getOperationContext ();
293- long operationId = operationContext .getId ();
294284 if (currentPhase != request .phase ) {
295285 CountDownLatch prevPhase = request .phase ;
296286 request .phase = currentPhase ;
297287 if (!description .isCompatibleWithDriver ()) {
298- logAndThrowIncompatibleException (operationId , request .originalSelector , description );
288+ logAndThrowIncompatibleException (operationContext , request .originalSelector , description );
299289 }
300290
301291
@@ -309,23 +299,13 @@ private boolean handleServerSelectionRequest(
309299
310300 if (serverTuple != null ) {
311301 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 );
318303 serverDeprioritization .updateCandidate (serverAddress );
319304 request .onResult (serverTuple , null );
320305 return true ;
321306 }
322307 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 );
329309 }
330310 }
331311
@@ -410,11 +390,11 @@ protected ClusterableServer createServer(final ServerAddress serverAddress) {
410390 }
411391
412392 private void logAndThrowIncompatibleException (
413- final long operationId ,
393+ final OperationContext operationContext ,
414394 final ServerSelector serverSelector ,
415395 final ClusterDescription clusterDescription ) {
416396 MongoIncompatibleDriverException exception = createIncompatibleException (clusterDescription );
417- logServerSelectionFailed (clusterId , operationId , exception , serverSelector , clusterDescription );
397+ logServerSelectionFailed (operationContext , clusterId , exception , serverSelector , clusterDescription );
418398 throw exception ;
419399 }
420400
@@ -448,7 +428,7 @@ private void logAndThrowTimeoutException(
448428 MongoTimeoutException exception = operationContext .getTimeoutContext ().hasTimeoutMS ()
449429 ? new MongoOperationTimeoutException (message ) : new MongoTimeoutException (message );
450430
451- logServerSelectionFailed (clusterId , operationContext . getId () , exception , serverSelector , clusterDescription );
431+ logServerSelectionFailed (operationContext , clusterId , exception , serverSelector , clusterDescription );
452432 throw exception ;
453433 }
454434
@@ -557,34 +537,34 @@ public void run() {
557537 }
558538
559539 static void logServerSelectionStarted (
540+ final OperationContext operationContext ,
560541 final ClusterId clusterId ,
561- final long operationId ,
562542 final ServerSelector serverSelector ,
563543 final ClusterDescription clusterDescription ) {
564544 if (STRUCTURED_LOGGER .isRequired (DEBUG , clusterId )) {
565545 STRUCTURED_LOGGER .log (new LogMessage (
566546 SERVER_SELECTION , DEBUG , "Server selection started" , clusterId ,
567547 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 () ),
570550 new Entry (SELECTOR , serverSelector .toString ()),
571551 new Entry (TOPOLOGY_DESCRIPTION , clusterDescription .getShortDescription ())),
572552 "Server selection started for operation[ {}] with ID {}. Selector: {}, topology description: {}" ));
573553 }
574554 }
575555
576556 private static void logServerSelectionWaiting (
557+ final OperationContext operationContext ,
577558 final ClusterId clusterId ,
578- final long operationId ,
579559 final Timeout timeout ,
580560 final ServerSelector serverSelector ,
581561 final ClusterDescription clusterDescription ) {
582562 if (STRUCTURED_LOGGER .isRequired (INFO , clusterId )) {
583563 STRUCTURED_LOGGER .log (new LogMessage (
584564 SERVER_SELECTION , INFO , "Waiting for suitable server to become available" , clusterId ,
585565 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 () ),
588568 timeout .call (MILLISECONDS ,
589569 () -> new Entry (REMAINING_TIME_MS , "infinite" ),
590570 (ms ) -> new Entry (REMAINING_TIME_MS , ms ),
@@ -597,8 +577,8 @@ private static void logServerSelectionWaiting(
597577 }
598578
599579 private static void logServerSelectionFailed (
580+ final OperationContext operationContext ,
600581 final ClusterId clusterId ,
601- final long operationId ,
602582 final MongoException failure ,
603583 final ServerSelector serverSelector ,
604584 final ClusterDescription clusterDescription ) {
@@ -612,8 +592,8 @@ private static void logServerSelectionFailed(
612592 STRUCTURED_LOGGER .log (new LogMessage (
613593 SERVER_SELECTION , DEBUG , "Server selection failed" , clusterId ,
614594 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 () ),
617597 new Entry (FAILURE , failureDescription ),
618598 new Entry (SELECTOR , serverSelector .toString ()),
619599 new Entry (TOPOLOGY_DESCRIPTION , clusterDescription .getShortDescription ())),
@@ -622,17 +602,17 @@ private static void logServerSelectionFailed(
622602 }
623603
624604 static void logServerSelectionSucceeded (
605+ final OperationContext operationContext ,
625606 final ClusterId clusterId ,
626- final long operationId ,
627607 final ServerAddress serverAddress ,
628608 final ServerSelector serverSelector ,
629609 final ClusterDescription clusterDescription ) {
630610 if (STRUCTURED_LOGGER .isRequired (DEBUG , clusterId )) {
631611 STRUCTURED_LOGGER .log (new LogMessage (
632612 SERVER_SELECTION , DEBUG , "Server selection succeeded" , clusterId ,
633613 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 () ),
636616 new Entry (SERVER_HOST , serverAddress .getHost ()),
637617 new Entry (SERVER_PORT , serverAddress instanceof UnixServerAddress ? null : serverAddress .getPort ()),
638618 new Entry (SELECTOR , serverSelector .toString ()),
0 commit comments