Skip to content

Commit 196b06e

Browse files
ekexiumandylokandy
andauthored
pessimistic locks use MAX_TTL (#329)
* pessimistic locks use MAX_TTL Signed-off-by: ekexium <ekexium@gmail.com> * fix clippy and test Signed-off-by: ekexium <ekexium@gmail.com> * fix the newTTL, use MAX_TTL Signed-off-by: ekexium <ekexium@gmail.com> Co-authored-by: Andy Lok <andylokandy@hotmail.com>
1 parent c045d1e commit 196b06e

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl Config {
4848
/// # use tikv_client::Config;
4949
/// let config = Config::default().with_security("root.ca", "internal.cert", "internal.key");
5050
/// ```
51+
#[must_use]
5152
pub fn with_security(
5253
mut self,
5354
ca_path: impl Into<PathBuf>,
@@ -74,6 +75,7 @@ impl Config {
7475
/// # use std::time::Duration;
7576
/// let config = Config::default().with_timeout(Duration::from_secs(10));
7677
/// ```
78+
#[must_use]
7779
pub fn with_timeout(mut self, timeout: Duration) -> Self {
7880
self.timeout = timeout;
7981
self

src/kv/key.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ impl Key {
120120

121121
/// Return the MVCC-encoded representation of the key.
122122
#[inline]
123+
#[must_use]
123124
pub fn to_encoded(&self) -> Key {
124125
let len = codec::max_encoded_bytes_size(self.0.len());
125126
let mut encoded = Vec::with_capacity(len);

src/raw/client.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ impl Client<PdRpcClient> {
130130
/// let get_request = client.get("foo".to_owned());
131131
/// # });
132132
/// ```
133+
#[must_use]
133134
pub fn with_cf(&self, cf: ColumnFamily) -> Self {
134135
Client {
135136
rpc: self.rpc.clone(),
@@ -146,6 +147,7 @@ impl Client<PdRpcClient> {
146147
/// the atomicity of CAS, write operations like [`put`](Client::put) or
147148
/// [`delete`](Client::delete) in atomic mode are more expensive. Some
148149
/// operations are not supported in the mode.
150+
#[must_use]
149151
pub fn with_atomic_for_cas(&self) -> Self {
150152
Client {
151153
rpc: self.rpc.clone(),

src/transaction/transaction.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ impl<PdC: PdClient> Transaction<PdC> {
664664
let request = new_heart_beat_request(
665665
self.timestamp.clone(),
666666
primary_key,
667-
self.start_instant.elapsed().as_millis() as u64 + DEFAULT_LOCK_TTL,
667+
self.start_instant.elapsed().as_millis() as u64 + MAX_TTL,
668668
);
669669
let plan = PlanBuilder::new(self.rpc.clone(), request)
670670
.resolve_lock(self.options.retry_options.lock_backoff.clone())
@@ -743,7 +743,7 @@ impl<PdC: PdClient> Transaction<PdC> {
743743
keys.clone().into_iter(),
744744
primary_lock,
745745
self.timestamp.clone(),
746-
DEFAULT_LOCK_TTL,
746+
MAX_TTL,
747747
for_update_ts,
748748
need_value,
749749
);
@@ -822,7 +822,7 @@ impl<PdC: PdClient> Transaction<PdC> {
822822
let request = new_heart_beat_request(
823823
start_ts.clone(),
824824
primary_key.clone(),
825-
start_instant.elapsed().as_millis() as u64 + DEFAULT_LOCK_TTL,
825+
start_instant.elapsed().as_millis() as u64 + MAX_TTL,
826826
);
827827
let plan = PlanBuilder::new(rpc.clone(), request)
828828
.retry_multi_region(region_backoff.clone())
@@ -945,42 +945,49 @@ impl TransactionOptions {
945945
}
946946

947947
/// Try to use async commit.
948+
#[must_use]
948949
pub fn use_async_commit(mut self) -> TransactionOptions {
949950
self.async_commit = true;
950951
self
951952
}
952953

953954
/// Try to use 1pc.
955+
#[must_use]
954956
pub fn try_one_pc(mut self) -> TransactionOptions {
955957
self.try_one_pc = true;
956958
self
957959
}
958960

959961
/// Make the transaction read only.
962+
#[must_use]
960963
pub fn read_only(mut self) -> TransactionOptions {
961964
self.read_only = true;
962965
self
963966
}
964967

965968
/// Don't automatically resolve locks and retry if keys are locked.
969+
#[must_use]
966970
pub fn no_resolve_locks(mut self) -> TransactionOptions {
967971
self.retry_options.lock_backoff = Backoff::no_backoff();
968972
self
969973
}
970974

971975
/// Don't automatically resolve regions with PD if we have outdated region information.
976+
#[must_use]
972977
pub fn no_resolve_regions(mut self) -> TransactionOptions {
973978
self.retry_options.region_backoff = Backoff::no_backoff();
974979
self
975980
}
976981

977982
/// Set RetryOptions.
983+
#[must_use]
978984
pub fn retry_options(mut self, options: RetryOptions) -> TransactionOptions {
979985
self.retry_options = options;
980986
self
981987
}
982988

983989
/// Set the behavior when dropping a transaction without an attempt to commit or rollback it.
990+
#[must_use]
984991
pub fn drop_check(mut self, level: CheckLevel) -> TransactionOptions {
985992
self.check_level = level;
986993
self
@@ -998,6 +1005,7 @@ impl TransactionOptions {
9981005
}
9991006
}
10001007

1008+
#[must_use]
10011009
pub fn heartbeat_option(mut self, heartbeat_option: HeartbeatOption) -> TransactionOptions {
10021010
self.heartbeat_option = heartbeat_option;
10031011
self

tests/integration_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ async fn txn_pessimistic_heartbeat() -> Result<()> {
742742
.await
743743
.unwrap();
744744

745-
tokio::time::sleep(tokio::time::Duration::from_millis(5000)).await;
745+
tokio::time::sleep(tokio::time::Duration::from_secs(23)).await;
746746

747747
// use other txns to check these locks
748748
let mut t3 = client

0 commit comments

Comments
 (0)