@@ -740,9 +740,6 @@ _mongoc_cluster_select (mongoc_cluster_t *cluster,
740
740
* in the fast path of command dispatching.
741
741
*/
742
742
743
- #define IS_NEARER_THAN (n , msec ) \
744
- ((msec < 0 && (n)->ping_avg_msec >= 0) || ((n)->ping_avg_msec < msec))
745
-
746
743
count = 0 ;
747
744
748
745
for (i = 0 ; i < MONGOC_CLUSTER_MAX_NODES ; i ++ ) {
@@ -759,10 +756,33 @@ _mongoc_cluster_select (mongoc_cluster_t *cluster,
759
756
}
760
757
761
758
}
759
+ count ++ ;
760
+ }
761
+ }
762
+
763
+ /*
764
+ * Filter nodes with score less than highest score.
765
+ */
766
+ if (max_score ) {
767
+ for (i = 0 ; i < MONGOC_CLUSTER_MAX_NODES ; i ++ ) {
768
+ if (nodes [i ] && (scores [i ] < max_score )) {
769
+ nodes [i ] = NULL ;
770
+ count -- ;
771
+ }
772
+ }
773
+ }
774
+
775
+ /*
776
+ * Get the nearest node among those which have not been filtered out
777
+ */
778
+ #define IS_NEARER_THAN (n , msec ) \
779
+ ((msec < 0 && (n)->ping_avg_msec >= 0) || ((n)->ping_avg_msec < msec))
780
+
781
+ for (i = 0 ; i < MONGOC_CLUSTER_MAX_NODES ; i ++ ) {
782
+ if (nodes [i ]) {
762
783
if (IS_NEARER_THAN (nodes [i ], nearest )) {
763
784
nearest = nodes [i ]-> ping_avg_msec ;
764
785
}
765
- count ++ ;
766
786
}
767
787
}
768
788
@@ -775,27 +795,14 @@ _mongoc_cluster_select (mongoc_cluster_t *cluster,
775
795
watermark = nearest + cluster -> sec_latency_ms ;
776
796
for (i = 0 ; i < MONGOC_CLUSTER_MAX_NODES ; i ++ ) {
777
797
if (nodes [i ]) {
778
- if (nodes [i ]-> ping_avg_msec > (int32_t )watermark ) {
798
+ if (nodes [i ]-> ping_avg_msec > (int32_t )watermark ) {
779
799
nodes [i ] = NULL ;
780
800
count -- ;
781
801
}
782
802
}
783
803
}
784
804
}
785
805
786
- /*
787
- * Filter nodes with score less than highest score.
788
- */
789
- if (max_score ) {
790
- for (i = 0 ; i < MONGOC_CLUSTER_MAX_NODES ; i ++ ) {
791
- if (nodes [i ] && (scores [i ] < max_score )) {
792
- nodes [i ] = NULL ;
793
- count -- ;
794
- }
795
- }
796
- }
797
-
798
-
799
806
/*
800
807
* Mark the error as unable to locate a target node.
801
808
*/
0 commit comments