Skip to content

Commit

Permalink
fixed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulrane50 committed Feb 14, 2024
1 parent 5366b6e commit 68f1b9f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/raw/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@ impl<PdC: PdClient> Client<PdC> {
/// only the first `limit` pairs are returned, ordered by the key.
///
///
/// Reverse Scan queries continuous kv pairs in range (endKey, startKey],
/// from startKey(upperBound) to endKey(lowerBound), up to limit pairs.
/// Reverse Scan queries continuous kv pairs in range [startKey, endKey),
/// from startKey(lowerBound) to endKey(upperBound) in reverse order, up to limit pairs.
/// The returned keys are in reversed lexicographical order.
/// If you want to include the endKey or exclude the startKey, push a '\0' to the key.
/// It doesn't support Scanning from "", because locating the last Region is not yet implemented.
Expand All @@ -522,7 +522,7 @@ impl<PdC: PdClient> Client<PdC> {
/// # use futures::prelude::*;
/// # futures::executor::block_on(async {
/// # let client = RawClient::new(vec!["192.168.0.100"]).await.unwrap();
/// let inclusive_range = "TiDB"..="TiKV";
/// let inclusive_range = "TiKV"..="TiDB";
/// let req = client.scan_reverse(inclusive_range.into_owned(), 2);
/// let result: Vec<KvPair> = req.await.unwrap();
/// # });
Expand Down
9 changes: 7 additions & 2 deletions src/raw/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,13 @@ pub fn new_raw_scan_request(
cf: Option<ColumnFamily>,
) -> kvrpcpb::RawScanRequest {
let mut req = kvrpcpb::RawScanRequest::default();
req.start_key = start_key;
req.end_key = end_key;
if !reverse {
req.start_key = start_key;
req.end_key = end_key;
} else {
req.start_key = end_key;
req.end_key = start_key;
}
req.limit = limit;
req.key_only = key_only;
req.reverse = reverse;
Expand Down
22 changes: 13 additions & 9 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,10 @@ async fn raw_req() -> Result<()> {
assert_eq!(res[6].1, "v5".as_bytes());

// reverse scan
// By default end key is exclusive, so k5 is not included and start key in included

// By default end key is exclusive, so k5 is not included and start key in included
let res = client
.scan_reverse("k5".to_owned().."k2".to_owned(), 5)
.scan_reverse("k2".to_owned().."k5".to_owned(), 5)
.await?;
assert_eq!(res.len(), 3);
assert_eq!(res[0].1, "v4".as_bytes());
Expand All @@ -574,7 +574,7 @@ async fn raw_req() -> Result<()> {

// by default end key in exclusive and start key is inclusive but now exclude start key
let res = client
.scan_reverse("k5".to_owned()..="k2".to_owned(), 5)
.scan_reverse("k2\0".to_owned().."k5".to_owned(), 5)
.await?;
assert_eq!(res.len(), 2);
assert_eq!(res[0].1, "v4".as_bytes());
Expand All @@ -583,7 +583,7 @@ async fn raw_req() -> Result<()> {
// reverse scan
// by default end key is exclusive and start key is inclusive but now include end key
let res = client
.scan_reverse("k5\0".to_owned().."k2".to_owned(), 5)
.scan_reverse("k2".to_owned()..="k5".to_owned(), 5)
.await?;
assert_eq!(res.len(), 4);
assert_eq!(res[0].1, "v5".as_bytes());
Expand All @@ -593,7 +593,7 @@ async fn raw_req() -> Result<()> {

// by default end key is exclusive and start key is inclusive but now include end key and exclude start key
let res = client
.scan_reverse("k5\0".to_owned()..="k2".to_owned(), 5)
.scan_reverse("k2\0".to_owned()..="k5".to_owned(), 5)
.await?;
assert_eq!(res.len(), 3);
assert_eq!(res[0].1, "v5".as_bytes());
Expand All @@ -602,16 +602,20 @@ async fn raw_req() -> Result<()> {

// limit results to first 2
let res = client
.scan_reverse("k5".to_owned().."k2".to_owned(), 2)
.scan_reverse("k2".to_owned().."k5".to_owned(), 2)
.await?;
assert_eq!(res.len(), 2);
assert_eq!(res[0].1, "v4".as_bytes());
assert_eq!(res[1].1, "v3".as_bytes());

//let range = "k5"..; // Upperbound (k5, +inf). This is NOT SUPPORTED by TiKV.
let range = BoundRange::range_from(Key::from("k5".to_owned()));
// if endKey is not provided then it scan everything including end key
let range = BoundRange::range_from(Key::from("k2".to_owned()));
let res = client.scan_reverse(range, 20).await?;
assert_eq!(res.len(), 0);
assert_eq!(res.len(), 4);
assert_eq!(res[0].1, "v5".as_bytes());
assert_eq!(res[1].1, "v4".as_bytes());
assert_eq!(res[2].1, "v3".as_bytes());
assert_eq!(res[3].1, "v2".as_bytes());

Ok(())
}
Expand Down

0 comments on commit 68f1b9f

Please sign in to comment.