@@ -11,6 +11,7 @@ use crate::{
1111use derive_new:: new;
1212use fail:: fail_point;
1313use futures:: { prelude:: * , stream:: BoxStream } ;
14+ use log:: debug;
1415use std:: { iter, ops:: RangeBounds , sync:: Arc , time:: Instant } ;
1516use tikv_client_proto:: { kvrpcpb, pdpb:: Timestamp } ;
1617use tokio:: { sync:: RwLock , time:: Duration } ;
@@ -104,6 +105,7 @@ impl<PdC: PdClient> Transaction<PdC> {
104105 /// # });
105106 /// ```
106107 pub async fn get ( & mut self , key : impl Into < Key > ) -> Result < Option < Value > > {
108+ debug ! ( "invoking transactional get request" ) ;
107109 self . check_allow_operation ( ) . await ?;
108110 let timestamp = self . timestamp . clone ( ) ;
109111 let rpc = self . rpc . clone ( ) ;
@@ -168,6 +170,7 @@ impl<PdC: PdClient> Transaction<PdC> {
168170 /// # });
169171 /// ```
170172 pub async fn get_for_update ( & mut self , key : impl Into < Key > ) -> Result < Option < Value > > {
173+ debug ! ( "invoking transactional get_for_update request" ) ;
171174 self . check_allow_operation ( ) . await ?;
172175 if !self . is_pessimistic ( ) {
173176 let key = key. into ( ) ;
@@ -198,6 +201,7 @@ impl<PdC: PdClient> Transaction<PdC> {
198201 /// # });
199202 /// ```
200203 pub async fn key_exists ( & mut self , key : impl Into < Key > ) -> Result < bool > {
204+ debug ! ( "invoking transactional key_exists request" ) ;
201205 let key = key. into ( ) ;
202206 Ok ( self . scan_keys ( key. clone ( ) ..=key, 1 ) . await ?. next ( ) . is_some ( ) )
203207 }
@@ -234,6 +238,7 @@ impl<PdC: PdClient> Transaction<PdC> {
234238 & mut self ,
235239 keys : impl IntoIterator < Item = impl Into < Key > > ,
236240 ) -> Result < impl Iterator < Item = KvPair > > {
241+ debug ! ( "invoking transactional batch_get request" ) ;
237242 self . check_allow_operation ( ) . await ?;
238243 let timestamp = self . timestamp . clone ( ) ;
239244 let rpc = self . rpc . clone ( ) ;
@@ -286,6 +291,7 @@ impl<PdC: PdClient> Transaction<PdC> {
286291 & mut self ,
287292 keys : impl IntoIterator < Item = impl Into < Key > > ,
288293 ) -> Result < Vec < KvPair > > {
294+ debug ! ( "invoking transactional batch_get_for_update request" ) ;
289295 self . check_allow_operation ( ) . await ?;
290296 let keys: Vec < Key > = keys. into_iter ( ) . map ( |k| k. into ( ) ) . collect ( ) ;
291297 if !self . is_pessimistic ( ) {
@@ -329,6 +335,7 @@ impl<PdC: PdClient> Transaction<PdC> {
329335 range : impl Into < BoundRange > ,
330336 limit : u32 ,
331337 ) -> Result < impl Iterator < Item = KvPair > > {
338+ debug ! ( "invoking transactional scan request" ) ;
332339 self . scan_inner ( range, limit, false ) . await
333340 }
334341
@@ -364,6 +371,7 @@ impl<PdC: PdClient> Transaction<PdC> {
364371 range : impl Into < BoundRange > ,
365372 limit : u32 ,
366373 ) -> Result < impl Iterator < Item = Key > > {
374+ debug ! ( "invoking transactional scan_keys request" ) ;
367375 Ok ( self
368376 . scan_inner ( range, limit, true )
369377 . await ?
@@ -374,6 +382,7 @@ impl<PdC: PdClient> Transaction<PdC> {
374382 ///
375383 /// Similar to [`scan`](Transaction::scan), but scans in the reverse direction.
376384 pub ( crate ) fn scan_reverse ( & self , _range : impl RangeBounds < Key > ) -> BoxStream < Result < KvPair > > {
385+ debug ! ( "invoking transactional scan_reverse request" ) ;
377386 unimplemented ! ( )
378387 }
379388
@@ -394,6 +403,7 @@ impl<PdC: PdClient> Transaction<PdC> {
394403 /// # });
395404 /// ```
396405 pub async fn put ( & mut self , key : impl Into < Key > , value : impl Into < Value > ) -> Result < ( ) > {
406+ debug ! ( "invoking transactional put request" ) ;
397407 self . check_allow_operation ( ) . await ?;
398408 let key = key. into ( ) ;
399409 if self . is_pessimistic ( ) {
@@ -424,6 +434,7 @@ impl<PdC: PdClient> Transaction<PdC> {
424434 /// # });
425435 /// ```
426436 pub async fn insert ( & mut self , key : impl Into < Key > , value : impl Into < Value > ) -> Result < ( ) > {
437+ debug ! ( "invoking transactional insert request" ) ;
427438 self . check_allow_operation ( ) . await ?;
428439 let key = key. into ( ) ;
429440 if self . buffer . get ( & key) . is_some ( ) {
@@ -458,6 +469,7 @@ impl<PdC: PdClient> Transaction<PdC> {
458469 /// # });
459470 /// ```
460471 pub async fn delete ( & mut self , key : impl Into < Key > ) -> Result < ( ) > {
472+ debug ! ( "invoking transactional delete request" ) ;
461473 self . check_allow_operation ( ) . await ?;
462474 let key = key. into ( ) ;
463475 if self . is_pessimistic ( ) {
@@ -495,6 +507,7 @@ impl<PdC: PdClient> Transaction<PdC> {
495507 & mut self ,
496508 keys : impl IntoIterator < Item = impl Into < Key > > ,
497509 ) -> Result < ( ) > {
510+ debug ! ( "invoking transactional lock_keys request" ) ;
498511 self . check_allow_operation ( ) . await ?;
499512 match self . options . kind {
500513 TransactionKind :: Optimistic => {
@@ -526,6 +539,7 @@ impl<PdC: PdClient> Transaction<PdC> {
526539 /// # });
527540 /// ```
528541 pub async fn commit ( & mut self ) -> Result < Option < Timestamp > > {
542+ debug ! ( "commiting transaction" ) ;
529543 {
530544 let mut status = self . status . write ( ) . await ;
531545 if !matches ! (
@@ -582,6 +596,7 @@ impl<PdC: PdClient> Transaction<PdC> {
582596 /// # });
583597 /// ```
584598 pub async fn rollback ( & mut self ) -> Result < ( ) > {
599+ debug ! ( "rolling back transaction" ) ;
585600 {
586601 let status = self . status . read ( ) . await ;
587602 if !matches ! (
@@ -625,6 +640,7 @@ impl<PdC: PdClient> Transaction<PdC> {
625640 /// Returns the TTL set on the transaction's locks by TiKV.
626641 #[ doc( hidden) ]
627642 pub async fn send_heart_beat ( & mut self ) -> Result < u64 > {
643+ debug ! ( "sending heart_beat" ) ;
628644 self . check_allow_operation ( ) . await ?;
629645 let primary_key = match self . buffer . get_primary_key ( ) {
630646 Some ( k) => k,
@@ -686,6 +702,7 @@ impl<PdC: PdClient> Transaction<PdC> {
686702 keys : impl IntoIterator < Item = impl PessimisticLock > ,
687703 need_value : bool ,
688704 ) -> Result < Vec < KvPair > > {
705+ debug ! ( "acquiring pessimistic lock" ) ;
689706 assert ! (
690707 matches!( self . options. kind, TransactionKind :: Pessimistic ( _) ) ,
691708 "`pessimistic_lock` is only valid to use with pessimistic transactions"
@@ -752,6 +769,7 @@ impl<PdC: PdClient> Transaction<PdC> {
752769 }
753770
754771 async fn start_auto_heartbeat ( & mut self ) {
772+ debug ! ( "starting auto_heartbeat" ) ;
755773 if !self . options . heartbeat_option . is_auto_heartbeat ( ) || self . is_heartbeat_started {
756774 return ;
757775 }
@@ -810,6 +828,7 @@ impl<PdC: PdClient> Transaction<PdC> {
810828
811829impl < PdC : PdClient > Drop for Transaction < PdC > {
812830 fn drop ( & mut self ) {
831+ debug ! ( "dropping transaction" ) ;
813832 if std:: thread:: panicking ( ) {
814833 return ;
815834 }
0 commit comments