Replace begin_with_timestamp with snapshot_at.

Users should not be able to begin a transaction with a custom timestamp.
If there were two transactions running with the same start TS, data could
be corrupted. However, a read-only snapshot with a custom timestamp is OK.

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
This commit is contained in:
Yilin Chen 2019-07-30 15:40:08 +08:00
parent 010fd4bea0
commit 934cce8785
No known key found for this signature in database
GPG Key ID: 353E7ED34BF326E0
2 changed files with 24 additions and 25 deletions

View File

@ -12,7 +12,7 @@ use std::pin::Pin;
pub struct Client; pub struct Client;
impl Client { impl Client {
/// Create a new [`Client`](Client) once the [`Connect`](Connect) resolves. /// Creates a new [`Client`](Client) once the [`Connect`](Connect) resolves.
/// ///
/// ```rust,no_run /// ```rust,no_run
/// # #![feature(async_await)] /// # #![feature(async_await)]
@ -27,7 +27,7 @@ impl Client {
Connect::new(config) Connect::new(config)
} }
/// Create a new [`Transaction`](Transaction) using the timestamp from [`current_timestamp`](Client::current_timestamp). /// Creates a new [`Transaction`](Transaction).
/// ///
/// Using the transaction you can issue commands like [`get`](Transaction::get) or [`set`](Transaction::set). /// Using the transaction you can issue commands like [`get`](Transaction::get) or [`set`](Transaction::set).
/// ///
@ -48,27 +48,7 @@ impl Client {
unimplemented!() unimplemented!()
} }
/// Create a new [`Transaction`](Transaction) at the provded timestamp. /// Gets the latest [`Snapshot`](Snapshot).
///
/// ```rust,no_run
/// # #![feature(async_await)]
/// use tikv_client::{Config, transaction::Client};
/// use futures::prelude::*;
/// # futures::executor::block_on(async {
/// let connect = Client::connect(Config::default());
/// let client = connect.await.unwrap();
/// let timestamp = client.current_timestamp();
/// let transaction = client.begin_with_timestamp(timestamp);
/// // ... Issue some commands.
/// let commit = transaction.commit();
/// let result: () = commit.await.unwrap();
/// # });
/// ```
pub fn begin_with_timestamp(&self, _timestamp: Timestamp) -> Transaction {
unimplemented!()
}
/// Get a [`Snapshot`](Snapshot) using the timestamp from [`current_timestamp`](Client::current_timestamp).
/// ///
/// ```rust,no_run /// ```rust,no_run
/// # #![feature(async_await)] /// # #![feature(async_await)]
@ -85,7 +65,24 @@ impl Client {
unimplemented!() unimplemented!()
} }
/// Retrieve the current [`Timestamp`](Timestamp). /// Gets a [`Snapshot`](Snapshot) at the given point in time.
///
/// ```rust,no_run
/// # #![feature(async_await)]
/// use tikv_client::{Config, transaction::Client};
/// use futures::prelude::*;
/// # futures::executor::block_on(async {
/// let connect = Client::connect(Config::default());
/// let client = connect.await.unwrap();
/// let snapshot = client.snapshot();
/// // ... Issue some commands.
/// # });
/// ```
pub fn snapshot_at(&self, timestamp: Timestamp) -> Snapshot {
unimplemented!()
}
/// Retrieves the current [`Timestamp`](Timestamp).
/// ///
/// ```rust,no_run /// ```rust,no_run
/// # #![feature(async_await)] /// # #![feature(async_await)]

View File

@ -257,7 +257,9 @@ pub struct TxnInfo {
} }
/// A snapshot of dataset at a particular point in time. /// A snapshot of dataset at a particular point in time.
pub struct Snapshot; pub struct Snapshot {
timestamp: Timestamp,
}
impl Snapshot { impl Snapshot {
pub fn get(&self, key: impl Into<Key>) -> Get { pub fn get(&self, key: impl Into<Key>) -> Get {