Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction::batch_get should return Result<Vec<KvPair>> #326

Closed
blacktear23 opened this issue Jan 16, 2022 · 4 comments
Closed

Transaction::batch_get should return Result<Vec<KvPair>> #326

blacktear23 opened this issue Jan 16, 2022 · 4 comments

Comments

@blacktear23
Copy link

Transaction::batch_get should return Result<Vec<KvPair>> as RawClient do.

Currently Result<impl Iterator<Item = KvPair>> not implements Copy trait so it cannot compile in tokio::spawn async block.

@ekexium
Copy link
Collaborator

ekexium commented Jan 17, 2022

Could you provide an example?

@blacktear23
Copy link
Author

blacktear23 commented Jan 18, 2022

Sample Code:

use tikv_client::TransactionClient;
use tokio::runtime::Runtime;

async fn tikv_test() {
    let pd_addrs = vec![String::from("127.0.0.1:2379")];
    let conn = TransactionClient::new(pd_addrs).await.unwrap();
    let mut txn = conn.begin_pessimistic().await.unwrap();
    txn.batch_get(vec![String::from("key1"), String::from("key2")]).await;
}

fn main() {
    let runtime = Runtime::new().unwrap();
    runtime.spawn(async move {
        tikv_test().await;
    });
    runtime.block_on(async {
        tikv_test().await;
    });
    println!("Hello, world!");
}
   Compiling tikvclienttest v0.1.0 (/Users/rain/work/tikvclienttest)
error[E0277]: `dyn Iterator<Item = Key>` cannot be sent between threads safely
  --> src/main.rs:13:13
   |
13 |     runtime.spawn(async move {
   |             ^^^^^ `dyn Iterator<Item = Key>` cannot be sent between threads safely
   |
   = help: the trait `Send` is not implemented for `dyn Iterator<Item = Key>`
   = note: required because of the requirements on the impl of `Send` for `Unique<dyn Iterator<Item = Key>>`
   = note: required because it appears within the type `Box<dyn Iterator<Item = Key>>`
   = note: required because it appears within the type `for<'r, 's> {ResumeTy, &'r mut transaction::buffer::Buffer, Map<std::vec::IntoIter<String>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#0}]>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#1}], FilterMap<std::vec::IntoIter<(Key, transaction::buffer::MutationValue)>, [closure@transaction::buffer::Buffer::batch_get_or_else<[closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#1}], impl Future, Map<std::vec::IntoIter<String>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#0}]>>::{closure#0}::{closure#2}]>, Map<std::vec::IntoIter<(Key, transaction::buffer::MutationValue)>, [closure@transaction::buffer::Buffer::batch_get_or_else<[closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#1}], impl Future, Map<std::vec::IntoIter<String>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#0}]>>::{closure#0}::{closure#3}]>, Box<(dyn Iterator<Item = Key> + 's)>, Box<Map<std::vec::IntoIter<(Key, transaction::buffer::MutationValue)>, [closure@transaction::buffer::Buffer::batch_get_or_else<[closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#1}], impl Future, Map<std::vec::IntoIter<String>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#0}]>>::{closure#0}::{closure#3}]>>, impl Future, ()}`
   = note: required because it appears within the type `[static generator@transaction::buffer::Buffer::batch_get_or_else<[closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#1}], impl Future, Map<std::vec::IntoIter<String>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#0}]>>::{closure#0}]`
   = note: required because it appears within the type `from_generator::GenFuture<[static generator@transaction::buffer::Buffer::batch_get_or_else<[closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#1}], impl Future, Map<std::vec::IntoIter<String>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#0}]>>::{closure#0}]>`
   = note: required because it appears within the type `impl Future`
   = note: required because it appears within the type `impl Future`
   = note: required because it appears within the type `for<'r, 's, 't0, 't1, 't2, 't3, 't4, 't5, 't6, 't7> {ResumeTy, &'r mut Transaction, Vec<String>, &'s Transaction, impl for<'t0> Future, (), Timestamp, Arc<tikv_client::pd::client::PdRpcClient>, RetryOptions, Transaction, &'t1 mut transaction::buffer::Buffer, transaction::buffer::Buffer, std::vec::IntoIter<String>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#0}], Map<std::vec::IntoIter<String>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#0}]>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#1}], impl for<'t4, 't5, 't6, 't7> Future}`
   = note: required because it appears within the type `[static generator@Transaction::batch_get<String, Vec<String>>::{closure#0}]`
   = note: required because it appears within the type `from_generator::GenFuture<[static generator@Transaction::batch_get<String, Vec<String>>::{closure#0}]>`
   = note: required because it appears within the type `impl Future`
   = note: required because it appears within the type `impl Future`
   = note: required because it appears within the type `for<'r, 's, 't0, 't1, 't2> {ResumeTy, Vec<String>, impl Future, (), TransactionClient, &'r TransactionClient, impl for<'s> Future, Transaction, &'t0 mut Transaction, &'t1 str, String, [String; 2], Box<[String]>, Box<[String; 2]>, impl for<'t2> Future}`
   = note: required because it appears within the type `[static generator@src/main.rs:4:22: 9:2]`
   = note: required because it appears within the type `from_generator::GenFuture<[static generator@src/main.rs:4:22: 9:2]>`
   = note: required because it appears within the type `impl Future`
   = note: required because it appears within the type `impl Future`
   = note: required because it appears within the type `{ResumeTy, impl Future, ()}`
   = note: required because it appears within the type `[static generator@src/main.rs:13:30: 15:6]`
   = note: required because it appears within the type `from_generator::GenFuture<[static generator@src/main.rs:13:30: 15:6]>`
   = note: required because it appears within the type `impl Future`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `tikvclienttest` due to previous error

@ekexium
Copy link
Collaborator

ekexium commented Jan 18, 2022

I see. It's been fixed in #297. You could try it on the master branch.

@blacktear23
Copy link
Author

@ekexium It works for master branch. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants