cassandra_cpp/cassandra/
cluster.rs

1use crate::cassandra::error::*;
2use crate::cassandra::future::CassFuture;
3use crate::cassandra::policy::retry::RetryPolicy;
4use crate::cassandra::session::Session;
5use crate::cassandra::ssl::Ssl;
6use crate::cassandra::time::TimestampGen;
7use crate::cassandra::util::{Protected, ProtectedInner};
8
9use crate::cassandra_sys::cass_cluster_free;
10use crate::cassandra_sys::cass_cluster_new;
11use crate::cassandra_sys::cass_cluster_set_cloud_secure_connection_bundle_n;
12use crate::cassandra_sys::cass_cluster_set_cloud_secure_connection_bundle_no_ssl_lib_init_n;
13use crate::cassandra_sys::cass_cluster_set_connect_timeout;
14use crate::cassandra_sys::cass_cluster_set_connection_heartbeat_interval;
15use crate::cassandra_sys::cass_cluster_set_connection_idle_timeout;
16use crate::cassandra_sys::cass_cluster_set_contact_points_n;
17use crate::cassandra_sys::cass_cluster_set_core_connections_per_host;
18use crate::cassandra_sys::cass_cluster_set_credentials_n;
19use crate::cassandra_sys::cass_cluster_set_exponential_reconnect;
20use crate::cassandra_sys::cass_cluster_set_latency_aware_routing;
21use crate::cassandra_sys::cass_cluster_set_latency_aware_routing_settings;
22use crate::cassandra_sys::cass_cluster_set_load_balance_dc_aware_n;
23use crate::cassandra_sys::cass_cluster_set_load_balance_round_robin;
24use crate::cassandra_sys::cass_cluster_set_local_address_n;
25use crate::cassandra_sys::cass_cluster_set_max_concurrent_creation;
26use crate::cassandra_sys::cass_cluster_set_max_concurrent_requests_threshold;
27use crate::cassandra_sys::cass_cluster_set_max_connections_per_host;
28use crate::cassandra_sys::cass_cluster_set_max_requests_per_flush;
29use crate::cassandra_sys::cass_cluster_set_num_threads_io;
30use crate::cassandra_sys::cass_cluster_set_pending_requests_high_water_mark;
31use crate::cassandra_sys::cass_cluster_set_pending_requests_low_water_mark;
32use crate::cassandra_sys::cass_cluster_set_port;
33use crate::cassandra_sys::cass_cluster_set_protocol_version;
34use crate::cassandra_sys::cass_cluster_set_queue_size_event;
35use crate::cassandra_sys::cass_cluster_set_queue_size_io;
36use crate::cassandra_sys::cass_cluster_set_reconnect_wait_time;
37use crate::cassandra_sys::cass_cluster_set_request_timeout;
38use crate::cassandra_sys::cass_cluster_set_resolve_timeout;
39use crate::cassandra_sys::cass_cluster_set_retry_policy;
40use crate::cassandra_sys::cass_cluster_set_ssl;
41use crate::cassandra_sys::cass_cluster_set_tcp_keepalive;
42use crate::cassandra_sys::cass_cluster_set_tcp_nodelay;
43use crate::cassandra_sys::cass_cluster_set_timestamp_gen;
44use crate::cassandra_sys::cass_cluster_set_token_aware_routing;
45use crate::cassandra_sys::cass_cluster_set_token_aware_routing_shuffle_replicas;
46use crate::cassandra_sys::cass_cluster_set_use_schema;
47use crate::cassandra_sys::cass_cluster_set_whitelist_filtering;
48use crate::cassandra_sys::cass_cluster_set_write_bytes_high_water_mark;
49use crate::cassandra_sys::cass_cluster_set_write_bytes_low_water_mark;
50use crate::cassandra_sys::cass_false;
51
52use crate::cassandra_sys::cass_session_connect;
53use crate::cassandra_sys::cass_session_connect_keyspace_n;
54
55use crate::cassandra_sys::cass_true;
56use crate::cassandra_sys::CassCluster as _Cluster;
57
58use std::os::raw::c_char;
59
60use std::time::Duration;
61
62/// A CQL protocol version is just an integer.
63pub type CqlProtocol = i32;
64
65///
66/// The main class to use when interacting with a Cassandra cluster.
67/// Typically, one instance of this class will be created for each separate
68/// Cassandra cluster that your application interacts with.
69///
70/// # Examples
71/// ```
72/// # async fn test() {
73/// use cassandra_cpp::Cluster;
74/// let mut cluster = Cluster::default();
75/// cluster.set_contact_points("127.0.0.1").unwrap();
76/// let session = cluster.connect().await.unwrap();
77/// # }
78/// ```
79#[derive(Debug)]
80pub struct Cluster(*mut _Cluster);
81
82// The underlying C type has no thread-local state, and forbids only concurrent
83// mutation/free: https://datastax.github.io/cpp-driver/topics/#thread-safety
84unsafe impl Send for Cluster {}
85unsafe impl Sync for Cluster {}
86
87impl Drop for Cluster {
88    /// Frees a cluster instance.
89    fn drop(&mut self) {
90        unsafe { cass_cluster_free(self.0) }
91    }
92}
93
94impl ProtectedInner<*mut _Cluster> for Cluster {
95    fn inner(&self) -> *mut _Cluster {
96        self.0
97    }
98}
99
100impl Protected<*mut _Cluster> for Cluster {
101    fn build(inner: *mut _Cluster) -> Self {
102        if inner.is_null() {
103            panic!("Unexpected null pointer")
104        };
105        Cluster(inner)
106    }
107}
108
109impl Default for Cluster {
110    /// Creates a new cluster
111    fn default() -> Cluster {
112        unsafe { Cluster(cass_cluster_new()) }
113    }
114}
115
116impl Cluster {
117    /// Sets/Appends contact points. This *MUST* be set. The first call sets
118    /// the contact points and any subsequent calls appends additional contact
119    /// points. Passing an empty string will clear the contact points. White space
120    /// is stripped from the contact points.
121    ///
122    ///
123    /// {contact points: "127.0.0.1" "127.0.0.1,127.0.0.2", "server1.domain.com"}
124    ///
125    ///
126    pub fn set_contact_points(&mut self, contact_points: &str) -> Result<&mut Self> {
127        unsafe {
128            let cp_ptr = contact_points.as_ptr() as *const c_char;
129            let err = cass_cluster_set_contact_points_n(self.0, cp_ptr, contact_points.len());
130            err.to_result(self)
131        }
132    }
133
134    /// Sets the local address to bind when connecting to the cluster,
135    /// if desired.
136    ///
137    /// Only numeric addresses are supported.
138    pub fn set_local_address(&mut self, name: &str) -> Result<&mut Self> {
139        unsafe {
140            let name_ptr = name.as_ptr() as *const c_char;
141            let err = cass_cluster_set_local_address_n(self.0, name_ptr, name.len());
142            err.to_result(self)
143        }
144    }
145
146    /// Sets the port
147    ///
148    ///
149    /// Default: 9042
150    ///
151    pub fn set_port(&mut self, port: u16) -> Result<&mut Self> {
152        unsafe { cass_cluster_set_port(self.0, port as i32).to_result(self) }
153    }
154
155    /// Sets the SSL context and enables SSL
156    pub fn set_ssl(&mut self, ssl: Ssl) -> &Self {
157        unsafe {
158            cass_cluster_set_ssl(self.0, ssl.inner());
159            self
160        }
161    }
162
163    /// Sets the secure connection bundle path for processing DBaaS credentials.
164    pub fn set_cloud_secure_connection_bundle(&mut self, path: &str) -> Result<&mut Self> {
165        unsafe {
166            let path_ptr = path.as_ptr() as *const c_char;
167            let err =
168                cass_cluster_set_cloud_secure_connection_bundle_n(self.0, path_ptr, path.len());
169            err.to_result(self)
170        }
171    }
172
173    /// Sets the secure connection bundle path for processing DBaaS credentials, but it
174    /// does not initialize the underlying SSL library implementation. The SSL library still
175    /// needs to be initialized, but it's up to the client application to handle
176    /// initialization.
177    pub fn set_cloud_secure_connection_bundle_no_ssl_lib_init(
178        &mut self,
179        path: &str,
180    ) -> Result<&mut Self> {
181        unsafe {
182            let path_ptr = path.as_ptr() as *const c_char;
183            let err = cass_cluster_set_cloud_secure_connection_bundle_no_ssl_lib_init_n(
184                self.0,
185                path_ptr,
186                path.len(),
187            );
188            err.to_result(self)
189        }
190    }
191
192    /// Connects to the cassandra cluster
193    pub async fn connect(&mut self) -> Result<Session> {
194        let session = Session::new();
195        let connect_future = {
196            let connect = unsafe { cass_session_connect(session.inner(), self.0) };
197            CassFuture::build(session, connect)
198        };
199        connect_future.await
200    }
201
202    /// Connects to the cassandra cluster, setting the keyspace of the session.
203    pub async fn connect_keyspace(&mut self, keyspace: &str) -> Result<Session> {
204        let session = Session::new();
205        let connect_future = {
206            let keyspace_ptr = keyspace.as_ptr() as *const c_char;
207            let connect_keyspace = unsafe {
208                cass_session_connect_keyspace_n(
209                    session.inner(),
210                    self.inner(),
211                    keyspace_ptr,
212                    keyspace.len(),
213                )
214            };
215            CassFuture::build(session, connect_keyspace)
216        };
217        connect_future.await
218    }
219
220    /// Sets the protocol version. This will automatically downgrade to the lowest
221    /// supported protocol version.
222    ///
223    ///
224    /// Default: version 4
225    ///
226    pub fn set_protocol_version(&mut self, protocol_version: CqlProtocol) -> Result<&mut Self> {
227        unsafe { cass_cluster_set_protocol_version(self.0, protocol_version).to_result(self) }
228    }
229
230    /// Sets the number of IO threads. This is the number of threads
231    /// that will handle query requests.
232    ///
233    ///
234    /// Default: 1
235    ///
236    pub fn set_num_threads_io(&mut self, num_threads: u32) -> Result<&mut Self> {
237        unsafe { cass_cluster_set_num_threads_io(self.0, num_threads).to_result(self) }
238    }
239
240    /// Sets the size of the fixed size queue that stores pending requests.
241    ///
242    ///
243    /// Default: 8192
244    ///
245    pub fn set_queue_size_io(&mut self, queue_size: u32) -> Result<&mut Self> {
246        unsafe { cass_cluster_set_queue_size_io(self.0, queue_size).to_result(self) }
247    }
248
249    /// Sets the size of the fixed size queue that stores events.
250    ///
251    ///
252    /// Default: 8192
253    ///
254    pub fn set_queue_size_event(&mut self, queue_size: u32) -> Result<&mut Self> {
255        unsafe { cass_cluster_set_queue_size_event(self.0, queue_size).to_result(self) }
256    }
257
258    /// Sets the number of connections made to each server in each
259    /// IO thread.
260    ///
261    ///
262    /// Default: 1
263    ///
264    pub fn set_core_connections_per_host(&mut self, num_connections: u32) -> Result<&mut Self> {
265        unsafe {
266            cass_cluster_set_core_connections_per_host(self.0, num_connections).to_result(self)
267        }
268    }
269
270    /// Sets the maximum number of connections made to each server in each
271    /// IO thread.
272    ///
273    ///
274    /// Default: 2
275    ///
276    pub fn set_max_connections_per_host(&mut self, num_connections: u32) -> Result<&mut Self> {
277        unsafe {
278            cass_cluster_set_max_connections_per_host(self.0, num_connections).to_result(self)
279        }
280    }
281
282    /// Sets the amount of time to wait before attempting to reconnect.
283    ///
284    ///
285    /// Default: 1000ms
286    ///
287    pub fn set_reconnect_wait_time(&mut self, wait_time: u32) -> &Self {
288        unsafe {
289            cass_cluster_set_reconnect_wait_time(self.0, wait_time);
290        }
291        self
292    }
293
294    /// Sets the maximum number of connections that will be created concurrently.
295    /// Connections are created when the current connections are unable to keep up with
296    /// request throughput.
297    ///
298    ///
299    /// Default: 1
300    pub fn set_max_concurrent_creation(&mut self, num_connections: u32) -> Result<&mut Self> {
301        unsafe { cass_cluster_set_max_concurrent_creation(self.0, num_connections).to_result(self) }
302    }
303
304    /// Sets the threshold for the maximum number of concurrent requests in-flight
305    /// on a connection before creating a new connection. The number of new connections
306    /// created will not exceed max_connections_per_host.
307    ///
308    ///
309    /// Default: 100
310    pub fn set_max_concurrent_requests_threshold(
311        &mut self,
312        num_requests: u32,
313    ) -> Result<&mut Self> {
314        unsafe {
315            cass_cluster_set_max_concurrent_requests_threshold(self.0, num_requests).to_result(self)
316        }
317    }
318
319    /// Sets the maximum number of requests processed by an IO worker
320    /// per flush.
321    ///
322    ///
323    /// Default: 128
324    pub fn set_max_requests_per_flush(&mut self, num_requests: u32) -> Result<&mut Self> {
325        unsafe { cass_cluster_set_max_requests_per_flush(self.0, num_requests).to_result(self) }
326    }
327
328    /// Sets the high water mark for the number of bytes outstanding
329    /// on a connection. Disables writes to a connection if the number
330    /// of bytes queued exceed this value.
331    ///
332    ///
333    /// Default: 64KB
334    pub fn set_write_bytes_high_water_mark(&mut self, num_bytes: u32) -> Result<&mut Self> {
335        unsafe { cass_cluster_set_write_bytes_high_water_mark(self.0, num_bytes).to_result(self) }
336    }
337
338    /// Sets the low water mark for the number of bytes outstanding
339    /// on a connection. Disables writes to a connection if the number
340    /// of bytes queued fall below this value.
341    ///
342    ///
343    /// Default: 32KB
344    pub fn set_write_bytes_low_water_mark(&mut self, num_bytes: u32) -> Result<&mut Self> {
345        unsafe { cass_cluster_set_write_bytes_low_water_mark(self.0, num_bytes).to_result(self) }
346    }
347
348    /// Sets the high water mark for the number of requests queued waiting
349    /// for a connection in a connection pool. Disables writes to a
350    /// host on an IO worker if the number of requests queued exceed this
351    /// value.
352    ///
353    ///
354    /// Default: 256
355    pub fn set_pending_requests_high_water_mark(&mut self, num_requests: u32) -> Result<&mut Self> {
356        unsafe {
357            cass_cluster_set_pending_requests_high_water_mark(self.0, num_requests).to_result(self)
358        }
359    }
360
361    /// Sets the low water mark for the number of requests queued waiting
362    /// for a connection in a connection pool. After exceeding high water mark
363    /// requests, writes to a host will only resume once the number of requests
364    /// fall below this value.
365    ///
366    ///
367    /// Default: 128
368    pub fn set_pending_requests_low_water_mark(&mut self, num_requests: u32) -> Result<&mut Self> {
369        unsafe {
370            cass_cluster_set_pending_requests_low_water_mark(self.0, num_requests).to_result(self)
371        }
372    }
373
374    /// Sets the timeout for connecting to a node.
375    ///
376    ///
377    /// Default: 5000ms
378    pub fn set_connect_timeout(&mut self, timeout: Duration) -> &Self {
379        unsafe {
380            cass_cluster_set_connect_timeout(self.0, timeout.as_millis() as u32);
381        }
382        self
383    }
384
385    /// Sets the timeout for waiting for a response from a node.
386    ///
387    ///
388    /// Default: 12000ms
389    pub fn set_request_timeout(&mut self, timeout: Duration) -> &Self {
390        unsafe {
391            cass_cluster_set_request_timeout(self.0, timeout.as_millis() as u32);
392        }
393        self
394    }
395
396    /// Sets the timeout for resolving the host.
397    /// Note: the default timeout when doing dns resolution with resolv.conf (as is done here) is 5000ms.
398    /// When using the default cassandra-cpp-driver timeout (also 5000ms) then DNS resolution will fail
399    /// before attempting to query backup DNS servers.
400    ///
401    ///
402    /// Default: 5000ms
403    pub fn set_resolve_timeout(&mut self, timeout: Duration) -> &Self {
404        unsafe {
405            cass_cluster_set_resolve_timeout(self.0, timeout.as_millis() as u32);
406        }
407        self
408    }
409
410    /// Configures the cluster to use a reconnection policy that waits
411    /// exponentially longer between each reconnection attempt; however
412    /// will maintain a constant delay once the maximum delay is reached.
413    ///
414    /// This is the default reconnection policy.
415    ///
416    ///
417    /// Default:
418    /// - base_delay_ms: 2000ms
419    /// - max_delay_ms: 600000ms (10 minutes)
420    ///
421    /// <b>Note:</b> A random amount of jitter (+/- 15%) will be added to the pure
422    /// exponential delay value. This helps to prevent situations where multiple
423    /// connections are in the reconnection process at exactly the same time. The
424    /// jitter will never cause the delay to be less than the base delay, or more
425    /// than the max delay.
426    pub fn set_exponential_reconnect(
427        &mut self,
428        base_delay_ms: Duration,
429        max_delay_ms: Duration,
430    ) -> &Self {
431        unsafe {
432            cass_cluster_set_exponential_reconnect(
433                self.0,
434                base_delay_ms.as_millis() as u64,
435                max_delay_ms.as_millis() as u64,
436            );
437        }
438        self
439    }
440
441    /// Sets credentials for plain text authentication.
442    pub fn set_credentials(&mut self, username: &str, password: &str) -> Result<&mut Self> {
443        unsafe {
444            let username_ptr = username.as_ptr() as *const c_char;
445            let password_ptr = password.as_ptr() as *const c_char;
446            cass_cluster_set_credentials_n(
447                self.0,
448                username_ptr,
449                username.len(),
450                password_ptr,
451                password.len(),
452            );
453        }
454        Ok(self)
455    }
456
457    /// Configures the cluster to use round-robin load balancing.
458    ///
459    /// The driver discovers all nodes in a cluster and cycles through
460    /// them per request. All are considered 'local'.
461    pub fn set_load_balance_round_robin(&mut self) -> &Self {
462        unsafe {
463            cass_cluster_set_load_balance_round_robin(self.0);
464            self
465        }
466    }
467
468    /// Configures the cluster to use DC-aware load balancing.
469    /// For each query, all live nodes in a primary 'local' DC are tried first,
470    /// followed by any node from other DCs.
471    ///
472    /// <b>Note:</b> This is the default, and does not need to be called unless
473    /// switching an existing from another policy or changing settings.
474    /// Without further configuration, a default local_dc is chosen from the
475    /// first connected contact point, and no remote hosts are considered in
476    /// query plans. If relying on this mechanism, be sure to use only contact
477    /// points from the local DC.
478    pub fn set_load_balance_dc_aware<S>(
479        &mut self,
480        local_dc: &str,
481        used_hosts_per_remote_dc: u32,
482        allow_remote_dcs_for_local_cl: bool,
483    ) -> Result<&mut Self> {
484        unsafe {
485            {
486                let local_dc_ptr = local_dc.as_ptr() as *const c_char;
487                cass_cluster_set_load_balance_dc_aware_n(
488                    self.0,
489                    local_dc_ptr,
490                    local_dc.len(),
491                    used_hosts_per_remote_dc,
492                    if allow_remote_dcs_for_local_cl {
493                        cass_true
494                    } else {
495                        cass_false
496                    },
497                )
498            }
499            .to_result(self)
500        }
501    }
502
503    /// Configures the cluster to use token-aware request routing or not.
504    ///
505    /// <b>Important:</b> Token-aware routing depends on keyspace information.
506    /// For this reason enabling token-aware routing will also enable the usage
507    /// of schema metadata.
508    ///
509    ///
510    /// Default: true (enabled).
511    ///
512    ///
513    /// This routing policy composes the base routing policy, routing
514    /// requests first to replicas on nodes considered 'local' by
515    /// the base load balancing policy.
516    pub fn set_token_aware_routing(&mut self, enabled: bool) -> &Self {
517        unsafe {
518            cass_cluster_set_token_aware_routing(
519                self.0,
520                if enabled { cass_true } else { cass_false },
521            );
522        }
523        self
524    }
525
526    /// Configures token-aware routing to randomly shuffle replicas.
527    /// This can reduce the effectiveness of server-side caching, but it
528    /// can better distribute load over replicas for a given partition key.
529    ///
530    ///
531    /// Default: true (enabled)
532    ///
533    ///
534    /// Note: Token-aware routing must be enabled for the setting to be
535    /// applicable.
536    pub fn set_token_aware_routing_shuffle_replicas(&mut self, enabled: bool) -> &Self {
537        unsafe {
538            cass_cluster_set_token_aware_routing_shuffle_replicas(
539                self.0,
540                if enabled { cass_true } else { cass_false },
541            );
542        }
543        self
544    }
545
546    /// Configures the cluster to use latency-aware request routing or not.
547    ///
548    ///
549    /// Default: false (disabled).
550    ///
551    ///
552    /// This routing policy is a top-level routing policy. It uses the
553    /// base routing policy to determine locality (dc-aware) and/or
554    /// placement (token-aware) before considering the latency.
555    pub fn set_latency_aware_routing(&mut self, enabled: bool) -> &Self {
556        unsafe {
557            cass_cluster_set_latency_aware_routing(
558                self.0,
559                if enabled { cass_true } else { cass_false },
560            );
561        }
562        self
563    }
564
565    /// Configures the settings for latency-aware request routing.
566    ///
567    ///
568    /// Defaults:
569    ///
570    /// <ul>
571    ///   <li>exclusion_threshold: 2.0</li>
572    ///   <li>scale_ms: 100 milliseconds</li>
573    ///  <li>retry_period_ms: 10,000 milliseconds (10 seconds)</li>
574    ///  <li>update_rate_ms: 100 milliseconds</li>
575    ///  <li>min_measured: 50</li>
576    /// </ul>
577    pub fn set_latency_aware_routing_settings(
578        &mut self,
579        exclusion_threshold: f64,
580        scale: Duration,
581        retry_period: Duration,
582        update_rate: Duration,
583        min_measured: u64,
584    ) -> &Self {
585        unsafe {
586            cass_cluster_set_latency_aware_routing_settings(
587                self.0,
588                exclusion_threshold,
589                scale.as_millis() as u64,
590                retry_period.as_millis() as u64,
591                update_rate.as_millis() as u64,
592                min_measured,
593            );
594        }
595        self
596    }
597
598    /// /Sets/Appends whitelist hosts. The first call sets the whitelist hosts and
599    /// any subsequent calls appends additional hosts. Passing an empty string will
600    /// clear and disable the whitelist. White space is striped from the hosts.
601    ///
602    /// This policy filters requests to all other policies, only allowing requests
603    /// to the hosts contained in the whitelist. Any host not in the whitelist will
604    /// be ignored and a connection will not be established. This policy is useful
605    /// for ensuring that the driver will only connect to a predefined set of hosts.
606    ///
607    ///
608    /// Examples: "127.0.0.1" "127.0.0.1,127.0.0.2", "server1.domain.com"
609    pub fn set_whitelist_filtering(&mut self, hosts: Vec<String>) -> &Self {
610        unsafe {
611            cass_cluster_set_whitelist_filtering(self.0, hosts.join(",").as_ptr() as *const c_char);
612        }
613        self
614    }
615
616    /// Enable/Disable Nagel's algorithm on connections.
617    ///
618    ///
619    /// <b>Default:</b> true (disables Nagel's algorithm).
620    pub fn set_tcp_nodelay(&mut self, enable: bool) -> &Self {
621        unsafe {
622            cass_cluster_set_tcp_nodelay(self.0, if enable { cass_true } else { cass_false });
623        }
624        self
625    }
626
627    /// Enable/Disable TCP keep-alive
628    ///
629    ///
630    /// Default: false (disabled).
631    pub fn set_tcp_keepalive(&mut self, enable: bool, delay: Duration) -> &Self {
632        unsafe {
633            cass_cluster_set_tcp_keepalive(
634                self.0,
635                if enable { cass_true } else { cass_false },
636                delay.as_secs() as u32,
637            );
638        }
639        self
640    }
641
642    /// Sets the timestamp generator used to assign timestamps to all requests
643    /// unless overridden by setting the timestamp on a statement or a batch.
644    ///
645    ///
646    /// Default: server-side timestamp generator.
647    pub fn set_timestamp_gen(&mut self, tsg: &TimestampGen) -> &mut Self {
648        unsafe {
649            cass_cluster_set_timestamp_gen(self.0, TimestampGen::inner(tsg));
650            self
651        }
652    }
653
654    /// Sets the amount of time between heartbeat messages and controls the amount
655    /// of time the connection must be idle before sending heartbeat messages. This
656    /// is useful for preventing intermediate network devices from dropping
657    /// connections.
658    ///
659    ///
660    /// Default: 30 seconds
661    pub fn set_connection_heartbeat_interval(&mut self, hearbeat: Duration) -> &mut Self {
662        unsafe {
663            cass_cluster_set_connection_heartbeat_interval(self.0, hearbeat.as_secs() as u32);
664            self
665        }
666    }
667
668    /// Sets the amount of time a connection is allowed to be without a successful
669    /// heartbeat response before being terminated and scheduled for reconnection.
670    ///
671    ///
672    /// Default: 60 seconds
673    pub fn set_connection_idle_timeout(&mut self, timeout: Duration) -> &mut Self {
674        unsafe {
675            cass_cluster_set_connection_idle_timeout(self.0, timeout.as_secs() as u32);
676            self
677        }
678    }
679
680    /// Sets the retry policy used for all requests unless overridden by setting
681    /// a retry policy on a statement or a batch.
682    ///
683    ///
684    /// Default: The same policy as would be created by the function:
685    /// cass_retry_policy_default_new(). This policy will retry on a read timeout
686    /// if there was enough replicas, but no data present, on a write timeout if a
687    /// logged batch request failed to write the batch log, and on a unavailable
688    /// error it retries using a new host. In all other cases the default policy
689    /// will return an error.
690    pub fn set_retry_policy(&mut self, retry_policy: RetryPolicy) -> &mut Self {
691        unsafe {
692            cass_cluster_set_retry_policy(self.0, retry_policy.inner());
693            self
694        }
695    }
696
697    /// Enable/Disable retrieving and updating schema metadata. If disabled
698    /// this is allows the driver to skip over retrieving and updating schema
699    /// metadata, but it also disables the usage of token-aware routing and
700    /// cass_session_get_schema() will always return an empty object. This can be
701    /// useful for reducing the startup overhead of short-lived sessions.
702    ///
703    ///
704    /// Default: true (enabled).
705    pub fn set_use_schema(&mut self, enabled: bool) -> &Self {
706        unsafe {
707            cass_cluster_set_use_schema(self.0, if enabled { cass_true } else { cass_false });
708        }
709        self
710    }
711}