@@ -11,6 +11,7 @@ use crate::{
11
11
use derive_new:: new;
12
12
use fail:: fail_point;
13
13
use futures:: { prelude:: * , stream:: BoxStream } ;
14
+ use log:: debug;
14
15
use std:: { iter, ops:: RangeBounds , sync:: Arc , time:: Instant } ;
15
16
use tikv_client_proto:: { kvrpcpb, pdpb:: Timestamp } ;
16
17
use tokio:: { sync:: RwLock , time:: Duration } ;
@@ -104,6 +105,7 @@ impl<PdC: PdClient> Transaction<PdC> {
104
105
/// # });
105
106
/// ```
106
107
pub async fn get ( & mut self , key : impl Into < Key > ) -> Result < Option < Value > > {
108
+ debug ! ( "invoking transactional get request" ) ;
107
109
self . check_allow_operation ( ) . await ?;
108
110
let timestamp = self . timestamp . clone ( ) ;
109
111
let rpc = self . rpc . clone ( ) ;
@@ -168,6 +170,7 @@ impl<PdC: PdClient> Transaction<PdC> {
168
170
/// # });
169
171
/// ```
170
172
pub async fn get_for_update ( & mut self , key : impl Into < Key > ) -> Result < Option < Value > > {
173
+ debug ! ( "invoking transactional get_for_update request" ) ;
171
174
self . check_allow_operation ( ) . await ?;
172
175
if !self . is_pessimistic ( ) {
173
176
let key = key. into ( ) ;
@@ -198,6 +201,7 @@ impl<PdC: PdClient> Transaction<PdC> {
198
201
/// # });
199
202
/// ```
200
203
pub async fn key_exists ( & mut self , key : impl Into < Key > ) -> Result < bool > {
204
+ debug ! ( "invoking transactional key_exists request" ) ;
201
205
let key = key. into ( ) ;
202
206
Ok ( self . scan_keys ( key. clone ( ) ..=key, 1 ) . await ?. next ( ) . is_some ( ) )
203
207
}
@@ -234,6 +238,7 @@ impl<PdC: PdClient> Transaction<PdC> {
234
238
& mut self ,
235
239
keys : impl IntoIterator < Item = impl Into < Key > > ,
236
240
) -> Result < impl Iterator < Item = KvPair > > {
241
+ debug ! ( "invoking transactional batch_get request" ) ;
237
242
self . check_allow_operation ( ) . await ?;
238
243
let timestamp = self . timestamp . clone ( ) ;
239
244
let rpc = self . rpc . clone ( ) ;
@@ -286,6 +291,7 @@ impl<PdC: PdClient> Transaction<PdC> {
286
291
& mut self ,
287
292
keys : impl IntoIterator < Item = impl Into < Key > > ,
288
293
) -> Result < Vec < KvPair > > {
294
+ debug ! ( "invoking transactional batch_get_for_update request" ) ;
289
295
self . check_allow_operation ( ) . await ?;
290
296
let keys: Vec < Key > = keys. into_iter ( ) . map ( |k| k. into ( ) ) . collect ( ) ;
291
297
if !self . is_pessimistic ( ) {
@@ -329,6 +335,7 @@ impl<PdC: PdClient> Transaction<PdC> {
329
335
range : impl Into < BoundRange > ,
330
336
limit : u32 ,
331
337
) -> Result < impl Iterator < Item = KvPair > > {
338
+ debug ! ( "invoking transactional scan request" ) ;
332
339
self . scan_inner ( range, limit, false ) . await
333
340
}
334
341
@@ -364,6 +371,7 @@ impl<PdC: PdClient> Transaction<PdC> {
364
371
range : impl Into < BoundRange > ,
365
372
limit : u32 ,
366
373
) -> Result < impl Iterator < Item = Key > > {
374
+ debug ! ( "invoking transactional scan_keys request" ) ;
367
375
Ok ( self
368
376
. scan_inner ( range, limit, true )
369
377
. await ?
@@ -374,6 +382,7 @@ impl<PdC: PdClient> Transaction<PdC> {
374
382
///
375
383
/// Similar to [`scan`](Transaction::scan), but scans in the reverse direction.
376
384
pub ( crate ) fn scan_reverse ( & self , _range : impl RangeBounds < Key > ) -> BoxStream < Result < KvPair > > {
385
+ debug ! ( "invoking transactional scan_reverse request" ) ;
377
386
unimplemented ! ( )
378
387
}
379
388
@@ -394,6 +403,7 @@ impl<PdC: PdClient> Transaction<PdC> {
394
403
/// # });
395
404
/// ```
396
405
pub async fn put ( & mut self , key : impl Into < Key > , value : impl Into < Value > ) -> Result < ( ) > {
406
+ debug ! ( "invoking transactional put request" ) ;
397
407
self . check_allow_operation ( ) . await ?;
398
408
let key = key. into ( ) ;
399
409
if self . is_pessimistic ( ) {
@@ -424,6 +434,7 @@ impl<PdC: PdClient> Transaction<PdC> {
424
434
/// # });
425
435
/// ```
426
436
pub async fn insert ( & mut self , key : impl Into < Key > , value : impl Into < Value > ) -> Result < ( ) > {
437
+ debug ! ( "invoking transactional insert request" ) ;
427
438
self . check_allow_operation ( ) . await ?;
428
439
let key = key. into ( ) ;
429
440
if self . buffer . get ( & key) . is_some ( ) {
@@ -458,6 +469,7 @@ impl<PdC: PdClient> Transaction<PdC> {
458
469
/// # });
459
470
/// ```
460
471
pub async fn delete ( & mut self , key : impl Into < Key > ) -> Result < ( ) > {
472
+ debug ! ( "invoking transactional delete request" ) ;
461
473
self . check_allow_operation ( ) . await ?;
462
474
let key = key. into ( ) ;
463
475
if self . is_pessimistic ( ) {
@@ -495,6 +507,7 @@ impl<PdC: PdClient> Transaction<PdC> {
495
507
& mut self ,
496
508
keys : impl IntoIterator < Item = impl Into < Key > > ,
497
509
) -> Result < ( ) > {
510
+ debug ! ( "invoking transactional lock_keys request" ) ;
498
511
self . check_allow_operation ( ) . await ?;
499
512
match self . options . kind {
500
513
TransactionKind :: Optimistic => {
@@ -526,6 +539,7 @@ impl<PdC: PdClient> Transaction<PdC> {
526
539
/// # });
527
540
/// ```
528
541
pub async fn commit ( & mut self ) -> Result < Option < Timestamp > > {
542
+ debug ! ( "commiting transaction" ) ;
529
543
{
530
544
let mut status = self . status . write ( ) . await ;
531
545
if !matches ! (
@@ -582,6 +596,7 @@ impl<PdC: PdClient> Transaction<PdC> {
582
596
/// # });
583
597
/// ```
584
598
pub async fn rollback ( & mut self ) -> Result < ( ) > {
599
+ debug ! ( "rolling back transaction" ) ;
585
600
{
586
601
let status = self . status . read ( ) . await ;
587
602
if !matches ! (
@@ -625,6 +640,7 @@ impl<PdC: PdClient> Transaction<PdC> {
625
640
/// Returns the TTL set on the transaction's locks by TiKV.
626
641
#[ doc( hidden) ]
627
642
pub async fn send_heart_beat ( & mut self ) -> Result < u64 > {
643
+ debug ! ( "sending heart_beat" ) ;
628
644
self . check_allow_operation ( ) . await ?;
629
645
let primary_key = match self . buffer . get_primary_key ( ) {
630
646
Some ( k) => k,
@@ -686,6 +702,7 @@ impl<PdC: PdClient> Transaction<PdC> {
686
702
keys : impl IntoIterator < Item = impl PessimisticLock > ,
687
703
need_value : bool ,
688
704
) -> Result < Vec < KvPair > > {
705
+ debug ! ( "acquiring pessimistic lock" ) ;
689
706
assert ! (
690
707
matches!( self . options. kind, TransactionKind :: Pessimistic ( _) ) ,
691
708
"`pessimistic_lock` is only valid to use with pessimistic transactions"
@@ -752,6 +769,7 @@ impl<PdC: PdClient> Transaction<PdC> {
752
769
}
753
770
754
771
async fn start_auto_heartbeat ( & mut self ) {
772
+ debug ! ( "starting auto_heartbeat" ) ;
755
773
if !self . options . heartbeat_option . is_auto_heartbeat ( ) || self . is_heartbeat_started {
756
774
return ;
757
775
}
@@ -810,6 +828,7 @@ impl<PdC: PdClient> Transaction<PdC> {
810
828
811
829
impl < PdC : PdClient > Drop for Transaction < PdC > {
812
830
fn drop ( & mut self ) {
831
+ debug ! ( "dropping transaction" ) ;
813
832
if std:: thread:: panicking ( ) {
814
833
return ;
815
834
}
0 commit comments