mirror of https://github.com/tikv/client-rust.git
req debug log
Signed-off-by: Ping Yu <yuping@pingcap.com>
This commit is contained in:
parent
c7db27f8b4
commit
fdf0e0874e
|
|
@ -42,7 +42,7 @@ mod shard;
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait KvRequest: Request + Sized + Clone + Sync + Send + 'static {
|
pub trait KvRequest: Request + Sized + Clone + Sync + Send + 'static {
|
||||||
/// The expected response to the request.
|
/// The expected response to the request.
|
||||||
type Response: HasKeyErrors + HasLocks + Clone + Send + 'static;
|
type Response: HasKeyErrors + HasLocks + Clone + Send + std::fmt::Debug + 'static;
|
||||||
|
|
||||||
// TODO: fn encode_request()
|
// TODO: fn encode_request()
|
||||||
// TODO: fn decode_response()
|
// TODO: fn decode_response()
|
||||||
|
|
@ -114,7 +114,7 @@ mod test {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_region_retry() {
|
async fn test_region_retry() {
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
struct MockRpcResponse;
|
struct MockRpcResponse;
|
||||||
|
|
||||||
impl HasKeyErrors for MockRpcResponse {
|
impl HasKeyErrors for MockRpcResponse {
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,9 @@ impl<Req: KvRequest> Plan for Dispatch<Req> {
|
||||||
|
|
||||||
async fn execute(&self) -> Result<Self::Result> {
|
async fn execute(&self) -> Result<Self::Result> {
|
||||||
let stats = tikv_stats(self.request.label());
|
let stats = tikv_stats(self.request.label());
|
||||||
|
if self.request.label() == "kv_prewrite" || self.request.label() == "kv_commit" {
|
||||||
|
info!("req {}", self.request.to_str())
|
||||||
|
}
|
||||||
let result = self
|
let result = self
|
||||||
.kv_client
|
.kv_client
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|
@ -70,8 +73,13 @@ impl<Req: KvRequest> Plan for Dispatch<Req> {
|
||||||
.await;
|
.await;
|
||||||
let result = stats.done(result);
|
let result = stats.done(result);
|
||||||
result.map(|r| {
|
result.map(|r| {
|
||||||
*r.downcast()
|
let resp = *r
|
||||||
.expect("Downcast failed: request and response type mismatch")
|
.downcast()
|
||||||
|
.expect("Downcast failed: request and response type mismatch");
|
||||||
|
if self.request.label() == "kv_prewrite" || self.request.label() == "kv_commit" {
|
||||||
|
info!("resp {:?}", resp);
|
||||||
|
}
|
||||||
|
resp
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,9 @@ pub trait Request: Any + Sync + Send + 'static {
|
||||||
/// Should always use `set_context` other than modify the `self.context` directly.
|
/// Should always use `set_context` other than modify the `self.context` directly.
|
||||||
fn set_context(&mut self, context: kvrpcpb::Context);
|
fn set_context(&mut self, context: kvrpcpb::Context);
|
||||||
fn set_api_version(&mut self, api_version: kvrpcpb::ApiVersion);
|
fn set_api_version(&mut self, api_version: kvrpcpb::ApiVersion);
|
||||||
|
fn to_str(&self) -> String {
|
||||||
|
"".to_string()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_request {
|
macro_rules! impl_request {
|
||||||
|
|
@ -68,6 +71,10 @@ macro_rules! impl_request {
|
||||||
let context = self.context.get_or_insert(kvrpcpb::Context::default());
|
let context = self.context.get_or_insert(kvrpcpb::Context::default());
|
||||||
context.api_version = api_version.into();
|
context.api_version = api_version.into();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn to_str(&self) -> String {
|
||||||
|
format!("{:?}", self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue