11// Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0.
22
33use std:: marker:: PhantomData ;
4+ use std:: sync:: atomic:: { AtomicU64 , Ordering } ;
45use std:: sync:: Arc ;
56
67use async_recursion:: async_recursion;
@@ -38,6 +39,12 @@ use crate::Error;
3839use crate :: Result ;
3940use crate :: Timestamp ;
4041
42+ static DISPATCH_REQUEST_ID : AtomicU64 = AtomicU64 :: new ( 1 ) ;
43+
44+ fn next_dispatch_request_id ( ) -> u64 {
45+ DISPATCH_REQUEST_ID . fetch_add ( 1 , Ordering :: Relaxed )
46+ }
47+
4148/// A plan for how to execute a request. A user builds up a plan with various
4249/// options, then exectutes it.
4350#[ async_trait]
@@ -61,9 +68,10 @@ impl<Req: KvRequest> Plan for Dispatch<Req> {
6168 type Result = Req :: Response ;
6269
6370 async fn execute ( & self ) -> Result < Self :: Result > {
71+ let request_id = next_dispatch_request_id ( ) ;
6472 let stats = tikv_stats ( self . request . label ( ) ) ;
6573 if self . request . label ( ) == "kv_prewrite" || self . request . label ( ) == "kv_commit" {
66- info ! ( "req {}" , self . request. to_str( ) )
74+ info ! ( "req_id={} req {}" , request_id , self . request. to_str( ) )
6775 }
6876 let result = self
6977 . kv_client
@@ -77,7 +85,7 @@ impl<Req: KvRequest> Plan for Dispatch<Req> {
7785 . downcast ( )
7886 . expect ( "Downcast failed: request and response type mismatch" ) ;
7987 if self . request . label ( ) == "kv_prewrite" || self . request . label ( ) == "kv_commit" {
80- info ! ( "resp {:?}" , resp) ;
88+ info ! ( "req_id={} resp {:?}" , request_id , resp) ;
8189 }
8290 resp
8391 } )
0 commit comments