mirror of https://github.com/tikv/client-rust.git
Simplifies code according to the review.
Signed-off-by: Steven Gu <asongala@163.com>
This commit is contained in:
parent
e3836ade98
commit
7f07f162be
|
|
@ -86,19 +86,13 @@ where
|
||||||
Compat01As03<RpcFuture>: Future<Output = std::result::Result<Resp, ::grpcio::Error>>,
|
Compat01As03<RpcFuture>: Future<Output = std::result::Result<Resp, ::grpcio::Error>>,
|
||||||
Resp: HasError + Sized + Clone + Send + 'static,
|
Resp: HasError + Sized + Clone + Send + 'static,
|
||||||
{
|
{
|
||||||
|
let res = match fut {
|
||||||
|
Ok(f) => Compat01As03::new(f).await,
|
||||||
|
Err(e) => Err(e),
|
||||||
|
};
|
||||||
|
|
||||||
let context = tikv_stats(request_name);
|
let context = tikv_stats(request_name);
|
||||||
|
context.done(res.map_err(|e| ErrorKind::Grpc(e).into()))
|
||||||
let fut = match fut {
|
|
||||||
Err(e) => return context.done(Err(ErrorKind::Grpc(e).into())),
|
|
||||||
Ok(f) => f,
|
|
||||||
};
|
|
||||||
|
|
||||||
let res = match Compat01As03::new(fut).await {
|
|
||||||
Err(e) => Err(ErrorKind::Grpc(e).into()),
|
|
||||||
Ok(r) => Ok(r),
|
|
||||||
};
|
|
||||||
|
|
||||||
context.done(res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(new)]
|
#[derive(new)]
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@ use crate::{
|
||||||
Result, Value,
|
Result, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
use futures::future::Either;
|
|
||||||
use futures::prelude::future;
|
|
||||||
use std::{sync::Arc, u32};
|
use std::{sync::Arc, u32};
|
||||||
|
|
||||||
const MAX_RAW_KV_SCAN_LIMIT: u32 = 10240;
|
const MAX_RAW_KV_SCAN_LIMIT: u32 = 10240;
|
||||||
|
|
@ -249,19 +247,13 @@ impl Client {
|
||||||
/// # });
|
/// # });
|
||||||
/// ```
|
/// ```
|
||||||
pub async fn scan(&self, range: impl Into<BoundRange>, limit: u32) -> Result<Vec<KvPair>> {
|
pub async fn scan(&self, range: impl Into<BoundRange>, limit: u32) -> Result<Vec<KvPair>> {
|
||||||
let request = if limit > MAX_RAW_KV_SCAN_LIMIT {
|
if limit > MAX_RAW_KV_SCAN_LIMIT {
|
||||||
Either::Right(future::err(Error::max_scan_limit_exceeded(
|
return Err(Error::max_scan_limit_exceeded(limit, MAX_RAW_KV_SCAN_LIMIT));
|
||||||
limit,
|
}
|
||||||
MAX_RAW_KV_SCAN_LIMIT,
|
|
||||||
)))
|
|
||||||
} else {
|
|
||||||
Either::Left(
|
|
||||||
requests::new_raw_scan_request(range, limit, self.key_only, self.cf.clone())
|
|
||||||
.execute(self.rpc.clone()),
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
request.await
|
requests::new_raw_scan_request(range, limit, self.key_only, self.cf.clone())
|
||||||
|
.execute(self.rpc.clone())
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new 'batch scan' request.
|
/// Create a new 'batch scan' request.
|
||||||
|
|
@ -285,23 +277,15 @@ impl Client {
|
||||||
ranges: impl IntoIterator<Item = impl Into<BoundRange>>,
|
ranges: impl IntoIterator<Item = impl Into<BoundRange>>,
|
||||||
each_limit: u32,
|
each_limit: u32,
|
||||||
) -> Result<Vec<KvPair>> {
|
) -> Result<Vec<KvPair>> {
|
||||||
let request = if each_limit > MAX_RAW_KV_SCAN_LIMIT {
|
if each_limit > MAX_RAW_KV_SCAN_LIMIT {
|
||||||
Either::Right(future::err(Error::max_scan_limit_exceeded(
|
return Err(Error::max_scan_limit_exceeded(
|
||||||
each_limit,
|
each_limit,
|
||||||
MAX_RAW_KV_SCAN_LIMIT,
|
MAX_RAW_KV_SCAN_LIMIT,
|
||||||
)))
|
));
|
||||||
} else {
|
}
|
||||||
Either::Left(
|
|
||||||
requests::new_raw_batch_scan_request(
|
|
||||||
ranges,
|
|
||||||
each_limit,
|
|
||||||
self.key_only,
|
|
||||||
self.cf.clone(),
|
|
||||||
)
|
|
||||||
.execute(self.rpc.clone()),
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
request.await
|
requests::new_raw_batch_scan_request(ranges, each_limit, self.key_only, self.cf.clone())
|
||||||
|
.execute(self.rpc.clone())
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue