Skip to content

Commit b0d35ee

Browse files
committed
frame/request: document modules and items
1 parent ef18538 commit b0d35ee

File tree

9 files changed

+129
-4
lines changed

9 files changed

+129
-4
lines changed

scylla-cql/src/frame/request/auth_response.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! CQL protocol-level representation of a `AUTH_RESPONSE` request.
2+
13
use std::num::TryFromIntError;
24

35
use thiserror::Error;
@@ -7,8 +9,11 @@ use crate::frame::frame_errors::CqlRequestSerializationError;
79
use crate::frame::request::{RequestOpcode, SerializableRequest};
810
use crate::frame::types::write_bytes_opt;
911

10-
// Implements Authenticate Response
12+
/// Represents AUTH_RESPONSE CQL request.
13+
///
14+
/// This request is sent by the client to respond to an authentication challenge.
1115
pub struct AuthResponse {
16+
/// Raw response bytes.
1217
pub response: Option<Vec<u8>>,
1318
}
1419

scylla-cql/src/frame/request/batch.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! CQL protocol-level representation of a `BATCH` request.
2+
13
use bytes::{Buf, BufMut};
24
use std::{borrow::Cow, convert::TryInto, num::TryFromIntError};
35
use thiserror::Error;
@@ -20,30 +22,56 @@ const FLAG_WITH_SERIAL_CONSISTENCY: u8 = 0x10;
2022
const FLAG_WITH_DEFAULT_TIMESTAMP: u8 = 0x20;
2123
const ALL_FLAGS: u8 = FLAG_WITH_SERIAL_CONSISTENCY | FLAG_WITH_DEFAULT_TIMESTAMP;
2224

25+
/// CQL protocol-level representation of a `BATCH` request, used to execute
26+
/// a batch of statements (prepared, unprepared, or a mix of both).
2327
#[cfg_attr(test, derive(Debug, PartialEq, Eq))]
2428
pub struct Batch<'b, Statement, Values>
2529
where
2630
BatchStatement<'b>: From<&'b Statement>,
2731
Statement: Clone,
2832
Values: RawBatchValues,
2933
{
34+
/// The statements in the batch.
3035
pub statements: Cow<'b, [Statement]>,
36+
37+
/// The type of the batch.
3138
pub batch_type: BatchType,
39+
40+
/// The consistency level for the batch.
3241
pub consistency: types::Consistency,
42+
43+
/// The serial consistency level for the batch, if any.
3344
pub serial_consistency: Option<types::SerialConsistency>,
45+
46+
/// The client-side-assigned timestamp for the batch, if any.
3447
pub timestamp: Option<i64>,
48+
49+
/// The bound values for the batch statements.
3550
pub values: Values,
3651
}
3752

3853
/// The type of a batch.
3954
#[derive(Clone, Copy)]
4055
#[cfg_attr(test, derive(Debug, PartialEq, Eq))]
4156
pub enum BatchType {
57+
/// By default, all operations in the batch are performed as logged, to ensure all mutations
58+
/// eventually complete (or none will). See the notes on [UNLOGGED](BatchType::Unlogged) batches for more details.
59+
/// A `LOGGED` batch to a single partition will be converted to an `UNLOGGED` batch as an optimization.
4260
Logged = 0,
61+
62+
/// By default, ScyllaDB uses a batch log to ensure all operations in a batch eventually complete or none will
63+
/// (note, however, that operations are only isolated within a single partition).
64+
/// There is a performance penalty for batch atomicity when a batch spans multiple partitions. If you do not want
65+
/// to incur this penalty, you can tell Scylla to skip the batchlog with the `UNLOGGED` option. If the `UNLOGGED`
66+
/// option is used, a failed batch might leave the batch only partly applied.
4367
Unlogged = 1,
68+
69+
/// Use the `COUNTER` option for batched counter updates. Unlike other updates in ScyllaDB, counter updates
70+
/// are not idempotent.
4471
Counter = 2,
4572
}
4673

74+
/// Encountered a malformed batch type.
4775
#[derive(Debug, Error)]
4876
#[error("Malformed batch type: {value}")]
4977
pub struct BatchTypeParseError {
@@ -63,10 +91,19 @@ impl TryFrom<u8> for BatchType {
6391
}
6492
}
6593

