@@ -83,6 +83,19 @@ async fn txn_cleanup_locks_batch_size() -> Result<()> {
8383
8484 init ( ) . await ?;
8585 let scenario = FailScenario :: setup ( ) ;
86+ let full_range = vec ! [ ] ..;
87+
88+ let client = TransactionClient :: new ( pd_addrs ( ) , Some ( logger. clone ( ) ) ) . await ?;
89+ // Clean all locks at the beginning to avoid other cases' side effect.
90+ let safepoint = client. current_timestamp ( ) . await ?;
91+ let options = ResolveLocksOptions {
92+ async_commit_only : false ,
93+ ..Default :: default ( )
94+ } ;
95+ client
96+ . cleanup_locks ( & safepoint, full_range. clone ( ) , options)
97+ . await
98+ . unwrap ( ) ;
8699
87100 fail:: cfg ( "after-prewrite" , "return" ) . unwrap ( ) ;
88101 fail:: cfg ( "before-cleanup-locks" , "return" ) . unwrap ( ) ;
@@ -91,7 +104,6 @@ async fn txn_cleanup_locks_batch_size() -> Result<()> {
91104 fail:: cfg( "before-cleanup-locks" , "off" ) . unwrap( ) ;
92105 } }
93106
94- let client = TransactionClient :: new ( pd_addrs ( ) , Some ( logger. clone ( ) ) ) . await ?;
95107 let keys = write_data ( & client, true , true ) . await ?;
96108 assert_eq ! ( count_locks( & client) . await ?, keys. len( ) ) ;
97109
@@ -101,7 +113,9 @@ async fn txn_cleanup_locks_batch_size() -> Result<()> {
101113 batch_size : 4 ,
102114 ..Default :: default ( )
103115 } ;
104- let res = client. cleanup_locks ( & safepoint, options) . await ?;
116+ let res = client
117+ . cleanup_locks ( & safepoint, full_range, options)
118+ . await ?;
105119
106120 assert_eq ! ( res. meet_locks, keys. len( ) ) ;
107121 assert_eq ! ( count_locks( & client) . await ?, keys. len( ) ) ;
@@ -117,6 +131,7 @@ async fn txn_cleanup_async_commit_locks() -> Result<()> {
117131
118132 init ( ) . await ?;
119133 let scenario = FailScenario :: setup ( ) ;
134+ let full_range = vec ! [ ] ..;
120135
121136 // no commit
122137 {
@@ -135,7 +150,9 @@ async fn txn_cleanup_async_commit_locks() -> Result<()> {
135150 async_commit_only : true ,
136151 ..Default :: default ( )
137152 } ;
138- client. cleanup_locks ( & safepoint, options) . await ?;
153+ client
154+ . cleanup_locks ( & safepoint, full_range. clone ( ) , options)
155+ . await ?;
139156
140157 must_committed ( & client, keys) . await ;
141158 assert_eq ! ( count_locks( & client) . await ?, 0 ) ;
@@ -160,7 +177,9 @@ async fn txn_cleanup_async_commit_locks() -> Result<()> {
160177 async_commit_only : true ,
161178 ..Default :: default ( )
162179 } ;
163- client. cleanup_locks ( & safepoint, options) . await ?;
180+ client
181+ . cleanup_locks ( & safepoint, full_range. clone ( ) , options)
182+ . await ?;
164183
165184 must_committed ( & client, keys) . await ;
166185 assert_eq ! ( count_locks( & client) . await ?, 0 ) ;
@@ -177,7 +196,9 @@ async fn txn_cleanup_async_commit_locks() -> Result<()> {
177196 async_commit_only : true ,
178197 ..Default :: default ( )
179198 } ;
180- client. cleanup_locks ( & safepoint, options) . await ?;
199+ client
200+ . cleanup_locks ( & safepoint, full_range, options)
201+ . await ?;
181202
182203 must_committed ( & client, keys) . await ;
183204 assert_eq ! ( count_locks( & client) . await ?, 0 ) ;
@@ -217,11 +238,11 @@ async fn txn_cleanup_range_async_commit_locks() -> Result<()> {
217238 let safepoint = client. current_timestamp ( ) . await ?;
218239 let options = ResolveLocksOptions {
219240 async_commit_only : true ,
220- start_key,
221- end_key,
222241 ..Default :: default ( )
223242 } ;
224- let res = client. cleanup_locks ( & safepoint, options) . await ?;
243+ let res = client
244+ . cleanup_locks ( & safepoint, start_key..end_key, options)
245+ . await ?;
225246
226247 assert_eq ! ( res. meet_locks, keys. len( ) - 3 ) ;
227248
@@ -230,7 +251,7 @@ async fn txn_cleanup_range_async_commit_locks() -> Result<()> {
230251 async_commit_only : false ,
231252 ..Default :: default ( )
232253 } ;
233- client. cleanup_locks ( & safepoint, options) . await ?;
254+ client. cleanup_locks ( & safepoint, vec ! [ ] .. , options) . await ?;
234255 must_committed ( & client, keys) . await ;
235256 assert_eq ! ( count_locks( & client) . await ?, 0 ) ;
236257
@@ -245,6 +266,7 @@ async fn txn_cleanup_2pc_locks() -> Result<()> {
245266
246267 init ( ) . await ?;
247268 let scenario = FailScenario :: setup ( ) ;
269+ let full_range = vec ! [ ] ..;
248270
249271 // no commit
250272 {
@@ -264,14 +286,18 @@ async fn txn_cleanup_2pc_locks() -> Result<()> {
264286 async_commit_only : true , // Skip 2pc locks.
265287 ..Default :: default ( )
266288 } ;
267- client. cleanup_locks ( & safepoint, options) . await ?;
289+ client
290+ . cleanup_locks ( & safepoint, full_range. clone ( ) , options)
291+ . await ?;
268292 assert_eq ! ( count_locks( & client) . await ?, keys. len( ) ) ;
269293 }
270294 let options = ResolveLocksOptions {
271295 async_commit_only : false ,
272296 ..Default :: default ( )
273297 } ;
274- client. cleanup_locks ( & safepoint, options) . await ?;
298+ client
299+ . cleanup_locks ( & safepoint, full_range. clone ( ) , options)
300+ . await ?;
275301
276302 must_rollbacked ( & client, keys) . await ;
277303 assert_eq ! ( count_locks( & client) . await ?, 0 ) ;
@@ -289,7 +315,9 @@ async fn txn_cleanup_2pc_locks() -> Result<()> {
289315 async_commit_only : false ,
290316 ..Default :: default ( )
291317 } ;
292- client. cleanup_locks ( & safepoint, options) . await ?;
318+ client
319+ . cleanup_locks ( & safepoint, full_range, options)
320+ . await ?;
293321
294322 must_committed ( & client, keys) . await ;
295323 assert_eq ! ( count_locks( & client) . await ?, 0 ) ;
@@ -319,7 +347,7 @@ async fn must_rollbacked(client: &TransactionClient, keys: HashSet<Vec<u8>>) {
319347
320348async fn count_locks ( client : & TransactionClient ) -> Result < usize > {
321349 let ts = client. current_timestamp ( ) . await . unwrap ( ) ;
322- let locks = client. scan_locks ( & ts, vec ! [ ] , vec ! [ ] , 1024 ) . await ?;
350+ let locks = client. scan_locks ( & ts, vec ! [ ] .. , 1024 ) . await ?;
323351 // De-duplicated as `scan_locks` will return duplicated locks due to retry on region changes.
324352 let locks_set: HashSet < Vec < u8 > > =
325353 HashSet :: from_iter ( locks. into_iter ( ) . map ( |mut l| l. take_key ( ) ) ) ;
0 commit comments