Simplifies code according to the review.

Signed-off-by: Steven Gu <asongala@163.com>
This commit is contained in:
Steven Gu 2020-02-13 00:43:20 +08:00
parent e3836ade98
commit 7f07f162be
2 changed files with 19 additions and 41 deletions

View File

@ -86,19 +86,13 @@ where
Compat01As03<RpcFuture>: Future<Output = std::result::Result<Resp, ::grpcio::Error>>,
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 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)
context.done(res.map_err(|e| ErrorKind::Grpc(e).into()))
}
#[derive(new)]

View File

@ -6,8 +6,6 @@ use crate::{
Result, Value,
};
use futures::future::Either;
use futures::prelude::future;
use std::{sync::Arc, u32};
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>> {
let request = if limit > MAX_RAW_KV_SCAN_LIMIT {
Either::Right(future::err(Error::max_scan_limit_exceeded(
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()),
)
};
if limit > MAX_RAW_KV_SCAN_LIMIT {
return Err(Error::max_scan_limit_exceeded(limit, MAX_RAW_KV_SCAN_LIMIT));
}
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.
@ -285,23 +277,15 @@ impl Client {
ranges: impl IntoIterator<Item = impl Into<BoundRange>>,
each_limit: u32,
) -> Result<Vec<KvPair>> {
let request = if each_limit > MAX_RAW_KV_SCAN_LIMIT {
Either::Right(future::err(Error::max_scan_limit_exceeded(
if each_limit > MAX_RAW_KV_SCAN_LIMIT {
return Err(Error::max_scan_limit_exceeded(
each_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
}
}