|
3 | 3 | use crate::connection::Connection;
|
4 | 4 | use crate::Client;
|
5 | 5 | use log::info;
|
| 6 | +use std::collections::HashMap; |
6 | 7 | use std::fmt;
|
7 | 8 | use std::net::IpAddr;
|
8 | 9 | use std::path::Path;
|
@@ -81,6 +82,22 @@ use tokio_postgres::{Error, Socket};
|
81 | 82 | /// `disable`, hosts and addresses will be tried in the order provided. If set to `random`, hosts will be tried
|
82 | 83 | /// in a random order, and the IP addresses resolved from a hostname will also be tried in a random order. Defaults
|
83 | 84 | /// to `disable`.
|
| 85 | +/// * `load_balance` - It expects true/false as its possible values. Default value is true. |
| 86 | +/// * `topology_keys` - It takes a comma separated geo-location values. A single geo-location can be given as 'cloud.region.zone'. |
| 87 | +/// Multiple geo-locations too can be specified, separated by comma (,). Each placement value can be suffixed with a colon (:) |
| 88 | +/// followed by a preference value between 1 and 10. A preference value of :1 means it is a primary placement. A preference |
| 89 | +/// value of :2 means it is the first fallback placement and so on. If no preference value is provided, it is considered to |
| 90 | +/// be a primary placement (equivalent to one with preference value :1). |
| 91 | +/// * `yb_servers_refresh_interval` - Time interval, in seconds, between two attempts to refresh the information about cluster nodes. |
| 92 | +/// Default is 300. Valid values are integers between 0 and 600. Value 0 means refresh for each connection request. Any value |
| 93 | +/// outside this range is ignored and the default is used. |
| 94 | +/// * `fallback_to_topology_keys_only` - (default value: false) Applicable only for TopologyAware Load Balancing. When set to true, |
| 95 | +/// the smart driver does not attempt to connect to servers outside of primary and fallback placements specified via property. |
| 96 | +/// The default behaviour is to fallback to any available server in the entire cluster. |
| 97 | +/// * `failed_host_reconnect_delay_secs` - (default value: 5 seconds) The driver marks a server as failed with a timestamp, when it cannot |
| 98 | +/// connect to it. Later, whenever it refreshes the server list via yb_servers(), if it sees the failed server in the response, |
| 99 | +/// it marks the server as UP only if failed-host-reconnect-delay-secs time has elapsed. (The yb_servers() function does not remove |
| 100 | +/// a failed server immediately from its result and retains it for a while.) |
84 | 101 | ///
|
85 | 102 | /// ## Examples
|
86 | 103 | ///
|
@@ -414,6 +431,103 @@ impl Config {
|
414 | 431 | self.config.get_load_balance_hosts()
|
415 | 432 | }
|
416 | 433 |
|
| 434 | + /// YugabyteDB Specific. |
| 435 | + /// |
| 436 | + /// Sets the load balance parameter. |
| 437 | + /// |
| 438 | + /// Defaults to false. |
| 439 | + pub fn load_balance(&mut self, load_balance: bool) -> &mut Config { |
| 440 | + self.config.load_balance(load_balance); |
| 441 | + self |
| 442 | + } |
| 443 | + |
| 444 | + /// YugabyteDB Specific. |
| 445 | + /// |
| 446 | + /// Gets the load balance value |
| 447 | + pub fn get_load_balance(&self) -> bool { |
| 448 | + self.config.get_load_balance() |
| 449 | + } |
| 450 | + |
| 451 | + /// YugabyteDB Specific. |
| 452 | + /// |
| 453 | + /// Sets the topology key parameter. |
| 454 | + /// |
| 455 | + /// Defaults to Hashmap::new(). |
| 456 | + pub fn topology_keys(&mut self, topology_key: &str, priority: i64) -> &mut Config { |
| 457 | + self.config.topology_keys(topology_key, priority); |
| 458 | + self |
| 459 | + } |
| 460 | + |
| 461 | + /// YugabyteDB Specific. |
| 462 | + /// |
| 463 | + /// Gets the host topology keys value. |
| 464 | + pub fn get_topology_keys(&self) -> HashMap<i64, Vec<String>> { |
| 465 | + self.config.get_topology_keys() |
| 466 | + } |
| 467 | + |
| 468 | + /// YugabyteDB Specific. |
| 469 | + /// |
| 470 | + /// Sets the yb_servers_refresh_interval parameter. |
| 471 | + /// |
| 472 | + /// Defaults to 300 sec. |
| 473 | + pub fn yb_servers_refresh_interval( |
| 474 | + &mut self, |
| 475 | + yb_servers_refresh_interval: Duration, |
| 476 | + ) -> &mut Config { |
| 477 | + self.config |
| 478 | + .yb_servers_refresh_interval(yb_servers_refresh_interval); |
| 479 | + self |
| 480 | + } |
| 481 | + |
| 482 | + /// YugabyteDB Specific. |
| 483 | + /// |
| 484 | + /// Gets the yb_servers_refresh_interval value. |
| 485 | + pub fn get_yb_servers_refresh_interval(&self) -> Duration { |
| 486 | + self.config.get_yb_servers_refresh_interval() |
| 487 | + } |
| 488 | + |
| 489 | + /// YugabyteDB Specific. |
| 490 | + /// |
| 491 | + /// Sets the fallback_to_topology_keys_only parameter. |
| 492 | + /// |
| 493 | + /// Defaults to false. |
| 494 | + pub fn fallback_to_topology_keys_only( |
| 495 | + &mut self, |
| 496 | + fallback_to_topology_keys_only: bool, |
| 497 | + ) -> &mut Config { |
| 498 | + self.config |
| 499 | + .fallback_to_topology_keys_only(fallback_to_topology_keys_only); |
| 500 | + self |
| 501 | + } |
| 502 | + |
| 503 | + /// YugabyteDB Specific. |
| 504 | + /// |
| 505 | + /// Gets the fallback_to_topology_keys_only value. |
| 506 | + pub fn get_fallback_to_topology_keys_only(&self) -> bool { |
| 507 | + self.config.get_fallback_to_topology_keys_only() |
| 508 | + } |
| 509 | + |
| 510 | + /// YugabyteDB Specific. |
| 511 | + /// |
| 512 | + /// Sets the failed_host_reconnect_delay_secs parameter. |
| 513 | + /// |
| 514 | + /// Defaults to 5 sec. |
| 515 | + pub fn failed_host_reconnect_delay_secs( |
| 516 | + &mut self, |
| 517 | + failed_host_reconnect_delay_secs: Duration, |
| 518 | + ) -> &mut Config { |
| 519 | + self.config |
| 520 | + .failed_host_reconnect_delay_secs(failed_host_reconnect_delay_secs); |
| 521 | + self |
| 522 | + } |
| 523 | + |
| 524 | + /// YugabyteDB Specific. |
| 525 | + /// |
| 526 | + /// Gets the failed_host_reconnect_delay_secs value. |
| 527 | + pub fn get_failed_host_reconnect_delay_secs(&self) -> Duration { |
| 528 | + self.config.get_failed_host_reconnect_delay_secs() |
| 529 | + } |
| 530 | + |
417 | 531 | /// Sets the notice callback.
|
418 | 532 | ///
|
419 | 533 | /// This callback will be invoked with the contents of every
|
|
0 commit comments