94+
/// A single statement in a batch, which can either be a statement string or a prepared statement ID.
6695
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord)]
6796
pub enum BatchStatement<'a> {
68-
Query { text: Cow<'a, str> },
69-
Prepared { id: Cow<'a, [u8]> },
97+
/// Unprepared CQL statement.
98+
Query {
99+
/// CQL statement string.
100+
text: Cow<'a, str>,
101+
},
102+
/// Prepared CQL statement.
103+
Prepared {
104+
/// Prepared CQL statement's ID.
105+
id: Cow<'a, [u8]>,
106+
},
70107
}
71108

72109
impl<Statement, Values> Batch<'_, Statement, Values>

scylla-cql/src/frame/request/execute.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! CQL protocol-level representation of a `EXECUTE` request.
2+
13
use std::num::TryFromIntError;
24

35
use crate::frame::frame_errors::CqlRequestSerializationError;
@@ -14,9 +16,14 @@ use super::{
1416
DeserializableRequest, RequestDeserializationError,
1517
};
1618

19+
/// CQL protocol-level representation of an `EXECUTE` request,
20+
/// used to execute a single prepared statement.
1721
#[cfg_attr(test, derive(Debug, PartialEq, Eq))]
1822
pub struct Execute<'a> {
23+
/// ID of the prepared statement to execute.
1924
pub id: Bytes,
25+
26+
/// Various parameters controlling the execution of the statement.
2027
pub parameters: query::QueryParameters<'a>,
2128
}
2229

scylla-cql/src/frame/request/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! CQL requests sent by the client.
2+
13
pub mod auth_response;
24
pub mod batch;
35
pub mod execute;
@@ -59,6 +61,7 @@ impl std::fmt::Display for CqlRequestKind {
5961
}
6062
}
6163

64+
/// Opcode of a request, used to identify the request type in a CQL frame.
6265
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
6366
#[repr(u8)]
6467
pub enum RequestOpcode {
@@ -93,21 +96,28 @@ impl TryFrom<u8> for RequestOpcode {
9396
}
9497
}
9598

99+
/// Requests that can be serialized into a CQL frame.
96100
pub trait SerializableRequest {
101+
/// Opcode of the request, used to identify the request type in the CQL frame.
97102
const OPCODE: RequestOpcode;
98103

104+
/// Serializes the request into the provided buffer.
99105
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), CqlRequestSerializationError>;
100106

107+
/// Serializes the request into a heap-allocated `Bytes` object.
101108
fn to_bytes(&self) -> Result<Bytes, CqlRequestSerializationError> {
102109
let mut v = Vec::new();
103110
self.serialize(&mut v)?;
104111
Ok(v.into())
105112
}
106113
}
107114

115+
/// Requests that can be deserialized from a CQL frame.
116+
///
108117
/// Not intended for driver's direct usage (as driver has no interest in deserialising CQL requests),
109118
/// but very useful for testing (e.g. asserting that the sent requests have proper parameters set).
110119
pub trait DeserializableRequest: SerializableRequest + Sized {
120+
/// Deserializes the request from the provided buffer.
111121
fn deserialize(buf: &mut &[u8]) -> Result<Self, RequestDeserializationError>;
112122
}
113123

@@ -133,14 +143,20 @@ pub enum RequestDeserializationError {
133143
UnexpectedBatchStatementKind(u8),
134144
}
135145

146+
/// A CQL request that can be sent to the server.
136147
#[non_exhaustive] // TODO: add remaining request types
137148
pub enum Request<'r> {
149+
/// QUERY request, used to execute a single unprepared statement.
138150
Query(Query<'r>),
151+
/// EXECUTE request, used to execute a single prepared statement.
139152
Execute(Execute<'r>),
153+
/// BATCH request, used to execute a batch of (prepared, unprepared, or mix of both)
154+
/// statements.
140155
Batch(Batch<'r, BatchStatement<'r>, Vec<SerializedValues>>),
141156
}
142157

143158
impl Request<'_> {
159+
/// Deserializes the request from the provided buffer.
144160
pub fn deserialize(
145161
buf: &mut &[u8],
146162
opcode: RequestOpcode,

scylla-cql/src/frame/request/options.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
//! CQL protocol-level representation of a `OPTIONS` request.
2+
13
use crate::frame::frame_errors::CqlRequestSerializationError;
24

35
use crate::frame::request::{RequestOpcode, SerializableRequest};
46

7+
/// The CQL protocol-level representation of an `OPTIONS` request,
8+
/// used to retrieve the server's supported options.
59
pub struct Options;
610

711
impl SerializableRequest for Options {

scylla-cql/src/frame/request/prepare.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! CQL protocol-level representation of a `PREPARE` request.
2+
13
use std::num::TryFromIntError;
24

35
use thiserror::Error;
@@ -9,7 +11,10 @@ use crate::{
911
frame::types,
1012
};
1113

14+
/// CQL protocol-level representation of an `PREPARE` request,
15+
/// used to prepare a single statement for further execution.
1216
pub struct Prepare<'a> {
17+
/// CQL statement string to prepare.
1318
pub query: &'a str,
1419
}
1520

scylla-cql/src/frame/request/query.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! CQL protocol-level representation of a `QUERY` request.
2+
13
use std::{borrow::Cow, num::TryFromIntError, ops::ControlFlow, sync::Arc};
24

35
use crate::frame::{frame_errors::CqlRequestSerializationError, types::SerialConsistency};
@@ -28,9 +30,14 @@ const ALL_FLAGS: u8 = FLAG_VALUES
2830
| FLAG_WITH_DEFAULT_TIMESTAMP
2931
| FLAG_WITH_NAMES_FOR_VALUES;
3032

33+
/// CQL protocol-level representation of an `QUERY` request,
34+
/// used to execute a single unprepared statement.
3135
#[cfg_attr(test, derive(Debug, PartialEq, Eq))]
3236
pub struct Query<'q> {
37+
/// CQL statement string to execute.
3338
pub contents: Cow<'q, str>,
39+
40+
/// Various parameters controlling the execution of the statement.
3441
pub parameters: QueryParameters<'q>,
3542
}
3643

@@ -59,14 +66,36 @@ impl DeserializableRequest for Query<'_> {
5966
}
6067
}
6168

