Skip to content

Commit b22710b

Browse files
committed
address review comments
Signed-off-by: haojinming <jinming.hao@pingcap.com>
1 parent 768df3c commit b22710b

File tree

3 files changed

+21
-34
lines changed

3 files changed

+21
-34
lines changed

src/request/plan.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -446,20 +446,13 @@ where
446446
pub struct CleanupLocksResult {
447447
pub region_error: Option<errorpb::Error>,
448448
pub key_error: Option<Vec<Error>>,
449-
pub meet_locks: usize,
450-
// TODO: pub resolved_locks: usize,
451-
}
452-
453-
impl CleanupLocksResult {
454-
fn has_error(&self) -> bool {
455-
self.key_error.is_some() || self.region_error.is_some()
456-
}
449+
pub resolved_locks: usize,
457450
}
458451

459452
impl Clone for CleanupLocksResult {
460453
fn clone(&self) -> Self {
461454
Self {
462-
meet_locks: self.meet_locks,
455+
resolved_locks: self.resolved_locks,
463456
..Default::default() // Ignore errors, which should be extracted by `extract_error()`.
464457
}
465458
}
@@ -484,14 +477,8 @@ impl Merge<CleanupLocksResult> for Collect {
484477
input
485478
.into_iter()
486479
.fold(Ok(CleanupLocksResult::default()), |acc, x| {
487-
let new_ret = x?;
488-
let new_lock_cnt = if new_ret.has_error() {
489-
0
490-
} else {
491-
new_ret.meet_locks
492-
};
493480
Ok(CleanupLocksResult {
494-
meet_locks: acc?.meet_locks + new_lock_cnt,
481+
resolved_locks: acc?.resolved_locks + x?.resolved_locks,
495482
..Default::default()
496483
})
497484
})
@@ -593,7 +580,7 @@ where
593580
.await
594581
{
595582
Ok(()) => {
596-
result.meet_locks += lock_size;
583+
result.resolved_locks += lock_size;
597584
}
598585
Err(Error::ExtractedErrors(mut errors)) => {
599586
// Propagate errors to `retry_multi_region` for retry.

src/transaction/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl Client {
242242
batch_size: SCAN_LOCK_BATCH_SIZE,
243243
..Default::default()
244244
};
245-
self.cleanup_locks(&safepoint, vec![].., options).await?;
245+
self.cleanup_locks(.., &safepoint, options).await?;
246246

247247
// update safepoint to PD
248248
let res: bool = self
@@ -258,8 +258,8 @@ impl Client {
258258

259259
pub async fn cleanup_locks(
260260
&self,
261-
safepoint: &Timestamp,
262261
range: impl Into<BoundRange>,
262+
safepoint: &Timestamp,
263263
options: ResolveLocksOptions,
264264
) -> Result<CleanupLocksResult> {
265265
debug!(self.logger, "invoking cleanup async commit locks");
@@ -270,8 +270,8 @@ impl Client {
270270
let plan = crate::request::PlanBuilder::new(self.pd.clone(), req)
271271
.cleanup_locks(self.logger.clone(), ctx.clone(), options, backoff)
272272
.retry_multi_region(DEFAULT_REGION_BACKOFF)
273-
.merge(crate::request::Collect)
274273
.extract_error()
274+
.merge(crate::request::Collect)
275275
.plan();
276276
plan.execute().await
277277
}

tests/failpoint_tests.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ async fn txn_cleanup_locks_batch_size() -> Result<()> {
9494

9595
init().await?;
9696
let scenario = FailScenario::setup();
97-
let full_range = vec![]..;
97+
let full_range = ..;
9898

9999
fail::cfg("after-prewrite", "return").unwrap();
100100
fail::cfg("before-cleanup-locks", "return").unwrap();
@@ -113,10 +113,10 @@ async fn txn_cleanup_locks_batch_size() -> Result<()> {
113113
batch_size: 4,
114114
};
115115
let res = client
116-
.cleanup_locks(&safepoint, full_range, options)
116+
.cleanup_locks(full_range, &safepoint, options)
117117
.await?;
118118

119-
assert_eq!(res.meet_locks, keys.len());
119+
assert_eq!(res.resolved_locks, keys.len());
120120
assert_eq!(count_locks(&client).await?, keys.len());
121121

122122
scenario.teardown();
@@ -130,7 +130,7 @@ async fn txn_cleanup_async_commit_locks() -> Result<()> {
130130

131131
init().await?;
132132
let scenario = FailScenario::setup();
133-
let full_range = vec![]..;
133+
let full_range = ..;
134134

135135
// no commit
136136
{
@@ -150,7 +150,7 @@ async fn txn_cleanup_async_commit_locks() -> Result<()> {
150150
..Default::default()
151151
};
152152
client
153-
.cleanup_locks(&safepoint, full_range.clone(), options)
153+
.cleanup_locks(full_range, &safepoint, options)
154154
.await?;
155155

156156
must_committed(&client, keys).await;
@@ -177,7 +177,7 @@ async fn txn_cleanup_async_commit_locks() -> Result<()> {
177177
..Default::default()
178178
};
179179
client
180-
.cleanup_locks(&safepoint, full_range.clone(), options)
180+
.cleanup_locks(full_range, &safepoint, options)
181181
.await?;
182182

183183
must_committed(&client, keys).await;
@@ -196,7 +196,7 @@ async fn txn_cleanup_async_commit_locks() -> Result<()> {
196196
..Default::default()
197197
};
198198
client
199-
.cleanup_locks(&safepoint, full_range, options)
199+
.cleanup_locks(full_range, &safepoint, options)
200200
.await?;
201201

202202
must_committed(&client, keys).await;
@@ -240,17 +240,17 @@ async fn txn_cleanup_range_async_commit_locks() -> Result<()> {
240240
..Default::default()
241241
};
242242
let res = client
243-
.cleanup_locks(&safepoint, start_key..end_key, options)
243+
.cleanup_locks(start_key..end_key, &safepoint, options)
244244
.await?;
245245

246-
assert_eq!(res.meet_locks, keys.len() - 3);
246+
assert_eq!(res.resolved_locks, keys.len() - 3);
247247

248248
// cleanup all locks to avoid affecting following cases.
249249
let options = ResolveLocksOptions {
250250
async_commit_only: false,
251251
..Default::default()
252252
};
253-
client.cleanup_locks(&safepoint, vec![].., options).await?;
253+
client.cleanup_locks(.., &safepoint, options).await?;
254254
must_committed(&client, keys).await;
255255
assert_eq!(count_locks(&client).await?, 0);
256256

@@ -265,7 +265,7 @@ async fn txn_cleanup_2pc_locks() -> Result<()> {
265265

266266
init().await?;
267267
let scenario = FailScenario::setup();
268-
let full_range = vec![]..;
268+
let full_range = ..;
269269

270270
// no commit
271271
{
@@ -286,7 +286,7 @@ async fn txn_cleanup_2pc_locks() -> Result<()> {
286286
..Default::default()
287287
};
288288
client
289-
.cleanup_locks(&safepoint, full_range.clone(), options)
289+
.cleanup_locks(full_range, &safepoint, options)
290290
.await?;
291291
assert_eq!(count_locks(&client).await?, keys.len());
292292
}
@@ -295,7 +295,7 @@ async fn txn_cleanup_2pc_locks() -> Result<()> {
295295
..Default::default()
296296
};
297297
client
298-
.cleanup_locks(&safepoint, full_range.clone(), options)
298+
.cleanup_locks(full_range, &safepoint, options)
299299
.await?;
300300

301301
must_rollbacked(&client, keys).await;
@@ -315,7 +315,7 @@ async fn txn_cleanup_2pc_locks() -> Result<()> {
315315
..Default::default()
316316
};
317317
client
318-
.cleanup_locks(&safepoint, full_range, options)
318+
.cleanup_locks(full_range, &safepoint, options)
319319
.await?;
320320

321321
must_committed(&client, keys).await;

0 commit comments

Comments
 (0)