Skip to content

Commit 503047f

Browse files
authored
don't update cache if scan is key_only (#346)
* don't update cache if scan is key_only Signed-off-by: ekexium <[email protected]> * fix clippy Signed-off-by: ekexium <[email protected]>
1 parent 9a7eff2 commit 503047f

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

src/transaction/buffer.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ impl Buffer {
110110
&mut self,
111111
range: BoundRange,
112112
limit: u32,
113+
update_cache: bool,
113114
f: F,
114115
) -> Result<impl Iterator<Item = KvPair>>
115116
where
@@ -147,8 +148,10 @@ impl Buffer {
147148
}
148149

149150
// update local buffer
150-
for (k, v) in &results {
151-
self.update_cache(k.clone(), Some(v.clone()));
151+
if update_cache {
152+
for (k, v) in &results {
153+
self.update_cache(k.clone(), Some(v.clone()));
154+
}
152155
}
153156

154157
let mut res = results

src/transaction/transaction.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ impl<PdC: PdClient> Transaction<PdC> {
690690
.scan_and_fetch(
691691
range.into(),
692692
limit,
693+
!key_only,
693694
move |new_range, new_limit| async move {
694695
let request = new_scan_request(new_range, timestamp, new_limit, key_only);
695696
let plan = PlanBuilder::new(rpc, request)

tests/integration_tests.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ async fn raw_req() -> Result<()> {
395395
assert_eq!(res[1].1, "v2".as_bytes());
396396

397397
// k1,k2; batch_put then batch_get
398-
let _ = client
398+
client
399399
.batch_put(vec![
400400
("k3".to_owned(), "v3".to_owned()),
401401
("k4".to_owned(), "v4".to_owned()),
@@ -437,7 +437,7 @@ async fn raw_req() -> Result<()> {
437437
assert_eq!(res.len(), 0);
438438

439439
// empty; batch_put then scan
440-
let _ = client
440+
client
441441
.batch_put(vec![
442442
("k3".to_owned(), "v3".to_owned()),
443443
("k5".to_owned(), "v5".to_owned()),
@@ -860,6 +860,29 @@ async fn raw_cas() -> Result<()> {
860860
Ok(())
861861
}
862862

863+
#[tokio::test]
864+
#[serial]
865+
async fn txn_scan() -> Result<()> {
866+
init().await?;
867+
let client = TransactionClient::new_with_config(pd_addrs(), Default::default(), None).await?;
868+
869+
let k1 = b"a".to_vec();
870+
let v = b"b".to_vec();
871+
872+
// pessimistic
873+
let option = TransactionOptions::new_pessimistic().drop_check(tikv_client::CheckLevel::Warn);
874+
let mut t = client.begin_with_options(option.clone()).await?;
875+
t.put(k1.clone(), v).await?;
876+
t.commit().await?;
877+
878+
let mut t2 = client.begin_with_options(option).await?;
879+
t2.get(k1.clone()).await?;
880+
t2.key_exists(k1).await?;
881+
t2.commit().await?;
882+
883+
Ok(())
884+
}
885+
863886
// helper function
864887
async fn get_u32(client: &RawClient, key: Vec<u8>) -> Result<u32> {
865888
let x = client.get(key).await?.unwrap();

tests/mock_tikv_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ mod test {
2424
assert_eq!(res.unwrap(), None);
2525

2626
// empty; put then batch_get
27-
let _ = client.put("k1".to_owned(), "v1".to_owned()).await.unwrap();
28-
let _ = client.put("k2".to_owned(), "v2".to_owned()).await.unwrap();
27+
client.put("k1".to_owned(), "v1".to_owned()).await.unwrap();
28+
client.put("k2".to_owned(), "v2".to_owned()).await.unwrap();
2929

3030
let res = client
3131
.batch_get(vec!["k1".to_owned(), "k2".to_owned(), "k3".to_owned()])
@@ -36,7 +36,7 @@ mod test {
3636
assert_eq!(res[1].1, "v2".as_bytes());
3737

3838
// k1,k2; batch_put then batch_get
39-
let _ = client
39+
client
4040
.batch_put(vec![
4141
KvPair::new("k3".to_owned(), "v3".to_owned()),
4242
KvPair::new("k4".to_owned(), "v4".to_owned()),

0 commit comments

Comments
 (0)