69+
/// Various parameters controlling the execution of the statement.
6270
#[cfg_attr(test, derive(Debug, PartialEq, Eq))]
6371
pub struct QueryParameters<'a> {
72+
/// Consistency level for the query.
6473
pub consistency: types::Consistency,
74+
75+
/// Serial consistency level for the query, if specified.
6576
pub serial_consistency: Option<types::SerialConsistency>,
77+
78+
/// Client-side-assigned timestamp for the query, if specified.
6679
pub timestamp: Option<i64>,
80+
81+
/// Maximum number of rows to return for the query, if specified.
82+
/// If not specified, the server will not page the result, and instead return all rows
83+
/// in a single response. This is not recommended for large result sets, as it puts
84+
/// a lot of pressure on the server and network, as well as brings high memory usage
85+
/// on both client and server sides.
6786
pub page_size: Option<i32>,
87+
88+
/// Paging state for the query, used to resume fetching results from a previous query.
89+
/// If empty paging state is provided, the query will start from the beginning.
6890
pub paging_state: PagingState,
91+
92+
/// Whether to skip metadata for the values in the result set.
93+
/// This is an optimisation that can be used when the client does not need
94+
/// the metadata for the values, because it has already been fetched upon
95+
/// preparing the statement.
6996
pub skip_metadata: bool,
97+
98+
/// Values bound to the statements.
7099
pub values: Cow<'a, SerializedValues>,
71100
}
72101

@@ -85,6 +114,7 @@ impl Default for QueryParameters<'_> {
85114
}
86115

87116
impl QueryParameters<'_> {
117+
/// Serializes the parameters into the provided buffer.
88118
pub fn serialize(
89119
&self,
90120
buf: &mut impl BufMut,
@@ -145,6 +175,7 @@ impl QueryParameters<'_> {
145175
}
146176

147177
impl QueryParameters<'_> {
178+
/// Deserializes the parameters from the provided buffer.
148179
pub fn deserialize(buf: &mut &[u8]) -> Result<Self, RequestDeserializationError> {
149180
let consistency = types::read_consistency(buf)?;
150181

@@ -209,9 +240,19 @@ impl QueryParameters<'_> {
209240
}
210241
}
211242

243+
/// A response containing the paging state of a paged query,
244+
/// i.e. whether there are more pages to fetch or not, and if so,
245+
/// what is the state to use for resuming the query from the next page.
212246
#[derive(Debug, Clone)]
213247
pub enum PagingStateResponse {
214-
HasMorePages { state: PagingState },
248+
/// Indicates that there are more pages to fetch, and provides the
249+
/// [PagingState] to use for resuming the query from the next page.
250+
HasMorePages {
251+
/// The paging state to use for resuming the query from the next page.
252+
state: PagingState,
253+
},
254+
255+
/// Indicates that there are no more pages to fetch, and the query has finished.
215256
NoMorePages,
216257
}
217258

scylla-cql/src/frame/request/register.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! CQL protocol-level representation of a `REGISTER` request.
2+
13
use std::num::TryFromIntError;
24

35
use thiserror::Error;
@@ -9,7 +11,10 @@ use crate::frame::{
911
types,
1012
};
1113

14+
/// The CQL protocol-level representation of an `REGISTER` request,
15+
/// used to subscribe for server events.
1216
pub struct Register {
17+
/// A list of event types to register for.
1318
pub event_types_to_register_for: Vec<EventType>,
1419
}
1520

scylla-cql/src/frame/request/startup.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! CQL protocol-level representation of a `STARTUP` request.
2+
13
use thiserror::Error;
24

35
use crate::frame::frame_errors::CqlRequestSerializationError;
@@ -11,7 +13,10 @@ use crate::{
1113

1214
use super::DeserializableRequest;
1315

16+
/// The CQL protocol-level representation of an `STARTUP` request,
17+
/// used to finalise connection negotiation phase and establish the CQL connection.
1418
pub struct Startup<'a> {
19+
/// The protocol options that were suggested by the server and accepted by the client.
1520
pub options: HashMap<Cow<'a, str>, Cow<'a, str>>,
1621
}
1722

0 commit comments

Comments
 (0)