Skip to content

Commit 4068bda

Browse files
authored
Merge pull request #1400 from wprzytula/scylla-more-docs
scylla: Write missing docstrings
2 parents dde3fad + 5dcfa92 commit 4068bda

38 files changed

+536
-54
lines changed

scylla-cql/benches/benchmark.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(missing_docs)]
2+
13
use std::borrow::Cow;
24

35
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};

scylla/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ required-features = ["unstable-testing"]
140140
[lints.rust]
141141
unnameable_types = "warn"
142142
unreachable_pub = "warn"
143+
missing-docs = "warn"
143144
unexpected_cfgs = { level = "warn", check-cfg = [
144145
'cfg(scylla_cloud_tests)',
145146
'cfg(cassandra_tests)',

scylla/benches/benchmark.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(missing_docs)]
2+
13
use criterion::{criterion_group, criterion_main, Criterion};
24

35
use bytes::BytesMut;

scylla/src/authentication/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Traits and implementations for custom authentication against a server.
2+
13
use async_trait::async_trait;
24
use bytes::{BufMut, BytesMut};
35

@@ -25,7 +27,7 @@ pub trait AuthenticatorSession: Send + Sync {
2527
/// Trait used to represent a factory of [`AuthenticatorSession`] instances.
2628
/// A new [`AuthenticatorSession`] instance will be created for each session.
2729
///
28-
/// The custom authenticator can be set using SessionBuilder::authenticator_provider method.
30+
/// The custom authenticator can be set using SessionBuilder::authenticator_provider method.
2931
///
3032
/// Default: [`PlainTextAuthenticator`] is the default authenticator which requires username and
3133
/// password. It can be set by using SessionBuilder::user(\"user\", \"pass\") method.

scylla/src/client/caching_session.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Provides a convenient wrapper over the [`Session`] that caches
2+
//! prepared statements automatically and reuses them when possible.
3+
14
use crate::errors::{ExecutionError, PagerExecutionError, PrepareError};
25
use crate::response::query_result::QueryResult;
36
use crate::response::{PagingState, PagingStateResponse};
@@ -63,6 +66,7 @@ impl<S> CachingSession<S>
6366
where
6467
S: Default + BuildHasher + Clone,
6568
{
69+
/// Builds a [`CachingSession`] from a [`Session`] and a cache size.
6670
pub fn from(session: Session, cache_size: usize) -> Self {
6771
Self {
6872
session: Arc::new(session),
@@ -246,10 +250,12 @@ where
246250
}
247251
}
248252

253+
/// Retrieves the maximum capacity of the prepared statements cache.
249254
pub fn get_max_capacity(&self) -> usize {
250255
self.max_capacity
251256
}
252257

258+
/// Retrieves the underlying [Session] instance.
253259
pub fn get_session(&self) -> &Session {
254260
&self.session
255261
}
@@ -297,11 +303,12 @@ where
297303
impl CachingSessionBuilder<RandomState> {
298304
/// Wraps a [Session] and creates a new [CachingSessionBuilder] instance,
299305
/// which can be used to create a new [CachingSession].
300-
///
301306
pub fn new(session: Session) -> Self {
302307
Self::new_shared(Arc::new(session))
303308
}
304309

310+
/// Wraps an Arc<[Session]> and creates a new [CachingSessionBuilder] instance,
311+
/// which can be used to create a new [CachingSession].
305312
pub fn new_shared(session: Arc<Session>) -> Self {
306313
Self {
307314
session,

scylla/src/client/self_identity.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,52 @@ use std::borrow::Cow;
44
/// to be sent in STARTUP message.
55
#[derive(Debug, Clone, Default)]
66
pub struct SelfIdentity<'id> {
7-
// Custom driver identity can be set if a custom driver build is running,
8-
// or an entirely different driver is operating on top of Rust driver
9-
// (e.g. cpp-rust-driver).
7+
/// Custom driver identity can be set if a custom driver build is running,
8+
/// or an entirely different driver is operating on top of Rust driver
9+
/// (e.g. cpp-rust-driver).
1010
custom_driver_name: Option<Cow<'id, str>>,
11+
/// Custom driver identity can be set if a custom driver build is running,
12+
/// or an entirely different driver is operating on top of Rust driver
13+
/// (e.g. cpp-rust-driver).
1114
custom_driver_version: Option<Cow<'id, str>>,
1215

1316
// ### Q: Where do APPLICATION_NAME, APPLICATION_VERSION and CLIENT_ID come from?
1417
// - there are no columns in system.clients dedicated to those attributes,
1518
// - APPLICATION_NAME / APPLICATION_VERSION are not present in Scylla's source code at all,
1619
// - only 2 results in Cassandra source is some example in docs:
17-
// https://github.com/apache/cassandra/blob/d3cbf9c1f72057d2a5da9df8ed567d20cd272931/doc/modules/cassandra/pages/managing/operating/virtualtables.adoc?plain=1#L218.
20+
// <https://github.com/apache/cassandra/blob/d3cbf9c1f72057d2a5da9df8ed567d20cd272931/doc/modules/cassandra/pages/managing/operating/virtualtables.adoc?plain=1#L218>.
1821
// APPLICATION_NAME and APPLICATION_VERSION appears in client_options which
1922
// is an arbitrary dict where client can send any keys.
2023
// - driver variables are mentioned in protocol v5
21-
// (https://github.com/apache/cassandra/blob/d3cbf9c1f72057d2a5da9df8ed567d20cd272931/doc/native_protocol_v5.spec#L480),
24+
// (<https://github.com/apache/cassandra/blob/d3cbf9c1f72057d2a5da9df8ed567d20cd272931/doc/native_protocol_v5.spec#L480>),
2225
// application variables are not.
2326
//
2427
// ### A:
2528
// The following options are not exposed anywhere in ScyllaDB tables.
2629
// They come directly from CPP driver, and they are supported in Cassandra
2730
//
28-
// See https://github.com/scylladb/cpp-driver/blob/fa0f27069a625057984d1fa58f434ea99b86c83f/include/cassandra.h#L2916.
31+
// See <https://github.com/scylladb/cpp-driver/blob/fa0f27069a625057984d1fa58f434ea99b86c83f/include/cassandra.h#L2916>.
2932
// As we want to support as big subset of its API as possible in cpp-rust-driver, I decided to expose API for setting
3033
// those particular key-value pairs, similarly to what cpp-driver does, and not an API to set arbitrary key-value pairs.
3134
//
3235
// Allowing users to set arbitrary options could break the driver by overwriting options that bear special meaning,
3336
// e.g. the shard-aware port. Therefore, I'm against such liberal API. OTOH, we need to expose APPLICATION_NAME,
3437
// APPLICATION_VERSION and CLIENT_ID for cpp-rust-driver.
35-
36-
// Application identity can be set to distinguish different applications
37-
// connected to the same cluster.
38+
/// Application identity can be set to distinguish different applications
39+
/// connected to the same cluster.
3840
application_name: Option<Cow<'id, str>>,
41+
/// Application identity can be set to distinguish different applications
42+
/// connected to the same cluster.
3943
application_version: Option<Cow<'id, str>>,
4044

41-
// A (unique) client ID can be set to distinguish different instances
42-
// of the same application connected to the same cluster.
45+
/// A (unique) client ID can be set to distinguish different instances
46+
/// of the same application connected to the same cluster.
4347
client_id: Option<Cow<'id, str>>,
4448
}
4549

4650
impl<'id> SelfIdentity<'id> {
51+
/// Creates a new empty instance of [`SelfIdentity`], which has all fields
52+
/// set to `None`.
4753
pub fn new() -> Self {
4854
Self::default()
4955
}

scylla/src/client/session.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,15 @@ impl std::fmt::Debug for Session {
124124
}
125125
}
126126

127+
/// Represents a TLS context used to configure TLS connections to DB nodes.
128+
/// Abstracts over various TLS implementations, such as OpenSSL and Rustls.
127129
#[derive(Clone)] // Cheaply clonable - reference counted.
128130
#[non_exhaustive]
129131
pub enum TlsContext {
132+
/// TLS context backed by OpenSSL 0.10.
130133
#[cfg(feature = "openssl-010")]
131134
OpenSsl010(openssl::ssl::SslContext),
135+
/// TLS context backed by Rustls 0.23.
132136
#[cfg(feature = "rustls-023")]
133137
Rustls023(Arc<rustls::ClientConfig>),
134138
}
@@ -173,19 +177,41 @@ pub struct SessionConfig {
173177
/// Preferred compression algorithm to use on connections.
174178
/// If it's not supported by database server Session will fall back to no compression.
175179
pub compression: Option<Compression>,
180+
181+
/// Whether to set the nodelay TCP flag.
176182
pub tcp_nodelay: bool,
183+
184+
/// TCP keepalive interval, which means how often keepalive messages
185+
/// are sent **on TCP layer** when a connection is idle.
186+
/// If `None`, no TCP keepalive messages are sent.
177187
pub tcp_keepalive_interval: Option<Duration>,
178188

189+
/// Handle to the default execution profile, which is used
190+
/// for all statements that do not specify an execution profile.
179191
pub default_execution_profile_handle: ExecutionProfileHandle,
180192

193+
/// Keyspace to be used on all connections.
194+
/// Each connection will send `"USE <keyspace_name>"` before sending any requests.
195+
/// This can be later changed with [`Session::use_keyspace`].
181196
pub used_keyspace: Option<String>,
197+
198+
/// Whether the keyspace name is case-sensitive.
199+
/// This is used to determine how the keyspace name is sent to the server:
200+
/// - if case-insensitive, it is sent as-is,
201+
/// - if case-sensitive, it is enclosed in double quotes.
182202
pub keyspace_case_sensitive: bool,
183203

184-
/// Provide our Session with TLS
204+
/// TLS context used configure TLS connections to DB nodes.
185205
pub tls_context: Option<TlsContext>,
186206

207+
/// Custom authenticator provider to create an authenticator instance
208+
/// upon session creation.
187209
pub authenticator: Option<Arc<dyn AuthenticatorProvider>>,
188210

211+
/// Timeout for establishing connections to a node.
212+
///
213+
/// If it's higher than underlying os's default connection timeout, it won't have
214+
/// any effect.
189215
pub connect_timeout: Duration,
190216

191217
/// Size of the per-node connection pool, i.e. how many connections the driver should keep to each node.

scylla/src/client/session_builder.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,23 @@ mod sealed {
3131
#[expect(unnameable_types)]
3232
pub trait Sealed {}
3333
}
34+
/// Kind of the session builder, used to distinguish between
35+
/// builders that create regular sessions and those that create custom
36+
/// sessions, such as cloud sessions.
37+
/// This is used to conditionally enable different sets of methods
38+
/// on the session builder based on its kind.
3439
pub trait SessionBuilderKind: sealed::Sealed + Clone {}
3540

41+
/// Default session builder kind, used to create regular sessions.
3642
#[derive(Clone)]
3743
pub enum DefaultMode {}
3844
impl sealed::Sealed for DefaultMode {}
3945
impl SessionBuilderKind for DefaultMode {}
4046

47+
/// Builder for regular sessions.
4148
pub type SessionBuilder = GenericSessionBuilder<DefaultMode>;
4249

50+
/// Session builder kind for creating cloud sessions.
4351
#[cfg(feature = "unstable-cloud")]
4452
#[derive(Clone)]
4553
pub enum CloudMode {}
@@ -48,10 +56,17 @@ impl sealed::Sealed for CloudMode {}
4856
#[cfg(feature = "unstable-cloud")]
4957
impl SessionBuilderKind for CloudMode {}
5058

59+
/// Builder for sessions that connect to Scylla Cloud.
5160
#[cfg(feature = "unstable-cloud")]
5261
pub type CloudSessionBuilder = GenericSessionBuilder<CloudMode>;
5362

54-
/// SessionBuilder is used to create new Session instances
63+
/// Used to conveniently configure new Session instances.
64+
///
65+
/// Most likely you will want to use [`SessionBuilder`]
66+
/// (for building regular session). If you want to build a session
67+
/// that connects to Scylla Cloud, you will want to use
68+
/// `CloudSessionBuilder`.
69+
///
5570
/// # Example
5671
///
5772
/// ```
@@ -69,6 +84,7 @@ pub type CloudSessionBuilder = GenericSessionBuilder<CloudMode>;
6984
/// ```
7085
#[derive(Clone)]
7186
pub struct GenericSessionBuilder<Kind: SessionBuilderKind> {
87+
/// Configuration for the session being built.
7288
pub config: SessionConfig,
7389
kind: PhantomData<Kind>,
7490
}

scylla/src/cloud/config.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,27 @@ use crate::errors::TranslationError;
1414
use crate::network::tls::{TlsConfig, TlsError};
1515
use crate::policies::address_translator::{AddressTranslator, UntranslatedPeer};
1616

17+
/// Error that can occur while parsing the cloud config yaml file.
1718
#[non_exhaustive]
1819
#[derive(Debug, Error)]
1920
pub enum CloudConfigError {
21+
/// Error while opening cloud config yaml.
2022
#[error("Error while opening cloud config yaml: {0}")]
2123
YamlOpen(#[from] io::Error),
2224

25+
/// Error while parsing cloud config yaml.
2326
#[error("Error while parsing cloud config yaml: {0}")]
2427
YamlParse(#[from] serde_yaml::Error),
2528

29+
/// Error while decoding base64 key/cert.
2630
#[error("Error while decoding base64 key/cert: {0}")]
2731
Base64(#[from] base64::DecodeError),
2832

33+
/// Error during cloud config validation.
2934
#[error("Error during cloud config validation: {0}")]
3035
Validation(String),
3136

37+
/// Error during TLS key/cert parsing.
3238
#[error("Error during key/cert parsing: {0}")]
3339
Tls(#[from] TlsError),
3440
}
@@ -158,8 +164,10 @@ impl AddressTranslator for CloudConfig {
158164
#[derive(Debug, Clone, Copy)]
159165
#[non_exhaustive]
160166
pub enum CloudTlsProvider {
167+
/// OpenSSL 0.10 - backed TLS provider.
161168
#[cfg(feature = "openssl-010")]
162169
OpenSsl010,
170+
/// Rustls 0.23 - backed TLS provider.
163171
#[cfg(feature = "rustls-023")]
164172
Rustls023,
165173
}

scylla/src/cloud/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Support for connecting to ScyllaDB Serverless Cloud.
2+
13
mod config;
24

35
pub use config::CloudConfig;

0 commit comments

Comments
 (0)