Skip to content

Commit 2fad975

Browse files
committed
add better documentation about snapshot
Signed-off-by: Otto Westerlund <westerlundotto@gmail.com>
1 parent d720774 commit 2fad975

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/transaction/sync_client.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,18 @@ impl SyncTransactionClient {
131131
Ok(SyncTransaction::new(inner, Arc::clone(&self.runtime)))
132132
}
133133

134-
/// Create a new [`SyncSnapshot`] at the given [`Timestamp`].
134+
/// Create a new read-only [`SyncSnapshot`] at the given [`Timestamp`].
135+
///
136+
/// A snapshot is a read-only transaction that reads data as if the snapshot was taken at the
137+
/// specified timestamp. It can read operations that happened before the timestamp, but ignores
138+
/// operations after the timestamp.
139+
///
140+
/// Use snapshots when you need:
141+
/// - Consistent reads across multiple operations without starting a full transaction
142+
/// - Point-in-time reads at a specific timestamp
143+
/// - Read-only access without the overhead of transaction tracking
144+
///
145+
/// Unlike transactions, snapshots cannot perform write operations (put, delete, etc.).
135146
///
136147
/// This is a synchronous version of [`TransactionClient::snapshot`](crate::TransactionClient::snapshot).
137148
///
@@ -141,7 +152,10 @@ impl SyncTransactionClient {
141152
/// # use tikv_client::{SyncTransactionClient, TransactionOptions};
142153
/// let client = SyncTransactionClient::new(vec!["192.168.0.100"]).unwrap();
143154
/// let timestamp = client.current_timestamp().unwrap();
144-
/// let snapshot = client.snapshot(timestamp, TransactionOptions::default());
155+
/// let mut snapshot = client.snapshot(timestamp, TransactionOptions::default());
156+
///
157+
/// // Read data as it existed at the snapshot timestamp
158+
/// let value = snapshot.get("key".to_owned()).unwrap();
145159
/// ```
146160
pub fn snapshot(&self, timestamp: Timestamp, options: TransactionOptions) -> SyncSnapshot {
147161
let inner = self.client.snapshot(timestamp, options);

0 commit comments

Comments
 (0)