@@ -502,18 +502,42 @@ def scan!(sync=true)
502
502
true
503
503
end
504
504
505
+ # Runs SDAM flow on the cluster.
506
+ #
507
+ # This method can be invoked to process a new server description returned
508
+ # by the server on a monitoring or non-monitoring connection, and also
509
+ # by the driver when it marks a server unknown as a result of a (network)
510
+ # error.
511
+ #
505
512
# @param [ Server::Description ] previous_desc Previous server description.
506
513
# @param [ Server::Description ] updated_desc The changed description.
514
+ # @param [ Hash ] options Options.
515
+ #
516
+ # @option options [ true | false ] :keep_connection_pool Usually when the
517
+ # new server description is unknown, the connection pool on the
518
+ # respective server is cleared. Set this option to true to keep the
519
+ # existing connection pool (required when handling not master errors
520
+ # on 4.2+ servers).
507
521
#
508
522
# @api private
509
- def run_sdam_flow ( previous_desc , updated_desc )
523
+ def run_sdam_flow ( previous_desc , updated_desc , options = { } )
510
524
@sdam_flow_lock . synchronize do
511
525
flow = SdamFlow . new ( self , previous_desc , updated_desc )
512
526
flow . server_description_changed
513
527
514
528
# SDAM flow may alter the updated description - grab the final
515
529
# version for the purposes of broadcasting if a server is available
516
530
updated_desc = flow . updated_desc
531
+
532
+ unless options [ :keep_connection_pool ]
533
+ if flow . became_unknown?
534
+ servers_list . each do |server |
535
+ if server . address == updated_desc . address
536
+ server . clear_connection_pool
537
+ end
538
+ end
539
+ end
540
+ end
517
541
end
518
542
519
543
# Some updated descriptions, e.g. a mismatched me one, result in the
0 commit comments