Skip to content

Commit 807b2b0

Browse files
committed
frame/types: document consistencies
1 parent 05a41bd commit 807b2b0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

scylla-cql/src/frame/types.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,45 @@ use std::str;
1616
use thiserror::Error;
1717
use uuid::Uuid;
1818

19+
/// A setting that defines a successful write or read by the number of cluster replicas
20+
/// that acknowledge the write or respond to the read request, respectively.
21+
/// See [ScyllaDB docs](https://docs.scylladb.com/manual/stable/cql/consistency.html)
22+
/// for more detailed description and guidelines.
1923
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord)]
2024
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
2125
#[cfg_attr(feature = "serde", serde(rename_all = "SCREAMING_SNAKE_CASE"))]
2226
#[repr(u16)]
2327
pub enum Consistency {
28+
/// **Write-only**. Closest replica, as determined by the
29+
/// [Snitch](https://docs.scylladb.com/manual/stable/reference/glossary.html#term-Snitch),
30+
/// must respond. If all replica nodes are down, write succeeds after a hinted handoff.
31+
/// Provides low latency, guarantees writes never fail.
2432
Any = 0x0000,
33+
/// The closest replica as determined by the Snitch must respond. Consistency requirements
34+
/// are not too strict.
2535
One = 0x0001,
36+
/// The closest two replicas as determined by the Snitch must respond.
2637
Two = 0x0002,
38+
/// The closest three replicas as determined by the Snitch must respond.
2739
Three = 0x0003,
40+
/// A simple majority of all replicas across all datacenters must respond.
41+
/// This CL allows for some level of failure.
2842
Quorum = 0x0004,
43+
/// _All_ replicas in the cluster must respond. May cause performance issues.
2944
All = 0x0005,
45+
/// Same as [QUORUM](Consistency::Quorum), but confined to the same datacenter as the coordinator.
3046
#[default]
3147
LocalQuorum = 0x0006,
48+
/// **Write-only**. A simple majority in each datacenter must respond.
3249
EachQuorum = 0x0007,
50+
/// Same as [ONE](Consistency::One), but confined to the local datacenter.
3351
LocalOne = 0x000A,
3452

3553
// Apparently, Consistency can be set to Serial or LocalSerial in SELECT statements
3654
// to make them use Paxos.
55+
/// **Read-only**. Returns results with the most recent data. Including uncommitted in-flight LWTs.
3756
Serial = 0x0008,
57+
/// **Read-only**. Same as [SERIAL](Consistency::Serial), but confined to a local datacenter.
3858
LocalSerial = 0x0009,
3959
}
4060

@@ -62,12 +82,18 @@ impl TryFrom<u16> for Consistency {
6282
}
6383
}
6484

85+
/// [Consistency] for Lightweight Transactions (LWTs).
86+
///
87+
/// [SerialConsistency] sets the consistency level for the serial phase of conditional updates.
88+
/// This option will be ignored for anything else that a conditional update/insert.
6589
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
6690
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
6791
#[cfg_attr(feature = "serde", serde(rename_all = "SCREAMING_SNAKE_CASE"))]
6892
#[repr(i16)]
6993
pub enum SerialConsistency {
94+
/// Guarantees linearizable semantics across the whole cluster.
7095
Serial = 0x0008,
96+
/// Guarantees linearizable semantics in a local datacenter.
7197
LocalSerial = 0x0009,
7298
}
7399

@@ -93,6 +119,7 @@ impl Consistency {
93119
}
94120
}
95121

122+
/// Error returned when a serial consistency what expected, yet got another kind of consistency.
96123
#[derive(Debug, Error)]
97124
#[error("Expected Consistency Serial or LocalSerial, got: {0}")]
98125
pub struct NonSerialConsistencyError(Consistency);

0 commit comments

Comments
 (0)