Skip to content

Commit 486a4b2

Browse files
TszKitLo40nrcandylokandy
authored
Automatic heartbeat (#236)
* Remove retry_response_stream Signed-off-by: Nick Cameron <[email protected]> * Move store-related functions from request to store Signed-off-by: Nick Cameron <[email protected]> * Be a little more consistent with the types in request ctor functions Signed-off-by: Nick Cameron <[email protected]> * Add request ctor functions taking high-level types Signed-off-by: Nick Cameron <[email protected]> * Refactor the command-abstraction into a composable plan abstraction Signed-off-by: Nick Cameron <[email protected]> * Support sending heartbeats automatically Signed-off-by: Zijie Lu <[email protected]> * nitpick Signed-off-by: Zijie Lu <[email protected]> * Add heartbeat check Signed-off-by: Zijie Lu <[email protected]> * Fix use Signed-off-by: Zijie Lu <[email protected]> * fix Signed-off-by: Zijie Lu <[email protected]> * fix complie errors Signed-off-by: Zijie Lu <[email protected]> * Address review comments Signed-off-by: Nick Cameron <[email protected]> * remove heartbeat plan and use spawn Signed-off-by: Zijie Lu <[email protected]> * Fix build errors and replace RwLock Signed-off-by: Zijie Lu <[email protected]> * Address review comments Signed-off-by: Nick Cameron <[email protected]> * Add unit test Signed-off-by: Zijie Lu <[email protected]> * nitpick Signed-off-by: Zijie Lu <[email protected]> * nitpick Signed-off-by: Zijie Lu <[email protected]> * Fix deadlock and unit tests Signed-off-by: Zijie Lu <[email protected]> * Add test for optimistic_heart Signed-off-by: Zijie Lu <[email protected]> * Add mod.rs for tests Signed-off-by: Zijie Lu <[email protected]> * Fix failpoint tests Signed-off-by: Zijie Lu <[email protected]> * Address review comments Signed-off-by: Zijie Lu <[email protected]> * Address review comments Signed-off-by: Zijie Lu <[email protected]> * Address review comments Signed-off-by: Zijie Lu <[email protected]> * Fix tests Signed-off-by: Zijie Lu <[email protected]> * Fix clippy errors Signed-off-by: Zijie Lu <[email protected]> * Address review comments Signed-off-by: Zijie Lu <[email protected]> * Remove bg_worker Signed-off-by: Andy Lok <[email protected]> * Fix test Signed-off-by: Zijie Lu <[email protected]> * rename to failpoint_tests Signed-off-by: Zijie Lu <[email protected]> * Update transaction.rs * Update transaction.rs Signed-off-by: Andy Lok <[email protected]> Co-authored-by: Nick Cameron <[email protected]> Co-authored-by: Andy Lok <[email protected]>
1 parent 405535c commit 486a4b2

File tree

8 files changed

+382
-95
lines changed

8 files changed

+382
-95
lines changed

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ name = "tikv_client"
2020
[dependencies]
2121
async-trait = "0.1"
2222
derive-new = "0.5"
23+
fail = "0.4"
2324
futures = { version = "0.3", features = ["async-await", "thread-pool"] }
2425
futures-timer = "3.0"
2526
grpcio = { version = "0.8", features = [ "secure", "prost-codec", "use-bindgen" ], default-features = false }
@@ -31,7 +32,7 @@ regex = "1"
3132
serde = "1.0"
3233
serde_derive = "1.0"
3334
thiserror = "1"
34-
tokio = { version = "1.0", features = [ "sync" ] }
35+
tokio = { version = "1.0", features = [ "sync", "time" ] }
3536

3637
tikv-client-common = { path = "tikv-client-common" }
3738
tikv-client-pd = { path = "tikv-client-pd" }
@@ -57,3 +58,8 @@ members = [
5758
"tikv-client-store",
5859
"mock-tikv"
5960
]
61+
62+
[[test]]
63+
name = "failpoint_tests"
64+
path = "tests/failpoint_tests.rs"
65+
required-features = ["fail/failpoints"]

rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
imports_granularity="Crate"
22
format_code_in_doc_comments = true
3+
edition = "2018"

src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl PdClient for MockPdClient {
147147
}
148148

149149
async fn get_timestamp(self: Arc<Self>) -> Result<Timestamp> {
150-
unimplemented!()
150+
Ok(Timestamp::default())
151151
}
152152

153153
async fn update_safepoint(self: Arc<Self>, _safepoint: u64) -> Result<bool> {

src/transaction/client.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::{
1010
transaction::{Snapshot, Transaction, TransactionOptions},
1111
Result,
1212
};
13-
use futures::executor::ThreadPool;
1413
use std::{mem, sync::Arc};
1514
use tikv_client_proto::{kvrpcpb, pdpb::Timestamp};
1615

@@ -35,9 +34,6 @@ const SCAN_LOCK_BATCH_SIZE: u32 = 1024; // FIXME: cargo-culted value
3534
/// The returned results of transactional requests are [`Future`](std::future::Future)s that must be awaited to execute.
3635
pub struct Client {
3736
pd: Arc<PdRpcClient>,
38-
/// The thread pool for background tasks including committing secondary keys and failed
39-
/// transaction cleanups.
40-
bg_worker: ThreadPool,
4137
}
4238

4339
impl Client {
@@ -76,9 +72,8 @@ impl Client {
7672
config: Config,
7773
) -> Result<Client> {
7874
let pd_endpoints: Vec<String> = pd_endpoints.into_iter().map(Into::into).collect();
79-
let bg_worker = ThreadPool::new()?;
8075
let pd = Arc::new(PdRpcClient::connect(&pd_endpoints, &config, true).await?);
81-
Ok(Client { pd, bg_worker })
76+
Ok(Client { pd })
8277
}
8378

8479
/// Creates a new [`Transaction`](Transaction) in optimistic mode.
@@ -223,6 +218,6 @@ impl Client {
223218
}
224219

225220
fn new_transaction(&self, timestamp: Timestamp, options: TransactionOptions) -> Transaction {
226-
Transaction::new(timestamp, self.bg_worker.clone(), self.pd.clone(), options)
221+
Transaction::new(timestamp, self.pd.clone(), options)
227222
}
228223
}

0 commit comments

Comments
 (0)