Skip to content

Commit 6dc7dfb

Browse files
TszKitLo40andylokandyekexium
authored
Update TTL in heartbeat request (#280)
* Update TTL in heartbeat request Signed-off-by: Zijie Lu <[email protected]> * Fix TTL calculation Signed-off-by: Andy Lok <[email protected]> * Fix clippy. Signed-off-by: Zijie Lu <[email protected]> * Update transaction.rs Signed-off-by: Andy Lok <[email protected]> * Update transaction.rs Signed-off-by: Andy Lok <[email protected]> * style: fix clippy Signed-off-by: ekexium <[email protected]> Co-authored-by: Andy Lok <[email protected]> Co-authored-by: Ziqian Qin <[email protected]>
1 parent 73a00ff commit 6dc7dfb

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/kv/kvpair.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ impl AsRef<Value> for KvPair {
133133
impl fmt::Debug for KvPair {
134134
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
135135
let KvPair(key, value) = self;
136-
match str::from_utf8(&value) {
136+
match str::from_utf8(value) {
137137
Ok(s) => write!(f, "KvPair({}, {:?})", HexRepr(&key.0), s),
138-
Err(_) => write!(f, "KvPair({}, {})", HexRepr(&key.0), HexRepr(&value)),
138+
Err(_) => write!(f, "KvPair({}, {})", HexRepr(&key.0), HexRepr(value)),
139139
}
140140
}
141141
}

src/transaction/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl Buffer {
237237

238238
fn get_from_mutations(&self, key: &Key) -> MutationValue {
239239
self.entry_map
240-
.get(&key)
240+
.get(key)
241241
.map(BufferEntry::get_value)
242242
.unwrap_or(MutationValue::Undetermined)
243243
}

src/transaction/transaction.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,11 @@ impl<PdC: PdClient> Transaction<PdC> {
646646
Some(k) => k,
647647
None => return Err(Error::NoPrimaryKey),
648648
};
649-
let request = new_heart_beat_request(self.timestamp.clone(), primary_key, DEFAULT_LOCK_TTL);
649+
let request = new_heart_beat_request(
650+
self.timestamp.clone(),
651+
primary_key,
652+
self.start_instant.elapsed().as_millis() as u64 + DEFAULT_LOCK_TTL,
653+
);
650654
let plan = PlanBuilder::new(self.rpc.clone(), request)
651655
.single_region()
652656
.await?
@@ -787,6 +791,7 @@ impl<PdC: PdClient> Transaction<PdC> {
787791
HeartbeatOption::NoHeartbeat => DEFAULT_HEARTBEAT_INTERVAL,
788792
HeartbeatOption::FixedTime(heartbeat_interval) => heartbeat_interval,
789793
};
794+
let start_instant = self.start_instant;
790795

791796
let heartbeat_task = async move {
792797
loop {
@@ -802,11 +807,10 @@ impl<PdC: PdClient> Transaction<PdC> {
802807
break;
803808
}
804809
}
805-
let current_ts = rpc.clone().get_timestamp().await?;
806810
let request = new_heart_beat_request(
807811
start_ts.clone(),
808812
primary_key.clone(),
809-
(current_ts.physical - start_ts.physical) as u64 + DEFAULT_LOCK_TTL,
813+
start_instant.elapsed().as_millis() as u64 + DEFAULT_LOCK_TTL,
810814
);
811815
let plan = PlanBuilder::new(rpc.clone(), request)
812816
.single_region()

0 commit comments

Comments
 (0)